]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #9253 from donaldsharp/igmp_no
[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/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nexthop.h"
57 #include "bgpd/bgp_open.h"
58 #include "bgpd/bgp_regex.h"
59 #include "bgpd/bgp_route.h"
60 #include "bgpd/bgp_mplsvpn.h"
61 #include "bgpd/bgp_zebra.h"
62 #include "bgpd/bgp_table.h"
63 #include "bgpd/bgp_vty.h"
64 #include "bgpd/bgp_mpath.h"
65 #include "bgpd/bgp_packet.h"
66 #include "bgpd/bgp_updgrp.h"
67 #include "bgpd/bgp_bfd.h"
68 #include "bgpd/bgp_io.h"
69 #include "bgpd/bgp_evpn.h"
70 #include "bgpd/bgp_evpn_vty.h"
71 #include "bgpd/bgp_evpn_mh.h"
72 #include "bgpd/bgp_addpath.h"
73 #include "bgpd/bgp_mac.h"
74 #include "bgpd/bgp_flowspec.h"
75 #include "bgpd/bgp_conditional_adv.h"
76 #ifdef ENABLE_BGP_VNC
77 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
78 #endif
79
80 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
81 {
82 .val_bool = false,
83 .match_profile = "traditional",
84 .match_version = "< 7.4",
85 },
86 { .val_bool = true },
87 );
88 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
91 );
92 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
95 );
96 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
99 );
100 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
103 );
104 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
105 { .val_ulong = 10, .match_profile = "datacenter", },
106 { .val_ulong = 120 },
107 );
108 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
109 { .val_ulong = 9, .match_profile = "datacenter", },
110 { .val_ulong = 180 },
111 );
112 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
113 { .val_ulong = 3, .match_profile = "datacenter", },
114 { .val_ulong = 60 },
115 );
116 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
117 { .val_bool = false, .match_profile = "datacenter", },
118 { .val_bool = false, .match_version = "< 7.4", },
119 { .val_bool = true },
120 );
121 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
122 { .val_bool = false, .match_version = "< 7.6", },
123 { .val_bool = true },
124 );
125
126 DEFINE_HOOK(bgp_inst_config_write,
127 (struct bgp *bgp, struct vty *vty),
128 (bgp, vty));
129 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
130 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
131
132 static struct peer_group *listen_range_exists(struct bgp *bgp,
133 struct prefix *range, int exact);
134
135 /* Show BGP peer's information. */
136 enum show_type {
137 show_all,
138 show_peer,
139 show_ipv4_all,
140 show_ipv6_all,
141 show_ipv4_peer,
142 show_ipv6_peer
143 };
144
145 static struct peer_group *listen_range_exists(struct bgp *bgp,
146 struct prefix *range, int exact);
147
148 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
149 struct bgp *bgp,
150 bool use_json,
151 json_object *json);
152
153 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
154 enum show_type type,
155 const char *ip_str,
156 afi_t afi, bool use_json);
157
158 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
159 {
160 switch (afi) {
161 case AFI_IP:
162 switch (safi) {
163 case SAFI_UNICAST:
164 return BGP_IPV4_NODE;
165 case SAFI_MULTICAST:
166 return BGP_IPV4M_NODE;
167 case SAFI_LABELED_UNICAST:
168 return BGP_IPV4L_NODE;
169 case SAFI_MPLS_VPN:
170 return BGP_VPNV4_NODE;
171 case SAFI_FLOWSPEC:
172 return BGP_FLOWSPECV4_NODE;
173 default:
174 /* not expected */
175 return BGP_IPV4_NODE;
176 }
177 break;
178 case AFI_IP6:
179 switch (safi) {
180 case SAFI_UNICAST:
181 return BGP_IPV6_NODE;
182 case SAFI_MULTICAST:
183 return BGP_IPV6M_NODE;
184 case SAFI_LABELED_UNICAST:
185 return BGP_IPV6L_NODE;
186 case SAFI_MPLS_VPN:
187 return BGP_VPNV6_NODE;
188 case SAFI_FLOWSPEC:
189 return BGP_FLOWSPECV6_NODE;
190 default:
191 /* not expected */
192 return BGP_IPV4_NODE;
193 }
194 break;
195 case AFI_L2VPN:
196 return BGP_EVPN_NODE;
197 case AFI_UNSPEC:
198 case AFI_MAX:
199 // We should never be here but to clarify the switch statement..
200 return BGP_IPV4_NODE;
201 }
202
203 // Impossible to happen
204 return BGP_IPV4_NODE;
205 }
206
207 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
208 {
209 if (afi == AFI_IP) {
210 if (safi == SAFI_UNICAST)
211 return "IPv4 Unicast";
212 if (safi == SAFI_MULTICAST)
213 return "IPv4 Multicast";
214 if (safi == SAFI_LABELED_UNICAST)
215 return "IPv4 Labeled Unicast";
216 if (safi == SAFI_MPLS_VPN)
217 return "IPv4 VPN";
218 if (safi == SAFI_ENCAP)
219 return "IPv4 Encap";
220 if (safi == SAFI_FLOWSPEC)
221 return "IPv4 Flowspec";
222 } else if (afi == AFI_IP6) {
223 if (safi == SAFI_UNICAST)
224 return "IPv6 Unicast";
225 if (safi == SAFI_MULTICAST)
226 return "IPv6 Multicast";
227 if (safi == SAFI_LABELED_UNICAST)
228 return "IPv6 Labeled Unicast";
229 if (safi == SAFI_MPLS_VPN)
230 return "IPv6 VPN";
231 if (safi == SAFI_ENCAP)
232 return "IPv6 Encap";
233 if (safi == SAFI_FLOWSPEC)
234 return "IPv6 Flowspec";
235 } else if (afi == AFI_L2VPN) {
236 if (safi == SAFI_EVPN)
237 return "L2VPN EVPN";
238 }
239
240 return "Unknown";
241 }
242
243 /*
244 * Please note that we have intentionally camelCased
245 * the return strings here. So if you want
246 * to use this function, please ensure you
247 * are doing this within json output
248 */
249 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
250 {
251 if (afi == AFI_IP) {
252 if (safi == SAFI_UNICAST)
253 return "ipv4Unicast";
254 if (safi == SAFI_MULTICAST)
255 return "ipv4Multicast";
256 if (safi == SAFI_LABELED_UNICAST)
257 return "ipv4LabeledUnicast";
258 if (safi == SAFI_MPLS_VPN)
259 return "ipv4Vpn";
260 if (safi == SAFI_ENCAP)
261 return "ipv4Encap";
262 if (safi == SAFI_FLOWSPEC)
263 return "ipv4Flowspec";
264 } else if (afi == AFI_IP6) {
265 if (safi == SAFI_UNICAST)
266 return "ipv6Unicast";
267 if (safi == SAFI_MULTICAST)
268 return "ipv6Multicast";
269 if (safi == SAFI_LABELED_UNICAST)
270 return "ipv6LabeledUnicast";
271 if (safi == SAFI_MPLS_VPN)
272 return "ipv6Vpn";
273 if (safi == SAFI_ENCAP)
274 return "ipv6Encap";
275 if (safi == SAFI_FLOWSPEC)
276 return "ipv6Flowspec";
277 } else if (afi == AFI_L2VPN) {
278 if (safi == SAFI_EVPN)
279 return "l2VpnEvpn";
280 }
281
282 return "Unknown";
283 }
284
285 /* Utility function to get address family from current node. */
286 afi_t bgp_node_afi(struct vty *vty)
287 {
288 afi_t afi;
289 switch (vty->node) {
290 case BGP_IPV6_NODE:
291 case BGP_IPV6M_NODE:
292 case BGP_IPV6L_NODE:
293 case BGP_VPNV6_NODE:
294 case BGP_FLOWSPECV6_NODE:
295 afi = AFI_IP6;
296 break;
297 case BGP_EVPN_NODE:
298 afi = AFI_L2VPN;
299 break;
300 default:
301 afi = AFI_IP;
302 break;
303 }
304 return afi;
305 }
306
307 /* Utility function to get subsequent address family from current
308 node. */
309 safi_t bgp_node_safi(struct vty *vty)
310 {
311 safi_t safi;
312 switch (vty->node) {
313 case BGP_VPNV4_NODE:
314 case BGP_VPNV6_NODE:
315 safi = SAFI_MPLS_VPN;
316 break;
317 case BGP_IPV4M_NODE:
318 case BGP_IPV6M_NODE:
319 safi = SAFI_MULTICAST;
320 break;
321 case BGP_EVPN_NODE:
322 safi = SAFI_EVPN;
323 break;
324 case BGP_IPV4L_NODE:
325 case BGP_IPV6L_NODE:
326 safi = SAFI_LABELED_UNICAST;
327 break;
328 case BGP_FLOWSPECV4_NODE:
329 case BGP_FLOWSPECV6_NODE:
330 safi = SAFI_FLOWSPEC;
331 break;
332 default:
333 safi = SAFI_UNICAST;
334 break;
335 }
336 return safi;
337 }
338
339 /**
340 * Converts an AFI in string form to afi_t
341 *
342 * @param afi string, one of
343 * - "ipv4"
344 * - "ipv6"
345 * - "l2vpn"
346 * @return the corresponding afi_t
347 */
348 afi_t bgp_vty_afi_from_str(const char *afi_str)
349 {
350 afi_t afi = AFI_MAX; /* unknown */
351 if (strmatch(afi_str, "ipv4"))
352 afi = AFI_IP;
353 else if (strmatch(afi_str, "ipv6"))
354 afi = AFI_IP6;
355 else if (strmatch(afi_str, "l2vpn"))
356 afi = AFI_L2VPN;
357 return afi;
358 }
359
360 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
361 afi_t *afi)
362 {
363 int ret = 0;
364 if (argv_find(argv, argc, "ipv4", index)) {
365 ret = 1;
366 if (afi)
367 *afi = AFI_IP;
368 } else if (argv_find(argv, argc, "ipv6", index)) {
369 ret = 1;
370 if (afi)
371 *afi = AFI_IP6;
372 } else if (argv_find(argv, argc, "l2vpn", index)) {
373 ret = 1;
374 if (afi)
375 *afi = AFI_L2VPN;
376 }
377 return ret;
378 }
379
380 /* supports <unicast|multicast|vpn|labeled-unicast> */
381 safi_t bgp_vty_safi_from_str(const char *safi_str)
382 {
383 safi_t safi = SAFI_MAX; /* unknown */
384 if (strmatch(safi_str, "multicast"))
385 safi = SAFI_MULTICAST;
386 else if (strmatch(safi_str, "unicast"))
387 safi = SAFI_UNICAST;
388 else if (strmatch(safi_str, "vpn"))
389 safi = SAFI_MPLS_VPN;
390 else if (strmatch(safi_str, "evpn"))
391 safi = SAFI_EVPN;
392 else if (strmatch(safi_str, "labeled-unicast"))
393 safi = SAFI_LABELED_UNICAST;
394 else if (strmatch(safi_str, "flowspec"))
395 safi = SAFI_FLOWSPEC;
396 return safi;
397 }
398
399 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
400 safi_t *safi)
401 {
402 int ret = 0;
403 if (argv_find(argv, argc, "unicast", index)) {
404 ret = 1;
405 if (safi)
406 *safi = SAFI_UNICAST;
407 } else if (argv_find(argv, argc, "multicast", index)) {
408 ret = 1;
409 if (safi)
410 *safi = SAFI_MULTICAST;
411 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
412 ret = 1;
413 if (safi)
414 *safi = SAFI_LABELED_UNICAST;
415 } else if (argv_find(argv, argc, "vpn", index)) {
416 ret = 1;
417 if (safi)
418 *safi = SAFI_MPLS_VPN;
419 } else if (argv_find(argv, argc, "evpn", index)) {
420 ret = 1;
421 if (safi)
422 *safi = SAFI_EVPN;
423 } else if (argv_find(argv, argc, "flowspec", index)) {
424 ret = 1;
425 if (safi)
426 *safi = SAFI_FLOWSPEC;
427 }
428 return ret;
429 }
430
431 /*
432 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
433 *
434 * afi
435 * address-family identifier
436 *
437 * safi
438 * subsequent address-family identifier
439 *
440 * Returns:
441 * default_af string corresponding to the supplied afi/safi pair.
442 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
443 * return -1.
444 */
445 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
446 {
447 switch (afi) {
448 case AFI_IP:
449 switch (safi) {
450 case SAFI_UNICAST:
451 return "ipv4-unicast";
452 case SAFI_MULTICAST:
453 return "ipv4-multicast";
454 case SAFI_MPLS_VPN:
455 return "ipv4-vpn";
456 case SAFI_ENCAP:
457 return "ipv4-encap";
458 case SAFI_LABELED_UNICAST:
459 return "ipv4-labeled-unicast";
460 case SAFI_FLOWSPEC:
461 return "ipv4-flowspec";
462 default:
463 return "unknown-afi/safi";
464 }
465 break;
466 case AFI_IP6:
467 switch (safi) {
468 case SAFI_UNICAST:
469 return "ipv6-unicast";
470 case SAFI_MULTICAST:
471 return "ipv6-multicast";
472 case SAFI_MPLS_VPN:
473 return "ipv6-vpn";
474 case SAFI_ENCAP:
475 return "ipv6-encap";
476 case SAFI_LABELED_UNICAST:
477 return "ipv6-labeled-unicast";
478 case SAFI_FLOWSPEC:
479 return "ipv6-flowspec";
480 default:
481 return "unknown-afi/safi";
482 }
483 break;
484 case AFI_L2VPN:
485 switch (safi) {
486 case SAFI_EVPN:
487 return "l2vpn-evpn";
488 default:
489 return "unknown-afi/safi";
490 }
491 case AFI_UNSPEC:
492 case AFI_MAX:
493 return "unknown-afi/safi";
494 }
495 /* all AFIs are accounted for above, so this shouldn't happen */
496 return "unknown-afi/safi";
497 }
498
499 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
500 enum bgp_instance_type inst_type)
501 {
502 int ret = bgp_get(bgp, as, name, inst_type);
503
504 if (ret == BGP_CREATED) {
505 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
506 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
507
508 if (DFLT_BGP_IMPORT_CHECK)
509 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
510 if (DFLT_BGP_SHOW_HOSTNAME)
511 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
512 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
513 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
514 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
515 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
516 if (DFLT_BGP_DETERMINISTIC_MED)
517 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
518 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
519 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
520 if (DFLT_BGP_SUPPRESS_DUPLICATES)
521 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
522
523 ret = BGP_SUCCESS;
524 }
525 return ret;
526 }
527
528 /*
529 * bgp_vty_find_and_parse_afi_safi_bgp
530 *
531 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
532 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
533 * to appropriate values for the calling function. This is to allow the
534 * calling function to make decisions appropriate for the show command
535 * that is being parsed.
536 *
537 * The show commands are generally of the form:
538 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
539 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
540 *
541 * Since we use argv_find if the show command in particular doesn't have:
542 * [ip]
543 * [<view|vrf> VIEWVRFNAME]
544 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
545 * The command parsing should still be ok.
546 *
547 * vty -> The vty for the command so we can output some useful data in
548 * the event of a parse error in the vrf.
549 * argv -> The command tokens
550 * argc -> How many command tokens we have
551 * idx -> The current place in the command, generally should be 0 for this
552 * function
553 * afi -> The parsed afi if it was included in the show command, returned here
554 * safi -> The parsed safi if it was included in the show command, returned here
555 * bgp -> Pointer to the bgp data structure we need to fill in.
556 * use_json -> json is configured or not
557 *
558 * The function returns the correct location in the parse tree for the
559 * last token found.
560 *
561 * Returns 0 for failure to parse correctly, else the idx position of where
562 * it found the last token.
563 */
564 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
565 struct cmd_token **argv, int argc,
566 int *idx, afi_t *afi, safi_t *safi,
567 struct bgp **bgp, bool use_json)
568 {
569 char *vrf_name = NULL;
570
571 assert(afi);
572 assert(safi);
573 assert(bgp);
574
575 if (argv_find(argv, argc, "ip", idx))
576 *afi = AFI_IP;
577
578 if (argv_find(argv, argc, "view", idx))
579 vrf_name = argv[*idx + 1]->arg;
580 else if (argv_find(argv, argc, "vrf", idx)) {
581 vrf_name = argv[*idx + 1]->arg;
582 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
583 vrf_name = NULL;
584 }
585 if (vrf_name) {
586 if (strmatch(vrf_name, "all"))
587 *bgp = NULL;
588 else {
589 *bgp = bgp_lookup_by_name(vrf_name);
590 if (!*bgp) {
591 if (use_json) {
592 json_object *json = NULL;
593 json = json_object_new_object();
594 json_object_string_add(
595 json, "warning",
596 "View/Vrf is unknown");
597 vty_out(vty, "%s\n",
598 json_object_to_json_string_ext(json,
599 JSON_C_TO_STRING_PRETTY));
600 json_object_free(json);
601 }
602 else
603 vty_out(vty, "View/Vrf %s is unknown\n",
604 vrf_name);
605 *idx = 0;
606 return 0;
607 }
608 }
609 } else {
610 *bgp = bgp_get_default();
611 if (!*bgp) {
612 if (use_json) {
613 json_object *json = NULL;
614 json = json_object_new_object();
615 json_object_string_add(
616 json, "warning",
617 "Default BGP instance not found");
618 vty_out(vty, "%s\n",
619 json_object_to_json_string_ext(json,
620 JSON_C_TO_STRING_PRETTY));
621 json_object_free(json);
622 }
623 else
624 vty_out(vty,
625 "Default BGP instance not found\n");
626 *idx = 0;
627 return 0;
628 }
629 }
630
631 if (argv_find_and_parse_afi(argv, argc, idx, afi))
632 argv_find_and_parse_safi(argv, argc, idx, safi);
633
634 *idx += 1;
635 return *idx;
636 }
637
638 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
639 {
640 struct interface *ifp = NULL;
641
642 if (su->sa.sa_family == AF_INET)
643 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
644 else if (su->sa.sa_family == AF_INET6)
645 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
646 su->sin6.sin6_scope_id,
647 bgp->vrf_id);
648
649 if (ifp)
650 return true;
651
652 return false;
653 }
654
655 /* Utility function for looking up peer from VTY. */
656 /* This is used only for configuration, so disallow if attempted on
657 * a dynamic neighbor.
658 */
659 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
660 {
661 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
662 int ret;
663 union sockunion su;
664 struct peer *peer;
665
666 if (!bgp) {
667 return NULL;
668 }
669
670 ret = str2sockunion(ip_str, &su);
671 if (ret < 0) {
672 peer = peer_lookup_by_conf_if(bgp, ip_str);
673 if (!peer) {
674 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
675 == NULL) {
676 vty_out(vty,
677 "%% Malformed address or name: %s\n",
678 ip_str);
679 return NULL;
680 }
681 }
682 } else {
683 peer = peer_lookup(bgp, &su);
684 if (!peer) {
685 vty_out(vty,
686 "%% Specify remote-as or peer-group commands first\n");
687 return NULL;
688 }
689 if (peer_dynamic_neighbor(peer)) {
690 vty_out(vty,
691 "%% Operation not allowed on a dynamic neighbor\n");
692 return NULL;
693 }
694 }
695 return peer;
696 }
697
698 /* Utility function for looking up peer or peer group. */
699 /* This is used only for configuration, so disallow if attempted on
700 * a dynamic neighbor.
701 */
702 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
703 {
704 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
705 int ret;
706 union sockunion su;
707 struct peer *peer = NULL;
708 struct peer_group *group = NULL;
709
710 if (!bgp) {
711 return NULL;
712 }
713
714 ret = str2sockunion(peer_str, &su);
715 if (ret == 0) {
716 /* IP address, locate peer. */
717 peer = peer_lookup(bgp, &su);
718 } else {
719 /* Not IP, could match either peer configured on interface or a
720 * group. */
721 peer = peer_lookup_by_conf_if(bgp, peer_str);
722 if (!peer)
723 group = peer_group_lookup(bgp, peer_str);
724 }
725
726 if (peer) {
727 if (peer_dynamic_neighbor(peer)) {
728 vty_out(vty,
729 "%% Operation not allowed on a dynamic neighbor\n");
730 return NULL;
731 }
732
733 return peer;
734 }
735
736 if (group)
737 return group->conf;
738
739 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
740
741 return NULL;
742 }
743
744 int bgp_vty_return(struct vty *vty, int ret)
745 {
746 const char *str = NULL;
747
748 switch (ret) {
749 case BGP_ERR_INVALID_VALUE:
750 str = "Invalid value";
751 break;
752 case BGP_ERR_INVALID_FLAG:
753 str = "Invalid flag";
754 break;
755 case BGP_ERR_PEER_GROUP_SHUTDOWN:
756 str = "Peer-group has been shutdown. Activate the peer-group first";
757 break;
758 case BGP_ERR_PEER_FLAG_CONFLICT:
759 str = "Can't set override-capability and strict-capability-match at the same time";
760 break;
761 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
762 str = "Specify remote-as or peer-group remote AS first";
763 break;
764 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
765 str = "Cannot change the peer-group. Deconfigure first";
766 break;
767 case BGP_ERR_PEER_GROUP_MISMATCH:
768 str = "Peer is not a member of this peer-group";
769 break;
770 case BGP_ERR_PEER_FILTER_CONFLICT:
771 str = "Prefix/distribute list can not co-exist";
772 break;
773 case BGP_ERR_NOT_INTERNAL_PEER:
774 str = "Invalid command. Not an internal neighbor";
775 break;
776 case BGP_ERR_REMOVE_PRIVATE_AS:
777 str = "remove-private-AS cannot be configured for IBGP peers";
778 break;
779 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
780 str = "Local-AS allowed only for EBGP peers";
781 break;
782 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
783 str = "Cannot have local-as same as BGP AS number";
784 break;
785 case BGP_ERR_TCPSIG_FAILED:
786 str = "Error while applying TCP-Sig to session(s)";
787 break;
788 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
789 str = "ebgp-multihop and ttl-security cannot be configured together";
790 break;
791 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
792 str = "ttl-security only allowed for EBGP peers";
793 break;
794 case BGP_ERR_AS_OVERRIDE:
795 str = "as-override cannot be configured for IBGP peers";
796 break;
797 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
798 str = "Invalid limit for number of dynamic neighbors";
799 break;
800 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
801 str = "Dynamic neighbor listen range already exists";
802 break;
803 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
804 str = "Operation not allowed on a dynamic neighbor";
805 break;
806 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
807 str = "Operation not allowed on a directly connected neighbor";
808 break;
809 case BGP_ERR_PEER_SAFI_CONFLICT:
810 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
811 break;
812 case BGP_ERR_GR_INVALID_CMD:
813 str = "The Graceful Restart command used is not valid at this moment.";
814 break;
815 case BGP_ERR_GR_OPERATION_FAILED:
816 str = "The Graceful Restart Operation failed due to an err.";
817 break;
818 }
819 if (str) {
820 vty_out(vty, "%% %s\n", str);
821 return CMD_WARNING_CONFIG_FAILED;
822 }
823 return CMD_SUCCESS;
824 }
825
826 /* BGP clear sort. */
827 enum clear_sort {
828 clear_all,
829 clear_peer,
830 clear_group,
831 clear_external,
832 clear_as
833 };
834
835 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
836 safi_t safi, int error)
837 {
838 switch (error) {
839 case BGP_ERR_AF_UNCONFIGURED:
840 vty_out(vty,
841 "%%BGP: Enable %s address family for the neighbor %s\n",
842 get_afi_safi_str(afi, safi, false), peer->host);
843 break;
844 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
845 vty_out(vty,
846 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
847 peer->host);
848 break;
849 default:
850 break;
851 }
852 }
853
854 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
855 struct listnode **nnode, enum bgp_clear_type stype)
856 {
857 int ret = 0;
858 struct peer_af *paf;
859
860 /* if afi/.safi not specified, spin thru all of them */
861 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
862 afi_t tmp_afi;
863 safi_t tmp_safi;
864
865 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
866 paf = peer_af_find(peer, tmp_afi, tmp_safi);
867 if (paf && paf->subgroup)
868 SET_FLAG(paf->subgroup->sflags,
869 SUBGRP_STATUS_FORCE_UPDATES);
870
871 if (!peer->afc[tmp_afi][tmp_safi])
872 continue;
873
874 if (stype == BGP_CLEAR_SOFT_NONE)
875 ret = peer_clear(peer, nnode);
876 else
877 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
878 stype);
879 }
880 /* if afi specified and safi not, spin thru safis on this afi */
881 } else if (safi == SAFI_UNSPEC) {
882 safi_t tmp_safi;
883
884 for (tmp_safi = SAFI_UNICAST;
885 tmp_safi < SAFI_MAX; tmp_safi++) {
886 if (!peer->afc[afi][tmp_safi])
887 continue;
888
889 paf = peer_af_find(peer, afi, tmp_safi);
890 if (paf && paf->subgroup)
891 SET_FLAG(paf->subgroup->sflags,
892 SUBGRP_STATUS_FORCE_UPDATES);
893
894 if (stype == BGP_CLEAR_SOFT_NONE)
895 ret = peer_clear(peer, nnode);
896 else
897 ret = peer_clear_soft(peer, afi,
898 tmp_safi, stype);
899 }
900 /* both afi/safi specified, let the caller know if not defined */
901 } else {
902 if (!peer->afc[afi][safi])
903 return 1;
904
905 paf = peer_af_find(peer, afi, safi);
906 if (paf && paf->subgroup)
907 SET_FLAG(paf->subgroup->sflags,
908 SUBGRP_STATUS_FORCE_UPDATES);
909
910 if (stype == BGP_CLEAR_SOFT_NONE)
911 ret = peer_clear(peer, nnode);
912 else
913 ret = peer_clear_soft(peer, afi, safi, stype);
914 }
915
916 return ret;
917 }
918
919 /* `clear ip bgp' functions. */
920 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
921 enum clear_sort sort, enum bgp_clear_type stype,
922 const char *arg)
923 {
924 int ret = 0;
925 bool found = false;
926 struct peer *peer;
927
928 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
929
930 /* Clear all neighbors. */
931 /*
932 * Pass along pointer to next node to peer_clear() when walking all
933 * nodes on the BGP instance as that may get freed if it is a
934 * doppelganger
935 */
936 if (sort == clear_all) {
937 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
938
939 bgp_peer_gr_flags_update(peer);
940
941 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
942 gr_router_detected = true;
943
944 ret = bgp_peer_clear(peer, afi, safi, &nnode,
945 stype);
946
947 if (ret < 0)
948 bgp_clear_vty_error(vty, peer, afi, safi, ret);
949 }
950
951 if (gr_router_detected
952 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
953 bgp_zebra_send_capabilities(bgp, false);
954 } else if (!gr_router_detected
955 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
956 bgp_zebra_send_capabilities(bgp, true);
957 }
958
959 /* This is to apply read-only mode on this clear. */
960 if (stype == BGP_CLEAR_SOFT_NONE)
961 bgp->update_delay_over = 0;
962
963 return CMD_SUCCESS;
964 }
965
966 /* Clear specified neighbor. */
967 if (sort == clear_peer) {
968 union sockunion su;
969
970 /* Make sockunion for lookup. */
971 ret = str2sockunion(arg, &su);
972 if (ret < 0) {
973 peer = peer_lookup_by_conf_if(bgp, arg);
974 if (!peer) {
975 peer = peer_lookup_by_hostname(bgp, arg);
976 if (!peer) {
977 vty_out(vty,
978 "Malformed address or name: %s\n",
979 arg);
980 return CMD_WARNING;
981 }
982 }
983 } else {
984 peer = peer_lookup(bgp, &su);
985 if (!peer) {
986 vty_out(vty,
987 "%%BGP: Unknown neighbor - \"%s\"\n",
988 arg);
989 return CMD_WARNING;
990 }
991 }
992
993 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
994 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
995
996 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
997
998 /* if afi/safi not defined for this peer, let caller know */
999 if (ret == 1)
1000 ret = BGP_ERR_AF_UNCONFIGURED;
1001
1002 if (ret < 0)
1003 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1004
1005 return CMD_SUCCESS;
1006 }
1007
1008 /* Clear all neighbors belonging to a specific peer-group. */
1009 if (sort == clear_group) {
1010 struct peer_group *group;
1011
1012 group = peer_group_lookup(bgp, arg);
1013 if (!group) {
1014 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
1015 return CMD_WARNING;
1016 }
1017
1018 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1019 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1020
1021 if (ret < 0)
1022 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1023 else
1024 found = true;
1025 }
1026
1027 if (!found)
1028 vty_out(vty,
1029 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
1030 get_afi_safi_str(afi, safi, false), arg);
1031
1032 return CMD_SUCCESS;
1033 }
1034
1035 /* Clear all external (eBGP) neighbors. */
1036 if (sort == clear_external) {
1037 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1038 if (peer->sort == BGP_PEER_IBGP)
1039 continue;
1040
1041 bgp_peer_gr_flags_update(peer);
1042
1043 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1044 gr_router_detected = true;
1045
1046 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1047
1048 if (ret < 0)
1049 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1050 else
1051 found = true;
1052 }
1053
1054 if (gr_router_detected
1055 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1056 bgp_zebra_send_capabilities(bgp, false);
1057 } else if (!gr_router_detected
1058 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1059 bgp_zebra_send_capabilities(bgp, true);
1060 }
1061
1062 if (!found)
1063 vty_out(vty,
1064 "%%BGP: No external %s peer is configured\n",
1065 get_afi_safi_str(afi, safi, false));
1066
1067 return CMD_SUCCESS;
1068 }
1069
1070 /* Clear all neighbors belonging to a specific AS. */
1071 if (sort == clear_as) {
1072 as_t as = strtoul(arg, NULL, 10);
1073
1074 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1075 if (peer->as != as)
1076 continue;
1077
1078 bgp_peer_gr_flags_update(peer);
1079
1080 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1081 gr_router_detected = true;
1082
1083 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1084
1085 if (ret < 0)
1086 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1087 else
1088 found = true;
1089 }
1090
1091 if (gr_router_detected
1092 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1093 bgp_zebra_send_capabilities(bgp, false);
1094 } else if (!gr_router_detected
1095 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1096 bgp_zebra_send_capabilities(bgp, true);
1097 }
1098
1099 if (!found)
1100 vty_out(vty,
1101 "%%BGP: No %s peer is configured with AS %s\n",
1102 get_afi_safi_str(afi, safi, false), arg);
1103
1104 return CMD_SUCCESS;
1105 }
1106
1107 return CMD_SUCCESS;
1108 }
1109
1110 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1111 safi_t safi, enum clear_sort sort,
1112 enum bgp_clear_type stype, const char *arg)
1113 {
1114 struct bgp *bgp;
1115
1116 /* BGP structure lookup. */
1117 if (name) {
1118 bgp = bgp_lookup_by_name(name);
1119 if (bgp == NULL) {
1120 vty_out(vty, "Can't find BGP instance %s\n", name);
1121 return CMD_WARNING;
1122 }
1123 } else {
1124 bgp = bgp_get_default();
1125 if (bgp == NULL) {
1126 vty_out(vty, "No BGP process is configured\n");
1127 return CMD_WARNING;
1128 }
1129 }
1130
1131 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1132 }
1133
1134 /* clear soft inbound */
1135 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1136 {
1137 afi_t afi;
1138 safi_t safi;
1139
1140 FOREACH_AFI_SAFI (afi, safi)
1141 bgp_clear_vty(vty, name, afi, safi, clear_all,
1142 BGP_CLEAR_SOFT_IN, NULL);
1143 }
1144
1145 /* clear soft outbound */
1146 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1147 {
1148 afi_t afi;
1149 safi_t safi;
1150
1151 FOREACH_AFI_SAFI (afi, safi)
1152 bgp_clear_vty(vty, name, afi, safi, clear_all,
1153 BGP_CLEAR_SOFT_OUT, NULL);
1154 }
1155
1156
1157 #ifndef VTYSH_EXTRACT_PL
1158 #include "bgpd/bgp_vty_clippy.c"
1159 #endif
1160
1161 DEFUN_HIDDEN (bgp_local_mac,
1162 bgp_local_mac_cmd,
1163 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1164 BGP_STR
1165 "Local MAC config\n"
1166 "VxLAN Network Identifier\n"
1167 "VNI number\n"
1168 "local mac\n"
1169 "mac address\n"
1170 "mac-mobility sequence\n"
1171 "seq number\n")
1172 {
1173 int rv;
1174 vni_t vni;
1175 struct ethaddr mac;
1176 struct ipaddr ip;
1177 uint32_t seq;
1178 struct bgp *bgp;
1179
1180 vni = strtoul(argv[3]->arg, NULL, 10);
1181 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1182 vty_out(vty, "%% Malformed MAC address\n");
1183 return CMD_WARNING;
1184 }
1185 memset(&ip, 0, sizeof(ip));
1186 seq = strtoul(argv[7]->arg, NULL, 10);
1187
1188 bgp = bgp_get_default();
1189 if (!bgp) {
1190 vty_out(vty, "Default BGP instance is not there\n");
1191 return CMD_WARNING;
1192 }
1193
1194 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1195 zero_esi);
1196 if (rv < 0) {
1197 vty_out(vty, "Internal error\n");
1198 return CMD_WARNING;
1199 }
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 DEFUN_HIDDEN (no_bgp_local_mac,
1205 no_bgp_local_mac_cmd,
1206 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1207 NO_STR
1208 BGP_STR
1209 "Local MAC config\n"
1210 "VxLAN Network Identifier\n"
1211 "VNI number\n"
1212 "local mac\n"
1213 "mac address\n")
1214 {
1215 int rv;
1216 vni_t vni;
1217 struct ethaddr mac;
1218 struct ipaddr ip;
1219 struct bgp *bgp;
1220
1221 vni = strtoul(argv[4]->arg, NULL, 10);
1222 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1223 vty_out(vty, "%% Malformed MAC address\n");
1224 return CMD_WARNING;
1225 }
1226 memset(&ip, 0, sizeof(ip));
1227
1228 bgp = bgp_get_default();
1229 if (!bgp) {
1230 vty_out(vty, "Default BGP instance is not there\n");
1231 return CMD_WARNING;
1232 }
1233
1234 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1235 if (rv < 0) {
1236 vty_out(vty, "Internal error\n");
1237 return CMD_WARNING;
1238 }
1239
1240 return CMD_SUCCESS;
1241 }
1242
1243 DEFUN (no_synchronization,
1244 no_synchronization_cmd,
1245 "no synchronization",
1246 NO_STR
1247 "Perform IGP synchronization\n")
1248 {
1249 return CMD_SUCCESS;
1250 }
1251
1252 DEFUN (no_auto_summary,
1253 no_auto_summary_cmd,
1254 "no auto-summary",
1255 NO_STR
1256 "Enable automatic network number summarization\n")
1257 {
1258 return CMD_SUCCESS;
1259 }
1260
1261 /* "router bgp" commands. */
1262 DEFUN_NOSH (router_bgp,
1263 router_bgp_cmd,
1264 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1265 ROUTER_STR
1266 BGP_STR
1267 AS_STR
1268 BGP_INSTANCE_HELP_STR)
1269 {
1270 int idx_asn = 2;
1271 int idx_view_vrf = 3;
1272 int idx_vrf = 4;
1273 int is_new_bgp = 0;
1274 int ret;
1275 as_t as;
1276 struct bgp *bgp;
1277 const char *name = NULL;
1278 enum bgp_instance_type inst_type;
1279
1280 // "router bgp" without an ASN
1281 if (argc == 2) {
1282 // Pending: Make VRF option available for ASN less config
1283 bgp = bgp_get_default();
1284
1285 if (bgp == NULL) {
1286 vty_out(vty, "%% No BGP process is configured\n");
1287 return CMD_WARNING_CONFIG_FAILED;
1288 }
1289
1290 if (listcount(bm->bgp) > 1) {
1291 vty_out(vty, "%% Please specify ASN and VRF\n");
1292 return CMD_WARNING_CONFIG_FAILED;
1293 }
1294 }
1295
1296 // "router bgp X"
1297 else {
1298 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1299
1300 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1301 if (argc > 3) {
1302 name = argv[idx_vrf]->arg;
1303
1304 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1305 if (strmatch(name, VRF_DEFAULT_NAME))
1306 name = NULL;
1307 else
1308 inst_type = BGP_INSTANCE_TYPE_VRF;
1309 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1310 inst_type = BGP_INSTANCE_TYPE_VIEW;
1311 }
1312
1313 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1314 is_new_bgp = (bgp_lookup(as, name) == NULL);
1315
1316 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1317 switch (ret) {
1318 case BGP_ERR_AS_MISMATCH:
1319 vty_out(vty, "BGP is already running; AS is %u\n", as);
1320 return CMD_WARNING_CONFIG_FAILED;
1321 case BGP_ERR_INSTANCE_MISMATCH:
1322 vty_out(vty,
1323 "BGP instance name and AS number mismatch\n");
1324 vty_out(vty,
1325 "BGP instance is already running; AS is %u\n",
1326 as);
1327 return CMD_WARNING_CONFIG_FAILED;
1328 }
1329
1330 /*
1331 * If we just instantiated the default instance, complete
1332 * any pending VRF-VPN leaking that was configured via
1333 * earlier "router bgp X vrf FOO" blocks.
1334 */
1335 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1336 vpn_leak_postchange_all();
1337
1338 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1339 bgp_vpn_leak_export(bgp);
1340 /* Pending: handle when user tries to change a view to vrf n vv.
1341 */
1342 }
1343
1344 /* unset the auto created flag as the user config is now present */
1345 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1346 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1347
1348 return CMD_SUCCESS;
1349 }
1350
1351 /* "no router bgp" commands. */
1352 DEFUN (no_router_bgp,
1353 no_router_bgp_cmd,
1354 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1355 NO_STR
1356 ROUTER_STR
1357 BGP_STR
1358 AS_STR
1359 BGP_INSTANCE_HELP_STR)
1360 {
1361 int idx_asn = 3;
1362 int idx_vrf = 5;
1363 as_t as;
1364 struct bgp *bgp;
1365 const char *name = NULL;
1366
1367 // "no router bgp" without an ASN
1368 if (argc == 3) {
1369 // Pending: Make VRF option available for ASN less config
1370 bgp = bgp_get_default();
1371
1372 if (bgp == NULL) {
1373 vty_out(vty, "%% No BGP process is configured\n");
1374 return CMD_WARNING_CONFIG_FAILED;
1375 }
1376
1377 if (listcount(bm->bgp) > 1) {
1378 vty_out(vty, "%% Please specify ASN and VRF\n");
1379 return CMD_WARNING_CONFIG_FAILED;
1380 }
1381
1382 if (bgp->l3vni) {
1383 vty_out(vty, "%% Please unconfigure l3vni %u",
1384 bgp->l3vni);
1385 return CMD_WARNING_CONFIG_FAILED;
1386 }
1387 } else {
1388 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1389
1390 if (argc > 4)
1391 name = argv[idx_vrf]->arg;
1392
1393 /* Lookup bgp structure. */
1394 bgp = bgp_lookup(as, name);
1395 if (!bgp) {
1396 vty_out(vty, "%% Can't find BGP instance\n");
1397 return CMD_WARNING_CONFIG_FAILED;
1398 }
1399
1400 if (bgp->l3vni) {
1401 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1402 bgp->l3vni);
1403 return CMD_WARNING_CONFIG_FAILED;
1404 }
1405
1406 /* Cannot delete default instance if vrf instances exist */
1407 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1408 struct listnode *node;
1409 struct bgp *tmp_bgp;
1410
1411 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1412 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1413 continue;
1414 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1415 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1416 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1417 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1418 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1419 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1420 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1421 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1422 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1423 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1424 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1425 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1426 (bgp == bgp_get_evpn() &&
1427 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1428 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1429 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1430 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1431 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1432 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1433 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1434 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1435 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1436 vty_out(vty,
1437 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1438 return CMD_WARNING_CONFIG_FAILED;
1439 }
1440 }
1441 }
1442 }
1443
1444 bgp_delete(bgp);
1445
1446 return CMD_SUCCESS;
1447 }
1448
1449
1450 /* BGP router-id. */
1451
1452 DEFPY (bgp_router_id,
1453 bgp_router_id_cmd,
1454 "bgp router-id A.B.C.D",
1455 BGP_STR
1456 "Override configured router identifier\n"
1457 "Manually configured router identifier\n")
1458 {
1459 VTY_DECLVAR_CONTEXT(bgp, bgp);
1460 bgp_router_id_static_set(bgp, router_id);
1461 return CMD_SUCCESS;
1462 }
1463
1464 DEFPY (no_bgp_router_id,
1465 no_bgp_router_id_cmd,
1466 "no bgp router-id [A.B.C.D]",
1467 NO_STR
1468 BGP_STR
1469 "Override configured router identifier\n"
1470 "Manually configured router identifier\n")
1471 {
1472 VTY_DECLVAR_CONTEXT(bgp, bgp);
1473
1474 if (router_id_str) {
1475 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1476 vty_out(vty, "%% BGP router-id doesn't match\n");
1477 return CMD_WARNING_CONFIG_FAILED;
1478 }
1479 }
1480
1481 router_id.s_addr = 0;
1482 bgp_router_id_static_set(bgp, router_id);
1483
1484 return CMD_SUCCESS;
1485 }
1486
1487 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1488 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1489 NO_STR BGP_STR
1490 "Add community specific parameters\n"
1491 "Create an alias for a community\n"
1492 "Community (AA:BB or AA:BB:CC)\n"
1493 "Alias name\n")
1494 {
1495 struct community_alias ca1;
1496 struct community_alias ca2;
1497 struct community_alias *lookup_community;
1498 struct community_alias *lookup_alias;
1499
1500 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1501 vty_out(vty, "Invalid community format\n");
1502 return CMD_WARNING;
1503 }
1504
1505 memset(&ca1, 0, sizeof(ca1));
1506 memset(&ca2, 0, sizeof(ca2));
1507 strlcpy(ca1.community, community, sizeof(ca1.community));
1508 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
1509
1510 lookup_community = bgp_ca_community_lookup(&ca1);
1511 lookup_alias = bgp_ca_alias_lookup(&ca1);
1512
1513 if (no) {
1514 bgp_ca_alias_delete(&ca1);
1515 bgp_ca_community_delete(&ca1);
1516 } else {
1517 if (lookup_alias) {
1518 /* Lookup if community hash table has an item
1519 * with the same alias name.
1520 */
1521 strlcpy(ca2.community, lookup_alias->community,
1522 sizeof(ca2.community));
1523 if (bgp_ca_community_lookup(&ca2)) {
1524 vty_out(vty,
1525 "community (%s) already has this alias (%s)\n",
1526 lookup_alias->community,
1527 lookup_alias->alias);
1528 return CMD_WARNING;
1529 }
1530 bgp_ca_alias_delete(&ca1);
1531 }
1532
1533 if (lookup_community)
1534 bgp_ca_community_delete(&ca1);
1535
1536 bgp_ca_alias_insert(&ca1);
1537 bgp_ca_community_insert(&ca1);
1538 }
1539
1540 return CMD_SUCCESS;
1541 }
1542
1543 DEFPY (bgp_global_suppress_fib_pending,
1544 bgp_global_suppress_fib_pending_cmd,
1545 "[no] bgp suppress-fib-pending",
1546 NO_STR
1547 BGP_STR
1548 "Advertise only routes that are programmed in kernel to peers globally\n")
1549 {
1550 bm_wait_for_fib_set(!no);
1551
1552 return CMD_SUCCESS;
1553 }
1554
1555 DEFPY (bgp_suppress_fib_pending,
1556 bgp_suppress_fib_pending_cmd,
1557 "[no] bgp suppress-fib-pending",
1558 NO_STR
1559 BGP_STR
1560 "Advertise only routes that are programmed in kernel to peers\n")
1561 {
1562 VTY_DECLVAR_CONTEXT(bgp, bgp);
1563
1564 bgp_suppress_fib_pending_set(bgp, !no);
1565 return CMD_SUCCESS;
1566 }
1567
1568
1569 /* BGP Cluster ID. */
1570 DEFUN (bgp_cluster_id,
1571 bgp_cluster_id_cmd,
1572 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1573 BGP_STR
1574 "Configure Route-Reflector Cluster-id\n"
1575 "Route-Reflector Cluster-id in IP address format\n"
1576 "Route-Reflector Cluster-id as 32 bit quantity\n")
1577 {
1578 VTY_DECLVAR_CONTEXT(bgp, bgp);
1579 int idx_ipv4 = 2;
1580 int ret;
1581 struct in_addr cluster;
1582
1583 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1584 if (!ret) {
1585 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1586 return CMD_WARNING_CONFIG_FAILED;
1587 }
1588
1589 bgp_cluster_id_set(bgp, &cluster);
1590 bgp_clear_star_soft_out(vty, bgp->name);
1591
1592 return CMD_SUCCESS;
1593 }
1594
1595 DEFUN (no_bgp_cluster_id,
1596 no_bgp_cluster_id_cmd,
1597 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1598 NO_STR
1599 BGP_STR
1600 "Configure Route-Reflector Cluster-id\n"
1601 "Route-Reflector Cluster-id in IP address format\n"
1602 "Route-Reflector Cluster-id as 32 bit quantity\n")
1603 {
1604 VTY_DECLVAR_CONTEXT(bgp, bgp);
1605 bgp_cluster_id_unset(bgp);
1606 bgp_clear_star_soft_out(vty, bgp->name);
1607
1608 return CMD_SUCCESS;
1609 }
1610
1611 DEFPY (bgp_norib,
1612 bgp_norib_cmd,
1613 "bgp no-rib",
1614 BGP_STR
1615 "Disable BGP route installation to RIB (Zebra)\n")
1616 {
1617 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1618 vty_out(vty,
1619 "%% No-RIB option is already set, nothing to do here.\n");
1620 return CMD_SUCCESS;
1621 }
1622
1623 bgp_option_norib_set_runtime();
1624
1625 return CMD_SUCCESS;
1626 }
1627
1628 DEFPY (no_bgp_norib,
1629 no_bgp_norib_cmd,
1630 "no bgp no-rib",
1631 NO_STR
1632 BGP_STR
1633 "Disable BGP route installation to RIB (Zebra)\n")
1634 {
1635 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1636 vty_out(vty,
1637 "%% No-RIB option is not set, nothing to do here.\n");
1638 return CMD_SUCCESS;
1639 }
1640
1641 bgp_option_norib_unset_runtime();
1642
1643 return CMD_SUCCESS;
1644 }
1645
1646 DEFPY (no_bgp_send_extra_data,
1647 no_bgp_send_extra_data_cmd,
1648 "[no] bgp send-extra-data zebra",
1649 NO_STR
1650 BGP_STR
1651 "Extra data to Zebra for display/use\n"
1652 "To zebra\n")
1653 {
1654 if (no)
1655 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1656 else
1657 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1658
1659 return CMD_SUCCESS;
1660 }
1661
1662 DEFUN (bgp_confederation_identifier,
1663 bgp_confederation_identifier_cmd,
1664 "bgp confederation identifier (1-4294967295)",
1665 "BGP specific commands\n"
1666 "AS confederation parameters\n"
1667 "AS number\n"
1668 "Set routing domain confederation AS\n")
1669 {
1670 VTY_DECLVAR_CONTEXT(bgp, bgp);
1671 int idx_number = 3;
1672 as_t as;
1673
1674 as = strtoul(argv[idx_number]->arg, NULL, 10);
1675
1676 bgp_confederation_id_set(bgp, as);
1677
1678 return CMD_SUCCESS;
1679 }
1680
1681 DEFUN (no_bgp_confederation_identifier,
1682 no_bgp_confederation_identifier_cmd,
1683 "no bgp confederation identifier [(1-4294967295)]",
1684 NO_STR
1685 "BGP specific commands\n"
1686 "AS confederation parameters\n"
1687 "AS number\n"
1688 "Set routing domain confederation AS\n")
1689 {
1690 VTY_DECLVAR_CONTEXT(bgp, bgp);
1691 bgp_confederation_id_unset(bgp);
1692
1693 return CMD_SUCCESS;
1694 }
1695
1696 DEFUN (bgp_confederation_peers,
1697 bgp_confederation_peers_cmd,
1698 "bgp confederation peers (1-4294967295)...",
1699 "BGP specific commands\n"
1700 "AS confederation parameters\n"
1701 "Peer ASs in BGP confederation\n"
1702 AS_STR)
1703 {
1704 VTY_DECLVAR_CONTEXT(bgp, bgp);
1705 int idx_asn = 3;
1706 as_t as;
1707 int i;
1708
1709 for (i = idx_asn; i < argc; i++) {
1710 as = strtoul(argv[i]->arg, NULL, 10);
1711
1712 if (bgp->as == as) {
1713 vty_out(vty,
1714 "%% Local member-AS not allowed in confed peer list\n");
1715 continue;
1716 }
1717
1718 bgp_confederation_peers_add(bgp, as);
1719 }
1720 return CMD_SUCCESS;
1721 }
1722
1723 DEFUN (no_bgp_confederation_peers,
1724 no_bgp_confederation_peers_cmd,
1725 "no bgp confederation peers (1-4294967295)...",
1726 NO_STR
1727 "BGP specific commands\n"
1728 "AS confederation parameters\n"
1729 "Peer ASs in BGP confederation\n"
1730 AS_STR)
1731 {
1732 VTY_DECLVAR_CONTEXT(bgp, bgp);
1733 int idx_asn = 4;
1734 as_t as;
1735 int i;
1736
1737 for (i = idx_asn; i < argc; i++) {
1738 as = strtoul(argv[i]->arg, NULL, 10);
1739
1740 bgp_confederation_peers_remove(bgp, as);
1741 }
1742 return CMD_SUCCESS;
1743 }
1744
1745 /**
1746 * Central routine for maximum-paths configuration.
1747 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1748 * @set: 1 for setting values, 0 for removing the max-paths config.
1749 */
1750 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1751 const char *mpaths, uint16_t options,
1752 int set)
1753 {
1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1755 uint16_t maxpaths = 0;
1756 int ret;
1757 afi_t afi;
1758 safi_t safi;
1759
1760 afi = bgp_node_afi(vty);
1761 safi = bgp_node_safi(vty);
1762
1763 if (set) {
1764 maxpaths = strtol(mpaths, NULL, 10);
1765 if (maxpaths > multipath_num) {
1766 vty_out(vty,
1767 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1768 maxpaths, multipath_num);
1769 return CMD_WARNING_CONFIG_FAILED;
1770 }
1771 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1772 options);
1773 } else
1774 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1775
1776 if (ret < 0) {
1777 vty_out(vty,
1778 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1779 (set == 1) ? "" : "un",
1780 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1781 maxpaths, afi, safi);
1782 return CMD_WARNING_CONFIG_FAILED;
1783 }
1784
1785 bgp_recalculate_all_bestpaths(bgp);
1786
1787 return CMD_SUCCESS;
1788 }
1789
1790 DEFUN (bgp_maxmed_admin,
1791 bgp_maxmed_admin_cmd,
1792 "bgp max-med administrative ",
1793 BGP_STR
1794 "Advertise routes with max-med\n"
1795 "Administratively applied, for an indefinite period\n")
1796 {
1797 VTY_DECLVAR_CONTEXT(bgp, bgp);
1798
1799 bgp->v_maxmed_admin = 1;
1800 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1801
1802 bgp_maxmed_update(bgp);
1803
1804 return CMD_SUCCESS;
1805 }
1806
1807 DEFUN (bgp_maxmed_admin_medv,
1808 bgp_maxmed_admin_medv_cmd,
1809 "bgp max-med administrative (0-4294967295)",
1810 BGP_STR
1811 "Advertise routes with max-med\n"
1812 "Administratively applied, for an indefinite period\n"
1813 "Max MED value to be used\n")
1814 {
1815 VTY_DECLVAR_CONTEXT(bgp, bgp);
1816 int idx_number = 3;
1817
1818 bgp->v_maxmed_admin = 1;
1819 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1820
1821 bgp_maxmed_update(bgp);
1822
1823 return CMD_SUCCESS;
1824 }
1825
1826 DEFUN (no_bgp_maxmed_admin,
1827 no_bgp_maxmed_admin_cmd,
1828 "no bgp max-med administrative [(0-4294967295)]",
1829 NO_STR
1830 BGP_STR
1831 "Advertise routes with max-med\n"
1832 "Administratively applied, for an indefinite period\n"
1833 "Max MED value to be used\n")
1834 {
1835 VTY_DECLVAR_CONTEXT(bgp, bgp);
1836 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1837 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1838 bgp_maxmed_update(bgp);
1839
1840 return CMD_SUCCESS;
1841 }
1842
1843 DEFUN (bgp_maxmed_onstartup,
1844 bgp_maxmed_onstartup_cmd,
1845 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1846 BGP_STR
1847 "Advertise routes with max-med\n"
1848 "Effective on a startup\n"
1849 "Time (seconds) period for max-med\n"
1850 "Max MED value to be used\n")
1851 {
1852 VTY_DECLVAR_CONTEXT(bgp, bgp);
1853 int idx = 0;
1854
1855 argv_find(argv, argc, "(5-86400)", &idx);
1856 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1857 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1858 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1859 else
1860 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1861
1862 bgp_maxmed_update(bgp);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867 DEFUN (no_bgp_maxmed_onstartup,
1868 no_bgp_maxmed_onstartup_cmd,
1869 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1870 NO_STR
1871 BGP_STR
1872 "Advertise routes with max-med\n"
1873 "Effective on a startup\n"
1874 "Time (seconds) period for max-med\n"
1875 "Max MED value to be used\n")
1876 {
1877 VTY_DECLVAR_CONTEXT(bgp, bgp);
1878
1879 /* Cancel max-med onstartup if its on */
1880 if (bgp->t_maxmed_onstartup) {
1881 thread_cancel(&bgp->t_maxmed_onstartup);
1882 bgp->maxmed_onstartup_over = 1;
1883 }
1884
1885 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1886 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1887
1888 bgp_maxmed_update(bgp);
1889
1890 return CMD_SUCCESS;
1891 }
1892
1893 static int bgp_global_update_delay_config_vty(struct vty *vty,
1894 uint16_t update_delay,
1895 uint16_t establish_wait)
1896 {
1897 struct listnode *node, *nnode;
1898 struct bgp *bgp;
1899 bool vrf_cfg = false;
1900
1901 /*
1902 * See if update-delay is set per-vrf and warn user to delete it
1903 * Note that we only need to check this if this is the first time
1904 * setting the global config.
1905 */
1906 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1907 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1908 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1909 vty_out(vty,
1910 "%% update-delay configuration found in vrf %s\n",
1911 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1912 ? VRF_DEFAULT_NAME
1913 : bgp->name);
1914 vrf_cfg = true;
1915 }
1916 }
1917 }
1918
1919 if (vrf_cfg) {
1920 vty_out(vty,
1921 "%%Failed: global update-delay config not permitted\n");
1922 return CMD_WARNING;
1923 }
1924
1925 if (!establish_wait) { /* update-delay <delay> */
1926 bm->v_update_delay = update_delay;
1927 bm->v_establish_wait = bm->v_update_delay;
1928 } else {
1929 /* update-delay <delay> <establish-wait> */
1930 if (update_delay < establish_wait) {
1931 vty_out(vty,
1932 "%%Failed: update-delay less than the establish-wait!\n");
1933 return CMD_WARNING_CONFIG_FAILED;
1934 }
1935
1936 bm->v_update_delay = update_delay;
1937 bm->v_establish_wait = establish_wait;
1938 }
1939
1940 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1941 bgp->v_update_delay = bm->v_update_delay;
1942 bgp->v_establish_wait = bm->v_establish_wait;
1943 }
1944
1945 return CMD_SUCCESS;
1946 }
1947
1948 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1949 {
1950 struct listnode *node, *nnode;
1951 struct bgp *bgp;
1952
1953 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1954 bm->v_establish_wait = bm->v_update_delay;
1955
1956 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1957 bgp->v_update_delay = bm->v_update_delay;
1958 bgp->v_establish_wait = bm->v_establish_wait;
1959 }
1960
1961 return CMD_SUCCESS;
1962 }
1963
1964 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1965 uint16_t establish_wait)
1966 {
1967 VTY_DECLVAR_CONTEXT(bgp, bgp);
1968
1969 /* if configured globally, per-instance config is not allowed */
1970 if (bm->v_update_delay) {
1971 vty_out(vty,
1972 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1973 return CMD_WARNING_CONFIG_FAILED;
1974 }
1975
1976
1977 if (!establish_wait) /* update-delay <delay> */
1978 {
1979 bgp->v_update_delay = update_delay;
1980 bgp->v_establish_wait = bgp->v_update_delay;
1981 return CMD_SUCCESS;
1982 }
1983
1984 /* update-delay <delay> <establish-wait> */
1985 if (update_delay < establish_wait) {
1986 vty_out(vty,
1987 "%%Failed: update-delay less than the establish-wait!\n");
1988 return CMD_WARNING_CONFIG_FAILED;
1989 }
1990
1991 bgp->v_update_delay = update_delay;
1992 bgp->v_establish_wait = establish_wait;
1993
1994 return CMD_SUCCESS;
1995 }
1996
1997 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1998 {
1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000
2001 /* If configured globally, cannot remove from one bgp instance */
2002 if (bm->v_update_delay) {
2003 vty_out(vty,
2004 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2005 return CMD_WARNING_CONFIG_FAILED;
2006 }
2007 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2008 bgp->v_establish_wait = bgp->v_update_delay;
2009
2010 return CMD_SUCCESS;
2011 }
2012
2013 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2014 {
2015 /* If configured globally, no need to display per-instance value */
2016 if (bgp->v_update_delay != bm->v_update_delay) {
2017 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2018 if (bgp->v_update_delay != bgp->v_establish_wait)
2019 vty_out(vty, " %d", bgp->v_establish_wait);
2020 vty_out(vty, "\n");
2021 }
2022 }
2023
2024 /* Global update-delay configuration */
2025 DEFPY (bgp_global_update_delay,
2026 bgp_global_update_delay_cmd,
2027 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2028 BGP_STR
2029 "Force initial delay for best-path and updates for all bgp instances\n"
2030 "Max delay in seconds\n"
2031 "Establish wait in seconds\n")
2032 {
2033 return bgp_global_update_delay_config_vty(vty, delay, wait);
2034 }
2035
2036 /* Global update-delay deconfiguration */
2037 DEFPY (no_bgp_global_update_delay,
2038 no_bgp_global_update_delay_cmd,
2039 "no bgp update-delay [(0-3600) [(1-3600)]]",
2040 NO_STR
2041 BGP_STR
2042 "Force initial delay for best-path and updates\n"
2043 "Max delay in seconds\n"
2044 "Establish wait in seconds\n")
2045 {
2046 return bgp_global_update_delay_deconfig_vty(vty);
2047 }
2048
2049 /* Update-delay configuration */
2050
2051 DEFPY (bgp_update_delay,
2052 bgp_update_delay_cmd,
2053 "update-delay (0-3600)$delay [(1-3600)$wait]",
2054 "Force initial delay for best-path and updates\n"
2055 "Max delay in seconds\n"
2056 "Establish wait in seconds\n")
2057 {
2058 return bgp_update_delay_config_vty(vty, delay, wait);
2059 }
2060
2061 /* Update-delay deconfiguration */
2062 DEFPY (no_bgp_update_delay,
2063 no_bgp_update_delay_cmd,
2064 "no update-delay [(0-3600) [(1-3600)]]",
2065 NO_STR
2066 "Force initial delay for best-path and updates\n"
2067 "Max delay in seconds\n"
2068 "Establish wait in seconds\n")
2069 {
2070 return bgp_update_delay_deconfig_vty(vty);
2071 }
2072
2073
2074 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2075 bool set)
2076 {
2077 VTY_DECLVAR_CONTEXT(bgp, bgp);
2078
2079 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2080 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2081
2082 return CMD_SUCCESS;
2083 }
2084
2085 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2086 bool set)
2087 {
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2091 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2092
2093 return CMD_SUCCESS;
2094 }
2095
2096 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2097 {
2098 uint32_t quanta =
2099 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2100 if (quanta != BGP_WRITE_PACKET_MAX)
2101 vty_out(vty, " write-quanta %d\n", quanta);
2102 }
2103
2104 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2105 {
2106 uint32_t quanta =
2107 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2108 if (quanta != BGP_READ_PACKET_MAX)
2109 vty_out(vty, " read-quanta %d\n", quanta);
2110 }
2111
2112 /* Packet quanta configuration
2113 *
2114 * XXX: The value set here controls the size of a stack buffer in the IO
2115 * thread. When changing these limits be careful to prevent stack overflow.
2116 *
2117 * Furthermore, the maximums used here should correspond to
2118 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2119 */
2120 DEFPY (bgp_wpkt_quanta,
2121 bgp_wpkt_quanta_cmd,
2122 "[no] write-quanta (1-64)$quanta",
2123 NO_STR
2124 "How many packets to write to peer socket per run\n"
2125 "Number of packets\n")
2126 {
2127 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2128 }
2129
2130 DEFPY (bgp_rpkt_quanta,
2131 bgp_rpkt_quanta_cmd,
2132 "[no] read-quanta (1-10)$quanta",
2133 NO_STR
2134 "How many packets to read from peer socket per I/O cycle\n"
2135 "Number of packets\n")
2136 {
2137 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2138 }
2139
2140 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2141 {
2142 if (!bgp->heuristic_coalesce)
2143 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2144 }
2145
2146
2147 DEFUN (bgp_coalesce_time,
2148 bgp_coalesce_time_cmd,
2149 "coalesce-time (0-4294967295)",
2150 "Subgroup coalesce timer\n"
2151 "Subgroup coalesce timer value (in ms)\n")
2152 {
2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
2154
2155 int idx = 0;
2156 argv_find(argv, argc, "(0-4294967295)", &idx);
2157 bgp->heuristic_coalesce = false;
2158 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2159 return CMD_SUCCESS;
2160 }
2161
2162 DEFUN (no_bgp_coalesce_time,
2163 no_bgp_coalesce_time_cmd,
2164 "no coalesce-time (0-4294967295)",
2165 NO_STR
2166 "Subgroup coalesce timer\n"
2167 "Subgroup coalesce timer value (in ms)\n")
2168 {
2169 VTY_DECLVAR_CONTEXT(bgp, bgp);
2170
2171 bgp->heuristic_coalesce = true;
2172 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2173 return CMD_SUCCESS;
2174 }
2175
2176 /* Maximum-paths configuration */
2177 DEFUN (bgp_maxpaths,
2178 bgp_maxpaths_cmd,
2179 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2180 "Forward packets over multiple paths\n"
2181 "Number of paths\n")
2182 {
2183 int idx_number = 1;
2184 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2185 argv[idx_number]->arg, 0, 1);
2186 }
2187
2188 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2189 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2190 "Forward packets over multiple paths\n"
2191 "Number of paths\n")
2192
2193 DEFUN (bgp_maxpaths_ibgp,
2194 bgp_maxpaths_ibgp_cmd,
2195 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2196 "Forward packets over multiple paths\n"
2197 "iBGP-multipath\n"
2198 "Number of paths\n")
2199 {
2200 int idx_number = 2;
2201 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2202 argv[idx_number]->arg, 0, 1);
2203 }
2204
2205 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2206 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2207 "Forward packets over multiple paths\n"
2208 "iBGP-multipath\n"
2209 "Number of paths\n")
2210
2211 DEFUN (bgp_maxpaths_ibgp_cluster,
2212 bgp_maxpaths_ibgp_cluster_cmd,
2213 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2214 "Forward packets over multiple paths\n"
2215 "iBGP-multipath\n"
2216 "Number of paths\n"
2217 "Match the cluster length\n")
2218 {
2219 int idx_number = 2;
2220 return bgp_maxpaths_config_vty(
2221 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2222 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
2223 }
2224
2225 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2226 "maximum-paths ibgp " CMD_RANGE_STR(
2227 1, MULTIPATH_NUM) " equal-cluster-length",
2228 "Forward packets over multiple paths\n"
2229 "iBGP-multipath\n"
2230 "Number of paths\n"
2231 "Match the cluster length\n")
2232
2233 DEFUN (no_bgp_maxpaths,
2234 no_bgp_maxpaths_cmd,
2235 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2236 NO_STR
2237 "Forward packets over multiple paths\n"
2238 "Number of paths\n")
2239 {
2240 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2241 }
2242
2243 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2244 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2245 "Forward packets over multiple paths\n"
2246 "Number of paths\n")
2247
2248 DEFUN (no_bgp_maxpaths_ibgp,
2249 no_bgp_maxpaths_ibgp_cmd,
2250 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2251 NO_STR
2252 "Forward packets over multiple paths\n"
2253 "iBGP-multipath\n"
2254 "Number of paths\n"
2255 "Match the cluster length\n")
2256 {
2257 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2258 }
2259
2260 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2261 "no maximum-paths ibgp [" CMD_RANGE_STR(
2262 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2263 NO_STR
2264 "Forward packets over multiple paths\n"
2265 "iBGP-multipath\n"
2266 "Number of paths\n"
2267 "Match the cluster length\n")
2268
2269 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2270 afi_t afi, safi_t safi)
2271 {
2272 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2273 vty_out(vty, " maximum-paths %d\n",
2274 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2275 }
2276
2277 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2278 vty_out(vty, " maximum-paths ibgp %d",
2279 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2280 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2281 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2282 vty_out(vty, " equal-cluster-length");
2283 vty_out(vty, "\n");
2284 }
2285 }
2286
2287 /* BGP timers. */
2288
2289 DEFUN (bgp_timers,
2290 bgp_timers_cmd,
2291 "timers bgp (0-65535) (0-65535)",
2292 "Adjust routing timers\n"
2293 "BGP timers\n"
2294 "Keepalive interval\n"
2295 "Holdtime\n")
2296 {
2297 VTY_DECLVAR_CONTEXT(bgp, bgp);
2298 int idx_number = 2;
2299 int idx_number_2 = 3;
2300 unsigned long keepalive = 0;
2301 unsigned long holdtime = 0;
2302
2303 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2304 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2305
2306 /* Holdtime value check. */
2307 if (holdtime < 3 && holdtime != 0) {
2308 vty_out(vty,
2309 "%% hold time value must be either 0 or greater than 3\n");
2310 return CMD_WARNING_CONFIG_FAILED;
2311 }
2312
2313 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2314 BGP_DEFAULT_DELAYOPEN);
2315
2316 return CMD_SUCCESS;
2317 }
2318
2319 DEFUN (no_bgp_timers,
2320 no_bgp_timers_cmd,
2321 "no timers bgp [(0-65535) (0-65535)]",
2322 NO_STR
2323 "Adjust routing timers\n"
2324 "BGP timers\n"
2325 "Keepalive interval\n"
2326 "Holdtime\n")
2327 {
2328 VTY_DECLVAR_CONTEXT(bgp, bgp);
2329 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2330 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2331
2332 return CMD_SUCCESS;
2333 }
2334
2335
2336 DEFUN (bgp_client_to_client_reflection,
2337 bgp_client_to_client_reflection_cmd,
2338 "bgp client-to-client reflection",
2339 "BGP specific commands\n"
2340 "Configure client to client route reflection\n"
2341 "reflection of routes allowed\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2345 bgp_clear_star_soft_out(vty, bgp->name);
2346
2347 return CMD_SUCCESS;
2348 }
2349
2350 DEFUN (no_bgp_client_to_client_reflection,
2351 no_bgp_client_to_client_reflection_cmd,
2352 "no bgp client-to-client reflection",
2353 NO_STR
2354 "BGP specific commands\n"
2355 "Configure client to client route reflection\n"
2356 "reflection of routes allowed\n")
2357 {
2358 VTY_DECLVAR_CONTEXT(bgp, bgp);
2359 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2360 bgp_clear_star_soft_out(vty, bgp->name);
2361
2362 return CMD_SUCCESS;
2363 }
2364
2365 /* "bgp always-compare-med" configuration. */
2366 DEFUN (bgp_always_compare_med,
2367 bgp_always_compare_med_cmd,
2368 "bgp always-compare-med",
2369 "BGP specific commands\n"
2370 "Allow comparing MED from different neighbors\n")
2371 {
2372 VTY_DECLVAR_CONTEXT(bgp, bgp);
2373 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2374 bgp_recalculate_all_bestpaths(bgp);
2375
2376 return CMD_SUCCESS;
2377 }
2378
2379 DEFUN (no_bgp_always_compare_med,
2380 no_bgp_always_compare_med_cmd,
2381 "no bgp always-compare-med",
2382 NO_STR
2383 "BGP specific commands\n"
2384 "Allow comparing MED from different neighbors\n")
2385 {
2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2388 bgp_recalculate_all_bestpaths(bgp);
2389
2390 return CMD_SUCCESS;
2391 }
2392
2393
2394 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2395 "bgp ebgp-requires-policy",
2396 "BGP specific commands\n"
2397 "Require in and out policy for eBGP peers (RFC8212)\n")
2398 {
2399 VTY_DECLVAR_CONTEXT(bgp, bgp);
2400 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2401 return CMD_SUCCESS;
2402 }
2403
2404 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2405 "no bgp ebgp-requires-policy",
2406 NO_STR
2407 "BGP specific commands\n"
2408 "Require in and out policy for eBGP peers (RFC8212)\n")
2409 {
2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2412 return CMD_SUCCESS;
2413 }
2414
2415 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2416 "bgp suppress-duplicates",
2417 "BGP specific commands\n"
2418 "Suppress duplicate updates if the route actually not changed\n")
2419 {
2420 VTY_DECLVAR_CONTEXT(bgp, bgp);
2421 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2422 return CMD_SUCCESS;
2423 }
2424
2425 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2426 "no bgp suppress-duplicates",
2427 NO_STR
2428 "BGP specific commands\n"
2429 "Suppress duplicate updates if the route actually not changed\n")
2430 {
2431 VTY_DECLVAR_CONTEXT(bgp, bgp);
2432 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2433 return CMD_SUCCESS;
2434 }
2435
2436 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2437 "bgp reject-as-sets",
2438 "BGP specific commands\n"
2439 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2440 {
2441 VTY_DECLVAR_CONTEXT(bgp, bgp);
2442 struct listnode *node, *nnode;
2443 struct peer *peer;
2444
2445 bgp->reject_as_sets = true;
2446
2447 /* Reset existing BGP sessions to reject routes
2448 * with aspath containing AS_SET or AS_CONFED_SET.
2449 */
2450 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2451 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2452 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2453 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2454 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2455 }
2456 }
2457
2458 return CMD_SUCCESS;
2459 }
2460
2461 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2462 "no bgp reject-as-sets",
2463 NO_STR
2464 "BGP specific commands\n"
2465 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2466 {
2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 struct listnode *node, *nnode;
2469 struct peer *peer;
2470
2471 bgp->reject_as_sets = false;
2472
2473 /* Reset existing BGP sessions to reject routes
2474 * with aspath containing AS_SET or AS_CONFED_SET.
2475 */
2476 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2477 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2478 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2479 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2480 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2481 }
2482 }
2483
2484 return CMD_SUCCESS;
2485 }
2486
2487 /* "bgp deterministic-med" configuration. */
2488 DEFUN (bgp_deterministic_med,
2489 bgp_deterministic_med_cmd,
2490 "bgp deterministic-med",
2491 "BGP specific commands\n"
2492 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2493 {
2494 VTY_DECLVAR_CONTEXT(bgp, bgp);
2495
2496 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2497 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2498 bgp_recalculate_all_bestpaths(bgp);
2499 }
2500
2501 return CMD_SUCCESS;
2502 }
2503
2504 DEFUN (no_bgp_deterministic_med,
2505 no_bgp_deterministic_med_cmd,
2506 "no bgp deterministic-med",
2507 NO_STR
2508 "BGP specific commands\n"
2509 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2510 {
2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 int bestpath_per_as_used;
2513 afi_t afi;
2514 safi_t safi;
2515 struct peer *peer;
2516 struct listnode *node, *nnode;
2517
2518 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2519 bestpath_per_as_used = 0;
2520
2521 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2522 FOREACH_AFI_SAFI (afi, safi)
2523 if (bgp_addpath_dmed_required(
2524 peer->addpath_type[afi][safi])) {
2525 bestpath_per_as_used = 1;
2526 break;
2527 }
2528
2529 if (bestpath_per_as_used)
2530 break;
2531 }
2532
2533 if (bestpath_per_as_used) {
2534 vty_out(vty,
2535 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2536 return CMD_WARNING_CONFIG_FAILED;
2537 } else {
2538 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2539 bgp_recalculate_all_bestpaths(bgp);
2540 }
2541 }
2542
2543 return CMD_SUCCESS;
2544 }
2545
2546 /* "bgp graceful-restart mode" configuration. */
2547 DEFUN (bgp_graceful_restart,
2548 bgp_graceful_restart_cmd,
2549 "bgp graceful-restart",
2550 "BGP specific commands\n"
2551 GR_CMD
2552 )
2553 {
2554 int ret = BGP_GR_FAILURE;
2555
2556 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2557 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2558
2559 VTY_DECLVAR_CONTEXT(bgp, bgp);
2560
2561 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2562
2563 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2564 ret);
2565
2566 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2567 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2568 vty_out(vty,
2569 "Graceful restart configuration changed, reset all peers to take effect\n");
2570 return bgp_vty_return(vty, ret);
2571 }
2572
2573 DEFUN (no_bgp_graceful_restart,
2574 no_bgp_graceful_restart_cmd,
2575 "no bgp graceful-restart",
2576 NO_STR
2577 "BGP specific commands\n"
2578 NO_GR_CMD
2579 )
2580 {
2581 VTY_DECLVAR_CONTEXT(bgp, bgp);
2582
2583 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2584 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2585
2586 int ret = BGP_GR_FAILURE;
2587
2588 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2589
2590 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2591 ret);
2592
2593 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2594 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2595 vty_out(vty,
2596 "Graceful restart configuration changed, reset all peers to take effect\n");
2597
2598 return bgp_vty_return(vty, ret);
2599 }
2600
2601 DEFUN (bgp_graceful_restart_stalepath_time,
2602 bgp_graceful_restart_stalepath_time_cmd,
2603 "bgp graceful-restart stalepath-time (1-4095)",
2604 "BGP specific commands\n"
2605 "Graceful restart capability parameters\n"
2606 "Set the max time to hold onto restarting peer's stale paths\n"
2607 "Delay value (seconds)\n")
2608 {
2609 VTY_DECLVAR_CONTEXT(bgp, bgp);
2610 int idx_number = 3;
2611 uint32_t stalepath;
2612
2613 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2614 bgp->stalepath_time = stalepath;
2615 return CMD_SUCCESS;
2616 }
2617
2618 DEFUN (bgp_graceful_restart_restart_time,
2619 bgp_graceful_restart_restart_time_cmd,
2620 "bgp graceful-restart restart-time (1-4095)",
2621 "BGP specific commands\n"
2622 "Graceful restart capability parameters\n"
2623 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2624 "Delay value (seconds)\n")
2625 {
2626 VTY_DECLVAR_CONTEXT(bgp, bgp);
2627 int idx_number = 3;
2628 uint32_t restart;
2629
2630 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2631 bgp->restart_time = restart;
2632 return CMD_SUCCESS;
2633 }
2634
2635 DEFUN (bgp_graceful_restart_select_defer_time,
2636 bgp_graceful_restart_select_defer_time_cmd,
2637 "bgp graceful-restart select-defer-time (0-3600)",
2638 "BGP specific commands\n"
2639 "Graceful restart capability parameters\n"
2640 "Set the time to defer the BGP route selection after restart\n"
2641 "Delay value (seconds, 0 - disable)\n")
2642 {
2643 VTY_DECLVAR_CONTEXT(bgp, bgp);
2644 int idx_number = 3;
2645 uint32_t defer_time;
2646
2647 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2648 bgp->select_defer_time = defer_time;
2649 if (defer_time == 0)
2650 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2651 else
2652 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2653
2654 return CMD_SUCCESS;
2655 }
2656
2657 DEFUN (no_bgp_graceful_restart_stalepath_time,
2658 no_bgp_graceful_restart_stalepath_time_cmd,
2659 "no bgp graceful-restart stalepath-time [(1-4095)]",
2660 NO_STR
2661 "BGP specific commands\n"
2662 "Graceful restart capability parameters\n"
2663 "Set the max time to hold onto restarting peer's stale paths\n"
2664 "Delay value (seconds)\n")
2665 {
2666 VTY_DECLVAR_CONTEXT(bgp, bgp);
2667
2668 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2669 return CMD_SUCCESS;
2670 }
2671
2672 DEFUN (no_bgp_graceful_restart_restart_time,
2673 no_bgp_graceful_restart_restart_time_cmd,
2674 "no bgp graceful-restart restart-time [(1-4095)]",
2675 NO_STR
2676 "BGP specific commands\n"
2677 "Graceful restart capability parameters\n"
2678 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2679 "Delay value (seconds)\n")
2680 {
2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
2682
2683 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2684 return CMD_SUCCESS;
2685 }
2686
2687 DEFUN (no_bgp_graceful_restart_select_defer_time,
2688 no_bgp_graceful_restart_select_defer_time_cmd,
2689 "no bgp graceful-restart select-defer-time [(0-3600)]",
2690 NO_STR
2691 "BGP specific commands\n"
2692 "Graceful restart capability parameters\n"
2693 "Set the time to defer the BGP route selection after restart\n"
2694 "Delay value (seconds)\n")
2695 {
2696 VTY_DECLVAR_CONTEXT(bgp, bgp);
2697
2698 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2699 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2700
2701 return CMD_SUCCESS;
2702 }
2703
2704 DEFUN (bgp_graceful_restart_preserve_fw,
2705 bgp_graceful_restart_preserve_fw_cmd,
2706 "bgp graceful-restart preserve-fw-state",
2707 "BGP specific commands\n"
2708 "Graceful restart capability parameters\n"
2709 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2710 {
2711 VTY_DECLVAR_CONTEXT(bgp, bgp);
2712 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2713 return CMD_SUCCESS;
2714 }
2715
2716 DEFUN (no_bgp_graceful_restart_preserve_fw,
2717 no_bgp_graceful_restart_preserve_fw_cmd,
2718 "no bgp graceful-restart preserve-fw-state",
2719 NO_STR
2720 "BGP specific commands\n"
2721 "Graceful restart capability parameters\n"
2722 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2723 {
2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
2725 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2726 return CMD_SUCCESS;
2727 }
2728
2729 DEFUN (bgp_graceful_restart_disable,
2730 bgp_graceful_restart_disable_cmd,
2731 "bgp graceful-restart-disable",
2732 "BGP specific commands\n"
2733 GR_DISABLE)
2734 {
2735 int ret = BGP_GR_FAILURE;
2736
2737 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2738 zlog_debug(
2739 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2740
2741 VTY_DECLVAR_CONTEXT(bgp, bgp);
2742
2743 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2744
2745 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2746 bgp->peer, ret);
2747
2748 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2749 zlog_debug(
2750 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2751 vty_out(vty,
2752 "Graceful restart configuration changed, reset all peers to take effect\n");
2753
2754 return bgp_vty_return(vty, ret);
2755 }
2756
2757 DEFUN (no_bgp_graceful_restart_disable,
2758 no_bgp_graceful_restart_disable_cmd,
2759 "no bgp graceful-restart-disable",
2760 NO_STR
2761 "BGP specific commands\n"
2762 NO_GR_DISABLE
2763 )
2764 {
2765 VTY_DECLVAR_CONTEXT(bgp, bgp);
2766
2767 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2768 zlog_debug(
2769 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2770
2771 int ret = BGP_GR_FAILURE;
2772
2773 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2774
2775 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2776 ret);
2777
2778 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2779 zlog_debug(
2780 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2781 vty_out(vty,
2782 "Graceful restart configuration changed, reset all peers to take effect\n");
2783
2784 return bgp_vty_return(vty, ret);
2785 }
2786
2787 DEFUN (bgp_neighbor_graceful_restart_set,
2788 bgp_neighbor_graceful_restart_set_cmd,
2789 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2790 NEIGHBOR_STR
2791 NEIGHBOR_ADDR_STR2
2792 GR_NEIGHBOR_CMD
2793 )
2794 {
2795 int idx_peer = 1;
2796 struct peer *peer;
2797 int ret = BGP_GR_FAILURE;
2798
2799 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2800
2801 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2802 zlog_debug(
2803 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2804
2805 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2806 if (!peer)
2807 return CMD_WARNING_CONFIG_FAILED;
2808
2809 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2810
2811 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2812 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2813
2814 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2815 zlog_debug(
2816 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2817 vty_out(vty,
2818 "Graceful restart configuration changed, reset this peer to take effect\n");
2819
2820 return bgp_vty_return(vty, ret);
2821 }
2822
2823 DEFUN (no_bgp_neighbor_graceful_restart,
2824 no_bgp_neighbor_graceful_restart_set_cmd,
2825 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2826 NO_STR
2827 NEIGHBOR_STR
2828 NEIGHBOR_ADDR_STR2
2829 NO_GR_NEIGHBOR_CMD
2830 )
2831 {
2832 int idx_peer = 2;
2833 int ret = BGP_GR_FAILURE;
2834 struct peer *peer;
2835
2836 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2837
2838 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2839 if (!peer)
2840 return CMD_WARNING_CONFIG_FAILED;
2841
2842 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2843 zlog_debug(
2844 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2845
2846 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2847
2848 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2849 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2850
2851 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2852 zlog_debug(
2853 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2854 vty_out(vty,
2855 "Graceful restart configuration changed, reset this peer to take effect\n");
2856
2857 return bgp_vty_return(vty, ret);
2858 }
2859
2860 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2861 bgp_neighbor_graceful_restart_helper_set_cmd,
2862 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2863 NEIGHBOR_STR
2864 NEIGHBOR_ADDR_STR2
2865 GR_NEIGHBOR_HELPER_CMD
2866 )
2867 {
2868 int idx_peer = 1;
2869 struct peer *peer;
2870 int ret = BGP_GR_FAILURE;
2871
2872 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2873
2874 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2875 zlog_debug(
2876 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2877
2878 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2879
2880 if (!peer)
2881 return CMD_WARNING_CONFIG_FAILED;
2882
2883
2884 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
2885
2886 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2887 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2888
2889 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2890 zlog_debug(
2891 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2892 vty_out(vty,
2893 "Graceful restart configuration changed, reset this peer to take effect\n");
2894
2895 return bgp_vty_return(vty, ret);
2896 }
2897
2898 DEFUN (no_bgp_neighbor_graceful_restart_helper,
2899 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2900 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2901 NO_STR
2902 NEIGHBOR_STR
2903 NEIGHBOR_ADDR_STR2
2904 NO_GR_NEIGHBOR_HELPER_CMD
2905 )
2906 {
2907 int idx_peer = 2;
2908 int ret = BGP_GR_FAILURE;
2909 struct peer *peer;
2910
2911 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2912
2913 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2914 if (!peer)
2915 return CMD_WARNING_CONFIG_FAILED;
2916
2917 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2918 zlog_debug(
2919 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2920
2921 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
2922
2923 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2924 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2925
2926 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2927 zlog_debug(
2928 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2929 vty_out(vty,
2930 "Graceful restart configuration changed, reset this peer to take effect\n");
2931
2932 return bgp_vty_return(vty, ret);
2933 }
2934
2935 DEFUN (bgp_neighbor_graceful_restart_disable_set,
2936 bgp_neighbor_graceful_restart_disable_set_cmd,
2937 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2938 NEIGHBOR_STR
2939 NEIGHBOR_ADDR_STR2
2940 GR_NEIGHBOR_DISABLE_CMD
2941 )
2942 {
2943 int idx_peer = 1;
2944 struct peer *peer;
2945 int ret = BGP_GR_FAILURE;
2946
2947 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2948
2949 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2950 zlog_debug(
2951 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2952
2953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2954 if (!peer)
2955 return CMD_WARNING_CONFIG_FAILED;
2956
2957 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
2958
2959 if (peer->bgp->t_startup)
2960 bgp_peer_gr_flags_update(peer);
2961
2962 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2963 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2964
2965 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2966 zlog_debug(
2967 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
2968 vty_out(vty,
2969 "Graceful restart configuration changed, reset this peer to take effect\n");
2970
2971 return bgp_vty_return(vty, ret);
2972 }
2973
2974 DEFUN (no_bgp_neighbor_graceful_restart_disable,
2975 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2976 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2977 NO_STR
2978 NEIGHBOR_STR
2979 NEIGHBOR_ADDR_STR2
2980 NO_GR_NEIGHBOR_DISABLE_CMD
2981 )
2982 {
2983 int idx_peer = 2;
2984 int ret = BGP_GR_FAILURE;
2985 struct peer *peer;
2986
2987 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2988
2989 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2990 if (!peer)
2991 return CMD_WARNING_CONFIG_FAILED;
2992
2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2995 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
2996
2997 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2998
2999 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3000 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3001
3002 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3003 zlog_debug(
3004 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3005 vty_out(vty,
3006 "Graceful restart configuration changed, reset this peer to take effect\n");
3007
3008 return bgp_vty_return(vty, ret);
3009 }
3010
3011 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3012 bgp_graceful_restart_disable_eor_cmd,
3013 "bgp graceful-restart disable-eor",
3014 "BGP specific commands\n"
3015 "Graceful restart configuration parameters\n"
3016 "Disable EOR Check\n")
3017 {
3018 VTY_DECLVAR_CONTEXT(bgp, bgp);
3019 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3020
3021 return CMD_SUCCESS;
3022 }
3023
3024 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3025 no_bgp_graceful_restart_disable_eor_cmd,
3026 "no bgp graceful-restart disable-eor",
3027 NO_STR
3028 "BGP specific commands\n"
3029 "Graceful restart configuration parameters\n"
3030 "Disable EOR Check\n")
3031 {
3032 VTY_DECLVAR_CONTEXT(bgp, bgp);
3033 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3034
3035 return CMD_SUCCESS;
3036 }
3037
3038 DEFUN (bgp_graceful_restart_rib_stale_time,
3039 bgp_graceful_restart_rib_stale_time_cmd,
3040 "bgp graceful-restart rib-stale-time (1-3600)",
3041 "BGP specific commands\n"
3042 "Graceful restart configuration parameters\n"
3043 "Specify the stale route removal timer in rib\n"
3044 "Delay value (seconds)\n")
3045 {
3046 VTY_DECLVAR_CONTEXT(bgp, bgp);
3047 int idx_number = 3;
3048 uint32_t stale_time;
3049
3050 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3051 bgp->rib_stale_time = stale_time;
3052 /* Send the stale timer update message to RIB */
3053 if (bgp_zebra_stale_timer_update(bgp))
3054 return CMD_WARNING;
3055
3056 return CMD_SUCCESS;
3057 }
3058
3059 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3060 no_bgp_graceful_restart_rib_stale_time_cmd,
3061 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3062 NO_STR
3063 "BGP specific commands\n"
3064 "Graceful restart configuration parameters\n"
3065 "Specify the stale route removal timer in rib\n"
3066 "Delay value (seconds)\n")
3067 {
3068 VTY_DECLVAR_CONTEXT(bgp, bgp);
3069
3070 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3071 /* Send the stale timer update message to RIB */
3072 if (bgp_zebra_stale_timer_update(bgp))
3073 return CMD_WARNING;
3074
3075 return CMD_SUCCESS;
3076 }
3077
3078 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3079 struct bgp *bgp)
3080 {
3081 bgp_static_redo_import_check(bgp);
3082 bgp_redistribute_redo(bgp);
3083 bgp_clear_star_soft_out(vty, bgp->name);
3084 bgp_clear_star_soft_in(vty, bgp->name);
3085 }
3086
3087 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3088 {
3089 struct listnode *node, *nnode;
3090 struct bgp *bgp;
3091 bool vrf_cfg = false;
3092
3093 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3094 return CMD_SUCCESS;
3095
3096 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3097 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3098 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3099 vty_out(vty,
3100 "%% graceful-shutdown configuration found in vrf %s\n",
3101 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3102 VRF_DEFAULT_NAME : bgp->name);
3103 vrf_cfg = true;
3104 }
3105 }
3106
3107 if (vrf_cfg) {
3108 vty_out(vty,
3109 "%%Failed: global graceful-shutdown not permitted\n");
3110 return CMD_WARNING;
3111 }
3112
3113 /* Set flag globally */
3114 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3115
3116 /* Initiate processing for all BGP instances. */
3117 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3118 bgp_initiate_graceful_shut_unshut(vty, bgp);
3119
3120 return CMD_SUCCESS;
3121 }
3122
3123 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3124 {
3125 struct listnode *node, *nnode;
3126 struct bgp *bgp;
3127
3128 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3129 return CMD_SUCCESS;
3130
3131 /* Unset flag globally */
3132 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3133
3134 /* Initiate processing for all BGP instances. */
3135 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3136 bgp_initiate_graceful_shut_unshut(vty, bgp);
3137
3138 return CMD_SUCCESS;
3139 }
3140
3141 /* "bgp graceful-shutdown" configuration */
3142 DEFUN (bgp_graceful_shutdown,
3143 bgp_graceful_shutdown_cmd,
3144 "bgp graceful-shutdown",
3145 BGP_STR
3146 "Graceful shutdown parameters\n")
3147 {
3148 if (vty->node == CONFIG_NODE)
3149 return bgp_global_graceful_shutdown_config_vty(vty);
3150
3151 VTY_DECLVAR_CONTEXT(bgp, bgp);
3152
3153 /* if configured globally, per-instance config is not allowed */
3154 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3155 vty_out(vty,
3156 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3157 return CMD_WARNING_CONFIG_FAILED;
3158 }
3159
3160 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3161 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3162 bgp_initiate_graceful_shut_unshut(vty, bgp);
3163 }
3164
3165 return CMD_SUCCESS;
3166 }
3167
3168 DEFUN (no_bgp_graceful_shutdown,
3169 no_bgp_graceful_shutdown_cmd,
3170 "no bgp graceful-shutdown",
3171 NO_STR
3172 BGP_STR
3173 "Graceful shutdown parameters\n")
3174 {
3175 if (vty->node == CONFIG_NODE)
3176 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3177
3178 VTY_DECLVAR_CONTEXT(bgp, bgp);
3179
3180 /* If configured globally, cannot remove from one bgp instance */
3181 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3182 vty_out(vty,
3183 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3184 return CMD_WARNING_CONFIG_FAILED;
3185 }
3186
3187 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3188 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3189 bgp_initiate_graceful_shut_unshut(vty, bgp);
3190 }
3191
3192 return CMD_SUCCESS;
3193 }
3194
3195 /* "bgp fast-external-failover" configuration. */
3196 DEFUN (bgp_fast_external_failover,
3197 bgp_fast_external_failover_cmd,
3198 "bgp fast-external-failover",
3199 BGP_STR
3200 "Immediately reset session if a link to a directly connected external peer goes down\n")
3201 {
3202 VTY_DECLVAR_CONTEXT(bgp, bgp);
3203 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3204 return CMD_SUCCESS;
3205 }
3206
3207 DEFUN (no_bgp_fast_external_failover,
3208 no_bgp_fast_external_failover_cmd,
3209 "no bgp fast-external-failover",
3210 NO_STR
3211 BGP_STR
3212 "Immediately reset session if a link to a directly connected external peer goes down\n")
3213 {
3214 VTY_DECLVAR_CONTEXT(bgp, bgp);
3215 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3216 return CMD_SUCCESS;
3217 }
3218
3219 /* "bgp bestpath compare-routerid" configuration. */
3220 DEFUN (bgp_bestpath_compare_router_id,
3221 bgp_bestpath_compare_router_id_cmd,
3222 "bgp bestpath compare-routerid",
3223 "BGP specific commands\n"
3224 "Change the default bestpath selection\n"
3225 "Compare router-id for identical EBGP paths\n")
3226 {
3227 VTY_DECLVAR_CONTEXT(bgp, bgp);
3228 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3229 bgp_recalculate_all_bestpaths(bgp);
3230
3231 return CMD_SUCCESS;
3232 }
3233
3234 DEFUN (no_bgp_bestpath_compare_router_id,
3235 no_bgp_bestpath_compare_router_id_cmd,
3236 "no bgp bestpath compare-routerid",
3237 NO_STR
3238 "BGP specific commands\n"
3239 "Change the default bestpath selection\n"
3240 "Compare router-id for identical EBGP paths\n")
3241 {
3242 VTY_DECLVAR_CONTEXT(bgp, bgp);
3243 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3244 bgp_recalculate_all_bestpaths(bgp);
3245
3246 return CMD_SUCCESS;
3247 }
3248
3249 /* "bgp bestpath as-path ignore" configuration. */
3250 DEFUN (bgp_bestpath_aspath_ignore,
3251 bgp_bestpath_aspath_ignore_cmd,
3252 "bgp bestpath as-path ignore",
3253 "BGP specific commands\n"
3254 "Change the default bestpath selection\n"
3255 "AS-path attribute\n"
3256 "Ignore as-path length in selecting a route\n")
3257 {
3258 VTY_DECLVAR_CONTEXT(bgp, bgp);
3259 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3260 bgp_recalculate_all_bestpaths(bgp);
3261
3262 return CMD_SUCCESS;
3263 }
3264
3265 DEFUN (no_bgp_bestpath_aspath_ignore,
3266 no_bgp_bestpath_aspath_ignore_cmd,
3267 "no bgp bestpath as-path ignore",
3268 NO_STR
3269 "BGP specific commands\n"
3270 "Change the default bestpath selection\n"
3271 "AS-path attribute\n"
3272 "Ignore as-path length in selecting a route\n")
3273 {
3274 VTY_DECLVAR_CONTEXT(bgp, bgp);
3275 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3276 bgp_recalculate_all_bestpaths(bgp);
3277
3278 return CMD_SUCCESS;
3279 }
3280
3281 /* "bgp bestpath as-path confed" configuration. */
3282 DEFUN (bgp_bestpath_aspath_confed,
3283 bgp_bestpath_aspath_confed_cmd,
3284 "bgp bestpath as-path confed",
3285 "BGP specific commands\n"
3286 "Change the default bestpath selection\n"
3287 "AS-path attribute\n"
3288 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3289 {
3290 VTY_DECLVAR_CONTEXT(bgp, bgp);
3291 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3292 bgp_recalculate_all_bestpaths(bgp);
3293
3294 return CMD_SUCCESS;
3295 }
3296
3297 DEFUN (no_bgp_bestpath_aspath_confed,
3298 no_bgp_bestpath_aspath_confed_cmd,
3299 "no bgp bestpath as-path confed",
3300 NO_STR
3301 "BGP specific commands\n"
3302 "Change the default bestpath selection\n"
3303 "AS-path attribute\n"
3304 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3305 {
3306 VTY_DECLVAR_CONTEXT(bgp, bgp);
3307 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3308 bgp_recalculate_all_bestpaths(bgp);
3309
3310 return CMD_SUCCESS;
3311 }
3312
3313 /* "bgp bestpath as-path multipath-relax" configuration. */
3314 DEFUN (bgp_bestpath_aspath_multipath_relax,
3315 bgp_bestpath_aspath_multipath_relax_cmd,
3316 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3317 "BGP specific commands\n"
3318 "Change the default bestpath selection\n"
3319 "AS-path attribute\n"
3320 "Allow load sharing across routes that have different AS paths (but same length)\n"
3321 "Generate an AS_SET\n"
3322 "Do not generate an AS_SET\n")
3323 {
3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
3325 int idx = 0;
3326 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3327
3328 /* no-as-set is now the default behavior so we can silently
3329 * ignore it */
3330 if (argv_find(argv, argc, "as-set", &idx))
3331 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3332 else
3333 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3334
3335 bgp_recalculate_all_bestpaths(bgp);
3336
3337 return CMD_SUCCESS;
3338 }
3339
3340 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3341 no_bgp_bestpath_aspath_multipath_relax_cmd,
3342 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3343 NO_STR
3344 "BGP specific commands\n"
3345 "Change the default bestpath selection\n"
3346 "AS-path attribute\n"
3347 "Allow load sharing across routes that have different AS paths (but same length)\n"
3348 "Generate an AS_SET\n"
3349 "Do not generate an AS_SET\n")
3350 {
3351 VTY_DECLVAR_CONTEXT(bgp, bgp);
3352 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3353 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3354 bgp_recalculate_all_bestpaths(bgp);
3355
3356 return CMD_SUCCESS;
3357 }
3358
3359 /* "bgp bestpath peer-type multipath-relax" configuration. */
3360 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3361 bgp_bestpath_peer_type_multipath_relax_cmd,
3362 "bgp bestpath peer-type multipath-relax",
3363 BGP_STR
3364 "Change the default bestpath selection\n"
3365 "Peer type\n"
3366 "Allow load sharing across routes learned from different peer types\n")
3367 {
3368 VTY_DECLVAR_CONTEXT(bgp, bgp);
3369 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3370 bgp_recalculate_all_bestpaths(bgp);
3371
3372 return CMD_SUCCESS;
3373 }
3374
3375 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3376 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3377 "no bgp bestpath peer-type multipath-relax",
3378 NO_STR BGP_STR
3379 "Change the default bestpath selection\n"
3380 "Peer type\n"
3381 "Allow load sharing across routes learned from different peer types\n")
3382 {
3383 VTY_DECLVAR_CONTEXT(bgp, bgp);
3384 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3385 bgp_recalculate_all_bestpaths(bgp);
3386
3387 return CMD_SUCCESS;
3388 }
3389
3390 /* "bgp log-neighbor-changes" configuration. */
3391 DEFUN (bgp_log_neighbor_changes,
3392 bgp_log_neighbor_changes_cmd,
3393 "bgp log-neighbor-changes",
3394 "BGP specific commands\n"
3395 "Log neighbor up/down and reset reason\n")
3396 {
3397 VTY_DECLVAR_CONTEXT(bgp, bgp);
3398 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3399 return CMD_SUCCESS;
3400 }
3401
3402 DEFUN (no_bgp_log_neighbor_changes,
3403 no_bgp_log_neighbor_changes_cmd,
3404 "no bgp log-neighbor-changes",
3405 NO_STR
3406 "BGP specific commands\n"
3407 "Log neighbor up/down and reset reason\n")
3408 {
3409 VTY_DECLVAR_CONTEXT(bgp, bgp);
3410 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3411 return CMD_SUCCESS;
3412 }
3413
3414 /* "bgp bestpath med" configuration. */
3415 DEFUN (bgp_bestpath_med,
3416 bgp_bestpath_med_cmd,
3417 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3418 "BGP specific commands\n"
3419 "Change the default bestpath selection\n"
3420 "MED attribute\n"
3421 "Compare MED among confederation paths\n"
3422 "Treat missing MED as the least preferred one\n"
3423 "Treat missing MED as the least preferred one\n"
3424 "Compare MED among confederation paths\n")
3425 {
3426 VTY_DECLVAR_CONTEXT(bgp, bgp);
3427
3428 int idx = 0;
3429 if (argv_find(argv, argc, "confed", &idx))
3430 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3431 idx = 0;
3432 if (argv_find(argv, argc, "missing-as-worst", &idx))
3433 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3434
3435 bgp_recalculate_all_bestpaths(bgp);
3436
3437 return CMD_SUCCESS;
3438 }
3439
3440 DEFUN (no_bgp_bestpath_med,
3441 no_bgp_bestpath_med_cmd,
3442 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3443 NO_STR
3444 "BGP specific commands\n"
3445 "Change the default bestpath selection\n"
3446 "MED attribute\n"
3447 "Compare MED among confederation paths\n"
3448 "Treat missing MED as the least preferred one\n"
3449 "Treat missing MED as the least preferred one\n"
3450 "Compare MED among confederation paths\n")
3451 {
3452 VTY_DECLVAR_CONTEXT(bgp, bgp);
3453
3454 int idx = 0;
3455 if (argv_find(argv, argc, "confed", &idx))
3456 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3457 idx = 0;
3458 if (argv_find(argv, argc, "missing-as-worst", &idx))
3459 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3460
3461 bgp_recalculate_all_bestpaths(bgp);
3462
3463 return CMD_SUCCESS;
3464 }
3465
3466 /* "bgp bestpath bandwidth" configuration. */
3467 DEFPY (bgp_bestpath_bw,
3468 bgp_bestpath_bw_cmd,
3469 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3470 "BGP specific commands\n"
3471 "Change the default bestpath selection\n"
3472 "Link Bandwidth attribute\n"
3473 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3474 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3475 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3476 {
3477 VTY_DECLVAR_CONTEXT(bgp, bgp);
3478 afi_t afi;
3479 safi_t safi;
3480
3481 if (!bw_cfg) {
3482 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3483 return CMD_ERR_INCOMPLETE;
3484 }
3485 if (!strcmp(bw_cfg, "ignore"))
3486 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3487 else if (!strcmp(bw_cfg, "skip-missing"))
3488 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3489 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3490 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3491 else
3492 return CMD_ERR_NO_MATCH;
3493
3494 /* This config is used in route install, so redo that. */
3495 FOREACH_AFI_SAFI (afi, safi) {
3496 if (!bgp_fibupd_safi(safi))
3497 continue;
3498 bgp_zebra_announce_table(bgp, afi, safi);
3499 }
3500
3501 return CMD_SUCCESS;
3502 }
3503
3504 DEFPY (no_bgp_bestpath_bw,
3505 no_bgp_bestpath_bw_cmd,
3506 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3507 NO_STR
3508 "BGP specific commands\n"
3509 "Change the default bestpath selection\n"
3510 "Link Bandwidth attribute\n"
3511 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3512 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3513 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3514 {
3515 VTY_DECLVAR_CONTEXT(bgp, bgp);
3516 afi_t afi;
3517 safi_t safi;
3518
3519 bgp->lb_handling = BGP_LINK_BW_ECMP;
3520
3521 /* This config is used in route install, so redo that. */
3522 FOREACH_AFI_SAFI (afi, safi) {
3523 if (!bgp_fibupd_safi(safi))
3524 continue;
3525 bgp_zebra_announce_table(bgp, afi, safi);
3526 }
3527 return CMD_SUCCESS;
3528 }
3529
3530 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3531 "[no] bgp default <ipv4-unicast|"
3532 "ipv4-multicast|"
3533 "ipv4-vpn|"
3534 "ipv4-labeled-unicast|"
3535 "ipv4-flowspec|"
3536 "ipv6-unicast|"
3537 "ipv6-multicast|"
3538 "ipv6-vpn|"
3539 "ipv6-labeled-unicast|"
3540 "ipv6-flowspec|"
3541 "l2vpn-evpn>$afi_safi",
3542 NO_STR
3543 "BGP specific commands\n"
3544 "Configure BGP defaults\n"
3545 "Activate ipv4-unicast for a peer by default\n"
3546 "Activate ipv4-multicast for a peer by default\n"
3547 "Activate ipv4-vpn for a peer by default\n"
3548 "Activate ipv4-labeled-unicast for a peer by default\n"
3549 "Activate ipv4-flowspec for a peer by default\n"
3550 "Activate ipv6-unicast for a peer by default\n"
3551 "Activate ipv6-multicast for a peer by default\n"
3552 "Activate ipv6-vpn for a peer by default\n"
3553 "Activate ipv6-labeled-unicast for a peer by default\n"
3554 "Activate ipv6-flowspec for a peer by default\n"
3555 "Activate l2vpn-evpn for a peer by default\n")
3556 {
3557 VTY_DECLVAR_CONTEXT(bgp, bgp);
3558 char afi_safi_str[strlen(afi_safi) + 1];
3559 char *afi_safi_str_tok;
3560
3561 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3562 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3563 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3564 afi_t afi = bgp_vty_afi_from_str(afi_str);
3565 safi_t safi;
3566
3567 if (strmatch(safi_str, "labeled"))
3568 safi = bgp_vty_safi_from_str("labeled-unicast");
3569 else
3570 safi = bgp_vty_safi_from_str(safi_str);
3571
3572 if (no)
3573 bgp->default_af[afi][safi] = false;
3574 else {
3575 if ((safi == SAFI_LABELED_UNICAST
3576 && bgp->default_af[afi][SAFI_UNICAST])
3577 || (safi == SAFI_UNICAST
3578 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3579 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3580 else
3581 bgp->default_af[afi][safi] = true;
3582 }
3583
3584 return CMD_SUCCESS;
3585 }
3586
3587 /* Display hostname in certain command outputs */
3588 DEFUN (bgp_default_show_hostname,
3589 bgp_default_show_hostname_cmd,
3590 "bgp default show-hostname",
3591 "BGP specific commands\n"
3592 "Configure BGP defaults\n"
3593 "Show hostname in certain command outputs\n")
3594 {
3595 VTY_DECLVAR_CONTEXT(bgp, bgp);
3596 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3597 return CMD_SUCCESS;
3598 }
3599
3600 DEFUN (no_bgp_default_show_hostname,
3601 no_bgp_default_show_hostname_cmd,
3602 "no bgp default show-hostname",
3603 NO_STR
3604 "BGP specific commands\n"
3605 "Configure BGP defaults\n"
3606 "Show hostname in certain command outputs\n")
3607 {
3608 VTY_DECLVAR_CONTEXT(bgp, bgp);
3609 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3610 return CMD_SUCCESS;
3611 }
3612
3613 /* Display hostname in certain command outputs */
3614 DEFUN (bgp_default_show_nexthop_hostname,
3615 bgp_default_show_nexthop_hostname_cmd,
3616 "bgp default show-nexthop-hostname",
3617 "BGP specific commands\n"
3618 "Configure BGP defaults\n"
3619 "Show hostname for nexthop in certain command outputs\n")
3620 {
3621 VTY_DECLVAR_CONTEXT(bgp, bgp);
3622 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3623 return CMD_SUCCESS;
3624 }
3625
3626 DEFUN (no_bgp_default_show_nexthop_hostname,
3627 no_bgp_default_show_nexthop_hostname_cmd,
3628 "no bgp default show-nexthop-hostname",
3629 NO_STR
3630 "BGP specific commands\n"
3631 "Configure BGP defaults\n"
3632 "Show hostname for nexthop in certain command outputs\n")
3633 {
3634 VTY_DECLVAR_CONTEXT(bgp, bgp);
3635 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3636 return CMD_SUCCESS;
3637 }
3638
3639 /* "bgp network import-check" configuration. */
3640 DEFUN (bgp_network_import_check,
3641 bgp_network_import_check_cmd,
3642 "bgp network import-check",
3643 "BGP specific commands\n"
3644 "BGP network command\n"
3645 "Check BGP network route exists in IGP\n")
3646 {
3647 VTY_DECLVAR_CONTEXT(bgp, bgp);
3648 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3649 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3650 bgp_static_redo_import_check(bgp);
3651 }
3652
3653 return CMD_SUCCESS;
3654 }
3655
3656 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3657 "bgp network import-check exact",
3658 "BGP specific commands\n"
3659 "BGP network command\n"
3660 "Check BGP network route exists in IGP\n"
3661 "Match route precisely\n")
3662
3663 DEFUN (no_bgp_network_import_check,
3664 no_bgp_network_import_check_cmd,
3665 "no bgp network import-check",
3666 NO_STR
3667 "BGP specific commands\n"
3668 "BGP network command\n"
3669 "Check BGP network route exists in IGP\n")
3670 {
3671 VTY_DECLVAR_CONTEXT(bgp, bgp);
3672 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3673 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3674 bgp_static_redo_import_check(bgp);
3675 }
3676
3677 return CMD_SUCCESS;
3678 }
3679
3680 DEFUN (bgp_default_local_preference,
3681 bgp_default_local_preference_cmd,
3682 "bgp default local-preference (0-4294967295)",
3683 "BGP specific commands\n"
3684 "Configure BGP defaults\n"
3685 "local preference (higher=more preferred)\n"
3686 "Configure default local preference value\n")
3687 {
3688 VTY_DECLVAR_CONTEXT(bgp, bgp);
3689 int idx_number = 3;
3690 uint32_t local_pref;
3691
3692 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3693
3694 bgp_default_local_preference_set(bgp, local_pref);
3695 bgp_clear_star_soft_in(vty, bgp->name);
3696
3697 return CMD_SUCCESS;
3698 }
3699
3700 DEFUN (no_bgp_default_local_preference,
3701 no_bgp_default_local_preference_cmd,
3702 "no bgp default local-preference [(0-4294967295)]",
3703 NO_STR
3704 "BGP specific commands\n"
3705 "Configure BGP defaults\n"
3706 "local preference (higher=more preferred)\n"
3707 "Configure default local preference value\n")
3708 {
3709 VTY_DECLVAR_CONTEXT(bgp, bgp);
3710 bgp_default_local_preference_unset(bgp);
3711 bgp_clear_star_soft_in(vty, bgp->name);
3712
3713 return CMD_SUCCESS;
3714 }
3715
3716
3717 DEFUN (bgp_default_subgroup_pkt_queue_max,
3718 bgp_default_subgroup_pkt_queue_max_cmd,
3719 "bgp default subgroup-pkt-queue-max (20-100)",
3720 "BGP specific commands\n"
3721 "Configure BGP defaults\n"
3722 "subgroup-pkt-queue-max\n"
3723 "Configure subgroup packet queue max\n")
3724 {
3725 VTY_DECLVAR_CONTEXT(bgp, bgp);
3726 int idx_number = 3;
3727 uint32_t max_size;
3728
3729 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3730
3731 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3732
3733 return CMD_SUCCESS;
3734 }
3735
3736 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3737 no_bgp_default_subgroup_pkt_queue_max_cmd,
3738 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3739 NO_STR
3740 "BGP specific commands\n"
3741 "Configure BGP defaults\n"
3742 "subgroup-pkt-queue-max\n"
3743 "Configure subgroup packet queue max\n")
3744 {
3745 VTY_DECLVAR_CONTEXT(bgp, bgp);
3746 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3747 return CMD_SUCCESS;
3748 }
3749
3750
3751 DEFUN (bgp_rr_allow_outbound_policy,
3752 bgp_rr_allow_outbound_policy_cmd,
3753 "bgp route-reflector allow-outbound-policy",
3754 "BGP specific commands\n"
3755 "Allow modifications made by out route-map\n"
3756 "on ibgp neighbors\n")
3757 {
3758 VTY_DECLVAR_CONTEXT(bgp, bgp);
3759
3760 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3761 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3762 update_group_announce_rrclients(bgp);
3763 bgp_clear_star_soft_out(vty, bgp->name);
3764 }
3765
3766 return CMD_SUCCESS;
3767 }
3768
3769 DEFUN (no_bgp_rr_allow_outbound_policy,
3770 no_bgp_rr_allow_outbound_policy_cmd,
3771 "no bgp route-reflector allow-outbound-policy",
3772 NO_STR
3773 "BGP specific commands\n"
3774 "Allow modifications made by out route-map\n"
3775 "on ibgp neighbors\n")
3776 {
3777 VTY_DECLVAR_CONTEXT(bgp, bgp);
3778
3779 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3780 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3781 update_group_announce_rrclients(bgp);
3782 bgp_clear_star_soft_out(vty, bgp->name);
3783 }
3784
3785 return CMD_SUCCESS;
3786 }
3787
3788 DEFUN (bgp_listen_limit,
3789 bgp_listen_limit_cmd,
3790 "bgp listen limit (1-65535)",
3791 "BGP specific commands\n"
3792 "BGP Dynamic Neighbors listen commands\n"
3793 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3794 "Configure Dynamic Neighbors listen limit value\n")
3795 {
3796 VTY_DECLVAR_CONTEXT(bgp, bgp);
3797 int idx_number = 3;
3798 int listen_limit;
3799
3800 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
3801
3802 bgp_listen_limit_set(bgp, listen_limit);
3803
3804 return CMD_SUCCESS;
3805 }
3806
3807 DEFUN (no_bgp_listen_limit,
3808 no_bgp_listen_limit_cmd,
3809 "no bgp listen limit [(1-65535)]",
3810 NO_STR
3811 "BGP specific commands\n"
3812 "BGP Dynamic Neighbors listen commands\n"
3813 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3814 "Configure Dynamic Neighbors listen limit value\n")
3815 {
3816 VTY_DECLVAR_CONTEXT(bgp, bgp);
3817 bgp_listen_limit_unset(bgp);
3818 return CMD_SUCCESS;
3819 }
3820
3821
3822 /*
3823 * Check if this listen range is already configured. Check for exact
3824 * match or overlap based on input.
3825 */
3826 static struct peer_group *listen_range_exists(struct bgp *bgp,
3827 struct prefix *range, int exact)
3828 {
3829 struct listnode *node, *nnode;
3830 struct listnode *node1, *nnode1;
3831 struct peer_group *group;
3832 struct prefix *lr;
3833 afi_t afi;
3834 int match;
3835
3836 afi = family2afi(range->family);
3837 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3838 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3839 lr)) {
3840 if (exact)
3841 match = prefix_same(range, lr);
3842 else
3843 match = (prefix_match(range, lr)
3844 || prefix_match(lr, range));
3845 if (match)
3846 return group;
3847 }
3848 }
3849
3850 return NULL;
3851 }
3852
3853 DEFUN (bgp_listen_range,
3854 bgp_listen_range_cmd,
3855 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3856 "BGP specific commands\n"
3857 "Configure BGP dynamic neighbors listen range\n"
3858 "Configure BGP dynamic neighbors listen range\n"
3859 NEIGHBOR_ADDR_STR
3860 "Member of the peer-group\n"
3861 "Peer-group name\n")
3862 {
3863 VTY_DECLVAR_CONTEXT(bgp, bgp);
3864 struct prefix range;
3865 struct peer_group *group, *existing_group;
3866 afi_t afi;
3867 int ret;
3868 int idx = 0;
3869
3870 argv_find(argv, argc, "A.B.C.D/M", &idx);
3871 argv_find(argv, argc, "X:X::X:X/M", &idx);
3872 char *prefix = argv[idx]->arg;
3873 argv_find(argv, argc, "PGNAME", &idx);
3874 char *peergroup = argv[idx]->arg;
3875
3876 /* Convert IP prefix string to struct prefix. */
3877 ret = str2prefix(prefix, &range);
3878 if (!ret) {
3879 vty_out(vty, "%% Malformed listen range\n");
3880 return CMD_WARNING_CONFIG_FAILED;
3881 }
3882
3883 afi = family2afi(range.family);
3884
3885 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3886 vty_out(vty,
3887 "%% Malformed listen range (link-local address)\n");
3888 return CMD_WARNING_CONFIG_FAILED;
3889 }
3890
3891 apply_mask(&range);
3892
3893 /* Check if same listen range is already configured. */
3894 existing_group = listen_range_exists(bgp, &range, 1);
3895 if (existing_group) {
3896 if (strcmp(existing_group->name, peergroup) == 0)
3897 return CMD_SUCCESS;
3898 else {
3899 vty_out(vty,
3900 "%% Same listen range is attached to peer-group %s\n",
3901 existing_group->name);
3902 return CMD_WARNING_CONFIG_FAILED;
3903 }
3904 }
3905
3906 /* Check if an overlapping listen range exists. */
3907 if (listen_range_exists(bgp, &range, 0)) {
3908 vty_out(vty,
3909 "%% Listen range overlaps with existing listen range\n");
3910 return CMD_WARNING_CONFIG_FAILED;
3911 }
3912
3913 group = peer_group_lookup(bgp, peergroup);
3914 if (!group) {
3915 vty_out(vty, "%% Configure the peer-group first\n");
3916 return CMD_WARNING_CONFIG_FAILED;
3917 }
3918
3919 ret = peer_group_listen_range_add(group, &range);
3920 return bgp_vty_return(vty, ret);
3921 }
3922
3923 DEFUN (no_bgp_listen_range,
3924 no_bgp_listen_range_cmd,
3925 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3926 NO_STR
3927 "BGP specific commands\n"
3928 "Unconfigure BGP dynamic neighbors listen range\n"
3929 "Unconfigure BGP dynamic neighbors listen range\n"
3930 NEIGHBOR_ADDR_STR
3931 "Member of the peer-group\n"
3932 "Peer-group name\n")
3933 {
3934 VTY_DECLVAR_CONTEXT(bgp, bgp);
3935 struct prefix range;
3936 struct peer_group *group;
3937 afi_t afi;
3938 int ret;
3939 int idx = 0;
3940
3941 argv_find(argv, argc, "A.B.C.D/M", &idx);
3942 argv_find(argv, argc, "X:X::X:X/M", &idx);
3943 char *prefix = argv[idx]->arg;
3944 argv_find(argv, argc, "PGNAME", &idx);
3945 char *peergroup = argv[idx]->arg;
3946
3947 /* Convert IP prefix string to struct prefix. */
3948 ret = str2prefix(prefix, &range);
3949 if (!ret) {
3950 vty_out(vty, "%% Malformed listen range\n");
3951 return CMD_WARNING_CONFIG_FAILED;
3952 }
3953
3954 afi = family2afi(range.family);
3955
3956 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3957 vty_out(vty,
3958 "%% Malformed listen range (link-local address)\n");
3959 return CMD_WARNING_CONFIG_FAILED;
3960 }
3961
3962 apply_mask(&range);
3963
3964 group = peer_group_lookup(bgp, peergroup);
3965 if (!group) {
3966 vty_out(vty, "%% Peer-group does not exist\n");
3967 return CMD_WARNING_CONFIG_FAILED;
3968 }
3969
3970 ret = peer_group_listen_range_del(group, &range);
3971 return bgp_vty_return(vty, ret);
3972 }
3973
3974 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
3975 {
3976 struct peer_group *group;
3977 struct listnode *node, *nnode, *rnode, *nrnode;
3978 struct prefix *range;
3979 afi_t afi;
3980
3981 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3982 vty_out(vty, " bgp listen limit %d\n",
3983 bgp->dynamic_neighbors_limit);
3984
3985 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3986 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3987 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3988 nrnode, range)) {
3989 vty_out(vty,
3990 " bgp listen range %pFX peer-group %s\n",
3991 range, group->name);
3992 }
3993 }
3994 }
3995 }
3996
3997
3998 DEFUN (bgp_disable_connected_route_check,
3999 bgp_disable_connected_route_check_cmd,
4000 "bgp disable-ebgp-connected-route-check",
4001 "BGP specific commands\n"
4002 "Disable checking if nexthop is connected on ebgp sessions\n")
4003 {
4004 VTY_DECLVAR_CONTEXT(bgp, bgp);
4005 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4006 bgp_clear_star_soft_in(vty, bgp->name);
4007
4008 return CMD_SUCCESS;
4009 }
4010
4011 DEFUN (no_bgp_disable_connected_route_check,
4012 no_bgp_disable_connected_route_check_cmd,
4013 "no bgp disable-ebgp-connected-route-check",
4014 NO_STR
4015 "BGP specific commands\n"
4016 "Disable checking if nexthop is connected on ebgp sessions\n")
4017 {
4018 VTY_DECLVAR_CONTEXT(bgp, bgp);
4019 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4020 bgp_clear_star_soft_in(vty, bgp->name);
4021
4022 return CMD_SUCCESS;
4023 }
4024
4025
4026 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4027 const char *as_str)
4028 {
4029 VTY_DECLVAR_CONTEXT(bgp, bgp);
4030 int ret;
4031 as_t as;
4032 int as_type = AS_SPECIFIED;
4033 union sockunion su;
4034
4035 if (as_str[0] == 'i') {
4036 as = 0;
4037 as_type = AS_INTERNAL;
4038 } else if (as_str[0] == 'e') {
4039 as = 0;
4040 as_type = AS_EXTERNAL;
4041 } else {
4042 /* Get AS number. */
4043 as = strtoul(as_str, NULL, 10);
4044 }
4045
4046 /* If peer is peer group or interface peer, call proper function. */
4047 ret = str2sockunion(peer_str, &su);
4048 if (ret < 0) {
4049 struct peer *peer;
4050
4051 /* Check if existing interface peer */
4052 peer = peer_lookup_by_conf_if(bgp, peer_str);
4053
4054 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4055
4056 /* if not interface peer, check peer-group settings */
4057 if (ret < 0 && !peer) {
4058 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4059 if (ret < 0) {
4060 vty_out(vty,
4061 "%% Create the peer-group or interface first\n");
4062 return CMD_WARNING_CONFIG_FAILED;
4063 }
4064 return CMD_SUCCESS;
4065 }
4066 } else {
4067 if (peer_address_self_check(bgp, &su)) {
4068 vty_out(vty,
4069 "%% Can not configure the local system as neighbor\n");
4070 return CMD_WARNING_CONFIG_FAILED;
4071 }
4072 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4073 }
4074
4075 /* This peer belongs to peer group. */
4076 switch (ret) {
4077 case BGP_ERR_PEER_GROUP_MEMBER:
4078 vty_out(vty,
4079 "%% Peer-group member cannot override remote-as of peer-group\n");
4080 return CMD_WARNING_CONFIG_FAILED;
4081 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
4082 vty_out(vty,
4083 "%% Peer-group members must be all internal or all external\n");
4084 return CMD_WARNING_CONFIG_FAILED;
4085 }
4086 return bgp_vty_return(vty, ret);
4087 }
4088
4089 DEFUN (bgp_default_shutdown,
4090 bgp_default_shutdown_cmd,
4091 "[no] bgp default shutdown",
4092 NO_STR
4093 BGP_STR
4094 "Configure BGP defaults\n"
4095 "Apply administrative shutdown to newly configured peers\n")
4096 {
4097 VTY_DECLVAR_CONTEXT(bgp, bgp);
4098 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4099 return CMD_SUCCESS;
4100 }
4101
4102 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4103 BGP_STR
4104 "Administrative shutdown of the BGP instance\n"
4105 "Add a shutdown message (RFC 8203)\n"
4106 "Shutdown message\n")
4107 {
4108 char *msgstr = NULL;
4109
4110 VTY_DECLVAR_CONTEXT(bgp, bgp);
4111
4112 if (argc > 3)
4113 msgstr = argv_concat(argv, argc, 3);
4114
4115 bgp_shutdown_enable(bgp, msgstr);
4116 XFREE(MTYPE_TMP, msgstr);
4117
4118 return CMD_SUCCESS;
4119 }
4120
4121 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4122 BGP_STR "Administrative shutdown of the BGP instance\n")
4123 {
4124 VTY_DECLVAR_CONTEXT(bgp, bgp);
4125
4126 bgp_shutdown_enable(bgp, NULL);
4127
4128 return CMD_SUCCESS;
4129 }
4130
4131 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4132 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4133 {
4134 VTY_DECLVAR_CONTEXT(bgp, bgp);
4135
4136 bgp_shutdown_disable(bgp);
4137
4138 return CMD_SUCCESS;
4139 }
4140
4141 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4142 "no bgp shutdown message MSG...", NO_STR BGP_STR
4143 "Administrative shutdown of the BGP instance\n"
4144 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4145
4146 DEFUN (neighbor_remote_as,
4147 neighbor_remote_as_cmd,
4148 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4149 NEIGHBOR_STR
4150 NEIGHBOR_ADDR_STR2
4151 "Specify a BGP neighbor\n"
4152 AS_STR
4153 "Internal BGP peer\n"
4154 "External BGP peer\n")
4155 {
4156 int idx_peer = 1;
4157 int idx_remote_as = 3;
4158 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4159 argv[idx_remote_as]->arg);
4160 }
4161
4162 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4163 int v6only,
4164 const char *peer_group_name,
4165 const char *as_str)
4166 {
4167 VTY_DECLVAR_CONTEXT(bgp, bgp);
4168 as_t as = 0;
4169 int as_type = AS_UNSPECIFIED;
4170 struct peer *peer;
4171 struct peer_group *group;
4172 int ret = 0;
4173
4174 group = peer_group_lookup(bgp, conf_if);
4175
4176 if (group) {
4177 vty_out(vty, "%% Name conflict with peer-group \n");
4178 return CMD_WARNING_CONFIG_FAILED;
4179 }
4180
4181 if (as_str) {
4182 if (as_str[0] == 'i') {
4183 as_type = AS_INTERNAL;
4184 } else if (as_str[0] == 'e') {
4185 as_type = AS_EXTERNAL;
4186 } else {
4187 /* Get AS number. */
4188 as = strtoul(as_str, NULL, 10);
4189 as_type = AS_SPECIFIED;
4190 }
4191 }
4192
4193 peer = peer_lookup_by_conf_if(bgp, conf_if);
4194 if (peer) {
4195 if (as_str)
4196 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4197 } else {
4198 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4199 NULL);
4200
4201 if (!peer) {
4202 vty_out(vty, "%% BGP failed to create peer\n");
4203 return CMD_WARNING_CONFIG_FAILED;
4204 }
4205
4206 if (v6only)
4207 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4208
4209 /* Request zebra to initiate IPv6 RAs on this interface. We do
4210 * this
4211 * any unnumbered peer in order to not worry about run-time
4212 * transitions
4213 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4214 * address
4215 * gets deleted later etc.)
4216 */
4217 if (peer->ifp)
4218 bgp_zebra_initiate_radv(bgp, peer);
4219 }
4220
4221 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4222 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4223 if (v6only)
4224 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4225 else
4226 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4227
4228 /* v6only flag changed. Reset bgp seesion */
4229 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4230 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4231 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4232 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4233 } else
4234 bgp_session_reset(peer);
4235 }
4236
4237 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4238 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4239 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4240 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4241 }
4242
4243 if (peer_group_name) {
4244 group = peer_group_lookup(bgp, peer_group_name);
4245 if (!group) {
4246 vty_out(vty, "%% Configure the peer-group first\n");
4247 return CMD_WARNING_CONFIG_FAILED;
4248 }
4249
4250 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4251 }
4252
4253 return bgp_vty_return(vty, ret);
4254 }
4255
4256 DEFUN (neighbor_interface_config,
4257 neighbor_interface_config_cmd,
4258 "neighbor WORD interface [peer-group PGNAME]",
4259 NEIGHBOR_STR
4260 "Interface name or neighbor tag\n"
4261 "Enable BGP on interface\n"
4262 "Member of the peer-group\n"
4263 "Peer-group name\n")
4264 {
4265 int idx_word = 1;
4266 int idx_peer_group_word = 4;
4267
4268 if (argc > idx_peer_group_word)
4269 return peer_conf_interface_get(
4270 vty, argv[idx_word]->arg, 0,
4271 argv[idx_peer_group_word]->arg, NULL);
4272 else
4273 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4274 NULL, NULL);
4275 }
4276
4277 DEFUN (neighbor_interface_config_v6only,
4278 neighbor_interface_config_v6only_cmd,
4279 "neighbor WORD interface v6only [peer-group PGNAME]",
4280 NEIGHBOR_STR
4281 "Interface name or neighbor tag\n"
4282 "Enable BGP on interface\n"
4283 "Enable BGP with v6 link-local only\n"
4284 "Member of the peer-group\n"
4285 "Peer-group name\n")
4286 {
4287 int idx_word = 1;
4288 int idx_peer_group_word = 5;
4289
4290 if (argc > idx_peer_group_word)
4291 return peer_conf_interface_get(
4292 vty, argv[idx_word]->arg, 1,
4293 argv[idx_peer_group_word]->arg, NULL);
4294
4295 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4296 }
4297
4298
4299 DEFUN (neighbor_interface_config_remote_as,
4300 neighbor_interface_config_remote_as_cmd,
4301 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4302 NEIGHBOR_STR
4303 "Interface name or neighbor tag\n"
4304 "Enable BGP on interface\n"
4305 "Specify a BGP neighbor\n"
4306 AS_STR
4307 "Internal BGP peer\n"
4308 "External BGP peer\n")
4309 {
4310 int idx_word = 1;
4311 int idx_remote_as = 4;
4312 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4313 argv[idx_remote_as]->arg);
4314 }
4315
4316 DEFUN (neighbor_interface_v6only_config_remote_as,
4317 neighbor_interface_v6only_config_remote_as_cmd,
4318 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4319 NEIGHBOR_STR
4320 "Interface name or neighbor tag\n"
4321 "Enable BGP with v6 link-local only\n"
4322 "Enable BGP on interface\n"
4323 "Specify a BGP neighbor\n"
4324 AS_STR
4325 "Internal BGP peer\n"
4326 "External BGP peer\n")
4327 {
4328 int idx_word = 1;
4329 int idx_remote_as = 5;
4330 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4331 argv[idx_remote_as]->arg);
4332 }
4333
4334 DEFUN (neighbor_peer_group,
4335 neighbor_peer_group_cmd,
4336 "neighbor WORD peer-group",
4337 NEIGHBOR_STR
4338 "Interface name or neighbor tag\n"
4339 "Configure peer-group\n")
4340 {
4341 VTY_DECLVAR_CONTEXT(bgp, bgp);
4342 int idx_word = 1;
4343 struct peer *peer;
4344 struct peer_group *group;
4345
4346 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4347 if (peer) {
4348 vty_out(vty, "%% Name conflict with interface: \n");
4349 return CMD_WARNING_CONFIG_FAILED;
4350 }
4351
4352 group = peer_group_get(bgp, argv[idx_word]->arg);
4353 if (!group) {
4354 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4355 return CMD_WARNING_CONFIG_FAILED;
4356 }
4357
4358 return CMD_SUCCESS;
4359 }
4360
4361 DEFUN (no_neighbor,
4362 no_neighbor_cmd,
4363 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4364 NO_STR
4365 NEIGHBOR_STR
4366 NEIGHBOR_ADDR_STR2
4367 "Specify a BGP neighbor\n"
4368 AS_STR
4369 "Internal BGP peer\n"
4370 "External BGP peer\n")
4371 {
4372 VTY_DECLVAR_CONTEXT(bgp, bgp);
4373 int idx_peer = 2;
4374 int ret;
4375 union sockunion su;
4376 struct peer_group *group;
4377 struct peer *peer;
4378 struct peer *other;
4379
4380 ret = str2sockunion(argv[idx_peer]->arg, &su);
4381 if (ret < 0) {
4382 /* look up for neighbor by interface name config. */
4383 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4384 if (peer) {
4385 /* Request zebra to terminate IPv6 RAs on this
4386 * interface. */
4387 if (peer->ifp)
4388 bgp_zebra_terminate_radv(peer->bgp, peer);
4389 peer_notify_unconfig(peer);
4390 peer_delete(peer);
4391 return CMD_SUCCESS;
4392 }
4393
4394 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4395 if (group) {
4396 peer_group_notify_unconfig(group);
4397 peer_group_delete(group);
4398 } else {
4399 vty_out(vty, "%% Create the peer-group first\n");
4400 return CMD_WARNING_CONFIG_FAILED;
4401 }
4402 } else {
4403 peer = peer_lookup(bgp, &su);
4404 if (peer) {
4405 if (peer_dynamic_neighbor(peer)) {
4406 vty_out(vty,
4407 "%% Operation not allowed on a dynamic neighbor\n");
4408 return CMD_WARNING_CONFIG_FAILED;
4409 }
4410
4411 other = peer->doppelganger;
4412
4413 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4414 bgp_zebra_terminate_radv(peer->bgp, peer);
4415
4416 peer_notify_unconfig(peer);
4417 peer_delete(peer);
4418 if (other && other->status != Deleted) {
4419 peer_notify_unconfig(other);
4420 peer_delete(other);
4421 }
4422 }
4423 }
4424
4425 return CMD_SUCCESS;
4426 }
4427
4428 DEFUN (no_neighbor_interface_config,
4429 no_neighbor_interface_config_cmd,
4430 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4431 NO_STR
4432 NEIGHBOR_STR
4433 "Interface name\n"
4434 "Configure BGP on interface\n"
4435 "Enable BGP with v6 link-local only\n"
4436 "Member of the peer-group\n"
4437 "Peer-group name\n"
4438 "Specify a BGP neighbor\n"
4439 AS_STR
4440 "Internal BGP peer\n"
4441 "External BGP peer\n")
4442 {
4443 VTY_DECLVAR_CONTEXT(bgp, bgp);
4444 int idx_word = 2;
4445 struct peer *peer;
4446
4447 /* look up for neighbor by interface name config. */
4448 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4449 if (peer) {
4450 /* Request zebra to terminate IPv6 RAs on this interface. */
4451 if (peer->ifp)
4452 bgp_zebra_terminate_radv(peer->bgp, peer);
4453 peer_notify_unconfig(peer);
4454 peer_delete(peer);
4455 } else {
4456 vty_out(vty, "%% Create the bgp interface first\n");
4457 return CMD_WARNING_CONFIG_FAILED;
4458 }
4459 return CMD_SUCCESS;
4460 }
4461
4462 DEFUN (no_neighbor_peer_group,
4463 no_neighbor_peer_group_cmd,
4464 "no neighbor WORD peer-group",
4465 NO_STR
4466 NEIGHBOR_STR
4467 "Neighbor tag\n"
4468 "Configure peer-group\n")
4469 {
4470 VTY_DECLVAR_CONTEXT(bgp, bgp);
4471 int idx_word = 2;
4472 struct peer_group *group;
4473
4474 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4475 if (group) {
4476 peer_group_notify_unconfig(group);
4477 peer_group_delete(group);
4478 } else {
4479 vty_out(vty, "%% Create the peer-group first\n");
4480 return CMD_WARNING_CONFIG_FAILED;
4481 }
4482 return CMD_SUCCESS;
4483 }
4484
4485 DEFUN (no_neighbor_interface_peer_group_remote_as,
4486 no_neighbor_interface_peer_group_remote_as_cmd,
4487 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4488 NO_STR
4489 NEIGHBOR_STR
4490 "Interface name or neighbor tag\n"
4491 "Specify a BGP neighbor\n"
4492 AS_STR
4493 "Internal BGP peer\n"
4494 "External BGP peer\n")
4495 {
4496 VTY_DECLVAR_CONTEXT(bgp, bgp);
4497 int idx_word = 2;
4498 struct peer_group *group;
4499 struct peer *peer;
4500
4501 /* look up for neighbor by interface name config. */
4502 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4503 if (peer) {
4504 peer_as_change(peer, 0, AS_UNSPECIFIED);
4505 return CMD_SUCCESS;
4506 }
4507
4508 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4509 if (group)
4510 peer_group_remote_as_delete(group);
4511 else {
4512 vty_out(vty, "%% Create the peer-group or interface first\n");
4513 return CMD_WARNING_CONFIG_FAILED;
4514 }
4515 return CMD_SUCCESS;
4516 }
4517
4518 DEFUN (neighbor_local_as,
4519 neighbor_local_as_cmd,
4520 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "Specify a local-as number\n"
4524 "AS number used as local AS\n")
4525 {
4526 int idx_peer = 1;
4527 int idx_number = 3;
4528 struct peer *peer;
4529 int ret;
4530 as_t as;
4531
4532 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4533 if (!peer)
4534 return CMD_WARNING_CONFIG_FAILED;
4535
4536 as = strtoul(argv[idx_number]->arg, NULL, 10);
4537 ret = peer_local_as_set(peer, as, 0, 0);
4538 return bgp_vty_return(vty, ret);
4539 }
4540
4541 DEFUN (neighbor_local_as_no_prepend,
4542 neighbor_local_as_no_prepend_cmd,
4543 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4544 NEIGHBOR_STR
4545 NEIGHBOR_ADDR_STR2
4546 "Specify a local-as number\n"
4547 "AS number used as local AS\n"
4548 "Do not prepend local-as to updates from ebgp peers\n")
4549 {
4550 int idx_peer = 1;
4551 int idx_number = 3;
4552 struct peer *peer;
4553 int ret;
4554 as_t as;
4555
4556 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4557 if (!peer)
4558 return CMD_WARNING_CONFIG_FAILED;
4559
4560 as = strtoul(argv[idx_number]->arg, NULL, 10);
4561 ret = peer_local_as_set(peer, as, 1, 0);
4562 return bgp_vty_return(vty, ret);
4563 }
4564
4565 DEFUN (neighbor_local_as_no_prepend_replace_as,
4566 neighbor_local_as_no_prepend_replace_as_cmd,
4567 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4568 NEIGHBOR_STR
4569 NEIGHBOR_ADDR_STR2
4570 "Specify a local-as number\n"
4571 "AS number used as local AS\n"
4572 "Do not prepend local-as to updates from ebgp peers\n"
4573 "Do not prepend local-as to updates from ibgp peers\n")
4574 {
4575 int idx_peer = 1;
4576 int idx_number = 3;
4577 struct peer *peer;
4578 int ret;
4579 as_t as;
4580
4581 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4582 if (!peer)
4583 return CMD_WARNING_CONFIG_FAILED;
4584
4585 as = strtoul(argv[idx_number]->arg, NULL, 10);
4586 ret = peer_local_as_set(peer, as, 1, 1);
4587 return bgp_vty_return(vty, ret);
4588 }
4589
4590 DEFUN (no_neighbor_local_as,
4591 no_neighbor_local_as_cmd,
4592 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4593 NO_STR
4594 NEIGHBOR_STR
4595 NEIGHBOR_ADDR_STR2
4596 "Specify a local-as number\n"
4597 "AS number used as local AS\n"
4598 "Do not prepend local-as to updates from ebgp peers\n"
4599 "Do not prepend local-as to updates from ibgp peers\n")
4600 {
4601 int idx_peer = 2;
4602 struct peer *peer;
4603 int ret;
4604
4605 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4606 if (!peer)
4607 return CMD_WARNING_CONFIG_FAILED;
4608
4609 ret = peer_local_as_unset(peer);
4610 return bgp_vty_return(vty, ret);
4611 }
4612
4613
4614 DEFUN (neighbor_solo,
4615 neighbor_solo_cmd,
4616 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4617 NEIGHBOR_STR
4618 NEIGHBOR_ADDR_STR2
4619 "Solo peer - part of its own update group\n")
4620 {
4621 int idx_peer = 1;
4622 struct peer *peer;
4623 int ret;
4624
4625 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4626 if (!peer)
4627 return CMD_WARNING_CONFIG_FAILED;
4628
4629 ret = update_group_adjust_soloness(peer, 1);
4630 return bgp_vty_return(vty, ret);
4631 }
4632
4633 DEFUN (no_neighbor_solo,
4634 no_neighbor_solo_cmd,
4635 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4636 NO_STR
4637 NEIGHBOR_STR
4638 NEIGHBOR_ADDR_STR2
4639 "Solo peer - part of its own update group\n")
4640 {
4641 int idx_peer = 2;
4642 struct peer *peer;
4643 int ret;
4644
4645 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4646 if (!peer)
4647 return CMD_WARNING_CONFIG_FAILED;
4648
4649 ret = update_group_adjust_soloness(peer, 0);
4650 return bgp_vty_return(vty, ret);
4651 }
4652
4653 DEFUN (neighbor_password,
4654 neighbor_password_cmd,
4655 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4656 NEIGHBOR_STR
4657 NEIGHBOR_ADDR_STR2
4658 "Set a password\n"
4659 "The password\n")
4660 {
4661 int idx_peer = 1;
4662 int idx_line = 3;
4663 struct peer *peer;
4664 int ret;
4665
4666 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4667 if (!peer)
4668 return CMD_WARNING_CONFIG_FAILED;
4669
4670 ret = peer_password_set(peer, argv[idx_line]->arg);
4671 return bgp_vty_return(vty, ret);
4672 }
4673
4674 DEFUN (no_neighbor_password,
4675 no_neighbor_password_cmd,
4676 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4677 NO_STR
4678 NEIGHBOR_STR
4679 NEIGHBOR_ADDR_STR2
4680 "Set a password\n"
4681 "The password\n")
4682 {
4683 int idx_peer = 2;
4684 struct peer *peer;
4685 int ret;
4686
4687 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4688 if (!peer)
4689 return CMD_WARNING_CONFIG_FAILED;
4690
4691 ret = peer_password_unset(peer);
4692 return bgp_vty_return(vty, ret);
4693 }
4694
4695 DEFUN (neighbor_activate,
4696 neighbor_activate_cmd,
4697 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4698 NEIGHBOR_STR
4699 NEIGHBOR_ADDR_STR2
4700 "Enable the Address Family for this Neighbor\n")
4701 {
4702 int idx_peer = 1;
4703 int ret;
4704 struct peer *peer;
4705
4706 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4707 if (!peer)
4708 return CMD_WARNING_CONFIG_FAILED;
4709
4710 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4711 return bgp_vty_return(vty, ret);
4712 }
4713
4714 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4715 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4716 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4717 "Enable the Address Family for this Neighbor\n")
4718
4719 DEFUN (no_neighbor_activate,
4720 no_neighbor_activate_cmd,
4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4722 NO_STR
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "Enable the Address Family for this Neighbor\n")
4726 {
4727 int idx_peer = 2;
4728 int ret;
4729 struct peer *peer;
4730
4731 /* Lookup peer. */
4732 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4733 if (!peer)
4734 return CMD_WARNING_CONFIG_FAILED;
4735
4736 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4737 return bgp_vty_return(vty, ret);
4738 }
4739
4740 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4741 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4742 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4743 "Enable the Address Family for this Neighbor\n")
4744
4745 DEFUN (neighbor_set_peer_group,
4746 neighbor_set_peer_group_cmd,
4747 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4748 NEIGHBOR_STR
4749 NEIGHBOR_ADDR_STR2
4750 "Member of the peer-group\n"
4751 "Peer-group name\n")
4752 {
4753 VTY_DECLVAR_CONTEXT(bgp, bgp);
4754 int idx_peer = 1;
4755 int idx_word = 3;
4756 int ret;
4757 as_t as;
4758 union sockunion su;
4759 struct peer *peer;
4760 struct peer_group *group;
4761
4762 ret = str2sockunion(argv[idx_peer]->arg, &su);
4763 if (ret < 0) {
4764 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4765 if (!peer) {
4766 vty_out(vty, "%% Malformed address or name: %s\n",
4767 argv[idx_peer]->arg);
4768 return CMD_WARNING_CONFIG_FAILED;
4769 }
4770 } else {
4771 if (peer_address_self_check(bgp, &su)) {
4772 vty_out(vty,
4773 "%% Can not configure the local system as neighbor\n");
4774 return CMD_WARNING_CONFIG_FAILED;
4775 }
4776
4777 /* Disallow for dynamic neighbor. */
4778 peer = peer_lookup(bgp, &su);
4779 if (peer && peer_dynamic_neighbor(peer)) {
4780 vty_out(vty,
4781 "%% Operation not allowed on a dynamic neighbor\n");
4782 return CMD_WARNING_CONFIG_FAILED;
4783 }
4784 }
4785
4786 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4787 if (!group) {
4788 vty_out(vty, "%% Configure the peer-group first\n");
4789 return CMD_WARNING_CONFIG_FAILED;
4790 }
4791
4792 ret = peer_group_bind(bgp, &su, peer, group, &as);
4793
4794 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4795 vty_out(vty,
4796 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4797 as);
4798 return CMD_WARNING_CONFIG_FAILED;
4799 }
4800
4801 return bgp_vty_return(vty, ret);
4802 }
4803
4804 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4805 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4806 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4807 "Member of the peer-group\n"
4808 "Peer-group name\n")
4809
4810 DEFUN (no_neighbor_set_peer_group,
4811 no_neighbor_set_peer_group_cmd,
4812 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4813 NO_STR
4814 NEIGHBOR_STR
4815 NEIGHBOR_ADDR_STR2
4816 "Member of the peer-group\n"
4817 "Peer-group name\n")
4818 {
4819 VTY_DECLVAR_CONTEXT(bgp, bgp);
4820 int idx_peer = 2;
4821 int idx_word = 4;
4822 int ret;
4823 struct peer *peer;
4824 struct peer_group *group;
4825
4826 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4827 if (!peer)
4828 return CMD_WARNING_CONFIG_FAILED;
4829
4830 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4831 if (!group) {
4832 vty_out(vty, "%% Configure the peer-group first\n");
4833 return CMD_WARNING_CONFIG_FAILED;
4834 }
4835
4836 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4837 bgp_zebra_terminate_radv(peer->bgp, peer);
4838
4839 peer_notify_unconfig(peer);
4840 ret = peer_delete(peer);
4841
4842 return bgp_vty_return(vty, ret);
4843 }
4844
4845 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4846 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4848 "Member of the peer-group\n"
4849 "Peer-group name\n")
4850
4851 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
4852 uint32_t flag, int set)
4853 {
4854 int ret;
4855 struct peer *peer;
4856
4857 peer = peer_and_group_lookup_vty(vty, ip_str);
4858 if (!peer)
4859 return CMD_WARNING_CONFIG_FAILED;
4860
4861 /*
4862 * If 'neighbor <interface>', then this is for directly connected peers,
4863 * we should not accept disable-connected-check.
4864 */
4865 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4866 vty_out(vty,
4867 "%s is directly connected peer, cannot accept disable-connected-check\n",
4868 ip_str);
4869 return CMD_WARNING_CONFIG_FAILED;
4870 }
4871
4872 if (!set && flag == PEER_FLAG_SHUTDOWN)
4873 peer_tx_shutdown_message_unset(peer);
4874
4875 if (set)
4876 ret = peer_flag_set(peer, flag);
4877 else
4878 ret = peer_flag_unset(peer, flag);
4879
4880 return bgp_vty_return(vty, ret);
4881 }
4882
4883 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
4884 {
4885 return peer_flag_modify_vty(vty, ip_str, flag, 1);
4886 }
4887
4888 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
4889 uint32_t flag)
4890 {
4891 return peer_flag_modify_vty(vty, ip_str, flag, 0);
4892 }
4893
4894 /* neighbor passive. */
4895 DEFUN (neighbor_passive,
4896 neighbor_passive_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
4900 "Don't send open messages to this neighbor\n")
4901 {
4902 int idx_peer = 1;
4903 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4904 }
4905
4906 DEFUN (no_neighbor_passive,
4907 no_neighbor_passive_cmd,
4908 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4909 NO_STR
4910 NEIGHBOR_STR
4911 NEIGHBOR_ADDR_STR2
4912 "Don't send open messages to this neighbor\n")
4913 {
4914 int idx_peer = 2;
4915 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
4916 }
4917
4918 /* neighbor shutdown. */
4919 DEFUN (neighbor_shutdown_msg,
4920 neighbor_shutdown_msg_cmd,
4921 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4922 NEIGHBOR_STR
4923 NEIGHBOR_ADDR_STR2
4924 "Administratively shut down this neighbor\n"
4925 "Add a shutdown message (RFC 8203)\n"
4926 "Shutdown message\n")
4927 {
4928 int idx_peer = 1;
4929
4930 if (argc >= 5) {
4931 struct peer *peer =
4932 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4933 char *message;
4934
4935 if (!peer)
4936 return CMD_WARNING_CONFIG_FAILED;
4937 message = argv_concat(argv, argc, 4);
4938 peer_tx_shutdown_message_set(peer, message);
4939 XFREE(MTYPE_TMP, message);
4940 }
4941
4942 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
4943 }
4944
4945 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4946 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4948 "Administratively shut down this neighbor\n")
4949
4950 DEFUN (no_neighbor_shutdown_msg,
4951 no_neighbor_shutdown_msg_cmd,
4952 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4953 NO_STR
4954 NEIGHBOR_STR
4955 NEIGHBOR_ADDR_STR2
4956 "Administratively shut down this neighbor\n"
4957 "Remove a shutdown message (RFC 8203)\n"
4958 "Shutdown message\n")
4959 {
4960 int idx_peer = 2;
4961
4962 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4963 PEER_FLAG_SHUTDOWN);
4964 }
4965
4966 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4967 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4969 "Administratively shut down this neighbor\n")
4970
4971 DEFUN(neighbor_shutdown_rtt,
4972 neighbor_shutdown_rtt_cmd,
4973 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
4974 NEIGHBOR_STR
4975 NEIGHBOR_ADDR_STR2
4976 "Administratively shut down this neighbor\n"
4977 "Shutdown if round-trip-time is higher than expected\n"
4978 "Round-trip-time in milliseconds\n"
4979 "Specify the number of keepalives before shutdown\n"
4980 "The number of keepalives with higher RTT to shutdown\n")
4981 {
4982 int idx_peer = 1;
4983 int idx_rtt = 4;
4984 int idx_count = 0;
4985 struct peer *peer;
4986
4987 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4988
4989 if (!peer)
4990 return CMD_WARNING_CONFIG_FAILED;
4991
4992 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
4993
4994 if (argv_find(argv, argc, "count", &idx_count))
4995 peer->rtt_keepalive_conf =
4996 strtol(argv[idx_count + 1]->arg, NULL, 10);
4997
4998 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4999 PEER_FLAG_RTT_SHUTDOWN);
5000 }
5001
5002 DEFUN(no_neighbor_shutdown_rtt,
5003 no_neighbor_shutdown_rtt_cmd,
5004 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5005 NO_STR
5006 NEIGHBOR_STR
5007 NEIGHBOR_ADDR_STR2
5008 "Administratively shut down this neighbor\n"
5009 "Shutdown if round-trip-time is higher than expected\n"
5010 "Round-trip-time in milliseconds\n"
5011 "Specify the number of keepalives before shutdown\n"
5012 "The number of keepalives with higher RTT to shutdown\n")
5013 {
5014 int idx_peer = 2;
5015 struct peer *peer;
5016
5017 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5018
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 peer->rtt_expected = 0;
5023 peer->rtt_keepalive_conf = 1;
5024
5025 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5026 PEER_FLAG_RTT_SHUTDOWN);
5027 }
5028
5029 /* neighbor capability dynamic. */
5030 DEFUN (neighbor_capability_dynamic,
5031 neighbor_capability_dynamic_cmd,
5032 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5033 NEIGHBOR_STR
5034 NEIGHBOR_ADDR_STR2
5035 "Advertise capability to the peer\n"
5036 "Advertise dynamic capability to this neighbor\n")
5037 {
5038 int idx_peer = 1;
5039 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5040 PEER_FLAG_DYNAMIC_CAPABILITY);
5041 }
5042
5043 DEFUN (no_neighbor_capability_dynamic,
5044 no_neighbor_capability_dynamic_cmd,
5045 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5046 NO_STR
5047 NEIGHBOR_STR
5048 NEIGHBOR_ADDR_STR2
5049 "Advertise capability to the peer\n"
5050 "Advertise dynamic capability to this neighbor\n")
5051 {
5052 int idx_peer = 2;
5053 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5054 PEER_FLAG_DYNAMIC_CAPABILITY);
5055 }
5056
5057 /* neighbor dont-capability-negotiate */
5058 DEFUN (neighbor_dont_capability_negotiate,
5059 neighbor_dont_capability_negotiate_cmd,
5060 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
5063 "Do not perform capability negotiation\n")
5064 {
5065 int idx_peer = 1;
5066 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5067 PEER_FLAG_DONT_CAPABILITY);
5068 }
5069
5070 DEFUN (no_neighbor_dont_capability_negotiate,
5071 no_neighbor_dont_capability_negotiate_cmd,
5072 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5073 NO_STR
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR2
5076 "Do not perform capability negotiation\n")
5077 {
5078 int idx_peer = 2;
5079 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5080 PEER_FLAG_DONT_CAPABILITY);
5081 }
5082
5083 /* neighbor capability extended next hop encoding */
5084 DEFUN (neighbor_capability_enhe,
5085 neighbor_capability_enhe_cmd,
5086 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5087 NEIGHBOR_STR
5088 NEIGHBOR_ADDR_STR2
5089 "Advertise capability to the peer\n"
5090 "Advertise extended next-hop capability to the peer\n")
5091 {
5092 int idx_peer = 1;
5093 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5094 PEER_FLAG_CAPABILITY_ENHE);
5095 }
5096
5097 DEFUN (no_neighbor_capability_enhe,
5098 no_neighbor_capability_enhe_cmd,
5099 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5100 NO_STR
5101 NEIGHBOR_STR
5102 NEIGHBOR_ADDR_STR2
5103 "Advertise capability to the peer\n"
5104 "Advertise extended next-hop capability to the peer\n")
5105 {
5106 int idx_peer = 2;
5107 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5108 PEER_FLAG_CAPABILITY_ENHE);
5109 }
5110
5111 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5112 afi_t afi, safi_t safi, uint32_t flag,
5113 int set)
5114 {
5115 int ret;
5116 struct peer *peer;
5117
5118 peer = peer_and_group_lookup_vty(vty, peer_str);
5119 if (!peer)
5120 return CMD_WARNING_CONFIG_FAILED;
5121
5122 if (set)
5123 ret = peer_af_flag_set(peer, afi, safi, flag);
5124 else
5125 ret = peer_af_flag_unset(peer, afi, safi, flag);
5126
5127 return bgp_vty_return(vty, ret);
5128 }
5129
5130 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5131 afi_t afi, safi_t safi, uint32_t flag)
5132 {
5133 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5134 }
5135
5136 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5137 afi_t afi, safi_t safi, uint32_t flag)
5138 {
5139 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5140 }
5141
5142 /* neighbor capability orf prefix-list. */
5143 DEFUN (neighbor_capability_orf_prefix,
5144 neighbor_capability_orf_prefix_cmd,
5145 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5146 NEIGHBOR_STR
5147 NEIGHBOR_ADDR_STR2
5148 "Advertise capability to the peer\n"
5149 "Advertise ORF capability to the peer\n"
5150 "Advertise prefixlist ORF capability to this neighbor\n"
5151 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5152 "Capability to RECEIVE the ORF from this neighbor\n"
5153 "Capability to SEND the ORF to this neighbor\n")
5154 {
5155 int idx_send_recv = 5;
5156 char *peer_str = argv[1]->arg;
5157 struct peer *peer;
5158 afi_t afi = bgp_node_afi(vty);
5159 safi_t safi = bgp_node_safi(vty);
5160
5161 peer = peer_and_group_lookup_vty(vty, peer_str);
5162 if (!peer)
5163 return CMD_WARNING_CONFIG_FAILED;
5164
5165 if (strmatch(argv[idx_send_recv]->text, "send"))
5166 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5167 PEER_FLAG_ORF_PREFIX_SM);
5168
5169 if (strmatch(argv[idx_send_recv]->text, "receive"))
5170 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5171 PEER_FLAG_ORF_PREFIX_RM);
5172
5173 if (strmatch(argv[idx_send_recv]->text, "both"))
5174 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5175 PEER_FLAG_ORF_PREFIX_SM)
5176 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5177 PEER_FLAG_ORF_PREFIX_RM);
5178
5179 return CMD_WARNING_CONFIG_FAILED;
5180 }
5181
5182 ALIAS_HIDDEN(
5183 neighbor_capability_orf_prefix,
5184 neighbor_capability_orf_prefix_hidden_cmd,
5185 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5186 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5187 "Advertise capability to the peer\n"
5188 "Advertise ORF capability to the peer\n"
5189 "Advertise prefixlist ORF capability to this neighbor\n"
5190 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5191 "Capability to RECEIVE the ORF from this neighbor\n"
5192 "Capability to SEND the ORF to this neighbor\n")
5193
5194 DEFUN (no_neighbor_capability_orf_prefix,
5195 no_neighbor_capability_orf_prefix_cmd,
5196 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5197 NO_STR
5198 NEIGHBOR_STR
5199 NEIGHBOR_ADDR_STR2
5200 "Advertise capability to the peer\n"
5201 "Advertise ORF capability to the peer\n"
5202 "Advertise prefixlist ORF capability to this neighbor\n"
5203 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5204 "Capability to RECEIVE the ORF from this neighbor\n"
5205 "Capability to SEND the ORF to this neighbor\n")
5206 {
5207 int idx_send_recv = 6;
5208 char *peer_str = argv[2]->arg;
5209 struct peer *peer;
5210 afi_t afi = bgp_node_afi(vty);
5211 safi_t safi = bgp_node_safi(vty);
5212
5213 peer = peer_and_group_lookup_vty(vty, peer_str);
5214 if (!peer)
5215 return CMD_WARNING_CONFIG_FAILED;
5216
5217 if (strmatch(argv[idx_send_recv]->text, "send"))
5218 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5219 PEER_FLAG_ORF_PREFIX_SM);
5220
5221 if (strmatch(argv[idx_send_recv]->text, "receive"))
5222 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5223 PEER_FLAG_ORF_PREFIX_RM);
5224
5225 if (strmatch(argv[idx_send_recv]->text, "both"))
5226 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5227 PEER_FLAG_ORF_PREFIX_SM)
5228 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5229 PEER_FLAG_ORF_PREFIX_RM);
5230
5231 return CMD_WARNING_CONFIG_FAILED;
5232 }
5233
5234 ALIAS_HIDDEN(
5235 no_neighbor_capability_orf_prefix,
5236 no_neighbor_capability_orf_prefix_hidden_cmd,
5237 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5238 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5239 "Advertise capability to the peer\n"
5240 "Advertise ORF capability to the peer\n"
5241 "Advertise prefixlist ORF capability to this neighbor\n"
5242 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5243 "Capability to RECEIVE the ORF from this neighbor\n"
5244 "Capability to SEND the ORF to this neighbor\n")
5245
5246 /* neighbor next-hop-self. */
5247 DEFUN (neighbor_nexthop_self,
5248 neighbor_nexthop_self_cmd,
5249 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "Disable the next hop calculation for this neighbor\n")
5253 {
5254 int idx_peer = 1;
5255 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5256 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5257 }
5258
5259 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5260 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5261 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5262 "Disable the next hop calculation for this neighbor\n")
5263
5264 /* neighbor next-hop-self. */
5265 DEFUN (neighbor_nexthop_self_force,
5266 neighbor_nexthop_self_force_cmd,
5267 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5268 NEIGHBOR_STR
5269 NEIGHBOR_ADDR_STR2
5270 "Disable the next hop calculation for this neighbor\n"
5271 "Set the next hop to self for reflected routes\n")
5272 {
5273 int idx_peer = 1;
5274 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5275 bgp_node_safi(vty),
5276 PEER_FLAG_FORCE_NEXTHOP_SELF);
5277 }
5278
5279 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5280 neighbor_nexthop_self_force_hidden_cmd,
5281 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5282 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5283 "Disable the next hop calculation for this neighbor\n"
5284 "Set the next hop to self for reflected routes\n")
5285
5286 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5287 neighbor_nexthop_self_all_hidden_cmd,
5288 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5290 "Disable the next hop calculation for this neighbor\n"
5291 "Set the next hop to self for reflected routes\n")
5292
5293 DEFUN (no_neighbor_nexthop_self,
5294 no_neighbor_nexthop_self_cmd,
5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Disable the next hop calculation for this neighbor\n")
5300 {
5301 int idx_peer = 2;
5302 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5303 bgp_node_afi(vty), bgp_node_safi(vty),
5304 PEER_FLAG_NEXTHOP_SELF);
5305 }
5306
5307 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5310 "Disable the next hop calculation for this neighbor\n")
5311
5312 DEFUN (no_neighbor_nexthop_self_force,
5313 no_neighbor_nexthop_self_force_cmd,
5314 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5315 NO_STR
5316 NEIGHBOR_STR
5317 NEIGHBOR_ADDR_STR2
5318 "Disable the next hop calculation for this neighbor\n"
5319 "Set the next hop to self for reflected routes\n")
5320 {
5321 int idx_peer = 2;
5322 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5323 bgp_node_afi(vty), bgp_node_safi(vty),
5324 PEER_FLAG_FORCE_NEXTHOP_SELF);
5325 }
5326
5327 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5328 no_neighbor_nexthop_self_force_hidden_cmd,
5329 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5330 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5331 "Disable the next hop calculation for this neighbor\n"
5332 "Set the next hop to self for reflected routes\n")
5333
5334 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5335 no_neighbor_nexthop_self_all_hidden_cmd,
5336 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5337 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5338 "Disable the next hop calculation for this neighbor\n"
5339 "Set the next hop to self for reflected routes\n")
5340
5341 /* neighbor as-override */
5342 DEFUN (neighbor_as_override,
5343 neighbor_as_override_cmd,
5344 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5345 NEIGHBOR_STR
5346 NEIGHBOR_ADDR_STR2
5347 "Override ASNs in outbound updates if aspath equals remote-as\n")
5348 {
5349 int idx_peer = 1;
5350 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5351 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5352 }
5353
5354 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5355 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5357 "Override ASNs in outbound updates if aspath equals remote-as\n")
5358
5359 DEFUN (no_neighbor_as_override,
5360 no_neighbor_as_override_cmd,
5361 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5362 NO_STR
5363 NEIGHBOR_STR
5364 NEIGHBOR_ADDR_STR2
5365 "Override ASNs in outbound updates if aspath equals remote-as\n")
5366 {
5367 int idx_peer = 2;
5368 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5369 bgp_node_afi(vty), bgp_node_safi(vty),
5370 PEER_FLAG_AS_OVERRIDE);
5371 }
5372
5373 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5374 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5375 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5376 "Override ASNs in outbound updates if aspath equals remote-as\n")
5377
5378 /* neighbor remove-private-AS. */
5379 DEFUN (neighbor_remove_private_as,
5380 neighbor_remove_private_as_cmd,
5381 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5382 NEIGHBOR_STR
5383 NEIGHBOR_ADDR_STR2
5384 "Remove private ASNs in outbound updates\n")
5385 {
5386 int idx_peer = 1;
5387 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5388 bgp_node_safi(vty),
5389 PEER_FLAG_REMOVE_PRIVATE_AS);
5390 }
5391
5392 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5393 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5394 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5395 "Remove private ASNs in outbound updates\n")
5396
5397 DEFUN (neighbor_remove_private_as_all,
5398 neighbor_remove_private_as_all_cmd,
5399 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5400 NEIGHBOR_STR
5401 NEIGHBOR_ADDR_STR2
5402 "Remove private ASNs in outbound updates\n"
5403 "Apply to all AS numbers\n")
5404 {
5405 int idx_peer = 1;
5406 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5407 bgp_node_safi(vty),
5408 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5409 }
5410
5411 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5412 neighbor_remove_private_as_all_hidden_cmd,
5413 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5414 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5415 "Remove private ASNs in outbound updates\n"
5416 "Apply to all AS numbers")
5417
5418 DEFUN (neighbor_remove_private_as_replace_as,
5419 neighbor_remove_private_as_replace_as_cmd,
5420 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5421 NEIGHBOR_STR
5422 NEIGHBOR_ADDR_STR2
5423 "Remove private ASNs in outbound updates\n"
5424 "Replace private ASNs with our ASN in outbound updates\n")
5425 {
5426 int idx_peer = 1;
5427 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5428 bgp_node_safi(vty),
5429 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5430 }
5431
5432 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5433 neighbor_remove_private_as_replace_as_hidden_cmd,
5434 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5435 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5436 "Remove private ASNs in outbound updates\n"
5437 "Replace private ASNs with our ASN in outbound updates\n")
5438
5439 DEFUN (neighbor_remove_private_as_all_replace_as,
5440 neighbor_remove_private_as_all_replace_as_cmd,
5441 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Remove private ASNs in outbound updates\n"
5445 "Apply to all AS numbers\n"
5446 "Replace private ASNs with our ASN in outbound updates\n")
5447 {
5448 int idx_peer = 1;
5449 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5450 bgp_node_safi(vty),
5451 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5452 }
5453
5454 ALIAS_HIDDEN(
5455 neighbor_remove_private_as_all_replace_as,
5456 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5459 "Remove private ASNs in outbound updates\n"
5460 "Apply to all AS numbers\n"
5461 "Replace private ASNs with our ASN in outbound updates\n")
5462
5463 DEFUN (no_neighbor_remove_private_as,
5464 no_neighbor_remove_private_as_cmd,
5465 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5466 NO_STR
5467 NEIGHBOR_STR
5468 NEIGHBOR_ADDR_STR2
5469 "Remove private ASNs in outbound updates\n")
5470 {
5471 int idx_peer = 2;
5472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5473 bgp_node_afi(vty), bgp_node_safi(vty),
5474 PEER_FLAG_REMOVE_PRIVATE_AS);
5475 }
5476
5477 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5478 no_neighbor_remove_private_as_hidden_cmd,
5479 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5481 "Remove private ASNs in outbound updates\n")
5482
5483 DEFUN (no_neighbor_remove_private_as_all,
5484 no_neighbor_remove_private_as_all_cmd,
5485 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5486 NO_STR
5487 NEIGHBOR_STR
5488 NEIGHBOR_ADDR_STR2
5489 "Remove private ASNs in outbound updates\n"
5490 "Apply to all AS numbers\n")
5491 {
5492 int idx_peer = 2;
5493 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5494 bgp_node_afi(vty), bgp_node_safi(vty),
5495 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5496 }
5497
5498 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5499 no_neighbor_remove_private_as_all_hidden_cmd,
5500 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5501 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5502 "Remove private ASNs in outbound updates\n"
5503 "Apply to all AS numbers\n")
5504
5505 DEFUN (no_neighbor_remove_private_as_replace_as,
5506 no_neighbor_remove_private_as_replace_as_cmd,
5507 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5508 NO_STR
5509 NEIGHBOR_STR
5510 NEIGHBOR_ADDR_STR2
5511 "Remove private ASNs in outbound updates\n"
5512 "Replace private ASNs with our ASN in outbound updates\n")
5513 {
5514 int idx_peer = 2;
5515 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5516 bgp_node_afi(vty), bgp_node_safi(vty),
5517 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5518 }
5519
5520 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5521 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5522 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5523 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5524 "Remove private ASNs in outbound updates\n"
5525 "Replace private ASNs with our ASN in outbound updates\n")
5526
5527 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5528 no_neighbor_remove_private_as_all_replace_as_cmd,
5529 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5530 NO_STR
5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Remove private ASNs in outbound updates\n"
5534 "Apply to all AS numbers\n"
5535 "Replace private ASNs with our ASN in outbound updates\n")
5536 {
5537 int idx_peer = 2;
5538 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5539 bgp_node_afi(vty), bgp_node_safi(vty),
5540 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5541 }
5542
5543 ALIAS_HIDDEN(
5544 no_neighbor_remove_private_as_all_replace_as,
5545 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5546 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5547 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5548 "Remove private ASNs in outbound updates\n"
5549 "Apply to all AS numbers\n"
5550 "Replace private ASNs with our ASN in outbound updates\n")
5551
5552
5553 /* neighbor send-community. */
5554 DEFUN (neighbor_send_community,
5555 neighbor_send_community_cmd,
5556 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5557 NEIGHBOR_STR
5558 NEIGHBOR_ADDR_STR2
5559 "Send Community attribute to this neighbor\n")
5560 {
5561 int idx_peer = 1;
5562
5563 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5564 bgp_node_safi(vty),
5565 PEER_FLAG_SEND_COMMUNITY);
5566 }
5567
5568 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5569 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5570 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5571 "Send Community attribute to this neighbor\n")
5572
5573 DEFUN (no_neighbor_send_community,
5574 no_neighbor_send_community_cmd,
5575 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5576 NO_STR
5577 NEIGHBOR_STR
5578 NEIGHBOR_ADDR_STR2
5579 "Send Community attribute to this neighbor\n")
5580 {
5581 int idx_peer = 2;
5582
5583 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5584 bgp_node_afi(vty), bgp_node_safi(vty),
5585 PEER_FLAG_SEND_COMMUNITY);
5586 }
5587
5588 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5589 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5590 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5591 "Send Community attribute to this neighbor\n")
5592
5593 /* neighbor send-community extended. */
5594 DEFUN (neighbor_send_community_type,
5595 neighbor_send_community_type_cmd,
5596 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5597 NEIGHBOR_STR
5598 NEIGHBOR_ADDR_STR2
5599 "Send Community attribute to this neighbor\n"
5600 "Send Standard and Extended Community attributes\n"
5601 "Send Standard, Large and Extended Community attributes\n"
5602 "Send Extended Community attributes\n"
5603 "Send Standard Community attributes\n"
5604 "Send Large Community attributes\n")
5605 {
5606 const char *type = argv[argc - 1]->text;
5607 char *peer_str = argv[1]->arg;
5608 struct peer *peer;
5609 afi_t afi = bgp_node_afi(vty);
5610 safi_t safi = bgp_node_safi(vty);
5611
5612 peer = peer_and_group_lookup_vty(vty, peer_str);
5613 if (!peer)
5614 return CMD_WARNING_CONFIG_FAILED;
5615
5616 if (strmatch(type, "standard"))
5617 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5618 PEER_FLAG_SEND_COMMUNITY);
5619
5620 if (strmatch(type, "extended"))
5621 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5622 PEER_FLAG_SEND_EXT_COMMUNITY);
5623
5624 if (strmatch(type, "large"))
5625 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5626 PEER_FLAG_SEND_LARGE_COMMUNITY);
5627
5628 if (strmatch(type, "both")) {
5629 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5630 PEER_FLAG_SEND_COMMUNITY)
5631 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5632 PEER_FLAG_SEND_EXT_COMMUNITY);
5633 }
5634 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5635 PEER_FLAG_SEND_COMMUNITY)
5636 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5637 PEER_FLAG_SEND_EXT_COMMUNITY)
5638 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5639 PEER_FLAG_SEND_LARGE_COMMUNITY);
5640 }
5641
5642 ALIAS_HIDDEN(
5643 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5646 "Send Community attribute to this neighbor\n"
5647 "Send Standard and Extended Community attributes\n"
5648 "Send Standard, Large and Extended Community attributes\n"
5649 "Send Extended Community attributes\n"
5650 "Send Standard Community attributes\n"
5651 "Send Large Community attributes\n")
5652
5653 DEFUN (no_neighbor_send_community_type,
5654 no_neighbor_send_community_type_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5656 NO_STR
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Send Community attribute to this neighbor\n"
5660 "Send Standard and Extended Community attributes\n"
5661 "Send Standard, Large and Extended Community attributes\n"
5662 "Send Extended Community attributes\n"
5663 "Send Standard Community attributes\n"
5664 "Send Large Community attributes\n")
5665 {
5666 const char *type = argv[argc - 1]->text;
5667 char *peer_str = argv[2]->arg;
5668 struct peer *peer;
5669 afi_t afi = bgp_node_afi(vty);
5670 safi_t safi = bgp_node_safi(vty);
5671
5672 peer = peer_and_group_lookup_vty(vty, peer_str);
5673 if (!peer)
5674 return CMD_WARNING_CONFIG_FAILED;
5675
5676 if (strmatch(type, "standard"))
5677 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5678 PEER_FLAG_SEND_COMMUNITY);
5679
5680 if (strmatch(type, "extended"))
5681 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5682 PEER_FLAG_SEND_EXT_COMMUNITY);
5683
5684 if (strmatch(type, "large"))
5685 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5686 PEER_FLAG_SEND_LARGE_COMMUNITY);
5687
5688 if (strmatch(type, "both")) {
5689
5690 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5691 PEER_FLAG_SEND_COMMUNITY)
5692 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5693 PEER_FLAG_SEND_EXT_COMMUNITY);
5694 }
5695
5696 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5697 PEER_FLAG_SEND_COMMUNITY)
5698 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5699 PEER_FLAG_SEND_EXT_COMMUNITY)
5700 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5701 PEER_FLAG_SEND_LARGE_COMMUNITY);
5702 }
5703
5704 ALIAS_HIDDEN(
5705 no_neighbor_send_community_type,
5706 no_neighbor_send_community_type_hidden_cmd,
5707 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5708 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5709 "Send Community attribute to this neighbor\n"
5710 "Send Standard and Extended Community attributes\n"
5711 "Send Standard, Large and Extended Community attributes\n"
5712 "Send Extended Community attributes\n"
5713 "Send Standard Community attributes\n"
5714 "Send Large Community attributes\n")
5715
5716 /* neighbor soft-reconfig. */
5717 DEFUN (neighbor_soft_reconfiguration,
5718 neighbor_soft_reconfiguration_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Per neighbor soft reconfiguration\n"
5723 "Allow inbound soft reconfiguration for this neighbor\n")
5724 {
5725 int idx_peer = 1;
5726 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5727 bgp_node_safi(vty),
5728 PEER_FLAG_SOFT_RECONFIG);
5729 }
5730
5731 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5732 neighbor_soft_reconfiguration_hidden_cmd,
5733 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5734 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5735 "Per neighbor soft reconfiguration\n"
5736 "Allow inbound soft reconfiguration for this neighbor\n")
5737
5738 DEFUN (no_neighbor_soft_reconfiguration,
5739 no_neighbor_soft_reconfiguration_cmd,
5740 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5741 NO_STR
5742 NEIGHBOR_STR
5743 NEIGHBOR_ADDR_STR2
5744 "Per neighbor soft reconfiguration\n"
5745 "Allow inbound soft reconfiguration for this neighbor\n")
5746 {
5747 int idx_peer = 2;
5748 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5749 bgp_node_afi(vty), bgp_node_safi(vty),
5750 PEER_FLAG_SOFT_RECONFIG);
5751 }
5752
5753 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5754 no_neighbor_soft_reconfiguration_hidden_cmd,
5755 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5756 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5757 "Per neighbor soft reconfiguration\n"
5758 "Allow inbound soft reconfiguration for this neighbor\n")
5759
5760 DEFUN (neighbor_route_reflector_client,
5761 neighbor_route_reflector_client_cmd,
5762 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5763 NEIGHBOR_STR
5764 NEIGHBOR_ADDR_STR2
5765 "Configure a neighbor as Route Reflector client\n")
5766 {
5767 int idx_peer = 1;
5768 struct peer *peer;
5769
5770
5771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5772 if (!peer)
5773 return CMD_WARNING_CONFIG_FAILED;
5774
5775 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5776 bgp_node_safi(vty),
5777 PEER_FLAG_REFLECTOR_CLIENT);
5778 }
5779
5780 ALIAS_HIDDEN(neighbor_route_reflector_client,
5781 neighbor_route_reflector_client_hidden_cmd,
5782 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5783 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5784 "Configure a neighbor as Route Reflector client\n")
5785
5786 DEFUN (no_neighbor_route_reflector_client,
5787 no_neighbor_route_reflector_client_cmd,
5788 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5789 NO_STR
5790 NEIGHBOR_STR
5791 NEIGHBOR_ADDR_STR2
5792 "Configure a neighbor as Route Reflector client\n")
5793 {
5794 int idx_peer = 2;
5795 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5796 bgp_node_afi(vty), bgp_node_safi(vty),
5797 PEER_FLAG_REFLECTOR_CLIENT);
5798 }
5799
5800 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5801 no_neighbor_route_reflector_client_hidden_cmd,
5802 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5803 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5804 "Configure a neighbor as Route Reflector client\n")
5805
5806 /* neighbor route-server-client. */
5807 DEFUN (neighbor_route_server_client,
5808 neighbor_route_server_client_cmd,
5809 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5810 NEIGHBOR_STR
5811 NEIGHBOR_ADDR_STR2
5812 "Configure a neighbor as Route Server client\n")
5813 {
5814 int idx_peer = 1;
5815 struct peer *peer;
5816
5817 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5818 if (!peer)
5819 return CMD_WARNING_CONFIG_FAILED;
5820 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5821 bgp_node_safi(vty),
5822 PEER_FLAG_RSERVER_CLIENT);
5823 }
5824
5825 ALIAS_HIDDEN(neighbor_route_server_client,
5826 neighbor_route_server_client_hidden_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5829 "Configure a neighbor as Route Server client\n")
5830
5831 DEFUN (no_neighbor_route_server_client,
5832 no_neighbor_route_server_client_cmd,
5833 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5834 NO_STR
5835 NEIGHBOR_STR
5836 NEIGHBOR_ADDR_STR2
5837 "Configure a neighbor as Route Server client\n")
5838 {
5839 int idx_peer = 2;
5840 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5841 bgp_node_afi(vty), bgp_node_safi(vty),
5842 PEER_FLAG_RSERVER_CLIENT);
5843 }
5844
5845 ALIAS_HIDDEN(no_neighbor_route_server_client,
5846 no_neighbor_route_server_client_hidden_cmd,
5847 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5849 "Configure a neighbor as Route Server client\n")
5850
5851 DEFUN (neighbor_nexthop_local_unchanged,
5852 neighbor_nexthop_local_unchanged_cmd,
5853 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5854 NEIGHBOR_STR
5855 NEIGHBOR_ADDR_STR2
5856 "Configure treatment of outgoing link-local nexthop attribute\n"
5857 "Leave link-local nexthop unchanged for this peer\n")
5858 {
5859 int idx_peer = 1;
5860 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5861 bgp_node_safi(vty),
5862 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5863 }
5864
5865 DEFUN (no_neighbor_nexthop_local_unchanged,
5866 no_neighbor_nexthop_local_unchanged_cmd,
5867 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
5868 NO_STR
5869 NEIGHBOR_STR
5870 NEIGHBOR_ADDR_STR2
5871 "Configure treatment of outgoing link-local-nexthop attribute\n"
5872 "Leave link-local nexthop unchanged for this peer\n")
5873 {
5874 int idx_peer = 2;
5875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5876 bgp_node_afi(vty), bgp_node_safi(vty),
5877 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
5878 }
5879
5880 DEFUN (neighbor_attr_unchanged,
5881 neighbor_attr_unchanged_cmd,
5882 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5883 NEIGHBOR_STR
5884 NEIGHBOR_ADDR_STR2
5885 "BGP attribute is propagated unchanged to this neighbor\n"
5886 "As-path attribute\n"
5887 "Nexthop attribute\n"
5888 "Med attribute\n")
5889 {
5890 int idx = 0;
5891 char *peer_str = argv[1]->arg;
5892 struct peer *peer;
5893 bool aspath = false;
5894 bool nexthop = false;
5895 bool med = false;
5896 afi_t afi = bgp_node_afi(vty);
5897 safi_t safi = bgp_node_safi(vty);
5898 int ret = 0;
5899
5900 peer = peer_and_group_lookup_vty(vty, peer_str);
5901 if (!peer)
5902 return CMD_WARNING_CONFIG_FAILED;
5903
5904 if (argv_find(argv, argc, "as-path", &idx))
5905 aspath = true;
5906
5907 idx = 0;
5908 if (argv_find(argv, argc, "next-hop", &idx))
5909 nexthop = true;
5910
5911 idx = 0;
5912 if (argv_find(argv, argc, "med", &idx))
5913 med = true;
5914
5915 /* no flags means all of them! */
5916 if (!aspath && !nexthop && !med) {
5917 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5918 PEER_FLAG_AS_PATH_UNCHANGED);
5919 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5920 PEER_FLAG_NEXTHOP_UNCHANGED);
5921 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5922 PEER_FLAG_MED_UNCHANGED);
5923 } else {
5924 if (!aspath) {
5925 if (peer_af_flag_check(peer, afi, safi,
5926 PEER_FLAG_AS_PATH_UNCHANGED)) {
5927 ret |= peer_af_flag_unset_vty(
5928 vty, peer_str, afi, safi,
5929 PEER_FLAG_AS_PATH_UNCHANGED);
5930 }
5931 } else
5932 ret |= peer_af_flag_set_vty(
5933 vty, peer_str, afi, safi,
5934 PEER_FLAG_AS_PATH_UNCHANGED);
5935
5936 if (!nexthop) {
5937 if (peer_af_flag_check(peer, afi, safi,
5938 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5939 ret |= peer_af_flag_unset_vty(
5940 vty, peer_str, afi, safi,
5941 PEER_FLAG_NEXTHOP_UNCHANGED);
5942 }
5943 } else
5944 ret |= peer_af_flag_set_vty(
5945 vty, peer_str, afi, safi,
5946 PEER_FLAG_NEXTHOP_UNCHANGED);
5947
5948 if (!med) {
5949 if (peer_af_flag_check(peer, afi, safi,
5950 PEER_FLAG_MED_UNCHANGED)) {
5951 ret |= peer_af_flag_unset_vty(
5952 vty, peer_str, afi, safi,
5953 PEER_FLAG_MED_UNCHANGED);
5954 }
5955 } else
5956 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5957 PEER_FLAG_MED_UNCHANGED);
5958 }
5959
5960 return ret;
5961 }
5962
5963 ALIAS_HIDDEN(
5964 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "BGP attribute is propagated unchanged to this neighbor\n"
5968 "As-path attribute\n"
5969 "Nexthop attribute\n"
5970 "Med attribute\n")
5971
5972 DEFUN (no_neighbor_attr_unchanged,
5973 no_neighbor_attr_unchanged_cmd,
5974 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5975 NO_STR
5976 NEIGHBOR_STR
5977 NEIGHBOR_ADDR_STR2
5978 "BGP attribute is propagated unchanged to this neighbor\n"
5979 "As-path attribute\n"
5980 "Nexthop attribute\n"
5981 "Med attribute\n")
5982 {
5983 int idx = 0;
5984 char *peer_str = argv[2]->arg;
5985 struct peer *peer;
5986 bool aspath = false;
5987 bool nexthop = false;
5988 bool med = false;
5989 afi_t afi = bgp_node_afi(vty);
5990 safi_t safi = bgp_node_safi(vty);
5991 int ret = 0;
5992
5993 peer = peer_and_group_lookup_vty(vty, peer_str);
5994 if (!peer)
5995 return CMD_WARNING_CONFIG_FAILED;
5996
5997 if (argv_find(argv, argc, "as-path", &idx))
5998 aspath = true;
5999
6000 idx = 0;
6001 if (argv_find(argv, argc, "next-hop", &idx))
6002 nexthop = true;
6003
6004 idx = 0;
6005 if (argv_find(argv, argc, "med", &idx))
6006 med = true;
6007
6008 if (!aspath && !nexthop && !med) // no flags means all of them!
6009 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6010 PEER_FLAG_AS_PATH_UNCHANGED)
6011 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6012 PEER_FLAG_NEXTHOP_UNCHANGED)
6013 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6014 PEER_FLAG_MED_UNCHANGED);
6015
6016 if (aspath)
6017 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6018 PEER_FLAG_AS_PATH_UNCHANGED);
6019
6020 if (nexthop)
6021 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6022 PEER_FLAG_NEXTHOP_UNCHANGED);
6023
6024 if (med)
6025 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6026 PEER_FLAG_MED_UNCHANGED);
6027
6028 return ret;
6029 }
6030
6031 ALIAS_HIDDEN(
6032 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6033 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6034 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6035 "BGP attribute is propagated unchanged to this neighbor\n"
6036 "As-path attribute\n"
6037 "Nexthop attribute\n"
6038 "Med attribute\n")
6039
6040 /* EBGP multihop configuration. */
6041 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6042 const char *ttl_str)
6043 {
6044 struct peer *peer;
6045 unsigned int ttl;
6046
6047 peer = peer_and_group_lookup_vty(vty, ip_str);
6048 if (!peer)
6049 return CMD_WARNING_CONFIG_FAILED;
6050
6051 if (peer->conf_if)
6052 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6053
6054 if (!ttl_str)
6055 ttl = MAXTTL;
6056 else
6057 ttl = strtoul(ttl_str, NULL, 10);
6058
6059 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6060 }
6061
6062 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6063 {
6064 struct peer *peer;
6065
6066 peer = peer_and_group_lookup_vty(vty, ip_str);
6067 if (!peer)
6068 return CMD_WARNING_CONFIG_FAILED;
6069
6070 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6071 }
6072
6073 /* neighbor ebgp-multihop. */
6074 DEFUN (neighbor_ebgp_multihop,
6075 neighbor_ebgp_multihop_cmd,
6076 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6077 NEIGHBOR_STR
6078 NEIGHBOR_ADDR_STR2
6079 "Allow EBGP neighbors not on directly connected networks\n")
6080 {
6081 int idx_peer = 1;
6082 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6083 }
6084
6085 DEFUN (neighbor_ebgp_multihop_ttl,
6086 neighbor_ebgp_multihop_ttl_cmd,
6087 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6088 NEIGHBOR_STR
6089 NEIGHBOR_ADDR_STR2
6090 "Allow EBGP neighbors not on directly connected networks\n"
6091 "maximum hop count\n")
6092 {
6093 int idx_peer = 1;
6094 int idx_number = 3;
6095 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6096 argv[idx_number]->arg);
6097 }
6098
6099 DEFUN (no_neighbor_ebgp_multihop,
6100 no_neighbor_ebgp_multihop_cmd,
6101 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6102 NO_STR
6103 NEIGHBOR_STR
6104 NEIGHBOR_ADDR_STR2
6105 "Allow EBGP neighbors not on directly connected networks\n"
6106 "maximum hop count\n")
6107 {
6108 int idx_peer = 2;
6109 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6110 }
6111
6112
6113 /* disable-connected-check */
6114 DEFUN (neighbor_disable_connected_check,
6115 neighbor_disable_connected_check_cmd,
6116 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "one-hop away EBGP peer using loopback address\n"
6120 "Enforce EBGP neighbors perform multihop\n")
6121 {
6122 int idx_peer = 1;
6123 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6124 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6125 }
6126
6127 DEFUN (no_neighbor_disable_connected_check,
6128 no_neighbor_disable_connected_check_cmd,
6129 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6130 NO_STR
6131 NEIGHBOR_STR
6132 NEIGHBOR_ADDR_STR2
6133 "one-hop away EBGP peer using loopback address\n"
6134 "Enforce EBGP neighbors perform multihop\n")
6135 {
6136 int idx_peer = 2;
6137 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6138 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6139 }
6140
6141
6142 /* enforce-first-as */
6143 DEFUN (neighbor_enforce_first_as,
6144 neighbor_enforce_first_as_cmd,
6145 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6146 NEIGHBOR_STR
6147 NEIGHBOR_ADDR_STR2
6148 "Enforce the first AS for EBGP routes\n")
6149 {
6150 int idx_peer = 1;
6151
6152 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6153 PEER_FLAG_ENFORCE_FIRST_AS);
6154 }
6155
6156 DEFUN (no_neighbor_enforce_first_as,
6157 no_neighbor_enforce_first_as_cmd,
6158 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6159 NO_STR
6160 NEIGHBOR_STR
6161 NEIGHBOR_ADDR_STR2
6162 "Enforce the first AS for EBGP routes\n")
6163 {
6164 int idx_peer = 2;
6165
6166 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6167 PEER_FLAG_ENFORCE_FIRST_AS);
6168 }
6169
6170
6171 DEFUN (neighbor_description,
6172 neighbor_description_cmd,
6173 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
6176 "Neighbor specific description\n"
6177 "Up to 80 characters describing this neighbor\n")
6178 {
6179 int idx_peer = 1;
6180 int idx_line = 3;
6181 struct peer *peer;
6182 char *str;
6183
6184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6185 if (!peer)
6186 return CMD_WARNING_CONFIG_FAILED;
6187
6188 str = argv_concat(argv, argc, idx_line);
6189
6190 peer_description_set(peer, str);
6191
6192 XFREE(MTYPE_TMP, str);
6193
6194 return CMD_SUCCESS;
6195 }
6196
6197 DEFUN (no_neighbor_description,
6198 no_neighbor_description_cmd,
6199 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6200 NO_STR
6201 NEIGHBOR_STR
6202 NEIGHBOR_ADDR_STR2
6203 "Neighbor specific description\n")
6204 {
6205 int idx_peer = 2;
6206 struct peer *peer;
6207
6208 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6209 if (!peer)
6210 return CMD_WARNING_CONFIG_FAILED;
6211
6212 peer_description_unset(peer);
6213
6214 return CMD_SUCCESS;
6215 }
6216
6217 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6218 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6219 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6220 "Neighbor specific description\n"
6221 "Up to 80 characters describing this neighbor\n")
6222
6223 /* Neighbor update-source. */
6224 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6225 const char *source_str)
6226 {
6227 struct peer *peer;
6228 struct prefix p;
6229 union sockunion su;
6230
6231 peer = peer_and_group_lookup_vty(vty, peer_str);
6232 if (!peer)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 if (peer->conf_if)
6236 return CMD_WARNING;
6237
6238 if (source_str) {
6239 if (str2sockunion(source_str, &su) == 0)
6240 peer_update_source_addr_set(peer, &su);
6241 else {
6242 if (str2prefix(source_str, &p)) {
6243 vty_out(vty,
6244 "%% Invalid update-source, remove prefix length \n");
6245 return CMD_WARNING_CONFIG_FAILED;
6246 } else
6247 peer_update_source_if_set(peer, source_str);
6248 }
6249 } else
6250 peer_update_source_unset(peer);
6251
6252 return CMD_SUCCESS;
6253 }
6254
6255 #define BGP_UPDATE_SOURCE_HELP_STR \
6256 "IPv4 address\n" \
6257 "IPv6 address\n" \
6258 "Interface name (requires zebra to be running)\n"
6259
6260 DEFUN (neighbor_update_source,
6261 neighbor_update_source_cmd,
6262 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6263 NEIGHBOR_STR
6264 NEIGHBOR_ADDR_STR2
6265 "Source of routing updates\n"
6266 BGP_UPDATE_SOURCE_HELP_STR)
6267 {
6268 int idx_peer = 1;
6269 int idx_peer_2 = 3;
6270 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6271 argv[idx_peer_2]->arg);
6272 }
6273
6274 DEFUN (no_neighbor_update_source,
6275 no_neighbor_update_source_cmd,
6276 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6277 NO_STR
6278 NEIGHBOR_STR
6279 NEIGHBOR_ADDR_STR2
6280 "Source of routing updates\n"
6281 BGP_UPDATE_SOURCE_HELP_STR)
6282 {
6283 int idx_peer = 2;
6284 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6285 }
6286
6287 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6288 afi_t afi, safi_t safi,
6289 const char *rmap, int set)
6290 {
6291 int ret;
6292 struct peer *peer;
6293 struct route_map *route_map = NULL;
6294
6295 peer = peer_and_group_lookup_vty(vty, peer_str);
6296 if (!peer)
6297 return CMD_WARNING_CONFIG_FAILED;
6298
6299 if (set) {
6300 if (rmap)
6301 route_map = route_map_lookup_warn_noexist(vty, rmap);
6302 ret = peer_default_originate_set(peer, afi, safi,
6303 rmap, route_map);
6304 } else
6305 ret = peer_default_originate_unset(peer, afi, safi);
6306
6307 return bgp_vty_return(vty, ret);
6308 }
6309
6310 /* neighbor default-originate. */
6311 DEFUN (neighbor_default_originate,
6312 neighbor_default_originate_cmd,
6313 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6314 NEIGHBOR_STR
6315 NEIGHBOR_ADDR_STR2
6316 "Originate default route to this neighbor\n")
6317 {
6318 int idx_peer = 1;
6319 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6320 bgp_node_afi(vty),
6321 bgp_node_safi(vty), NULL, 1);
6322 }
6323
6324 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6325 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6327 "Originate default route to this neighbor\n")
6328
6329 DEFUN (neighbor_default_originate_rmap,
6330 neighbor_default_originate_rmap_cmd,
6331 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6332 NEIGHBOR_STR
6333 NEIGHBOR_ADDR_STR2
6334 "Originate default route to this neighbor\n"
6335 "Route-map to specify criteria to originate default\n"
6336 "route-map name\n")
6337 {
6338 int idx_peer = 1;
6339 int idx_word = 4;
6340 return peer_default_originate_set_vty(
6341 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6342 argv[idx_word]->arg, 1);
6343 }
6344
6345 ALIAS_HIDDEN(
6346 neighbor_default_originate_rmap,
6347 neighbor_default_originate_rmap_hidden_cmd,
6348 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6349 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6350 "Originate default route to this neighbor\n"
6351 "Route-map to specify criteria to originate default\n"
6352 "route-map name\n")
6353
6354 DEFUN (no_neighbor_default_originate,
6355 no_neighbor_default_originate_cmd,
6356 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6357 NO_STR
6358 NEIGHBOR_STR
6359 NEIGHBOR_ADDR_STR2
6360 "Originate default route to this neighbor\n"
6361 "Route-map to specify criteria to originate default\n"
6362 "route-map name\n")
6363 {
6364 int idx_peer = 2;
6365 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6366 bgp_node_afi(vty),
6367 bgp_node_safi(vty), NULL, 0);
6368 }
6369
6370 ALIAS_HIDDEN(
6371 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6372 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6373 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6374 "Originate default route to this neighbor\n"
6375 "Route-map to specify criteria to originate default\n"
6376 "route-map name\n")
6377
6378
6379 /* Set neighbor's BGP port. */
6380 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6381 const char *port_str)
6382 {
6383 struct peer *peer;
6384 uint16_t port;
6385 struct servent *sp;
6386
6387 peer = peer_lookup_vty(vty, ip_str);
6388 if (!peer)
6389 return CMD_WARNING_CONFIG_FAILED;
6390
6391 if (!port_str) {
6392 sp = getservbyname("bgp", "tcp");
6393 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6394 } else {
6395 port = strtoul(port_str, NULL, 10);
6396 }
6397
6398 peer_port_set(peer, port);
6399
6400 return CMD_SUCCESS;
6401 }
6402
6403 /* Set specified peer's BGP port. */
6404 DEFUN (neighbor_port,
6405 neighbor_port_cmd,
6406 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6407 NEIGHBOR_STR
6408 NEIGHBOR_ADDR_STR
6409 "Neighbor's BGP port\n"
6410 "TCP port number\n")
6411 {
6412 int idx_ip = 1;
6413 int idx_number = 3;
6414 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6415 argv[idx_number]->arg);
6416 }
6417
6418 DEFUN (no_neighbor_port,
6419 no_neighbor_port_cmd,
6420 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR
6424 "Neighbor's BGP port\n"
6425 "TCP port number\n")
6426 {
6427 int idx_ip = 2;
6428 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6429 }
6430
6431
6432 /* neighbor weight. */
6433 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6434 safi_t safi, const char *weight_str)
6435 {
6436 int ret;
6437 struct peer *peer;
6438 unsigned long weight;
6439
6440 peer = peer_and_group_lookup_vty(vty, ip_str);
6441 if (!peer)
6442 return CMD_WARNING_CONFIG_FAILED;
6443
6444 weight = strtoul(weight_str, NULL, 10);
6445
6446 ret = peer_weight_set(peer, afi, safi, weight);
6447 return bgp_vty_return(vty, ret);
6448 }
6449
6450 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6451 safi_t safi)
6452 {
6453 int ret;
6454 struct peer *peer;
6455
6456 peer = peer_and_group_lookup_vty(vty, ip_str);
6457 if (!peer)
6458 return CMD_WARNING_CONFIG_FAILED;
6459
6460 ret = peer_weight_unset(peer, afi, safi);
6461 return bgp_vty_return(vty, ret);
6462 }
6463
6464 DEFUN (neighbor_weight,
6465 neighbor_weight_cmd,
6466 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6467 NEIGHBOR_STR
6468 NEIGHBOR_ADDR_STR2
6469 "Set default weight for routes from this neighbor\n"
6470 "default weight\n")
6471 {
6472 int idx_peer = 1;
6473 int idx_number = 3;
6474 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6475 bgp_node_safi(vty), argv[idx_number]->arg);
6476 }
6477
6478 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6479 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6480 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6481 "Set default weight for routes from this neighbor\n"
6482 "default weight\n")
6483
6484 DEFUN (no_neighbor_weight,
6485 no_neighbor_weight_cmd,
6486 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6487 NO_STR
6488 NEIGHBOR_STR
6489 NEIGHBOR_ADDR_STR2
6490 "Set default weight for routes from this neighbor\n"
6491 "default weight\n")
6492 {
6493 int idx_peer = 2;
6494 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6495 bgp_node_afi(vty), bgp_node_safi(vty));
6496 }
6497
6498 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6499 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6500 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6501 "Set default weight for routes from this neighbor\n"
6502 "default weight\n")
6503
6504
6505 /* Override capability negotiation. */
6506 DEFUN (neighbor_override_capability,
6507 neighbor_override_capability_cmd,
6508 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6509 NEIGHBOR_STR
6510 NEIGHBOR_ADDR_STR2
6511 "Override capability negotiation result\n")
6512 {
6513 int idx_peer = 1;
6514 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6515 PEER_FLAG_OVERRIDE_CAPABILITY);
6516 }
6517
6518 DEFUN (no_neighbor_override_capability,
6519 no_neighbor_override_capability_cmd,
6520 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6521 NO_STR
6522 NEIGHBOR_STR
6523 NEIGHBOR_ADDR_STR2
6524 "Override capability negotiation result\n")
6525 {
6526 int idx_peer = 2;
6527 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6528 PEER_FLAG_OVERRIDE_CAPABILITY);
6529 }
6530
6531 DEFUN (neighbor_strict_capability,
6532 neighbor_strict_capability_cmd,
6533 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6534 NEIGHBOR_STR
6535 NEIGHBOR_ADDR_STR2
6536 "Strict capability negotiation match\n")
6537 {
6538 int idx_peer = 1;
6539
6540 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6541 PEER_FLAG_STRICT_CAP_MATCH);
6542 }
6543
6544 DEFUN (no_neighbor_strict_capability,
6545 no_neighbor_strict_capability_cmd,
6546 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6547 NO_STR
6548 NEIGHBOR_STR
6549 NEIGHBOR_ADDR_STR2
6550 "Strict capability negotiation match\n")
6551 {
6552 int idx_peer = 2;
6553
6554 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6555 PEER_FLAG_STRICT_CAP_MATCH);
6556 }
6557
6558 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6559 const char *keep_str, const char *hold_str)
6560 {
6561 int ret;
6562 struct peer *peer;
6563 uint32_t keepalive;
6564 uint32_t holdtime;
6565
6566 peer = peer_and_group_lookup_vty(vty, ip_str);
6567 if (!peer)
6568 return CMD_WARNING_CONFIG_FAILED;
6569
6570 keepalive = strtoul(keep_str, NULL, 10);
6571 holdtime = strtoul(hold_str, NULL, 10);
6572
6573 ret = peer_timers_set(peer, keepalive, holdtime);
6574
6575 return bgp_vty_return(vty, ret);
6576 }
6577
6578 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
6579 {
6580 int ret;
6581 struct peer *peer;
6582
6583 peer = peer_and_group_lookup_vty(vty, ip_str);
6584 if (!peer)
6585 return CMD_WARNING_CONFIG_FAILED;
6586
6587 ret = peer_timers_unset(peer);
6588
6589 return bgp_vty_return(vty, ret);
6590 }
6591
6592 DEFUN (neighbor_timers,
6593 neighbor_timers_cmd,
6594 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6595 NEIGHBOR_STR
6596 NEIGHBOR_ADDR_STR2
6597 "BGP per neighbor timers\n"
6598 "Keepalive interval\n"
6599 "Holdtime\n")
6600 {
6601 int idx_peer = 1;
6602 int idx_number = 3;
6603 int idx_number_2 = 4;
6604 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6605 argv[idx_number]->arg,
6606 argv[idx_number_2]->arg);
6607 }
6608
6609 DEFUN (no_neighbor_timers,
6610 no_neighbor_timers_cmd,
6611 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6612 NO_STR
6613 NEIGHBOR_STR
6614 NEIGHBOR_ADDR_STR2
6615 "BGP per neighbor timers\n"
6616 "Keepalive interval\n"
6617 "Holdtime\n")
6618 {
6619 int idx_peer = 2;
6620 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6621 }
6622
6623
6624 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6625 const char *time_str)
6626 {
6627 int ret;
6628 struct peer *peer;
6629 uint32_t connect;
6630
6631 peer = peer_and_group_lookup_vty(vty, ip_str);
6632 if (!peer)
6633 return CMD_WARNING_CONFIG_FAILED;
6634
6635 connect = strtoul(time_str, NULL, 10);
6636
6637 ret = peer_timers_connect_set(peer, connect);
6638
6639 return bgp_vty_return(vty, ret);
6640 }
6641
6642 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
6643 {
6644 int ret;
6645 struct peer *peer;
6646
6647 peer = peer_and_group_lookup_vty(vty, ip_str);
6648 if (!peer)
6649 return CMD_WARNING_CONFIG_FAILED;
6650
6651 ret = peer_timers_connect_unset(peer);
6652
6653 return bgp_vty_return(vty, ret);
6654 }
6655
6656 DEFUN (neighbor_timers_connect,
6657 neighbor_timers_connect_cmd,
6658 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6659 NEIGHBOR_STR
6660 NEIGHBOR_ADDR_STR2
6661 "BGP per neighbor timers\n"
6662 "BGP connect timer\n"
6663 "Connect timer\n")
6664 {
6665 int idx_peer = 1;
6666 int idx_number = 4;
6667 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6668 argv[idx_number]->arg);
6669 }
6670
6671 DEFUN (no_neighbor_timers_connect,
6672 no_neighbor_timers_connect_cmd,
6673 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6674 NO_STR
6675 NEIGHBOR_STR
6676 NEIGHBOR_ADDR_STR2
6677 "BGP per neighbor timers\n"
6678 "BGP connect timer\n"
6679 "Connect timer\n")
6680 {
6681 int idx_peer = 2;
6682 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
6683 }
6684
6685 DEFPY (neighbor_timers_delayopen,
6686 neighbor_timers_delayopen_cmd,
6687 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6688 NEIGHBOR_STR
6689 NEIGHBOR_ADDR_STR2
6690 "BGP per neighbor timers\n"
6691 "RFC 4271 DelayOpenTimer\n"
6692 "DelayOpenTime timer interval\n")
6693 {
6694 struct peer *peer;
6695
6696 peer = peer_and_group_lookup_vty(vty, neighbor);
6697 if (!peer)
6698 return CMD_WARNING_CONFIG_FAILED;
6699
6700 if (!interval) {
6701 if (peer_timers_delayopen_unset(peer))
6702 return CMD_WARNING_CONFIG_FAILED;
6703 } else {
6704 if (peer_timers_delayopen_set(peer, interval))
6705 return CMD_WARNING_CONFIG_FAILED;
6706 }
6707
6708 return CMD_SUCCESS;
6709 }
6710
6711 DEFPY (no_neighbor_timers_delayopen,
6712 no_neighbor_timers_delayopen_cmd,
6713 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6714 NO_STR
6715 NEIGHBOR_STR
6716 NEIGHBOR_ADDR_STR2
6717 "BGP per neighbor timers\n"
6718 "RFC 4271 DelayOpenTimer\n"
6719 "DelayOpenTime timer interval\n")
6720 {
6721 struct peer *peer;
6722
6723 peer = peer_and_group_lookup_vty(vty, neighbor);
6724 if (!peer)
6725 return CMD_WARNING_CONFIG_FAILED;
6726
6727 if (peer_timers_delayopen_unset(peer))
6728 return CMD_WARNING_CONFIG_FAILED;
6729
6730 return CMD_SUCCESS;
6731 }
6732
6733 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6734 const char *time_str, int set)
6735 {
6736 int ret;
6737 struct peer *peer;
6738 uint32_t routeadv = 0;
6739
6740 peer = peer_and_group_lookup_vty(vty, ip_str);
6741 if (!peer)
6742 return CMD_WARNING_CONFIG_FAILED;
6743
6744 if (time_str)
6745 routeadv = strtoul(time_str, NULL, 10);
6746
6747 if (set)
6748 ret = peer_advertise_interval_set(peer, routeadv);
6749 else
6750 ret = peer_advertise_interval_unset(peer);
6751
6752 return bgp_vty_return(vty, ret);
6753 }
6754
6755 DEFUN (neighbor_advertise_interval,
6756 neighbor_advertise_interval_cmd,
6757 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6758 NEIGHBOR_STR
6759 NEIGHBOR_ADDR_STR2
6760 "Minimum interval between sending BGP routing updates\n"
6761 "time in seconds\n")
6762 {
6763 int idx_peer = 1;
6764 int idx_number = 3;
6765 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6766 argv[idx_number]->arg, 1);
6767 }
6768
6769 DEFUN (no_neighbor_advertise_interval,
6770 no_neighbor_advertise_interval_cmd,
6771 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6772 NO_STR
6773 NEIGHBOR_STR
6774 NEIGHBOR_ADDR_STR2
6775 "Minimum interval between sending BGP routing updates\n"
6776 "time in seconds\n")
6777 {
6778 int idx_peer = 2;
6779 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
6780 }
6781
6782
6783 /* Time to wait before processing route-map updates */
6784 DEFUN (bgp_set_route_map_delay_timer,
6785 bgp_set_route_map_delay_timer_cmd,
6786 "bgp route-map delay-timer (0-600)",
6787 SET_STR
6788 "BGP route-map delay timer\n"
6789 "Time in secs to wait before processing route-map changes\n"
6790 "0 disables the timer, no route updates happen when route-maps change\n")
6791 {
6792 int idx_number = 3;
6793 uint32_t rmap_delay_timer;
6794
6795 if (argv[idx_number]->arg) {
6796 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6797 bm->rmap_update_timer = rmap_delay_timer;
6798
6799 /* if the dynamic update handling is being disabled, and a timer
6800 * is
6801 * running, stop the timer and act as if the timer has already
6802 * fired.
6803 */
6804 if (!rmap_delay_timer && bm->t_rmap_update) {
6805 BGP_TIMER_OFF(bm->t_rmap_update);
6806 thread_execute(bm->master, bgp_route_map_update_timer,
6807 NULL, 0);
6808 }
6809 return CMD_SUCCESS;
6810 } else {
6811 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6812 return CMD_WARNING_CONFIG_FAILED;
6813 }
6814 }
6815
6816 DEFUN (no_bgp_set_route_map_delay_timer,
6817 no_bgp_set_route_map_delay_timer_cmd,
6818 "no bgp route-map delay-timer [(0-600)]",
6819 NO_STR
6820 BGP_STR
6821 "Default BGP route-map delay timer\n"
6822 "Reset to default time to wait for processing route-map changes\n"
6823 "0 disables the timer, no route updates happen when route-maps change\n")
6824 {
6825
6826 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
6827
6828 return CMD_SUCCESS;
6829 }
6830
6831 /* neighbor interface */
6832 static int peer_interface_vty(struct vty *vty, const char *ip_str,
6833 const char *str)
6834 {
6835 struct peer *peer;
6836
6837 peer = peer_lookup_vty(vty, ip_str);
6838 if (!peer || peer->conf_if) {
6839 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6840 return CMD_WARNING_CONFIG_FAILED;
6841 }
6842
6843 if (str)
6844 peer_interface_set(peer, str);
6845 else
6846 peer_interface_unset(peer);
6847
6848 return CMD_SUCCESS;
6849 }
6850
6851 DEFUN (neighbor_interface,
6852 neighbor_interface_cmd,
6853 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
6854 NEIGHBOR_STR
6855 NEIGHBOR_ADDR_STR
6856 "Interface\n"
6857 "Interface name\n")
6858 {
6859 int idx_ip = 1;
6860 int idx_word = 3;
6861 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
6862 }
6863
6864 DEFUN (no_neighbor_interface,
6865 no_neighbor_interface_cmd,
6866 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
6867 NO_STR
6868 NEIGHBOR_STR
6869 NEIGHBOR_ADDR_STR2
6870 "Interface\n"
6871 "Interface name\n")
6872 {
6873 int idx_peer = 2;
6874 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
6875 }
6876
6877 DEFUN (neighbor_distribute_list,
6878 neighbor_distribute_list_cmd,
6879 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6880 NEIGHBOR_STR
6881 NEIGHBOR_ADDR_STR2
6882 "Filter updates to/from this neighbor\n"
6883 "IP access-list number\n"
6884 "IP access-list number (expanded range)\n"
6885 "IP Access-list name\n"
6886 "Filter incoming updates\n"
6887 "Filter outgoing updates\n")
6888 {
6889 int idx_peer = 1;
6890 int idx_acl = 3;
6891 int direct, ret;
6892 struct peer *peer;
6893
6894 const char *pstr = argv[idx_peer]->arg;
6895 const char *acl = argv[idx_acl]->arg;
6896 const char *inout = argv[argc - 1]->text;
6897
6898 peer = peer_and_group_lookup_vty(vty, pstr);
6899 if (!peer)
6900 return CMD_WARNING_CONFIG_FAILED;
6901
6902 /* Check filter direction. */
6903 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6904 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6905 direct, acl);
6906
6907 return bgp_vty_return(vty, ret);
6908 }
6909
6910 ALIAS_HIDDEN(
6911 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6912 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6913 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6914 "Filter updates to/from this neighbor\n"
6915 "IP access-list number\n"
6916 "IP access-list number (expanded range)\n"
6917 "IP Access-list name\n"
6918 "Filter incoming updates\n"
6919 "Filter outgoing updates\n")
6920
6921 DEFUN (no_neighbor_distribute_list,
6922 no_neighbor_distribute_list_cmd,
6923 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6924 NO_STR
6925 NEIGHBOR_STR
6926 NEIGHBOR_ADDR_STR2
6927 "Filter updates to/from this neighbor\n"
6928 "IP access-list number\n"
6929 "IP access-list number (expanded range)\n"
6930 "IP Access-list name\n"
6931 "Filter incoming updates\n"
6932 "Filter outgoing updates\n")
6933 {
6934 int idx_peer = 2;
6935 int direct, ret;
6936 struct peer *peer;
6937
6938 const char *pstr = argv[idx_peer]->arg;
6939 const char *inout = argv[argc - 1]->text;
6940
6941 peer = peer_and_group_lookup_vty(vty, pstr);
6942 if (!peer)
6943 return CMD_WARNING_CONFIG_FAILED;
6944
6945 /* Check filter direction. */
6946 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6947 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6948 direct);
6949
6950 return bgp_vty_return(vty, ret);
6951 }
6952
6953 ALIAS_HIDDEN(
6954 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6955 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6957 "Filter updates to/from this neighbor\n"
6958 "IP access-list number\n"
6959 "IP access-list number (expanded range)\n"
6960 "IP Access-list name\n"
6961 "Filter incoming updates\n"
6962 "Filter outgoing updates\n")
6963
6964 /* Set prefix list to the peer. */
6965 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6966 afi_t afi, safi_t safi,
6967 const char *name_str,
6968 const char *direct_str)
6969 {
6970 int ret;
6971 int direct = FILTER_IN;
6972 struct peer *peer;
6973
6974 peer = peer_and_group_lookup_vty(vty, ip_str);
6975 if (!peer)
6976 return CMD_WARNING_CONFIG_FAILED;
6977
6978 /* Check filter direction. */
6979 if (strncmp(direct_str, "i", 1) == 0)
6980 direct = FILTER_IN;
6981 else if (strncmp(direct_str, "o", 1) == 0)
6982 direct = FILTER_OUT;
6983
6984 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
6985
6986 return bgp_vty_return(vty, ret);
6987 }
6988
6989 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6990 afi_t afi, safi_t safi,
6991 const char *direct_str)
6992 {
6993 int ret;
6994 struct peer *peer;
6995 int direct = FILTER_IN;
6996
6997 peer = peer_and_group_lookup_vty(vty, ip_str);
6998 if (!peer)
6999 return CMD_WARNING_CONFIG_FAILED;
7000
7001 /* Check filter direction. */
7002 if (strncmp(direct_str, "i", 1) == 0)
7003 direct = FILTER_IN;
7004 else if (strncmp(direct_str, "o", 1) == 0)
7005 direct = FILTER_OUT;
7006
7007 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7008
7009 return bgp_vty_return(vty, ret);
7010 }
7011
7012 DEFUN (neighbor_prefix_list,
7013 neighbor_prefix_list_cmd,
7014 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7015 NEIGHBOR_STR
7016 NEIGHBOR_ADDR_STR2
7017 "Filter updates to/from this neighbor\n"
7018 "Name of a prefix list\n"
7019 "Filter incoming updates\n"
7020 "Filter outgoing updates\n")
7021 {
7022 int idx_peer = 1;
7023 int idx_word = 3;
7024 int idx_in_out = 4;
7025 return peer_prefix_list_set_vty(
7026 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7027 argv[idx_word]->arg, argv[idx_in_out]->arg);
7028 }
7029
7030 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7031 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7032 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7033 "Filter updates to/from this neighbor\n"
7034 "Name of a prefix list\n"
7035 "Filter incoming updates\n"
7036 "Filter outgoing updates\n")
7037
7038 DEFUN (no_neighbor_prefix_list,
7039 no_neighbor_prefix_list_cmd,
7040 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7041 NO_STR
7042 NEIGHBOR_STR
7043 NEIGHBOR_ADDR_STR2
7044 "Filter updates to/from this neighbor\n"
7045 "Name of a prefix list\n"
7046 "Filter incoming updates\n"
7047 "Filter outgoing updates\n")
7048 {
7049 int idx_peer = 2;
7050 int idx_in_out = 5;
7051 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7052 bgp_node_afi(vty), bgp_node_safi(vty),
7053 argv[idx_in_out]->arg);
7054 }
7055
7056 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7057 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7058 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7059 "Filter updates to/from this neighbor\n"
7060 "Name of a prefix list\n"
7061 "Filter incoming updates\n"
7062 "Filter outgoing updates\n")
7063
7064 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7065 safi_t safi, const char *name_str,
7066 const char *direct_str)
7067 {
7068 int ret;
7069 struct peer *peer;
7070 int direct = FILTER_IN;
7071
7072 peer = peer_and_group_lookup_vty(vty, ip_str);
7073 if (!peer)
7074 return CMD_WARNING_CONFIG_FAILED;
7075
7076 /* Check filter direction. */
7077 if (strncmp(direct_str, "i", 1) == 0)
7078 direct = FILTER_IN;
7079 else if (strncmp(direct_str, "o", 1) == 0)
7080 direct = FILTER_OUT;
7081
7082 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7083
7084 return bgp_vty_return(vty, ret);
7085 }
7086
7087 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7088 safi_t safi, const char *direct_str)
7089 {
7090 int ret;
7091 struct peer *peer;
7092 int direct = FILTER_IN;
7093
7094 peer = peer_and_group_lookup_vty(vty, ip_str);
7095 if (!peer)
7096 return CMD_WARNING_CONFIG_FAILED;
7097
7098 /* Check filter direction. */
7099 if (strncmp(direct_str, "i", 1) == 0)
7100 direct = FILTER_IN;
7101 else if (strncmp(direct_str, "o", 1) == 0)
7102 direct = FILTER_OUT;
7103
7104 ret = peer_aslist_unset(peer, afi, safi, direct);
7105
7106 return bgp_vty_return(vty, ret);
7107 }
7108
7109 DEFUN (neighbor_filter_list,
7110 neighbor_filter_list_cmd,
7111 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7112 NEIGHBOR_STR
7113 NEIGHBOR_ADDR_STR2
7114 "Establish BGP filters\n"
7115 "AS path access-list name\n"
7116 "Filter incoming routes\n"
7117 "Filter outgoing routes\n")
7118 {
7119 int idx_peer = 1;
7120 int idx_word = 3;
7121 int idx_in_out = 4;
7122 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7123 bgp_node_safi(vty), argv[idx_word]->arg,
7124 argv[idx_in_out]->arg);
7125 }
7126
7127 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7128 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7130 "Establish BGP filters\n"
7131 "AS path access-list name\n"
7132 "Filter incoming routes\n"
7133 "Filter outgoing routes\n")
7134
7135 DEFUN (no_neighbor_filter_list,
7136 no_neighbor_filter_list_cmd,
7137 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7138 NO_STR
7139 NEIGHBOR_STR
7140 NEIGHBOR_ADDR_STR2
7141 "Establish BGP filters\n"
7142 "AS path access-list name\n"
7143 "Filter incoming routes\n"
7144 "Filter outgoing routes\n")
7145 {
7146 int idx_peer = 2;
7147 int idx_in_out = 5;
7148 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7149 bgp_node_afi(vty), bgp_node_safi(vty),
7150 argv[idx_in_out]->arg);
7151 }
7152
7153 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7154 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7155 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7156 "Establish BGP filters\n"
7157 "AS path access-list name\n"
7158 "Filter incoming routes\n"
7159 "Filter outgoing routes\n")
7160
7161 /* Set advertise-map to the peer. */
7162 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7163 afi_t afi, safi_t safi,
7164 const char *advertise_str,
7165 const char *condition_str, bool condition,
7166 bool set)
7167 {
7168 int ret = CMD_WARNING_CONFIG_FAILED;
7169 struct peer *peer;
7170 struct route_map *advertise_map;
7171 struct route_map *condition_map;
7172
7173 peer = peer_and_group_lookup_vty(vty, ip_str);
7174 if (!peer)
7175 return ret;
7176
7177 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7178 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7179
7180 if (set)
7181 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7182 advertise_map, condition_str,
7183 condition_map, condition);
7184 else
7185 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7186 advertise_map, condition_str,
7187 condition_map, condition);
7188
7189 return bgp_vty_return(vty, ret);
7190 }
7191
7192 DEFPY (bgp_condadv_period,
7193 bgp_condadv_period_cmd,
7194 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7195 NO_STR
7196 BGP_STR
7197 "Conditional advertisement settings\n"
7198 "Set period to rescan BGP table to check if condition is met\n"
7199 "Period between BGP table scans, in seconds; default 60\n")
7200 {
7201 VTY_DECLVAR_CONTEXT(bgp, bgp);
7202
7203 bgp->condition_check_period =
7204 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7205
7206 return CMD_SUCCESS;
7207 }
7208
7209 DEFPY (neighbor_advertise_map,
7210 neighbor_advertise_map_cmd,
7211 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7212 NO_STR
7213 NEIGHBOR_STR
7214 NEIGHBOR_ADDR_STR2
7215 "Route-map to conditionally advertise routes\n"
7216 "Name of advertise map\n"
7217 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7218 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7219 "Name of the exist or non exist map\n")
7220 {
7221 bool condition = CONDITION_EXIST;
7222
7223 if (!strcmp(exist, "non-exist-map"))
7224 condition = CONDITION_NON_EXIST;
7225
7226 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7227 bgp_node_safi(vty), advertise_str,
7228 condition_str, condition, !no);
7229 }
7230
7231 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7232 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7233 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7234 "Route-map to conditionally advertise routes\n"
7235 "Name of advertise map\n"
7236 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7237 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7238 "Name of the exist or non exist map\n")
7239
7240 /* Set route-map to the peer. */
7241 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7242 afi_t afi, safi_t safi, const char *name_str,
7243 const char *direct_str)
7244 {
7245 int ret;
7246 struct peer *peer;
7247 int direct = RMAP_IN;
7248 struct route_map *route_map;
7249
7250 peer = peer_and_group_lookup_vty(vty, ip_str);
7251 if (!peer)
7252 return CMD_WARNING_CONFIG_FAILED;
7253
7254 /* Check filter direction. */
7255 if (strncmp(direct_str, "in", 2) == 0)
7256 direct = RMAP_IN;
7257 else if (strncmp(direct_str, "o", 1) == 0)
7258 direct = RMAP_OUT;
7259
7260 route_map = route_map_lookup_warn_noexist(vty, name_str);
7261 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7262
7263 return bgp_vty_return(vty, ret);
7264 }
7265
7266 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7267 afi_t afi, safi_t safi,
7268 const char *direct_str)
7269 {
7270 int ret;
7271 struct peer *peer;
7272 int direct = RMAP_IN;
7273
7274 peer = peer_and_group_lookup_vty(vty, ip_str);
7275 if (!peer)
7276 return CMD_WARNING_CONFIG_FAILED;
7277
7278 /* Check filter direction. */
7279 if (strncmp(direct_str, "in", 2) == 0)
7280 direct = RMAP_IN;
7281 else if (strncmp(direct_str, "o", 1) == 0)
7282 direct = RMAP_OUT;
7283
7284 ret = peer_route_map_unset(peer, afi, safi, direct);
7285
7286 return bgp_vty_return(vty, ret);
7287 }
7288
7289 DEFUN (neighbor_route_map,
7290 neighbor_route_map_cmd,
7291 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7292 NEIGHBOR_STR
7293 NEIGHBOR_ADDR_STR2
7294 "Apply route map to neighbor\n"
7295 "Name of route map\n"
7296 "Apply map to incoming routes\n"
7297 "Apply map to outbound routes\n")
7298 {
7299 int idx_peer = 1;
7300 int idx_word = 3;
7301 int idx_in_out = 4;
7302 return peer_route_map_set_vty(
7303 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7304 argv[idx_word]->arg, argv[idx_in_out]->arg);
7305 }
7306
7307 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7308 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7309 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7310 "Apply route map to neighbor\n"
7311 "Name of route map\n"
7312 "Apply map to incoming routes\n"
7313 "Apply map to outbound routes\n")
7314
7315 DEFUN (no_neighbor_route_map,
7316 no_neighbor_route_map_cmd,
7317 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7318 NO_STR
7319 NEIGHBOR_STR
7320 NEIGHBOR_ADDR_STR2
7321 "Apply route map to neighbor\n"
7322 "Name of route map\n"
7323 "Apply map to incoming routes\n"
7324 "Apply map to outbound routes\n")
7325 {
7326 int idx_peer = 2;
7327 int idx_in_out = 5;
7328 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7329 bgp_node_afi(vty), bgp_node_safi(vty),
7330 argv[idx_in_out]->arg);
7331 }
7332
7333 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7334 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7335 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7336 "Apply route map to neighbor\n"
7337 "Name of route map\n"
7338 "Apply map to incoming routes\n"
7339 "Apply map to outbound routes\n")
7340
7341 /* Set unsuppress-map to the peer. */
7342 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7343 afi_t afi, safi_t safi,
7344 const char *name_str)
7345 {
7346 int ret;
7347 struct peer *peer;
7348 struct route_map *route_map;
7349
7350 peer = peer_and_group_lookup_vty(vty, ip_str);
7351 if (!peer)
7352 return CMD_WARNING_CONFIG_FAILED;
7353
7354 route_map = route_map_lookup_warn_noexist(vty, name_str);
7355 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7356
7357 return bgp_vty_return(vty, ret);
7358 }
7359
7360 /* Unset route-map from the peer. */
7361 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7362 afi_t afi, safi_t safi)
7363 {
7364 int ret;
7365 struct peer *peer;
7366
7367 peer = peer_and_group_lookup_vty(vty, ip_str);
7368 if (!peer)
7369 return CMD_WARNING_CONFIG_FAILED;
7370
7371 ret = peer_unsuppress_map_unset(peer, afi, safi);
7372
7373 return bgp_vty_return(vty, ret);
7374 }
7375
7376 DEFUN (neighbor_unsuppress_map,
7377 neighbor_unsuppress_map_cmd,
7378 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7379 NEIGHBOR_STR
7380 NEIGHBOR_ADDR_STR2
7381 "Route-map to selectively unsuppress suppressed routes\n"
7382 "Name of route map\n")
7383 {
7384 int idx_peer = 1;
7385 int idx_word = 3;
7386 return peer_unsuppress_map_set_vty(
7387 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7388 argv[idx_word]->arg);
7389 }
7390
7391 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7392 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7393 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7394 "Route-map to selectively unsuppress suppressed routes\n"
7395 "Name of route map\n")
7396
7397 DEFUN (no_neighbor_unsuppress_map,
7398 no_neighbor_unsuppress_map_cmd,
7399 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7400 NO_STR
7401 NEIGHBOR_STR
7402 NEIGHBOR_ADDR_STR2
7403 "Route-map to selectively unsuppress suppressed routes\n"
7404 "Name of route map\n")
7405 {
7406 int idx_peer = 2;
7407 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7408 bgp_node_afi(vty),
7409 bgp_node_safi(vty));
7410 }
7411
7412 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7413 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7414 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7415 "Route-map to selectively unsuppress suppressed routes\n"
7416 "Name of route map\n")
7417
7418 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7419 afi_t afi, safi_t safi,
7420 const char *num_str,
7421 const char *threshold_str, int warning,
7422 const char *restart_str,
7423 const char *force_str)
7424 {
7425 int ret;
7426 struct peer *peer;
7427 uint32_t max;
7428 uint8_t threshold;
7429 uint16_t restart;
7430
7431 peer = peer_and_group_lookup_vty(vty, ip_str);
7432 if (!peer)
7433 return CMD_WARNING_CONFIG_FAILED;
7434
7435 max = strtoul(num_str, NULL, 10);
7436 if (threshold_str)
7437 threshold = atoi(threshold_str);
7438 else
7439 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7440
7441 if (restart_str)
7442 restart = atoi(restart_str);
7443 else
7444 restart = 0;
7445
7446 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7447 restart, force_str ? true : false);
7448
7449 return bgp_vty_return(vty, ret);
7450 }
7451
7452 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7453 afi_t afi, safi_t safi)
7454 {
7455 int ret;
7456 struct peer *peer;
7457
7458 peer = peer_and_group_lookup_vty(vty, ip_str);
7459 if (!peer)
7460 return CMD_WARNING_CONFIG_FAILED;
7461
7462 ret = peer_maximum_prefix_unset(peer, afi, safi);
7463
7464 return bgp_vty_return(vty, ret);
7465 }
7466
7467 /* Maximum number of prefix to be sent to the neighbor. */
7468 DEFUN(neighbor_maximum_prefix_out,
7469 neighbor_maximum_prefix_out_cmd,
7470 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7471 NEIGHBOR_STR
7472 NEIGHBOR_ADDR_STR2
7473 "Maximum number of prefixes to be sent to this peer\n"
7474 "Maximum no. of prefix limit\n")
7475 {
7476 int idx_peer = 1;
7477 int idx_number = 3;
7478 struct peer *peer;
7479 uint32_t max;
7480 afi_t afi = bgp_node_afi(vty);
7481 safi_t safi = bgp_node_safi(vty);
7482
7483 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7484 if (!peer)
7485 return CMD_WARNING_CONFIG_FAILED;
7486
7487 max = strtoul(argv[idx_number]->arg, NULL, 10);
7488
7489 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7490 peer->pmax_out[afi][safi] = max;
7491
7492 return CMD_SUCCESS;
7493 }
7494
7495 DEFUN(no_neighbor_maximum_prefix_out,
7496 no_neighbor_maximum_prefix_out_cmd,
7497 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7498 NO_STR
7499 NEIGHBOR_STR
7500 NEIGHBOR_ADDR_STR2
7501 "Maximum number of prefixes to be sent to this peer\n")
7502 {
7503 int idx_peer = 2;
7504 struct peer *peer;
7505 afi_t afi = bgp_node_afi(vty);
7506 safi_t safi = bgp_node_safi(vty);
7507
7508 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7509 if (!peer)
7510 return CMD_WARNING_CONFIG_FAILED;
7511
7512 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7513 peer->pmax_out[afi][safi] = 0;
7514
7515 return CMD_SUCCESS;
7516 }
7517
7518 /* Maximum number of prefix configuration. Prefix count is different
7519 for each peer configuration. So this configuration can be set for
7520 each peer configuration. */
7521 DEFUN (neighbor_maximum_prefix,
7522 neighbor_maximum_prefix_cmd,
7523 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7524 NEIGHBOR_STR
7525 NEIGHBOR_ADDR_STR2
7526 "Maximum number of prefix accept from this peer\n"
7527 "maximum no. of prefix limit\n"
7528 "Force checking all received routes not only accepted\n")
7529 {
7530 int idx_peer = 1;
7531 int idx_number = 3;
7532 int idx_force = 0;
7533 char *force = NULL;
7534
7535 if (argv_find(argv, argc, "force", &idx_force))
7536 force = argv[idx_force]->arg;
7537
7538 return peer_maximum_prefix_set_vty(
7539 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7540 argv[idx_number]->arg, NULL, 0, NULL, force);
7541 }
7542
7543 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7544 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7546 "Maximum number of prefix accept from this peer\n"
7547 "maximum no. of prefix limit\n"
7548 "Force checking all received routes not only accepted\n")
7549
7550 DEFUN (neighbor_maximum_prefix_threshold,
7551 neighbor_maximum_prefix_threshold_cmd,
7552 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7553 NEIGHBOR_STR
7554 NEIGHBOR_ADDR_STR2
7555 "Maximum number of prefix accept from this peer\n"
7556 "maximum no. of prefix limit\n"
7557 "Threshold value (%) at which to generate a warning msg\n"
7558 "Force checking all received routes not only accepted\n")
7559 {
7560 int idx_peer = 1;
7561 int idx_number = 3;
7562 int idx_number_2 = 4;
7563 int idx_force = 0;
7564 char *force = NULL;
7565
7566 if (argv_find(argv, argc, "force", &idx_force))
7567 force = argv[idx_force]->arg;
7568
7569 return peer_maximum_prefix_set_vty(
7570 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7571 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
7572 }
7573
7574 ALIAS_HIDDEN(
7575 neighbor_maximum_prefix_threshold,
7576 neighbor_maximum_prefix_threshold_hidden_cmd,
7577 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7578 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7579 "Maximum number of prefix accept from this peer\n"
7580 "maximum no. of prefix limit\n"
7581 "Threshold value (%) at which to generate a warning msg\n"
7582 "Force checking all received routes not only accepted\n")
7583
7584 DEFUN (neighbor_maximum_prefix_warning,
7585 neighbor_maximum_prefix_warning_cmd,
7586 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7587 NEIGHBOR_STR
7588 NEIGHBOR_ADDR_STR2
7589 "Maximum number of prefix accept from this peer\n"
7590 "maximum no. of prefix limit\n"
7591 "Only give warning message when limit is exceeded\n"
7592 "Force checking all received routes not only accepted\n")
7593 {
7594 int idx_peer = 1;
7595 int idx_number = 3;
7596 int idx_force = 0;
7597 char *force = NULL;
7598
7599 if (argv_find(argv, argc, "force", &idx_force))
7600 force = argv[idx_force]->arg;
7601
7602 return peer_maximum_prefix_set_vty(
7603 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7604 argv[idx_number]->arg, NULL, 1, NULL, force);
7605 }
7606
7607 ALIAS_HIDDEN(
7608 neighbor_maximum_prefix_warning,
7609 neighbor_maximum_prefix_warning_hidden_cmd,
7610 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7611 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7612 "Maximum number of prefix accept from this peer\n"
7613 "maximum no. of prefix limit\n"
7614 "Only give warning message when limit is exceeded\n"
7615 "Force checking all received routes not only accepted\n")
7616
7617 DEFUN (neighbor_maximum_prefix_threshold_warning,
7618 neighbor_maximum_prefix_threshold_warning_cmd,
7619 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7620 NEIGHBOR_STR
7621 NEIGHBOR_ADDR_STR2
7622 "Maximum number of prefix accept from this peer\n"
7623 "maximum no. of prefix limit\n"
7624 "Threshold value (%) at which to generate a warning msg\n"
7625 "Only give warning message when limit is exceeded\n"
7626 "Force checking all received routes not only accepted\n")
7627 {
7628 int idx_peer = 1;
7629 int idx_number = 3;
7630 int idx_number_2 = 4;
7631 int idx_force = 0;
7632 char *force = NULL;
7633
7634 if (argv_find(argv, argc, "force", &idx_force))
7635 force = argv[idx_force]->arg;
7636
7637 return peer_maximum_prefix_set_vty(
7638 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7639 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
7640 }
7641
7642 ALIAS_HIDDEN(
7643 neighbor_maximum_prefix_threshold_warning,
7644 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
7645 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7646 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7647 "Maximum number of prefix accept from this peer\n"
7648 "maximum no. of prefix limit\n"
7649 "Threshold value (%) at which to generate a warning msg\n"
7650 "Only give warning message when limit is exceeded\n"
7651 "Force checking all received routes not only accepted\n")
7652
7653 DEFUN (neighbor_maximum_prefix_restart,
7654 neighbor_maximum_prefix_restart_cmd,
7655 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7656 NEIGHBOR_STR
7657 NEIGHBOR_ADDR_STR2
7658 "Maximum number of prefix accept from this peer\n"
7659 "maximum no. of prefix limit\n"
7660 "Restart bgp connection after limit is exceeded\n"
7661 "Restart interval in minutes\n"
7662 "Force checking all received routes not only accepted\n")
7663 {
7664 int idx_peer = 1;
7665 int idx_number = 3;
7666 int idx_number_2 = 5;
7667 int idx_force = 0;
7668 char *force = NULL;
7669
7670 if (argv_find(argv, argc, "force", &idx_force))
7671 force = argv[idx_force]->arg;
7672
7673 return peer_maximum_prefix_set_vty(
7674 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7675 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
7676 }
7677
7678 ALIAS_HIDDEN(
7679 neighbor_maximum_prefix_restart,
7680 neighbor_maximum_prefix_restart_hidden_cmd,
7681 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7682 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7683 "Maximum number of prefix accept from this peer\n"
7684 "maximum no. of prefix limit\n"
7685 "Restart bgp connection after limit is exceeded\n"
7686 "Restart interval in minutes\n"
7687 "Force checking all received routes not only accepted\n")
7688
7689 DEFUN (neighbor_maximum_prefix_threshold_restart,
7690 neighbor_maximum_prefix_threshold_restart_cmd,
7691 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7692 NEIGHBOR_STR
7693 NEIGHBOR_ADDR_STR2
7694 "Maximum number of prefixes to accept from this peer\n"
7695 "maximum no. of prefix limit\n"
7696 "Threshold value (%) at which to generate a warning msg\n"
7697 "Restart bgp connection after limit is exceeded\n"
7698 "Restart interval in minutes\n"
7699 "Force checking all received routes not only accepted\n")
7700 {
7701 int idx_peer = 1;
7702 int idx_number = 3;
7703 int idx_number_2 = 4;
7704 int idx_number_3 = 6;
7705 int idx_force = 0;
7706 char *force = NULL;
7707
7708 if (argv_find(argv, argc, "force", &idx_force))
7709 force = argv[idx_force]->arg;
7710
7711 return peer_maximum_prefix_set_vty(
7712 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7713 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7714 argv[idx_number_3]->arg, force);
7715 }
7716
7717 ALIAS_HIDDEN(
7718 neighbor_maximum_prefix_threshold_restart,
7719 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
7720 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7722 "Maximum number of prefixes to accept from this peer\n"
7723 "maximum no. of prefix limit\n"
7724 "Threshold value (%) at which to generate a warning msg\n"
7725 "Restart bgp connection after limit is exceeded\n"
7726 "Restart interval in minutes\n"
7727 "Force checking all received routes not only accepted\n")
7728
7729 DEFUN (no_neighbor_maximum_prefix,
7730 no_neighbor_maximum_prefix_cmd,
7731 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7732 NO_STR
7733 NEIGHBOR_STR
7734 NEIGHBOR_ADDR_STR2
7735 "Maximum number of prefixes to accept from this peer\n"
7736 "maximum no. of prefix limit\n"
7737 "Threshold value (%) at which to generate a warning msg\n"
7738 "Restart bgp connection after limit is exceeded\n"
7739 "Restart interval in minutes\n"
7740 "Only give warning message when limit is exceeded\n"
7741 "Force checking all received routes not only accepted\n")
7742 {
7743 int idx_peer = 2;
7744 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7745 bgp_node_afi(vty),
7746 bgp_node_safi(vty));
7747 }
7748
7749 ALIAS_HIDDEN(
7750 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
7751 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7752 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7753 "Maximum number of prefixes to accept from this peer\n"
7754 "maximum no. of prefix limit\n"
7755 "Threshold value (%) at which to generate a warning msg\n"
7756 "Restart bgp connection after limit is exceeded\n"
7757 "Restart interval in minutes\n"
7758 "Only give warning message when limit is exceeded\n"
7759 "Force checking all received routes not only accepted\n")
7760
7761
7762 /* "neighbor allowas-in" */
7763 DEFUN (neighbor_allowas_in,
7764 neighbor_allowas_in_cmd,
7765 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7766 NEIGHBOR_STR
7767 NEIGHBOR_ADDR_STR2
7768 "Accept as-path with my AS present in it\n"
7769 "Number of occurrences of AS number\n"
7770 "Only accept my AS in the as-path if the route was originated in my AS\n")
7771 {
7772 int idx_peer = 1;
7773 int idx_number_origin = 3;
7774 int ret;
7775 int origin = 0;
7776 struct peer *peer;
7777 int allow_num = 0;
7778
7779 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7780 if (!peer)
7781 return CMD_WARNING_CONFIG_FAILED;
7782
7783 if (argc <= idx_number_origin)
7784 allow_num = 3;
7785 else {
7786 if (argv[idx_number_origin]->type == WORD_TKN)
7787 origin = 1;
7788 else
7789 allow_num = atoi(argv[idx_number_origin]->arg);
7790 }
7791
7792 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7793 allow_num, origin);
7794
7795 return bgp_vty_return(vty, ret);
7796 }
7797
7798 ALIAS_HIDDEN(
7799 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7800 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7802 "Accept as-path with my AS present in it\n"
7803 "Number of occurrences of AS number\n"
7804 "Only accept my AS in the as-path if the route was originated in my AS\n")
7805
7806 DEFUN (no_neighbor_allowas_in,
7807 no_neighbor_allowas_in_cmd,
7808 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7809 NO_STR
7810 NEIGHBOR_STR
7811 NEIGHBOR_ADDR_STR2
7812 "allow local ASN appears in aspath attribute\n"
7813 "Number of occurrences of AS number\n"
7814 "Only accept my AS in the as-path if the route was originated in my AS\n")
7815 {
7816 int idx_peer = 2;
7817 int ret;
7818 struct peer *peer;
7819
7820 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7821 if (!peer)
7822 return CMD_WARNING_CONFIG_FAILED;
7823
7824 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7825 bgp_node_safi(vty));
7826
7827 return bgp_vty_return(vty, ret);
7828 }
7829
7830 ALIAS_HIDDEN(
7831 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7832 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7833 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7834 "allow local ASN appears in aspath attribute\n"
7835 "Number of occurrences of AS number\n"
7836 "Only accept my AS in the as-path if the route was originated in my AS\n")
7837
7838 DEFUN (neighbor_ttl_security,
7839 neighbor_ttl_security_cmd,
7840 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7841 NEIGHBOR_STR
7842 NEIGHBOR_ADDR_STR2
7843 "BGP ttl-security parameters\n"
7844 "Specify the maximum number of hops to the BGP peer\n"
7845 "Number of hops to BGP peer\n")
7846 {
7847 int idx_peer = 1;
7848 int idx_number = 4;
7849 struct peer *peer;
7850 int gtsm_hops;
7851
7852 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7853 if (!peer)
7854 return CMD_WARNING_CONFIG_FAILED;
7855
7856 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7857
7858 /*
7859 * If 'neighbor swpX', then this is for directly connected peers,
7860 * we should not accept a ttl-security hops value greater than 1.
7861 */
7862 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7863 vty_out(vty,
7864 "%s is directly connected peer, hops cannot exceed 1\n",
7865 argv[idx_peer]->arg);
7866 return CMD_WARNING_CONFIG_FAILED;
7867 }
7868
7869 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
7870 }
7871
7872 DEFUN (no_neighbor_ttl_security,
7873 no_neighbor_ttl_security_cmd,
7874 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7875 NO_STR
7876 NEIGHBOR_STR
7877 NEIGHBOR_ADDR_STR2
7878 "BGP ttl-security parameters\n"
7879 "Specify the maximum number of hops to the BGP peer\n"
7880 "Number of hops to BGP peer\n")
7881 {
7882 int idx_peer = 2;
7883 struct peer *peer;
7884
7885 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7886 if (!peer)
7887 return CMD_WARNING_CONFIG_FAILED;
7888
7889 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
7890 }
7891
7892 DEFUN (neighbor_addpath_tx_all_paths,
7893 neighbor_addpath_tx_all_paths_cmd,
7894 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7895 NEIGHBOR_STR
7896 NEIGHBOR_ADDR_STR2
7897 "Use addpath to advertise all paths to a neighbor\n")
7898 {
7899 int idx_peer = 1;
7900 struct peer *peer;
7901
7902 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7903 if (!peer)
7904 return CMD_WARNING_CONFIG_FAILED;
7905
7906 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7907 BGP_ADDPATH_ALL);
7908 return CMD_SUCCESS;
7909 }
7910
7911 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7912 neighbor_addpath_tx_all_paths_hidden_cmd,
7913 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7914 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7915 "Use addpath to advertise all paths to a neighbor\n")
7916
7917 DEFUN (no_neighbor_addpath_tx_all_paths,
7918 no_neighbor_addpath_tx_all_paths_cmd,
7919 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7920 NO_STR
7921 NEIGHBOR_STR
7922 NEIGHBOR_ADDR_STR2
7923 "Use addpath to advertise all paths to a neighbor\n")
7924 {
7925 int idx_peer = 2;
7926 struct peer *peer;
7927
7928 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7929 if (!peer)
7930 return CMD_WARNING_CONFIG_FAILED;
7931
7932 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7933 != BGP_ADDPATH_ALL) {
7934 vty_out(vty,
7935 "%% Peer not currently configured to transmit all paths.");
7936 return CMD_WARNING_CONFIG_FAILED;
7937 }
7938
7939 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7940 BGP_ADDPATH_NONE);
7941
7942 return CMD_SUCCESS;
7943 }
7944
7945 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7946 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7947 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7949 "Use addpath to advertise all paths to a neighbor\n")
7950
7951 DEFUN (neighbor_addpath_tx_bestpath_per_as,
7952 neighbor_addpath_tx_bestpath_per_as_cmd,
7953 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7954 NEIGHBOR_STR
7955 NEIGHBOR_ADDR_STR2
7956 "Use addpath to advertise the bestpath per each neighboring AS\n")
7957 {
7958 int idx_peer = 1;
7959 struct peer *peer;
7960
7961 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7962 if (!peer)
7963 return CMD_WARNING_CONFIG_FAILED;
7964
7965 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7966 BGP_ADDPATH_BEST_PER_AS);
7967
7968 return CMD_SUCCESS;
7969 }
7970
7971 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7972 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7973 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7975 "Use addpath to advertise the bestpath per each neighboring AS\n")
7976
7977 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7978 no_neighbor_addpath_tx_bestpath_per_as_cmd,
7979 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7980 NO_STR
7981 NEIGHBOR_STR
7982 NEIGHBOR_ADDR_STR2
7983 "Use addpath to advertise the bestpath per each neighboring AS\n")
7984 {
7985 int idx_peer = 2;
7986 struct peer *peer;
7987
7988 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7989 if (!peer)
7990 return CMD_WARNING_CONFIG_FAILED;
7991
7992 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7993 != BGP_ADDPATH_BEST_PER_AS) {
7994 vty_out(vty,
7995 "%% Peer not currently configured to transmit all best path per as.");
7996 return CMD_WARNING_CONFIG_FAILED;
7997 }
7998
7999 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8000 BGP_ADDPATH_NONE);
8001
8002 return CMD_SUCCESS;
8003 }
8004
8005 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8006 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8007 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8008 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8009 "Use addpath to advertise the bestpath per each neighboring AS\n")
8010
8011 DEFPY(
8012 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8013 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8014 NEIGHBOR_STR
8015 NEIGHBOR_ADDR_STR2
8016 "Detect AS loops before sending to neighbor\n")
8017 {
8018 struct peer *peer;
8019
8020 peer = peer_and_group_lookup_vty(vty, neighbor);
8021 if (!peer)
8022 return CMD_WARNING_CONFIG_FAILED;
8023
8024 peer->as_path_loop_detection = true;
8025
8026 return CMD_SUCCESS;
8027 }
8028
8029 DEFPY(
8030 no_neighbor_aspath_loop_detection,
8031 no_neighbor_aspath_loop_detection_cmd,
8032 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8033 NO_STR
8034 NEIGHBOR_STR
8035 NEIGHBOR_ADDR_STR2
8036 "Detect AS loops before sending to neighbor\n")
8037 {
8038 struct peer *peer;
8039
8040 peer = peer_and_group_lookup_vty(vty, neighbor);
8041 if (!peer)
8042 return CMD_WARNING_CONFIG_FAILED;
8043
8044 peer->as_path_loop_detection = false;
8045
8046 return CMD_SUCCESS;
8047 }
8048
8049 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8050 struct ecommunity **list, bool is_rt6)
8051 {
8052 struct ecommunity *ecom = NULL;
8053 struct ecommunity *ecomadd;
8054
8055 for (; argc; --argc, ++argv) {
8056 if (is_rt6)
8057 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8058 ECOMMUNITY_ROUTE_TARGET,
8059 0);
8060 else
8061 ecomadd = ecommunity_str2com(argv[0]->arg,
8062 ECOMMUNITY_ROUTE_TARGET,
8063 0);
8064 if (!ecomadd) {
8065 vty_out(vty, "Malformed community-list value\n");
8066 if (ecom)
8067 ecommunity_free(&ecom);
8068 return CMD_WARNING_CONFIG_FAILED;
8069 }
8070
8071 if (ecom) {
8072 ecommunity_merge(ecom, ecomadd);
8073 ecommunity_free(&ecomadd);
8074 } else {
8075 ecom = ecomadd;
8076 }
8077 }
8078
8079 if (*list) {
8080 ecommunity_free(&*list);
8081 }
8082 *list = ecom;
8083
8084 return CMD_SUCCESS;
8085 }
8086
8087 /*
8088 * v2vimport is true if we are handling a `import vrf ...` command
8089 */
8090 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8091 {
8092 afi_t afi;
8093
8094 switch (vty->node) {
8095 case BGP_IPV4_NODE:
8096 afi = AFI_IP;
8097 break;
8098 case BGP_IPV6_NODE:
8099 afi = AFI_IP6;
8100 break;
8101 default:
8102 vty_out(vty,
8103 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8104 return AFI_MAX;
8105 }
8106
8107 if (!v2vimport) {
8108 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8109 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8110 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8111 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8112 vty_out(vty,
8113 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8114 return AFI_MAX;
8115 }
8116 } else {
8117 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8118 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8119 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8120 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8121 vty_out(vty,
8122 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8123 return AFI_MAX;
8124 }
8125 }
8126 return afi;
8127 }
8128
8129 DEFPY (af_rd_vpn_export,
8130 af_rd_vpn_export_cmd,
8131 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8132 NO_STR
8133 "Specify route distinguisher\n"
8134 "Between current address-family and vpn\n"
8135 "For routes leaked from current address-family to vpn\n"
8136 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8137 {
8138 VTY_DECLVAR_CONTEXT(bgp, bgp);
8139 struct prefix_rd prd;
8140 int ret;
8141 afi_t afi;
8142 int idx = 0;
8143 bool yes = true;
8144
8145 if (argv_find(argv, argc, "no", &idx))
8146 yes = false;
8147
8148 if (yes) {
8149 ret = str2prefix_rd(rd_str, &prd);
8150 if (!ret) {
8151 vty_out(vty, "%% Malformed rd\n");
8152 return CMD_WARNING_CONFIG_FAILED;
8153 }
8154 }
8155
8156 afi = vpn_policy_getafi(vty, bgp, false);
8157 if (afi == AFI_MAX)
8158 return CMD_WARNING_CONFIG_FAILED;
8159
8160 /*
8161 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8162 */
8163 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8164 bgp_get_default(), bgp);
8165
8166 if (yes) {
8167 bgp->vpn_policy[afi].tovpn_rd = prd;
8168 SET_FLAG(bgp->vpn_policy[afi].flags,
8169 BGP_VPN_POLICY_TOVPN_RD_SET);
8170 } else {
8171 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8172 BGP_VPN_POLICY_TOVPN_RD_SET);
8173 }
8174
8175 /* post-change: re-export vpn routes */
8176 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8177 bgp_get_default(), bgp);
8178
8179 return CMD_SUCCESS;
8180 }
8181
8182 ALIAS (af_rd_vpn_export,
8183 af_no_rd_vpn_export_cmd,
8184 "no rd vpn export",
8185 NO_STR
8186 "Specify route distinguisher\n"
8187 "Between current address-family and vpn\n"
8188 "For routes leaked from current address-family to vpn\n")
8189
8190 DEFPY (af_label_vpn_export,
8191 af_label_vpn_export_cmd,
8192 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8193 NO_STR
8194 "label value for VRF\n"
8195 "Between current address-family and vpn\n"
8196 "For routes leaked from current address-family to vpn\n"
8197 "Label Value <0-1048575>\n"
8198 "Automatically assign a label\n")
8199 {
8200 VTY_DECLVAR_CONTEXT(bgp, bgp);
8201 mpls_label_t label = MPLS_LABEL_NONE;
8202 afi_t afi;
8203 int idx = 0;
8204 bool yes = true;
8205
8206 if (argv_find(argv, argc, "no", &idx))
8207 yes = false;
8208
8209 /* If "no ...", squash trailing parameter */
8210 if (!yes)
8211 label_auto = NULL;
8212
8213 if (yes) {
8214 if (!label_auto)
8215 label = label_val; /* parser should force unsigned */
8216 }
8217
8218 afi = vpn_policy_getafi(vty, bgp, false);
8219 if (afi == AFI_MAX)
8220 return CMD_WARNING_CONFIG_FAILED;
8221
8222
8223 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8224 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8225 /* no change */
8226 return CMD_SUCCESS;
8227
8228 /*
8229 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8230 */
8231 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8232 bgp_get_default(), bgp);
8233
8234 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8235 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8236
8237 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8238
8239 /*
8240 * label has previously been automatically
8241 * assigned by labelpool: release it
8242 *
8243 * NB if tovpn_label == MPLS_LABEL_NONE it
8244 * means the automatic assignment is in flight
8245 * and therefore the labelpool callback must
8246 * detect that the auto label is not needed.
8247 */
8248
8249 bgp_lp_release(LP_TYPE_VRF,
8250 &bgp->vpn_policy[afi],
8251 bgp->vpn_policy[afi].tovpn_label);
8252 }
8253 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8254 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8255 }
8256
8257 bgp->vpn_policy[afi].tovpn_label = label;
8258 if (label_auto) {
8259 SET_FLAG(bgp->vpn_policy[afi].flags,
8260 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8261 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8262 vpn_leak_label_callback);
8263 }
8264
8265 /* post-change: re-export vpn routes */
8266 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8267 bgp_get_default(), bgp);
8268
8269 hook_call(bgp_snmp_update_last_changed, bgp);
8270 return CMD_SUCCESS;
8271 }
8272
8273 DEFPY (af_sid_vpn_export,
8274 af_sid_vpn_export_cmd,
8275 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8276 NO_STR
8277 "sid value for VRF\n"
8278 "Between current address-family and vpn\n"
8279 "For routes leaked from current address-family to vpn\n"
8280 "Sid allocation index\n"
8281 "Automatically assign a label\n")
8282 {
8283 VTY_DECLVAR_CONTEXT(bgp, bgp);
8284 afi_t afi;
8285 int debug = 0;
8286 int idx = 0;
8287 bool yes = true;
8288
8289 if (argv_find(argv, argc, "no", &idx))
8290 yes = false;
8291 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8292 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8293
8294 afi = vpn_policy_getafi(vty, bgp, false);
8295 if (afi == AFI_MAX)
8296 return CMD_WARNING_CONFIG_FAILED;
8297
8298 if (!yes) {
8299 /* implement me */
8300 vty_out(vty, "It's not implemented");
8301 return CMD_WARNING_CONFIG_FAILED;
8302 }
8303
8304 /* skip when it's already configured */
8305 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8306 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8307 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8308 return CMD_SUCCESS;
8309
8310 /*
8311 * mode change between sid_idx and sid_auto isn't supported.
8312 * user must negate sid vpn export when they want to change the mode
8313 */
8314 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8315 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8316 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8317 vty_out(vty, "it's already configured as %s.\n",
8318 sid_auto ? "auto-mode" : "idx-mode");
8319 return CMD_WARNING_CONFIG_FAILED;
8320 }
8321
8322 /* pre-change */
8323 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8324 bgp_get_default(), bgp);
8325
8326 if (sid_auto) {
8327 /* SID allocation auto-mode */
8328 if (debug)
8329 zlog_debug("%s: auto sid alloc.", __func__);
8330 SET_FLAG(bgp->vpn_policy[afi].flags,
8331 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8332 } else {
8333 /* SID allocation index-mode */
8334 if (debug)
8335 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8336 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8337 }
8338
8339 /* post-change */
8340 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8341 bgp_get_default(), bgp);
8342 return CMD_SUCCESS;
8343 }
8344
8345 ALIAS (af_label_vpn_export,
8346 af_no_label_vpn_export_cmd,
8347 "no label vpn export",
8348 NO_STR
8349 "label value for VRF\n"
8350 "Between current address-family and vpn\n"
8351 "For routes leaked from current address-family to vpn\n")
8352
8353 DEFPY (af_nexthop_vpn_export,
8354 af_nexthop_vpn_export_cmd,
8355 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8356 NO_STR
8357 "Specify next hop to use for VRF advertised prefixes\n"
8358 "Between current address-family and vpn\n"
8359 "For routes leaked from current address-family to vpn\n"
8360 "IPv4 prefix\n"
8361 "IPv6 prefix\n")
8362 {
8363 VTY_DECLVAR_CONTEXT(bgp, bgp);
8364 afi_t afi;
8365 struct prefix p;
8366
8367 if (!no) {
8368 if (!nexthop_su) {
8369 vty_out(vty, "%% Nexthop required\n");
8370 return CMD_WARNING_CONFIG_FAILED;
8371 }
8372 if (!sockunion2hostprefix(nexthop_su, &p))
8373 return CMD_WARNING_CONFIG_FAILED;
8374 }
8375
8376 afi = vpn_policy_getafi(vty, bgp, false);
8377 if (afi == AFI_MAX)
8378 return CMD_WARNING_CONFIG_FAILED;
8379
8380 /*
8381 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8382 */
8383 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8384 bgp_get_default(), bgp);
8385
8386 if (!no) {
8387 bgp->vpn_policy[afi].tovpn_nexthop = p;
8388 SET_FLAG(bgp->vpn_policy[afi].flags,
8389 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8390 } else {
8391 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8392 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8393 }
8394
8395 /* post-change: re-export vpn routes */
8396 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8397 bgp_get_default(), bgp);
8398
8399 return CMD_SUCCESS;
8400 }
8401
8402 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8403 {
8404 if (!strcmp(dstr, "import")) {
8405 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8406 } else if (!strcmp(dstr, "export")) {
8407 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8408 } else if (!strcmp(dstr, "both")) {
8409 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8410 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8411 } else {
8412 vty_out(vty, "%% direction parse error\n");
8413 return CMD_WARNING_CONFIG_FAILED;
8414 }
8415 return CMD_SUCCESS;
8416 }
8417
8418 DEFPY (af_rt_vpn_imexport,
8419 af_rt_vpn_imexport_cmd,
8420 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8421 NO_STR
8422 "Specify route target list\n"
8423 "Specify route target list\n"
8424 "Between current address-family and vpn\n"
8425 "For routes leaked from vpn to current address-family: match any\n"
8426 "For routes leaked from current address-family to vpn: set\n"
8427 "both import: match any and export: set\n"
8428 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8429 {
8430 VTY_DECLVAR_CONTEXT(bgp, bgp);
8431 int ret;
8432 struct ecommunity *ecom = NULL;
8433 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8434 vpn_policy_direction_t dir;
8435 afi_t afi;
8436 int idx = 0;
8437 bool yes = true;
8438
8439 if (argv_find(argv, argc, "no", &idx))
8440 yes = false;
8441
8442 afi = vpn_policy_getafi(vty, bgp, false);
8443 if (afi == AFI_MAX)
8444 return CMD_WARNING_CONFIG_FAILED;
8445
8446 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8447 if (ret != CMD_SUCCESS)
8448 return ret;
8449
8450 if (yes) {
8451 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8452 vty_out(vty, "%% Missing RTLIST\n");
8453 return CMD_WARNING_CONFIG_FAILED;
8454 }
8455 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8456 if (ret != CMD_SUCCESS) {
8457 return ret;
8458 }
8459 }
8460
8461 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8462 if (!dodir[dir])
8463 continue;
8464
8465 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8466
8467 if (yes) {
8468 if (bgp->vpn_policy[afi].rtlist[dir])
8469 ecommunity_free(
8470 &bgp->vpn_policy[afi].rtlist[dir]);
8471 bgp->vpn_policy[afi].rtlist[dir] =
8472 ecommunity_dup(ecom);
8473 } else {
8474 if (bgp->vpn_policy[afi].rtlist[dir])
8475 ecommunity_free(
8476 &bgp->vpn_policy[afi].rtlist[dir]);
8477 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8478 }
8479
8480 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8481 }
8482
8483 if (ecom)
8484 ecommunity_free(&ecom);
8485
8486 return CMD_SUCCESS;
8487 }
8488
8489 ALIAS (af_rt_vpn_imexport,
8490 af_no_rt_vpn_imexport_cmd,
8491 "no <rt|route-target> vpn <import|export|both>$direction_str",
8492 NO_STR
8493 "Specify route target list\n"
8494 "Specify route target list\n"
8495 "Between current address-family and vpn\n"
8496 "For routes leaked from vpn to current address-family\n"
8497 "For routes leaked from current address-family to vpn\n"
8498 "both import and export\n")
8499
8500 DEFPY (af_route_map_vpn_imexport,
8501 af_route_map_vpn_imexport_cmd,
8502 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8503 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8504 NO_STR
8505 "Specify route map\n"
8506 "Between current address-family and vpn\n"
8507 "For routes leaked from vpn to current address-family\n"
8508 "For routes leaked from current address-family to vpn\n"
8509 "name of route-map\n")
8510 {
8511 VTY_DECLVAR_CONTEXT(bgp, bgp);
8512 int ret;
8513 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8514 vpn_policy_direction_t dir;
8515 afi_t afi;
8516 int idx = 0;
8517 bool yes = true;
8518
8519 if (argv_find(argv, argc, "no", &idx))
8520 yes = false;
8521
8522 afi = vpn_policy_getafi(vty, bgp, false);
8523 if (afi == AFI_MAX)
8524 return CMD_WARNING_CONFIG_FAILED;
8525
8526 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8527 if (ret != CMD_SUCCESS)
8528 return ret;
8529
8530 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8531 if (!dodir[dir])
8532 continue;
8533
8534 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8535
8536 if (yes) {
8537 if (bgp->vpn_policy[afi].rmap_name[dir])
8538 XFREE(MTYPE_ROUTE_MAP_NAME,
8539 bgp->vpn_policy[afi].rmap_name[dir]);
8540 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8541 MTYPE_ROUTE_MAP_NAME, rmap_str);
8542 bgp->vpn_policy[afi].rmap[dir] =
8543 route_map_lookup_warn_noexist(vty, rmap_str);
8544 if (!bgp->vpn_policy[afi].rmap[dir])
8545 return CMD_SUCCESS;
8546 } else {
8547 if (bgp->vpn_policy[afi].rmap_name[dir])
8548 XFREE(MTYPE_ROUTE_MAP_NAME,
8549 bgp->vpn_policy[afi].rmap_name[dir]);
8550 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8551 bgp->vpn_policy[afi].rmap[dir] = NULL;
8552 }
8553
8554 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8555 }
8556
8557 return CMD_SUCCESS;
8558 }
8559
8560 ALIAS (af_route_map_vpn_imexport,
8561 af_no_route_map_vpn_imexport_cmd,
8562 "no route-map vpn <import|export>$direction_str",
8563 NO_STR
8564 "Specify route map\n"
8565 "Between current address-family and vpn\n"
8566 "For routes leaked from vpn to current address-family\n"
8567 "For routes leaked from current address-family to vpn\n")
8568
8569 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
8570 "import vrf route-map RMAP$rmap_str",
8571 "Import routes from another VRF\n"
8572 "Vrf routes being filtered\n"
8573 "Specify route map\n"
8574 "name of route-map\n")
8575 {
8576 VTY_DECLVAR_CONTEXT(bgp, bgp);
8577 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8578 afi_t afi;
8579 struct bgp *bgp_default;
8580
8581 afi = vpn_policy_getafi(vty, bgp, true);
8582 if (afi == AFI_MAX)
8583 return CMD_WARNING_CONFIG_FAILED;
8584
8585 bgp_default = bgp_get_default();
8586 if (!bgp_default) {
8587 int32_t ret;
8588 as_t as = bgp->as;
8589
8590 /* Auto-create assuming the same AS */
8591 ret = bgp_get_vty(&bgp_default, &as, NULL,
8592 BGP_INSTANCE_TYPE_DEFAULT);
8593
8594 if (ret) {
8595 vty_out(vty,
8596 "VRF default is not configured as a bgp instance\n");
8597 return CMD_WARNING;
8598 }
8599 }
8600
8601 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8602
8603 if (bgp->vpn_policy[afi].rmap_name[dir])
8604 XFREE(MTYPE_ROUTE_MAP_NAME,
8605 bgp->vpn_policy[afi].rmap_name[dir]);
8606 bgp->vpn_policy[afi].rmap_name[dir] =
8607 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8608 bgp->vpn_policy[afi].rmap[dir] =
8609 route_map_lookup_warn_noexist(vty, rmap_str);
8610 if (!bgp->vpn_policy[afi].rmap[dir])
8611 return CMD_SUCCESS;
8612
8613 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8614 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8615
8616 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8617
8618 return CMD_SUCCESS;
8619 }
8620
8621 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8622 "no import vrf route-map [RMAP$rmap_str]",
8623 NO_STR
8624 "Import routes from another VRF\n"
8625 "Vrf routes being filtered\n"
8626 "Specify route map\n"
8627 "name of route-map\n")
8628 {
8629 VTY_DECLVAR_CONTEXT(bgp, bgp);
8630 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8631 afi_t afi;
8632
8633 afi = vpn_policy_getafi(vty, bgp, true);
8634 if (afi == AFI_MAX)
8635 return CMD_WARNING_CONFIG_FAILED;
8636
8637 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8638
8639 if (bgp->vpn_policy[afi].rmap_name[dir])
8640 XFREE(MTYPE_ROUTE_MAP_NAME,
8641 bgp->vpn_policy[afi].rmap_name[dir]);
8642 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8643 bgp->vpn_policy[afi].rmap[dir] = NULL;
8644
8645 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8646 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8647 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8648
8649 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8650
8651 return CMD_SUCCESS;
8652 }
8653
8654 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8655 "[no] import vrf VIEWVRFNAME$import_name",
8656 NO_STR
8657 "Import routes from another VRF\n"
8658 "VRF to import from\n"
8659 "The name of the VRF\n")
8660 {
8661 VTY_DECLVAR_CONTEXT(bgp, bgp);
8662 struct listnode *node;
8663 struct bgp *vrf_bgp, *bgp_default;
8664 int32_t ret = 0;
8665 as_t as = bgp->as;
8666 bool remove = false;
8667 int32_t idx = 0;
8668 char *vname;
8669 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
8670 safi_t safi;
8671 afi_t afi;
8672
8673 if (import_name == NULL) {
8674 vty_out(vty, "%% Missing import name\n");
8675 return CMD_WARNING;
8676 }
8677
8678 if (strcmp(import_name, "route-map") == 0) {
8679 vty_out(vty, "%% Must include route-map name\n");
8680 return CMD_WARNING;
8681 }
8682
8683 if (argv_find(argv, argc, "no", &idx))
8684 remove = true;
8685
8686 afi = vpn_policy_getafi(vty, bgp, true);
8687 if (afi == AFI_MAX)
8688 return CMD_WARNING_CONFIG_FAILED;
8689
8690 safi = bgp_node_safi(vty);
8691
8692 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8693 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8694 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8695 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8696 remove ? "unimport" : "import", import_name);
8697 return CMD_WARNING;
8698 }
8699
8700 bgp_default = bgp_get_default();
8701 if (!bgp_default) {
8702 /* Auto-create assuming the same AS */
8703 ret = bgp_get_vty(&bgp_default, &as, NULL,
8704 BGP_INSTANCE_TYPE_DEFAULT);
8705
8706 if (ret) {
8707 vty_out(vty,
8708 "VRF default is not configured as a bgp instance\n");
8709 return CMD_WARNING;
8710 }
8711 }
8712
8713 vrf_bgp = bgp_lookup_by_name(import_name);
8714 if (!vrf_bgp) {
8715 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8716 vrf_bgp = bgp_default;
8717 else
8718 /* Auto-create assuming the same AS */
8719 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8720
8721 if (ret) {
8722 vty_out(vty,
8723 "VRF %s is not configured as a bgp instance\n",
8724 import_name);
8725 return CMD_WARNING;
8726 }
8727 }
8728
8729 if (remove) {
8730 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8731 } else {
8732 /* Already importing from "import_vrf"? */
8733 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8734 vname)) {
8735 if (strcmp(vname, import_name) == 0)
8736 return CMD_WARNING;
8737 }
8738
8739 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8740 }
8741
8742 return CMD_SUCCESS;
8743 }
8744
8745 /* This command is valid only in a bgp vrf instance or the default instance */
8746 DEFPY (bgp_imexport_vpn,
8747 bgp_imexport_vpn_cmd,
8748 "[no] <import|export>$direction_str vpn",
8749 NO_STR
8750 "Import routes to this address-family\n"
8751 "Export routes from this address-family\n"
8752 "to/from default instance VPN RIB\n")
8753 {
8754 VTY_DECLVAR_CONTEXT(bgp, bgp);
8755 int previous_state;
8756 afi_t afi;
8757 safi_t safi;
8758 int idx = 0;
8759 bool yes = true;
8760 int flag;
8761 vpn_policy_direction_t dir;
8762
8763 if (argv_find(argv, argc, "no", &idx))
8764 yes = false;
8765
8766 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
8767 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
8768
8769 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
8770 return CMD_WARNING_CONFIG_FAILED;
8771 }
8772
8773 afi = bgp_node_afi(vty);
8774 safi = bgp_node_safi(vty);
8775 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
8776 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
8777 return CMD_WARNING_CONFIG_FAILED;
8778 }
8779
8780 if (!strcmp(direction_str, "import")) {
8781 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
8782 dir = BGP_VPN_POLICY_DIR_FROMVPN;
8783 } else if (!strcmp(direction_str, "export")) {
8784 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
8785 dir = BGP_VPN_POLICY_DIR_TOVPN;
8786 } else {
8787 vty_out(vty, "%% unknown direction %s\n", direction_str);
8788 return CMD_WARNING_CONFIG_FAILED;
8789 }
8790
8791 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
8792
8793 if (yes) {
8794 SET_FLAG(bgp->af_flags[afi][safi], flag);
8795 if (!previous_state) {
8796 /* trigger export current vrf */
8797 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8798 }
8799 } else {
8800 if (previous_state) {
8801 /* trigger un-export current vrf */
8802 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8803 }
8804 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
8805 }
8806
8807 hook_call(bgp_snmp_init_stats, bgp);
8808
8809 return CMD_SUCCESS;
8810 }
8811
8812 DEFPY (af_routetarget_import,
8813 af_routetarget_import_cmd,
8814 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
8815 NO_STR
8816 "Specify route target list\n"
8817 "Specify route target list\n"
8818 "Specify route target list\n"
8819 "Specify route target list\n"
8820 "Flow-spec redirect type route target\n"
8821 "Import routes to this address-family\n"
8822 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
8823 {
8824 VTY_DECLVAR_CONTEXT(bgp, bgp);
8825 int ret;
8826 struct ecommunity *ecom = NULL;
8827 afi_t afi;
8828 int idx = 0, idx_unused = 0;
8829 bool yes = true;
8830 bool rt6 = false;
8831
8832 if (argv_find(argv, argc, "no", &idx))
8833 yes = false;
8834
8835 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8836 argv_find(argv, argc, "route-target6", &idx_unused))
8837 rt6 = true;
8838
8839 afi = vpn_policy_getafi(vty, bgp, false);
8840 if (afi == AFI_MAX)
8841 return CMD_WARNING_CONFIG_FAILED;
8842
8843 if (rt6 && afi != AFI_IP6)
8844 return CMD_WARNING_CONFIG_FAILED;
8845
8846 if (yes) {
8847 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8848 vty_out(vty, "%% Missing RTLIST\n");
8849 return CMD_WARNING_CONFIG_FAILED;
8850 }
8851 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
8852 if (ret != CMD_SUCCESS)
8853 return ret;
8854 }
8855
8856 if (yes) {
8857 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8858 ecommunity_free(&bgp->vpn_policy[afi]
8859 .import_redirect_rtlist);
8860 bgp->vpn_policy[afi].import_redirect_rtlist =
8861 ecommunity_dup(ecom);
8862 } else {
8863 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8864 ecommunity_free(&bgp->vpn_policy[afi]
8865 .import_redirect_rtlist);
8866 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
8867 }
8868
8869 if (ecom)
8870 ecommunity_free(&ecom);
8871
8872 return CMD_SUCCESS;
8873 }
8874
8875 DEFUN_NOSH (address_family_ipv4_safi,
8876 address_family_ipv4_safi_cmd,
8877 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8878 "Enter Address Family command mode\n"
8879 "Address Family\n"
8880 BGP_SAFI_WITH_LABEL_HELP_STR)
8881 {
8882
8883 if (argc == 3) {
8884 VTY_DECLVAR_CONTEXT(bgp, bgp);
8885 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8886 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8887 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
8888 && safi != SAFI_EVPN) {
8889 vty_out(vty,
8890 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
8891 return CMD_WARNING_CONFIG_FAILED;
8892 }
8893 vty->node = bgp_node_type(AFI_IP, safi);
8894 } else
8895 vty->node = BGP_IPV4_NODE;
8896
8897 return CMD_SUCCESS;
8898 }
8899
8900 DEFUN_NOSH (address_family_ipv6_safi,
8901 address_family_ipv6_safi_cmd,
8902 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8903 "Enter Address Family command mode\n"
8904 "Address Family\n"
8905 BGP_SAFI_WITH_LABEL_HELP_STR)
8906 {
8907 if (argc == 3) {
8908 VTY_DECLVAR_CONTEXT(bgp, bgp);
8909 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8910 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8911 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
8912 && safi != SAFI_EVPN) {
8913 vty_out(vty,
8914 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
8915 return CMD_WARNING_CONFIG_FAILED;
8916 }
8917 vty->node = bgp_node_type(AFI_IP6, safi);
8918 } else
8919 vty->node = BGP_IPV6_NODE;
8920
8921 return CMD_SUCCESS;
8922 }
8923
8924 #ifdef KEEP_OLD_VPN_COMMANDS
8925 DEFUN_NOSH (address_family_vpnv4,
8926 address_family_vpnv4_cmd,
8927 "address-family vpnv4 [unicast]",
8928 "Enter Address Family command mode\n"
8929 "Address Family\n"
8930 "Address Family modifier\n")
8931 {
8932 vty->node = BGP_VPNV4_NODE;
8933 return CMD_SUCCESS;
8934 }
8935
8936 DEFUN_NOSH (address_family_vpnv6,
8937 address_family_vpnv6_cmd,
8938 "address-family vpnv6 [unicast]",
8939 "Enter Address Family command mode\n"
8940 "Address Family\n"
8941 "Address Family modifier\n")
8942 {
8943 vty->node = BGP_VPNV6_NODE;
8944 return CMD_SUCCESS;
8945 }
8946 #endif /* KEEP_OLD_VPN_COMMANDS */
8947
8948 DEFUN_NOSH (address_family_evpn,
8949 address_family_evpn_cmd,
8950 "address-family l2vpn evpn",
8951 "Enter Address Family command mode\n"
8952 "Address Family\n"
8953 "Address Family modifier\n")
8954 {
8955 VTY_DECLVAR_CONTEXT(bgp, bgp);
8956 vty->node = BGP_EVPN_NODE;
8957 return CMD_SUCCESS;
8958 }
8959
8960 DEFUN_NOSH (bgp_segment_routing_srv6,
8961 bgp_segment_routing_srv6_cmd,
8962 "segment-routing srv6",
8963 "Segment-Routing configuration\n"
8964 "Segment-Routing SRv6 configuration\n")
8965 {
8966 VTY_DECLVAR_CONTEXT(bgp, bgp);
8967 bgp->srv6_enabled = true;
8968 vty->node = BGP_SRV6_NODE;
8969 return CMD_SUCCESS;
8970 }
8971
8972 DEFPY (bgp_srv6_locator,
8973 bgp_srv6_locator_cmd,
8974 "locator NAME$name",
8975 "Specify SRv6 locator\n"
8976 "Specify SRv6 locator\n")
8977 {
8978 VTY_DECLVAR_CONTEXT(bgp, bgp);
8979 int ret;
8980
8981 if (strlen(bgp->srv6_locator_name) > 0
8982 && strcmp(name, bgp->srv6_locator_name) != 0) {
8983 vty_out(vty, "srv6 locator is already configured\n");
8984 return CMD_WARNING_CONFIG_FAILED;
8985 }
8986
8987 snprintf(bgp->srv6_locator_name,
8988 sizeof(bgp->srv6_locator_name), "%s", name);
8989
8990 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
8991 if (ret < 0)
8992 return CMD_WARNING_CONFIG_FAILED;
8993
8994 return CMD_SUCCESS;
8995 }
8996
8997 DEFPY (show_bgp_srv6,
8998 show_bgp_srv6_cmd,
8999 "show bgp segment-routing srv6",
9000 SHOW_STR
9001 BGP_STR
9002 "BGP Segment Routing\n"
9003 "BGP Segment Routing SRv6\n")
9004 {
9005 struct bgp *bgp;
9006 struct listnode *node;
9007 struct prefix_ipv6 *chunk;
9008 struct bgp_srv6_function *func;
9009 struct in6_addr *tovpn4_sid;
9010 struct in6_addr *tovpn6_sid;
9011 char buf[256];
9012 char buf_tovpn4_sid[256];
9013 char buf_tovpn6_sid[256];
9014
9015 bgp = bgp_get_default();
9016 if (!bgp)
9017 return CMD_SUCCESS;
9018
9019 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9020 vty_out(vty, "locator_chunks:\n");
9021 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9022 prefix2str(chunk, buf, sizeof(buf));
9023 vty_out(vty, "- %s\n", buf);
9024 }
9025
9026 vty_out(vty, "functions:\n");
9027 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9028 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9029 vty_out(vty, "- sid: %s\n", buf);
9030 vty_out(vty, " locator: %s\n", func->locator_name);
9031 }
9032
9033 vty_out(vty, "bgps:\n");
9034 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9035 vty_out(vty, "- name: %s\n",
9036 bgp->name ? bgp->name : "default");
9037
9038 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9039 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9040 if (tovpn4_sid)
9041 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9042 sizeof(buf_tovpn4_sid));
9043 if (tovpn6_sid)
9044 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9045 sizeof(buf_tovpn6_sid));
9046
9047 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9048 tovpn4_sid ? buf_tovpn4_sid : "none");
9049 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9050 tovpn6_sid ? buf_tovpn6_sid : "none");
9051 }
9052
9053 return CMD_SUCCESS;
9054 }
9055
9056 DEFUN_NOSH (exit_address_family,
9057 exit_address_family_cmd,
9058 "exit-address-family",
9059 "Exit from Address Family configuration mode\n")
9060 {
9061 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9062 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9063 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9064 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9065 || vty->node == BGP_EVPN_NODE
9066 || vty->node == BGP_FLOWSPECV4_NODE
9067 || vty->node == BGP_FLOWSPECV6_NODE)
9068 vty->node = BGP_NODE;
9069 return CMD_SUCCESS;
9070 }
9071
9072 /* Recalculate bestpath and re-advertise a prefix */
9073 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9074 const char *ip_str, afi_t afi, safi_t safi,
9075 struct prefix_rd *prd)
9076 {
9077 int ret;
9078 struct prefix match;
9079 struct bgp_dest *dest;
9080 struct bgp_dest *rm;
9081 struct bgp *bgp;
9082 struct bgp_table *table;
9083 struct bgp_table *rib;
9084
9085 /* BGP structure lookup. */
9086 if (view_name) {
9087 bgp = bgp_lookup_by_name(view_name);
9088 if (bgp == NULL) {
9089 vty_out(vty, "%% Can't find BGP instance %s\n",
9090 view_name);
9091 return CMD_WARNING;
9092 }
9093 } else {
9094 bgp = bgp_get_default();
9095 if (bgp == NULL) {
9096 vty_out(vty, "%% No BGP process is configured\n");
9097 return CMD_WARNING;
9098 }
9099 }
9100
9101 /* Check IP address argument. */
9102 ret = str2prefix(ip_str, &match);
9103 if (!ret) {
9104 vty_out(vty, "%% address is malformed\n");
9105 return CMD_WARNING;
9106 }
9107
9108 match.family = afi2family(afi);
9109 rib = bgp->rib[afi][safi];
9110
9111 if (safi == SAFI_MPLS_VPN) {
9112 for (dest = bgp_table_top(rib); dest;
9113 dest = bgp_route_next(dest)) {
9114 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9115
9116 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9117 continue;
9118
9119 table = bgp_dest_get_bgp_table_info(dest);
9120 if (table == NULL)
9121 continue;
9122
9123 rm = bgp_node_match(table, &match);
9124 if (rm != NULL) {
9125 const struct prefix *rm_p =
9126 bgp_dest_get_prefix(rm);
9127
9128 if (rm_p->prefixlen == match.prefixlen) {
9129 SET_FLAG(rm->flags,
9130 BGP_NODE_USER_CLEAR);
9131 bgp_process(bgp, rm, afi, safi);
9132 }
9133 bgp_dest_unlock_node(rm);
9134 }
9135 }
9136 } else {
9137 dest = bgp_node_match(rib, &match);
9138 if (dest != NULL) {
9139 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9140
9141 if (dest_p->prefixlen == match.prefixlen) {
9142 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9143 bgp_process(bgp, dest, afi, safi);
9144 }
9145 bgp_dest_unlock_node(dest);
9146 }
9147 }
9148
9149 return CMD_SUCCESS;
9150 }
9151
9152 /* one clear bgp command to rule them all */
9153 DEFUN (clear_ip_bgp_all,
9154 clear_ip_bgp_all_cmd,
9155 "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>]",
9156 CLEAR_STR
9157 IP_STR
9158 BGP_STR
9159 BGP_INSTANCE_HELP_STR
9160 BGP_AFI_HELP_STR
9161 "Address Family\n"
9162 BGP_SAFI_WITH_LABEL_HELP_STR
9163 "Address Family modifier\n"
9164 "Clear all peers\n"
9165 "BGP IPv4 neighbor to clear\n"
9166 "BGP IPv6 neighbor to clear\n"
9167 "BGP neighbor on interface to clear\n"
9168 "Clear peers with the AS number\n"
9169 "Clear all external peers\n"
9170 "Clear all members of peer-group\n"
9171 "BGP peer-group name\n"
9172 BGP_SOFT_STR
9173 BGP_SOFT_IN_STR
9174 BGP_SOFT_OUT_STR
9175 BGP_SOFT_IN_STR
9176 "Push out prefix-list ORF and do inbound soft reconfig\n"
9177 BGP_SOFT_OUT_STR)
9178 {
9179 char *vrf = NULL;
9180
9181 afi_t afi = AFI_UNSPEC;
9182 safi_t safi = SAFI_UNSPEC;
9183 enum clear_sort clr_sort = clear_peer;
9184 enum bgp_clear_type clr_type;
9185 char *clr_arg = NULL;
9186
9187 int idx = 0;
9188
9189 /* clear [ip] bgp */
9190 if (argv_find(argv, argc, "ip", &idx))
9191 afi = AFI_IP;
9192
9193 /* [<vrf> VIEWVRFNAME] */
9194 if (argv_find(argv, argc, "vrf", &idx)) {
9195 vrf = argv[idx + 1]->arg;
9196 idx += 2;
9197 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9198 vrf = NULL;
9199 } else if (argv_find(argv, argc, "view", &idx)) {
9200 /* [<view> VIEWVRFNAME] */
9201 vrf = argv[idx + 1]->arg;
9202 idx += 2;
9203 }
9204 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9205 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9206 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9207
9208 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9209 if (argv_find(argv, argc, "*", &idx)) {
9210 clr_sort = clear_all;
9211 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9212 clr_sort = clear_peer;
9213 clr_arg = argv[idx]->arg;
9214 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9215 clr_sort = clear_peer;
9216 clr_arg = argv[idx]->arg;
9217 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9218 clr_sort = clear_group;
9219 idx++;
9220 clr_arg = argv[idx]->arg;
9221 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9222 clr_sort = clear_peer;
9223 clr_arg = argv[idx]->arg;
9224 } else if (argv_find(argv, argc, "WORD", &idx)) {
9225 clr_sort = clear_peer;
9226 clr_arg = argv[idx]->arg;
9227 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9228 clr_sort = clear_as;
9229 clr_arg = argv[idx]->arg;
9230 } else if (argv_find(argv, argc, "external", &idx)) {
9231 clr_sort = clear_external;
9232 }
9233
9234 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9235 if (argv_find(argv, argc, "soft", &idx)) {
9236 if (argv_find(argv, argc, "in", &idx)
9237 || argv_find(argv, argc, "out", &idx))
9238 clr_type = strmatch(argv[idx]->text, "in")
9239 ? BGP_CLEAR_SOFT_IN
9240 : BGP_CLEAR_SOFT_OUT;
9241 else
9242 clr_type = BGP_CLEAR_SOFT_BOTH;
9243 } else if (argv_find(argv, argc, "in", &idx)) {
9244 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9245 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9246 : BGP_CLEAR_SOFT_IN;
9247 } else if (argv_find(argv, argc, "out", &idx)) {
9248 clr_type = BGP_CLEAR_SOFT_OUT;
9249 } else
9250 clr_type = BGP_CLEAR_SOFT_NONE;
9251
9252 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9253 }
9254
9255 DEFUN (clear_ip_bgp_prefix,
9256 clear_ip_bgp_prefix_cmd,
9257 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9258 CLEAR_STR
9259 IP_STR
9260 BGP_STR
9261 BGP_INSTANCE_HELP_STR
9262 "Clear bestpath and re-advertise\n"
9263 "IPv4 prefix\n")
9264 {
9265 char *vrf = NULL;
9266 char *prefix = NULL;
9267
9268 int idx = 0;
9269
9270 /* [<view|vrf> VIEWVRFNAME] */
9271 if (argv_find(argv, argc, "vrf", &idx)) {
9272 vrf = argv[idx + 1]->arg;
9273 idx += 2;
9274 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9275 vrf = NULL;
9276 } else if (argv_find(argv, argc, "view", &idx)) {
9277 /* [<view> VIEWVRFNAME] */
9278 vrf = argv[idx + 1]->arg;
9279 idx += 2;
9280 }
9281
9282 prefix = argv[argc - 1]->arg;
9283
9284 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9285 }
9286
9287 DEFUN (clear_bgp_ipv6_safi_prefix,
9288 clear_bgp_ipv6_safi_prefix_cmd,
9289 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9290 CLEAR_STR
9291 IP_STR
9292 BGP_STR
9293 "Address Family\n"
9294 BGP_SAFI_HELP_STR
9295 "Clear bestpath and re-advertise\n"
9296 "IPv6 prefix\n")
9297 {
9298 int idx_safi = 0;
9299 int idx_ipv6_prefix = 0;
9300 safi_t safi = SAFI_UNICAST;
9301 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9302 argv[idx_ipv6_prefix]->arg : NULL;
9303
9304 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9305 return bgp_clear_prefix(
9306 vty, NULL, prefix, AFI_IP6,
9307 safi, NULL);
9308 }
9309
9310 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9311 clear_bgp_instance_ipv6_safi_prefix_cmd,
9312 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9313 CLEAR_STR
9314 IP_STR
9315 BGP_STR
9316 BGP_INSTANCE_HELP_STR
9317 "Address Family\n"
9318 BGP_SAFI_HELP_STR
9319 "Clear bestpath and re-advertise\n"
9320 "IPv6 prefix\n")
9321 {
9322 int idx_safi = 0;
9323 int idx_vrfview = 0;
9324 int idx_ipv6_prefix = 0;
9325 safi_t safi = SAFI_UNICAST;
9326 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9327 argv[idx_ipv6_prefix]->arg : NULL;
9328 char *vrfview = NULL;
9329
9330 /* [<view|vrf> VIEWVRFNAME] */
9331 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9332 vrfview = argv[idx_vrfview + 1]->arg;
9333 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9334 vrfview = NULL;
9335 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9336 /* [<view> VIEWVRFNAME] */
9337 vrfview = argv[idx_vrfview + 1]->arg;
9338 }
9339 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9340
9341 return bgp_clear_prefix(
9342 vty, vrfview, prefix,
9343 AFI_IP6, safi, NULL);
9344 }
9345
9346 DEFUN (show_bgp_views,
9347 show_bgp_views_cmd,
9348 "show [ip] bgp views",
9349 SHOW_STR
9350 IP_STR
9351 BGP_STR
9352 "Show the defined BGP views\n")
9353 {
9354 struct list *inst = bm->bgp;
9355 struct listnode *node;
9356 struct bgp *bgp;
9357
9358 vty_out(vty, "Defined BGP views:\n");
9359 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9360 /* Skip VRFs. */
9361 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9362 continue;
9363 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9364 bgp->as);
9365 }
9366
9367 return CMD_SUCCESS;
9368 }
9369
9370 DEFUN (show_bgp_vrfs,
9371 show_bgp_vrfs_cmd,
9372 "show [ip] bgp vrfs [json]",
9373 SHOW_STR
9374 IP_STR
9375 BGP_STR
9376 "Show BGP VRFs\n"
9377 JSON_STR)
9378 {
9379 char buf[ETHER_ADDR_STRLEN];
9380 struct list *inst = bm->bgp;
9381 struct listnode *node;
9382 struct bgp *bgp;
9383 bool uj = use_json(argc, argv);
9384 json_object *json = NULL;
9385 json_object *json_vrfs = NULL;
9386 int count = 0;
9387
9388 if (uj) {
9389 json = json_object_new_object();
9390 json_vrfs = json_object_new_object();
9391 }
9392
9393 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9394 const char *name, *type;
9395 struct peer *peer;
9396 struct listnode *node2, *nnode2;
9397 int peers_cfg, peers_estb;
9398 json_object *json_vrf = NULL;
9399
9400 /* Skip Views. */
9401 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9402 continue;
9403
9404 count++;
9405 if (!uj && count == 1) {
9406 vty_out(vty,
9407 "%4s %-5s %-16s %9s %10s %-37s\n",
9408 "Type", "Id", "routerId", "#PeersCfg",
9409 "#PeersEstb", "Name");
9410 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9411 "L3-VNI", "RouterMAC", "Interface");
9412 }
9413
9414 peers_cfg = peers_estb = 0;
9415 if (uj)
9416 json_vrf = json_object_new_object();
9417
9418
9419 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9420 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9421 continue;
9422 peers_cfg++;
9423 if (peer_established(peer))
9424 peers_estb++;
9425 }
9426
9427 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9428 name = VRF_DEFAULT_NAME;
9429 type = "DFLT";
9430 } else {
9431 name = bgp->name;
9432 type = "VRF";
9433 }
9434
9435
9436 if (uj) {
9437 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9438 ? -1
9439 : (int64_t)bgp->vrf_id;
9440 char buf[BUFSIZ] = {0};
9441
9442 json_object_string_add(json_vrf, "type", type);
9443 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9444 json_object_string_add(json_vrf, "routerId",
9445 inet_ntop(AF_INET,
9446 &bgp->router_id, buf,
9447 sizeof(buf)));
9448 json_object_int_add(json_vrf, "numConfiguredPeers",
9449 peers_cfg);
9450 json_object_int_add(json_vrf, "numEstablishedPeers",
9451 peers_estb);
9452
9453 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9454 json_object_string_add(
9455 json_vrf, "rmac",
9456 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9457 json_object_string_add(json_vrf, "interface",
9458 ifindex2ifname(bgp->l3vni_svi_ifindex,
9459 bgp->vrf_id));
9460 json_object_object_add(json_vrfs, name, json_vrf);
9461 } else {
9462 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
9463 type,
9464 bgp->vrf_id == VRF_UNKNOWN ? -1
9465 : (int)bgp->vrf_id,
9466 &bgp->router_id, peers_cfg, peers_estb, name);
9467 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9468 bgp->l3vni,
9469 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9470 ifindex2ifname(bgp->l3vni_svi_ifindex,
9471 bgp->vrf_id));
9472 }
9473 }
9474
9475 if (uj) {
9476 json_object_object_add(json, "vrfs", json_vrfs);
9477
9478 json_object_int_add(json, "totalVrfs", count);
9479
9480 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9481 json, JSON_C_TO_STRING_PRETTY));
9482 json_object_free(json);
9483 } else {
9484 if (count)
9485 vty_out(vty,
9486 "\nTotal number of VRFs (including default): %d\n",
9487 count);
9488 }
9489
9490 return CMD_SUCCESS;
9491 }
9492
9493 DEFUN (show_bgp_mac_hash,
9494 show_bgp_mac_hash_cmd,
9495 "show bgp mac hash",
9496 SHOW_STR
9497 BGP_STR
9498 "Mac Address\n"
9499 "Mac Address database\n")
9500 {
9501 bgp_mac_dump_table(vty);
9502
9503 return CMD_SUCCESS;
9504 }
9505
9506 static void show_tip_entry(struct hash_bucket *bucket, void *args)
9507 {
9508 struct vty *vty = (struct vty *)args;
9509 struct tip_addr *tip = (struct tip_addr *)bucket->data;
9510
9511 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
9512 }
9513
9514 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9515 {
9516 vty_out(vty, "self nexthop database:\n");
9517 bgp_nexthop_show_address_hash(vty, bgp);
9518
9519 vty_out(vty, "Tunnel-ip database:\n");
9520 hash_iterate(bgp->tip_hash,
9521 (void (*)(struct hash_bucket *, void *))show_tip_entry,
9522 vty);
9523 }
9524
9525 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9526 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9527 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
9528 "martian next-hops\n"
9529 "martian next-hop database\n")
9530 {
9531 struct bgp *bgp = NULL;
9532 int idx = 0;
9533 char *name = NULL;
9534
9535 /* [<vrf> VIEWVRFNAME] */
9536 if (argv_find(argv, argc, "vrf", &idx)) {
9537 name = argv[idx + 1]->arg;
9538 if (name && strmatch(name, VRF_DEFAULT_NAME))
9539 name = NULL;
9540 } else if (argv_find(argv, argc, "view", &idx))
9541 /* [<view> VIEWVRFNAME] */
9542 name = argv[idx + 1]->arg;
9543 if (name)
9544 bgp = bgp_lookup_by_name(name);
9545 else
9546 bgp = bgp_get_default();
9547
9548 if (!bgp) {
9549 vty_out(vty, "%% No BGP process is configured\n");
9550 return CMD_WARNING;
9551 }
9552 bgp_show_martian_nexthops(vty, bgp);
9553
9554 return CMD_SUCCESS;
9555 }
9556
9557 DEFUN (show_bgp_memory,
9558 show_bgp_memory_cmd,
9559 "show [ip] bgp memory",
9560 SHOW_STR
9561 IP_STR
9562 BGP_STR
9563 "Global BGP memory statistics\n")
9564 {
9565 char memstrbuf[MTYPE_MEMSTR_LEN];
9566 unsigned long count;
9567
9568 /* RIB related usage stats */
9569 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9570 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9571 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9572 count * sizeof(struct bgp_dest)));
9573
9574 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9575 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9576 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9577 count * sizeof(struct bgp_path_info)));
9578 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9579 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9580 count,
9581 mtype_memstr(
9582 memstrbuf, sizeof(memstrbuf),
9583 count * sizeof(struct bgp_path_info_extra)));
9584
9585 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9586 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9587 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9588 count * sizeof(struct bgp_static)));
9589
9590 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9591 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9592 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9593 count * sizeof(struct bpacket)));
9594
9595 /* Adj-In/Out */
9596 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9597 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9598 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9599 count * sizeof(struct bgp_adj_in)));
9600 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9601 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9602 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9603 count * sizeof(struct bgp_adj_out)));
9604
9605 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9606 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9607 count,
9608 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9609 count * sizeof(struct bgp_nexthop_cache)));
9610
9611 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9612 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9613 count,
9614 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9615 count * sizeof(struct bgp_damp_info)));
9616
9617 /* Attributes */
9618 count = attr_count();
9619 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9620 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9621 count * sizeof(struct attr)));
9622
9623 if ((count = attr_unknown_count()))
9624 vty_out(vty, "%ld unknown attributes\n", count);
9625
9626 /* AS_PATH attributes */
9627 count = aspath_count();
9628 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9629 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9630 count * sizeof(struct aspath)));
9631
9632 count = mtype_stats_alloc(MTYPE_AS_SEG);
9633 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9634 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9635 count * sizeof(struct assegment)));
9636
9637 /* Other attributes */
9638 if ((count = community_count()))
9639 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9640 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9641 count * sizeof(struct community)));
9642 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9643 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9644 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9645 count * sizeof(struct ecommunity)));
9646 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9647 vty_out(vty,
9648 "%ld BGP large-community entries, using %s of memory\n",
9649 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9650 count * sizeof(struct lcommunity)));
9651
9652 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9653 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9654 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9655 count * sizeof(struct cluster_list)));
9656
9657 /* Peer related usage */
9658 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9659 vty_out(vty, "%ld peers, using %s of memory\n", count,
9660 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9661 count * sizeof(struct peer)));
9662
9663 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9664 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9666 count * sizeof(struct peer_group)));
9667
9668 /* Other */
9669 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9670 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9671 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9672 count * sizeof(regex_t)));
9673 return CMD_SUCCESS;
9674 }
9675
9676 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9677 {
9678 json_object *bestpath = json_object_new_object();
9679
9680 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
9681 json_object_string_add(bestpath, "asPath", "ignore");
9682
9683 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
9684 json_object_string_add(bestpath, "asPath", "confed");
9685
9686 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9687 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
9688 json_object_string_add(bestpath, "multiPathRelax",
9689 "as-set");
9690 else
9691 json_object_string_add(bestpath, "multiPathRelax",
9692 "true");
9693 } else
9694 json_object_string_add(bestpath, "multiPathRelax", "false");
9695
9696 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9697 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9698
9699 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
9700 json_object_string_add(bestpath, "compareRouterId", "true");
9701 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9702 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9703 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
9704 json_object_string_add(bestpath, "med", "confed");
9705 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
9706 json_object_string_add(bestpath, "med",
9707 "missing-as-worst");
9708 else
9709 json_object_string_add(bestpath, "med", "true");
9710 }
9711
9712 json_object_object_add(json, "bestPath", bestpath);
9713 }
9714
9715 /* Print the error code/subcode for why the peer is down */
9716 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9717 json_object *json_peer, bool use_json)
9718 {
9719 const char *code_str;
9720 const char *subcode_str;
9721
9722 if (use_json) {
9723 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9724 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9725 char errorcodesubcode_hexstr[5];
9726 char errorcodesubcode_str[256];
9727
9728 code_str = bgp_notify_code_str(peer->notify.code);
9729 subcode_str = bgp_notify_subcode_str(
9730 peer->notify.code,
9731 peer->notify.subcode);
9732
9733 snprintf(errorcodesubcode_hexstr,
9734 sizeof(errorcodesubcode_hexstr), "%02X%02X",
9735 peer->notify.code, peer->notify.subcode);
9736 json_object_string_add(json_peer,
9737 "lastErrorCodeSubcode",
9738 errorcodesubcode_hexstr);
9739 snprintf(errorcodesubcode_str, 255, "%s%s",
9740 code_str, subcode_str);
9741 json_object_string_add(json_peer,
9742 "lastNotificationReason",
9743 errorcodesubcode_str);
9744 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9745 && peer->notify.code == BGP_NOTIFY_CEASE
9746 && (peer->notify.subcode
9747 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9748 || peer->notify.subcode
9749 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9750 && peer->notify.length) {
9751 char msgbuf[1024];
9752 const char *msg_str;
9753
9754 msg_str = bgp_notify_admin_message(
9755 msgbuf, sizeof(msgbuf),
9756 (uint8_t *)peer->notify.data,
9757 peer->notify.length);
9758 if (msg_str)
9759 json_object_string_add(
9760 json_peer,
9761 "lastShutdownDescription",
9762 msg_str);
9763 }
9764
9765 }
9766 json_object_string_add(json_peer, "lastResetDueTo",
9767 peer_down_str[(int)peer->last_reset]);
9768 json_object_int_add(json_peer, "lastResetCode",
9769 peer->last_reset);
9770 } else {
9771 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9772 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9773 code_str = bgp_notify_code_str(peer->notify.code);
9774 subcode_str =
9775 bgp_notify_subcode_str(peer->notify.code,
9776 peer->notify.subcode);
9777 vty_out(vty, " Notification %s (%s%s)\n",
9778 peer->last_reset == PEER_DOWN_NOTIFY_SEND
9779 ? "sent"
9780 : "received",
9781 code_str, subcode_str);
9782 } else {
9783 vty_out(vty, " %s\n",
9784 peer_down_str[(int)peer->last_reset]);
9785 }
9786 }
9787 }
9788
9789 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
9790 safi_t safi)
9791 {
9792 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
9793 }
9794
9795 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
9796 struct peer *peer, json_object *json_peer,
9797 int max_neighbor_width, bool use_json)
9798 {
9799 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9800 int len;
9801
9802 if (use_json) {
9803 if (peer_dynamic_neighbor(peer))
9804 json_object_boolean_true_add(json_peer,
9805 "dynamicPeer");
9806 if (peer->hostname)
9807 json_object_string_add(json_peer, "hostname",
9808 peer->hostname);
9809
9810 if (peer->domainname)
9811 json_object_string_add(json_peer, "domainname",
9812 peer->domainname);
9813 json_object_int_add(json_peer, "connectionsEstablished",
9814 peer->established);
9815 json_object_int_add(json_peer, "connectionsDropped",
9816 peer->dropped);
9817 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9818 use_json, json_peer);
9819 if (peer_established(peer))
9820 json_object_string_add(json_peer, "lastResetDueTo",
9821 "AFI/SAFI Not Negotiated");
9822 else
9823 bgp_show_peer_reset(NULL, peer, json_peer, true);
9824 } else {
9825 dn_flag[1] = '\0';
9826 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
9827 if (peer->hostname
9828 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
9829 len = vty_out(vty, "%s%s(%s)", dn_flag,
9830 peer->hostname, peer->host);
9831 else
9832 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9833
9834 /* pad the neighbor column with spaces */
9835 if (len < max_neighbor_width)
9836 vty_out(vty, "%*s", max_neighbor_width - len,
9837 " ");
9838 vty_out(vty, "%7d %7d %9s", peer->established,
9839 peer->dropped,
9840 peer_uptime(peer->uptime, timebuf,
9841 BGP_UPTIME_LEN, 0, NULL));
9842 if (peer_established(peer))
9843 vty_out(vty, " AFI/SAFI Not Negotiated\n");
9844 else
9845 bgp_show_peer_reset(vty, peer, NULL,
9846 false);
9847 }
9848 }
9849
9850 /* If the peer's description includes whitespaces
9851 * then return the first occurrence. Also strip description
9852 * to the given size if needed.
9853 */
9854 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
9855 {
9856 static char stripped[BUFSIZ];
9857 char *pnt;
9858 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
9859
9860 pnt = strchr(desc, ' ');
9861 if (pnt)
9862 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
9863 : size;
9864
9865 strlcpy(stripped, desc, len + 1);
9866
9867 return stripped;
9868 }
9869
9870 /* Determine whether var peer should be filtered out of the summary. */
9871 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
9872 struct peer *fpeer, int as_type,
9873 as_t as)
9874 {
9875
9876 /* filter neighbor XXXX */
9877 if (fpeer && fpeer != peer)
9878 return true;
9879
9880 /* filter remote-as (internal|external) */
9881 if (as_type != AS_UNSPECIFIED) {
9882 if (peer->as_type == AS_SPECIFIED) {
9883 if (as_type == AS_INTERNAL) {
9884 if (peer->as != peer->local_as)
9885 return true;
9886 } else if (peer->as == peer->local_as)
9887 return true;
9888 } else if (as_type != peer->as_type)
9889 return true;
9890 } else if (as && as != peer->as) /* filter remote-as XXX */
9891 return true;
9892
9893 return false;
9894 }
9895
9896 /* Show BGP peer's summary information. */
9897 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9898 struct peer *fpeer, int as_type, as_t as,
9899 uint16_t show_flags)
9900 {
9901 struct peer *peer;
9902 struct listnode *node, *nnode;
9903 unsigned int count = 0, dn_count = 0;
9904 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9905 char neighbor_buf[VTY_BUFSIZ];
9906 int neighbor_col_default_width = 16;
9907 int len, failed_count = 0;
9908 unsigned int filtered_count = 0;
9909 int max_neighbor_width = 0;
9910 int pfx_rcd_safi;
9911 json_object *json = NULL;
9912 json_object *json_peer = NULL;
9913 json_object *json_peers = NULL;
9914 struct peer_af *paf;
9915 struct bgp_filter *filter;
9916 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
9917 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
9918 bool show_established =
9919 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
9920 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
9921 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
9922
9923 /* labeled-unicast routes are installed in the unicast table so in order
9924 * to
9925 * display the correct PfxRcd value we must look at SAFI_UNICAST
9926 */
9927
9928 if (safi == SAFI_LABELED_UNICAST)
9929 pfx_rcd_safi = SAFI_UNICAST;
9930 else
9931 pfx_rcd_safi = safi;
9932
9933 if (use_json) {
9934 json = json_object_new_object();
9935 json_peers = json_object_new_object();
9936 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9937 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
9938 as_type, as)) {
9939 filtered_count++;
9940 count++;
9941 continue;
9942 }
9943
9944 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9945 continue;
9946
9947 if (peer->afc[afi][safi]) {
9948 /* See if we have at least a single failed peer */
9949 if (bgp_has_peer_failed(peer, afi, safi))
9950 failed_count++;
9951 count++;
9952 }
9953 if (peer_dynamic_neighbor(peer))
9954 dn_count++;
9955 }
9956
9957 } else {
9958 /* Loop over all neighbors that will be displayed to determine
9959 * how many
9960 * characters are needed for the Neighbor column
9961 */
9962 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9963 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
9964 as_type, as)) {
9965 filtered_count++;
9966 count++;
9967 continue;
9968 }
9969
9970 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9971 continue;
9972
9973 if (peer->afc[afi][safi]) {
9974 memset(dn_flag, '\0', sizeof(dn_flag));
9975 if (peer_dynamic_neighbor(peer))
9976 dn_flag[0] = '*';
9977
9978 if (peer->hostname
9979 && CHECK_FLAG(bgp->flags,
9980 BGP_FLAG_SHOW_HOSTNAME))
9981 snprintf(neighbor_buf,
9982 sizeof(neighbor_buf),
9983 "%s%s(%s) ", dn_flag,
9984 peer->hostname, peer->host);
9985 else
9986 snprintf(neighbor_buf,
9987 sizeof(neighbor_buf), "%s%s ",
9988 dn_flag, peer->host);
9989
9990 len = strlen(neighbor_buf);
9991
9992 if (len > max_neighbor_width)
9993 max_neighbor_width = len;
9994
9995 /* See if we have at least a single failed peer */
9996 if (bgp_has_peer_failed(peer, afi, safi))
9997 failed_count++;
9998 count++;
9999 }
10000 }
10001
10002 /* Originally we displayed the Neighbor column as 16
10003 * characters wide so make that the default
10004 */
10005 if (max_neighbor_width < neighbor_col_default_width)
10006 max_neighbor_width = neighbor_col_default_width;
10007 }
10008
10009 if (show_failed && !failed_count) {
10010 if (use_json) {
10011 json_object_int_add(json, "failedPeersCount", 0);
10012 json_object_int_add(json, "dynamicPeers", dn_count);
10013 json_object_int_add(json, "totalPeers", count);
10014
10015 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10016 json, JSON_C_TO_STRING_PRETTY));
10017 json_object_free(json);
10018 } else {
10019 vty_out(vty, "%% No failed BGP neighbors found\n");
10020 }
10021 return CMD_SUCCESS;
10022 }
10023
10024 count = 0; /* Reset the value as its used again */
10025 filtered_count = 0;
10026 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10027 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10028 continue;
10029
10030 if (!peer->afc[afi][safi])
10031 continue;
10032
10033 if (!count) {
10034 unsigned long ents;
10035 char memstrbuf[MTYPE_MEMSTR_LEN];
10036 int64_t vrf_id_ui;
10037
10038 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10039 ? -1
10040 : (int64_t)bgp->vrf_id;
10041
10042 /* Usage summary and header */
10043 if (use_json) {
10044 char buf[BUFSIZ] = {0};
10045
10046 json_object_string_add(
10047 json, "routerId",
10048 inet_ntop(AF_INET, &bgp->router_id, buf,
10049 sizeof(buf)));
10050 json_object_int_add(json, "as", bgp->as);
10051 json_object_int_add(json, "vrfId", vrf_id_ui);
10052 json_object_string_add(
10053 json, "vrfName",
10054 (bgp->inst_type
10055 == BGP_INSTANCE_TYPE_DEFAULT)
10056 ? VRF_DEFAULT_NAME
10057 : bgp->name);
10058 } else {
10059 vty_out(vty,
10060 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10061 &bgp->router_id, bgp->as,
10062 bgp->vrf_id == VRF_UNKNOWN
10063 ? -1
10064 : (int)bgp->vrf_id);
10065 vty_out(vty, "\n");
10066 }
10067
10068 if (bgp_update_delay_configured(bgp)) {
10069 if (use_json) {
10070 json_object_int_add(
10071 json, "updateDelayLimit",
10072 bgp->v_update_delay);
10073
10074 if (bgp->v_update_delay
10075 != bgp->v_establish_wait)
10076 json_object_int_add(
10077 json,
10078 "updateDelayEstablishWait",
10079 bgp->v_establish_wait);
10080
10081 if (bgp_update_delay_active(bgp)) {
10082 json_object_string_add(
10083 json,
10084 "updateDelayFirstNeighbor",
10085 bgp->update_delay_begin_time);
10086 json_object_boolean_true_add(
10087 json,
10088 "updateDelayInProgress");
10089 } else {
10090 if (bgp->update_delay_over) {
10091 json_object_string_add(
10092 json,
10093 "updateDelayFirstNeighbor",
10094 bgp->update_delay_begin_time);
10095 json_object_string_add(
10096 json,
10097 "updateDelayBestpathResumed",
10098 bgp->update_delay_end_time);
10099 json_object_string_add(
10100 json,
10101 "updateDelayZebraUpdateResume",
10102 bgp->update_delay_zebra_resume_time);
10103 json_object_string_add(
10104 json,
10105 "updateDelayPeerUpdateResume",
10106 bgp->update_delay_peers_resume_time);
10107 }
10108 }
10109 } else {
10110 vty_out(vty,
10111 "Read-only mode update-delay limit: %d seconds\n",
10112 bgp->v_update_delay);
10113 if (bgp->v_update_delay
10114 != bgp->v_establish_wait)
10115 vty_out(vty,
10116 " Establish wait: %d seconds\n",
10117 bgp->v_establish_wait);
10118
10119 if (bgp_update_delay_active(bgp)) {
10120 vty_out(vty,
10121 " First neighbor established: %s\n",
10122 bgp->update_delay_begin_time);
10123 vty_out(vty,
10124 " Delay in progress\n");
10125 } else {
10126 if (bgp->update_delay_over) {
10127 vty_out(vty,
10128 " First neighbor established: %s\n",
10129 bgp->update_delay_begin_time);
10130 vty_out(vty,
10131 " Best-paths resumed: %s\n",
10132 bgp->update_delay_end_time);
10133 vty_out(vty,
10134 " zebra update resumed: %s\n",
10135 bgp->update_delay_zebra_resume_time);
10136 vty_out(vty,
10137 " peers update resumed: %s\n",
10138 bgp->update_delay_peers_resume_time);
10139 }
10140 }
10141 }
10142 }
10143
10144 if (use_json) {
10145 if (bgp_maxmed_onstartup_configured(bgp)
10146 && bgp->maxmed_active)
10147 json_object_boolean_true_add(
10148 json, "maxMedOnStartup");
10149 if (bgp->v_maxmed_admin)
10150 json_object_boolean_true_add(
10151 json, "maxMedAdministrative");
10152
10153 json_object_int_add(
10154 json, "tableVersion",
10155 bgp_table_version(bgp->rib[afi][safi]));
10156
10157 ents = bgp_table_count(bgp->rib[afi][safi]);
10158 json_object_int_add(json, "ribCount", ents);
10159 json_object_int_add(
10160 json, "ribMemory",
10161 ents * sizeof(struct bgp_dest));
10162
10163 ents = bgp->af_peer_count[afi][safi];
10164 json_object_int_add(json, "peerCount", ents);
10165 json_object_int_add(json, "peerMemory",
10166 ents * sizeof(struct peer));
10167
10168 if ((ents = listcount(bgp->group))) {
10169 json_object_int_add(
10170 json, "peerGroupCount", ents);
10171 json_object_int_add(
10172 json, "peerGroupMemory",
10173 ents * sizeof(struct
10174 peer_group));
10175 }
10176
10177 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10178 BGP_CONFIG_DAMPENING))
10179 json_object_boolean_true_add(
10180 json, "dampeningEnabled");
10181 } else {
10182 if (!show_terse) {
10183 if (bgp_maxmed_onstartup_configured(bgp)
10184 && bgp->maxmed_active)
10185 vty_out(vty,
10186 "Max-med on-startup active\n");
10187 if (bgp->v_maxmed_admin)
10188 vty_out(vty,
10189 "Max-med administrative active\n");
10190
10191 vty_out(vty,
10192 "BGP table version %" PRIu64
10193 "\n",
10194 bgp_table_version(
10195 bgp->rib[afi][safi]));
10196
10197 ents = bgp_table_count(
10198 bgp->rib[afi][safi]);
10199 vty_out(vty,
10200 "RIB entries %ld, using %s of memory\n",
10201 ents,
10202 mtype_memstr(
10203 memstrbuf,
10204 sizeof(memstrbuf),
10205 ents
10206 * sizeof(
10207 struct
10208 bgp_dest)));
10209
10210 /* Peer related usage */
10211 ents = bgp->af_peer_count[afi][safi];
10212 vty_out(vty,
10213 "Peers %ld, using %s of memory\n",
10214 ents,
10215 mtype_memstr(
10216 memstrbuf,
10217 sizeof(memstrbuf),
10218 ents
10219 * sizeof(
10220 struct
10221 peer)));
10222
10223 if ((ents = listcount(bgp->group)))
10224 vty_out(vty,
10225 "Peer groups %ld, using %s of memory\n",
10226 ents,
10227 mtype_memstr(
10228 memstrbuf,
10229 sizeof(memstrbuf),
10230 ents
10231 * sizeof(
10232 struct
10233 peer_group)));
10234
10235 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10236 BGP_CONFIG_DAMPENING))
10237 vty_out(vty,
10238 "Dampening enabled.\n");
10239 }
10240 if (show_failed) {
10241 vty_out(vty, "\n");
10242
10243 /* Subtract 8 here because 'Neighbor' is
10244 * 8 characters */
10245 vty_out(vty, "Neighbor");
10246 vty_out(vty, "%*s",
10247 max_neighbor_width - 8, " ");
10248 vty_out(vty,
10249 BGP_SHOW_SUMMARY_HEADER_FAILED);
10250 }
10251 }
10252 }
10253
10254 paf = peer_af_find(peer, afi, safi);
10255 filter = &peer->filter[afi][safi];
10256
10257 count++;
10258 /* Works for both failed & successful cases */
10259 if (peer_dynamic_neighbor(peer))
10260 dn_count++;
10261
10262 if (use_json) {
10263 json_peer = NULL;
10264 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10265 as_type, as)) {
10266 filtered_count++;
10267 continue;
10268 }
10269 if (show_failed &&
10270 bgp_has_peer_failed(peer, afi, safi)) {
10271 json_peer = json_object_new_object();
10272 bgp_show_failed_summary(vty, bgp, peer,
10273 json_peer, 0, use_json);
10274 } else if (!show_failed) {
10275 if (show_established
10276 && bgp_has_peer_failed(peer, afi, safi)) {
10277 filtered_count++;
10278 continue;
10279 }
10280
10281 json_peer = json_object_new_object();
10282 if (peer_dynamic_neighbor(peer)) {
10283 json_object_boolean_true_add(json_peer,
10284 "dynamicPeer");
10285 }
10286
10287 if (peer->hostname)
10288 json_object_string_add(json_peer, "hostname",
10289 peer->hostname);
10290
10291 if (peer->domainname)
10292 json_object_string_add(json_peer, "domainname",
10293 peer->domainname);
10294
10295 json_object_int_add(json_peer, "remoteAs", peer->as);
10296 json_object_int_add(
10297 json_peer, "localAs",
10298 peer->change_local_as
10299 ? peer->change_local_as
10300 : peer->local_as);
10301 json_object_int_add(json_peer, "version", 4);
10302 json_object_int_add(json_peer, "msgRcvd",
10303 PEER_TOTAL_RX(peer));
10304 json_object_int_add(json_peer, "msgSent",
10305 PEER_TOTAL_TX(peer));
10306
10307 atomic_size_t outq_count, inq_count;
10308 outq_count = atomic_load_explicit(
10309 &peer->obuf->count,
10310 memory_order_relaxed);
10311 inq_count = atomic_load_explicit(
10312 &peer->ibuf->count,
10313 memory_order_relaxed);
10314
10315 json_object_int_add(json_peer, "tableVersion",
10316 peer->version[afi][safi]);
10317 json_object_int_add(json_peer, "outq",
10318 outq_count);
10319 json_object_int_add(json_peer, "inq",
10320 inq_count);
10321 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10322 use_json, json_peer);
10323
10324 json_object_int_add(json_peer, "pfxRcd",
10325 peer->pcount[afi][pfx_rcd_safi]);
10326
10327 if (paf && PAF_SUBGRP(paf))
10328 json_object_int_add(
10329 json_peer, "pfxSnt",
10330 (PAF_SUBGRP(paf))->scount);
10331 else
10332 json_object_int_add(json_peer, "pfxSnt",
10333 0);
10334
10335 /* BGP FSM state */
10336 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10337 || CHECK_FLAG(peer->bgp->flags,
10338 BGP_FLAG_SHUTDOWN))
10339 json_object_string_add(json_peer,
10340 "state",
10341 "Idle (Admin)");
10342 else if (peer->afc_recv[afi][safi])
10343 json_object_string_add(
10344 json_peer, "state",
10345 lookup_msg(bgp_status_msg,
10346 peer->status, NULL));
10347 else if (CHECK_FLAG(
10348 peer->sflags,
10349 PEER_STATUS_PREFIX_OVERFLOW))
10350 json_object_string_add(json_peer,
10351 "state",
10352 "Idle (PfxCt)");
10353 else
10354 json_object_string_add(
10355 json_peer, "state",
10356 lookup_msg(bgp_status_msg,
10357 peer->status, NULL));
10358
10359 /* BGP peer state */
10360 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10361 || CHECK_FLAG(peer->bgp->flags,
10362 BGP_FLAG_SHUTDOWN))
10363 json_object_string_add(json_peer,
10364 "peerState",
10365 "Admin");
10366 else if (CHECK_FLAG(
10367 peer->sflags,
10368 PEER_STATUS_PREFIX_OVERFLOW))
10369 json_object_string_add(json_peer,
10370 "peerState",
10371 "PfxCt");
10372 else if (CHECK_FLAG(peer->flags,
10373 PEER_FLAG_PASSIVE))
10374 json_object_string_add(json_peer,
10375 "peerState",
10376 "Passive");
10377 else if (CHECK_FLAG(peer->sflags,
10378 PEER_STATUS_NSF_WAIT))
10379 json_object_string_add(json_peer,
10380 "peerState",
10381 "NSF passive");
10382 else if (CHECK_FLAG(
10383 peer->bgp->flags,
10384 BGP_FLAG_EBGP_REQUIRES_POLICY)
10385 && (!bgp_inbound_policy_exists(peer,
10386 filter)
10387 || !bgp_outbound_policy_exists(
10388 peer, filter)))
10389 json_object_string_add(json_peer,
10390 "peerState",
10391 "Policy");
10392 else
10393 json_object_string_add(
10394 json_peer, "peerState", "OK");
10395
10396 json_object_int_add(json_peer, "connectionsEstablished",
10397 peer->established);
10398 json_object_int_add(json_peer, "connectionsDropped",
10399 peer->dropped);
10400 if (peer->desc)
10401 json_object_string_add(
10402 json_peer, "desc", peer->desc);
10403 }
10404 /* Avoid creating empty peer dicts in JSON */
10405 if (json_peer == NULL)
10406 continue;
10407
10408 if (peer->conf_if)
10409 json_object_string_add(json_peer, "idType",
10410 "interface");
10411 else if (peer->su.sa.sa_family == AF_INET)
10412 json_object_string_add(json_peer, "idType",
10413 "ipv4");
10414 else if (peer->su.sa.sa_family == AF_INET6)
10415 json_object_string_add(json_peer, "idType",
10416 "ipv6");
10417 json_object_object_add(json_peers, peer->host,
10418 json_peer);
10419 } else {
10420 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10421 as_type, as)) {
10422 filtered_count++;
10423 continue;
10424 }
10425 if (show_failed &&
10426 bgp_has_peer_failed(peer, afi, safi)) {
10427 bgp_show_failed_summary(vty, bgp, peer, NULL,
10428 max_neighbor_width,
10429 use_json);
10430 } else if (!show_failed) {
10431 if (show_established
10432 && bgp_has_peer_failed(peer, afi, safi)) {
10433 filtered_count++;
10434 continue;
10435 }
10436
10437 if ((count - filtered_count) == 1) {
10438 /* display headline before the first
10439 * neighbor line */
10440 vty_out(vty, "\n");
10441
10442 /* Subtract 8 here because 'Neighbor' is
10443 * 8 characters */
10444 vty_out(vty, "Neighbor");
10445 vty_out(vty, "%*s",
10446 max_neighbor_width - 8, " ");
10447 vty_out(vty,
10448 show_wide
10449 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10450 : BGP_SHOW_SUMMARY_HEADER_ALL);
10451 }
10452
10453 memset(dn_flag, '\0', sizeof(dn_flag));
10454 if (peer_dynamic_neighbor(peer)) {
10455 dn_flag[0] = '*';
10456 }
10457
10458 if (peer->hostname
10459 && CHECK_FLAG(bgp->flags,
10460 BGP_FLAG_SHOW_HOSTNAME))
10461 len = vty_out(vty, "%s%s(%s)", dn_flag,
10462 peer->hostname,
10463 peer->host);
10464 else
10465 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10466
10467 /* pad the neighbor column with spaces */
10468 if (len < max_neighbor_width)
10469 vty_out(vty, "%*s", max_neighbor_width - len,
10470 " ");
10471
10472 atomic_size_t outq_count, inq_count;
10473 outq_count = atomic_load_explicit(
10474 &peer->obuf->count,
10475 memory_order_relaxed);
10476 inq_count = atomic_load_explicit(
10477 &peer->ibuf->count,
10478 memory_order_relaxed);
10479
10480 if (show_wide)
10481 vty_out(vty,
10482 "4 %10u %10u %9u %9u %8" PRIu64
10483 " %4zu %4zu %8s",
10484 peer->as,
10485 peer->change_local_as
10486 ? peer->change_local_as
10487 : peer->local_as,
10488 PEER_TOTAL_RX(peer),
10489 PEER_TOTAL_TX(peer),
10490 peer->version[afi][safi],
10491 inq_count, outq_count,
10492 peer_uptime(peer->uptime,
10493 timebuf,
10494 BGP_UPTIME_LEN, 0,
10495 NULL));
10496 else
10497 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10498 " %4zu %4zu %8s",
10499 peer->as, PEER_TOTAL_RX(peer),
10500 PEER_TOTAL_TX(peer),
10501 peer->version[afi][safi],
10502 inq_count, outq_count,
10503 peer_uptime(peer->uptime,
10504 timebuf,
10505 BGP_UPTIME_LEN, 0,
10506 NULL));
10507
10508 if (peer_established(peer)) {
10509 if (peer->afc_recv[afi][safi]) {
10510 if (CHECK_FLAG(
10511 bgp->flags,
10512 BGP_FLAG_EBGP_REQUIRES_POLICY)
10513 && !bgp_inbound_policy_exists(
10514 peer, filter))
10515 vty_out(vty, " %12s",
10516 "(Policy)");
10517 else
10518 vty_out(vty,
10519 " %12u",
10520 peer->pcount
10521 [afi]
10522 [pfx_rcd_safi]);
10523 } else {
10524 vty_out(vty, " NoNeg");
10525 }
10526
10527 if (paf && PAF_SUBGRP(paf)) {
10528 if (CHECK_FLAG(
10529 bgp->flags,
10530 BGP_FLAG_EBGP_REQUIRES_POLICY)
10531 && !bgp_outbound_policy_exists(
10532 peer, filter))
10533 vty_out(vty, " %8s",
10534 "(Policy)");
10535 else
10536 vty_out(vty,
10537 " %8u",
10538 (PAF_SUBGRP(
10539 paf))
10540 ->scount);
10541 } else {
10542 vty_out(vty, " NoNeg");
10543 }
10544 } else {
10545 if (CHECK_FLAG(peer->flags,
10546 PEER_FLAG_SHUTDOWN)
10547 || CHECK_FLAG(peer->bgp->flags,
10548 BGP_FLAG_SHUTDOWN))
10549 vty_out(vty, " Idle (Admin)");
10550 else if (CHECK_FLAG(
10551 peer->sflags,
10552 PEER_STATUS_PREFIX_OVERFLOW))
10553 vty_out(vty, " Idle (PfxCt)");
10554 else
10555 vty_out(vty, " %12s",
10556 lookup_msg(bgp_status_msg,
10557 peer->status, NULL));
10558
10559 vty_out(vty, " %8u", 0);
10560 }
10561 if (peer->desc)
10562 vty_out(vty, " %s",
10563 bgp_peer_description_stripped(
10564 peer->desc,
10565 show_wide ? 64 : 20));
10566 else
10567 vty_out(vty, " N/A");
10568 vty_out(vty, "\n");
10569 }
10570
10571 }
10572 }
10573
10574 if (use_json) {
10575 json_object_object_add(json, "peers", json_peers);
10576 json_object_int_add(json, "failedPeers", failed_count);
10577 json_object_int_add(json, "displayedPeers",
10578 count - filtered_count);
10579 json_object_int_add(json, "totalPeers", count);
10580 json_object_int_add(json, "dynamicPeers", dn_count);
10581
10582 if (!show_failed)
10583 bgp_show_bestpath_json(bgp, json);
10584
10585 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10586 json, JSON_C_TO_STRING_PRETTY));
10587 json_object_free(json);
10588 } else {
10589 if (count) {
10590 if (filtered_count == count)
10591 vty_out(vty, "\n%% No matching neighbor\n");
10592 else {
10593 if (show_failed)
10594 vty_out(vty, "\nDisplayed neighbors %d",
10595 failed_count);
10596 else if (as_type != AS_UNSPECIFIED || as
10597 || fpeer || show_established)
10598 vty_out(vty, "\nDisplayed neighbors %d",
10599 count - filtered_count);
10600
10601 vty_out(vty, "\nTotal number of neighbors %d\n",
10602 count);
10603 }
10604 } else {
10605 vty_out(vty, "No %s neighbor is configured\n",
10606 get_afi_safi_str(afi, safi, false));
10607 }
10608
10609 if (dn_count) {
10610 vty_out(vty, "* - dynamic neighbor\n");
10611 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10612 dn_count, bgp->dynamic_neighbors_limit);
10613 }
10614 }
10615
10616 return CMD_SUCCESS;
10617 }
10618
10619 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10620 int safi, struct peer *fpeer, int as_type,
10621 as_t as, uint16_t show_flags)
10622 {
10623 int is_first = 1;
10624 int afi_wildcard = (afi == AFI_MAX);
10625 int safi_wildcard = (safi == SAFI_MAX);
10626 int is_wildcard = (afi_wildcard || safi_wildcard);
10627 bool nbr_output = false;
10628 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10629
10630 if (use_json && is_wildcard)
10631 vty_out(vty, "{\n");
10632 if (afi_wildcard)
10633 afi = 1; /* AFI_IP */
10634 while (afi < AFI_MAX) {
10635 if (safi_wildcard)
10636 safi = 1; /* SAFI_UNICAST */
10637 while (safi < SAFI_MAX) {
10638 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
10639 nbr_output = true;
10640
10641 if (is_wildcard) {
10642 /*
10643 * So limit output to those afi/safi
10644 * pairs that
10645 * actualy have something interesting in
10646 * them
10647 */
10648 if (use_json) {
10649 if (!is_first)
10650 vty_out(vty, ",\n");
10651 else
10652 is_first = 0;
10653
10654 vty_out(vty, "\"%s\":",
10655 get_afi_safi_str(afi,
10656 safi,
10657 true));
10658 } else {
10659 vty_out(vty,
10660 "\n%s Summary (%s):\n",
10661 get_afi_safi_str(afi,
10662 safi,
10663 false),
10664 bgp->name_pretty);
10665 }
10666 }
10667 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10668 as_type, as, show_flags);
10669 }
10670 safi++;
10671 if (!safi_wildcard)
10672 safi = SAFI_MAX;
10673 }
10674 afi++;
10675 if (!afi_wildcard)
10676 afi = AFI_MAX;
10677 }
10678
10679 if (use_json && is_wildcard)
10680 vty_out(vty, "}\n");
10681 else if (!nbr_output) {
10682 if (use_json)
10683 vty_out(vty, "{}\n");
10684 else
10685 vty_out(vty, "%% No BGP neighbors found in %s\n",
10686 bgp->name_pretty);
10687 }
10688 }
10689
10690 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
10691 safi_t safi,
10692 const char *neighbor,
10693 int as_type, as_t as,
10694 uint16_t show_flags)
10695 {
10696 struct listnode *node, *nnode;
10697 struct bgp *bgp;
10698 struct peer *fpeer = NULL;
10699 int is_first = 1;
10700 bool nbr_output = false;
10701 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10702
10703 if (use_json)
10704 vty_out(vty, "{\n");
10705
10706 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10707 nbr_output = true;
10708 if (use_json) {
10709 if (!is_first)
10710 vty_out(vty, ",\n");
10711 else
10712 is_first = 0;
10713
10714 vty_out(vty, "\"%s\":",
10715 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10716 ? VRF_DEFAULT_NAME
10717 : bgp->name);
10718 }
10719 if (neighbor) {
10720 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10721 use_json);
10722 if (!fpeer)
10723 continue;
10724 }
10725 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
10726 as, show_flags);
10727 }
10728
10729 if (use_json)
10730 vty_out(vty, "}\n");
10731 else if (!nbr_output)
10732 vty_out(vty, "%% BGP instance not found\n");
10733 }
10734
10735 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10736 safi_t safi, const char *neighbor, int as_type,
10737 as_t as, uint16_t show_flags)
10738 {
10739 struct bgp *bgp;
10740 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10741 struct peer *fpeer = NULL;
10742
10743 if (name) {
10744 if (strmatch(name, "all")) {
10745 bgp_show_all_instances_summary_vty(vty, afi, safi,
10746 neighbor, as_type,
10747 as, show_flags);
10748 return CMD_SUCCESS;
10749 } else {
10750 bgp = bgp_lookup_by_name(name);
10751
10752 if (!bgp) {
10753 if (use_json)
10754 vty_out(vty, "{}\n");
10755 else
10756 vty_out(vty,
10757 "%% BGP instance not found\n");
10758 return CMD_WARNING;
10759 }
10760
10761 if (neighbor) {
10762 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10763 use_json);
10764 if (!fpeer)
10765 return CMD_WARNING;
10766 }
10767 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
10768 as_type, as, show_flags);
10769 return CMD_SUCCESS;
10770 }
10771 }
10772
10773 bgp = bgp_get_default();
10774
10775 if (bgp) {
10776 if (neighbor) {
10777 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10778 use_json);
10779 if (!fpeer)
10780 return CMD_WARNING;
10781 }
10782 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
10783 as, show_flags);
10784 } else {
10785 if (use_json)
10786 vty_out(vty, "{}\n");
10787 else
10788 vty_out(vty, "%% BGP instance not found\n");
10789 return CMD_WARNING;
10790 }
10791
10792 return CMD_SUCCESS;
10793 }
10794
10795 /* `show [ip] bgp summary' commands. */
10796 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
10797 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
10798 " [" BGP_SAFI_WITH_LABEL_CMD_STR
10799 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
10800 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
10801 BGP_SAFI_WITH_LABEL_HELP_STR
10802 "Display the entries for all address families\n"
10803 "Summary of BGP neighbor status\n"
10804 "Show only sessions in Established state\n"
10805 "Show only sessions not in Established state\n"
10806 "Show only the specified neighbor session\n"
10807 "Neighbor to display information about\n"
10808 "Neighbor to display information about\n"
10809 "Neighbor on BGP configured interface\n"
10810 "Show only the specified remote AS sessions\n"
10811 "AS number\n"
10812 "Internal (iBGP) AS sessions\n"
10813 "External (eBGP) AS sessions\n"
10814 "Shorten the information on BGP instances\n"
10815 "Increase table width for longer output\n" JSON_STR)
10816 {
10817 char *vrf = NULL;
10818 afi_t afi = AFI_MAX;
10819 safi_t safi = SAFI_MAX;
10820 as_t as = 0; /* 0 means AS filter not set */
10821 int as_type = AS_UNSPECIFIED;
10822 uint16_t show_flags = 0;
10823
10824 int idx = 0;
10825
10826 /* show [ip] bgp */
10827 if (!all && argv_find(argv, argc, "ip", &idx))
10828 afi = AFI_IP;
10829 /* [<vrf> VIEWVRFNAME] */
10830 if (argv_find(argv, argc, "vrf", &idx)) {
10831 vrf = argv[idx + 1]->arg;
10832 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10833 vrf = NULL;
10834 } else if (argv_find(argv, argc, "view", &idx))
10835 /* [<view> VIEWVRFNAME] */
10836 vrf = argv[idx + 1]->arg;
10837 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10838 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10839 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10840 }
10841
10842 if (argv_find(argv, argc, "failed", &idx))
10843 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10844
10845 if (argv_find(argv, argc, "established", &idx))
10846 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10847
10848 if (argv_find(argv, argc, "remote-as", &idx)) {
10849 if (argv[idx + 1]->arg[0] == 'i')
10850 as_type = AS_INTERNAL;
10851 else if (argv[idx + 1]->arg[0] == 'e')
10852 as_type = AS_EXTERNAL;
10853 else
10854 as = (as_t)atoi(argv[idx + 1]->arg);
10855 }
10856
10857 if (argv_find(argv, argc, "terse", &idx))
10858 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10859
10860 if (argv_find(argv, argc, "wide", &idx))
10861 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10862
10863 if (argv_find(argv, argc, "json", &idx))
10864 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10865
10866 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
10867 show_flags);
10868 }
10869
10870 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
10871 {
10872 if (for_json)
10873 return get_afi_safi_json_str(afi, safi);
10874 else
10875 return get_afi_safi_vty_str(afi, safi);
10876 }
10877
10878
10879 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
10880 afi_t afi, safi_t safi,
10881 uint16_t adv_smcap, uint16_t adv_rmcap,
10882 uint16_t rcv_smcap, uint16_t rcv_rmcap,
10883 bool use_json, json_object *json_pref)
10884 {
10885 /* Send-Mode */
10886 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10887 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
10888 if (use_json) {
10889 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10890 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10891 json_object_string_add(json_pref, "sendMode",
10892 "advertisedAndReceived");
10893 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10894 json_object_string_add(json_pref, "sendMode",
10895 "advertised");
10896 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10897 json_object_string_add(json_pref, "sendMode",
10898 "received");
10899 } else {
10900 vty_out(vty, " Send-mode: ");
10901 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10902 vty_out(vty, "advertised");
10903 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10904 vty_out(vty, "%sreceived",
10905 CHECK_FLAG(p->af_cap[afi][safi],
10906 adv_smcap)
10907 ? ", "
10908 : "");
10909 vty_out(vty, "\n");
10910 }
10911 }
10912
10913 /* Receive-Mode */
10914 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10915 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
10916 if (use_json) {
10917 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10918 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10919 json_object_string_add(json_pref, "recvMode",
10920 "advertisedAndReceived");
10921 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10922 json_object_string_add(json_pref, "recvMode",
10923 "advertised");
10924 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10925 json_object_string_add(json_pref, "recvMode",
10926 "received");
10927 } else {
10928 vty_out(vty, " Receive-mode: ");
10929 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10930 vty_out(vty, "advertised");
10931 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10932 vty_out(vty, "%sreceived",
10933 CHECK_FLAG(p->af_cap[afi][safi],
10934 adv_rmcap)
10935 ? ", "
10936 : "");
10937 vty_out(vty, "\n");
10938 }
10939 }
10940 }
10941
10942 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
10943 struct peer *p,
10944 bool use_json,
10945 json_object *json)
10946 {
10947 bool rbit_status = false;
10948
10949 if (!use_json)
10950 vty_out(vty, "\n R bit: ");
10951
10952 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
10953 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
10954 && (peer_established(p))) {
10955
10956 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
10957 rbit_status = true;
10958 else
10959 rbit_status = false;
10960 }
10961
10962 if (rbit_status) {
10963 if (use_json)
10964 json_object_boolean_true_add(json, "rBit");
10965 else
10966 vty_out(vty, "True\n");
10967 } else {
10968 if (use_json)
10969 json_object_boolean_false_add(json, "rBit");
10970 else
10971 vty_out(vty, "False\n");
10972 }
10973 }
10974
10975 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
10976 struct peer *peer,
10977 bool use_json,
10978 json_object *json)
10979 {
10980 const char *mode = "NotApplicable";
10981
10982 if (!use_json)
10983 vty_out(vty, "\n Remote GR Mode: ");
10984
10985 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10986 && (peer_established(peer))) {
10987
10988 if ((peer->nsf_af_count == 0)
10989 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
10990
10991 mode = "Disable";
10992
10993 } else if (peer->nsf_af_count == 0
10994 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
10995
10996 mode = "Helper";
10997
10998 } else if (peer->nsf_af_count != 0
10999 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11000
11001 mode = "Restart";
11002 }
11003 }
11004
11005 if (use_json) {
11006 json_object_string_add(json, "remoteGrMode", mode);
11007 } else
11008 vty_out(vty, mode, "\n");
11009 }
11010
11011 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11012 struct peer *p,
11013 bool use_json,
11014 json_object *json)
11015 {
11016 const char *mode = "Invalid";
11017
11018 if (!use_json)
11019 vty_out(vty, " Local GR Mode: ");
11020
11021 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11022 mode = "Helper";
11023 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11024 mode = "Restart";
11025 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11026 mode = "Disable";
11027 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11028 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11029 mode = "Helper*";
11030 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11031 mode = "Restart*";
11032 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11033 mode = "Disable*";
11034 else
11035 mode = "Invalid*";
11036 }
11037
11038 if (use_json) {
11039 json_object_string_add(json, "localGrMode", mode);
11040 } else {
11041 vty_out(vty, mode, "\n");
11042 }
11043 }
11044
11045 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11046 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11047 {
11048 afi_t afi;
11049 safi_t safi;
11050 json_object *json_afi_safi = NULL;
11051 json_object *json_timer = NULL;
11052 json_object *json_endofrib_status = NULL;
11053 bool eor_flag = false;
11054
11055 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11056 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11057 if (!peer->afc[afi][safi])
11058 continue;
11059
11060 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11061 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11062 continue;
11063
11064 if (use_json) {
11065 json_afi_safi = json_object_new_object();
11066 json_endofrib_status = json_object_new_object();
11067 json_timer = json_object_new_object();
11068 }
11069
11070 if (peer->eor_stime[afi][safi]
11071 >= peer->pkt_stime[afi][safi])
11072 eor_flag = true;
11073 else
11074 eor_flag = false;
11075
11076 if (!use_json) {
11077 vty_out(vty, " %s:\n",
11078 get_afi_safi_str(afi, safi, false));
11079
11080 vty_out(vty, " F bit: ");
11081 }
11082
11083 if (peer->nsf[afi][safi]
11084 && CHECK_FLAG(peer->af_cap[afi][safi],
11085 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11086
11087 if (use_json) {
11088 json_object_boolean_true_add(
11089 json_afi_safi, "fBit");
11090 } else
11091 vty_out(vty, "True\n");
11092 } else {
11093 if (use_json)
11094 json_object_boolean_false_add(
11095 json_afi_safi, "fBit");
11096 else
11097 vty_out(vty, "False\n");
11098 }
11099
11100 if (!use_json)
11101 vty_out(vty, " End-of-RIB sent: ");
11102
11103 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11104 PEER_STATUS_EOR_SEND)) {
11105 if (use_json) {
11106 json_object_boolean_true_add(
11107 json_endofrib_status,
11108 "endOfRibSend");
11109
11110 PRINT_EOR_JSON(eor_flag);
11111 } else {
11112 vty_out(vty, "Yes\n");
11113 vty_out(vty,
11114 " End-of-RIB sent after update: ");
11115
11116 PRINT_EOR(eor_flag);
11117 }
11118 } else {
11119 if (use_json) {
11120 json_object_boolean_false_add(
11121 json_endofrib_status,
11122 "endOfRibSend");
11123 json_object_boolean_false_add(
11124 json_endofrib_status,
11125 "endOfRibSentAfterUpdate");
11126 } else {
11127 vty_out(vty, "No\n");
11128 vty_out(vty,
11129 " End-of-RIB sent after update: ");
11130 vty_out(vty, "No\n");
11131 }
11132 }
11133
11134 if (!use_json)
11135 vty_out(vty, " End-of-RIB received: ");
11136
11137 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11138 PEER_STATUS_EOR_RECEIVED)) {
11139 if (use_json)
11140 json_object_boolean_true_add(
11141 json_endofrib_status,
11142 "endOfRibRecv");
11143 else
11144 vty_out(vty, "Yes\n");
11145 } else {
11146 if (use_json)
11147 json_object_boolean_false_add(
11148 json_endofrib_status,
11149 "endOfRibRecv");
11150 else
11151 vty_out(vty, "No\n");
11152 }
11153
11154 if (use_json) {
11155 json_object_int_add(json_timer,
11156 "stalePathTimer",
11157 peer->bgp->stalepath_time);
11158
11159 if (peer->t_gr_stale != NULL) {
11160 json_object_int_add(
11161 json_timer,
11162 "stalePathTimerRemaining",
11163 thread_timer_remain_second(
11164 peer->t_gr_stale));
11165 }
11166
11167 /* Display Configured Selection
11168 * Deferral only when when
11169 * Gr mode is enabled.
11170 */
11171 if (CHECK_FLAG(peer->flags,
11172 PEER_FLAG_GRACEFUL_RESTART)) {
11173 json_object_int_add(
11174 json_timer,
11175 "selectionDeferralTimer",
11176 peer->bgp->stalepath_time);
11177 }
11178
11179 if (peer->bgp->gr_info[afi][safi]
11180 .t_select_deferral
11181 != NULL) {
11182
11183 json_object_int_add(
11184 json_timer,
11185 "selectionDeferralTimerRemaining",
11186 thread_timer_remain_second(
11187 peer->bgp
11188 ->gr_info[afi]
11189 [safi]
11190 .t_select_deferral));
11191 }
11192 } else {
11193 vty_out(vty, " Timers:\n");
11194 vty_out(vty,
11195 " Configured Stale Path Time(sec): %u\n",
11196 peer->bgp->stalepath_time);
11197
11198 if (peer->t_gr_stale != NULL)
11199 vty_out(vty,
11200 " Stale Path Remaining(sec): %ld\n",
11201 thread_timer_remain_second(
11202 peer->t_gr_stale));
11203 /* Display Configured Selection
11204 * Deferral only when when
11205 * Gr mode is enabled.
11206 */
11207 if (CHECK_FLAG(peer->flags,
11208 PEER_FLAG_GRACEFUL_RESTART))
11209 vty_out(vty,
11210 " Configured Selection Deferral Time(sec): %u\n",
11211 peer->bgp->select_defer_time);
11212
11213 if (peer->bgp->gr_info[afi][safi]
11214 .t_select_deferral
11215 != NULL)
11216 vty_out(vty,
11217 " Selection Deferral Time Remaining(sec): %ld\n",
11218 thread_timer_remain_second(
11219 peer->bgp
11220 ->gr_info[afi]
11221 [safi]
11222 .t_select_deferral));
11223 }
11224 if (use_json) {
11225 json_object_object_add(json_afi_safi,
11226 "endOfRibStatus",
11227 json_endofrib_status);
11228 json_object_object_add(json_afi_safi, "timers",
11229 json_timer);
11230 json_object_object_add(
11231 json, get_afi_safi_str(afi, safi, true),
11232 json_afi_safi);
11233 }
11234 }
11235 }
11236 }
11237
11238 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11239 struct peer *p,
11240 bool use_json,
11241 json_object *json)
11242 {
11243 if (use_json) {
11244 json_object *json_timer = NULL;
11245
11246 json_timer = json_object_new_object();
11247
11248 json_object_int_add(json_timer, "configuredRestartTimer",
11249 p->bgp->restart_time);
11250
11251 json_object_int_add(json_timer, "receivedRestartTimer",
11252 p->v_gr_restart);
11253
11254 if (p->t_gr_restart != NULL)
11255 json_object_int_add(
11256 json_timer, "restartTimerRemaining",
11257 thread_timer_remain_second(p->t_gr_restart));
11258
11259 json_object_object_add(json, "timers", json_timer);
11260 } else {
11261
11262 vty_out(vty, " Timers:\n");
11263 vty_out(vty, " Configured Restart Time(sec): %u\n",
11264 p->bgp->restart_time);
11265
11266 vty_out(vty, " Received Restart Time(sec): %u\n",
11267 p->v_gr_restart);
11268 if (p->t_gr_restart != NULL)
11269 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11270 thread_timer_remain_second(p->t_gr_restart));
11271 if (p->t_gr_restart != NULL) {
11272 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11273 thread_timer_remain_second(p->t_gr_restart));
11274 }
11275 }
11276 }
11277
11278 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11279 bool use_json, json_object *json)
11280 {
11281 char buf[SU_ADDRSTRLEN] = {0};
11282 char dn_flag[2] = {0};
11283 /* '*' + v6 address of neighbor */
11284 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11285
11286 if (!p->conf_if && peer_dynamic_neighbor(p))
11287 dn_flag[0] = '*';
11288
11289 if (p->conf_if) {
11290 if (use_json)
11291 json_object_string_add(
11292 json, "neighborAddr",
11293 BGP_PEER_SU_UNSPEC(p)
11294 ? "none"
11295 : sockunion2str(&p->su, buf,
11296 SU_ADDRSTRLEN));
11297 else
11298 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11299 BGP_PEER_SU_UNSPEC(p)
11300 ? "none"
11301 : sockunion2str(&p->su, buf,
11302 SU_ADDRSTRLEN));
11303 } else {
11304 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11305 p->host);
11306
11307 if (use_json)
11308 json_object_string_add(json, "neighborAddr",
11309 neighborAddr);
11310 else
11311 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11312 }
11313
11314 /* more gr info in new format */
11315 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11316 }
11317
11318 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11319 safi_t safi, bool use_json,
11320 json_object *json_neigh)
11321 {
11322 struct bgp_filter *filter;
11323 struct peer_af *paf;
11324 char orf_pfx_name[BUFSIZ];
11325 int orf_pfx_count;
11326 json_object *json_af = NULL;
11327 json_object *json_prefA = NULL;
11328 json_object *json_prefB = NULL;
11329 json_object *json_addr = NULL;
11330 json_object *json_advmap = NULL;
11331
11332 if (use_json) {
11333 json_addr = json_object_new_object();
11334 json_af = json_object_new_object();
11335 filter = &p->filter[afi][safi];
11336
11337 if (peer_group_active(p))
11338 json_object_string_add(json_addr, "peerGroupMember",
11339 p->group->name);
11340
11341 paf = peer_af_find(p, afi, safi);
11342 if (paf && PAF_SUBGRP(paf)) {
11343 json_object_int_add(json_addr, "updateGroupId",
11344 PAF_UPDGRP(paf)->id);
11345 json_object_int_add(json_addr, "subGroupId",
11346 PAF_SUBGRP(paf)->id);
11347 json_object_int_add(json_addr, "packetQueueLength",
11348 bpacket_queue_virtual_length(paf));
11349 }
11350
11351 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11352 || CHECK_FLAG(p->af_cap[afi][safi],
11353 PEER_CAP_ORF_PREFIX_SM_RCV)
11354 || CHECK_FLAG(p->af_cap[afi][safi],
11355 PEER_CAP_ORF_PREFIX_RM_ADV)
11356 || CHECK_FLAG(p->af_cap[afi][safi],
11357 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11358 json_object_int_add(json_af, "orfType",
11359 ORF_TYPE_PREFIX);
11360 json_prefA = json_object_new_object();
11361 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11362 PEER_CAP_ORF_PREFIX_SM_ADV,
11363 PEER_CAP_ORF_PREFIX_RM_ADV,
11364 PEER_CAP_ORF_PREFIX_SM_RCV,
11365 PEER_CAP_ORF_PREFIX_RM_RCV,
11366 use_json, json_prefA);
11367 json_object_object_add(json_af, "orfPrefixList",
11368 json_prefA);
11369 }
11370
11371 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11372 || CHECK_FLAG(p->af_cap[afi][safi],
11373 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11374 || CHECK_FLAG(p->af_cap[afi][safi],
11375 PEER_CAP_ORF_PREFIX_RM_ADV)
11376 || CHECK_FLAG(p->af_cap[afi][safi],
11377 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11378 json_object_int_add(json_af, "orfOldType",
11379 ORF_TYPE_PREFIX_OLD);
11380 json_prefB = json_object_new_object();
11381 bgp_show_peer_afi_orf_cap(
11382 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11383 PEER_CAP_ORF_PREFIX_RM_ADV,
11384 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11385 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11386 json_prefB);
11387 json_object_object_add(json_af, "orfOldPrefixList",
11388 json_prefB);
11389 }
11390
11391 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11392 || CHECK_FLAG(p->af_cap[afi][safi],
11393 PEER_CAP_ORF_PREFIX_SM_RCV)
11394 || CHECK_FLAG(p->af_cap[afi][safi],
11395 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11396 || CHECK_FLAG(p->af_cap[afi][safi],
11397 PEER_CAP_ORF_PREFIX_RM_ADV)
11398 || CHECK_FLAG(p->af_cap[afi][safi],
11399 PEER_CAP_ORF_PREFIX_RM_RCV)
11400 || CHECK_FLAG(p->af_cap[afi][safi],
11401 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11402 json_object_object_add(json_addr, "afDependentCap",
11403 json_af);
11404 else
11405 json_object_free(json_af);
11406
11407 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11408 p->host, afi, safi);
11409 orf_pfx_count = prefix_bgp_show_prefix_list(
11410 NULL, afi, orf_pfx_name, use_json);
11411
11412 if (CHECK_FLAG(p->af_sflags[afi][safi],
11413 PEER_STATUS_ORF_PREFIX_SEND)
11414 || orf_pfx_count) {
11415 if (CHECK_FLAG(p->af_sflags[afi][safi],
11416 PEER_STATUS_ORF_PREFIX_SEND))
11417 json_object_boolean_true_add(json_neigh,
11418 "orfSent");
11419 if (orf_pfx_count)
11420 json_object_int_add(json_addr, "orfRecvCounter",
11421 orf_pfx_count);
11422 }
11423 if (CHECK_FLAG(p->af_sflags[afi][safi],
11424 PEER_STATUS_ORF_WAIT_REFRESH))
11425 json_object_string_add(
11426 json_addr, "orfFirstUpdate",
11427 "deferredUntilORFOrRouteRefreshRecvd");
11428
11429 if (CHECK_FLAG(p->af_flags[afi][safi],
11430 PEER_FLAG_REFLECTOR_CLIENT))
11431 json_object_boolean_true_add(json_addr,
11432 "routeReflectorClient");
11433 if (CHECK_FLAG(p->af_flags[afi][safi],
11434 PEER_FLAG_RSERVER_CLIENT))
11435 json_object_boolean_true_add(json_addr,
11436 "routeServerClient");
11437 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11438 json_object_boolean_true_add(json_addr,
11439 "inboundSoftConfigPermit");
11440
11441 if (CHECK_FLAG(p->af_flags[afi][safi],
11442 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11443 json_object_boolean_true_add(
11444 json_addr,
11445 "privateAsNumsAllReplacedInUpdatesToNbr");
11446 else if (CHECK_FLAG(p->af_flags[afi][safi],
11447 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11448 json_object_boolean_true_add(
11449 json_addr,
11450 "privateAsNumsReplacedInUpdatesToNbr");
11451 else if (CHECK_FLAG(p->af_flags[afi][safi],
11452 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11453 json_object_boolean_true_add(
11454 json_addr,
11455 "privateAsNumsAllRemovedInUpdatesToNbr");
11456 else if (CHECK_FLAG(p->af_flags[afi][safi],
11457 PEER_FLAG_REMOVE_PRIVATE_AS))
11458 json_object_boolean_true_add(
11459 json_addr,
11460 "privateAsNumsRemovedInUpdatesToNbr");
11461
11462 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11463 json_object_boolean_true_add(
11464 json_addr,
11465 bgp_addpath_names(p->addpath_type[afi][safi])
11466 ->type_json_name);
11467
11468 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11469 json_object_string_add(json_addr,
11470 "overrideASNsInOutboundUpdates",
11471 "ifAspathEqualRemoteAs");
11472
11473 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11474 || CHECK_FLAG(p->af_flags[afi][safi],
11475 PEER_FLAG_FORCE_NEXTHOP_SELF))
11476 json_object_boolean_true_add(json_addr,
11477 "routerAlwaysNextHop");
11478 if (CHECK_FLAG(p->af_flags[afi][safi],
11479 PEER_FLAG_AS_PATH_UNCHANGED))
11480 json_object_boolean_true_add(
11481 json_addr, "unchangedAsPathPropogatedToNbr");
11482 if (CHECK_FLAG(p->af_flags[afi][safi],
11483 PEER_FLAG_NEXTHOP_UNCHANGED))
11484 json_object_boolean_true_add(
11485 json_addr, "unchangedNextHopPropogatedToNbr");
11486 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11487 json_object_boolean_true_add(
11488 json_addr, "unchangedMedPropogatedToNbr");
11489 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11490 || CHECK_FLAG(p->af_flags[afi][safi],
11491 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11492 if (CHECK_FLAG(p->af_flags[afi][safi],
11493 PEER_FLAG_SEND_COMMUNITY)
11494 && CHECK_FLAG(p->af_flags[afi][safi],
11495 PEER_FLAG_SEND_EXT_COMMUNITY))
11496 json_object_string_add(json_addr,
11497 "commAttriSentToNbr",
11498 "extendedAndStandard");
11499 else if (CHECK_FLAG(p->af_flags[afi][safi],
11500 PEER_FLAG_SEND_EXT_COMMUNITY))
11501 json_object_string_add(json_addr,
11502 "commAttriSentToNbr",
11503 "extended");
11504 else
11505 json_object_string_add(json_addr,
11506 "commAttriSentToNbr",
11507 "standard");
11508 }
11509 if (CHECK_FLAG(p->af_flags[afi][safi],
11510 PEER_FLAG_DEFAULT_ORIGINATE)) {
11511 if (p->default_rmap[afi][safi].name)
11512 json_object_string_add(
11513 json_addr, "defaultRouteMap",
11514 p->default_rmap[afi][safi].name);
11515
11516 if (paf && PAF_SUBGRP(paf)
11517 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11518 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11519 json_object_boolean_true_add(json_addr,
11520 "defaultSent");
11521 else
11522 json_object_boolean_true_add(json_addr,
11523 "defaultNotSent");
11524 }
11525
11526 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11527 if (is_evpn_enabled())
11528 json_object_boolean_true_add(
11529 json_addr, "advertiseAllVnis");
11530 }
11531
11532 if (filter->plist[FILTER_IN].name
11533 || filter->dlist[FILTER_IN].name
11534 || filter->aslist[FILTER_IN].name
11535 || filter->map[RMAP_IN].name)
11536 json_object_boolean_true_add(json_addr,
11537 "inboundPathPolicyConfig");
11538 if (filter->plist[FILTER_OUT].name
11539 || filter->dlist[FILTER_OUT].name
11540 || filter->aslist[FILTER_OUT].name
11541 || filter->map[RMAP_OUT].name || filter->usmap.name)
11542 json_object_boolean_true_add(
11543 json_addr, "outboundPathPolicyConfig");
11544
11545 /* prefix-list */
11546 if (filter->plist[FILTER_IN].name)
11547 json_object_string_add(json_addr,
11548 "incomingUpdatePrefixFilterList",
11549 filter->plist[FILTER_IN].name);
11550 if (filter->plist[FILTER_OUT].name)
11551 json_object_string_add(json_addr,
11552 "outgoingUpdatePrefixFilterList",
11553 filter->plist[FILTER_OUT].name);
11554
11555 /* distribute-list */
11556 if (filter->dlist[FILTER_IN].name)
11557 json_object_string_add(
11558 json_addr, "incomingUpdateNetworkFilterList",
11559 filter->dlist[FILTER_IN].name);
11560 if (filter->dlist[FILTER_OUT].name)
11561 json_object_string_add(
11562 json_addr, "outgoingUpdateNetworkFilterList",
11563 filter->dlist[FILTER_OUT].name);
11564
11565 /* filter-list. */
11566 if (filter->aslist[FILTER_IN].name)
11567 json_object_string_add(json_addr,
11568 "incomingUpdateAsPathFilterList",
11569 filter->aslist[FILTER_IN].name);
11570 if (filter->aslist[FILTER_OUT].name)
11571 json_object_string_add(json_addr,
11572 "outgoingUpdateAsPathFilterList",
11573 filter->aslist[FILTER_OUT].name);
11574
11575 /* route-map. */
11576 if (filter->map[RMAP_IN].name)
11577 json_object_string_add(
11578 json_addr, "routeMapForIncomingAdvertisements",
11579 filter->map[RMAP_IN].name);
11580 if (filter->map[RMAP_OUT].name)
11581 json_object_string_add(
11582 json_addr, "routeMapForOutgoingAdvertisements",
11583 filter->map[RMAP_OUT].name);
11584
11585 /* ebgp-requires-policy (inbound) */
11586 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11587 && !bgp_inbound_policy_exists(p, filter))
11588 json_object_string_add(
11589 json_addr, "inboundEbgpRequiresPolicy",
11590 "Inbound updates discarded due to missing policy");
11591
11592 /* ebgp-requires-policy (outbound) */
11593 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11594 && (!bgp_outbound_policy_exists(p, filter)))
11595 json_object_string_add(
11596 json_addr, "outboundEbgpRequiresPolicy",
11597 "Outbound updates discarded due to missing policy");
11598
11599 /* unsuppress-map */
11600 if (filter->usmap.name)
11601 json_object_string_add(json_addr,
11602 "selectiveUnsuppressRouteMap",
11603 filter->usmap.name);
11604
11605 /* advertise-map */
11606 if (filter->advmap.aname) {
11607 json_advmap = json_object_new_object();
11608 json_object_string_add(json_advmap, "condition",
11609 filter->advmap.condition
11610 ? "EXIST"
11611 : "NON_EXIST");
11612 json_object_string_add(json_advmap, "conditionMap",
11613 filter->advmap.cname);
11614 json_object_string_add(json_advmap, "advertiseMap",
11615 filter->advmap.aname);
11616 json_object_string_add(json_advmap, "advertiseStatus",
11617 filter->advmap.update_type
11618 == ADVERTISE
11619 ? "Advertise"
11620 : "Withdraw");
11621 json_object_object_add(json_addr, "advertiseMap",
11622 json_advmap);
11623 }
11624
11625 /* Receive prefix count */
11626 json_object_int_add(json_addr, "acceptedPrefixCounter",
11627 p->pcount[afi][safi]);
11628 if (paf && PAF_SUBGRP(paf))
11629 json_object_int_add(json_addr, "sentPrefixCounter",
11630 (PAF_SUBGRP(paf))->scount);
11631
11632 /* Maximum prefix */
11633 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11634 json_object_int_add(json_addr, "prefixOutAllowedMax",
11635 p->pmax_out[afi][safi]);
11636
11637 /* Maximum prefix */
11638 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11639 json_object_int_add(json_addr, "prefixAllowedMax",
11640 p->pmax[afi][safi]);
11641 if (CHECK_FLAG(p->af_flags[afi][safi],
11642 PEER_FLAG_MAX_PREFIX_WARNING))
11643 json_object_boolean_true_add(
11644 json_addr, "prefixAllowedMaxWarning");
11645 json_object_int_add(json_addr,
11646 "prefixAllowedWarningThresh",
11647 p->pmax_threshold[afi][safi]);
11648 if (p->pmax_restart[afi][safi])
11649 json_object_int_add(
11650 json_addr,
11651 "prefixAllowedRestartIntervalMsecs",
11652 p->pmax_restart[afi][safi] * 60000);
11653 }
11654 json_object_object_add(json_neigh,
11655 get_afi_safi_str(afi, safi, true),
11656 json_addr);
11657
11658 } else {
11659 filter = &p->filter[afi][safi];
11660
11661 vty_out(vty, " For address family: %s\n",
11662 get_afi_safi_str(afi, safi, false));
11663
11664 if (peer_group_active(p))
11665 vty_out(vty, " %s peer-group member\n",
11666 p->group->name);
11667
11668 paf = peer_af_find(p, afi, safi);
11669 if (paf && PAF_SUBGRP(paf)) {
11670 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
11671 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11672 vty_out(vty, " Packet Queue length %d\n",
11673 bpacket_queue_virtual_length(paf));
11674 } else {
11675 vty_out(vty, " Not part of any update group\n");
11676 }
11677 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11678 || CHECK_FLAG(p->af_cap[afi][safi],
11679 PEER_CAP_ORF_PREFIX_SM_RCV)
11680 || CHECK_FLAG(p->af_cap[afi][safi],
11681 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11682 || CHECK_FLAG(p->af_cap[afi][safi],
11683 PEER_CAP_ORF_PREFIX_RM_ADV)
11684 || CHECK_FLAG(p->af_cap[afi][safi],
11685 PEER_CAP_ORF_PREFIX_RM_RCV)
11686 || CHECK_FLAG(p->af_cap[afi][safi],
11687 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11688 vty_out(vty, " AF-dependant capabilities:\n");
11689
11690 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11691 || CHECK_FLAG(p->af_cap[afi][safi],
11692 PEER_CAP_ORF_PREFIX_SM_RCV)
11693 || CHECK_FLAG(p->af_cap[afi][safi],
11694 PEER_CAP_ORF_PREFIX_RM_ADV)
11695 || CHECK_FLAG(p->af_cap[afi][safi],
11696 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11697 vty_out(vty,
11698 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11699 ORF_TYPE_PREFIX);
11700 bgp_show_peer_afi_orf_cap(
11701 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11702 PEER_CAP_ORF_PREFIX_RM_ADV,
11703 PEER_CAP_ORF_PREFIX_SM_RCV,
11704 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11705 }
11706 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11707 || CHECK_FLAG(p->af_cap[afi][safi],
11708 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11709 || CHECK_FLAG(p->af_cap[afi][safi],
11710 PEER_CAP_ORF_PREFIX_RM_ADV)
11711 || CHECK_FLAG(p->af_cap[afi][safi],
11712 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11713 vty_out(vty,
11714 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11715 ORF_TYPE_PREFIX_OLD);
11716 bgp_show_peer_afi_orf_cap(
11717 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11718 PEER_CAP_ORF_PREFIX_RM_ADV,
11719 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11720 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11721 }
11722
11723 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11724 p->host, afi, safi);
11725 orf_pfx_count = prefix_bgp_show_prefix_list(
11726 NULL, afi, orf_pfx_name, use_json);
11727
11728 if (CHECK_FLAG(p->af_sflags[afi][safi],
11729 PEER_STATUS_ORF_PREFIX_SEND)
11730 || orf_pfx_count) {
11731 vty_out(vty, " Outbound Route Filter (ORF):");
11732 if (CHECK_FLAG(p->af_sflags[afi][safi],
11733 PEER_STATUS_ORF_PREFIX_SEND))
11734 vty_out(vty, " sent;");
11735 if (orf_pfx_count)
11736 vty_out(vty, " received (%d entries)",
11737 orf_pfx_count);
11738 vty_out(vty, "\n");
11739 }
11740 if (CHECK_FLAG(p->af_sflags[afi][safi],
11741 PEER_STATUS_ORF_WAIT_REFRESH))
11742 vty_out(vty,
11743 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11744
11745 if (CHECK_FLAG(p->af_flags[afi][safi],
11746 PEER_FLAG_REFLECTOR_CLIENT))
11747 vty_out(vty, " Route-Reflector Client\n");
11748 if (CHECK_FLAG(p->af_flags[afi][safi],
11749 PEER_FLAG_RSERVER_CLIENT))
11750 vty_out(vty, " Route-Server Client\n");
11751 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11752 vty_out(vty,
11753 " Inbound soft reconfiguration allowed\n");
11754
11755 if (CHECK_FLAG(p->af_flags[afi][safi],
11756 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11757 vty_out(vty,
11758 " Private AS numbers (all) replaced in updates to this neighbor\n");
11759 else if (CHECK_FLAG(p->af_flags[afi][safi],
11760 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11761 vty_out(vty,
11762 " Private AS numbers replaced in updates to this neighbor\n");
11763 else if (CHECK_FLAG(p->af_flags[afi][safi],
11764 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11765 vty_out(vty,
11766 " Private AS numbers (all) removed in updates to this neighbor\n");
11767 else if (CHECK_FLAG(p->af_flags[afi][safi],
11768 PEER_FLAG_REMOVE_PRIVATE_AS))
11769 vty_out(vty,
11770 " Private AS numbers removed in updates to this neighbor\n");
11771
11772 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11773 vty_out(vty, " %s\n",
11774 bgp_addpath_names(p->addpath_type[afi][safi])
11775 ->human_description);
11776
11777 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11778 vty_out(vty,
11779 " Override ASNs in outbound updates if aspath equals remote-as\n");
11780
11781 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11782 || CHECK_FLAG(p->af_flags[afi][safi],
11783 PEER_FLAG_FORCE_NEXTHOP_SELF))
11784 vty_out(vty, " NEXT_HOP is always this router\n");
11785 if (CHECK_FLAG(p->af_flags[afi][safi],
11786 PEER_FLAG_AS_PATH_UNCHANGED))
11787 vty_out(vty,
11788 " AS_PATH is propagated unchanged to this neighbor\n");
11789 if (CHECK_FLAG(p->af_flags[afi][safi],
11790 PEER_FLAG_NEXTHOP_UNCHANGED))
11791 vty_out(vty,
11792 " NEXT_HOP is propagated unchanged to this neighbor\n");
11793 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11794 vty_out(vty,
11795 " MED is propagated unchanged to this neighbor\n");
11796 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11797 || CHECK_FLAG(p->af_flags[afi][safi],
11798 PEER_FLAG_SEND_EXT_COMMUNITY)
11799 || CHECK_FLAG(p->af_flags[afi][safi],
11800 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
11801 vty_out(vty,
11802 " Community attribute sent to this neighbor");
11803 if (CHECK_FLAG(p->af_flags[afi][safi],
11804 PEER_FLAG_SEND_COMMUNITY)
11805 && CHECK_FLAG(p->af_flags[afi][safi],
11806 PEER_FLAG_SEND_EXT_COMMUNITY)
11807 && CHECK_FLAG(p->af_flags[afi][safi],
11808 PEER_FLAG_SEND_LARGE_COMMUNITY))
11809 vty_out(vty, "(all)\n");
11810 else if (CHECK_FLAG(p->af_flags[afi][safi],
11811 PEER_FLAG_SEND_LARGE_COMMUNITY))
11812 vty_out(vty, "(large)\n");
11813 else if (CHECK_FLAG(p->af_flags[afi][safi],
11814 PEER_FLAG_SEND_EXT_COMMUNITY))
11815 vty_out(vty, "(extended)\n");
11816 else
11817 vty_out(vty, "(standard)\n");
11818 }
11819 if (CHECK_FLAG(p->af_flags[afi][safi],
11820 PEER_FLAG_DEFAULT_ORIGINATE)) {
11821 vty_out(vty, " Default information originate,");
11822
11823 if (p->default_rmap[afi][safi].name)
11824 vty_out(vty, " default route-map %s%s,",
11825 p->default_rmap[afi][safi].map ? "*"
11826 : "",
11827 p->default_rmap[afi][safi].name);
11828 if (paf && PAF_SUBGRP(paf)
11829 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11830 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11831 vty_out(vty, " default sent\n");
11832 else
11833 vty_out(vty, " default not sent\n");
11834 }
11835
11836 /* advertise-vni-all */
11837 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11838 if (is_evpn_enabled())
11839 vty_out(vty, " advertise-all-vni\n");
11840 }
11841
11842 if (filter->plist[FILTER_IN].name
11843 || filter->dlist[FILTER_IN].name
11844 || filter->aslist[FILTER_IN].name
11845 || filter->map[RMAP_IN].name)
11846 vty_out(vty, " Inbound path policy configured\n");
11847 if (filter->plist[FILTER_OUT].name
11848 || filter->dlist[FILTER_OUT].name
11849 || filter->aslist[FILTER_OUT].name
11850 || filter->map[RMAP_OUT].name || filter->usmap.name)
11851 vty_out(vty, " Outbound path policy configured\n");
11852
11853 /* prefix-list */
11854 if (filter->plist[FILTER_IN].name)
11855 vty_out(vty,
11856 " Incoming update prefix filter list is %s%s\n",
11857 filter->plist[FILTER_IN].plist ? "*" : "",
11858 filter->plist[FILTER_IN].name);
11859 if (filter->plist[FILTER_OUT].name)
11860 vty_out(vty,
11861 " Outgoing update prefix filter list is %s%s\n",
11862 filter->plist[FILTER_OUT].plist ? "*" : "",
11863 filter->plist[FILTER_OUT].name);
11864
11865 /* distribute-list */
11866 if (filter->dlist[FILTER_IN].name)
11867 vty_out(vty,
11868 " Incoming update network filter list is %s%s\n",
11869 filter->dlist[FILTER_IN].alist ? "*" : "",
11870 filter->dlist[FILTER_IN].name);
11871 if (filter->dlist[FILTER_OUT].name)
11872 vty_out(vty,
11873 " Outgoing update network filter list is %s%s\n",
11874 filter->dlist[FILTER_OUT].alist ? "*" : "",
11875 filter->dlist[FILTER_OUT].name);
11876
11877 /* filter-list. */
11878 if (filter->aslist[FILTER_IN].name)
11879 vty_out(vty,
11880 " Incoming update AS path filter list is %s%s\n",
11881 filter->aslist[FILTER_IN].aslist ? "*" : "",
11882 filter->aslist[FILTER_IN].name);
11883 if (filter->aslist[FILTER_OUT].name)
11884 vty_out(vty,
11885 " Outgoing update AS path filter list is %s%s\n",
11886 filter->aslist[FILTER_OUT].aslist ? "*" : "",
11887 filter->aslist[FILTER_OUT].name);
11888
11889 /* route-map. */
11890 if (filter->map[RMAP_IN].name)
11891 vty_out(vty,
11892 " Route map for incoming advertisements is %s%s\n",
11893 filter->map[RMAP_IN].map ? "*" : "",
11894 filter->map[RMAP_IN].name);
11895 if (filter->map[RMAP_OUT].name)
11896 vty_out(vty,
11897 " Route map for outgoing advertisements is %s%s\n",
11898 filter->map[RMAP_OUT].map ? "*" : "",
11899 filter->map[RMAP_OUT].name);
11900
11901 /* ebgp-requires-policy (inbound) */
11902 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11903 && !bgp_inbound_policy_exists(p, filter))
11904 vty_out(vty,
11905 " Inbound updates discarded due to missing policy\n");
11906
11907 /* ebgp-requires-policy (outbound) */
11908 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11909 && !bgp_outbound_policy_exists(p, filter))
11910 vty_out(vty,
11911 " Outbound updates discarded due to missing policy\n");
11912
11913 /* unsuppress-map */
11914 if (filter->usmap.name)
11915 vty_out(vty,
11916 " Route map for selective unsuppress is %s%s\n",
11917 filter->usmap.map ? "*" : "",
11918 filter->usmap.name);
11919
11920 /* advertise-map */
11921 if (filter->advmap.aname && filter->advmap.cname)
11922 vty_out(vty,
11923 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
11924 filter->advmap.condition ? "EXIST"
11925 : "NON_EXIST",
11926 filter->advmap.cmap ? "*" : "",
11927 filter->advmap.cname,
11928 filter->advmap.amap ? "*" : "",
11929 filter->advmap.aname,
11930 filter->advmap.update_type == ADVERTISE
11931 ? "Advertise"
11932 : "Withdraw");
11933
11934 /* Receive prefix count */
11935 vty_out(vty, " %u accepted prefixes\n",
11936 p->pcount[afi][safi]);
11937
11938 /* maximum-prefix-out */
11939 if (CHECK_FLAG(p->af_flags[afi][safi],
11940 PEER_FLAG_MAX_PREFIX_OUT))
11941 vty_out(vty,
11942 " Maximum allowed prefixes sent %u\n",
11943 p->pmax_out[afi][safi]);
11944
11945 /* Maximum prefix */
11946 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11947 vty_out(vty,
11948 " Maximum prefixes allowed %u%s\n",
11949 p->pmax[afi][safi],
11950 CHECK_FLAG(p->af_flags[afi][safi],
11951 PEER_FLAG_MAX_PREFIX_WARNING)
11952 ? " (warning-only)"
11953 : "");
11954 vty_out(vty, " Threshold for warning message %d%%",
11955 p->pmax_threshold[afi][safi]);
11956 if (p->pmax_restart[afi][safi])
11957 vty_out(vty, ", restart interval %d min",
11958 p->pmax_restart[afi][safi]);
11959 vty_out(vty, "\n");
11960 }
11961
11962 vty_out(vty, "\n");
11963 }
11964 }
11965
11966 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
11967 json_object *json)
11968 {
11969 struct bgp *bgp;
11970 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
11971 char timebuf[BGP_UPTIME_LEN];
11972 char dn_flag[2];
11973 afi_t afi;
11974 safi_t safi;
11975 uint16_t i;
11976 uint8_t *msg;
11977 json_object *json_neigh = NULL;
11978 time_t epoch_tbuf;
11979 uint32_t sync_tcp_mss;
11980
11981 bgp = p->bgp;
11982
11983 if (use_json)
11984 json_neigh = json_object_new_object();
11985
11986 memset(dn_flag, '\0', sizeof(dn_flag));
11987 if (!p->conf_if && peer_dynamic_neighbor(p))
11988 dn_flag[0] = '*';
11989
11990 if (!use_json) {
11991 if (p->conf_if) /* Configured interface name. */
11992 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
11993 BGP_PEER_SU_UNSPEC(p)
11994 ? "None"
11995 : sockunion2str(&p->su, buf,
11996 SU_ADDRSTRLEN));
11997 else /* Configured IP address. */
11998 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
11999 p->host);
12000 }
12001
12002 if (use_json) {
12003 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12004 json_object_string_add(json_neigh, "bgpNeighborAddr",
12005 "none");
12006 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12007 json_object_string_add(
12008 json_neigh, "bgpNeighborAddr",
12009 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12010
12011 json_object_int_add(json_neigh, "remoteAs", p->as);
12012
12013 if (p->change_local_as)
12014 json_object_int_add(json_neigh, "localAs",
12015 p->change_local_as);
12016 else
12017 json_object_int_add(json_neigh, "localAs", p->local_as);
12018
12019 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12020 json_object_boolean_true_add(json_neigh,
12021 "localAsNoPrepend");
12022
12023 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12024 json_object_boolean_true_add(json_neigh,
12025 "localAsReplaceAs");
12026 } else {
12027 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12028 || (p->as_type == AS_INTERNAL))
12029 vty_out(vty, "remote AS %u, ", p->as);
12030 else
12031 vty_out(vty, "remote AS Unspecified, ");
12032 vty_out(vty, "local AS %u%s%s, ",
12033 p->change_local_as ? p->change_local_as : p->local_as,
12034 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12035 ? " no-prepend"
12036 : "",
12037 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12038 ? " replace-as"
12039 : "");
12040 }
12041 /* peer type internal or confed-internal */
12042 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12043 if (use_json) {
12044 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12045 json_object_boolean_true_add(
12046 json_neigh, "nbrConfedInternalLink");
12047 else
12048 json_object_boolean_true_add(json_neigh,
12049 "nbrInternalLink");
12050 } else {
12051 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12052 vty_out(vty, "confed-internal link\n");
12053 else
12054 vty_out(vty, "internal link\n");
12055 }
12056 /* peer type external or confed-external */
12057 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12058 if (use_json) {
12059 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12060 json_object_boolean_true_add(
12061 json_neigh, "nbrConfedExternalLink");
12062 else
12063 json_object_boolean_true_add(json_neigh,
12064 "nbrExternalLink");
12065 } else {
12066 if (bgp_confederation_peers_check(bgp, p->as))
12067 vty_out(vty, "confed-external link\n");
12068 else
12069 vty_out(vty, "external link\n");
12070 }
12071 } else {
12072 if (use_json)
12073 json_object_boolean_true_add(json_neigh,
12074 "nbrUnspecifiedLink");
12075 else
12076 vty_out(vty, "unspecified link\n");
12077 }
12078
12079 /* Description. */
12080 if (p->desc) {
12081 if (use_json)
12082 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12083 else
12084 vty_out(vty, " Description: %s\n", p->desc);
12085 }
12086
12087 if (p->hostname) {
12088 if (use_json) {
12089 if (p->hostname)
12090 json_object_string_add(json_neigh, "hostname",
12091 p->hostname);
12092
12093 if (p->domainname)
12094 json_object_string_add(json_neigh, "domainname",
12095 p->domainname);
12096 } else {
12097 if (p->domainname && (p->domainname[0] != '\0'))
12098 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12099 p->domainname);
12100 else
12101 vty_out(vty, "Hostname: %s\n", p->hostname);
12102 }
12103 }
12104
12105 /* Peer-group */
12106 if (p->group) {
12107 if (use_json) {
12108 json_object_string_add(json_neigh, "peerGroup",
12109 p->group->name);
12110
12111 if (dn_flag[0]) {
12112 struct prefix prefix, *range = NULL;
12113
12114 if (sockunion2hostprefix(&(p->su), &prefix))
12115 range = peer_group_lookup_dynamic_neighbor_range(
12116 p->group, &prefix);
12117
12118 if (range) {
12119 prefix2str(range, buf1, sizeof(buf1));
12120 json_object_string_add(
12121 json_neigh,
12122 "peerSubnetRangeGroup", buf1);
12123 }
12124 }
12125 } else {
12126 vty_out(vty,
12127 " Member of peer-group %s for session parameters\n",
12128 p->group->name);
12129
12130 if (dn_flag[0]) {
12131 struct prefix prefix, *range = NULL;
12132
12133 if (sockunion2hostprefix(&(p->su), &prefix))
12134 range = peer_group_lookup_dynamic_neighbor_range(
12135 p->group, &prefix);
12136
12137 if (range) {
12138 vty_out(vty,
12139 " Belongs to the subnet range group: %pFX\n",
12140 range);
12141 }
12142 }
12143 }
12144 }
12145
12146 if (use_json) {
12147 /* Administrative shutdown. */
12148 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12149 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12150 json_object_boolean_true_add(json_neigh,
12151 "adminShutDown");
12152
12153 /* BGP Version. */
12154 json_object_int_add(json_neigh, "bgpVersion", 4);
12155 json_object_string_add(
12156 json_neigh, "remoteRouterId",
12157 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12158 json_object_string_add(
12159 json_neigh, "localRouterId",
12160 inet_ntop(AF_INET, &bgp->router_id, buf1,
12161 sizeof(buf1)));
12162
12163 /* Confederation */
12164 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12165 && bgp_confederation_peers_check(bgp, p->as))
12166 json_object_boolean_true_add(json_neigh,
12167 "nbrCommonAdmin");
12168
12169 /* Status. */
12170 json_object_string_add(
12171 json_neigh, "bgpState",
12172 lookup_msg(bgp_status_msg, p->status, NULL));
12173
12174 if (peer_established(p)) {
12175 time_t uptime;
12176
12177 uptime = bgp_clock();
12178 uptime -= p->uptime;
12179 epoch_tbuf = time(NULL) - uptime;
12180
12181 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12182 uptime * 1000);
12183 json_object_string_add(json_neigh, "bgpTimerUpString",
12184 peer_uptime(p->uptime, timebuf,
12185 BGP_UPTIME_LEN, 0,
12186 NULL));
12187 json_object_int_add(json_neigh,
12188 "bgpTimerUpEstablishedEpoch",
12189 epoch_tbuf);
12190 }
12191
12192 else if (p->status == Active) {
12193 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12194 json_object_string_add(json_neigh, "bgpStateIs",
12195 "passive");
12196 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12197 json_object_string_add(json_neigh, "bgpStateIs",
12198 "passiveNSF");
12199 }
12200
12201 /* read timer */
12202 time_t uptime;
12203 struct tm tm;
12204
12205 uptime = bgp_clock();
12206 uptime -= p->readtime;
12207 gmtime_r(&uptime, &tm);
12208
12209 json_object_int_add(json_neigh, "bgpTimerLastRead",
12210 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12211 + (tm.tm_hour * 3600000));
12212
12213 uptime = bgp_clock();
12214 uptime -= p->last_write;
12215 gmtime_r(&uptime, &tm);
12216
12217 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12218 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12219 + (tm.tm_hour * 3600000));
12220
12221 uptime = bgp_clock();
12222 uptime -= p->update_time;
12223 gmtime_r(&uptime, &tm);
12224
12225 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12226 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12227 + (tm.tm_hour * 3600000));
12228
12229 /* Configured timer values. */
12230 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12231 p->v_holdtime * 1000);
12232 json_object_int_add(json_neigh,
12233 "bgpTimerKeepAliveIntervalMsecs",
12234 p->v_keepalive * 1000);
12235 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12236 json_object_int_add(json_neigh,
12237 "bgpTimerDelayOpenTimeMsecs",
12238 p->v_delayopen * 1000);
12239 }
12240
12241 /* Configured and Synced tcp-mss value for peer */
12242 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12243 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12244 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12245 p->tcp_mss);
12246 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12247 sync_tcp_mss);
12248 }
12249
12250 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12251 json_object_int_add(json_neigh,
12252 "bgpTimerConfiguredHoldTimeMsecs",
12253 p->holdtime * 1000);
12254 json_object_int_add(
12255 json_neigh,
12256 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12257 p->keepalive * 1000);
12258 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12259 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12260 json_object_int_add(json_neigh,
12261 "bgpTimerConfiguredHoldTimeMsecs",
12262 bgp->default_holdtime);
12263 json_object_int_add(
12264 json_neigh,
12265 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12266 bgp->default_keepalive);
12267 }
12268 } else {
12269 /* Administrative shutdown. */
12270 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12271 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12272 vty_out(vty, " Administratively shut down\n");
12273
12274 /* BGP Version. */
12275 vty_out(vty, " BGP version 4");
12276 vty_out(vty, ", remote router ID %s",
12277 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12278 vty_out(vty, ", local router ID %s\n",
12279 inet_ntop(AF_INET, &bgp->router_id, buf1,
12280 sizeof(buf1)));
12281
12282 /* Confederation */
12283 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12284 && bgp_confederation_peers_check(bgp, p->as))
12285 vty_out(vty,
12286 " Neighbor under common administration\n");
12287
12288 /* Status. */
12289 vty_out(vty, " BGP state = %s",
12290 lookup_msg(bgp_status_msg, p->status, NULL));
12291
12292 if (peer_established(p))
12293 vty_out(vty, ", up for %8s",
12294 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12295 0, NULL));
12296
12297 else if (p->status == Active) {
12298 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12299 vty_out(vty, " (passive)");
12300 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12301 vty_out(vty, " (NSF passive)");
12302 }
12303 vty_out(vty, "\n");
12304
12305 /* read timer */
12306 vty_out(vty, " Last read %s",
12307 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12308 NULL));
12309 vty_out(vty, ", Last write %s\n",
12310 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12311 NULL));
12312
12313 /* Configured timer values. */
12314 vty_out(vty,
12315 " Hold time is %d, keepalive interval is %d seconds\n",
12316 p->v_holdtime, p->v_keepalive);
12317 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12318 vty_out(vty, " Configured hold time is %d",
12319 p->holdtime);
12320 vty_out(vty, ", keepalive interval is %d seconds\n",
12321 p->keepalive);
12322 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12323 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12324 vty_out(vty, " Configured hold time is %d",
12325 bgp->default_holdtime);
12326 vty_out(vty, ", keepalive interval is %d seconds\n",
12327 bgp->default_keepalive);
12328 }
12329 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12330 vty_out(vty,
12331 " Configured DelayOpenTime is %d seconds\n",
12332 p->delayopen);
12333
12334 /* Configured and synced tcp-mss value for peer */
12335 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12336 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12337 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12338 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12339 }
12340 }
12341 /* Capability. */
12342 if (peer_established(p)) {
12343 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12344 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12345 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12346 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12347 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12348 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12349 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12350 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12351 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12352 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12353 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12354 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12355 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12356 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12357 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12358 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12359 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12360 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12361 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12362 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12363 if (use_json) {
12364 json_object *json_cap = NULL;
12365
12366 json_cap = json_object_new_object();
12367
12368 /* AS4 */
12369 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12370 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12371 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12372 && CHECK_FLAG(p->cap,
12373 PEER_CAP_AS4_RCV))
12374 json_object_string_add(
12375 json_cap, "4byteAs",
12376 "advertisedAndReceived");
12377 else if (CHECK_FLAG(p->cap,
12378 PEER_CAP_AS4_ADV))
12379 json_object_string_add(
12380 json_cap, "4byteAs",
12381 "advertised");
12382 else if (CHECK_FLAG(p->cap,
12383 PEER_CAP_AS4_RCV))
12384 json_object_string_add(
12385 json_cap, "4byteAs",
12386 "received");
12387 }
12388
12389 /* Extended Message Support */
12390 if (CHECK_FLAG(p->cap,
12391 PEER_CAP_EXTENDED_MESSAGE_ADV)
12392 && CHECK_FLAG(
12393 p->cap,
12394 PEER_CAP_EXTENDED_MESSAGE_RCV))
12395 json_object_string_add(
12396 json_cap, "extendedMessage",
12397 "advertisedAndReceived");
12398 else if (CHECK_FLAG(
12399 p->cap,
12400 PEER_CAP_EXTENDED_MESSAGE_ADV))
12401 json_object_string_add(
12402 json_cap, "extendedMessage",
12403 "advertised");
12404 else if (CHECK_FLAG(
12405 p->cap,
12406 PEER_CAP_EXTENDED_MESSAGE_RCV))
12407 json_object_string_add(
12408 json_cap, "extendedMessage",
12409 "received");
12410
12411 /* AddPath */
12412 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12413 || CHECK_FLAG(p->cap,
12414 PEER_CAP_ADDPATH_ADV)) {
12415 json_object *json_add = NULL;
12416 const char *print_store;
12417
12418 json_add = json_object_new_object();
12419
12420 FOREACH_AFI_SAFI (afi, safi) {
12421 json_object *json_sub = NULL;
12422 json_sub =
12423 json_object_new_object();
12424 print_store = get_afi_safi_str(
12425 afi, safi, true);
12426
12427 if (CHECK_FLAG(
12428 p->af_cap[afi]
12429 [safi],
12430 PEER_CAP_ADDPATH_AF_TX_ADV)
12431 || CHECK_FLAG(
12432 p->af_cap[afi]
12433 [safi],
12434 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12435 if (CHECK_FLAG(
12436 p->af_cap
12437 [afi]
12438 [safi],
12439 PEER_CAP_ADDPATH_AF_TX_ADV)
12440 && CHECK_FLAG(
12441 p->af_cap
12442 [afi]
12443 [safi],
12444 PEER_CAP_ADDPATH_AF_TX_RCV))
12445 json_object_boolean_true_add(
12446 json_sub,
12447 "txAdvertisedAndReceived");
12448 else if (
12449 CHECK_FLAG(
12450 p->af_cap
12451 [afi]
12452 [safi],
12453 PEER_CAP_ADDPATH_AF_TX_ADV))
12454 json_object_boolean_true_add(
12455 json_sub,
12456 "txAdvertised");
12457 else if (
12458 CHECK_FLAG(
12459 p->af_cap
12460 [afi]
12461 [safi],
12462 PEER_CAP_ADDPATH_AF_TX_RCV))
12463 json_object_boolean_true_add(
12464 json_sub,
12465 "txReceived");
12466 }
12467
12468 if (CHECK_FLAG(
12469 p->af_cap[afi]
12470 [safi],
12471 PEER_CAP_ADDPATH_AF_RX_ADV)
12472 || CHECK_FLAG(
12473 p->af_cap[afi]
12474 [safi],
12475 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12476 if (CHECK_FLAG(
12477 p->af_cap
12478 [afi]
12479 [safi],
12480 PEER_CAP_ADDPATH_AF_RX_ADV)
12481 && CHECK_FLAG(
12482 p->af_cap
12483 [afi]
12484 [safi],
12485 PEER_CAP_ADDPATH_AF_RX_RCV))
12486 json_object_boolean_true_add(
12487 json_sub,
12488 "rxAdvertisedAndReceived");
12489 else if (
12490 CHECK_FLAG(
12491 p->af_cap
12492 [afi]
12493 [safi],
12494 PEER_CAP_ADDPATH_AF_RX_ADV))
12495 json_object_boolean_true_add(
12496 json_sub,
12497 "rxAdvertised");
12498 else if (
12499 CHECK_FLAG(
12500 p->af_cap
12501 [afi]
12502 [safi],
12503 PEER_CAP_ADDPATH_AF_RX_RCV))
12504 json_object_boolean_true_add(
12505 json_sub,
12506 "rxReceived");
12507 }
12508
12509 if (CHECK_FLAG(
12510 p->af_cap[afi]
12511 [safi],
12512 PEER_CAP_ADDPATH_AF_TX_ADV)
12513 || CHECK_FLAG(
12514 p->af_cap[afi]
12515 [safi],
12516 PEER_CAP_ADDPATH_AF_TX_RCV)
12517 || CHECK_FLAG(
12518 p->af_cap[afi]
12519 [safi],
12520 PEER_CAP_ADDPATH_AF_RX_ADV)
12521 || CHECK_FLAG(
12522 p->af_cap[afi]
12523 [safi],
12524 PEER_CAP_ADDPATH_AF_RX_RCV))
12525 json_object_object_add(
12526 json_add,
12527 print_store,
12528 json_sub);
12529 else
12530 json_object_free(
12531 json_sub);
12532 }
12533
12534 json_object_object_add(
12535 json_cap, "addPath", json_add);
12536 }
12537
12538 /* Dynamic */
12539 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12540 || CHECK_FLAG(p->cap,
12541 PEER_CAP_DYNAMIC_ADV)) {
12542 if (CHECK_FLAG(p->cap,
12543 PEER_CAP_DYNAMIC_ADV)
12544 && CHECK_FLAG(p->cap,
12545 PEER_CAP_DYNAMIC_RCV))
12546 json_object_string_add(
12547 json_cap, "dynamic",
12548 "advertisedAndReceived");
12549 else if (CHECK_FLAG(
12550 p->cap,
12551 PEER_CAP_DYNAMIC_ADV))
12552 json_object_string_add(
12553 json_cap, "dynamic",
12554 "advertised");
12555 else if (CHECK_FLAG(
12556 p->cap,
12557 PEER_CAP_DYNAMIC_RCV))
12558 json_object_string_add(
12559 json_cap, "dynamic",
12560 "received");
12561 }
12562
12563 /* Extended nexthop */
12564 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12565 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12566 json_object *json_nxt = NULL;
12567 const char *print_store;
12568
12569
12570 if (CHECK_FLAG(p->cap,
12571 PEER_CAP_ENHE_ADV)
12572 && CHECK_FLAG(p->cap,
12573 PEER_CAP_ENHE_RCV))
12574 json_object_string_add(
12575 json_cap,
12576 "extendedNexthop",
12577 "advertisedAndReceived");
12578 else if (CHECK_FLAG(p->cap,
12579 PEER_CAP_ENHE_ADV))
12580 json_object_string_add(
12581 json_cap,
12582 "extendedNexthop",
12583 "advertised");
12584 else if (CHECK_FLAG(p->cap,
12585 PEER_CAP_ENHE_RCV))
12586 json_object_string_add(
12587 json_cap,
12588 "extendedNexthop",
12589 "received");
12590
12591 if (CHECK_FLAG(p->cap,
12592 PEER_CAP_ENHE_RCV)) {
12593 json_nxt =
12594 json_object_new_object();
12595
12596 for (safi = SAFI_UNICAST;
12597 safi < SAFI_MAX; safi++) {
12598 if (CHECK_FLAG(
12599 p->af_cap
12600 [AFI_IP]
12601 [safi],
12602 PEER_CAP_ENHE_AF_RCV)) {
12603 print_store = get_afi_safi_str(
12604 AFI_IP,
12605 safi, true);
12606 json_object_string_add(
12607 json_nxt,
12608 print_store,
12609 "recieved"); /* misspelled for compatibility */
12610 }
12611 }
12612 json_object_object_add(
12613 json_cap,
12614 "extendedNexthopFamililesByPeer",
12615 json_nxt);
12616 }
12617 }
12618
12619 /* Route Refresh */
12620 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12621 || CHECK_FLAG(p->cap,
12622 PEER_CAP_REFRESH_NEW_RCV)
12623 || CHECK_FLAG(p->cap,
12624 PEER_CAP_REFRESH_OLD_RCV)) {
12625 if (CHECK_FLAG(p->cap,
12626 PEER_CAP_REFRESH_ADV)
12627 && (CHECK_FLAG(
12628 p->cap,
12629 PEER_CAP_REFRESH_NEW_RCV)
12630 || CHECK_FLAG(
12631 p->cap,
12632 PEER_CAP_REFRESH_OLD_RCV))) {
12633 if (CHECK_FLAG(
12634 p->cap,
12635 PEER_CAP_REFRESH_OLD_RCV)
12636 && CHECK_FLAG(
12637 p->cap,
12638 PEER_CAP_REFRESH_NEW_RCV))
12639 json_object_string_add(
12640 json_cap,
12641 "routeRefresh",
12642 "advertisedAndReceivedOldNew");
12643 else {
12644 if (CHECK_FLAG(
12645 p->cap,
12646 PEER_CAP_REFRESH_OLD_RCV))
12647 json_object_string_add(
12648 json_cap,
12649 "routeRefresh",
12650 "advertisedAndReceivedOld");
12651 else
12652 json_object_string_add(
12653 json_cap,
12654 "routeRefresh",
12655 "advertisedAndReceivedNew");
12656 }
12657 } else if (
12658 CHECK_FLAG(
12659 p->cap,
12660 PEER_CAP_REFRESH_ADV))
12661 json_object_string_add(
12662 json_cap,
12663 "routeRefresh",
12664 "advertised");
12665 else if (
12666 CHECK_FLAG(
12667 p->cap,
12668 PEER_CAP_REFRESH_NEW_RCV)
12669 || CHECK_FLAG(
12670 p->cap,
12671 PEER_CAP_REFRESH_OLD_RCV))
12672 json_object_string_add(
12673 json_cap,
12674 "routeRefresh",
12675 "received");
12676 }
12677
12678 /* Enhanced Route Refresh */
12679 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
12680 || CHECK_FLAG(p->cap,
12681 PEER_CAP_ENHANCED_RR_RCV)) {
12682 if (CHECK_FLAG(p->cap,
12683 PEER_CAP_ENHANCED_RR_ADV)
12684 && CHECK_FLAG(
12685 p->cap,
12686 PEER_CAP_ENHANCED_RR_RCV))
12687 json_object_string_add(
12688 json_cap,
12689 "enhancedRouteRefresh",
12690 "advertisedAndReceived");
12691 else if (
12692 CHECK_FLAG(
12693 p->cap,
12694 PEER_CAP_ENHANCED_RR_ADV))
12695 json_object_string_add(
12696 json_cap,
12697 "enhancedRouteRefresh",
12698 "advertised");
12699 else if (
12700 CHECK_FLAG(
12701 p->cap,
12702 PEER_CAP_ENHANCED_RR_RCV))
12703 json_object_string_add(
12704 json_cap,
12705 "enhancedRouteRefresh",
12706 "received");
12707 }
12708
12709 /* Multiprotocol Extensions */
12710 json_object *json_multi = NULL;
12711 json_multi = json_object_new_object();
12712
12713 FOREACH_AFI_SAFI (afi, safi) {
12714 if (p->afc_adv[afi][safi]
12715 || p->afc_recv[afi][safi]) {
12716 json_object *json_exten = NULL;
12717 json_exten =
12718 json_object_new_object();
12719
12720 if (p->afc_adv[afi][safi]
12721 && p->afc_recv[afi][safi])
12722 json_object_boolean_true_add(
12723 json_exten,
12724 "advertisedAndReceived");
12725 else if (p->afc_adv[afi][safi])
12726 json_object_boolean_true_add(
12727 json_exten,
12728 "advertised");
12729 else if (p->afc_recv[afi][safi])
12730 json_object_boolean_true_add(
12731 json_exten,
12732 "received");
12733
12734 json_object_object_add(
12735 json_multi,
12736 get_afi_safi_str(afi,
12737 safi,
12738 true),
12739 json_exten);
12740 }
12741 }
12742 json_object_object_add(
12743 json_cap, "multiprotocolExtensions",
12744 json_multi);
12745
12746 /* Hostname capabilities */
12747 json_object *json_hname = NULL;
12748
12749 json_hname = json_object_new_object();
12750
12751 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12752 json_object_string_add(
12753 json_hname, "advHostName",
12754 bgp->peer_self->hostname
12755 ? bgp->peer_self
12756 ->hostname
12757 : "n/a");
12758 json_object_string_add(
12759 json_hname, "advDomainName",
12760 bgp->peer_self->domainname
12761 ? bgp->peer_self
12762 ->domainname
12763 : "n/a");
12764 }
12765
12766
12767 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12768 json_object_string_add(
12769 json_hname, "rcvHostName",
12770 p->hostname ? p->hostname
12771 : "n/a");
12772 json_object_string_add(
12773 json_hname, "rcvDomainName",
12774 p->domainname ? p->domainname
12775 : "n/a");
12776 }
12777
12778 json_object_object_add(json_cap, "hostName",
12779 json_hname);
12780
12781 /* Gracefull Restart */
12782 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12783 || CHECK_FLAG(p->cap,
12784 PEER_CAP_RESTART_ADV)) {
12785 if (CHECK_FLAG(p->cap,
12786 PEER_CAP_RESTART_ADV)
12787 && CHECK_FLAG(p->cap,
12788 PEER_CAP_RESTART_RCV))
12789 json_object_string_add(
12790 json_cap,
12791 "gracefulRestart",
12792 "advertisedAndReceived");
12793 else if (CHECK_FLAG(
12794 p->cap,
12795 PEER_CAP_RESTART_ADV))
12796 json_object_string_add(
12797 json_cap,
12798 "gracefulRestartCapability",
12799 "advertised");
12800 else if (CHECK_FLAG(
12801 p->cap,
12802 PEER_CAP_RESTART_RCV))
12803 json_object_string_add(
12804 json_cap,
12805 "gracefulRestartCapability",
12806 "received");
12807
12808 if (CHECK_FLAG(p->cap,
12809 PEER_CAP_RESTART_RCV)) {
12810 int restart_af_count = 0;
12811 json_object *json_restart =
12812 NULL;
12813 json_restart =
12814 json_object_new_object();
12815
12816 json_object_int_add(
12817 json_cap,
12818 "gracefulRestartRemoteTimerMsecs",
12819 p->v_gr_restart * 1000);
12820
12821 FOREACH_AFI_SAFI (afi, safi) {
12822 if (CHECK_FLAG(
12823 p->af_cap
12824 [afi]
12825 [safi],
12826 PEER_CAP_RESTART_AF_RCV)) {
12827 json_object *
12828 json_sub =
12829 NULL;
12830 json_sub =
12831 json_object_new_object();
12832
12833 if (CHECK_FLAG(
12834 p->af_cap
12835 [afi]
12836 [safi],
12837 PEER_CAP_RESTART_AF_PRESERVE_RCV))
12838 json_object_boolean_true_add(
12839 json_sub,
12840 "preserved");
12841 restart_af_count++;
12842 json_object_object_add(
12843 json_restart,
12844 get_afi_safi_str(
12845 afi,
12846 safi,
12847 true),
12848 json_sub);
12849 }
12850 }
12851 if (!restart_af_count) {
12852 json_object_string_add(
12853 json_cap,
12854 "addressFamiliesByPeer",
12855 "none");
12856 json_object_free(
12857 json_restart);
12858 } else
12859 json_object_object_add(
12860 json_cap,
12861 "addressFamiliesByPeer",
12862 json_restart);
12863 }
12864 }
12865 json_object_object_add(json_neigh,
12866 "neighborCapabilities",
12867 json_cap);
12868 } else {
12869 vty_out(vty, " Neighbor capabilities:\n");
12870
12871 /* AS4 */
12872 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12873 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12874 vty_out(vty, " 4 Byte AS:");
12875 if (CHECK_FLAG(p->cap,
12876 PEER_CAP_AS4_ADV))
12877 vty_out(vty, " advertised");
12878 if (CHECK_FLAG(p->cap,
12879 PEER_CAP_AS4_RCV))
12880 vty_out(vty, " %sreceived",
12881 CHECK_FLAG(
12882 p->cap,
12883 PEER_CAP_AS4_ADV)
12884 ? "and "
12885 : "");
12886 vty_out(vty, "\n");
12887 }
12888
12889 /* Extended Message Support */
12890 if (CHECK_FLAG(p->cap,
12891 PEER_CAP_EXTENDED_MESSAGE_RCV)
12892 || CHECK_FLAG(
12893 p->cap,
12894 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
12895 vty_out(vty, " Extended Message:");
12896 if (CHECK_FLAG(
12897 p->cap,
12898 PEER_CAP_EXTENDED_MESSAGE_ADV))
12899 vty_out(vty, " advertised");
12900 if (CHECK_FLAG(
12901 p->cap,
12902 PEER_CAP_EXTENDED_MESSAGE_RCV))
12903 vty_out(vty, " %sreceived",
12904 CHECK_FLAG(
12905 p->cap,
12906 PEER_CAP_EXTENDED_MESSAGE_ADV)
12907 ? "and "
12908 : "");
12909 vty_out(vty, "\n");
12910 }
12911
12912 /* AddPath */
12913 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12914 || CHECK_FLAG(p->cap,
12915 PEER_CAP_ADDPATH_ADV)) {
12916 vty_out(vty, " AddPath:\n");
12917
12918 FOREACH_AFI_SAFI (afi, safi) {
12919 if (CHECK_FLAG(
12920 p->af_cap[afi]
12921 [safi],
12922 PEER_CAP_ADDPATH_AF_TX_ADV)
12923 || CHECK_FLAG(
12924 p->af_cap[afi]
12925 [safi],
12926 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12927 vty_out(vty,
12928 " %s: TX ",
12929 get_afi_safi_str(
12930 afi,
12931 safi,
12932 false));
12933
12934 if (CHECK_FLAG(
12935 p->af_cap
12936 [afi]
12937 [safi],
12938 PEER_CAP_ADDPATH_AF_TX_ADV))
12939 vty_out(vty,
12940 "advertised %s",
12941 get_afi_safi_str(
12942 afi,
12943 safi,
12944 false));
12945
12946 if (CHECK_FLAG(
12947 p->af_cap
12948 [afi]
12949 [safi],
12950 PEER_CAP_ADDPATH_AF_TX_RCV))
12951 vty_out(vty,
12952 "%sreceived",
12953 CHECK_FLAG(
12954 p->af_cap
12955 [afi]
12956 [safi],
12957 PEER_CAP_ADDPATH_AF_TX_ADV)
12958 ? " and "
12959 : "");
12960
12961 vty_out(vty, "\n");
12962 }
12963
12964 if (CHECK_FLAG(
12965 p->af_cap[afi]
12966 [safi],
12967 PEER_CAP_ADDPATH_AF_RX_ADV)
12968 || CHECK_FLAG(
12969 p->af_cap[afi]
12970 [safi],
12971 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12972 vty_out(vty,
12973 " %s: RX ",
12974 get_afi_safi_str(
12975 afi,
12976 safi,
12977 false));
12978
12979 if (CHECK_FLAG(
12980 p->af_cap
12981 [afi]
12982 [safi],
12983 PEER_CAP_ADDPATH_AF_RX_ADV))
12984 vty_out(vty,
12985 "advertised %s",
12986 get_afi_safi_str(
12987 afi,
12988 safi,
12989 false));
12990
12991 if (CHECK_FLAG(
12992 p->af_cap
12993 [afi]
12994 [safi],
12995 PEER_CAP_ADDPATH_AF_RX_RCV))
12996 vty_out(vty,
12997 "%sreceived",
12998 CHECK_FLAG(
12999 p->af_cap
13000 [afi]
13001 [safi],
13002 PEER_CAP_ADDPATH_AF_RX_ADV)
13003 ? " and "
13004 : "");
13005
13006 vty_out(vty, "\n");
13007 }
13008 }
13009 }
13010
13011 /* Dynamic */
13012 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13013 || CHECK_FLAG(p->cap,
13014 PEER_CAP_DYNAMIC_ADV)) {
13015 vty_out(vty, " Dynamic:");
13016 if (CHECK_FLAG(p->cap,
13017 PEER_CAP_DYNAMIC_ADV))
13018 vty_out(vty, " advertised");
13019 if (CHECK_FLAG(p->cap,
13020 PEER_CAP_DYNAMIC_RCV))
13021 vty_out(vty, " %sreceived",
13022 CHECK_FLAG(
13023 p->cap,
13024 PEER_CAP_DYNAMIC_ADV)
13025 ? "and "
13026 : "");
13027 vty_out(vty, "\n");
13028 }
13029
13030 /* Extended nexthop */
13031 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13032 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13033 vty_out(vty, " Extended nexthop:");
13034 if (CHECK_FLAG(p->cap,
13035 PEER_CAP_ENHE_ADV))
13036 vty_out(vty, " advertised");
13037 if (CHECK_FLAG(p->cap,
13038 PEER_CAP_ENHE_RCV))
13039 vty_out(vty, " %sreceived",
13040 CHECK_FLAG(
13041 p->cap,
13042 PEER_CAP_ENHE_ADV)
13043 ? "and "
13044 : "");
13045 vty_out(vty, "\n");
13046
13047 if (CHECK_FLAG(p->cap,
13048 PEER_CAP_ENHE_RCV)) {
13049 vty_out(vty,
13050 " Address families by peer:\n ");
13051 for (safi = SAFI_UNICAST;
13052 safi < SAFI_MAX; safi++)
13053 if (CHECK_FLAG(
13054 p->af_cap
13055 [AFI_IP]
13056 [safi],
13057 PEER_CAP_ENHE_AF_RCV))
13058 vty_out(vty,
13059 " %s\n",
13060 get_afi_safi_str(
13061 AFI_IP,
13062 safi,
13063 false));
13064 }
13065 }
13066
13067 /* Route Refresh */
13068 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13069 || CHECK_FLAG(p->cap,
13070 PEER_CAP_REFRESH_NEW_RCV)
13071 || CHECK_FLAG(p->cap,
13072 PEER_CAP_REFRESH_OLD_RCV)) {
13073 vty_out(vty, " Route refresh:");
13074 if (CHECK_FLAG(p->cap,
13075 PEER_CAP_REFRESH_ADV))
13076 vty_out(vty, " advertised");
13077 if (CHECK_FLAG(p->cap,
13078 PEER_CAP_REFRESH_NEW_RCV)
13079 || CHECK_FLAG(
13080 p->cap,
13081 PEER_CAP_REFRESH_OLD_RCV))
13082 vty_out(vty, " %sreceived(%s)",
13083 CHECK_FLAG(
13084 p->cap,
13085 PEER_CAP_REFRESH_ADV)
13086 ? "and "
13087 : "",
13088 (CHECK_FLAG(
13089 p->cap,
13090 PEER_CAP_REFRESH_OLD_RCV)
13091 && CHECK_FLAG(
13092 p->cap,
13093 PEER_CAP_REFRESH_NEW_RCV))
13094 ? "old & new"
13095 : CHECK_FLAG(
13096 p->cap,
13097 PEER_CAP_REFRESH_OLD_RCV)
13098 ? "old"
13099 : "new");
13100
13101 vty_out(vty, "\n");
13102 }
13103
13104 /* Enhanced Route Refresh */
13105 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13106 || CHECK_FLAG(p->cap,
13107 PEER_CAP_ENHANCED_RR_RCV)) {
13108 vty_out(vty,
13109 " Enhanced Route Refresh:");
13110 if (CHECK_FLAG(
13111 p->cap,
13112 PEER_CAP_ENHANCED_RR_ADV))
13113 vty_out(vty, " advertised");
13114 if (CHECK_FLAG(
13115 p->cap,
13116 PEER_CAP_ENHANCED_RR_RCV))
13117 vty_out(vty, " %sreceived",
13118 CHECK_FLAG(
13119 p->cap,
13120 PEER_CAP_REFRESH_ADV)
13121 ? "and "
13122 : "");
13123 vty_out(vty, "\n");
13124 }
13125
13126 /* Multiprotocol Extensions */
13127 FOREACH_AFI_SAFI (afi, safi)
13128 if (p->afc_adv[afi][safi]
13129 || p->afc_recv[afi][safi]) {
13130 vty_out(vty,
13131 " Address Family %s:",
13132 get_afi_safi_str(
13133 afi,
13134 safi,
13135 false));
13136 if (p->afc_adv[afi][safi])
13137 vty_out(vty,
13138 " advertised");
13139 if (p->afc_recv[afi][safi])
13140 vty_out(vty,
13141 " %sreceived",
13142 p->afc_adv[afi]
13143 [safi]
13144 ? "and "
13145 : "");
13146 vty_out(vty, "\n");
13147 }
13148
13149 /* Hostname capability */
13150 vty_out(vty, " Hostname Capability:");
13151
13152 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13153 vty_out(vty,
13154 " advertised (name: %s,domain name: %s)",
13155 bgp->peer_self->hostname
13156 ? bgp->peer_self
13157 ->hostname
13158 : "n/a",
13159 bgp->peer_self->domainname
13160 ? bgp->peer_self
13161 ->domainname
13162 : "n/a");
13163 } else {
13164 vty_out(vty, " not advertised");
13165 }
13166
13167 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13168 vty_out(vty,
13169 " received (name: %s,domain name: %s)",
13170 p->hostname ? p->hostname
13171 : "n/a",
13172 p->domainname ? p->domainname
13173 : "n/a");
13174 } else {
13175 vty_out(vty, " not received");
13176 }
13177
13178 vty_out(vty, "\n");
13179
13180 /* Graceful Restart */
13181 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13182 || CHECK_FLAG(p->cap,
13183 PEER_CAP_RESTART_ADV)) {
13184 vty_out(vty,
13185 " Graceful Restart Capability:");
13186 if (CHECK_FLAG(p->cap,
13187 PEER_CAP_RESTART_ADV))
13188 vty_out(vty, " advertised");
13189 if (CHECK_FLAG(p->cap,
13190 PEER_CAP_RESTART_RCV))
13191 vty_out(vty, " %sreceived",
13192 CHECK_FLAG(
13193 p->cap,
13194 PEER_CAP_RESTART_ADV)
13195 ? "and "
13196 : "");
13197 vty_out(vty, "\n");
13198
13199 if (CHECK_FLAG(p->cap,
13200 PEER_CAP_RESTART_RCV)) {
13201 int restart_af_count = 0;
13202
13203 vty_out(vty,
13204 " Remote Restart timer is %d seconds\n",
13205 p->v_gr_restart);
13206 vty_out(vty,
13207 " Address families by peer:\n ");
13208
13209 FOREACH_AFI_SAFI (afi, safi)
13210 if (CHECK_FLAG(
13211 p->af_cap
13212 [afi]
13213 [safi],
13214 PEER_CAP_RESTART_AF_RCV)) {
13215 vty_out(vty,
13216 "%s%s(%s)",
13217 restart_af_count
13218 ? ", "
13219 : "",
13220 get_afi_safi_str(
13221 afi,
13222 safi,
13223 false),
13224 CHECK_FLAG(
13225 p->af_cap
13226 [afi]
13227 [safi],
13228 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13229 ? "preserved"
13230 : "not preserved");
13231 restart_af_count++;
13232 }
13233 if (!restart_af_count)
13234 vty_out(vty, "none");
13235 vty_out(vty, "\n");
13236 }
13237 } /* Gracefull Restart */
13238 }
13239 }
13240 }
13241
13242 /* graceful restart information */
13243 json_object *json_grace = NULL;
13244 json_object *json_grace_send = NULL;
13245 json_object *json_grace_recv = NULL;
13246 int eor_send_af_count = 0;
13247 int eor_receive_af_count = 0;
13248
13249 if (use_json) {
13250 json_grace = json_object_new_object();
13251 json_grace_send = json_object_new_object();
13252 json_grace_recv = json_object_new_object();
13253
13254 if ((peer_established(p))
13255 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13256 FOREACH_AFI_SAFI (afi, safi) {
13257 if (CHECK_FLAG(p->af_sflags[afi][safi],
13258 PEER_STATUS_EOR_SEND)) {
13259 json_object_boolean_true_add(
13260 json_grace_send,
13261 get_afi_safi_str(afi,
13262 safi,
13263 true));
13264 eor_send_af_count++;
13265 }
13266 }
13267 FOREACH_AFI_SAFI (afi, safi) {
13268 if (CHECK_FLAG(
13269 p->af_sflags[afi][safi],
13270 PEER_STATUS_EOR_RECEIVED)) {
13271 json_object_boolean_true_add(
13272 json_grace_recv,
13273 get_afi_safi_str(afi,
13274 safi,
13275 true));
13276 eor_receive_af_count++;
13277 }
13278 }
13279 }
13280 json_object_object_add(json_grace, "endOfRibSend",
13281 json_grace_send);
13282 json_object_object_add(json_grace, "endOfRibRecv",
13283 json_grace_recv);
13284
13285
13286 if (p->t_gr_restart)
13287 json_object_int_add(json_grace,
13288 "gracefulRestartTimerMsecs",
13289 thread_timer_remain_second(
13290 p->t_gr_restart)
13291 * 1000);
13292
13293 if (p->t_gr_stale)
13294 json_object_int_add(
13295 json_grace,
13296 "gracefulStalepathTimerMsecs",
13297 thread_timer_remain_second(
13298 p->t_gr_stale)
13299 * 1000);
13300 /* more gr info in new format */
13301 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13302 json_grace);
13303 json_object_object_add(
13304 json_neigh, "gracefulRestartInfo", json_grace);
13305 } else {
13306 vty_out(vty, " Graceful restart information:\n");
13307 if ((peer_established(p))
13308 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13309
13310 vty_out(vty, " End-of-RIB send: ");
13311 FOREACH_AFI_SAFI (afi, safi) {
13312 if (CHECK_FLAG(p->af_sflags[afi][safi],
13313 PEER_STATUS_EOR_SEND)) {
13314 vty_out(vty, "%s%s",
13315 eor_send_af_count ? ", "
13316 : "",
13317 get_afi_safi_str(
13318 afi, safi,
13319 false));
13320 eor_send_af_count++;
13321 }
13322 }
13323 vty_out(vty, "\n");
13324 vty_out(vty, " End-of-RIB received: ");
13325 FOREACH_AFI_SAFI (afi, safi) {
13326 if (CHECK_FLAG(
13327 p->af_sflags[afi][safi],
13328 PEER_STATUS_EOR_RECEIVED)) {
13329 vty_out(vty, "%s%s",
13330 eor_receive_af_count
13331 ? ", "
13332 : "",
13333 get_afi_safi_str(afi,
13334 safi,
13335 false));
13336 eor_receive_af_count++;
13337 }
13338 }
13339 vty_out(vty, "\n");
13340 }
13341
13342 if (p->t_gr_restart)
13343 vty_out(vty,
13344 " The remaining time of restart timer is %ld\n",
13345 thread_timer_remain_second(
13346 p->t_gr_restart));
13347
13348 if (p->t_gr_stale)
13349 vty_out(vty,
13350 " The remaining time of stalepath timer is %ld\n",
13351 thread_timer_remain_second(
13352 p->t_gr_stale));
13353
13354 /* more gr info in new format */
13355 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13356 }
13357
13358 if (use_json) {
13359 json_object *json_stat = NULL;
13360 json_stat = json_object_new_object();
13361 /* Packet counts. */
13362
13363 atomic_size_t outq_count, inq_count;
13364 outq_count = atomic_load_explicit(&p->obuf->count,
13365 memory_order_relaxed);
13366 inq_count = atomic_load_explicit(&p->ibuf->count,
13367 memory_order_relaxed);
13368
13369 json_object_int_add(json_stat, "depthInq",
13370 (unsigned long)inq_count);
13371 json_object_int_add(json_stat, "depthOutq",
13372 (unsigned long)outq_count);
13373 json_object_int_add(json_stat, "opensSent",
13374 atomic_load_explicit(&p->open_out,
13375 memory_order_relaxed));
13376 json_object_int_add(json_stat, "opensRecv",
13377 atomic_load_explicit(&p->open_in,
13378 memory_order_relaxed));
13379 json_object_int_add(json_stat, "notificationsSent",
13380 atomic_load_explicit(&p->notify_out,
13381 memory_order_relaxed));
13382 json_object_int_add(json_stat, "notificationsRecv",
13383 atomic_load_explicit(&p->notify_in,
13384 memory_order_relaxed));
13385 json_object_int_add(json_stat, "updatesSent",
13386 atomic_load_explicit(&p->update_out,
13387 memory_order_relaxed));
13388 json_object_int_add(json_stat, "updatesRecv",
13389 atomic_load_explicit(&p->update_in,
13390 memory_order_relaxed));
13391 json_object_int_add(json_stat, "keepalivesSent",
13392 atomic_load_explicit(&p->keepalive_out,
13393 memory_order_relaxed));
13394 json_object_int_add(json_stat, "keepalivesRecv",
13395 atomic_load_explicit(&p->keepalive_in,
13396 memory_order_relaxed));
13397 json_object_int_add(json_stat, "routeRefreshSent",
13398 atomic_load_explicit(&p->refresh_out,
13399 memory_order_relaxed));
13400 json_object_int_add(json_stat, "routeRefreshRecv",
13401 atomic_load_explicit(&p->refresh_in,
13402 memory_order_relaxed));
13403 json_object_int_add(json_stat, "capabilitySent",
13404 atomic_load_explicit(&p->dynamic_cap_out,
13405 memory_order_relaxed));
13406 json_object_int_add(json_stat, "capabilityRecv",
13407 atomic_load_explicit(&p->dynamic_cap_in,
13408 memory_order_relaxed));
13409 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13410 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13411 json_object_object_add(json_neigh, "messageStats", json_stat);
13412 } else {
13413 atomic_size_t outq_count, inq_count;
13414 outq_count = atomic_load_explicit(&p->obuf->count,
13415 memory_order_relaxed);
13416 inq_count = atomic_load_explicit(&p->ibuf->count,
13417 memory_order_relaxed);
13418
13419 /* Packet counts. */
13420 vty_out(vty, " Message statistics:\n");
13421 vty_out(vty, " Inq depth is %zu\n", inq_count);
13422 vty_out(vty, " Outq depth is %zu\n", outq_count);
13423 vty_out(vty, " Sent Rcvd\n");
13424 vty_out(vty, " Opens: %10d %10d\n",
13425 atomic_load_explicit(&p->open_out,
13426 memory_order_relaxed),
13427 atomic_load_explicit(&p->open_in,
13428 memory_order_relaxed));
13429 vty_out(vty, " Notifications: %10d %10d\n",
13430 atomic_load_explicit(&p->notify_out,
13431 memory_order_relaxed),
13432 atomic_load_explicit(&p->notify_in,
13433 memory_order_relaxed));
13434 vty_out(vty, " Updates: %10d %10d\n",
13435 atomic_load_explicit(&p->update_out,
13436 memory_order_relaxed),
13437 atomic_load_explicit(&p->update_in,
13438 memory_order_relaxed));
13439 vty_out(vty, " Keepalives: %10d %10d\n",
13440 atomic_load_explicit(&p->keepalive_out,
13441 memory_order_relaxed),
13442 atomic_load_explicit(&p->keepalive_in,
13443 memory_order_relaxed));
13444 vty_out(vty, " Route Refresh: %10d %10d\n",
13445 atomic_load_explicit(&p->refresh_out,
13446 memory_order_relaxed),
13447 atomic_load_explicit(&p->refresh_in,
13448 memory_order_relaxed));
13449 vty_out(vty, " Capability: %10d %10d\n",
13450 atomic_load_explicit(&p->dynamic_cap_out,
13451 memory_order_relaxed),
13452 atomic_load_explicit(&p->dynamic_cap_in,
13453 memory_order_relaxed));
13454 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13455 PEER_TOTAL_RX(p));
13456 }
13457
13458 if (use_json) {
13459 /* advertisement-interval */
13460 json_object_int_add(json_neigh,
13461 "minBtwnAdvertisementRunsTimerMsecs",
13462 p->v_routeadv * 1000);
13463
13464 /* Update-source. */
13465 if (p->update_if || p->update_source) {
13466 if (p->update_if)
13467 json_object_string_add(json_neigh,
13468 "updateSource",
13469 p->update_if);
13470 else if (p->update_source)
13471 json_object_string_add(
13472 json_neigh, "updateSource",
13473 sockunion2str(p->update_source, buf1,
13474 SU_ADDRSTRLEN));
13475 }
13476 } else {
13477 /* advertisement-interval */
13478 vty_out(vty,
13479 " Minimum time between advertisement runs is %d seconds\n",
13480 p->v_routeadv);
13481
13482 /* Update-source. */
13483 if (p->update_if || p->update_source) {
13484 vty_out(vty, " Update source is ");
13485 if (p->update_if)
13486 vty_out(vty, "%s", p->update_if);
13487 else if (p->update_source)
13488 vty_out(vty, "%s",
13489 sockunion2str(p->update_source, buf1,
13490 SU_ADDRSTRLEN));
13491 vty_out(vty, "\n");
13492 }
13493
13494 vty_out(vty, "\n");
13495 }
13496
13497 /* Address Family Information */
13498 json_object *json_hold = NULL;
13499
13500 if (use_json)
13501 json_hold = json_object_new_object();
13502
13503 FOREACH_AFI_SAFI (afi, safi)
13504 if (p->afc[afi][safi])
13505 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13506 json_hold);
13507
13508 if (use_json) {
13509 json_object_object_add(json_neigh, "addressFamilyInfo",
13510 json_hold);
13511 json_object_int_add(json_neigh, "connectionsEstablished",
13512 p->established);
13513 json_object_int_add(json_neigh, "connectionsDropped",
13514 p->dropped);
13515 } else
13516 vty_out(vty, " Connections established %d; dropped %d\n",
13517 p->established, p->dropped);
13518
13519 if (!p->last_reset) {
13520 if (use_json)
13521 json_object_string_add(json_neigh, "lastReset",
13522 "never");
13523 else
13524 vty_out(vty, " Last reset never\n");
13525 } else {
13526 if (use_json) {
13527 time_t uptime;
13528 struct tm tm;
13529
13530 uptime = bgp_clock();
13531 uptime -= p->resettime;
13532 gmtime_r(&uptime, &tm);
13533
13534 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13535 (tm.tm_sec * 1000)
13536 + (tm.tm_min * 60000)
13537 + (tm.tm_hour * 3600000));
13538 bgp_show_peer_reset(NULL, p, json_neigh, true);
13539 } else {
13540 vty_out(vty, " Last reset %s, ",
13541 peer_uptime(p->resettime, timebuf,
13542 BGP_UPTIME_LEN, 0, NULL));
13543
13544 bgp_show_peer_reset(vty, p, NULL, false);
13545 if (p->last_reset_cause_size) {
13546 msg = p->last_reset_cause;
13547 vty_out(vty,
13548 " Message received that caused BGP to send a NOTIFICATION:\n ");
13549 for (i = 1; i <= p->last_reset_cause_size;
13550 i++) {
13551 vty_out(vty, "%02X", *msg++);
13552
13553 if (i != p->last_reset_cause_size) {
13554 if (i % 16 == 0) {
13555 vty_out(vty, "\n ");
13556 } else if (i % 4 == 0) {
13557 vty_out(vty, " ");
13558 }
13559 }
13560 }
13561 vty_out(vty, "\n");
13562 }
13563 }
13564 }
13565
13566 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13567 if (use_json)
13568 json_object_boolean_true_add(json_neigh,
13569 "prefixesConfigExceedMax");
13570 else
13571 vty_out(vty,
13572 " Peer had exceeded the max. no. of prefixes configured.\n");
13573
13574 if (p->t_pmax_restart) {
13575 if (use_json) {
13576 json_object_boolean_true_add(
13577 json_neigh, "reducePrefixNumFrom");
13578 json_object_int_add(json_neigh,
13579 "restartInTimerMsec",
13580 thread_timer_remain_second(
13581 p->t_pmax_restart)
13582 * 1000);
13583 } else
13584 vty_out(vty,
13585 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13586 p->host, thread_timer_remain_second(
13587 p->t_pmax_restart));
13588 } else {
13589 if (use_json)
13590 json_object_boolean_true_add(
13591 json_neigh,
13592 "reducePrefixNumAndClearIpBgp");
13593 else
13594 vty_out(vty,
13595 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13596 p->host);
13597 }
13598 }
13599
13600 /* EBGP Multihop and GTSM */
13601 if (p->sort != BGP_PEER_IBGP) {
13602 if (use_json) {
13603 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13604 json_object_int_add(json_neigh,
13605 "externalBgpNbrMaxHopsAway",
13606 p->gtsm_hops);
13607 else if (p->ttl > BGP_DEFAULT_TTL)
13608 json_object_int_add(json_neigh,
13609 "externalBgpNbrMaxHopsAway",
13610 p->ttl);
13611 } else {
13612 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13613 vty_out(vty,
13614 " External BGP neighbor may be up to %d hops away.\n",
13615 p->gtsm_hops);
13616 else if (p->ttl > BGP_DEFAULT_TTL)
13617 vty_out(vty,
13618 " External BGP neighbor may be up to %d hops away.\n",
13619 p->ttl);
13620 }
13621 } else {
13622 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
13623 if (use_json)
13624 json_object_int_add(json_neigh,
13625 "internalBgpNbrMaxHopsAway",
13626 p->gtsm_hops);
13627 else
13628 vty_out(vty,
13629 " Internal BGP neighbor may be up to %d hops away.\n",
13630 p->gtsm_hops);
13631 }
13632 }
13633
13634 /* Local address. */
13635 if (p->su_local) {
13636 if (use_json) {
13637 json_object_string_add(json_neigh, "hostLocal",
13638 sockunion2str(p->su_local, buf1,
13639 SU_ADDRSTRLEN));
13640 json_object_int_add(json_neigh, "portLocal",
13641 ntohs(p->su_local->sin.sin_port));
13642 } else
13643 vty_out(vty, "Local host: %s, Local port: %d\n",
13644 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13645 ntohs(p->su_local->sin.sin_port));
13646 }
13647
13648 /* Remote address. */
13649 if (p->su_remote) {
13650 if (use_json) {
13651 json_object_string_add(json_neigh, "hostForeign",
13652 sockunion2str(p->su_remote, buf1,
13653 SU_ADDRSTRLEN));
13654 json_object_int_add(json_neigh, "portForeign",
13655 ntohs(p->su_remote->sin.sin_port));
13656 } else
13657 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13658 sockunion2str(p->su_remote, buf1,
13659 SU_ADDRSTRLEN),
13660 ntohs(p->su_remote->sin.sin_port));
13661 }
13662
13663 /* Nexthop display. */
13664 if (p->su_local) {
13665 if (use_json) {
13666 json_object_string_add(json_neigh, "nexthop",
13667 inet_ntop(AF_INET,
13668 &p->nexthop.v4, buf1,
13669 sizeof(buf1)));
13670 json_object_string_add(json_neigh, "nexthopGlobal",
13671 inet_ntop(AF_INET6,
13672 &p->nexthop.v6_global,
13673 buf1, sizeof(buf1)));
13674 json_object_string_add(json_neigh, "nexthopLocal",
13675 inet_ntop(AF_INET6,
13676 &p->nexthop.v6_local,
13677 buf1, sizeof(buf1)));
13678 if (p->shared_network)
13679 json_object_string_add(json_neigh,
13680 "bgpConnection",
13681 "sharedNetwork");
13682 else
13683 json_object_string_add(json_neigh,
13684 "bgpConnection",
13685 "nonSharedNetwork");
13686 } else {
13687 vty_out(vty, "Nexthop: %s\n",
13688 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13689 sizeof(buf1)));
13690 vty_out(vty, "Nexthop global: %s\n",
13691 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13692 sizeof(buf1)));
13693 vty_out(vty, "Nexthop local: %s\n",
13694 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13695 sizeof(buf1)));
13696 vty_out(vty, "BGP connection: %s\n",
13697 p->shared_network ? "shared network"
13698 : "non shared network");
13699 }
13700 }
13701
13702 /* Timer information. */
13703 if (use_json) {
13704 json_object_int_add(json_neigh, "connectRetryTimer",
13705 p->v_connect);
13706 if (peer_established(p) && p->rtt)
13707 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13708 p->rtt);
13709 if (p->t_start)
13710 json_object_int_add(
13711 json_neigh, "nextStartTimerDueInMsecs",
13712 thread_timer_remain_second(p->t_start) * 1000);
13713 if (p->t_connect)
13714 json_object_int_add(
13715 json_neigh, "nextConnectTimerDueInMsecs",
13716 thread_timer_remain_second(p->t_connect)
13717 * 1000);
13718 if (p->t_routeadv) {
13719 json_object_int_add(json_neigh, "mraiInterval",
13720 p->v_routeadv);
13721 json_object_int_add(
13722 json_neigh, "mraiTimerExpireInMsecs",
13723 thread_timer_remain_second(p->t_routeadv)
13724 * 1000);
13725 }
13726 if (p->password)
13727 json_object_int_add(json_neigh, "authenticationEnabled",
13728 1);
13729
13730 if (p->t_read)
13731 json_object_string_add(json_neigh, "readThread", "on");
13732 else
13733 json_object_string_add(json_neigh, "readThread", "off");
13734
13735 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
13736 json_object_string_add(json_neigh, "writeThread", "on");
13737 else
13738 json_object_string_add(json_neigh, "writeThread",
13739 "off");
13740 } else {
13741 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13742 p->v_connect);
13743 if (peer_established(p) && p->rtt)
13744 vty_out(vty, "Estimated round trip time: %d ms\n",
13745 p->rtt);
13746 if (p->t_start)
13747 vty_out(vty, "Next start timer due in %ld seconds\n",
13748 thread_timer_remain_second(p->t_start));
13749 if (p->t_connect)
13750 vty_out(vty, "Next connect timer due in %ld seconds\n",
13751 thread_timer_remain_second(p->t_connect));
13752 if (p->t_routeadv)
13753 vty_out(vty,
13754 "MRAI (interval %u) timer expires in %ld seconds\n",
13755 p->v_routeadv,
13756 thread_timer_remain_second(p->t_routeadv));
13757 if (p->password)
13758 vty_out(vty, "Peer Authentication Enabled\n");
13759
13760 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
13761 p->t_read ? "on" : "off",
13762 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13763 ? "on"
13764 : "off", p->fd);
13765 }
13766
13767 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13768 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13769 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13770
13771 if (!use_json)
13772 vty_out(vty, "\n");
13773
13774 /* BFD information. */
13775 if (p->bfd_config)
13776 bgp_bfd_show_info(vty, p, json_neigh);
13777
13778 if (use_json) {
13779 if (p->conf_if) /* Configured interface name. */
13780 json_object_object_add(json, p->conf_if, json_neigh);
13781 else /* Configured IP address. */
13782 json_object_object_add(json, p->host, json_neigh);
13783 }
13784 }
13785
13786 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13787 enum show_type type,
13788 union sockunion *su,
13789 const char *conf_if, afi_t afi,
13790 bool use_json)
13791 {
13792 struct listnode *node, *nnode;
13793 struct peer *peer;
13794 int find = 0;
13795 safi_t safi = SAFI_UNICAST;
13796 json_object *json = NULL;
13797 json_object *json_neighbor = NULL;
13798
13799 if (use_json) {
13800 json = json_object_new_object();
13801 json_neighbor = json_object_new_object();
13802 }
13803
13804 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13805
13806 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13807 continue;
13808
13809 if ((peer->afc[afi][safi]) == 0)
13810 continue;
13811
13812 if (type == show_all) {
13813 bgp_show_peer_gr_status(vty, peer, use_json,
13814 json_neighbor);
13815
13816 if (use_json) {
13817 json_object_object_add(json, peer->host,
13818 json_neighbor);
13819 json_neighbor = NULL;
13820 }
13821
13822 } else if (type == show_peer) {
13823 if (conf_if) {
13824 if ((peer->conf_if
13825 && !strcmp(peer->conf_if, conf_if))
13826 || (peer->hostname
13827 && !strcmp(peer->hostname, conf_if))) {
13828 find = 1;
13829 bgp_show_peer_gr_status(vty, peer,
13830 use_json,
13831 json_neighbor);
13832 }
13833 } else {
13834 if (sockunion_same(&peer->su, su)) {
13835 find = 1;
13836 bgp_show_peer_gr_status(vty, peer,
13837 use_json,
13838 json_neighbor);
13839 }
13840 }
13841 if (use_json && find)
13842 json_object_object_add(json, peer->host,
13843 json_neighbor);
13844 }
13845
13846 if (find) {
13847 json_neighbor = NULL;
13848 break;
13849 }
13850 }
13851
13852 if (type == show_peer && !find) {
13853 if (use_json)
13854 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13855 else
13856 vty_out(vty, "%% No such neighbor\n");
13857 }
13858 if (use_json) {
13859 vty_out(vty, "%s\n",
13860 json_object_to_json_string_ext(
13861 json, JSON_C_TO_STRING_PRETTY));
13862
13863 if (json_neighbor)
13864 json_object_free(json_neighbor);
13865 json_object_free(json);
13866 } else {
13867 vty_out(vty, "\n");
13868 }
13869
13870 return CMD_SUCCESS;
13871 }
13872
13873 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
13874 enum show_type type, union sockunion *su,
13875 const char *conf_if, bool use_json,
13876 json_object *json)
13877 {
13878 struct listnode *node, *nnode;
13879 struct peer *peer;
13880 int find = 0;
13881 bool nbr_output = false;
13882 afi_t afi = AFI_MAX;
13883 safi_t safi = SAFI_MAX;
13884
13885 if (type == show_ipv4_peer || type == show_ipv4_all) {
13886 afi = AFI_IP;
13887 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
13888 afi = AFI_IP6;
13889 }
13890
13891 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13892 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13893 continue;
13894
13895 switch (type) {
13896 case show_all:
13897 bgp_show_peer(vty, peer, use_json, json);
13898 nbr_output = true;
13899 break;
13900 case show_peer:
13901 if (conf_if) {
13902 if ((peer->conf_if
13903 && !strcmp(peer->conf_if, conf_if))
13904 || (peer->hostname
13905 && !strcmp(peer->hostname, conf_if))) {
13906 find = 1;
13907 bgp_show_peer(vty, peer, use_json,
13908 json);
13909 }
13910 } else {
13911 if (sockunion_same(&peer->su, su)) {
13912 find = 1;
13913 bgp_show_peer(vty, peer, use_json,
13914 json);
13915 }
13916 }
13917 break;
13918 case show_ipv4_peer:
13919 case show_ipv6_peer:
13920 FOREACH_SAFI (safi) {
13921 if (peer->afc[afi][safi]) {
13922 if (conf_if) {
13923 if ((peer->conf_if
13924 && !strcmp(peer->conf_if, conf_if))
13925 || (peer->hostname
13926 && !strcmp(peer->hostname, conf_if))) {
13927 find = 1;
13928 bgp_show_peer(vty, peer, use_json,
13929 json);
13930 break;
13931 }
13932 } else {
13933 if (sockunion_same(&peer->su, su)) {
13934 find = 1;
13935 bgp_show_peer(vty, peer, use_json,
13936 json);
13937 break;
13938 }
13939 }
13940 }
13941 }
13942 break;
13943 case show_ipv4_all:
13944 case show_ipv6_all:
13945 FOREACH_SAFI (safi) {
13946 if (peer->afc[afi][safi]) {
13947 bgp_show_peer(vty, peer, use_json, json);
13948 nbr_output = true;
13949 break;
13950 }
13951 }
13952 break;
13953 }
13954 }
13955
13956 if ((type == show_peer || type == show_ipv4_peer ||
13957 type == show_ipv6_peer) && !find) {
13958 if (use_json)
13959 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13960 else
13961 vty_out(vty, "%% No such neighbor in this view/vrf\n");
13962 }
13963
13964 if (type != show_peer && type != show_ipv4_peer &&
13965 type != show_ipv6_peer && !nbr_output && !use_json)
13966 vty_out(vty, "%% No BGP neighbors found\n");
13967
13968 if (use_json) {
13969 vty_out(vty, "%s\n", json_object_to_json_string_ext(
13970 json, JSON_C_TO_STRING_PRETTY));
13971 } else {
13972 vty_out(vty, "\n");
13973 }
13974
13975 return CMD_SUCCESS;
13976 }
13977
13978 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
13979 enum show_type type,
13980 const char *ip_str,
13981 afi_t afi, bool use_json)
13982 {
13983
13984 int ret;
13985 struct bgp *bgp;
13986 union sockunion su;
13987
13988 bgp = bgp_get_default();
13989
13990 if (!bgp)
13991 return;
13992
13993 if (!use_json)
13994 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
13995 NULL);
13996
13997 if (ip_str) {
13998 ret = str2sockunion(ip_str, &su);
13999 if (ret < 0)
14000 bgp_show_neighbor_graceful_restart(
14001 vty, bgp, type, NULL, ip_str, afi, use_json);
14002 else
14003 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14004 NULL, afi, use_json);
14005 } else
14006 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14007 afi, use_json);
14008 }
14009
14010 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14011 enum show_type type,
14012 const char *ip_str,
14013 bool use_json)
14014 {
14015 struct listnode *node, *nnode;
14016 struct bgp *bgp;
14017 union sockunion su;
14018 json_object *json = NULL;
14019 int ret, is_first = 1;
14020 bool nbr_output = false;
14021
14022 if (use_json)
14023 vty_out(vty, "{\n");
14024
14025 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14026 nbr_output = true;
14027 if (use_json) {
14028 if (!(json = json_object_new_object())) {
14029 flog_err(
14030 EC_BGP_JSON_MEM_ERROR,
14031 "Unable to allocate memory for JSON object");
14032 vty_out(vty,
14033 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14034 return;
14035 }
14036
14037 json_object_int_add(json, "vrfId",
14038 (bgp->vrf_id == VRF_UNKNOWN)
14039 ? -1
14040 : (int64_t)bgp->vrf_id);
14041 json_object_string_add(
14042 json, "vrfName",
14043 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14044 ? VRF_DEFAULT_NAME
14045 : bgp->name);
14046
14047 if (!is_first)
14048 vty_out(vty, ",\n");
14049 else
14050 is_first = 0;
14051
14052 vty_out(vty, "\"%s\":",
14053 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14054 ? VRF_DEFAULT_NAME
14055 : bgp->name);
14056 } else {
14057 vty_out(vty, "\nInstance %s:\n",
14058 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14059 ? VRF_DEFAULT_NAME
14060 : bgp->name);
14061 }
14062
14063 if (type == show_peer || type == show_ipv4_peer ||
14064 type == show_ipv6_peer) {
14065 ret = str2sockunion(ip_str, &su);
14066 if (ret < 0)
14067 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14068 use_json, json);
14069 else
14070 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14071 use_json, json);
14072 } else {
14073 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14074 use_json, json);
14075 }
14076 json_object_free(json);
14077 json = NULL;
14078 }
14079
14080 if (use_json)
14081 vty_out(vty, "}\n");
14082 else if (!nbr_output)
14083 vty_out(vty, "%% BGP instance not found\n");
14084 }
14085
14086 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14087 enum show_type type, const char *ip_str,
14088 bool use_json)
14089 {
14090 int ret;
14091 struct bgp *bgp;
14092 union sockunion su;
14093 json_object *json = NULL;
14094
14095 if (name) {
14096 if (strmatch(name, "all")) {
14097 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14098 use_json);
14099 return CMD_SUCCESS;
14100 } else {
14101 bgp = bgp_lookup_by_name(name);
14102 if (!bgp) {
14103 if (use_json) {
14104 json = json_object_new_object();
14105 vty_out(vty, "%s\n",
14106 json_object_to_json_string_ext(
14107 json,
14108 JSON_C_TO_STRING_PRETTY));
14109 json_object_free(json);
14110 } else
14111 vty_out(vty,
14112 "%% BGP instance not found\n");
14113
14114 return CMD_WARNING;
14115 }
14116 }
14117 } else {
14118 bgp = bgp_get_default();
14119 }
14120
14121 if (bgp) {
14122 json = json_object_new_object();
14123 if (ip_str) {
14124 ret = str2sockunion(ip_str, &su);
14125 if (ret < 0)
14126 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14127 use_json, json);
14128 else
14129 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14130 use_json, json);
14131 } else {
14132 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14133 json);
14134 }
14135 json_object_free(json);
14136 } else {
14137 if (use_json)
14138 vty_out(vty, "{}\n");
14139 else
14140 vty_out(vty, "%% BGP instance not found\n");
14141 }
14142
14143 return CMD_SUCCESS;
14144 }
14145
14146
14147
14148 /* "show [ip] bgp neighbors graceful-restart" commands. */
14149 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14150 show_ip_bgp_neighbors_graceful_restart_cmd,
14151 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14152 SHOW_STR
14153 BGP_STR
14154 IP_STR
14155 IPV6_STR
14156 NEIGHBOR_STR
14157 "Neighbor to display information about\n"
14158 "Neighbor to display information about\n"
14159 "Neighbor on BGP configured interface\n"
14160 GR_SHOW
14161 JSON_STR)
14162 {
14163 char *sh_arg = NULL;
14164 enum show_type sh_type;
14165 int idx = 0;
14166 afi_t afi = AFI_MAX;
14167 bool uj = use_json(argc, argv);
14168
14169 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14170 afi = AFI_MAX;
14171
14172 idx++;
14173
14174 if (argv_find(argv, argc, "A.B.C.D", &idx)
14175 || argv_find(argv, argc, "X:X::X:X", &idx)
14176 || argv_find(argv, argc, "WORD", &idx)) {
14177 sh_type = show_peer;
14178 sh_arg = argv[idx]->arg;
14179 } else
14180 sh_type = show_all;
14181
14182 if (!argv_find(argv, argc, "graceful-restart", &idx))
14183 return CMD_SUCCESS;
14184
14185
14186 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14187 afi, uj);
14188 }
14189
14190 /* "show [ip] bgp neighbors" commands. */
14191 DEFUN (show_ip_bgp_neighbors,
14192 show_ip_bgp_neighbors_cmd,
14193 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14194 SHOW_STR
14195 IP_STR
14196 BGP_STR
14197 BGP_INSTANCE_HELP_STR
14198 "Address Family\n"
14199 "Address Family\n"
14200 "Detailed information on TCP and BGP neighbor connections\n"
14201 "Neighbor to display information about\n"
14202 "Neighbor to display information about\n"
14203 "Neighbor on BGP configured interface\n"
14204 JSON_STR)
14205 {
14206 char *vrf = NULL;
14207 char *sh_arg = NULL;
14208 enum show_type sh_type;
14209 afi_t afi = AFI_MAX;
14210
14211 bool uj = use_json(argc, argv);
14212
14213 int idx = 0;
14214
14215 /* [<vrf> VIEWVRFNAME] */
14216 if (argv_find(argv, argc, "vrf", &idx)) {
14217 vrf = argv[idx + 1]->arg;
14218 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14219 vrf = NULL;
14220 } else if (argv_find(argv, argc, "view", &idx))
14221 /* [<view> VIEWVRFNAME] */
14222 vrf = argv[idx + 1]->arg;
14223
14224 idx++;
14225
14226 if (argv_find(argv, argc, "ipv4", &idx)) {
14227 sh_type = show_ipv4_all;
14228 afi = AFI_IP;
14229 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14230 sh_type = show_ipv6_all;
14231 afi = AFI_IP6;
14232 } else {
14233 sh_type = show_all;
14234 }
14235
14236 if (argv_find(argv, argc, "A.B.C.D", &idx)
14237 || argv_find(argv, argc, "X:X::X:X", &idx)
14238 || argv_find(argv, argc, "WORD", &idx)) {
14239 sh_type = show_peer;
14240 sh_arg = argv[idx]->arg;
14241 }
14242
14243 if (sh_type == show_peer && afi == AFI_IP) {
14244 sh_type = show_ipv4_peer;
14245 } else if (sh_type == show_peer && afi == AFI_IP6) {
14246 sh_type = show_ipv6_peer;
14247 }
14248
14249 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14250 }
14251
14252 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14253 paths' and `show ip mbgp paths'. Those functions results are the
14254 same.*/
14255 DEFUN (show_ip_bgp_paths,
14256 show_ip_bgp_paths_cmd,
14257 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14258 SHOW_STR
14259 IP_STR
14260 BGP_STR
14261 BGP_SAFI_HELP_STR
14262 "Path information\n")
14263 {
14264 vty_out(vty, "Address Refcnt Path\n");
14265 aspath_print_all_vty(vty);
14266 return CMD_SUCCESS;
14267 }
14268
14269 #include "hash.h"
14270
14271 static void community_show_all_iterator(struct hash_bucket *bucket,
14272 struct vty *vty)
14273 {
14274 struct community *com;
14275
14276 com = (struct community *)bucket->data;
14277 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14278 community_str(com, false));
14279 }
14280
14281 /* Show BGP's community internal data. */
14282 DEFUN (show_ip_bgp_community_info,
14283 show_ip_bgp_community_info_cmd,
14284 "show [ip] bgp community-info",
14285 SHOW_STR
14286 IP_STR
14287 BGP_STR
14288 "List all bgp community information\n")
14289 {
14290 vty_out(vty, "Address Refcnt Community\n");
14291
14292 hash_iterate(community_hash(),
14293 (void (*)(struct hash_bucket *,
14294 void *))community_show_all_iterator,
14295 vty);
14296
14297 return CMD_SUCCESS;
14298 }
14299
14300 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14301 struct vty *vty)
14302 {
14303 struct lcommunity *lcom;
14304
14305 lcom = (struct lcommunity *)bucket->data;
14306 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14307 lcommunity_str(lcom, false));
14308 }
14309
14310 /* Show BGP's community internal data. */
14311 DEFUN (show_ip_bgp_lcommunity_info,
14312 show_ip_bgp_lcommunity_info_cmd,
14313 "show ip bgp large-community-info",
14314 SHOW_STR
14315 IP_STR
14316 BGP_STR
14317 "List all bgp large-community information\n")
14318 {
14319 vty_out(vty, "Address Refcnt Large-community\n");
14320
14321 hash_iterate(lcommunity_hash(),
14322 (void (*)(struct hash_bucket *,
14323 void *))lcommunity_show_all_iterator,
14324 vty);
14325
14326 return CMD_SUCCESS;
14327 }
14328 /* Graceful Restart */
14329
14330 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14331 struct bgp *bgp,
14332 bool use_json,
14333 json_object *json)
14334 {
14335
14336
14337 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14338
14339 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14340
14341 switch (bgp_global_gr_mode) {
14342
14343 case GLOBAL_HELPER:
14344 vty_out(vty, "Global BGP GR Mode : Helper\n");
14345 break;
14346
14347 case GLOBAL_GR:
14348 vty_out(vty, "Global BGP GR Mode : Restart\n");
14349 break;
14350
14351 case GLOBAL_DISABLE:
14352 vty_out(vty, "Global BGP GR Mode : Disable\n");
14353 break;
14354
14355 case GLOBAL_INVALID:
14356 vty_out(vty,
14357 "Global BGP GR Mode Invalid\n");
14358 break;
14359 }
14360 vty_out(vty, "\n");
14361 }
14362
14363 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14364 enum show_type type,
14365 const char *ip_str,
14366 afi_t afi, bool use_json)
14367 {
14368 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14369 afi = AFI_IP;
14370
14371 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14372
14373 bgp_show_neighbor_graceful_restart_vty(
14374 vty, type, ip_str, afi, use_json);
14375 afi++;
14376 }
14377 } else if (afi != AFI_MAX) {
14378 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14379 use_json);
14380 } else {
14381 return CMD_ERR_INCOMPLETE;
14382 }
14383
14384 return CMD_SUCCESS;
14385 }
14386 /* Graceful Restart */
14387
14388 DEFUN (show_ip_bgp_attr_info,
14389 show_ip_bgp_attr_info_cmd,
14390 "show [ip] bgp attribute-info",
14391 SHOW_STR
14392 IP_STR
14393 BGP_STR
14394 "List all bgp attribute information\n")
14395 {
14396 attr_show_all(vty);
14397 return CMD_SUCCESS;
14398 }
14399
14400 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14401 afi_t afi, safi_t safi,
14402 bool use_json, json_object *json)
14403 {
14404 struct bgp *bgp;
14405 struct listnode *node;
14406 char *vname;
14407 char buf1[INET6_ADDRSTRLEN];
14408 char *ecom_str;
14409 vpn_policy_direction_t dir;
14410
14411 if (json) {
14412 json_object *json_import_vrfs = NULL;
14413 json_object *json_export_vrfs = NULL;
14414
14415 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14416
14417 if (!bgp) {
14418 vty_out(vty, "%s\n",
14419 json_object_to_json_string_ext(
14420 json,
14421 JSON_C_TO_STRING_PRETTY));
14422 json_object_free(json);
14423
14424 return CMD_WARNING;
14425 }
14426
14427 /* Provide context for the block */
14428 json_object_string_add(json, "vrf", name ? name : "default");
14429 json_object_string_add(json, "afiSafi",
14430 get_afi_safi_str(afi, safi, true));
14431
14432 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14433 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14434 json_object_string_add(json, "importFromVrfs", "none");
14435 json_object_string_add(json, "importRts", "none");
14436 } else {
14437 json_import_vrfs = json_object_new_array();
14438
14439 for (ALL_LIST_ELEMENTS_RO(
14440 bgp->vpn_policy[afi].import_vrf,
14441 node, vname))
14442 json_object_array_add(json_import_vrfs,
14443 json_object_new_string(vname));
14444
14445 json_object_object_add(json, "importFromVrfs",
14446 json_import_vrfs);
14447 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14448 if (bgp->vpn_policy[afi].rtlist[dir]) {
14449 ecom_str = ecommunity_ecom2str(
14450 bgp->vpn_policy[afi].rtlist[dir],
14451 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14452 json_object_string_add(json, "importRts",
14453 ecom_str);
14454 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14455 } else
14456 json_object_string_add(json, "importRts",
14457 "none");
14458 }
14459
14460 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14461 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14462 json_object_string_add(json, "exportToVrfs", "none");
14463 json_object_string_add(json, "routeDistinguisher",
14464 "none");
14465 json_object_string_add(json, "exportRts", "none");
14466 } else {
14467 json_export_vrfs = json_object_new_array();
14468
14469 for (ALL_LIST_ELEMENTS_RO(
14470 bgp->vpn_policy[afi].export_vrf,
14471 node, vname))
14472 json_object_array_add(json_export_vrfs,
14473 json_object_new_string(vname));
14474 json_object_object_add(json, "exportToVrfs",
14475 json_export_vrfs);
14476 json_object_string_add(json, "routeDistinguisher",
14477 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14478 buf1, RD_ADDRSTRLEN));
14479
14480 dir = BGP_VPN_POLICY_DIR_TOVPN;
14481 if (bgp->vpn_policy[afi].rtlist[dir]) {
14482 ecom_str = ecommunity_ecom2str(
14483 bgp->vpn_policy[afi].rtlist[dir],
14484 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14485 json_object_string_add(json, "exportRts",
14486 ecom_str);
14487 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14488 } else
14489 json_object_string_add(json, "exportRts",
14490 "none");
14491 }
14492
14493 if (use_json) {
14494 vty_out(vty, "%s\n",
14495 json_object_to_json_string_ext(json,
14496 JSON_C_TO_STRING_PRETTY));
14497 json_object_free(json);
14498 }
14499 } else {
14500 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14501
14502 if (!bgp) {
14503 vty_out(vty, "%% No such BGP instance exist\n");
14504 return CMD_WARNING;
14505 }
14506
14507 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14508 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14509 vty_out(vty,
14510 "This VRF is not importing %s routes from any other VRF\n",
14511 get_afi_safi_str(afi, safi, false));
14512 else {
14513 vty_out(vty,
14514 "This VRF is importing %s routes from the following VRFs:\n",
14515 get_afi_safi_str(afi, safi, false));
14516
14517 for (ALL_LIST_ELEMENTS_RO(
14518 bgp->vpn_policy[afi].import_vrf,
14519 node, vname))
14520 vty_out(vty, " %s\n", vname);
14521
14522 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14523 ecom_str = NULL;
14524 if (bgp->vpn_policy[afi].rtlist[dir]) {
14525 ecom_str = ecommunity_ecom2str(
14526 bgp->vpn_policy[afi].rtlist[dir],
14527 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14528 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14529
14530 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14531 } else
14532 vty_out(vty, "Import RT(s):\n");
14533 }
14534
14535 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14536 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14537 vty_out(vty,
14538 "This VRF is not exporting %s routes to any other VRF\n",
14539 get_afi_safi_str(afi, safi, false));
14540 else {
14541 vty_out(vty,
14542 "This VRF is exporting %s routes to the following VRFs:\n",
14543 get_afi_safi_str(afi, safi, false));
14544
14545 for (ALL_LIST_ELEMENTS_RO(
14546 bgp->vpn_policy[afi].export_vrf,
14547 node, vname))
14548 vty_out(vty, " %s\n", vname);
14549
14550 vty_out(vty, "RD: %s\n",
14551 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14552 buf1, RD_ADDRSTRLEN));
14553
14554 dir = BGP_VPN_POLICY_DIR_TOVPN;
14555 if (bgp->vpn_policy[afi].rtlist[dir]) {
14556 ecom_str = ecommunity_ecom2str(
14557 bgp->vpn_policy[afi].rtlist[dir],
14558 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14559 vty_out(vty, "Export RT: %s\n", ecom_str);
14560 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14561 } else
14562 vty_out(vty, "Import RT(s):\n");
14563 }
14564 }
14565
14566 return CMD_SUCCESS;
14567 }
14568
14569 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14570 safi_t safi, bool use_json)
14571 {
14572 struct listnode *node, *nnode;
14573 struct bgp *bgp;
14574 char *vrf_name = NULL;
14575 json_object *json = NULL;
14576 json_object *json_vrf = NULL;
14577 json_object *json_vrfs = NULL;
14578
14579 if (use_json) {
14580 json = json_object_new_object();
14581 json_vrfs = json_object_new_object();
14582 }
14583
14584 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14585
14586 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14587 vrf_name = bgp->name;
14588
14589 if (use_json) {
14590 json_vrf = json_object_new_object();
14591 } else {
14592 vty_out(vty, "\nInstance %s:\n",
14593 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14594 ? VRF_DEFAULT_NAME : bgp->name);
14595 }
14596 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14597 if (use_json) {
14598 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14599 json_object_object_add(json_vrfs,
14600 VRF_DEFAULT_NAME, json_vrf);
14601 else
14602 json_object_object_add(json_vrfs, vrf_name,
14603 json_vrf);
14604 }
14605 }
14606
14607 if (use_json) {
14608 json_object_object_add(json, "vrfs", json_vrfs);
14609 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
14610 JSON_C_TO_STRING_PRETTY));
14611 json_object_free(json);
14612 }
14613
14614 return CMD_SUCCESS;
14615 }
14616
14617 /* "show [ip] bgp route-leak" command. */
14618 DEFUN (show_ip_bgp_route_leak,
14619 show_ip_bgp_route_leak_cmd,
14620 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
14621 SHOW_STR
14622 IP_STR
14623 BGP_STR
14624 BGP_INSTANCE_HELP_STR
14625 BGP_AFI_HELP_STR
14626 BGP_SAFI_HELP_STR
14627 "Route leaking information\n"
14628 JSON_STR)
14629 {
14630 char *vrf = NULL;
14631 afi_t afi = AFI_MAX;
14632 safi_t safi = SAFI_MAX;
14633
14634 bool uj = use_json(argc, argv);
14635 int idx = 0;
14636 json_object *json = NULL;
14637
14638 /* show [ip] bgp */
14639 if (argv_find(argv, argc, "ip", &idx)) {
14640 afi = AFI_IP;
14641 safi = SAFI_UNICAST;
14642 }
14643 /* [vrf VIEWVRFNAME] */
14644 if (argv_find(argv, argc, "view", &idx)) {
14645 vty_out(vty,
14646 "%% This command is not applicable to BGP views\n");
14647 return CMD_WARNING;
14648 }
14649
14650 if (argv_find(argv, argc, "vrf", &idx)) {
14651 vrf = argv[idx + 1]->arg;
14652 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14653 vrf = NULL;
14654 }
14655 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14656 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14657 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14658 }
14659
14660 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
14661 vty_out(vty,
14662 "%% This command is applicable only for unicast ipv4|ipv6\n");
14663 return CMD_WARNING;
14664 }
14665
14666 if (vrf && strmatch(vrf, "all"))
14667 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14668
14669 if (uj)
14670 json = json_object_new_object();
14671
14672 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
14673 }
14674
14675 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14676 safi_t safi)
14677 {
14678 struct listnode *node, *nnode;
14679 struct bgp *bgp;
14680
14681 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14682 vty_out(vty, "\nInstance %s:\n",
14683 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14684 ? VRF_DEFAULT_NAME
14685 : bgp->name);
14686 update_group_show(bgp, afi, safi, vty, 0);
14687 }
14688 }
14689
14690 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14691 int safi, uint64_t subgrp_id)
14692 {
14693 struct bgp *bgp;
14694
14695 if (name) {
14696 if (strmatch(name, "all")) {
14697 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14698 return CMD_SUCCESS;
14699 } else {
14700 bgp = bgp_lookup_by_name(name);
14701 }
14702 } else {
14703 bgp = bgp_get_default();
14704 }
14705
14706 if (bgp)
14707 update_group_show(bgp, afi, safi, vty, subgrp_id);
14708 return CMD_SUCCESS;
14709 }
14710
14711 DEFUN (show_ip_bgp_updgrps,
14712 show_ip_bgp_updgrps_cmd,
14713 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
14714 SHOW_STR
14715 IP_STR
14716 BGP_STR
14717 BGP_INSTANCE_HELP_STR
14718 BGP_AFI_HELP_STR
14719 BGP_SAFI_WITH_LABEL_HELP_STR
14720 "Detailed info about dynamic update groups\n"
14721 "Specific subgroup to display detailed info for\n")
14722 {
14723 char *vrf = NULL;
14724 afi_t afi = AFI_IP6;
14725 safi_t safi = SAFI_UNICAST;
14726 uint64_t subgrp_id = 0;
14727
14728 int idx = 0;
14729
14730 /* show [ip] bgp */
14731 if (argv_find(argv, argc, "ip", &idx))
14732 afi = AFI_IP;
14733 /* [<vrf> VIEWVRFNAME] */
14734 if (argv_find(argv, argc, "vrf", &idx)) {
14735 vrf = argv[idx + 1]->arg;
14736 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14737 vrf = NULL;
14738 } else if (argv_find(argv, argc, "view", &idx))
14739 /* [<view> VIEWVRFNAME] */
14740 vrf = argv[idx + 1]->arg;
14741 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14742 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14743 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14744 }
14745
14746 /* get subgroup id, if provided */
14747 idx = argc - 1;
14748 if (argv[idx]->type == VARIABLE_TKN)
14749 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
14750
14751 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
14752 }
14753
14754 DEFUN (show_bgp_instance_all_ipv6_updgrps,
14755 show_bgp_instance_all_ipv6_updgrps_cmd,
14756 "show [ip] bgp <view|vrf> all update-groups",
14757 SHOW_STR
14758 IP_STR
14759 BGP_STR
14760 BGP_INSTANCE_ALL_HELP_STR
14761 "Detailed info about dynamic update groups\n")
14762 {
14763 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14764 return CMD_SUCCESS;
14765 }
14766
14767 DEFUN (show_bgp_l2vpn_evpn_updgrps,
14768 show_bgp_l2vpn_evpn_updgrps_cmd,
14769 "show [ip] bgp l2vpn evpn update-groups",
14770 SHOW_STR
14771 IP_STR
14772 BGP_STR
14773 "l2vpn address family\n"
14774 "evpn sub-address family\n"
14775 "Detailed info about dynamic update groups\n")
14776 {
14777 char *vrf = NULL;
14778 uint64_t subgrp_id = 0;
14779
14780 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14781 return CMD_SUCCESS;
14782 }
14783
14784 DEFUN (show_bgp_updgrps_stats,
14785 show_bgp_updgrps_stats_cmd,
14786 "show [ip] bgp update-groups statistics",
14787 SHOW_STR
14788 IP_STR
14789 BGP_STR
14790 "Detailed info about dynamic update groups\n"
14791 "Statistics\n")
14792 {
14793 struct bgp *bgp;
14794
14795 bgp = bgp_get_default();
14796 if (bgp)
14797 update_group_show_stats(bgp, vty);
14798
14799 return CMD_SUCCESS;
14800 }
14801
14802 DEFUN (show_bgp_instance_updgrps_stats,
14803 show_bgp_instance_updgrps_stats_cmd,
14804 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
14805 SHOW_STR
14806 IP_STR
14807 BGP_STR
14808 BGP_INSTANCE_HELP_STR
14809 "Detailed info about dynamic update groups\n"
14810 "Statistics\n")
14811 {
14812 int idx_word = 3;
14813 struct bgp *bgp;
14814
14815 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14816 if (bgp)
14817 update_group_show_stats(bgp, vty);
14818
14819 return CMD_SUCCESS;
14820 }
14821
14822 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14823 afi_t afi, safi_t safi,
14824 const char *what, uint64_t subgrp_id)
14825 {
14826 struct bgp *bgp;
14827
14828 if (name)
14829 bgp = bgp_lookup_by_name(name);
14830 else
14831 bgp = bgp_get_default();
14832
14833 if (bgp) {
14834 if (!strcmp(what, "advertise-queue"))
14835 update_group_show_adj_queue(bgp, afi, safi, vty,
14836 subgrp_id);
14837 else if (!strcmp(what, "advertised-routes"))
14838 update_group_show_advertised(bgp, afi, safi, vty,
14839 subgrp_id);
14840 else if (!strcmp(what, "packet-queue"))
14841 update_group_show_packet_queue(bgp, afi, safi, vty,
14842 subgrp_id);
14843 }
14844 }
14845
14846 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14847 show_ip_bgp_instance_updgrps_adj_s_cmd,
14848 "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",
14849 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14850 BGP_SAFI_HELP_STR
14851 "Detailed info about dynamic update groups\n"
14852 "Specific subgroup to display info for\n"
14853 "Advertisement queue\n"
14854 "Announced routes\n"
14855 "Packet queue\n")
14856 {
14857 uint64_t subgrp_id = 0;
14858 afi_t afiz;
14859 safi_t safiz;
14860 if (sgid)
14861 subgrp_id = strtoull(sgid, NULL, 10);
14862
14863 if (!ip && !afi)
14864 afiz = AFI_IP6;
14865 if (!ip && afi)
14866 afiz = bgp_vty_afi_from_str(afi);
14867 if (ip && !afi)
14868 afiz = AFI_IP;
14869 if (ip && afi) {
14870 afiz = bgp_vty_afi_from_str(afi);
14871 if (afiz != AFI_IP)
14872 vty_out(vty,
14873 "%% Cannot specify both 'ip' and 'ipv6'\n");
14874 return CMD_WARNING;
14875 }
14876
14877 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
14878
14879 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
14880 return CMD_SUCCESS;
14881 }
14882
14883 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
14884 json_object *json)
14885 {
14886 struct listnode *node, *nnode;
14887 struct prefix *range;
14888 struct peer *conf;
14889 struct peer *peer;
14890 afi_t afi;
14891 safi_t safi;
14892 const char *peer_status;
14893 int lr_count;
14894 int dynamic;
14895 bool af_cfgd;
14896 json_object *json_peer_group = NULL;
14897 json_object *json_peer_group_afc = NULL;
14898 json_object *json_peer_group_members = NULL;
14899 json_object *json_peer_group_dynamic = NULL;
14900 json_object *json_peer_group_dynamic_af = NULL;
14901 json_object *json_peer_group_ranges = NULL;
14902
14903 conf = group->conf;
14904
14905 if (json) {
14906 json_peer_group = json_object_new_object();
14907 json_peer_group_afc = json_object_new_array();
14908 }
14909
14910 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
14911 if (json)
14912 json_object_int_add(json_peer_group, "remoteAs",
14913 conf->as);
14914 else
14915 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
14916 group->name, conf->as);
14917 } else if (conf->as_type == AS_INTERNAL) {
14918 if (json)
14919 json_object_int_add(json_peer_group, "remoteAs",
14920 group->bgp->as);
14921 else
14922 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
14923 group->name, group->bgp->as);
14924 } else {
14925 if (!json)
14926 vty_out(vty, "\nBGP peer-group %s\n", group->name);
14927 }
14928
14929 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
14930 if (json)
14931 json_object_string_add(json_peer_group, "type",
14932 "internal");
14933 else
14934 vty_out(vty, " Peer-group type is internal\n");
14935 } else {
14936 if (json)
14937 json_object_string_add(json_peer_group, "type",
14938 "external");
14939 else
14940 vty_out(vty, " Peer-group type is external\n");
14941 }
14942
14943 /* Display AFs configured. */
14944 if (!json)
14945 vty_out(vty, " Configured address-families:");
14946
14947 FOREACH_AFI_SAFI (afi, safi) {
14948 if (conf->afc[afi][safi]) {
14949 af_cfgd = true;
14950 if (json)
14951 json_object_array_add(
14952 json_peer_group_afc,
14953 json_object_new_string(get_afi_safi_str(
14954 afi, safi, false)));
14955 else
14956 vty_out(vty, " %s;",
14957 get_afi_safi_str(afi, safi, false));
14958 }
14959 }
14960
14961 if (json) {
14962 json_object_object_add(json_peer_group,
14963 "addressFamiliesConfigured",
14964 json_peer_group_afc);
14965 } else {
14966 if (!af_cfgd)
14967 vty_out(vty, " none\n");
14968 else
14969 vty_out(vty, "\n");
14970 }
14971
14972 /* Display listen ranges (for dynamic neighbors), if any */
14973 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
14974 lr_count = listcount(group->listen_range[afi]);
14975 if (lr_count) {
14976 if (json) {
14977 if (!json_peer_group_dynamic)
14978 json_peer_group_dynamic =
14979 json_object_new_object();
14980
14981 json_peer_group_dynamic_af =
14982 json_object_new_object();
14983 json_peer_group_ranges =
14984 json_object_new_array();
14985 json_object_int_add(json_peer_group_dynamic_af,
14986 "count", lr_count);
14987 } else {
14988 vty_out(vty, " %d %s listen range(s)\n",
14989 lr_count, afi2str(afi));
14990 }
14991
14992 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
14993 nnode, range)) {
14994 if (json) {
14995 char buf[BUFSIZ];
14996
14997 snprintfrr(buf, sizeof(buf), "%pFX",
14998 range);
14999
15000 json_object_array_add(
15001 json_peer_group_ranges,
15002 json_object_new_string(buf));
15003 } else {
15004 vty_out(vty, " %pFX\n", range);
15005 }
15006 }
15007
15008 if (json) {
15009 json_object_object_add(
15010 json_peer_group_dynamic_af, "ranges",
15011 json_peer_group_ranges);
15012
15013 json_object_object_add(
15014 json_peer_group_dynamic, afi2str(afi),
15015 json_peer_group_dynamic_af);
15016 }
15017 }
15018 }
15019
15020 if (json_peer_group_dynamic)
15021 json_object_object_add(json_peer_group, "dynamicRanges",
15022 json_peer_group_dynamic);
15023
15024 /* Display group members and their status */
15025 if (listcount(group->peer)) {
15026 if (json)
15027 json_peer_group_members = json_object_new_object();
15028 else
15029 vty_out(vty, " Peer-group members:\n");
15030 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15031 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15032 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15033 peer_status = "Idle (Admin)";
15034 else if (CHECK_FLAG(peer->sflags,
15035 PEER_STATUS_PREFIX_OVERFLOW))
15036 peer_status = "Idle (PfxCt)";
15037 else
15038 peer_status = lookup_msg(bgp_status_msg,
15039 peer->status, NULL);
15040
15041 dynamic = peer_dynamic_neighbor(peer);
15042
15043 if (json) {
15044 json_object *json_peer_group_member =
15045 json_object_new_object();
15046
15047 json_object_string_add(json_peer_group_member,
15048 "status", peer_status);
15049
15050 if (dynamic)
15051 json_object_boolean_true_add(
15052 json_peer_group_member,
15053 "dynamic");
15054
15055 json_object_object_add(json_peer_group_members,
15056 peer->host,
15057 json_peer_group_member);
15058 } else {
15059 vty_out(vty, " %s %s %s \n", peer->host,
15060 dynamic ? "(dynamic)" : "",
15061 peer_status);
15062 }
15063 }
15064 if (json)
15065 json_object_object_add(json_peer_group, "members",
15066 json_peer_group_members);
15067 }
15068
15069 if (json)
15070 json_object_object_add(json, group->name, json_peer_group);
15071
15072 return CMD_SUCCESS;
15073 }
15074
15075 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15076 const char *group_name, bool uj)
15077 {
15078 struct bgp *bgp;
15079 struct listnode *node, *nnode;
15080 struct peer_group *group;
15081 bool found = false;
15082 json_object *json = NULL;
15083
15084 if (uj)
15085 json = json_object_new_object();
15086
15087 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15088
15089 if (!bgp) {
15090 if (uj) {
15091 vty_out(vty, "%s\n",
15092 json_object_to_json_string_ext(
15093 json, JSON_C_TO_STRING_PRETTY));
15094 json_object_free(json);
15095 } else {
15096 vty_out(vty, "%% BGP instance not found\n");
15097 }
15098
15099 return CMD_WARNING;
15100 }
15101
15102 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15103 if (group_name) {
15104 if (strmatch(group->name, group_name)) {
15105 bgp_show_one_peer_group(vty, group, json);
15106 found = true;
15107 break;
15108 }
15109 } else {
15110 bgp_show_one_peer_group(vty, group, json);
15111 }
15112 }
15113
15114 if (group_name && !found && !uj)
15115 vty_out(vty, "%% No such peer-group\n");
15116
15117 if (uj) {
15118 vty_out(vty, "%s\n",
15119 json_object_to_json_string_ext(
15120 json, JSON_C_TO_STRING_PRETTY));
15121 json_object_free(json);
15122 }
15123
15124 return CMD_SUCCESS;
15125 }
15126
15127 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15128 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15129 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15130 "Detailed information on BGP peer groups\n"
15131 "Peer group name\n" JSON_STR)
15132 {
15133 char *vrf, *pg;
15134 int idx = 0;
15135 bool uj = use_json(argc, argv);
15136
15137 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15138 : NULL;
15139 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15140
15141 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15142 }
15143
15144
15145 /* Redistribute VTY commands. */
15146
15147 DEFUN (bgp_redistribute_ipv4,
15148 bgp_redistribute_ipv4_cmd,
15149 "redistribute " FRR_IP_REDIST_STR_BGPD,
15150 "Redistribute information from another routing protocol\n"
15151 FRR_IP_REDIST_HELP_STR_BGPD)
15152 {
15153 VTY_DECLVAR_CONTEXT(bgp, bgp);
15154 int idx_protocol = 1;
15155 int type;
15156
15157 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15158 if (type < 0) {
15159 vty_out(vty, "%% Invalid route type\n");
15160 return CMD_WARNING_CONFIG_FAILED;
15161 }
15162
15163 bgp_redist_add(bgp, AFI_IP, type, 0);
15164 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15165 }
15166
15167 ALIAS_HIDDEN(
15168 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15169 "redistribute " FRR_IP_REDIST_STR_BGPD,
15170 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15171
15172 DEFUN (bgp_redistribute_ipv4_rmap,
15173 bgp_redistribute_ipv4_rmap_cmd,
15174 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15175 "Redistribute information from another routing protocol\n"
15176 FRR_IP_REDIST_HELP_STR_BGPD
15177 "Route map reference\n"
15178 "Pointer to route-map entries\n")
15179 {
15180 VTY_DECLVAR_CONTEXT(bgp, bgp);
15181 int idx_protocol = 1;
15182 int idx_word = 3;
15183 int type;
15184 struct bgp_redist *red;
15185 bool changed;
15186 struct route_map *route_map = route_map_lookup_warn_noexist(
15187 vty, argv[idx_word]->arg);
15188
15189 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15190 if (type < 0) {
15191 vty_out(vty, "%% Invalid route type\n");
15192 return CMD_WARNING_CONFIG_FAILED;
15193 }
15194
15195 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15196 changed =
15197 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15198 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15199 }
15200
15201 ALIAS_HIDDEN(
15202 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15203 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15204 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15205 "Route map reference\n"
15206 "Pointer to route-map entries\n")
15207
15208 DEFUN (bgp_redistribute_ipv4_metric,
15209 bgp_redistribute_ipv4_metric_cmd,
15210 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15211 "Redistribute information from another routing protocol\n"
15212 FRR_IP_REDIST_HELP_STR_BGPD
15213 "Metric for redistributed routes\n"
15214 "Default metric\n")
15215 {
15216 VTY_DECLVAR_CONTEXT(bgp, bgp);
15217 int idx_protocol = 1;
15218 int idx_number = 3;
15219 int type;
15220 uint32_t metric;
15221 struct bgp_redist *red;
15222 bool changed;
15223
15224 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15225 if (type < 0) {
15226 vty_out(vty, "%% Invalid route type\n");
15227 return CMD_WARNING_CONFIG_FAILED;
15228 }
15229 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15230
15231 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15232 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15233 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15234 }
15235
15236 ALIAS_HIDDEN(
15237 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15238 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15239 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15240 "Metric for redistributed routes\n"
15241 "Default metric\n")
15242
15243 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15244 bgp_redistribute_ipv4_rmap_metric_cmd,
15245 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15246 "Redistribute information from another routing protocol\n"
15247 FRR_IP_REDIST_HELP_STR_BGPD
15248 "Route map reference\n"
15249 "Pointer to route-map entries\n"
15250 "Metric for redistributed routes\n"
15251 "Default metric\n")
15252 {
15253 VTY_DECLVAR_CONTEXT(bgp, bgp);
15254 int idx_protocol = 1;
15255 int idx_word = 3;
15256 int idx_number = 5;
15257 int type;
15258 uint32_t metric;
15259 struct bgp_redist *red;
15260 bool changed;
15261 struct route_map *route_map =
15262 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15263
15264 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15265 if (type < 0) {
15266 vty_out(vty, "%% Invalid route type\n");
15267 return CMD_WARNING_CONFIG_FAILED;
15268 }
15269 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15270
15271 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15272 changed =
15273 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15274 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15275 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15276 }
15277
15278 ALIAS_HIDDEN(
15279 bgp_redistribute_ipv4_rmap_metric,
15280 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15281 "redistribute " FRR_IP_REDIST_STR_BGPD
15282 " route-map WORD metric (0-4294967295)",
15283 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15284 "Route map reference\n"
15285 "Pointer to route-map entries\n"
15286 "Metric for redistributed routes\n"
15287 "Default metric\n")
15288
15289 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15290 bgp_redistribute_ipv4_metric_rmap_cmd,
15291 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15292 "Redistribute information from another routing protocol\n"
15293 FRR_IP_REDIST_HELP_STR_BGPD
15294 "Metric for redistributed routes\n"
15295 "Default metric\n"
15296 "Route map reference\n"
15297 "Pointer to route-map entries\n")
15298 {
15299 VTY_DECLVAR_CONTEXT(bgp, bgp);
15300 int idx_protocol = 1;
15301 int idx_number = 3;
15302 int idx_word = 5;
15303 int type;
15304 uint32_t metric;
15305 struct bgp_redist *red;
15306 bool changed;
15307 struct route_map *route_map =
15308 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15309
15310 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15311 if (type < 0) {
15312 vty_out(vty, "%% Invalid route type\n");
15313 return CMD_WARNING_CONFIG_FAILED;
15314 }
15315 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15316
15317 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15318 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15319 changed |=
15320 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15321 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15322 }
15323
15324 ALIAS_HIDDEN(
15325 bgp_redistribute_ipv4_metric_rmap,
15326 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15327 "redistribute " FRR_IP_REDIST_STR_BGPD
15328 " metric (0-4294967295) route-map WORD",
15329 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15330 "Metric for redistributed routes\n"
15331 "Default metric\n"
15332 "Route map reference\n"
15333 "Pointer to route-map entries\n")
15334
15335 DEFUN (bgp_redistribute_ipv4_ospf,
15336 bgp_redistribute_ipv4_ospf_cmd,
15337 "redistribute <ospf|table> (1-65535)",
15338 "Redistribute information from another routing protocol\n"
15339 "Open Shortest Path First (OSPFv2)\n"
15340 "Non-main Kernel Routing Table\n"
15341 "Instance ID/Table ID\n")
15342 {
15343 VTY_DECLVAR_CONTEXT(bgp, bgp);
15344 int idx_ospf_table = 1;
15345 int idx_number = 2;
15346 unsigned short instance;
15347 unsigned short protocol;
15348
15349 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15350
15351 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15352 protocol = ZEBRA_ROUTE_OSPF;
15353 else
15354 protocol = ZEBRA_ROUTE_TABLE;
15355
15356 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15357 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15358 }
15359
15360 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15361 "redistribute <ospf|table> (1-65535)",
15362 "Redistribute information from another routing protocol\n"
15363 "Open Shortest Path First (OSPFv2)\n"
15364 "Non-main Kernel Routing Table\n"
15365 "Instance ID/Table ID\n")
15366
15367 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15368 bgp_redistribute_ipv4_ospf_rmap_cmd,
15369 "redistribute <ospf|table> (1-65535) route-map WORD",
15370 "Redistribute information from another routing protocol\n"
15371 "Open Shortest Path First (OSPFv2)\n"
15372 "Non-main Kernel Routing Table\n"
15373 "Instance ID/Table ID\n"
15374 "Route map reference\n"
15375 "Pointer to route-map entries\n")
15376 {
15377 VTY_DECLVAR_CONTEXT(bgp, bgp);
15378 int idx_ospf_table = 1;
15379 int idx_number = 2;
15380 int idx_word = 4;
15381 struct bgp_redist *red;
15382 unsigned short instance;
15383 int protocol;
15384 bool changed;
15385 struct route_map *route_map =
15386 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15387
15388 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15389 protocol = ZEBRA_ROUTE_OSPF;
15390 else
15391 protocol = ZEBRA_ROUTE_TABLE;
15392
15393 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15394 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15395 changed =
15396 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15397 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15398 }
15399
15400 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15401 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15402 "redistribute <ospf|table> (1-65535) route-map WORD",
15403 "Redistribute information from another routing protocol\n"
15404 "Open Shortest Path First (OSPFv2)\n"
15405 "Non-main Kernel Routing Table\n"
15406 "Instance ID/Table ID\n"
15407 "Route map reference\n"
15408 "Pointer to route-map entries\n")
15409
15410 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15411 bgp_redistribute_ipv4_ospf_metric_cmd,
15412 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15413 "Redistribute information from another routing protocol\n"
15414 "Open Shortest Path First (OSPFv2)\n"
15415 "Non-main Kernel Routing Table\n"
15416 "Instance ID/Table ID\n"
15417 "Metric for redistributed routes\n"
15418 "Default metric\n")
15419 {
15420 VTY_DECLVAR_CONTEXT(bgp, bgp);
15421 int idx_ospf_table = 1;
15422 int idx_number = 2;
15423 int idx_number_2 = 4;
15424 uint32_t metric;
15425 struct bgp_redist *red;
15426 unsigned short instance;
15427 int protocol;
15428 bool changed;
15429
15430 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15431 protocol = ZEBRA_ROUTE_OSPF;
15432 else
15433 protocol = ZEBRA_ROUTE_TABLE;
15434
15435 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15436 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15437
15438 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15439 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15440 metric);
15441 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15442 }
15443
15444 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15445 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15446 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15447 "Redistribute information from another routing protocol\n"
15448 "Open Shortest Path First (OSPFv2)\n"
15449 "Non-main Kernel Routing Table\n"
15450 "Instance ID/Table ID\n"
15451 "Metric for redistributed routes\n"
15452 "Default metric\n")
15453
15454 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15455 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15456 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15457 "Redistribute information from another routing protocol\n"
15458 "Open Shortest Path First (OSPFv2)\n"
15459 "Non-main Kernel Routing Table\n"
15460 "Instance ID/Table ID\n"
15461 "Route map reference\n"
15462 "Pointer to route-map entries\n"
15463 "Metric for redistributed routes\n"
15464 "Default metric\n")
15465 {
15466 VTY_DECLVAR_CONTEXT(bgp, bgp);
15467 int idx_ospf_table = 1;
15468 int idx_number = 2;
15469 int idx_word = 4;
15470 int idx_number_2 = 6;
15471 uint32_t metric;
15472 struct bgp_redist *red;
15473 unsigned short instance;
15474 int protocol;
15475 bool changed;
15476 struct route_map *route_map =
15477 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15478
15479 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15480 protocol = ZEBRA_ROUTE_OSPF;
15481 else
15482 protocol = ZEBRA_ROUTE_TABLE;
15483
15484 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15485 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15486
15487 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15488 changed =
15489 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15490 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15491 metric);
15492 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15493 }
15494
15495 ALIAS_HIDDEN(
15496 bgp_redistribute_ipv4_ospf_rmap_metric,
15497 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15498 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15499 "Redistribute information from another routing protocol\n"
15500 "Open Shortest Path First (OSPFv2)\n"
15501 "Non-main Kernel Routing Table\n"
15502 "Instance ID/Table ID\n"
15503 "Route map reference\n"
15504 "Pointer to route-map entries\n"
15505 "Metric for redistributed routes\n"
15506 "Default metric\n")
15507
15508 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15509 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15510 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15511 "Redistribute information from another routing protocol\n"
15512 "Open Shortest Path First (OSPFv2)\n"
15513 "Non-main Kernel Routing Table\n"
15514 "Instance ID/Table ID\n"
15515 "Metric for redistributed routes\n"
15516 "Default metric\n"
15517 "Route map reference\n"
15518 "Pointer to route-map entries\n")
15519 {
15520 VTY_DECLVAR_CONTEXT(bgp, bgp);
15521 int idx_ospf_table = 1;
15522 int idx_number = 2;
15523 int idx_number_2 = 4;
15524 int idx_word = 6;
15525 uint32_t metric;
15526 struct bgp_redist *red;
15527 unsigned short instance;
15528 int protocol;
15529 bool changed;
15530 struct route_map *route_map =
15531 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15532
15533 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15534 protocol = ZEBRA_ROUTE_OSPF;
15535 else
15536 protocol = ZEBRA_ROUTE_TABLE;
15537
15538 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15539 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15540
15541 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15542 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15543 metric);
15544 changed |=
15545 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15546 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15547 }
15548
15549 ALIAS_HIDDEN(
15550 bgp_redistribute_ipv4_ospf_metric_rmap,
15551 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15552 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15553 "Redistribute information from another routing protocol\n"
15554 "Open Shortest Path First (OSPFv2)\n"
15555 "Non-main Kernel Routing Table\n"
15556 "Instance ID/Table ID\n"
15557 "Metric for redistributed routes\n"
15558 "Default metric\n"
15559 "Route map reference\n"
15560 "Pointer to route-map entries\n")
15561
15562 DEFUN (no_bgp_redistribute_ipv4_ospf,
15563 no_bgp_redistribute_ipv4_ospf_cmd,
15564 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15565 NO_STR
15566 "Redistribute information from another routing protocol\n"
15567 "Open Shortest Path First (OSPFv2)\n"
15568 "Non-main Kernel Routing Table\n"
15569 "Instance ID/Table ID\n"
15570 "Metric for redistributed routes\n"
15571 "Default metric\n"
15572 "Route map reference\n"
15573 "Pointer to route-map entries\n")
15574 {
15575 VTY_DECLVAR_CONTEXT(bgp, bgp);
15576 int idx_ospf_table = 2;
15577 int idx_number = 3;
15578 unsigned short instance;
15579 int protocol;
15580
15581 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15582 protocol = ZEBRA_ROUTE_OSPF;
15583 else
15584 protocol = ZEBRA_ROUTE_TABLE;
15585
15586 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15587 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
15588 }
15589
15590 ALIAS_HIDDEN(
15591 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15592 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15593 NO_STR
15594 "Redistribute information from another routing protocol\n"
15595 "Open Shortest Path First (OSPFv2)\n"
15596 "Non-main Kernel Routing Table\n"
15597 "Instance ID/Table ID\n"
15598 "Metric for redistributed routes\n"
15599 "Default metric\n"
15600 "Route map reference\n"
15601 "Pointer to route-map entries\n")
15602
15603 DEFUN (no_bgp_redistribute_ipv4,
15604 no_bgp_redistribute_ipv4_cmd,
15605 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15606 NO_STR
15607 "Redistribute information from another routing protocol\n"
15608 FRR_IP_REDIST_HELP_STR_BGPD
15609 "Metric for redistributed routes\n"
15610 "Default metric\n"
15611 "Route map reference\n"
15612 "Pointer to route-map entries\n")
15613 {
15614 VTY_DECLVAR_CONTEXT(bgp, bgp);
15615 int idx_protocol = 2;
15616 int type;
15617
15618 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15619 if (type < 0) {
15620 vty_out(vty, "%% Invalid route type\n");
15621 return CMD_WARNING_CONFIG_FAILED;
15622 }
15623 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
15624 }
15625
15626 ALIAS_HIDDEN(
15627 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15628 "no redistribute " FRR_IP_REDIST_STR_BGPD
15629 " [{metric (0-4294967295)|route-map WORD}]",
15630 NO_STR
15631 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15632 "Metric for redistributed routes\n"
15633 "Default metric\n"
15634 "Route map reference\n"
15635 "Pointer to route-map entries\n")
15636
15637 DEFUN (bgp_redistribute_ipv6,
15638 bgp_redistribute_ipv6_cmd,
15639 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15640 "Redistribute information from another routing protocol\n"
15641 FRR_IP6_REDIST_HELP_STR_BGPD)
15642 {
15643 VTY_DECLVAR_CONTEXT(bgp, bgp);
15644 int idx_protocol = 1;
15645 int type;
15646
15647 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15648 if (type < 0) {
15649 vty_out(vty, "%% Invalid route type\n");
15650 return CMD_WARNING_CONFIG_FAILED;
15651 }
15652
15653 bgp_redist_add(bgp, AFI_IP6, type, 0);
15654 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
15655 }
15656
15657 DEFUN (bgp_redistribute_ipv6_rmap,
15658 bgp_redistribute_ipv6_rmap_cmd,
15659 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15660 "Redistribute information from another routing protocol\n"
15661 FRR_IP6_REDIST_HELP_STR_BGPD
15662 "Route map reference\n"
15663 "Pointer to route-map entries\n")
15664 {
15665 VTY_DECLVAR_CONTEXT(bgp, bgp);
15666 int idx_protocol = 1;
15667 int idx_word = 3;
15668 int type;
15669 struct bgp_redist *red;
15670 bool changed;
15671 struct route_map *route_map =
15672 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15673
15674 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15675 if (type < 0) {
15676 vty_out(vty, "%% Invalid route type\n");
15677 return CMD_WARNING_CONFIG_FAILED;
15678 }
15679
15680 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15681 changed =
15682 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15683 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15684 }
15685
15686 DEFUN (bgp_redistribute_ipv6_metric,
15687 bgp_redistribute_ipv6_metric_cmd,
15688 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
15689 "Redistribute information from another routing protocol\n"
15690 FRR_IP6_REDIST_HELP_STR_BGPD
15691 "Metric for redistributed routes\n"
15692 "Default metric\n")
15693 {
15694 VTY_DECLVAR_CONTEXT(bgp, bgp);
15695 int idx_protocol = 1;
15696 int idx_number = 3;
15697 int type;
15698 uint32_t metric;
15699 struct bgp_redist *red;
15700 bool changed;
15701
15702 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15703 if (type < 0) {
15704 vty_out(vty, "%% Invalid route type\n");
15705 return CMD_WARNING_CONFIG_FAILED;
15706 }
15707 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15708
15709 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15710 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15711 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15712 }
15713
15714 DEFUN (bgp_redistribute_ipv6_rmap_metric,
15715 bgp_redistribute_ipv6_rmap_metric_cmd,
15716 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15717 "Redistribute information from another routing protocol\n"
15718 FRR_IP6_REDIST_HELP_STR_BGPD
15719 "Route map reference\n"
15720 "Pointer to route-map entries\n"
15721 "Metric for redistributed routes\n"
15722 "Default metric\n")
15723 {
15724 VTY_DECLVAR_CONTEXT(bgp, bgp);
15725 int idx_protocol = 1;
15726 int idx_word = 3;
15727 int idx_number = 5;
15728 int type;
15729 uint32_t metric;
15730 struct bgp_redist *red;
15731 bool changed;
15732 struct route_map *route_map =
15733 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15734
15735 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15736 if (type < 0) {
15737 vty_out(vty, "%% Invalid route type\n");
15738 return CMD_WARNING_CONFIG_FAILED;
15739 }
15740 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15741
15742 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15743 changed =
15744 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15745 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15746 metric);
15747 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15748 }
15749
15750 DEFUN (bgp_redistribute_ipv6_metric_rmap,
15751 bgp_redistribute_ipv6_metric_rmap_cmd,
15752 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15753 "Redistribute information from another routing protocol\n"
15754 FRR_IP6_REDIST_HELP_STR_BGPD
15755 "Metric for redistributed routes\n"
15756 "Default metric\n"
15757 "Route map reference\n"
15758 "Pointer to route-map entries\n")
15759 {
15760 VTY_DECLVAR_CONTEXT(bgp, bgp);
15761 int idx_protocol = 1;
15762 int idx_number = 3;
15763 int idx_word = 5;
15764 int type;
15765 uint32_t metric;
15766 struct bgp_redist *red;
15767 bool changed;
15768 struct route_map *route_map =
15769 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15770
15771 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15772 if (type < 0) {
15773 vty_out(vty, "%% Invalid route type\n");
15774 return CMD_WARNING_CONFIG_FAILED;
15775 }
15776 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15777
15778 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15779 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15780 metric);
15781 changed |=
15782 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15783 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15784 }
15785
15786 DEFUN (no_bgp_redistribute_ipv6,
15787 no_bgp_redistribute_ipv6_cmd,
15788 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15789 NO_STR
15790 "Redistribute information from another routing protocol\n"
15791 FRR_IP6_REDIST_HELP_STR_BGPD
15792 "Metric for redistributed routes\n"
15793 "Default metric\n"
15794 "Route map reference\n"
15795 "Pointer to route-map entries\n")
15796 {
15797 VTY_DECLVAR_CONTEXT(bgp, bgp);
15798 int idx_protocol = 2;
15799 int type;
15800
15801 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15802 if (type < 0) {
15803 vty_out(vty, "%% Invalid route type\n");
15804 return CMD_WARNING_CONFIG_FAILED;
15805 }
15806
15807 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
15808 }
15809
15810 /* Neighbor update tcp-mss. */
15811 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15812 const char *tcp_mss_str)
15813 {
15814 struct peer *peer;
15815 uint32_t tcp_mss_val = 0;
15816
15817 peer = peer_and_group_lookup_vty(vty, peer_str);
15818 if (!peer)
15819 return CMD_WARNING_CONFIG_FAILED;
15820
15821 if (tcp_mss_str) {
15822 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15823 peer_tcp_mss_set(peer, tcp_mss_val);
15824 } else {
15825 peer_tcp_mss_unset(peer);
15826 }
15827
15828 return CMD_SUCCESS;
15829 }
15830
15831 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15832 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15833 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15834 "TCP max segment size\n"
15835 "TCP MSS value\n")
15836 {
15837 int peer_index = 1;
15838 int mss_index = 3;
15839
15840 vty_out(vty,
15841 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15842 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
15843 argv[mss_index]->arg);
15844 }
15845
15846 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
15847 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
15848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15849 "TCP max segment size\n"
15850 "TCP MSS value\n")
15851 {
15852 int peer_index = 2;
15853
15854 vty_out(vty,
15855 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15856 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
15857 }
15858
15859 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15860 afi_t afi, safi_t safi)
15861 {
15862 int i;
15863
15864 /* Unicast redistribution only. */
15865 if (safi != SAFI_UNICAST)
15866 return;
15867
15868 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
15869 /* Redistribute BGP does not make sense. */
15870 if (i != ZEBRA_ROUTE_BGP) {
15871 struct list *red_list;
15872 struct listnode *node;
15873 struct bgp_redist *red;
15874
15875 red_list = bgp->redist[afi][i];
15876 if (!red_list)
15877 continue;
15878
15879 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
15880 /* "redistribute" configuration. */
15881 vty_out(vty, " redistribute %s",
15882 zebra_route_string(i));
15883 if (red->instance)
15884 vty_out(vty, " %d", red->instance);
15885 if (red->redist_metric_flag)
15886 vty_out(vty, " metric %u",
15887 red->redist_metric);
15888 if (red->rmap.name)
15889 vty_out(vty, " route-map %s",
15890 red->rmap.name);
15891 vty_out(vty, "\n");
15892 }
15893 }
15894 }
15895 }
15896
15897 /* peer-group helpers for config-write */
15898
15899 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
15900 {
15901 if (!peer_group_active(peer)) {
15902 if (CHECK_FLAG(peer->flags_invert, flag))
15903 return !CHECK_FLAG(peer->flags, flag);
15904 else
15905 return !!CHECK_FLAG(peer->flags, flag);
15906 }
15907
15908 return !!CHECK_FLAG(peer->flags_override, flag);
15909 }
15910
15911 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
15912 uint32_t flag)
15913 {
15914 if (!peer_group_active(peer)) {
15915 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
15916 return !peer_af_flag_check(peer, afi, safi, flag);
15917 else
15918 return !!peer_af_flag_check(peer, afi, safi, flag);
15919 }
15920
15921 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
15922 }
15923
15924 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
15925 uint8_t type, int direct)
15926 {
15927 struct bgp_filter *filter;
15928
15929 if (peer_group_active(peer))
15930 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
15931 type);
15932
15933 filter = &peer->filter[afi][safi];
15934 switch (type) {
15935 case PEER_FT_DISTRIBUTE_LIST:
15936 return !!(filter->dlist[direct].name);
15937 case PEER_FT_FILTER_LIST:
15938 return !!(filter->aslist[direct].name);
15939 case PEER_FT_PREFIX_LIST:
15940 return !!(filter->plist[direct].name);
15941 case PEER_FT_ROUTE_MAP:
15942 return !!(filter->map[direct].name);
15943 case PEER_FT_UNSUPPRESS_MAP:
15944 return !!(filter->usmap.name);
15945 case PEER_FT_ADVERTISE_MAP:
15946 return !!(filter->advmap.aname
15947 && ((filter->advmap.condition == direct)
15948 && filter->advmap.cname));
15949 default:
15950 return false;
15951 }
15952 }
15953
15954 /* Return true if the addpath type is set for peer and different from
15955 * peer-group.
15956 */
15957 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15958 safi_t safi)
15959 {
15960 enum bgp_addpath_strat type, g_type;
15961
15962 type = peer->addpath_type[afi][safi];
15963
15964 if (type != BGP_ADDPATH_NONE) {
15965 if (peer_group_active(peer)) {
15966 g_type = peer->group->conf->addpath_type[afi][safi];
15967
15968 if (type != g_type)
15969 return true;
15970 else
15971 return false;
15972 }
15973
15974 return true;
15975 }
15976
15977 return false;
15978 }
15979
15980 /* This is part of the address-family block (unicast only) */
15981 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
15982 afi_t afi)
15983 {
15984 int indent = 2;
15985
15986 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
15987 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15988 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15989 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
15990 bgp->vpn_policy[afi]
15991 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15992 else
15993 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
15994 bgp->vpn_policy[afi]
15995 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15996 }
15997 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15998 BGP_CONFIG_VRF_TO_VRF_IMPORT)
15999 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16000 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16001 return;
16002
16003 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16004 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16005
16006 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16007
16008 } else {
16009 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16010 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16011 bgp->vpn_policy[afi].tovpn_label);
16012 }
16013 }
16014 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16015 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16016 char buf[RD_ADDRSTRLEN];
16017 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16018 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16019 sizeof(buf)));
16020 }
16021 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16022 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16023
16024 char buf[PREFIX_STRLEN];
16025 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16026 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16027 sizeof(buf))) {
16028
16029 vty_out(vty, "%*snexthop vpn export %s\n",
16030 indent, "", buf);
16031 }
16032 }
16033 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16034 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16035 && ecommunity_cmp(
16036 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16037 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16038
16039 char *b = ecommunity_ecom2str(
16040 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16041 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16042 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16043 XFREE(MTYPE_ECOMMUNITY_STR, b);
16044 } else {
16045 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16046 char *b = ecommunity_ecom2str(
16047 bgp->vpn_policy[afi]
16048 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16049 ECOMMUNITY_FORMAT_ROUTE_MAP,
16050 ECOMMUNITY_ROUTE_TARGET);
16051 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16052 XFREE(MTYPE_ECOMMUNITY_STR, b);
16053 }
16054 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16055 char *b = ecommunity_ecom2str(
16056 bgp->vpn_policy[afi]
16057 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16058 ECOMMUNITY_FORMAT_ROUTE_MAP,
16059 ECOMMUNITY_ROUTE_TARGET);
16060 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16061 XFREE(MTYPE_ECOMMUNITY_STR, b);
16062 }
16063 }
16064
16065 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16066 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16067 bgp->vpn_policy[afi]
16068 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16069
16070 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16071 char *b = ecommunity_ecom2str(
16072 bgp->vpn_policy[afi]
16073 .import_redirect_rtlist,
16074 ECOMMUNITY_FORMAT_ROUTE_MAP,
16075 ECOMMUNITY_ROUTE_TARGET);
16076
16077 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16078 != ECOMMUNITY_SIZE)
16079 vty_out(vty, "%*srt6 redirect import %s\n",
16080 indent, "", b);
16081 else
16082 vty_out(vty, "%*srt redirect import %s\n",
16083 indent, "", b);
16084 XFREE(MTYPE_ECOMMUNITY_STR, b);
16085 }
16086 }
16087
16088 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16089 afi_t afi, safi_t safi)
16090 {
16091 struct bgp_filter *filter;
16092 char *addr;
16093
16094 addr = peer->host;
16095 filter = &peer->filter[afi][safi];
16096
16097 /* distribute-list. */
16098 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16099 FILTER_IN))
16100 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16101 filter->dlist[FILTER_IN].name);
16102
16103 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16104 FILTER_OUT))
16105 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16106 filter->dlist[FILTER_OUT].name);
16107
16108 /* prefix-list. */
16109 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16110 FILTER_IN))
16111 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16112 filter->plist[FILTER_IN].name);
16113
16114 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16115 FILTER_OUT))
16116 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16117 filter->plist[FILTER_OUT].name);
16118
16119 /* route-map. */
16120 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16121 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16122 filter->map[RMAP_IN].name);
16123
16124 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16125 RMAP_OUT))
16126 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16127 filter->map[RMAP_OUT].name);
16128
16129 /* unsuppress-map */
16130 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16131 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16132 filter->usmap.name);
16133
16134 /* advertise-map : always applied in OUT direction*/
16135 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16136 CONDITION_NON_EXIST))
16137 vty_out(vty,
16138 " neighbor %s advertise-map %s non-exist-map %s\n",
16139 addr, filter->advmap.aname, filter->advmap.cname);
16140
16141 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16142 CONDITION_EXIST))
16143 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16144 addr, filter->advmap.aname, filter->advmap.cname);
16145
16146 /* filter-list. */
16147 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16148 FILTER_IN))
16149 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16150 filter->aslist[FILTER_IN].name);
16151
16152 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16153 FILTER_OUT))
16154 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16155 filter->aslist[FILTER_OUT].name);
16156 }
16157
16158 /* BGP peer configuration display function. */
16159 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16160 struct peer *peer)
16161 {
16162 struct peer *g_peer = NULL;
16163 char buf[SU_ADDRSTRLEN];
16164 char *addr;
16165 int if_pg_printed = false;
16166 int if_ras_printed = false;
16167
16168 /* Skip dynamic neighbors. */
16169 if (peer_dynamic_neighbor(peer))
16170 return;
16171
16172 if (peer->conf_if)
16173 addr = peer->conf_if;
16174 else
16175 addr = peer->host;
16176
16177 /************************************
16178 ****** Global to the neighbor ******
16179 ************************************/
16180 if (peer->conf_if) {
16181 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16182 vty_out(vty, " neighbor %s interface v6only", addr);
16183 else
16184 vty_out(vty, " neighbor %s interface", addr);
16185
16186 if (peer_group_active(peer)) {
16187 vty_out(vty, " peer-group %s", peer->group->name);
16188 if_pg_printed = true;
16189 } else if (peer->as_type == AS_SPECIFIED) {
16190 vty_out(vty, " remote-as %u", peer->as);
16191 if_ras_printed = true;
16192 } else if (peer->as_type == AS_INTERNAL) {
16193 vty_out(vty, " remote-as internal");
16194 if_ras_printed = true;
16195 } else if (peer->as_type == AS_EXTERNAL) {
16196 vty_out(vty, " remote-as external");
16197 if_ras_printed = true;
16198 }
16199
16200 vty_out(vty, "\n");
16201 }
16202
16203 /* remote-as and peer-group */
16204 /* peer is a member of a peer-group */
16205 if (peer_group_active(peer)) {
16206 g_peer = peer->group->conf;
16207
16208 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16209 if (peer->as_type == AS_SPECIFIED) {
16210 vty_out(vty, " neighbor %s remote-as %u\n",
16211 addr, peer->as);
16212 } else if (peer->as_type == AS_INTERNAL) {
16213 vty_out(vty,
16214 " neighbor %s remote-as internal\n",
16215 addr);
16216 } else if (peer->as_type == AS_EXTERNAL) {
16217 vty_out(vty,
16218 " neighbor %s remote-as external\n",
16219 addr);
16220 }
16221 }
16222
16223 /* For swpX peers we displayed the peer-group
16224 * via 'neighbor swpX interface peer-group PGNAME' */
16225 if (!if_pg_printed)
16226 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16227 peer->group->name);
16228 }
16229
16230 /* peer is NOT a member of a peer-group */
16231 else {
16232 /* peer is a peer-group, declare the peer-group */
16233 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16234 vty_out(vty, " neighbor %s peer-group\n", addr);
16235 }
16236
16237 if (!if_ras_printed) {
16238 if (peer->as_type == AS_SPECIFIED) {
16239 vty_out(vty, " neighbor %s remote-as %u\n",
16240 addr, peer->as);
16241 } else if (peer->as_type == AS_INTERNAL) {
16242 vty_out(vty,
16243 " neighbor %s remote-as internal\n",
16244 addr);
16245 } else if (peer->as_type == AS_EXTERNAL) {
16246 vty_out(vty,
16247 " neighbor %s remote-as external\n",
16248 addr);
16249 }
16250 }
16251 }
16252
16253 /* local-as */
16254 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16255 vty_out(vty, " neighbor %s local-as %u", addr,
16256 peer->change_local_as);
16257 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16258 vty_out(vty, " no-prepend");
16259 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16260 vty_out(vty, " replace-as");
16261 vty_out(vty, "\n");
16262 }
16263
16264 /* description */
16265 if (peer->desc) {
16266 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16267 }
16268
16269 /* shutdown */
16270 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16271 if (peer->tx_shutdown_message)
16272 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16273 peer->tx_shutdown_message);
16274 else
16275 vty_out(vty, " neighbor %s shutdown\n", addr);
16276 }
16277
16278 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16279 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16280 peer->rtt_expected, peer->rtt_keepalive_conf);
16281
16282 /* bfd */
16283 if (peer->bfd_config)
16284 bgp_bfd_peer_config_write(vty, peer, addr);
16285
16286 /* password */
16287 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16288 vty_out(vty, " neighbor %s password %s\n", addr,
16289 peer->password);
16290
16291 /* neighbor solo */
16292 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16293 if (!peer_group_active(peer)) {
16294 vty_out(vty, " neighbor %s solo\n", addr);
16295 }
16296 }
16297
16298 /* BGP port */
16299 if (peer->port != BGP_PORT_DEFAULT) {
16300 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16301 }
16302
16303 /* Local interface name */
16304 if (peer->ifname) {
16305 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16306 }
16307
16308 /* TCP max segment size */
16309 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16310 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16311
16312 /* passive */
16313 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16314 vty_out(vty, " neighbor %s passive\n", addr);
16315
16316 /* ebgp-multihop */
16317 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16318 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16319 && peer->ttl == MAXTTL)) {
16320 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16321 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16322 peer->ttl);
16323 }
16324 }
16325
16326 /* ttl-security hops */
16327 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16328 if (!peer_group_active(peer)
16329 || g_peer->gtsm_hops != peer->gtsm_hops) {
16330 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16331 addr, peer->gtsm_hops);
16332 }
16333 }
16334
16335 /* disable-connected-check */
16336 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16337 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16338
16339 /* enforce-first-as */
16340 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16341 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16342
16343 /* update-source */
16344 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16345 if (peer->update_source)
16346 vty_out(vty, " neighbor %s update-source %s\n", addr,
16347 sockunion2str(peer->update_source, buf,
16348 SU_ADDRSTRLEN));
16349 else if (peer->update_if)
16350 vty_out(vty, " neighbor %s update-source %s\n", addr,
16351 peer->update_if);
16352 }
16353
16354 /* advertisement-interval */
16355 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16356 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16357 peer->routeadv);
16358
16359 /* timers */
16360 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16361 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16362 peer->keepalive, peer->holdtime);
16363
16364 /* timers connect */
16365 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16366 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16367 peer->connect);
16368 /* need special-case handling for changed default values due to
16369 * config profile / version (because there is no "timers bgp connect"
16370 * command, we need to save this per-peer :/)
16371 */
16372 else if (!peer_group_active(peer) && !peer->connect &&
16373 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16374 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16375 peer->bgp->default_connect_retry);
16376
16377 /* timers delayopen */
16378 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16379 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16380 peer->delayopen);
16381 /* Save config even though flag is not set if default values have been
16382 * changed
16383 */
16384 else if (!peer_group_active(peer) && !peer->delayopen
16385 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16386 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16387 peer->bgp->default_delayopen);
16388
16389 /* capability dynamic */
16390 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16391 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16392
16393 /* capability extended-nexthop */
16394 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16395 if (!peer->conf_if) {
16396 if (CHECK_FLAG(peer->flags_invert,
16397 PEER_FLAG_CAPABILITY_ENHE))
16398 vty_out(vty,
16399 " no neighbor %s capability extended-nexthop\n",
16400 addr);
16401 else
16402 vty_out(vty,
16403 " neighbor %s capability extended-nexthop\n",
16404 addr);
16405 }
16406 }
16407
16408 /* dont-capability-negotiation */
16409 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16410 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16411
16412 /* override-capability */
16413 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16414 vty_out(vty, " neighbor %s override-capability\n", addr);
16415
16416 /* strict-capability-match */
16417 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16418 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16419
16420 /* Sender side AS path loop detection. */
16421 if (peer->as_path_loop_detection)
16422 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16423 addr);
16424
16425 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16426 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16427
16428 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16429 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16430 vty_out(vty,
16431 " neighbor %s graceful-restart-helper\n", addr);
16432 } else if (CHECK_FLAG(
16433 peer->peer_gr_new_status_flag,
16434 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16435 vty_out(vty,
16436 " neighbor %s graceful-restart\n", addr);
16437 } else if (
16438 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16439 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16440 && !(CHECK_FLAG(
16441 peer->peer_gr_new_status_flag,
16442 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16443 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16444 addr);
16445 }
16446 }
16447 }
16448
16449 /* BGP peer configuration display function. */
16450 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16451 struct peer *peer, afi_t afi, safi_t safi)
16452 {
16453 struct peer *g_peer = NULL;
16454 char *addr;
16455 bool flag_scomm, flag_secomm, flag_slcomm;
16456
16457 /* Skip dynamic neighbors. */
16458 if (peer_dynamic_neighbor(peer))
16459 return;
16460
16461 if (peer->conf_if)
16462 addr = peer->conf_if;
16463 else
16464 addr = peer->host;
16465
16466 /************************************
16467 ****** Per AF to the neighbor ******
16468 ************************************/
16469 if (peer_group_active(peer)) {
16470 g_peer = peer->group->conf;
16471
16472 /* If the peer-group is active but peer is not, print a 'no
16473 * activate' */
16474 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16475 vty_out(vty, " no neighbor %s activate\n", addr);
16476 }
16477
16478 /* If the peer-group is not active but peer is, print an
16479 'activate' */
16480 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16481 vty_out(vty, " neighbor %s activate\n", addr);
16482 }
16483 } else {
16484 if (peer->afc[afi][safi]) {
16485 if (safi == SAFI_ENCAP)
16486 vty_out(vty, " neighbor %s activate\n", addr);
16487 else if (!bgp->default_af[afi][safi])
16488 vty_out(vty, " neighbor %s activate\n", addr);
16489 } else {
16490 if (bgp->default_af[afi][safi])
16491 vty_out(vty, " no neighbor %s activate\n",
16492 addr);
16493 }
16494 }
16495
16496 /* addpath TX knobs */
16497 if (peergroup_af_addpath_check(peer, afi, safi)) {
16498 switch (peer->addpath_type[afi][safi]) {
16499 case BGP_ADDPATH_ALL:
16500 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16501 addr);
16502 break;
16503 case BGP_ADDPATH_BEST_PER_AS:
16504 vty_out(vty,
16505 " neighbor %s addpath-tx-bestpath-per-AS\n",
16506 addr);
16507 break;
16508 case BGP_ADDPATH_MAX:
16509 case BGP_ADDPATH_NONE:
16510 break;
16511 }
16512 }
16513
16514 /* ORF capability. */
16515 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16516 || peergroup_af_flag_check(peer, afi, safi,
16517 PEER_FLAG_ORF_PREFIX_RM)) {
16518 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16519
16520 if (peergroup_af_flag_check(peer, afi, safi,
16521 PEER_FLAG_ORF_PREFIX_SM)
16522 && peergroup_af_flag_check(peer, afi, safi,
16523 PEER_FLAG_ORF_PREFIX_RM))
16524 vty_out(vty, " both");
16525 else if (peergroup_af_flag_check(peer, afi, safi,
16526 PEER_FLAG_ORF_PREFIX_SM))
16527 vty_out(vty, " send");
16528 else
16529 vty_out(vty, " receive");
16530 vty_out(vty, "\n");
16531 }
16532
16533 /* Route reflector client. */
16534 if (peergroup_af_flag_check(peer, afi, safi,
16535 PEER_FLAG_REFLECTOR_CLIENT)) {
16536 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16537 }
16538
16539 /* next-hop-self force */
16540 if (peergroup_af_flag_check(peer, afi, safi,
16541 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16542 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16543 }
16544
16545 /* next-hop-self */
16546 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16547 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16548 }
16549
16550 /* remove-private-AS */
16551 if (peergroup_af_flag_check(peer, afi, safi,
16552 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16553 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16554 addr);
16555 }
16556
16557 else if (peergroup_af_flag_check(peer, afi, safi,
16558 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16559 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16560 addr);
16561 }
16562
16563 else if (peergroup_af_flag_check(peer, afi, safi,
16564 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16565 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16566 }
16567
16568 else if (peergroup_af_flag_check(peer, afi, safi,
16569 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16570 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16571 }
16572
16573 /* as-override */
16574 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16575 vty_out(vty, " neighbor %s as-override\n", addr);
16576 }
16577
16578 /* send-community print. */
16579 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16580 PEER_FLAG_SEND_COMMUNITY);
16581 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16582 PEER_FLAG_SEND_EXT_COMMUNITY);
16583 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16584 PEER_FLAG_SEND_LARGE_COMMUNITY);
16585
16586 if (flag_scomm && flag_secomm && flag_slcomm) {
16587 vty_out(vty, " no neighbor %s send-community all\n", addr);
16588 } else {
16589 if (flag_scomm)
16590 vty_out(vty, " no neighbor %s send-community\n", addr);
16591 if (flag_secomm)
16592 vty_out(vty,
16593 " no neighbor %s send-community extended\n",
16594 addr);
16595
16596 if (flag_slcomm)
16597 vty_out(vty, " no neighbor %s send-community large\n",
16598 addr);
16599 }
16600
16601 /* Default information */
16602 if (peergroup_af_flag_check(peer, afi, safi,
16603 PEER_FLAG_DEFAULT_ORIGINATE)) {
16604 vty_out(vty, " neighbor %s default-originate", addr);
16605
16606 if (peer->default_rmap[afi][safi].name)
16607 vty_out(vty, " route-map %s",
16608 peer->default_rmap[afi][safi].name);
16609
16610 vty_out(vty, "\n");
16611 }
16612
16613 /* Soft reconfiguration inbound. */
16614 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16615 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16616 addr);
16617 }
16618
16619 /* maximum-prefix. */
16620 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16621 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16622 peer->pmax[afi][safi]);
16623
16624 if (peer->pmax_threshold[afi][safi]
16625 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16626 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16627 if (peer_af_flag_check(peer, afi, safi,
16628 PEER_FLAG_MAX_PREFIX_WARNING))
16629 vty_out(vty, " warning-only");
16630 if (peer->pmax_restart[afi][safi])
16631 vty_out(vty, " restart %u",
16632 peer->pmax_restart[afi][safi]);
16633 if (peer_af_flag_check(peer, afi, safi,
16634 PEER_FLAG_MAX_PREFIX_FORCE))
16635 vty_out(vty, " force");
16636
16637 vty_out(vty, "\n");
16638 }
16639
16640 /* maximum-prefix-out */
16641 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16642 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16643 addr, peer->pmax_out[afi][safi]);
16644
16645 /* Route server client. */
16646 if (peergroup_af_flag_check(peer, afi, safi,
16647 PEER_FLAG_RSERVER_CLIENT)) {
16648 vty_out(vty, " neighbor %s route-server-client\n", addr);
16649 }
16650
16651 /* Nexthop-local unchanged. */
16652 if (peergroup_af_flag_check(peer, afi, safi,
16653 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16654 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16655 }
16656
16657 /* allowas-in <1-10> */
16658 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16659 if (peer_af_flag_check(peer, afi, safi,
16660 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16661 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16662 } else if (peer->allowas_in[afi][safi] == 3) {
16663 vty_out(vty, " neighbor %s allowas-in\n", addr);
16664 } else {
16665 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16666 peer->allowas_in[afi][safi]);
16667 }
16668 }
16669
16670 /* weight */
16671 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16672 vty_out(vty, " neighbor %s weight %lu\n", addr,
16673 peer->weight[afi][safi]);
16674
16675 /* Filter. */
16676 bgp_config_write_filter(vty, peer, afi, safi);
16677
16678 /* atribute-unchanged. */
16679 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16680 || (safi != SAFI_EVPN
16681 && peer_af_flag_check(peer, afi, safi,
16682 PEER_FLAG_NEXTHOP_UNCHANGED))
16683 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16684
16685 if (!peer_group_active(peer)
16686 || peergroup_af_flag_check(peer, afi, safi,
16687 PEER_FLAG_AS_PATH_UNCHANGED)
16688 || peergroup_af_flag_check(peer, afi, safi,
16689 PEER_FLAG_NEXTHOP_UNCHANGED)
16690 || peergroup_af_flag_check(peer, afi, safi,
16691 PEER_FLAG_MED_UNCHANGED)) {
16692
16693 vty_out(vty,
16694 " neighbor %s attribute-unchanged%s%s%s\n",
16695 addr,
16696 peer_af_flag_check(peer, afi, safi,
16697 PEER_FLAG_AS_PATH_UNCHANGED)
16698 ? " as-path"
16699 : "",
16700 peer_af_flag_check(peer, afi, safi,
16701 PEER_FLAG_NEXTHOP_UNCHANGED)
16702 ? " next-hop"
16703 : "",
16704 peer_af_flag_check(peer, afi, safi,
16705 PEER_FLAG_MED_UNCHANGED)
16706 ? " med"
16707 : "");
16708 }
16709 }
16710 }
16711
16712 /* Address family based peer configuration display. */
16713 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16714 safi_t safi)
16715 {
16716 struct peer *peer;
16717 struct peer_group *group;
16718 struct listnode *node, *nnode;
16719
16720
16721 vty_frame(vty, " !\n address-family ");
16722 if (afi == AFI_IP) {
16723 if (safi == SAFI_UNICAST)
16724 vty_frame(vty, "ipv4 unicast");
16725 else if (safi == SAFI_LABELED_UNICAST)
16726 vty_frame(vty, "ipv4 labeled-unicast");
16727 else if (safi == SAFI_MULTICAST)
16728 vty_frame(vty, "ipv4 multicast");
16729 else if (safi == SAFI_MPLS_VPN)
16730 vty_frame(vty, "ipv4 vpn");
16731 else if (safi == SAFI_ENCAP)
16732 vty_frame(vty, "ipv4 encap");
16733 else if (safi == SAFI_FLOWSPEC)
16734 vty_frame(vty, "ipv4 flowspec");
16735 } else if (afi == AFI_IP6) {
16736 if (safi == SAFI_UNICAST)
16737 vty_frame(vty, "ipv6 unicast");
16738 else if (safi == SAFI_LABELED_UNICAST)
16739 vty_frame(vty, "ipv6 labeled-unicast");
16740 else if (safi == SAFI_MULTICAST)
16741 vty_frame(vty, "ipv6 multicast");
16742 else if (safi == SAFI_MPLS_VPN)
16743 vty_frame(vty, "ipv6 vpn");
16744 else if (safi == SAFI_ENCAP)
16745 vty_frame(vty, "ipv6 encap");
16746 else if (safi == SAFI_FLOWSPEC)
16747 vty_frame(vty, "ipv6 flowspec");
16748 } else if (afi == AFI_L2VPN) {
16749 if (safi == SAFI_EVPN)
16750 vty_frame(vty, "l2vpn evpn");
16751 }
16752 vty_frame(vty, "\n");
16753
16754 bgp_config_write_distance(vty, bgp, afi, safi);
16755
16756 bgp_config_write_network(vty, bgp, afi, safi);
16757
16758 bgp_config_write_redistribute(vty, bgp, afi, safi);
16759
16760 /* BGP flag dampening. */
16761 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16762 bgp_config_write_damp(vty, afi, safi);
16763
16764 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16765 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16766
16767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16768 /* Do not display doppelganger peers */
16769 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16770 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16771 }
16772
16773 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16774 bgp_config_write_table_map(vty, bgp, afi, safi);
16775
16776 if (safi == SAFI_EVPN)
16777 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16778
16779 if (safi == SAFI_FLOWSPEC)
16780 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16781
16782 if (safi == SAFI_UNICAST) {
16783 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16784 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16785 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16786
16787 vty_out(vty, " export vpn\n");
16788 }
16789 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16790 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16791
16792 vty_out(vty, " import vpn\n");
16793 }
16794 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16795 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16796 char *name;
16797
16798 for (ALL_LIST_ELEMENTS_RO(
16799 bgp->vpn_policy[afi].import_vrf, node,
16800 name))
16801 vty_out(vty, " import vrf %s\n", name);
16802 }
16803 }
16804
16805 vty_endframe(vty, " exit-address-family\n");
16806 }
16807
16808 int bgp_config_write(struct vty *vty)
16809 {
16810 struct bgp *bgp;
16811 struct peer_group *group;
16812 struct peer *peer;
16813 struct listnode *node, *nnode;
16814 struct listnode *mnode, *mnnode;
16815 afi_t afi;
16816 safi_t safi;
16817
16818 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16819 vty_out(vty, "bgp route-map delay-timer %u\n",
16820 bm->rmap_update_timer);
16821
16822 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16823 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16824 if (bm->v_update_delay != bm->v_establish_wait)
16825 vty_out(vty, " %d", bm->v_establish_wait);
16826 vty_out(vty, "\n");
16827 }
16828
16829 if (bm->wait_for_fib)
16830 vty_out(vty, "bgp suppress-fib-pending\n");
16831
16832 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16833 vty_out(vty, "bgp graceful-shutdown\n");
16834
16835 /* No-RIB (Zebra) option flag configuration */
16836 if (bgp_option_check(BGP_OPT_NO_FIB))
16837 vty_out(vty, "bgp no-rib\n");
16838
16839 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
16840 vty_out(vty, "no bgp send-extra-data zebra\n");
16841
16842 /* BGP configuration. */
16843 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16844
16845 /* skip all auto created vrf as they dont have user config */
16846 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
16847 continue;
16848
16849 /* Router bgp ASN */
16850 vty_out(vty, "router bgp %u", bgp->as);
16851
16852 if (bgp->name)
16853 vty_out(vty, " %s %s",
16854 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
16855 ? "view" : "vrf", bgp->name);
16856 vty_out(vty, "\n");
16857
16858 /* BGP fast-external-failover. */
16859 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
16860 vty_out(vty, " no bgp fast-external-failover\n");
16861
16862 /* BGP router ID. */
16863 if (bgp->router_id_static.s_addr != INADDR_ANY)
16864 vty_out(vty, " bgp router-id %pI4\n",
16865 &bgp->router_id_static);
16866
16867 /* Suppress fib pending */
16868 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
16869 vty_out(vty, " bgp suppress-fib-pending\n");
16870
16871 /* BGP log-neighbor-changes. */
16872 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
16873 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
16874 vty_out(vty, " %sbgp log-neighbor-changes\n",
16875 CHECK_FLAG(bgp->flags,
16876 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
16877 ? ""
16878 : "no ");
16879
16880 /* BGP configuration. */
16881 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
16882 vty_out(vty, " bgp always-compare-med\n");
16883
16884 /* RFC8212 default eBGP policy. */
16885 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
16886 != SAVE_BGP_EBGP_REQUIRES_POLICY)
16887 vty_out(vty, " %sbgp ebgp-requires-policy\n",
16888 CHECK_FLAG(bgp->flags,
16889 BGP_FLAG_EBGP_REQUIRES_POLICY)
16890 ? ""
16891 : "no ");
16892
16893 /* draft-ietf-idr-deprecate-as-set-confed-set */
16894 if (bgp->reject_as_sets)
16895 vty_out(vty, " bgp reject-as-sets\n");
16896
16897 /* Suppress duplicate updates if the route actually not changed
16898 */
16899 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
16900 != SAVE_BGP_SUPPRESS_DUPLICATES)
16901 vty_out(vty, " %sbgp suppress-duplicates\n",
16902 CHECK_FLAG(bgp->flags,
16903 BGP_FLAG_SUPPRESS_DUPLICATES)
16904 ? ""
16905 : "no ");
16906
16907 /* BGP default <afi>-<safi> */
16908 FOREACH_AFI_SAFI (afi, safi) {
16909 if (afi == AFI_IP && safi == SAFI_UNICAST) {
16910 if (!bgp->default_af[afi][safi])
16911 vty_out(vty, " no bgp default %s\n",
16912 get_bgp_default_af_flag(afi,
16913 safi));
16914 } else if (bgp->default_af[afi][safi])
16915 vty_out(vty, " bgp default %s\n",
16916 get_bgp_default_af_flag(afi, safi));
16917 }
16918
16919 /* BGP default local-preference. */
16920 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
16921 vty_out(vty, " bgp default local-preference %u\n",
16922 bgp->default_local_pref);
16923
16924 /* BGP default show-hostname */
16925 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
16926 != SAVE_BGP_SHOW_HOSTNAME)
16927 vty_out(vty, " %sbgp default show-hostname\n",
16928 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
16929 ? ""
16930 : "no ");
16931
16932 /* BGP default show-nexthop-hostname */
16933 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16934 != SAVE_BGP_SHOW_HOSTNAME)
16935 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
16936 CHECK_FLAG(bgp->flags,
16937 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16938 ? ""
16939 : "no ");
16940
16941 /* BGP default subgroup-pkt-queue-max. */
16942 if (bgp->default_subgroup_pkt_queue_max
16943 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
16944 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
16945 bgp->default_subgroup_pkt_queue_max);
16946
16947 /* BGP client-to-client reflection. */
16948 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
16949 vty_out(vty, " no bgp client-to-client reflection\n");
16950
16951 /* BGP cluster ID. */
16952 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
16953 vty_out(vty, " bgp cluster-id %pI4\n",
16954 &bgp->cluster_id);
16955
16956 /* Disable ebgp connected nexthop check */
16957 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
16958 vty_out(vty,
16959 " bgp disable-ebgp-connected-route-check\n");
16960
16961 /* Confederation identifier*/
16962 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
16963 vty_out(vty, " bgp confederation identifier %u\n",
16964 bgp->confed_id);
16965
16966 /* Confederation peer */
16967 if (bgp->confed_peers_cnt > 0) {
16968 int i;
16969
16970 vty_out(vty, " bgp confederation peers");
16971
16972 for (i = 0; i < bgp->confed_peers_cnt; i++)
16973 vty_out(vty, " %u", bgp->confed_peers[i]);
16974
16975 vty_out(vty, "\n");
16976 }
16977
16978 /* BGP deterministic-med. */
16979 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
16980 != SAVE_BGP_DETERMINISTIC_MED)
16981 vty_out(vty, " %sbgp deterministic-med\n",
16982 CHECK_FLAG(bgp->flags,
16983 BGP_FLAG_DETERMINISTIC_MED)
16984 ? ""
16985 : "no ");
16986
16987 /* BGP update-delay. */
16988 bgp_config_write_update_delay(vty, bgp);
16989
16990 if (bgp->v_maxmed_onstartup
16991 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
16992 vty_out(vty, " bgp max-med on-startup %u",
16993 bgp->v_maxmed_onstartup);
16994 if (bgp->maxmed_onstartup_value
16995 != BGP_MAXMED_VALUE_DEFAULT)
16996 vty_out(vty, " %u",
16997 bgp->maxmed_onstartup_value);
16998 vty_out(vty, "\n");
16999 }
17000 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17001 vty_out(vty, " bgp max-med administrative");
17002 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17003 vty_out(vty, " %u", bgp->maxmed_admin_value);
17004 vty_out(vty, "\n");
17005 }
17006
17007 /* write quanta */
17008 bgp_config_write_wpkt_quanta(vty, bgp);
17009 /* read quanta */
17010 bgp_config_write_rpkt_quanta(vty, bgp);
17011
17012 /* coalesce time */
17013 bgp_config_write_coalesce_time(vty, bgp);
17014
17015 /* BGP per-instance graceful-shutdown */
17016 /* BGP-wide settings and per-instance settings are mutually
17017 * exclusive.
17018 */
17019 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17020 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17021 vty_out(vty, " bgp graceful-shutdown\n");
17022
17023 /* BGP graceful-restart. */
17024 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17025 vty_out(vty,
17026 " bgp graceful-restart stalepath-time %u\n",
17027 bgp->stalepath_time);
17028
17029 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17030 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17031 bgp->restart_time);
17032
17033 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17034 vty_out(vty,
17035 " bgp graceful-restart select-defer-time %u\n",
17036 bgp->select_defer_time);
17037
17038 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17039 vty_out(vty, " bgp graceful-restart\n");
17040
17041 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17042 vty_out(vty, " bgp graceful-restart-disable\n");
17043
17044 /* BGP graceful-restart Preserve State F bit. */
17045 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17046 vty_out(vty,
17047 " bgp graceful-restart preserve-fw-state\n");
17048
17049 /* Stale timer for RIB */
17050 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17051 vty_out(vty,
17052 " bgp graceful-restart rib-stale-time %u\n",
17053 bgp->rib_stale_time);
17054
17055 /* BGP bestpath method. */
17056 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17057 vty_out(vty, " bgp bestpath as-path ignore\n");
17058 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17059 vty_out(vty, " bgp bestpath as-path confed\n");
17060
17061 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17062 if (CHECK_FLAG(bgp->flags,
17063 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17064 vty_out(vty,
17065 " bgp bestpath as-path multipath-relax as-set\n");
17066 } else {
17067 vty_out(vty,
17068 " bgp bestpath as-path multipath-relax\n");
17069 }
17070 }
17071
17072 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17073 vty_out(vty,
17074 " bgp route-reflector allow-outbound-policy\n");
17075 }
17076 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17077 vty_out(vty, " bgp bestpath compare-routerid\n");
17078 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17079 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17080 vty_out(vty, " bgp bestpath med");
17081 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17082 vty_out(vty, " confed");
17083 if (CHECK_FLAG(bgp->flags,
17084 BGP_FLAG_MED_MISSING_AS_WORST))
17085 vty_out(vty, " missing-as-worst");
17086 vty_out(vty, "\n");
17087 }
17088
17089 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17090 vty_out(vty,
17091 " bgp bestpath peer-type multipath-relax\n");
17092
17093 /* Link bandwidth handling. */
17094 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17095 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17096 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17097 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17098 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17099 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17100
17101 /* BGP network import check. */
17102 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17103 != SAVE_BGP_IMPORT_CHECK)
17104 vty_out(vty, " %sbgp network import-check\n",
17105 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17106 ? ""
17107 : "no ");
17108
17109 /* BGP timers configuration. */
17110 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17111 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17112 vty_out(vty, " timers bgp %u %u\n",
17113 bgp->default_keepalive, bgp->default_holdtime);
17114
17115 /* Conditional advertisement timer configuration */
17116 if (bgp->condition_check_period
17117 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17118 vty_out(vty,
17119 " bgp conditional-advertisement timer %u\n",
17120 bgp->condition_check_period);
17121
17122 /* peer-group */
17123 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17124 bgp_config_write_peer_global(vty, bgp, group->conf);
17125 }
17126
17127 /* Normal neighbor configuration. */
17128 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17129 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17130 bgp_config_write_peer_global(vty, bgp, peer);
17131 }
17132
17133 /* listen range and limit for dynamic BGP neighbors */
17134 bgp_config_write_listen(vty, bgp);
17135
17136 /*
17137 * BGP default autoshutdown neighbors
17138 *
17139 * This must be placed after any peer and peer-group
17140 * configuration, to avoid setting all peers to shutdown after
17141 * a daemon restart, which is undesired behavior. (see #2286)
17142 */
17143 if (bgp->autoshutdown)
17144 vty_out(vty, " bgp default shutdown\n");
17145
17146 /* BGP instance administrative shutdown */
17147 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17148 vty_out(vty, " bgp shutdown\n");
17149
17150 if (bgp->srv6_enabled) {
17151 vty_frame(vty, " !\n segment-routing srv6\n");
17152 if (strlen(bgp->srv6_locator_name))
17153 vty_out(vty, " locator %s\n",
17154 bgp->srv6_locator_name);
17155 }
17156
17157
17158 /* IPv4 unicast configuration. */
17159 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17160
17161 /* IPv4 multicast configuration. */
17162 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17163
17164 /* IPv4 labeled-unicast configuration. */
17165 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17166
17167 /* IPv4 VPN configuration. */
17168 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17169
17170 /* ENCAPv4 configuration. */
17171 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17172
17173 /* FLOWSPEC v4 configuration. */
17174 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17175
17176 /* IPv6 unicast configuration. */
17177 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17178
17179 /* IPv6 multicast configuration. */
17180 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17181
17182 /* IPv6 labeled-unicast configuration. */
17183 bgp_config_write_family(vty, bgp, AFI_IP6,
17184 SAFI_LABELED_UNICAST);
17185
17186 /* IPv6 VPN configuration. */
17187 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17188
17189 /* ENCAPv6 configuration. */
17190 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17191
17192 /* FLOWSPEC v6 configuration. */
17193 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17194
17195 /* EVPN configuration. */
17196 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17197
17198 hook_call(bgp_inst_config_write, bgp, vty);
17199
17200 #ifdef ENABLE_BGP_VNC
17201 bgp_rfapi_cfg_write(vty, bgp);
17202 #endif
17203
17204 vty_out(vty, "!\n");
17205 }
17206 return 0;
17207 }
17208
17209
17210 /* BGP node structure. */
17211 static struct cmd_node bgp_node = {
17212 .name = "bgp",
17213 .node = BGP_NODE,
17214 .parent_node = CONFIG_NODE,
17215 .prompt = "%s(config-router)# ",
17216 .config_write = bgp_config_write,
17217 };
17218
17219 static struct cmd_node bgp_ipv4_unicast_node = {
17220 .name = "bgp ipv4 unicast",
17221 .node = BGP_IPV4_NODE,
17222 .parent_node = BGP_NODE,
17223 .prompt = "%s(config-router-af)# ",
17224 };
17225
17226 static struct cmd_node bgp_ipv4_multicast_node = {
17227 .name = "bgp ipv4 multicast",
17228 .node = BGP_IPV4M_NODE,
17229 .parent_node = BGP_NODE,
17230 .prompt = "%s(config-router-af)# ",
17231 };
17232
17233 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17234 .name = "bgp ipv4 labeled unicast",
17235 .node = BGP_IPV4L_NODE,
17236 .parent_node = BGP_NODE,
17237 .prompt = "%s(config-router-af)# ",
17238 };
17239
17240 static struct cmd_node bgp_ipv6_unicast_node = {
17241 .name = "bgp ipv6 unicast",
17242 .node = BGP_IPV6_NODE,
17243 .parent_node = BGP_NODE,
17244 .prompt = "%s(config-router-af)# ",
17245 };
17246
17247 static struct cmd_node bgp_ipv6_multicast_node = {
17248 .name = "bgp ipv6 multicast",
17249 .node = BGP_IPV6M_NODE,
17250 .parent_node = BGP_NODE,
17251 .prompt = "%s(config-router-af)# ",
17252 };
17253
17254 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17255 .name = "bgp ipv6 labeled unicast",
17256 .node = BGP_IPV6L_NODE,
17257 .parent_node = BGP_NODE,
17258 .prompt = "%s(config-router-af)# ",
17259 };
17260
17261 static struct cmd_node bgp_vpnv4_node = {
17262 .name = "bgp vpnv4",
17263 .node = BGP_VPNV4_NODE,
17264 .parent_node = BGP_NODE,
17265 .prompt = "%s(config-router-af)# ",
17266 };
17267
17268 static struct cmd_node bgp_vpnv6_node = {
17269 .name = "bgp vpnv6",
17270 .node = BGP_VPNV6_NODE,
17271 .parent_node = BGP_NODE,
17272 .prompt = "%s(config-router-af-vpnv6)# ",
17273 };
17274
17275 static struct cmd_node bgp_evpn_node = {
17276 .name = "bgp evpn",
17277 .node = BGP_EVPN_NODE,
17278 .parent_node = BGP_NODE,
17279 .prompt = "%s(config-router-evpn)# ",
17280 };
17281
17282 static struct cmd_node bgp_evpn_vni_node = {
17283 .name = "bgp evpn vni",
17284 .node = BGP_EVPN_VNI_NODE,
17285 .parent_node = BGP_EVPN_NODE,
17286 .prompt = "%s(config-router-af-vni)# ",
17287 };
17288
17289 static struct cmd_node bgp_flowspecv4_node = {
17290 .name = "bgp ipv4 flowspec",
17291 .node = BGP_FLOWSPECV4_NODE,
17292 .parent_node = BGP_NODE,
17293 .prompt = "%s(config-router-af)# ",
17294 };
17295
17296 static struct cmd_node bgp_flowspecv6_node = {
17297 .name = "bgp ipv6 flowspec",
17298 .node = BGP_FLOWSPECV6_NODE,
17299 .parent_node = BGP_NODE,
17300 .prompt = "%s(config-router-af-vpnv6)# ",
17301 };
17302
17303 static struct cmd_node bgp_srv6_node = {
17304 .name = "bgp srv6",
17305 .node = BGP_SRV6_NODE,
17306 .parent_node = BGP_NODE,
17307 .prompt = "%s(config-router-srv6)# ",
17308 };
17309
17310 static void community_list_vty(void);
17311
17312 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17313 {
17314 struct bgp *bgp;
17315 struct peer *peer;
17316 struct listnode *lnbgp, *lnpeer;
17317
17318 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17319 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17320 /* only provide suggestions on the appropriate input
17321 * token type,
17322 * they'll otherwise show up multiple times */
17323 enum cmd_token_type match_type;
17324 char *name = peer->host;
17325
17326 if (peer->conf_if) {
17327 match_type = VARIABLE_TKN;
17328 name = peer->conf_if;
17329 } else if (strchr(peer->host, ':'))
17330 match_type = IPV6_TKN;
17331 else
17332 match_type = IPV4_TKN;
17333
17334 if (token->type != match_type)
17335 continue;
17336
17337 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17338 }
17339 }
17340 }
17341
17342 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17343 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17344 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17345 {.varname = "peer", .completions = bgp_ac_neighbor},
17346 {.completions = NULL}};
17347
17348 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17349 {
17350 struct bgp *bgp;
17351 struct peer_group *group;
17352 struct listnode *lnbgp, *lnpeer;
17353
17354 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17355 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17356 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17357 group->name));
17358 }
17359 }
17360
17361 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17362 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17363 {.completions = NULL} };
17364
17365 void bgp_vty_init(void)
17366 {
17367 cmd_variable_handler_register(bgp_var_neighbor);
17368 cmd_variable_handler_register(bgp_var_peergroup);
17369
17370 /* Install bgp top node. */
17371 install_node(&bgp_node);
17372 install_node(&bgp_ipv4_unicast_node);
17373 install_node(&bgp_ipv4_multicast_node);
17374 install_node(&bgp_ipv4_labeled_unicast_node);
17375 install_node(&bgp_ipv6_unicast_node);
17376 install_node(&bgp_ipv6_multicast_node);
17377 install_node(&bgp_ipv6_labeled_unicast_node);
17378 install_node(&bgp_vpnv4_node);
17379 install_node(&bgp_vpnv6_node);
17380 install_node(&bgp_evpn_node);
17381 install_node(&bgp_evpn_vni_node);
17382 install_node(&bgp_flowspecv4_node);
17383 install_node(&bgp_flowspecv6_node);
17384 install_node(&bgp_srv6_node);
17385
17386 /* Install default VTY commands to new nodes. */
17387 install_default(BGP_NODE);
17388 install_default(BGP_IPV4_NODE);
17389 install_default(BGP_IPV4M_NODE);
17390 install_default(BGP_IPV4L_NODE);
17391 install_default(BGP_IPV6_NODE);
17392 install_default(BGP_IPV6M_NODE);
17393 install_default(BGP_IPV6L_NODE);
17394 install_default(BGP_VPNV4_NODE);
17395 install_default(BGP_VPNV6_NODE);
17396 install_default(BGP_FLOWSPECV4_NODE);
17397 install_default(BGP_FLOWSPECV6_NODE);
17398 install_default(BGP_EVPN_NODE);
17399 install_default(BGP_EVPN_VNI_NODE);
17400 install_default(BGP_SRV6_NODE);
17401
17402 /* "bgp local-mac" hidden commands. */
17403 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17404 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17405
17406 /* "bgp suppress-fib-pending" global */
17407 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17408
17409 /* bgp route-map delay-timer commands. */
17410 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17411 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17412
17413 /* global bgp update-delay command */
17414 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17415 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17416
17417 /* global bgp graceful-shutdown command */
17418 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17419 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17420
17421 /* Dummy commands (Currently not supported) */
17422 install_element(BGP_NODE, &no_synchronization_cmd);
17423 install_element(BGP_NODE, &no_auto_summary_cmd);
17424
17425 /* "router bgp" commands. */
17426 install_element(CONFIG_NODE, &router_bgp_cmd);
17427
17428 /* "no router bgp" commands. */
17429 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17430
17431 /* "bgp router-id" commands. */
17432 install_element(BGP_NODE, &bgp_router_id_cmd);
17433 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17434
17435 /* "bgp suppress-fib-pending" command */
17436 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17437
17438 /* "bgp cluster-id" commands. */
17439 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17440 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17441
17442 /* "bgp no-rib" commands. */
17443 install_element(CONFIG_NODE, &bgp_norib_cmd);
17444 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17445
17446 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17447
17448 /* "bgp confederation" commands. */
17449 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17450 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17451
17452 /* "bgp confederation peers" commands. */
17453 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17454 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17455
17456 /* bgp max-med command */
17457 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17458 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17459 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17460 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17461 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17462
17463 /* bgp disable-ebgp-connected-nh-check */
17464 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17465 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17466
17467 /* bgp update-delay command */
17468 install_element(BGP_NODE, &bgp_update_delay_cmd);
17469 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17470
17471 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17472 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17473
17474 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17475 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17476
17477 /* "maximum-paths" commands. */
17478 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17479 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17480 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17481 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17482 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17483 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17484 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17485 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17486 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17487 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17488 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17489 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17490 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17491 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17492 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17493
17494 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17495 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17496 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17497 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17498 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17499 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17500 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17501 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17502 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17503 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17504
17505 /* "timers bgp" commands. */
17506 install_element(BGP_NODE, &bgp_timers_cmd);
17507 install_element(BGP_NODE, &no_bgp_timers_cmd);
17508
17509 /* route-map delay-timer commands - per instance for backwards compat.
17510 */
17511 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17512 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17513
17514 /* "bgp client-to-client reflection" commands */
17515 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17516 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17517
17518 /* "bgp always-compare-med" commands */
17519 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17520 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17521
17522 /* bgp ebgp-requires-policy */
17523 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17524 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17525
17526 /* bgp suppress-duplicates */
17527 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17528 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17529
17530 /* bgp reject-as-sets */
17531 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17532 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17533
17534 /* "bgp deterministic-med" commands */
17535 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17536 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17537
17538 /* "bgp graceful-restart" command */
17539 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17540 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17541
17542 /* "bgp graceful-restart-disable" command */
17543 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17544 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17545
17546 /* "neighbor a:b:c:d graceful-restart" command */
17547 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17548 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17549
17550 /* "neighbor a:b:c:d graceful-restart-disable" command */
17551 install_element(BGP_NODE,
17552 &bgp_neighbor_graceful_restart_disable_set_cmd);
17553 install_element(BGP_NODE,
17554 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17555
17556 /* "neighbor a:b:c:d graceful-restart-helper" command */
17557 install_element(BGP_NODE,
17558 &bgp_neighbor_graceful_restart_helper_set_cmd);
17559 install_element(BGP_NODE,
17560 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17561
17562 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17563 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17564 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17565 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17566 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17567 install_element(BGP_NODE,
17568 &no_bgp_graceful_restart_select_defer_time_cmd);
17569 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17570 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17571
17572 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17573 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17574 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17575 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17576
17577 /* "bgp graceful-shutdown" commands */
17578 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17579 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17580
17581 /* "bgp fast-external-failover" commands */
17582 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17583 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17584
17585 /* "bgp bestpath compare-routerid" commands */
17586 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17587 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17588
17589 /* "bgp bestpath as-path ignore" commands */
17590 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17591 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17592
17593 /* "bgp bestpath as-path confed" commands */
17594 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17595 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17596
17597 /* "bgp bestpath as-path multipath-relax" commands */
17598 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17599 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17600
17601 /* "bgp bestpath peer-type multipath-relax" commands */
17602 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17603 install_element(BGP_NODE,
17604 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17605
17606 /* "bgp log-neighbor-changes" commands */
17607 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17608 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17609
17610 /* "bgp bestpath med" commands */
17611 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17612 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17613
17614 /* "bgp bestpath bandwidth" commands */
17615 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17616 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17617
17618 /* "no bgp default <afi>-<safi>" commands. */
17619 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
17620
17621 /* "bgp network import-check" commands. */
17622 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17623 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17624 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17625
17626 /* "bgp default local-preference" commands. */
17627 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17628 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17629
17630 /* bgp default show-hostname */
17631 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17632 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17633
17634 /* bgp default show-nexthop-hostname */
17635 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17636 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17637
17638 /* "bgp default subgroup-pkt-queue-max" commands. */
17639 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17640 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17641
17642 /* bgp ibgp-allow-policy-mods command */
17643 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17644 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17645
17646 /* "bgp listen limit" commands. */
17647 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17648 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17649
17650 /* "bgp listen range" commands. */
17651 install_element(BGP_NODE, &bgp_listen_range_cmd);
17652 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17653
17654 /* "bgp default shutdown" command */
17655 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17656
17657 /* "bgp shutdown" commands */
17658 install_element(BGP_NODE, &bgp_shutdown_cmd);
17659 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17660 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17661 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17662
17663 /* "neighbor remote-as" commands. */
17664 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17665 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17666 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17667 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17668 install_element(BGP_NODE,
17669 &neighbor_interface_v6only_config_remote_as_cmd);
17670 install_element(BGP_NODE, &no_neighbor_cmd);
17671 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17672
17673 /* "neighbor peer-group" commands. */
17674 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17675 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17676 install_element(BGP_NODE,
17677 &no_neighbor_interface_peer_group_remote_as_cmd);
17678
17679 /* "neighbor local-as" commands. */
17680 install_element(BGP_NODE, &neighbor_local_as_cmd);
17681 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17682 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17683 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17684
17685 /* "neighbor solo" commands. */
17686 install_element(BGP_NODE, &neighbor_solo_cmd);
17687 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17688
17689 /* "neighbor password" commands. */
17690 install_element(BGP_NODE, &neighbor_password_cmd);
17691 install_element(BGP_NODE, &no_neighbor_password_cmd);
17692
17693 /* "neighbor activate" commands. */
17694 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17695 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17696 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17697 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17698 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17699 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17700 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17701 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17702 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
17703 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17704 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
17705 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17706
17707 /* "no neighbor activate" commands. */
17708 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17709 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17710 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17711 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17712 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17713 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17714 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17715 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17716 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
17717 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17718 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
17719 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17720
17721 /* "neighbor peer-group" set commands. */
17722 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17723 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17724 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17725 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17726 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17727 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17728 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17729 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17730 install_element(BGP_FLOWSPECV4_NODE,
17731 &neighbor_set_peer_group_hidden_cmd);
17732 install_element(BGP_FLOWSPECV6_NODE,
17733 &neighbor_set_peer_group_hidden_cmd);
17734
17735 /* "no neighbor peer-group unset" commands. */
17736 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17737 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17738 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17739 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17740 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17741 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17742 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17743 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17744 install_element(BGP_FLOWSPECV4_NODE,
17745 &no_neighbor_set_peer_group_hidden_cmd);
17746 install_element(BGP_FLOWSPECV6_NODE,
17747 &no_neighbor_set_peer_group_hidden_cmd);
17748
17749 /* "neighbor softreconfiguration inbound" commands.*/
17750 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17751 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17752 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17753 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17754 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17755 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17756 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17757 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17758 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17759 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17760 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17761 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17762 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17763 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17764 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17765 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17766 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17767 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17768 install_element(BGP_FLOWSPECV4_NODE,
17769 &neighbor_soft_reconfiguration_cmd);
17770 install_element(BGP_FLOWSPECV4_NODE,
17771 &no_neighbor_soft_reconfiguration_cmd);
17772 install_element(BGP_FLOWSPECV6_NODE,
17773 &neighbor_soft_reconfiguration_cmd);
17774 install_element(BGP_FLOWSPECV6_NODE,
17775 &no_neighbor_soft_reconfiguration_cmd);
17776 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17777 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
17778
17779 /* "neighbor attribute-unchanged" commands. */
17780 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17781 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17782 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17783 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17784 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17785 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17786 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17787 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17788 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17789 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17790 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17791 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17792 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17793 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17794 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17795 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17796 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17797 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17798
17799 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17800 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17801
17802 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
17803 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
17804 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
17805 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
17806
17807 /* "nexthop-local unchanged" commands */
17808 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
17809 install_element(BGP_IPV6_NODE,
17810 &no_neighbor_nexthop_local_unchanged_cmd);
17811
17812 /* "neighbor next-hop-self" commands. */
17813 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17814 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17815 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17816 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17817 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17818 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17819 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17820 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17821 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17822 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17823 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17824 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17825 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17826 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17827 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17828 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17829 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17830 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
17831 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17832 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
17833
17834 /* "neighbor next-hop-self force" commands. */
17835 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17836 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
17837 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17838 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
17839 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17840 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
17841 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17842 install_element(BGP_IPV4_NODE,
17843 &no_neighbor_nexthop_self_all_hidden_cmd);
17844 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17845 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
17846 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17847 install_element(BGP_IPV4M_NODE,
17848 &no_neighbor_nexthop_self_all_hidden_cmd);
17849 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17850 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
17851 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17852 install_element(BGP_IPV4L_NODE,
17853 &no_neighbor_nexthop_self_all_hidden_cmd);
17854 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
17855 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
17856 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17857 install_element(BGP_IPV6_NODE,
17858 &no_neighbor_nexthop_self_all_hidden_cmd);
17859 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
17860 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
17861 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17862 install_element(BGP_IPV6M_NODE,
17863 &no_neighbor_nexthop_self_all_hidden_cmd);
17864 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
17865 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
17866 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17867 install_element(BGP_IPV6L_NODE,
17868 &no_neighbor_nexthop_self_all_hidden_cmd);
17869 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
17870 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
17871 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17872 install_element(BGP_VPNV4_NODE,
17873 &no_neighbor_nexthop_self_all_hidden_cmd);
17874 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
17875 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
17876 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17877 install_element(BGP_VPNV6_NODE,
17878 &no_neighbor_nexthop_self_all_hidden_cmd);
17879 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
17880 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
17881
17882 /* "neighbor as-override" commands. */
17883 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
17884 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
17885 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
17886 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
17887 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
17888 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
17889 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
17890 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
17891 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
17892 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
17893 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
17894 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
17895 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
17896 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
17897 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
17898 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
17899 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
17900 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
17901
17902 /* "neighbor remove-private-AS" commands. */
17903 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
17904 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
17905 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
17906 install_element(BGP_NODE,
17907 &no_neighbor_remove_private_as_all_hidden_cmd);
17908 install_element(BGP_NODE,
17909 &neighbor_remove_private_as_replace_as_hidden_cmd);
17910 install_element(BGP_NODE,
17911 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
17912 install_element(BGP_NODE,
17913 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
17914 install_element(
17915 BGP_NODE,
17916 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
17917 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
17918 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
17919 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
17920 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17921 install_element(BGP_IPV4_NODE,
17922 &neighbor_remove_private_as_replace_as_cmd);
17923 install_element(BGP_IPV4_NODE,
17924 &no_neighbor_remove_private_as_replace_as_cmd);
17925 install_element(BGP_IPV4_NODE,
17926 &neighbor_remove_private_as_all_replace_as_cmd);
17927 install_element(BGP_IPV4_NODE,
17928 &no_neighbor_remove_private_as_all_replace_as_cmd);
17929 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
17930 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
17931 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
17932 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
17933 install_element(BGP_IPV4M_NODE,
17934 &neighbor_remove_private_as_replace_as_cmd);
17935 install_element(BGP_IPV4M_NODE,
17936 &no_neighbor_remove_private_as_replace_as_cmd);
17937 install_element(BGP_IPV4M_NODE,
17938 &neighbor_remove_private_as_all_replace_as_cmd);
17939 install_element(BGP_IPV4M_NODE,
17940 &no_neighbor_remove_private_as_all_replace_as_cmd);
17941 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
17942 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
17943 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
17944 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
17945 install_element(BGP_IPV4L_NODE,
17946 &neighbor_remove_private_as_replace_as_cmd);
17947 install_element(BGP_IPV4L_NODE,
17948 &no_neighbor_remove_private_as_replace_as_cmd);
17949 install_element(BGP_IPV4L_NODE,
17950 &neighbor_remove_private_as_all_replace_as_cmd);
17951 install_element(BGP_IPV4L_NODE,
17952 &no_neighbor_remove_private_as_all_replace_as_cmd);
17953 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
17954 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
17955 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
17956 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17957 install_element(BGP_IPV6_NODE,
17958 &neighbor_remove_private_as_replace_as_cmd);
17959 install_element(BGP_IPV6_NODE,
17960 &no_neighbor_remove_private_as_replace_as_cmd);
17961 install_element(BGP_IPV6_NODE,
17962 &neighbor_remove_private_as_all_replace_as_cmd);
17963 install_element(BGP_IPV6_NODE,
17964 &no_neighbor_remove_private_as_all_replace_as_cmd);
17965 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
17966 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
17967 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
17968 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
17969 install_element(BGP_IPV6M_NODE,
17970 &neighbor_remove_private_as_replace_as_cmd);
17971 install_element(BGP_IPV6M_NODE,
17972 &no_neighbor_remove_private_as_replace_as_cmd);
17973 install_element(BGP_IPV6M_NODE,
17974 &neighbor_remove_private_as_all_replace_as_cmd);
17975 install_element(BGP_IPV6M_NODE,
17976 &no_neighbor_remove_private_as_all_replace_as_cmd);
17977 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
17978 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
17979 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
17980 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
17981 install_element(BGP_IPV6L_NODE,
17982 &neighbor_remove_private_as_replace_as_cmd);
17983 install_element(BGP_IPV6L_NODE,
17984 &no_neighbor_remove_private_as_replace_as_cmd);
17985 install_element(BGP_IPV6L_NODE,
17986 &neighbor_remove_private_as_all_replace_as_cmd);
17987 install_element(BGP_IPV6L_NODE,
17988 &no_neighbor_remove_private_as_all_replace_as_cmd);
17989 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
17990 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
17991 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
17992 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17993 install_element(BGP_VPNV4_NODE,
17994 &neighbor_remove_private_as_replace_as_cmd);
17995 install_element(BGP_VPNV4_NODE,
17996 &no_neighbor_remove_private_as_replace_as_cmd);
17997 install_element(BGP_VPNV4_NODE,
17998 &neighbor_remove_private_as_all_replace_as_cmd);
17999 install_element(BGP_VPNV4_NODE,
18000 &no_neighbor_remove_private_as_all_replace_as_cmd);
18001 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18002 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18003 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18004 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18005 install_element(BGP_VPNV6_NODE,
18006 &neighbor_remove_private_as_replace_as_cmd);
18007 install_element(BGP_VPNV6_NODE,
18008 &no_neighbor_remove_private_as_replace_as_cmd);
18009 install_element(BGP_VPNV6_NODE,
18010 &neighbor_remove_private_as_all_replace_as_cmd);
18011 install_element(BGP_VPNV6_NODE,
18012 &no_neighbor_remove_private_as_all_replace_as_cmd);
18013
18014 /* "neighbor send-community" commands.*/
18015 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18016 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18017 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18018 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18019 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18020 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18021 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18022 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18023 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18024 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18025 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18026 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18027 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18028 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18029 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18030 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18031 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18032 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18033 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18034 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18035 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18036 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18037 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18038 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18039 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18040 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18041 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18042 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18043 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18044 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18045 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18046 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18047 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18048 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18049 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18050 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18051
18052 /* "neighbor route-reflector" commands.*/
18053 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18054 install_element(BGP_NODE,
18055 &no_neighbor_route_reflector_client_hidden_cmd);
18056 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18057 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18058 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18059 install_element(BGP_IPV4M_NODE,
18060 &no_neighbor_route_reflector_client_cmd);
18061 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18062 install_element(BGP_IPV4L_NODE,
18063 &no_neighbor_route_reflector_client_cmd);
18064 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18065 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18066 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18067 install_element(BGP_IPV6M_NODE,
18068 &no_neighbor_route_reflector_client_cmd);
18069 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18070 install_element(BGP_IPV6L_NODE,
18071 &no_neighbor_route_reflector_client_cmd);
18072 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18073 install_element(BGP_VPNV4_NODE,
18074 &no_neighbor_route_reflector_client_cmd);
18075 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18076 install_element(BGP_VPNV6_NODE,
18077 &no_neighbor_route_reflector_client_cmd);
18078 install_element(BGP_FLOWSPECV4_NODE,
18079 &neighbor_route_reflector_client_cmd);
18080 install_element(BGP_FLOWSPECV4_NODE,
18081 &no_neighbor_route_reflector_client_cmd);
18082 install_element(BGP_FLOWSPECV6_NODE,
18083 &neighbor_route_reflector_client_cmd);
18084 install_element(BGP_FLOWSPECV6_NODE,
18085 &no_neighbor_route_reflector_client_cmd);
18086 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18087 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18088
18089 /* "neighbor route-server" commands.*/
18090 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18091 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18092 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18093 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18094 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18095 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18096 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18097 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18098 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18099 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18100 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18101 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18102 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18103 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18104 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18105 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18106 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18107 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18108 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18109 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18110 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18111 install_element(BGP_FLOWSPECV4_NODE,
18112 &no_neighbor_route_server_client_cmd);
18113 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18114 install_element(BGP_FLOWSPECV6_NODE,
18115 &no_neighbor_route_server_client_cmd);
18116
18117 /* "neighbor addpath-tx-all-paths" commands.*/
18118 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18119 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18120 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18121 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18122 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18123 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18124 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18125 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18126 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18127 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18128 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18129 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18130 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18131 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18132 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18133 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18134 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18135 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18136
18137 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18138 install_element(BGP_NODE,
18139 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18140 install_element(BGP_NODE,
18141 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18142 install_element(BGP_IPV4_NODE,
18143 &neighbor_addpath_tx_bestpath_per_as_cmd);
18144 install_element(BGP_IPV4_NODE,
18145 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18146 install_element(BGP_IPV4M_NODE,
18147 &neighbor_addpath_tx_bestpath_per_as_cmd);
18148 install_element(BGP_IPV4M_NODE,
18149 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18150 install_element(BGP_IPV4L_NODE,
18151 &neighbor_addpath_tx_bestpath_per_as_cmd);
18152 install_element(BGP_IPV4L_NODE,
18153 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18154 install_element(BGP_IPV6_NODE,
18155 &neighbor_addpath_tx_bestpath_per_as_cmd);
18156 install_element(BGP_IPV6_NODE,
18157 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18158 install_element(BGP_IPV6M_NODE,
18159 &neighbor_addpath_tx_bestpath_per_as_cmd);
18160 install_element(BGP_IPV6M_NODE,
18161 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18162 install_element(BGP_IPV6L_NODE,
18163 &neighbor_addpath_tx_bestpath_per_as_cmd);
18164 install_element(BGP_IPV6L_NODE,
18165 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18166 install_element(BGP_VPNV4_NODE,
18167 &neighbor_addpath_tx_bestpath_per_as_cmd);
18168 install_element(BGP_VPNV4_NODE,
18169 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18170 install_element(BGP_VPNV6_NODE,
18171 &neighbor_addpath_tx_bestpath_per_as_cmd);
18172 install_element(BGP_VPNV6_NODE,
18173 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18174
18175 /* "neighbor sender-as-path-loop-detection" commands. */
18176 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18177 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18178
18179 /* "neighbor passive" commands. */
18180 install_element(BGP_NODE, &neighbor_passive_cmd);
18181 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18182
18183
18184 /* "neighbor shutdown" commands. */
18185 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18186 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18187 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18188 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18189 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18190 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18191
18192 /* "neighbor capability extended-nexthop" commands.*/
18193 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18194 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18195
18196 /* "neighbor capability orf prefix-list" commands.*/
18197 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18198 install_element(BGP_NODE,
18199 &no_neighbor_capability_orf_prefix_hidden_cmd);
18200 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18201 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18202 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18203 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18204 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18205 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18206 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18207 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18208 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18209 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18210 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18211 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18212
18213 /* "neighbor capability dynamic" commands.*/
18214 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18215 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18216
18217 /* "neighbor dont-capability-negotiate" commands. */
18218 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18219 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18220
18221 /* "neighbor ebgp-multihop" commands. */
18222 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18223 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18224 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18225
18226 /* "neighbor disable-connected-check" commands. */
18227 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18228 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18229
18230 /* "neighbor enforce-first-as" commands. */
18231 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18232 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18233
18234 /* "neighbor description" commands. */
18235 install_element(BGP_NODE, &neighbor_description_cmd);
18236 install_element(BGP_NODE, &no_neighbor_description_cmd);
18237 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18238
18239 /* "neighbor update-source" commands. "*/
18240 install_element(BGP_NODE, &neighbor_update_source_cmd);
18241 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18242
18243 /* "neighbor default-originate" commands. */
18244 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18245 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18246 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18247 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18248 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18249 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18250 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18251 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18252 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18253 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18254 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18255 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18256 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18257 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18258 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18259 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18260 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18261 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18262 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18263 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18264 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18265
18266 /* "neighbor port" commands. */
18267 install_element(BGP_NODE, &neighbor_port_cmd);
18268 install_element(BGP_NODE, &no_neighbor_port_cmd);
18269
18270 /* "neighbor weight" commands. */
18271 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18272 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18273
18274 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18275 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18276 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18277 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18278 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18279 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18280 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18281 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18282 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18283 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18284 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18285 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18286 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18287 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18288 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18289 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18290
18291 /* "neighbor override-capability" commands. */
18292 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18293 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18294
18295 /* "neighbor strict-capability-match" commands. */
18296 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18297 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18298
18299 /* "neighbor timers" commands. */
18300 install_element(BGP_NODE, &neighbor_timers_cmd);
18301 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18302
18303 /* "neighbor timers connect" commands. */
18304 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18305 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18306
18307 /* "neighbor timers delayopen" commands. */
18308 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18309 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18310
18311 /* "neighbor advertisement-interval" commands. */
18312 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18313 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18314
18315 /* "neighbor interface" commands. */
18316 install_element(BGP_NODE, &neighbor_interface_cmd);
18317 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18318
18319 /* "neighbor distribute" commands. */
18320 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18321 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18322 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18323 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18324 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18325 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18326 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18327 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18328 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18329 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18330 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18331 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18332 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18333 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18334 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18335 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18336 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18337 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18338
18339 /* "neighbor prefix-list" commands. */
18340 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18341 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18342 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18343 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18344 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18345 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18346 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18347 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18348 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18349 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18350 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18351 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18352 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18353 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18354 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18355 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18356 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18357 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18358 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18359 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18360 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18361 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18362
18363 /* "neighbor filter-list" commands. */
18364 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18365 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18366 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18367 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18368 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18369 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18370 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18371 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18372 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18373 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18374 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18375 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18376 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18377 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18378 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18379 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18380 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18381 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18382 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18383 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18384 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18385 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18386
18387 /* "neighbor route-map" commands. */
18388 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18389 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18390 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18391 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18392 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18393 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18394 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18395 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18396 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18397 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18398 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18399 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18400 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18401 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18402 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18403 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18404 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18405 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18406 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18407 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18408 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18409 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18410 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18411 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18412
18413 /* "neighbor unsuppress-map" commands. */
18414 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18415 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18416 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18417 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18418 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18419 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18420 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18421 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18422 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18423 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18424 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18425 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18426 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18427 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18428 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18429 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18430 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18431 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18432
18433 /* "neighbor advertise-map" commands. */
18434 install_element(BGP_NODE, &bgp_condadv_period_cmd);
18435 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18436 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18437 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18438 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18439 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18440 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18441 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18442 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18443 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18444
18445 /* neighbor maximum-prefix-out commands. */
18446 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18447 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18448 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18449 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18450 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18451 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18452 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18453 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18454 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18455 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18456 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18457 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18458 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18459 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18460 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18461 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18462 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18463 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18464
18465 /* "neighbor maximum-prefix" commands. */
18466 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18467 install_element(BGP_NODE,
18468 &neighbor_maximum_prefix_threshold_hidden_cmd);
18469 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18470 install_element(BGP_NODE,
18471 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18472 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18473 install_element(BGP_NODE,
18474 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18475 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18476 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18477 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18478 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18479 install_element(BGP_IPV4_NODE,
18480 &neighbor_maximum_prefix_threshold_warning_cmd);
18481 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18482 install_element(BGP_IPV4_NODE,
18483 &neighbor_maximum_prefix_threshold_restart_cmd);
18484 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18485 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18486 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18487 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18488 install_element(BGP_IPV4M_NODE,
18489 &neighbor_maximum_prefix_threshold_warning_cmd);
18490 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18491 install_element(BGP_IPV4M_NODE,
18492 &neighbor_maximum_prefix_threshold_restart_cmd);
18493 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18494 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18495 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18496 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18497 install_element(BGP_IPV4L_NODE,
18498 &neighbor_maximum_prefix_threshold_warning_cmd);
18499 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18500 install_element(BGP_IPV4L_NODE,
18501 &neighbor_maximum_prefix_threshold_restart_cmd);
18502 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18503 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18504 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18505 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18506 install_element(BGP_IPV6_NODE,
18507 &neighbor_maximum_prefix_threshold_warning_cmd);
18508 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18509 install_element(BGP_IPV6_NODE,
18510 &neighbor_maximum_prefix_threshold_restart_cmd);
18511 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18512 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18513 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18514 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18515 install_element(BGP_IPV6M_NODE,
18516 &neighbor_maximum_prefix_threshold_warning_cmd);
18517 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18518 install_element(BGP_IPV6M_NODE,
18519 &neighbor_maximum_prefix_threshold_restart_cmd);
18520 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18521 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18522 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18523 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18524 install_element(BGP_IPV6L_NODE,
18525 &neighbor_maximum_prefix_threshold_warning_cmd);
18526 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18527 install_element(BGP_IPV6L_NODE,
18528 &neighbor_maximum_prefix_threshold_restart_cmd);
18529 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18530 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18531 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18532 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18533 install_element(BGP_VPNV4_NODE,
18534 &neighbor_maximum_prefix_threshold_warning_cmd);
18535 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18536 install_element(BGP_VPNV4_NODE,
18537 &neighbor_maximum_prefix_threshold_restart_cmd);
18538 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18539 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18540 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18541 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18542 install_element(BGP_VPNV6_NODE,
18543 &neighbor_maximum_prefix_threshold_warning_cmd);
18544 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18545 install_element(BGP_VPNV6_NODE,
18546 &neighbor_maximum_prefix_threshold_restart_cmd);
18547 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18548
18549 /* "neighbor allowas-in" */
18550 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18551 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18552 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18553 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18554 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18555 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18556 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18557 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18558 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18559 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18560 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18561 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18562 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18563 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18564 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18565 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18566 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18567 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18568 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18569 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18570
18571 /* address-family commands. */
18572 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18573 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18574 #ifdef KEEP_OLD_VPN_COMMANDS
18575 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18576 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18577 #endif /* KEEP_OLD_VPN_COMMANDS */
18578
18579 install_element(BGP_NODE, &address_family_evpn_cmd);
18580
18581 /* "exit-address-family" command. */
18582 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18583 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18584 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18585 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18586 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18587 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18588 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18589 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18590 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18591 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18592 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18593
18594 /* "clear ip bgp commands" */
18595 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18596
18597 /* clear ip bgp prefix */
18598 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18599 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18600 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18601
18602 /* "show [ip] bgp summary" commands. */
18603 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18604 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18605 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18606 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18607 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18608 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18609 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18610
18611 /* "show [ip] bgp neighbors" commands. */
18612 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18613
18614 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18615
18616 /* "show [ip] bgp peer-group" commands. */
18617 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18618
18619 /* "show [ip] bgp paths" commands. */
18620 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18621
18622 /* "show [ip] bgp community" commands. */
18623 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18624
18625 /* "show ip bgp large-community" commands. */
18626 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18627 /* "show [ip] bgp attribute-info" commands. */
18628 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18629 /* "show [ip] bgp route-leak" command */
18630 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18631
18632 /* "redistribute" commands. */
18633 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18634 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18635 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18636 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18637 install_element(BGP_NODE,
18638 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18639 install_element(BGP_NODE,
18640 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18641 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18642 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18643 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18644 install_element(BGP_NODE,
18645 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18646 install_element(BGP_NODE,
18647 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18648 install_element(BGP_NODE,
18649 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18650 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18651 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18652 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18653 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18654 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18655 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18656 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18657 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18658 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18659 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18660 install_element(BGP_IPV4_NODE,
18661 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18662 install_element(BGP_IPV4_NODE,
18663 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18664 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18665 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18666 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18667 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18668 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18669 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18670
18671 /* import|export vpn [route-map WORD] */
18672 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18673 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
18674
18675 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18676 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18677
18678 /* ttl_security commands */
18679 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18680 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18681
18682 /* "show [ip] bgp memory" commands. */
18683 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18684
18685 /* "show bgp martian next-hop" */
18686 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18687
18688 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18689
18690 /* "show [ip] bgp views" commands. */
18691 install_element(VIEW_NODE, &show_bgp_views_cmd);
18692
18693 /* "show [ip] bgp vrfs" commands. */
18694 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18695
18696 /* Community-list. */
18697 community_list_vty();
18698
18699 community_alias_vty();
18700
18701 /* vpn-policy commands */
18702 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18703 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18704 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18705 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18706 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18707 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18708 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18709 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18710 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18711 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
18712 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18713 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
18714
18715 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18716 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18717
18718 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18719 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18720 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18721 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
18722 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18723 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18724 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18725 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
18726 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18727 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
18728
18729 /* tcp-mss command */
18730 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18731 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
18732
18733 /* srv6 commands */
18734 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
18735 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
18736 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
18737 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
18738 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
18739 }
18740
18741 #include "memory.h"
18742 #include "bgp_regex.h"
18743 #include "bgp_clist.h"
18744 #include "bgp_ecommunity.h"
18745
18746 /* VTY functions. */
18747
18748 /* Direction value to string conversion. */
18749 static const char *community_direct_str(int direct)
18750 {
18751 switch (direct) {
18752 case COMMUNITY_DENY:
18753 return "deny";
18754 case COMMUNITY_PERMIT:
18755 return "permit";
18756 default:
18757 return "unknown";
18758 }
18759 }
18760
18761 /* Display error string. */
18762 static void community_list_perror(struct vty *vty, int ret)
18763 {
18764 switch (ret) {
18765 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18766 vty_out(vty, "%% Can't find community-list\n");
18767 break;
18768 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18769 vty_out(vty, "%% Malformed community-list value\n");
18770 break;
18771 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
18772 vty_out(vty,
18773 "%% Community name conflict, previously defined as standard community\n");
18774 break;
18775 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
18776 vty_out(vty,
18777 "%% Community name conflict, previously defined as expanded community\n");
18778 break;
18779 }
18780 }
18781
18782 /* "community-list" keyword help string. */
18783 #define COMMUNITY_LIST_STR "Add a community list entry\n"
18784
18785 /*community-list standard */
18786 DEFUN (community_list_standard,
18787 bgp_community_list_standard_cmd,
18788 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
18789 BGP_STR
18790 COMMUNITY_LIST_STR
18791 "Community list number (standard)\n"
18792 "Add an standard community-list entry\n"
18793 "Community list name\n"
18794 "Sequence number of an entry\n"
18795 "Sequence number\n"
18796 "Specify community to reject\n"
18797 "Specify community to accept\n"
18798 COMMUNITY_VAL_STR)
18799 {
18800 char *cl_name_or_number = NULL;
18801 char *seq = NULL;
18802 int direct = 0;
18803 int style = COMMUNITY_LIST_STANDARD;
18804 int idx = 0;
18805
18806 argv_find(argv, argc, "(0-4294967295)", &idx);
18807 if (idx)
18808 seq = argv[idx]->arg;
18809
18810 idx = 0;
18811 argv_find(argv, argc, "(1-99)", &idx);
18812 argv_find(argv, argc, "WORD", &idx);
18813 cl_name_or_number = argv[idx]->arg;
18814 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18815 : COMMUNITY_DENY;
18816 argv_find(argv, argc, "AA:NN", &idx);
18817 char *str = argv_concat(argv, argc, idx);
18818
18819 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18820 direct, style);
18821
18822 XFREE(MTYPE_TMP, str);
18823
18824 if (ret < 0) {
18825 /* Display error string. */
18826 community_list_perror(vty, ret);
18827 return CMD_WARNING_CONFIG_FAILED;
18828 }
18829
18830 return CMD_SUCCESS;
18831 }
18832
18833 DEFUN (no_community_list_standard_all,
18834 no_bgp_community_list_standard_all_cmd,
18835 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
18836 NO_STR
18837 BGP_STR
18838 COMMUNITY_LIST_STR
18839 "Community list number (standard)\n"
18840 "Add an standard community-list entry\n"
18841 "Community list name\n"
18842 "Sequence number of an entry\n"
18843 "Sequence number\n"
18844 "Specify community to reject\n"
18845 "Specify community to accept\n"
18846 COMMUNITY_VAL_STR)
18847 {
18848 char *cl_name_or_number = NULL;
18849 char *str = NULL;
18850 int direct = 0;
18851 int style = COMMUNITY_LIST_STANDARD;
18852 char *seq = NULL;
18853 int idx = 0;
18854
18855 argv_find(argv, argc, "(0-4294967295)", &idx);
18856 if (idx)
18857 seq = argv[idx]->arg;
18858
18859 idx = 0;
18860 argv_find(argv, argc, "permit", &idx);
18861 argv_find(argv, argc, "deny", &idx);
18862
18863 if (idx) {
18864 direct = argv_find(argv, argc, "permit", &idx)
18865 ? COMMUNITY_PERMIT
18866 : COMMUNITY_DENY;
18867
18868 idx = 0;
18869 argv_find(argv, argc, "AA:NN", &idx);
18870 str = argv_concat(argv, argc, idx);
18871 }
18872
18873 idx = 0;
18874 argv_find(argv, argc, "(1-99)", &idx);
18875 argv_find(argv, argc, "WORD", &idx);
18876 cl_name_or_number = argv[idx]->arg;
18877
18878 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
18879 direct, style);
18880
18881 XFREE(MTYPE_TMP, str);
18882
18883 if (ret < 0) {
18884 community_list_perror(vty, ret);
18885 return CMD_WARNING_CONFIG_FAILED;
18886 }
18887
18888 return CMD_SUCCESS;
18889 }
18890
18891 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
18892 "no bgp community-list <(1-99)|standard WORD>",
18893 NO_STR BGP_STR COMMUNITY_LIST_STR
18894 "Community list number (standard)\n"
18895 "Add an standard community-list entry\n"
18896 "Community list name\n")
18897
18898 /*community-list expanded */
18899 DEFUN (community_list_expanded_all,
18900 bgp_community_list_expanded_all_cmd,
18901 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
18902 BGP_STR
18903 COMMUNITY_LIST_STR
18904 "Community list number (expanded)\n"
18905 "Add an expanded community-list entry\n"
18906 "Community list name\n"
18907 "Sequence number of an entry\n"
18908 "Sequence number\n"
18909 "Specify community to reject\n"
18910 "Specify community to accept\n"
18911 COMMUNITY_VAL_STR)
18912 {
18913 char *cl_name_or_number = NULL;
18914 char *seq = NULL;
18915 int direct = 0;
18916 int style = COMMUNITY_LIST_EXPANDED;
18917 int idx = 0;
18918
18919 argv_find(argv, argc, "(0-4294967295)", &idx);
18920 if (idx)
18921 seq = argv[idx]->arg;
18922
18923 idx = 0;
18924
18925 argv_find(argv, argc, "(100-500)", &idx);
18926 argv_find(argv, argc, "WORD", &idx);
18927 cl_name_or_number = argv[idx]->arg;
18928 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18929 : COMMUNITY_DENY;
18930 argv_find(argv, argc, "AA:NN", &idx);
18931 char *str = argv_concat(argv, argc, idx);
18932
18933 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18934 direct, style);
18935
18936 XFREE(MTYPE_TMP, str);
18937
18938 if (ret < 0) {
18939 /* Display error string. */
18940 community_list_perror(vty, ret);
18941 return CMD_WARNING_CONFIG_FAILED;
18942 }
18943
18944 return CMD_SUCCESS;
18945 }
18946
18947 DEFUN (no_community_list_expanded_all,
18948 no_bgp_community_list_expanded_all_cmd,
18949 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
18950 NO_STR
18951 BGP_STR
18952 COMMUNITY_LIST_STR
18953 "Community list number (expanded)\n"
18954 "Add an expanded community-list entry\n"
18955 "Community list name\n"
18956 "Sequence number of an entry\n"
18957 "Sequence number\n"
18958 "Specify community to reject\n"
18959 "Specify community to accept\n"
18960 COMMUNITY_VAL_STR)
18961 {
18962 char *cl_name_or_number = NULL;
18963 char *seq = NULL;
18964 char *str = NULL;
18965 int direct = 0;
18966 int style = COMMUNITY_LIST_EXPANDED;
18967 int idx = 0;
18968
18969 argv_find(argv, argc, "(0-4294967295)", &idx);
18970 if (idx)
18971 seq = argv[idx]->arg;
18972
18973 idx = 0;
18974 argv_find(argv, argc, "permit", &idx);
18975 argv_find(argv, argc, "deny", &idx);
18976
18977 if (idx) {
18978 direct = argv_find(argv, argc, "permit", &idx)
18979 ? COMMUNITY_PERMIT
18980 : COMMUNITY_DENY;
18981
18982 idx = 0;
18983 argv_find(argv, argc, "AA:NN", &idx);
18984 str = argv_concat(argv, argc, idx);
18985 }
18986
18987 idx = 0;
18988 argv_find(argv, argc, "(100-500)", &idx);
18989 argv_find(argv, argc, "WORD", &idx);
18990 cl_name_or_number = argv[idx]->arg;
18991
18992 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
18993 direct, style);
18994
18995 XFREE(MTYPE_TMP, str);
18996
18997 if (ret < 0) {
18998 community_list_perror(vty, ret);
18999 return CMD_WARNING_CONFIG_FAILED;
19000 }
19001
19002 return CMD_SUCCESS;
19003 }
19004
19005 ALIAS(no_community_list_expanded_all,
19006 no_bgp_community_list_expanded_all_list_cmd,
19007 "no bgp community-list <(100-500)|expanded WORD>",
19008 NO_STR BGP_STR COMMUNITY_LIST_STR
19009 "Community list number (expanded)\n"
19010 "Add an expanded community-list entry\n"
19011 "Community list name\n")
19012
19013 /* Return configuration string of community-list entry. */
19014 static const char *community_list_config_str(struct community_entry *entry)
19015 {
19016 const char *str;
19017
19018 if (entry->any)
19019 str = "";
19020 else {
19021 if (entry->style == COMMUNITY_LIST_STANDARD)
19022 str = community_str(entry->u.com, false);
19023 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19024 str = lcommunity_str(entry->u.lcom, false);
19025 else
19026 str = entry->config;
19027 }
19028 return str;
19029 }
19030
19031 static void community_list_show(struct vty *vty, struct community_list *list)
19032 {
19033 struct community_entry *entry;
19034
19035 for (entry = list->head; entry; entry = entry->next) {
19036 if (entry == list->head) {
19037 if (all_digit(list->name))
19038 vty_out(vty, "Community %s list %s\n",
19039 entry->style == COMMUNITY_LIST_STANDARD
19040 ? "standard"
19041 : "(expanded) access",
19042 list->name);
19043 else
19044 vty_out(vty, "Named Community %s list %s\n",
19045 entry->style == COMMUNITY_LIST_STANDARD
19046 ? "standard"
19047 : "expanded",
19048 list->name);
19049 }
19050 if (entry->any)
19051 vty_out(vty, " %s\n",
19052 community_direct_str(entry->direct));
19053 else
19054 vty_out(vty, " %s %s\n",
19055 community_direct_str(entry->direct),
19056 community_list_config_str(entry));
19057 }
19058 }
19059
19060 DEFUN (show_community_list,
19061 show_bgp_community_list_cmd,
19062 "show bgp community-list",
19063 SHOW_STR
19064 BGP_STR
19065 "List community-list\n")
19066 {
19067 struct community_list *list;
19068 struct community_list_master *cm;
19069
19070 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19071 if (!cm)
19072 return CMD_SUCCESS;
19073
19074 for (list = cm->num.head; list; list = list->next)
19075 community_list_show(vty, list);
19076
19077 for (list = cm->str.head; list; list = list->next)
19078 community_list_show(vty, list);
19079
19080 return CMD_SUCCESS;
19081 }
19082
19083 DEFUN (show_community_list_arg,
19084 show_bgp_community_list_arg_cmd,
19085 "show bgp community-list <(1-500)|WORD> detail",
19086 SHOW_STR
19087 BGP_STR
19088 "List community-list\n"
19089 "Community-list number\n"
19090 "Community-list name\n"
19091 "Detailed information on community-list\n")
19092 {
19093 int idx_comm_list = 3;
19094 struct community_list *list;
19095
19096 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19097 COMMUNITY_LIST_MASTER);
19098 if (!list) {
19099 vty_out(vty, "%% Can't find community-list\n");
19100 return CMD_WARNING;
19101 }
19102
19103 community_list_show(vty, list);
19104
19105 return CMD_SUCCESS;
19106 }
19107
19108 /*
19109 * Large Community code.
19110 */
19111 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19112 struct cmd_token **argv, int style,
19113 int reject_all_digit_name)
19114 {
19115 int ret;
19116 int direct;
19117 char *str;
19118 int idx = 0;
19119 char *cl_name;
19120 char *seq = NULL;
19121
19122 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19123 seq = argv[idx]->arg;
19124
19125 idx = 0;
19126 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19127 : COMMUNITY_DENY;
19128
19129 /* All digit name check. */
19130 idx = 0;
19131 argv_find(argv, argc, "WORD", &idx);
19132 argv_find(argv, argc, "(1-99)", &idx);
19133 argv_find(argv, argc, "(100-500)", &idx);
19134 cl_name = argv[idx]->arg;
19135 if (reject_all_digit_name && all_digit(cl_name)) {
19136 vty_out(vty, "%% Community name cannot have all digits\n");
19137 return CMD_WARNING_CONFIG_FAILED;
19138 }
19139
19140 idx = 0;
19141 argv_find(argv, argc, "AA:BB:CC", &idx);
19142 argv_find(argv, argc, "LINE", &idx);
19143 /* Concat community string argument. */
19144 if (idx)
19145 str = argv_concat(argv, argc, idx);
19146 else
19147 str = NULL;
19148
19149 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19150
19151 /* Free temporary community list string allocated by
19152 argv_concat(). */
19153 XFREE(MTYPE_TMP, str);
19154
19155 if (ret < 0) {
19156 community_list_perror(vty, ret);
19157 return CMD_WARNING_CONFIG_FAILED;
19158 }
19159 return CMD_SUCCESS;
19160 }
19161
19162 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19163 struct cmd_token **argv, int style)
19164 {
19165 int ret;
19166 int direct = 0;
19167 char *str = NULL;
19168 int idx = 0;
19169 char *seq = NULL;
19170
19171 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19172 seq = argv[idx]->arg;
19173
19174 idx = 0;
19175 argv_find(argv, argc, "permit", &idx);
19176 argv_find(argv, argc, "deny", &idx);
19177
19178 if (idx) {
19179 /* Check the list direct. */
19180 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19181 direct = COMMUNITY_PERMIT;
19182 else
19183 direct = COMMUNITY_DENY;
19184
19185 idx = 0;
19186 argv_find(argv, argc, "LINE", &idx);
19187 argv_find(argv, argc, "AA:AA:NN", &idx);
19188 /* Concat community string argument. */
19189 str = argv_concat(argv, argc, idx);
19190 }
19191
19192 idx = 0;
19193 argv_find(argv, argc, "(1-99)", &idx);
19194 argv_find(argv, argc, "(100-500)", &idx);
19195 argv_find(argv, argc, "WORD", &idx);
19196
19197 /* Unset community list. */
19198 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19199 style);
19200
19201 /* Free temporary community list string allocated by
19202 argv_concat(). */
19203 XFREE(MTYPE_TMP, str);
19204
19205 if (ret < 0) {
19206 community_list_perror(vty, ret);
19207 return CMD_WARNING_CONFIG_FAILED;
19208 }
19209
19210 return CMD_SUCCESS;
19211 }
19212
19213 /* "large-community-list" keyword help string. */
19214 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19215 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19216
19217 DEFUN (lcommunity_list_standard,
19218 bgp_lcommunity_list_standard_cmd,
19219 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19220 BGP_STR
19221 LCOMMUNITY_LIST_STR
19222 "Large Community list number (standard)\n"
19223 "Sequence number of an entry\n"
19224 "Sequence number\n"
19225 "Specify large community to reject\n"
19226 "Specify large community to accept\n"
19227 LCOMMUNITY_VAL_STR)
19228 {
19229 return lcommunity_list_set_vty(vty, argc, argv,
19230 LARGE_COMMUNITY_LIST_STANDARD, 0);
19231 }
19232
19233 DEFUN (lcommunity_list_expanded,
19234 bgp_lcommunity_list_expanded_cmd,
19235 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19236 BGP_STR
19237 LCOMMUNITY_LIST_STR
19238 "Large Community list number (expanded)\n"
19239 "Sequence number of an entry\n"
19240 "Sequence number\n"
19241 "Specify large community to reject\n"
19242 "Specify large community to accept\n"
19243 "An ordered list as a regular-expression\n")
19244 {
19245 return lcommunity_list_set_vty(vty, argc, argv,
19246 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19247 }
19248
19249 DEFUN (lcommunity_list_name_standard,
19250 bgp_lcommunity_list_name_standard_cmd,
19251 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19252 BGP_STR
19253 LCOMMUNITY_LIST_STR
19254 "Specify standard large-community-list\n"
19255 "Large Community list name\n"
19256 "Sequence number of an entry\n"
19257 "Sequence number\n"
19258 "Specify large community to reject\n"
19259 "Specify large community to accept\n"
19260 LCOMMUNITY_VAL_STR)
19261 {
19262 return lcommunity_list_set_vty(vty, argc, argv,
19263 LARGE_COMMUNITY_LIST_STANDARD, 1);
19264 }
19265
19266 DEFUN (lcommunity_list_name_expanded,
19267 bgp_lcommunity_list_name_expanded_cmd,
19268 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
19269 BGP_STR
19270 LCOMMUNITY_LIST_STR
19271 "Specify expanded large-community-list\n"
19272 "Large Community list name\n"
19273 "Sequence number of an entry\n"
19274 "Sequence number\n"
19275 "Specify large community to reject\n"
19276 "Specify large community to accept\n"
19277 "An ordered list as a regular-expression\n")
19278 {
19279 return lcommunity_list_set_vty(vty, argc, argv,
19280 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19281 }
19282
19283 DEFUN (no_lcommunity_list_all,
19284 no_bgp_lcommunity_list_all_cmd,
19285 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19286 NO_STR
19287 BGP_STR
19288 LCOMMUNITY_LIST_STR
19289 "Large Community list number (standard)\n"
19290 "Large Community list number (expanded)\n"
19291 "Large Community list name\n")
19292 {
19293 return lcommunity_list_unset_vty(vty, argc, argv,
19294 LARGE_COMMUNITY_LIST_STANDARD);
19295 }
19296
19297 DEFUN (no_lcommunity_list_name_standard_all,
19298 no_bgp_lcommunity_list_name_standard_all_cmd,
19299 "no bgp large-community-list standard WORD",
19300 NO_STR
19301 BGP_STR
19302 LCOMMUNITY_LIST_STR
19303 "Specify standard large-community-list\n"
19304 "Large Community list name\n")
19305 {
19306 return lcommunity_list_unset_vty(vty, argc, argv,
19307 LARGE_COMMUNITY_LIST_STANDARD);
19308 }
19309
19310 DEFUN (no_lcommunity_list_name_expanded_all,
19311 no_bgp_lcommunity_list_name_expanded_all_cmd,
19312 "no bgp large-community-list expanded WORD",
19313 NO_STR
19314 BGP_STR
19315 LCOMMUNITY_LIST_STR
19316 "Specify expanded large-community-list\n"
19317 "Large Community list name\n")
19318 {
19319 return lcommunity_list_unset_vty(vty, argc, argv,
19320 LARGE_COMMUNITY_LIST_EXPANDED);
19321 }
19322
19323 DEFUN (no_lcommunity_list_standard,
19324 no_bgp_lcommunity_list_standard_cmd,
19325 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19326 NO_STR
19327 BGP_STR
19328 LCOMMUNITY_LIST_STR
19329 "Large Community list number (standard)\n"
19330 "Sequence number of an entry\n"
19331 "Sequence number\n"
19332 "Specify large community to reject\n"
19333 "Specify large community to accept\n"
19334 LCOMMUNITY_VAL_STR)
19335 {
19336 return lcommunity_list_unset_vty(vty, argc, argv,
19337 LARGE_COMMUNITY_LIST_STANDARD);
19338 }
19339
19340 DEFUN (no_lcommunity_list_expanded,
19341 no_bgp_lcommunity_list_expanded_cmd,
19342 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19343 NO_STR
19344 BGP_STR
19345 LCOMMUNITY_LIST_STR
19346 "Large Community list number (expanded)\n"
19347 "Sequence number of an entry\n"
19348 "Sequence number\n"
19349 "Specify large community to reject\n"
19350 "Specify large community to accept\n"
19351 "An ordered list as a regular-expression\n")
19352 {
19353 return lcommunity_list_unset_vty(vty, argc, argv,
19354 LARGE_COMMUNITY_LIST_EXPANDED);
19355 }
19356
19357 DEFUN (no_lcommunity_list_name_standard,
19358 no_bgp_lcommunity_list_name_standard_cmd,
19359 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19360 NO_STR
19361 BGP_STR
19362 LCOMMUNITY_LIST_STR
19363 "Specify standard large-community-list\n"
19364 "Large Community list name\n"
19365 "Sequence number of an entry\n"
19366 "Sequence number\n"
19367 "Specify large community to reject\n"
19368 "Specify large community to accept\n"
19369 LCOMMUNITY_VAL_STR)
19370 {
19371 return lcommunity_list_unset_vty(vty, argc, argv,
19372 LARGE_COMMUNITY_LIST_STANDARD);
19373 }
19374
19375 DEFUN (no_lcommunity_list_name_expanded,
19376 no_bgp_lcommunity_list_name_expanded_cmd,
19377 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
19378 NO_STR
19379 BGP_STR
19380 LCOMMUNITY_LIST_STR
19381 "Specify expanded large-community-list\n"
19382 "Large community list name\n"
19383 "Sequence number of an entry\n"
19384 "Sequence number\n"
19385 "Specify large community to reject\n"
19386 "Specify large community to accept\n"
19387 "An ordered list as a regular-expression\n")
19388 {
19389 return lcommunity_list_unset_vty(vty, argc, argv,
19390 LARGE_COMMUNITY_LIST_EXPANDED);
19391 }
19392
19393 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19394 {
19395 struct community_entry *entry;
19396
19397 for (entry = list->head; entry; entry = entry->next) {
19398 if (entry == list->head) {
19399 if (all_digit(list->name))
19400 vty_out(vty, "Large community %s list %s\n",
19401 entry->style ==
19402 LARGE_COMMUNITY_LIST_STANDARD
19403 ? "standard"
19404 : "(expanded) access",
19405 list->name);
19406 else
19407 vty_out(vty,
19408 "Named large community %s list %s\n",
19409 entry->style ==
19410 LARGE_COMMUNITY_LIST_STANDARD
19411 ? "standard"
19412 : "expanded",
19413 list->name);
19414 }
19415 if (entry->any)
19416 vty_out(vty, " %s\n",
19417 community_direct_str(entry->direct));
19418 else
19419 vty_out(vty, " %s %s\n",
19420 community_direct_str(entry->direct),
19421 community_list_config_str(entry));
19422 }
19423 }
19424
19425 DEFUN (show_lcommunity_list,
19426 show_bgp_lcommunity_list_cmd,
19427 "show bgp large-community-list",
19428 SHOW_STR
19429 BGP_STR
19430 "List large-community list\n")
19431 {
19432 struct community_list *list;
19433 struct community_list_master *cm;
19434
19435 cm = community_list_master_lookup(bgp_clist,
19436 LARGE_COMMUNITY_LIST_MASTER);
19437 if (!cm)
19438 return CMD_SUCCESS;
19439
19440 for (list = cm->num.head; list; list = list->next)
19441 lcommunity_list_show(vty, list);
19442
19443 for (list = cm->str.head; list; list = list->next)
19444 lcommunity_list_show(vty, list);
19445
19446 return CMD_SUCCESS;
19447 }
19448
19449 DEFUN (show_lcommunity_list_arg,
19450 show_bgp_lcommunity_list_arg_cmd,
19451 "show bgp large-community-list <(1-500)|WORD> detail",
19452 SHOW_STR
19453 BGP_STR
19454 "List large-community list\n"
19455 "Large-community-list number\n"
19456 "Large-community-list name\n"
19457 "Detailed information on large-community-list\n")
19458 {
19459 struct community_list *list;
19460
19461 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19462 LARGE_COMMUNITY_LIST_MASTER);
19463 if (!list) {
19464 vty_out(vty, "%% Can't find large-community-list\n");
19465 return CMD_WARNING;
19466 }
19467
19468 lcommunity_list_show(vty, list);
19469
19470 return CMD_SUCCESS;
19471 }
19472
19473 /* "extcommunity-list" keyword help string. */
19474 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19475 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19476
19477 DEFUN (extcommunity_list_standard,
19478 bgp_extcommunity_list_standard_cmd,
19479 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19480 BGP_STR
19481 EXTCOMMUNITY_LIST_STR
19482 "Extended Community list number (standard)\n"
19483 "Specify standard extcommunity-list\n"
19484 "Community list name\n"
19485 "Sequence number of an entry\n"
19486 "Sequence number\n"
19487 "Specify community to reject\n"
19488 "Specify community to accept\n"
19489 EXTCOMMUNITY_VAL_STR)
19490 {
19491 int style = EXTCOMMUNITY_LIST_STANDARD;
19492 int direct = 0;
19493 char *cl_number_or_name = NULL;
19494 char *seq = NULL;
19495
19496 int idx = 0;
19497
19498 argv_find(argv, argc, "(1-99)", &idx);
19499 argv_find(argv, argc, "WORD", &idx);
19500 cl_number_or_name = argv[idx]->arg;
19501
19502 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19503 seq = argv[idx]->arg;
19504
19505 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19506 : COMMUNITY_DENY;
19507 argv_find(argv, argc, "AA:NN", &idx);
19508 char *str = argv_concat(argv, argc, idx);
19509
19510 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19511 direct, style);
19512
19513 XFREE(MTYPE_TMP, str);
19514
19515 if (ret < 0) {
19516 community_list_perror(vty, ret);
19517 return CMD_WARNING_CONFIG_FAILED;
19518 }
19519
19520 return CMD_SUCCESS;
19521 }
19522
19523 DEFUN (extcommunity_list_name_expanded,
19524 bgp_extcommunity_list_name_expanded_cmd,
19525 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
19526 BGP_STR
19527 EXTCOMMUNITY_LIST_STR
19528 "Extended Community list number (expanded)\n"
19529 "Specify expanded extcommunity-list\n"
19530 "Extended Community list name\n"
19531 "Sequence number of an entry\n"
19532 "Sequence number\n"
19533 "Specify community to reject\n"
19534 "Specify community to accept\n"
19535 "An ordered list as a regular-expression\n")
19536 {
19537 int style = EXTCOMMUNITY_LIST_EXPANDED;
19538 int direct = 0;
19539 char *cl_number_or_name = NULL;
19540 char *seq = NULL;
19541 int idx = 0;
19542
19543 argv_find(argv, argc, "(100-500)", &idx);
19544 argv_find(argv, argc, "WORD", &idx);
19545 cl_number_or_name = argv[idx]->arg;
19546
19547 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19548 seq = argv[idx]->arg;
19549
19550 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19551 : COMMUNITY_DENY;
19552 argv_find(argv, argc, "LINE", &idx);
19553 char *str = argv_concat(argv, argc, idx);
19554
19555 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19556 direct, style);
19557
19558 XFREE(MTYPE_TMP, str);
19559
19560 if (ret < 0) {
19561 community_list_perror(vty, ret);
19562 return CMD_WARNING_CONFIG_FAILED;
19563 }
19564
19565 return CMD_SUCCESS;
19566 }
19567
19568 DEFUN (no_extcommunity_list_standard_all,
19569 no_bgp_extcommunity_list_standard_all_cmd,
19570 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
19571 NO_STR
19572 BGP_STR
19573 EXTCOMMUNITY_LIST_STR
19574 "Extended Community list number (standard)\n"
19575 "Specify standard extcommunity-list\n"
19576 "Community list name\n"
19577 "Sequence number of an entry\n"
19578 "Sequence number\n"
19579 "Specify community to reject\n"
19580 "Specify community to accept\n"
19581 EXTCOMMUNITY_VAL_STR)
19582 {
19583 int style = EXTCOMMUNITY_LIST_STANDARD;
19584 int direct = 0;
19585 char *cl_number_or_name = NULL;
19586 char *str = NULL;
19587 char *seq = NULL;
19588 int idx = 0;
19589
19590 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19591 seq = argv[idx]->arg;
19592
19593 idx = 0;
19594 argv_find(argv, argc, "permit", &idx);
19595 argv_find(argv, argc, "deny", &idx);
19596 if (idx) {
19597 direct = argv_find(argv, argc, "permit", &idx)
19598 ? COMMUNITY_PERMIT
19599 : COMMUNITY_DENY;
19600
19601 idx = 0;
19602 argv_find(argv, argc, "AA:NN", &idx);
19603 str = argv_concat(argv, argc, idx);
19604 }
19605
19606 idx = 0;
19607 argv_find(argv, argc, "(1-99)", &idx);
19608 argv_find(argv, argc, "WORD", &idx);
19609 cl_number_or_name = argv[idx]->arg;
19610
19611 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19612 seq, direct, style);
19613
19614 XFREE(MTYPE_TMP, str);
19615
19616 if (ret < 0) {
19617 community_list_perror(vty, ret);
19618 return CMD_WARNING_CONFIG_FAILED;
19619 }
19620
19621 return CMD_SUCCESS;
19622 }
19623
19624 ALIAS(no_extcommunity_list_standard_all,
19625 no_bgp_extcommunity_list_standard_all_list_cmd,
19626 "no bgp extcommunity-list <(1-99)|standard WORD>",
19627 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19628 "Extended Community list number (standard)\n"
19629 "Specify standard extcommunity-list\n"
19630 "Community list name\n")
19631
19632 DEFUN (no_extcommunity_list_expanded_all,
19633 no_bgp_extcommunity_list_expanded_all_cmd,
19634 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
19635 NO_STR
19636 BGP_STR
19637 EXTCOMMUNITY_LIST_STR
19638 "Extended Community list number (expanded)\n"
19639 "Specify expanded extcommunity-list\n"
19640 "Extended Community list name\n"
19641 "Sequence number of an entry\n"
19642 "Sequence number\n"
19643 "Specify community to reject\n"
19644 "Specify community to accept\n"
19645 "An ordered list as a regular-expression\n")
19646 {
19647 int style = EXTCOMMUNITY_LIST_EXPANDED;
19648 int direct = 0;
19649 char *cl_number_or_name = NULL;
19650 char *str = NULL;
19651 char *seq = NULL;
19652 int idx = 0;
19653
19654 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19655 seq = argv[idx]->arg;
19656
19657 idx = 0;
19658 argv_find(argv, argc, "permit", &idx);
19659 argv_find(argv, argc, "deny", &idx);
19660
19661 if (idx) {
19662 direct = argv_find(argv, argc, "permit", &idx)
19663 ? COMMUNITY_PERMIT
19664 : COMMUNITY_DENY;
19665
19666 idx = 0;
19667 argv_find(argv, argc, "LINE", &idx);
19668 str = argv_concat(argv, argc, idx);
19669 }
19670
19671 idx = 0;
19672 argv_find(argv, argc, "(100-500)", &idx);
19673 argv_find(argv, argc, "WORD", &idx);
19674 cl_number_or_name = argv[idx]->arg;
19675
19676 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19677 seq, direct, style);
19678
19679 XFREE(MTYPE_TMP, str);
19680
19681 if (ret < 0) {
19682 community_list_perror(vty, ret);
19683 return CMD_WARNING_CONFIG_FAILED;
19684 }
19685
19686 return CMD_SUCCESS;
19687 }
19688
19689 ALIAS(no_extcommunity_list_expanded_all,
19690 no_bgp_extcommunity_list_expanded_all_list_cmd,
19691 "no bgp extcommunity-list <(100-500)|expanded WORD>",
19692 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19693 "Extended Community list number (expanded)\n"
19694 "Specify expanded extcommunity-list\n"
19695 "Extended Community list name\n")
19696
19697 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
19698 {
19699 struct community_entry *entry;
19700
19701 for (entry = list->head; entry; entry = entry->next) {
19702 if (entry == list->head) {
19703 if (all_digit(list->name))
19704 vty_out(vty, "Extended community %s list %s\n",
19705 entry->style == EXTCOMMUNITY_LIST_STANDARD
19706 ? "standard"
19707 : "(expanded) access",
19708 list->name);
19709 else
19710 vty_out(vty,
19711 "Named extended community %s list %s\n",
19712 entry->style == EXTCOMMUNITY_LIST_STANDARD
19713 ? "standard"
19714 : "expanded",
19715 list->name);
19716 }
19717 if (entry->any)
19718 vty_out(vty, " %s\n",
19719 community_direct_str(entry->direct));
19720 else
19721 vty_out(vty, " %s %s\n",
19722 community_direct_str(entry->direct),
19723 community_list_config_str(entry));
19724 }
19725 }
19726
19727 DEFUN (show_extcommunity_list,
19728 show_bgp_extcommunity_list_cmd,
19729 "show bgp extcommunity-list",
19730 SHOW_STR
19731 BGP_STR
19732 "List extended-community list\n")
19733 {
19734 struct community_list *list;
19735 struct community_list_master *cm;
19736
19737 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19738 if (!cm)
19739 return CMD_SUCCESS;
19740
19741 for (list = cm->num.head; list; list = list->next)
19742 extcommunity_list_show(vty, list);
19743
19744 for (list = cm->str.head; list; list = list->next)
19745 extcommunity_list_show(vty, list);
19746
19747 return CMD_SUCCESS;
19748 }
19749
19750 DEFUN (show_extcommunity_list_arg,
19751 show_bgp_extcommunity_list_arg_cmd,
19752 "show bgp extcommunity-list <(1-500)|WORD> detail",
19753 SHOW_STR
19754 BGP_STR
19755 "List extended-community list\n"
19756 "Extcommunity-list number\n"
19757 "Extcommunity-list name\n"
19758 "Detailed information on extcommunity-list\n")
19759 {
19760 int idx_comm_list = 3;
19761 struct community_list *list;
19762
19763 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19764 EXTCOMMUNITY_LIST_MASTER);
19765 if (!list) {
19766 vty_out(vty, "%% Can't find extcommunity-list\n");
19767 return CMD_WARNING;
19768 }
19769
19770 extcommunity_list_show(vty, list);
19771
19772 return CMD_SUCCESS;
19773 }
19774
19775 /* Display community-list and extcommunity-list configuration. */
19776 static int community_list_config_write(struct vty *vty)
19777 {
19778 struct community_list *list;
19779 struct community_entry *entry;
19780 struct community_list_master *cm;
19781 int write = 0;
19782
19783 /* Community-list. */
19784 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19785
19786 for (list = cm->num.head; list; list = list->next)
19787 for (entry = list->head; entry; entry = entry->next) {
19788 vty_out(vty,
19789 "bgp community-list %s seq %" PRId64 " %s %s\n",
19790 list->name, entry->seq,
19791 community_direct_str(entry->direct),
19792 community_list_config_str(entry));
19793 write++;
19794 }
19795 for (list = cm->str.head; list; list = list->next)
19796 for (entry = list->head; entry; entry = entry->next) {
19797 vty_out(vty,
19798 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
19799 entry->style == COMMUNITY_LIST_STANDARD
19800 ? "standard"
19801 : "expanded",
19802 list->name, entry->seq,
19803 community_direct_str(entry->direct),
19804 community_list_config_str(entry));
19805 write++;
19806 }
19807
19808 /* Extcommunity-list. */
19809 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19810
19811 for (list = cm->num.head; list; list = list->next)
19812 for (entry = list->head; entry; entry = entry->next) {
19813 vty_out(vty,
19814 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
19815 list->name, entry->seq,
19816 community_direct_str(entry->direct),
19817 community_list_config_str(entry));
19818 write++;
19819 }
19820 for (list = cm->str.head; list; list = list->next)
19821 for (entry = list->head; entry; entry = entry->next) {
19822 vty_out(vty,
19823 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
19824 entry->style == EXTCOMMUNITY_LIST_STANDARD
19825 ? "standard"
19826 : "expanded",
19827 list->name, entry->seq,
19828 community_direct_str(entry->direct),
19829 community_list_config_str(entry));
19830 write++;
19831 }
19832
19833
19834 /* lcommunity-list. */
19835 cm = community_list_master_lookup(bgp_clist,
19836 LARGE_COMMUNITY_LIST_MASTER);
19837
19838 for (list = cm->num.head; list; list = list->next)
19839 for (entry = list->head; entry; entry = entry->next) {
19840 vty_out(vty,
19841 "bgp large-community-list %s seq %" PRId64" %s %s\n",
19842 list->name, entry->seq,
19843 community_direct_str(entry->direct),
19844 community_list_config_str(entry));
19845 write++;
19846 }
19847 for (list = cm->str.head; list; list = list->next)
19848 for (entry = list->head; entry; entry = entry->next) {
19849 vty_out(vty,
19850 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
19851
19852 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19853 ? "standard"
19854 : "expanded",
19855 list->name, entry->seq, community_direct_str(entry->direct),
19856 community_list_config_str(entry));
19857 write++;
19858 }
19859
19860 return write;
19861 }
19862
19863 static int community_list_config_write(struct vty *vty);
19864 static struct cmd_node community_list_node = {
19865 .name = "community list",
19866 .node = COMMUNITY_LIST_NODE,
19867 .prompt = "",
19868 .config_write = community_list_config_write,
19869 };
19870
19871 static void community_list_vty(void)
19872 {
19873 install_node(&community_list_node);
19874
19875 /* Community-list. */
19876 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
19877 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
19878 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
19879 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
19880 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
19881 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
19882 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
19883 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
19884
19885 /* Extcommunity-list. */
19886 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
19887 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
19888 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
19889 install_element(CONFIG_NODE,
19890 &no_bgp_extcommunity_list_standard_all_list_cmd);
19891 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
19892 install_element(CONFIG_NODE,
19893 &no_bgp_extcommunity_list_expanded_all_list_cmd);
19894 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
19895 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
19896
19897 /* Large Community List */
19898 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
19899 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
19900 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
19901 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
19902 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
19903 install_element(CONFIG_NODE,
19904 &no_bgp_lcommunity_list_name_standard_all_cmd);
19905 install_element(CONFIG_NODE,
19906 &no_bgp_lcommunity_list_name_expanded_all_cmd);
19907 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
19908 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
19909 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
19910 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
19911 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
19912 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
19913 }
19914
19915 static struct cmd_node community_alias_node = {
19916 .name = "community alias",
19917 .node = COMMUNITY_ALIAS_NODE,
19918 .prompt = "",
19919 .config_write = bgp_community_alias_write,
19920 };
19921
19922 void community_alias_vty(void)
19923 {
19924 install_node(&community_alias_node);
19925
19926 /* Community-list. */
19927 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
19928
19929 bgp_community_alias_command_completion_setup();
19930 }