]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12811 from Avineus/frr_neighlog_5884
[mirror_frr.git] / bgpd / bgp_vty.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* BGP VTY interface.
3 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
4 */
5
6 #include <zebra.h>
7
8 #include "command.h"
9 #include "lib/json.h"
10 #include "lib/sockopt.h"
11 #include "lib_errors.h"
12 #include "lib/zclient.h"
13 #include "lib/printfrr.h"
14 #include "prefix.h"
15 #include "plist.h"
16 #include "buffer.h"
17 #include "linklist.h"
18 #include "stream.h"
19 #include "thread.h"
20 #include "log.h"
21 #include "memory.h"
22 #include "lib_vty.h"
23 #include "hash.h"
24 #include "queue.h"
25 #include "filter.h"
26 #include "frrstr.h"
27 #include "asn.h"
28
29 #include "bgpd/bgpd.h"
30 #include "bgpd/bgp_attr_evpn.h"
31 #include "bgpd/bgp_advertise.h"
32 #include "bgpd/bgp_attr.h"
33 #include "bgpd/bgp_aspath.h"
34 #include "bgpd/bgp_community.h"
35 #include "bgpd/bgp_community_alias.h"
36 #include "bgpd/bgp_ecommunity.h"
37 #include "bgpd/bgp_lcommunity.h"
38 #include "bgpd/bgp_damp.h"
39 #include "bgpd/bgp_debug.h"
40 #include "bgpd/bgp_errors.h"
41 #include "bgpd/bgp_fsm.h"
42 #include "bgpd/bgp_nht.h"
43 #include "bgpd/bgp_nexthop.h"
44 #include "bgpd/bgp_network.h"
45 #include "bgpd/bgp_open.h"
46 #include "bgpd/bgp_regex.h"
47 #include "bgpd/bgp_route.h"
48 #include "bgpd/bgp_mplsvpn.h"
49 #include "bgpd/bgp_zebra.h"
50 #include "bgpd/bgp_table.h"
51 #include "bgpd/bgp_vty.h"
52 #include "bgpd/bgp_mpath.h"
53 #include "bgpd/bgp_packet.h"
54 #include "bgpd/bgp_updgrp.h"
55 #include "bgpd/bgp_bfd.h"
56 #include "bgpd/bgp_io.h"
57 #include "bgpd/bgp_evpn.h"
58 #include "bgpd/bgp_evpn_vty.h"
59 #include "bgpd/bgp_evpn_mh.h"
60 #include "bgpd/bgp_addpath.h"
61 #include "bgpd/bgp_mac.h"
62 #include "bgpd/bgp_flowspec.h"
63 #include "bgpd/bgp_conditional_adv.h"
64 #ifdef ENABLE_BGP_VNC
65 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
66 #endif
67
68 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
69 {
70 .val_bool = false,
71 .match_profile = "traditional",
72 .match_version = "< 7.4",
73 },
74 { .val_bool = true },
75 );
76 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
77 { .val_bool = true, .match_profile = "datacenter", },
78 { .val_bool = false },
79 );
80 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
81 { .val_bool = true, .match_profile = "datacenter", },
82 { .val_bool = false },
83 );
84 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
85 { .val_bool = true, .match_profile = "datacenter", },
86 { .val_bool = false },
87 );
88 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
91 );
92 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
93 { .val_ulong = 10, .match_profile = "datacenter", },
94 { .val_ulong = 120 },
95 );
96 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
97 { .val_ulong = 9, .match_profile = "datacenter", },
98 { .val_ulong = 180 },
99 );
100 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
101 { .val_ulong = 3, .match_profile = "datacenter", },
102 { .val_ulong = 60 },
103 );
104 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
105 { .val_bool = false, .match_profile = "datacenter", },
106 { .val_bool = false, .match_version = "< 7.4", },
107 { .val_bool = true },
108 );
109 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
110 { .val_bool = false, .match_version = "< 7.6", },
111 { .val_bool = true },
112 );
113 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
114 { .val_bool = false, .match_version = "< 8.3", },
115 { .val_bool = true },
116 );
117 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
118 { .val_bool = false, .match_version = "< 8.3", },
119 { .val_bool = true },
120 );
121
122 DEFINE_HOOK(bgp_inst_config_write,
123 (struct bgp *bgp, struct vty *vty),
124 (bgp, vty));
125 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
126 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
127
128 static struct peer_group *listen_range_exists(struct bgp *bgp,
129 struct prefix *range, int exact);
130
131 /* Show BGP peer's information. */
132 enum show_type {
133 show_all,
134 show_peer,
135 show_ipv4_all,
136 show_ipv6_all,
137 show_ipv4_peer,
138 show_ipv6_peer
139 };
140
141 static struct peer_group *listen_range_exists(struct bgp *bgp,
142 struct prefix *range, int exact);
143
144 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
145 struct bgp *bgp);
146
147 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
148 enum show_type type,
149 const char *ip_str,
150 afi_t afi, bool use_json);
151
152 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
153 {
154 switch (afi) {
155 case AFI_IP:
156 switch (safi) {
157 case SAFI_UNICAST:
158 return BGP_IPV4_NODE;
159 case SAFI_MULTICAST:
160 return BGP_IPV4M_NODE;
161 case SAFI_LABELED_UNICAST:
162 return BGP_IPV4L_NODE;
163 case SAFI_MPLS_VPN:
164 return BGP_VPNV4_NODE;
165 case SAFI_FLOWSPEC:
166 return BGP_FLOWSPECV4_NODE;
167 case SAFI_UNSPEC:
168 case SAFI_ENCAP:
169 case SAFI_EVPN:
170 case SAFI_MAX:
171 /* not expected */
172 return BGP_IPV4_NODE;
173 }
174 break;
175 case AFI_IP6:
176 switch (safi) {
177 case SAFI_UNICAST:
178 return BGP_IPV6_NODE;
179 case SAFI_MULTICAST:
180 return BGP_IPV6M_NODE;
181 case SAFI_LABELED_UNICAST:
182 return BGP_IPV6L_NODE;
183 case SAFI_MPLS_VPN:
184 return BGP_VPNV6_NODE;
185 case SAFI_FLOWSPEC:
186 return BGP_FLOWSPECV6_NODE;
187 case SAFI_UNSPEC:
188 case SAFI_ENCAP:
189 case SAFI_EVPN:
190 case SAFI_MAX:
191 /* not expected and the return value seems wrong */
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 /* unset srv6 locator */
286 static int bgp_srv6_locator_unset(struct bgp *bgp)
287 {
288 int ret;
289 struct listnode *node, *nnode;
290 struct srv6_locator_chunk *chunk;
291 struct bgp_srv6_function *func;
292 struct bgp *bgp_vrf;
293
294 /* release chunk notification via ZAPI */
295 ret = bgp_zebra_srv6_manager_release_locator_chunk(
296 bgp->srv6_locator_name);
297 if (ret < 0)
298 return -1;
299
300 /* refresh chunks */
301 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
302 listnode_delete(bgp->srv6_locator_chunks, chunk);
303 srv6_locator_chunk_free(&chunk);
304 }
305
306 /* refresh functions */
307 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
308 listnode_delete(bgp->srv6_functions, func);
309 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
310 }
311
312 /* refresh tovpn_sid */
313 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
314 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
315 continue;
316
317 /* refresh vpnv4 tovpn_sid */
318 XFREE(MTYPE_BGP_SRV6_SID,
319 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
320
321 /* refresh vpnv6 tovpn_sid */
322 XFREE(MTYPE_BGP_SRV6_SID,
323 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
324
325 /* refresh per-vrf tovpn_sid */
326 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
327 }
328
329 /* update vpn bgp processes */
330 vpn_leak_postchange_all();
331
332 /* refresh tovpn_sid_locator */
333 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
334 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
335 continue;
336
337 /* refresh vpnv4 tovpn_sid_locator */
338 srv6_locator_chunk_free(
339 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
340
341 /* refresh vpnv6 tovpn_sid_locator */
342 srv6_locator_chunk_free(
343 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
344
345 /* refresh per-vrf tovpn_sid_locator */
346 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
347 }
348
349 /* clear locator name */
350 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
351
352 return 0;
353 }
354
355 /* Utility function to get address family from current node. */
356 afi_t bgp_node_afi(struct vty *vty)
357 {
358 afi_t afi;
359 switch (vty->node) {
360 case BGP_IPV6_NODE:
361 case BGP_IPV6M_NODE:
362 case BGP_IPV6L_NODE:
363 case BGP_VPNV6_NODE:
364 case BGP_FLOWSPECV6_NODE:
365 afi = AFI_IP6;
366 break;
367 case BGP_EVPN_NODE:
368 afi = AFI_L2VPN;
369 break;
370 default:
371 afi = AFI_IP;
372 break;
373 }
374 return afi;
375 }
376
377 /* Utility function to get subsequent address family from current
378 node. */
379 safi_t bgp_node_safi(struct vty *vty)
380 {
381 safi_t safi;
382 switch (vty->node) {
383 case BGP_VPNV4_NODE:
384 case BGP_VPNV6_NODE:
385 safi = SAFI_MPLS_VPN;
386 break;
387 case BGP_IPV4M_NODE:
388 case BGP_IPV6M_NODE:
389 safi = SAFI_MULTICAST;
390 break;
391 case BGP_EVPN_NODE:
392 safi = SAFI_EVPN;
393 break;
394 case BGP_IPV4L_NODE:
395 case BGP_IPV6L_NODE:
396 safi = SAFI_LABELED_UNICAST;
397 break;
398 case BGP_FLOWSPECV4_NODE:
399 case BGP_FLOWSPECV6_NODE:
400 safi = SAFI_FLOWSPEC;
401 break;
402 default:
403 safi = SAFI_UNICAST;
404 break;
405 }
406 return safi;
407 }
408
409 /**
410 * Converts an AFI in string form to afi_t
411 *
412 * @param afi string, one of
413 * - "ipv4"
414 * - "ipv6"
415 * - "l2vpn"
416 * @return the corresponding afi_t
417 */
418 afi_t bgp_vty_afi_from_str(const char *afi_str)
419 {
420 afi_t afi = AFI_MAX; /* unknown */
421 if (strmatch(afi_str, "ipv4"))
422 afi = AFI_IP;
423 else if (strmatch(afi_str, "ipv6"))
424 afi = AFI_IP6;
425 else if (strmatch(afi_str, "l2vpn"))
426 afi = AFI_L2VPN;
427 return afi;
428 }
429
430 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
431 afi_t *afi)
432 {
433 int ret = 0;
434 if (argv_find(argv, argc, "ipv4", index)) {
435 ret = 1;
436 if (afi)
437 *afi = AFI_IP;
438 } else if (argv_find(argv, argc, "ipv6", index)) {
439 ret = 1;
440 if (afi)
441 *afi = AFI_IP6;
442 } else if (argv_find(argv, argc, "l2vpn", index)) {
443 ret = 1;
444 if (afi)
445 *afi = AFI_L2VPN;
446 }
447 return ret;
448 }
449
450 /* supports <unicast|multicast|vpn|labeled-unicast> */
451 safi_t bgp_vty_safi_from_str(const char *safi_str)
452 {
453 safi_t safi = SAFI_MAX; /* unknown */
454 if (strmatch(safi_str, "multicast"))
455 safi = SAFI_MULTICAST;
456 else if (strmatch(safi_str, "unicast"))
457 safi = SAFI_UNICAST;
458 else if (strmatch(safi_str, "vpn"))
459 safi = SAFI_MPLS_VPN;
460 else if (strmatch(safi_str, "evpn"))
461 safi = SAFI_EVPN;
462 else if (strmatch(safi_str, "labeled-unicast"))
463 safi = SAFI_LABELED_UNICAST;
464 else if (strmatch(safi_str, "flowspec"))
465 safi = SAFI_FLOWSPEC;
466 return safi;
467 }
468
469 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
470 safi_t *safi)
471 {
472 int ret = 0;
473 if (argv_find(argv, argc, "unicast", index)) {
474 ret = 1;
475 if (safi)
476 *safi = SAFI_UNICAST;
477 } else if (argv_find(argv, argc, "multicast", index)) {
478 ret = 1;
479 if (safi)
480 *safi = SAFI_MULTICAST;
481 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_LABELED_UNICAST;
485 } else if (argv_find(argv, argc, "vpn", index)) {
486 ret = 1;
487 if (safi)
488 *safi = SAFI_MPLS_VPN;
489 } else if (argv_find(argv, argc, "evpn", index)) {
490 ret = 1;
491 if (safi)
492 *safi = SAFI_EVPN;
493 } else if (argv_find(argv, argc, "flowspec", index)) {
494 ret = 1;
495 if (safi)
496 *safi = SAFI_FLOWSPEC;
497 }
498 return ret;
499 }
500
501 /*
502 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
503 *
504 * afi
505 * address-family identifier
506 *
507 * safi
508 * subsequent address-family identifier
509 *
510 * Returns:
511 * default_af string corresponding to the supplied afi/safi pair.
512 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
513 * return -1.
514 */
515 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
516 {
517 switch (afi) {
518 case AFI_IP:
519 switch (safi) {
520 case SAFI_UNICAST:
521 return "ipv4-unicast";
522 case SAFI_MULTICAST:
523 return "ipv4-multicast";
524 case SAFI_MPLS_VPN:
525 return "ipv4-vpn";
526 case SAFI_ENCAP:
527 return "ipv4-encap";
528 case SAFI_LABELED_UNICAST:
529 return "ipv4-labeled-unicast";
530 case SAFI_FLOWSPEC:
531 return "ipv4-flowspec";
532 case SAFI_UNSPEC:
533 case SAFI_EVPN:
534 case SAFI_MAX:
535 return "unknown-afi/safi";
536 }
537 break;
538 case AFI_IP6:
539 switch (safi) {
540 case SAFI_UNICAST:
541 return "ipv6-unicast";
542 case SAFI_MULTICAST:
543 return "ipv6-multicast";
544 case SAFI_MPLS_VPN:
545 return "ipv6-vpn";
546 case SAFI_ENCAP:
547 return "ipv6-encap";
548 case SAFI_LABELED_UNICAST:
549 return "ipv6-labeled-unicast";
550 case SAFI_FLOWSPEC:
551 return "ipv6-flowspec";
552 case SAFI_UNSPEC:
553 case SAFI_EVPN:
554 case SAFI_MAX:
555 return "unknown-afi/safi";
556 }
557 break;
558 case AFI_L2VPN:
559 switch (safi) {
560 case SAFI_EVPN:
561 return "l2vpn-evpn";
562 case SAFI_UNICAST:
563 case SAFI_MULTICAST:
564 case SAFI_MPLS_VPN:
565 case SAFI_ENCAP:
566 case SAFI_LABELED_UNICAST:
567 case SAFI_FLOWSPEC:
568 case SAFI_UNSPEC:
569 case SAFI_MAX:
570 return "unknown-afi/safi";
571 }
572 break;
573 case AFI_UNSPEC:
574 case AFI_MAX:
575 return "unknown-afi/safi";
576 }
577 /* all AFIs are accounted for above, so this shouldn't happen */
578
579 assert(!"Reached end of function where we did not expect to");
580 }
581
582 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
583 enum bgp_instance_type inst_type, const char *as_pretty,
584 enum asnotation_mode asnotation)
585 {
586 int ret = bgp_get(bgp, as, name, inst_type, as_pretty, asnotation);
587
588 if (ret == BGP_CREATED) {
589 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
590 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
591
592 if (DFLT_BGP_IMPORT_CHECK)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
594 if (DFLT_BGP_SHOW_HOSTNAME)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
596 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
598 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
600 if (DFLT_BGP_DETERMINISTIC_MED)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
602 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
604 if (DFLT_BGP_SUPPRESS_DUPLICATES)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
606 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
607 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
608 if (DFLT_BGP_HARD_ADMIN_RESET)
609 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
610
611 ret = BGP_SUCCESS;
612 }
613 return ret;
614 }
615
616 /*
617 * bgp_vty_find_and_parse_afi_safi_bgp
618 *
619 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
620 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
621 * to appropriate values for the calling function. This is to allow the
622 * calling function to make decisions appropriate for the show command
623 * that is being parsed.
624 *
625 * The show commands are generally of the form:
626 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
627 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
628 *
629 * Since we use argv_find if the show command in particular doesn't have:
630 * [ip]
631 * [<view|vrf> VIEWVRFNAME]
632 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
633 * The command parsing should still be ok.
634 *
635 * vty -> The vty for the command so we can output some useful data in
636 * the event of a parse error in the vrf.
637 * argv -> The command tokens
638 * argc -> How many command tokens we have
639 * idx -> The current place in the command, generally should be 0 for this
640 * function
641 * afi -> The parsed afi if it was included in the show command, returned here
642 * safi -> The parsed safi if it was included in the show command, returned here
643 * bgp -> Pointer to the bgp data structure we need to fill in.
644 * use_json -> json is configured or not
645 *
646 * The function returns the correct location in the parse tree for the
647 * last token found.
648 *
649 * Returns 0 for failure to parse correctly, else the idx position of where
650 * it found the last token.
651 */
652 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
653 struct cmd_token **argv, int argc,
654 int *idx, afi_t *afi, safi_t *safi,
655 struct bgp **bgp, bool use_json)
656 {
657 char *vrf_name = NULL;
658
659 assert(afi);
660 assert(safi);
661 assert(bgp);
662
663 if (argv_find(argv, argc, "ip", idx))
664 *afi = AFI_IP;
665
666 if (argv_find(argv, argc, "view", idx))
667 vrf_name = argv[*idx + 1]->arg;
668 else if (argv_find(argv, argc, "vrf", idx)) {
669 vrf_name = argv[*idx + 1]->arg;
670 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
671 vrf_name = NULL;
672 }
673 if (vrf_name) {
674 if (strmatch(vrf_name, "all"))
675 *bgp = NULL;
676 else {
677 *bgp = bgp_lookup_by_name(vrf_name);
678 if (!*bgp) {
679 if (use_json) {
680 json_object *json = NULL;
681 json = json_object_new_object();
682 json_object_string_add(
683 json, "warning",
684 "View/Vrf is unknown");
685 vty_json(vty, json);
686 }
687 else
688 vty_out(vty, "View/Vrf %s is unknown\n",
689 vrf_name);
690 *idx = 0;
691 return 0;
692 }
693 }
694 } else {
695 *bgp = bgp_get_default();
696 if (!*bgp) {
697 if (use_json) {
698 json_object *json = NULL;
699 json = json_object_new_object();
700 json_object_string_add(
701 json, "warning",
702 "Default BGP instance not found");
703 vty_json(vty, json);
704 }
705 else
706 vty_out(vty,
707 "Default BGP instance not found\n");
708 *idx = 0;
709 return 0;
710 }
711 }
712
713 if (argv_find_and_parse_afi(argv, argc, idx, afi))
714 argv_find_and_parse_safi(argv, argc, idx, safi);
715
716 *idx += 1;
717 return *idx;
718 }
719
720 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
721 {
722 struct interface *ifp = NULL;
723 struct listnode *node;
724 struct bgp_listener *listener;
725 union sockunion all_su;
726
727 if (su->sa.sa_family == AF_INET) {
728 (void)str2sockunion("0.0.0.0", &all_su);
729 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
730 } else if (su->sa.sa_family == AF_INET6) {
731 (void)str2sockunion("::", &all_su);
732 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
733 su->sin6.sin6_scope_id,
734 bgp->vrf_id);
735 }
736
737 if (ifp) {
738 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
739 if (sockunion_family(su) !=
740 sockunion_family(&listener->su))
741 continue;
742
743 /* If 0.0.0.0/:: is a listener, then treat as self and
744 * reject.
745 */
746 if (!sockunion_cmp(&listener->su, su) ||
747 !sockunion_cmp(&listener->su, &all_su))
748 return true;
749 }
750 }
751
752 return false;
753 }
754
755 /* Utility function for looking up peer from VTY. */
756 /* This is used only for configuration, so disallow if attempted on
757 * a dynamic neighbor.
758 */
759 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
760 {
761 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
762 int ret;
763 union sockunion su;
764 struct peer *peer;
765
766 if (!bgp) {
767 return NULL;
768 }
769
770 ret = str2sockunion(ip_str, &su);
771 if (ret < 0) {
772 peer = peer_lookup_by_conf_if(bgp, ip_str);
773 if (!peer) {
774 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
775 == NULL) {
776 vty_out(vty,
777 "%% Malformed address or name: %s\n",
778 ip_str);
779 return NULL;
780 }
781 }
782 } else {
783 peer = peer_lookup(bgp, &su);
784 if (!peer) {
785 vty_out(vty,
786 "%% Specify remote-as or peer-group commands first\n");
787 return NULL;
788 }
789 if (peer_dynamic_neighbor(peer)) {
790 vty_out(vty,
791 "%% Operation not allowed on a dynamic neighbor\n");
792 return NULL;
793 }
794 }
795 return peer;
796 }
797
798 /* Utility function for looking up peer or peer group. */
799 /* This is used only for configuration, so disallow if attempted on
800 * a dynamic neighbor.
801 */
802 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
803 {
804 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
805 int ret;
806 union sockunion su;
807 struct peer *peer = NULL;
808 struct peer_group *group = NULL;
809
810 if (!bgp) {
811 return NULL;
812 }
813
814 ret = str2sockunion(peer_str, &su);
815 if (ret == 0) {
816 /* IP address, locate peer. */
817 peer = peer_lookup(bgp, &su);
818 } else {
819 /* Not IP, could match either peer configured on interface or a
820 * group. */
821 peer = peer_lookup_by_conf_if(bgp, peer_str);
822 if (!peer)
823 group = peer_group_lookup(bgp, peer_str);
824 }
825
826 if (peer) {
827 if (peer_dynamic_neighbor(peer)) {
828 zlog_warn(
829 "%pBP: Operation not allowed on a dynamic neighbor",
830 peer);
831 vty_out(vty,
832 "%% Operation not allowed on a dynamic neighbor\n");
833 return NULL;
834 }
835
836 return peer;
837 }
838
839 if (group)
840 return group->conf;
841
842 zlog_warn("Specify remote-as or peer-group commands first before: %s",
843 vty->buf);
844 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
845
846 return NULL;
847 }
848
849 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
850 {
851 const char *str = NULL;
852
853 switch (ret) {
854 case BGP_SUCCESS:
855 case BGP_CREATED:
856 case BGP_GR_NO_OPERATION:
857 break;
858 case BGP_ERR_INVALID_VALUE:
859 str = "Invalid value";
860 break;
861 case BGP_ERR_INVALID_FLAG:
862 str = "Invalid flag";
863 break;
864 case BGP_ERR_PEER_GROUP_SHUTDOWN:
865 str = "Peer-group has been shutdown. Activate the peer-group first";
866 break;
867 case BGP_ERR_PEER_FLAG_CONFLICT:
868 str = "Can't set override-capability and strict-capability-match at the same time";
869 break;
870 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
871 str = "Specify remote-as or peer-group remote AS first";
872 break;
873 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
874 str = "Cannot change the peer-group. Deconfigure first";
875 break;
876 case BGP_ERR_PEER_GROUP_MISMATCH:
877 str = "Peer is not a member of this peer-group";
878 break;
879 case BGP_ERR_PEER_FILTER_CONFLICT:
880 str = "Prefix/distribute list can not co-exist";
881 break;
882 case BGP_ERR_NOT_INTERNAL_PEER:
883 str = "Invalid command. Not an internal neighbor";
884 break;
885 case BGP_ERR_REMOVE_PRIVATE_AS:
886 str = "remove-private-AS cannot be configured for IBGP peers";
887 break;
888 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
889 str = "Cannot have local-as same as BGP AS number";
890 break;
891 case BGP_ERR_TCPSIG_FAILED:
892 str = "Error while applying TCP-Sig to session(s)";
893 break;
894 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
895 str = "ebgp-multihop and ttl-security cannot be configured together";
896 break;
897 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
898 str = "ttl-security only allowed for EBGP peers";
899 break;
900 case BGP_ERR_AS_OVERRIDE:
901 str = "as-override cannot be configured for IBGP peers";
902 break;
903 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
904 str = "Invalid limit for number of dynamic neighbors";
905 break;
906 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
907 str = "Dynamic neighbor listen range already exists";
908 break;
909 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
910 str = "Operation not allowed on a dynamic neighbor";
911 break;
912 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
913 str = "Operation not allowed on a directly connected neighbor";
914 break;
915 case BGP_ERR_PEER_SAFI_CONFLICT:
916 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
917 break;
918 case BGP_ERR_GR_INVALID_CMD:
919 str = "The Graceful Restart command used is not valid at this moment.";
920 break;
921 case BGP_ERR_GR_OPERATION_FAILED:
922 str = "The Graceful Restart Operation failed due to an err.";
923 break;
924 case BGP_ERR_PEER_GROUP_MEMBER:
925 str = "Peer-group member cannot override remote-as of peer-group.";
926 break;
927 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
928 str = "Peer-group members must be all internal or all external.";
929 break;
930 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
931 str = "Range specified cannot be deleted because it is not part of current config.";
932 break;
933 case BGP_ERR_INSTANCE_MISMATCH:
934 str = "Instance specified does not match the current instance.";
935 break;
936 case BGP_ERR_NO_INTERFACE_CONFIG:
937 str = "Interface specified is not being used for interface based peer.";
938 break;
939 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
940 str = "No configuration already specified for soft reconfiguration.";
941 break;
942 case BGP_ERR_AS_MISMATCH:
943 str = "BGP is already running.";
944 break;
945 case BGP_ERR_AF_UNCONFIGURED:
946 str = "AFI/SAFI specified is not currently configured.";
947 break;
948 case BGP_ERR_INVALID_AS:
949 str = "Confederation AS specified is the same AS as our AS.";
950 break;
951 case BGP_ERR_INVALID_ROLE_NAME:
952 str = "Invalid role name";
953 break;
954 case BGP_ERR_INVALID_INTERNAL_ROLE:
955 str = "External roles can be set only on eBGP session";
956 break;
957 }
958 if (str) {
959 vty_out(vty, "%% %s\n", str);
960 return CMD_WARNING_CONFIG_FAILED;
961 }
962 return CMD_SUCCESS;
963 }
964
965 /* BGP clear sort. */
966 enum clear_sort {
967 clear_all,
968 clear_peer,
969 clear_group,
970 clear_external,
971 clear_as
972 };
973
974 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
975 safi_t safi, int error)
976 {
977 switch (error) {
978 case BGP_ERR_AF_UNCONFIGURED:
979 if (vty)
980 vty_out(vty,
981 "%% BGP: Enable %s address family for the neighbor %s\n",
982 get_afi_safi_str(afi, safi, false), peer->host);
983 else
984 zlog_warn(
985 "%% BGP: Enable %s address family for the neighbor %s",
986 get_afi_safi_str(afi, safi, false), peer->host);
987 break;
988 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
989 if (vty)
990 vty_out(vty,
991 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
992 peer->host);
993 else
994 zlog_warn(
995 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
996 peer->host);
997 break;
998 default:
999 break;
1000 }
1001 }
1002
1003 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
1004 struct listnode **nnode, enum bgp_clear_type stype)
1005 {
1006 int ret = 0;
1007 struct peer_af *paf;
1008
1009 /* if afi/.safi not specified, spin thru all of them */
1010 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1011 afi_t tmp_afi;
1012 safi_t tmp_safi;
1013 enum bgp_af_index index;
1014
1015 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1016 paf = peer->peer_af_array[index];
1017 if (!paf)
1018 continue;
1019
1020 if (paf && paf->subgroup)
1021 SET_FLAG(paf->subgroup->sflags,
1022 SUBGRP_STATUS_FORCE_UPDATES);
1023
1024 tmp_afi = paf->afi;
1025 tmp_safi = paf->safi;
1026 if (!peer->afc[tmp_afi][tmp_safi])
1027 continue;
1028
1029 if (stype == BGP_CLEAR_SOFT_NONE)
1030 ret = peer_clear(peer, nnode);
1031 else
1032 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1033 stype);
1034 }
1035 /* if afi specified and safi not, spin thru safis on this afi */
1036 } else if (safi == SAFI_UNSPEC) {
1037 safi_t tmp_safi;
1038
1039 for (tmp_safi = SAFI_UNICAST;
1040 tmp_safi < SAFI_MAX; tmp_safi++) {
1041 if (!peer->afc[afi][tmp_safi])
1042 continue;
1043
1044 paf = peer_af_find(peer, afi, tmp_safi);
1045 if (paf && paf->subgroup)
1046 SET_FLAG(paf->subgroup->sflags,
1047 SUBGRP_STATUS_FORCE_UPDATES);
1048
1049 if (stype == BGP_CLEAR_SOFT_NONE)
1050 ret = peer_clear(peer, nnode);
1051 else
1052 ret = peer_clear_soft(peer, afi,
1053 tmp_safi, stype);
1054 }
1055 /* both afi/safi specified, let the caller know if not defined */
1056 } else {
1057 if (!peer->afc[afi][safi])
1058 return 1;
1059
1060 paf = peer_af_find(peer, afi, safi);
1061 if (paf && paf->subgroup)
1062 SET_FLAG(paf->subgroup->sflags,
1063 SUBGRP_STATUS_FORCE_UPDATES);
1064
1065 if (stype == BGP_CLEAR_SOFT_NONE)
1066 ret = peer_clear(peer, nnode);
1067 else
1068 ret = peer_clear_soft(peer, afi, safi, stype);
1069 }
1070
1071 return ret;
1072 }
1073
1074 /* `clear ip bgp' functions. */
1075 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1076 enum clear_sort sort, enum bgp_clear_type stype,
1077 const char *arg)
1078 {
1079 int ret = 0;
1080 bool found = false;
1081 struct peer *peer;
1082
1083 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1084
1085 /* Clear all neighbors. */
1086 /*
1087 * Pass along pointer to next node to peer_clear() when walking all
1088 * nodes on the BGP instance as that may get freed if it is a
1089 * doppelganger
1090 */
1091 if (sort == clear_all) {
1092 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1093
1094 bgp_peer_gr_flags_update(peer);
1095
1096 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1097 gr_router_detected = true;
1098
1099 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1100 stype);
1101
1102 if (ret < 0)
1103 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1104 }
1105
1106 if (gr_router_detected
1107 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1108 bgp_zebra_send_capabilities(bgp, false);
1109 } else if (!gr_router_detected
1110 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1111 bgp_zebra_send_capabilities(bgp, true);
1112 }
1113
1114 /* This is to apply read-only mode on this clear. */
1115 if (stype == BGP_CLEAR_SOFT_NONE)
1116 bgp->update_delay_over = 0;
1117
1118 return CMD_SUCCESS;
1119 }
1120
1121 /* Clear specified neighbor. */
1122 if (sort == clear_peer) {
1123 union sockunion su;
1124
1125 /* Make sockunion for lookup. */
1126 ret = str2sockunion(arg, &su);
1127 if (ret < 0) {
1128 peer = peer_lookup_by_conf_if(bgp, arg);
1129 if (!peer) {
1130 peer = peer_lookup_by_hostname(bgp, arg);
1131 if (!peer) {
1132 vty_out(vty,
1133 "Malformed address or name: %s\n",
1134 arg);
1135 return CMD_WARNING;
1136 }
1137 }
1138 } else {
1139 peer = peer_lookup(bgp, &su);
1140 if (!peer) {
1141 vty_out(vty,
1142 "%% BGP: Unknown neighbor - \"%s\"\n",
1143 arg);
1144 return CMD_WARNING;
1145 }
1146 }
1147
1148 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1149 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1150
1151 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1152
1153 /* if afi/safi not defined for this peer, let caller know */
1154 if (ret == 1)
1155 ret = BGP_ERR_AF_UNCONFIGURED;
1156
1157 if (ret < 0)
1158 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1159
1160 return CMD_SUCCESS;
1161 }
1162
1163 /* Clear all neighbors belonging to a specific peer-group. */
1164 if (sort == clear_group) {
1165 struct peer_group *group;
1166
1167 group = peer_group_lookup(bgp, arg);
1168 if (!group) {
1169 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1170 return CMD_WARNING;
1171 }
1172
1173 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1174 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1175
1176 if (ret < 0)
1177 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1178 else
1179 found = true;
1180 }
1181
1182 if (!found)
1183 vty_out(vty,
1184 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1185 get_afi_safi_str(afi, safi, false), arg);
1186
1187 return CMD_SUCCESS;
1188 }
1189
1190 /* Clear all external (eBGP) neighbors. */
1191 if (sort == clear_external) {
1192 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1193 if (peer->sort == BGP_PEER_IBGP)
1194 continue;
1195
1196 bgp_peer_gr_flags_update(peer);
1197
1198 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1199 gr_router_detected = true;
1200
1201 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1202
1203 if (ret < 0)
1204 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1205 else
1206 found = true;
1207 }
1208
1209 if (gr_router_detected
1210 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1211 bgp_zebra_send_capabilities(bgp, false);
1212 } else if (!gr_router_detected
1213 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1214 bgp_zebra_send_capabilities(bgp, true);
1215 }
1216
1217 if (!found)
1218 vty_out(vty,
1219 "%% BGP: No external %s peer is configured\n",
1220 get_afi_safi_str(afi, safi, false));
1221
1222 return CMD_SUCCESS;
1223 }
1224
1225 /* Clear all neighbors belonging to a specific AS. */
1226 if (sort == clear_as) {
1227 as_t as;
1228
1229 if (!asn_str2asn(arg, &as)) {
1230 vty_out(vty, "%% BGP: No such AS %s\n", arg);
1231 return CMD_WARNING;
1232 }
1233
1234 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1235 if (peer->as != as)
1236 continue;
1237
1238 bgp_peer_gr_flags_update(peer);
1239
1240 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1241 gr_router_detected = true;
1242
1243 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1244
1245 if (ret < 0)
1246 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1247 else
1248 found = true;
1249 }
1250
1251 if (gr_router_detected
1252 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1253 bgp_zebra_send_capabilities(bgp, false);
1254 } else if (!gr_router_detected
1255 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1256 bgp_zebra_send_capabilities(bgp, true);
1257 }
1258
1259 if (!found)
1260 vty_out(vty,
1261 "%% BGP: No %s peer is configured with AS %s\n",
1262 get_afi_safi_str(afi, safi, false), arg);
1263
1264 return CMD_SUCCESS;
1265 }
1266
1267 return CMD_SUCCESS;
1268 }
1269
1270 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1271 safi_t safi, enum clear_sort sort,
1272 enum bgp_clear_type stype, const char *arg)
1273 {
1274 struct bgp *bgp;
1275
1276 /* BGP structure lookup. */
1277 if (name) {
1278 bgp = bgp_lookup_by_name(name);
1279 if (bgp == NULL) {
1280 vty_out(vty, "Can't find BGP instance %s\n", name);
1281 return CMD_WARNING;
1282 }
1283 } else {
1284 bgp = bgp_get_default();
1285 if (bgp == NULL) {
1286 vty_out(vty, "No BGP process is configured\n");
1287 return CMD_WARNING;
1288 }
1289 }
1290
1291 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1292 }
1293
1294 /* clear soft inbound */
1295 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1296 {
1297 afi_t afi;
1298 safi_t safi;
1299
1300 FOREACH_AFI_SAFI (afi, safi)
1301 bgp_clear_vty(vty, name, afi, safi, clear_all,
1302 BGP_CLEAR_SOFT_IN, NULL);
1303 }
1304
1305 /* clear soft outbound */
1306 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1307 {
1308 afi_t afi;
1309 safi_t safi;
1310
1311 FOREACH_AFI_SAFI (afi, safi)
1312 bgp_clear_vty(vty, name, afi, safi, clear_all,
1313 BGP_CLEAR_SOFT_OUT, NULL);
1314 }
1315
1316
1317 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1318 {
1319 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1320 }
1321
1322 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1323 uint64_t flag, int set)
1324 {
1325 int ret;
1326 struct peer *peer;
1327
1328 peer = peer_and_group_lookup_vty(vty, ip_str);
1329 if (!peer)
1330 return CMD_WARNING_CONFIG_FAILED;
1331
1332 /*
1333 * If 'neighbor <interface>', then this is for directly connected peers,
1334 * we should not accept disable-connected-check.
1335 */
1336 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1337 vty_out(vty,
1338 "%s is directly connected peer, cannot accept disable-connected-check\n",
1339 ip_str);
1340 return CMD_WARNING_CONFIG_FAILED;
1341 }
1342
1343 if (!set && flag == PEER_FLAG_SHUTDOWN)
1344 peer_tx_shutdown_message_unset(peer);
1345
1346 if (set)
1347 ret = peer_flag_set(peer, flag);
1348 else
1349 ret = peer_flag_unset(peer, flag);
1350
1351 return bgp_vty_return(vty, ret);
1352 }
1353
1354 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1355 {
1356 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1357 }
1358
1359 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1360 uint64_t flag)
1361 {
1362 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1363 }
1364
1365 #include "bgpd/bgp_vty_clippy.c"
1366
1367 DEFUN_HIDDEN (bgp_local_mac,
1368 bgp_local_mac_cmd,
1369 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1370 BGP_STR
1371 "Local MAC config\n"
1372 "VxLAN Network Identifier\n"
1373 "VNI number\n"
1374 "local mac\n"
1375 "mac address\n"
1376 "mac-mobility sequence\n"
1377 "seq number\n")
1378 {
1379 int rv;
1380 vni_t vni;
1381 struct ethaddr mac;
1382 struct ipaddr ip;
1383 uint32_t seq;
1384 struct bgp *bgp;
1385
1386 vni = strtoul(argv[3]->arg, NULL, 10);
1387 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1388 vty_out(vty, "%% Malformed MAC address\n");
1389 return CMD_WARNING;
1390 }
1391 memset(&ip, 0, sizeof(ip));
1392 seq = strtoul(argv[7]->arg, NULL, 10);
1393
1394 bgp = bgp_get_default();
1395 if (!bgp) {
1396 vty_out(vty, "Default BGP instance is not there\n");
1397 return CMD_WARNING;
1398 }
1399
1400 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1401 zero_esi);
1402 if (rv < 0) {
1403 vty_out(vty, "Internal error\n");
1404 return CMD_WARNING;
1405 }
1406
1407 return CMD_SUCCESS;
1408 }
1409
1410 DEFUN_HIDDEN (no_bgp_local_mac,
1411 no_bgp_local_mac_cmd,
1412 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1413 NO_STR
1414 BGP_STR
1415 "Local MAC config\n"
1416 "VxLAN Network Identifier\n"
1417 "VNI number\n"
1418 "local mac\n"
1419 "mac address\n")
1420 {
1421 int rv;
1422 vni_t vni;
1423 struct ethaddr mac;
1424 struct ipaddr ip;
1425 struct bgp *bgp;
1426
1427 vni = strtoul(argv[4]->arg, NULL, 10);
1428 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1429 vty_out(vty, "%% Malformed MAC address\n");
1430 return CMD_WARNING;
1431 }
1432 memset(&ip, 0, sizeof(ip));
1433
1434 bgp = bgp_get_default();
1435 if (!bgp) {
1436 vty_out(vty, "Default BGP instance is not there\n");
1437 return CMD_WARNING;
1438 }
1439
1440 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1441 if (rv < 0) {
1442 vty_out(vty, "Internal error\n");
1443 return CMD_WARNING;
1444 }
1445
1446 return CMD_SUCCESS;
1447 }
1448
1449 DEFUN (no_synchronization,
1450 no_synchronization_cmd,
1451 "no synchronization",
1452 NO_STR
1453 "Perform IGP synchronization\n")
1454 {
1455 return CMD_SUCCESS;
1456 }
1457
1458 DEFUN (no_auto_summary,
1459 no_auto_summary_cmd,
1460 "no auto-summary",
1461 NO_STR
1462 "Enable automatic network number summarization\n")
1463 {
1464 return CMD_SUCCESS;
1465 }
1466
1467 /* "router bgp" commands. */
1468 DEFUN_NOSH (router_bgp,
1469 router_bgp_cmd,
1470 "router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
1471 ROUTER_STR
1472 BGP_STR
1473 AS_STR
1474 BGP_INSTANCE_HELP_STR
1475 "Force the AS notation output\n"
1476 "use 'AA.BB' format for AS 4 byte values\n"
1477 "use 'AA.BB' format for all AS values\n"
1478 "use plain format for all AS values\n")
1479 {
1480 int idx_asn = 2;
1481 int idx_view_vrf = 3;
1482 int idx_vrf = 4;
1483 int is_new_bgp = 0;
1484 int idx_asnotation = 3;
1485 int idx_asnotation_kind = 4;
1486 enum asnotation_mode asnotation = ASNOTATION_UNDEFINED;
1487 int ret;
1488 as_t as;
1489 struct bgp *bgp;
1490 const char *name = NULL;
1491 enum bgp_instance_type inst_type;
1492
1493 // "router bgp" without an ASN
1494 if (argc == 2) {
1495 // Pending: Make VRF option available for ASN less config
1496 bgp = bgp_get_default();
1497
1498 if (bgp == NULL) {
1499 vty_out(vty, "%% No BGP process is configured\n");
1500 return CMD_WARNING_CONFIG_FAILED;
1501 }
1502
1503 if (listcount(bm->bgp) > 1) {
1504 vty_out(vty, "%% Please specify ASN and VRF\n");
1505 return CMD_WARNING_CONFIG_FAILED;
1506 }
1507 }
1508
1509 // "router bgp X"
1510 else {
1511 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1512 vty_out(vty, "%% BGP: No such AS %s\n",
1513 argv[idx_asn]->arg);
1514 return CMD_WARNING_CONFIG_FAILED;
1515 }
1516
1517 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1518 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1519 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1520
1521 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1522
1523 if (argv_find(argv, argc, "VIEWVRFNAME", &idx_vrf)) {
1524 idx_view_vrf = idx_vrf - 1;
1525 if (argv[idx_view_vrf]->text) {
1526 name = argv[idx_vrf]->arg;
1527
1528 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1529 if (strmatch(name, VRF_DEFAULT_NAME))
1530 name = NULL;
1531 else
1532 inst_type =
1533 BGP_INSTANCE_TYPE_VRF;
1534 } else if (!strcmp(argv[idx_view_vrf]->text,
1535 "view"))
1536 inst_type = BGP_INSTANCE_TYPE_VIEW;
1537 }
1538 }
1539 if (argv_find(argv, argc, "as-notation", &idx_asnotation)) {
1540 idx_asnotation_kind = idx_asnotation + 1;
1541 if (strmatch(argv[idx_asnotation_kind]->text, "dot+"))
1542 asnotation = ASNOTATION_DOTPLUS;
1543 else if (strmatch(argv[idx_asnotation_kind]->text,
1544 "dot"))
1545 asnotation = ASNOTATION_DOT;
1546 else if (strmatch(argv[idx_asnotation_kind]->text,
1547 "plain"))
1548 asnotation = ASNOTATION_PLAIN;
1549 }
1550
1551 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1552 is_new_bgp = (bgp_lookup(as, name) == NULL);
1553
1554 ret = bgp_get_vty(&bgp, &as, name, inst_type,
1555 argv[idx_asn]->arg, asnotation);
1556 switch (ret) {
1557 case BGP_ERR_AS_MISMATCH:
1558 vty_out(vty, "BGP is already running; AS is %s\n",
1559 bgp->as_pretty);
1560 return CMD_WARNING_CONFIG_FAILED;
1561 case BGP_ERR_INSTANCE_MISMATCH:
1562 vty_out(vty,
1563 "BGP instance name and AS number mismatch\n");
1564 vty_out(vty,
1565 "BGP instance is already running; AS is %s\n",
1566 bgp->as_pretty);
1567 return CMD_WARNING_CONFIG_FAILED;
1568 }
1569
1570 /*
1571 * If we just instantiated the default instance, complete
1572 * any pending VRF-VPN leaking that was configured via
1573 * earlier "router bgp X vrf FOO" blocks.
1574 */
1575 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1576 vpn_leak_postchange_all();
1577
1578 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1579 bgp_vpn_leak_export(bgp);
1580 /* Pending: handle when user tries to change a view to vrf n vv.
1581 */
1582 /* for pre-existing bgp instance,
1583 * - update as_pretty
1584 * - update asnotation if explicitly mentioned
1585 */
1586 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) {
1587 XFREE(MTYPE_BGP, bgp->as_pretty);
1588 bgp->as_pretty = XSTRDUP(MTYPE_BGP, argv[idx_asn]->arg);
1589 if (!CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION) &&
1590 asnotation != ASNOTATION_UNDEFINED) {
1591 SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION);
1592 bgp->asnotation = asnotation;
1593 }
1594 }
1595 }
1596
1597 /* unset the auto created flag as the user config is now present */
1598 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1599 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1600
1601 return CMD_SUCCESS;
1602 }
1603
1604 /* "no router bgp" commands. */
1605 DEFUN (no_router_bgp,
1606 no_router_bgp_cmd,
1607 "no router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
1608 NO_STR
1609 ROUTER_STR
1610 BGP_STR
1611 AS_STR
1612 BGP_INSTANCE_HELP_STR
1613 "Force the AS notation output\n"
1614 "use 'AA.BB' format for AS 4 byte values\n"
1615 "use 'AA.BB' format for all AS values\n"
1616 "use plain format for all AS values\n")
1617 {
1618 int idx_asn = 3;
1619 int idx_vrf = 5;
1620 as_t as;
1621 struct bgp *bgp;
1622 const char *name = NULL;
1623
1624 // "no router bgp" without an ASN
1625 if (argc == 3) {
1626 // Pending: Make VRF option available for ASN less config
1627 bgp = bgp_get_default();
1628
1629 if (bgp == NULL) {
1630 vty_out(vty, "%% No BGP process is configured\n");
1631 return CMD_WARNING_CONFIG_FAILED;
1632 }
1633
1634 if (listcount(bm->bgp) > 1) {
1635 vty_out(vty, "%% Please specify ASN and VRF\n");
1636 return CMD_WARNING_CONFIG_FAILED;
1637 }
1638
1639 if (bgp->l3vni) {
1640 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1641 bgp->l3vni);
1642 return CMD_WARNING_CONFIG_FAILED;
1643 }
1644 } else {
1645 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1646 vty_out(vty, "%% BGP: No such AS %s\n",
1647 argv[idx_asn]->arg);
1648 return CMD_WARNING_CONFIG_FAILED;
1649 }
1650 if (argc > 4) {
1651 name = argv[idx_vrf]->arg;
1652 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1653 && strmatch(name, VRF_DEFAULT_NAME))
1654 name = NULL;
1655 }
1656
1657 /* Lookup bgp structure. */
1658 bgp = bgp_lookup(as, name);
1659 if (!bgp) {
1660 vty_out(vty, "%% Can't find BGP instance\n");
1661 return CMD_WARNING_CONFIG_FAILED;
1662 }
1663
1664 if (bgp->l3vni) {
1665 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1666 bgp->l3vni);
1667 return CMD_WARNING_CONFIG_FAILED;
1668 }
1669
1670 /* Cannot delete default instance if vrf instances exist */
1671 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1672 struct listnode *node;
1673 struct bgp *tmp_bgp;
1674
1675 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1676 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1677 continue;
1678 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1679 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1680 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1681 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1682 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1683 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1684 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1685 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1686 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1687 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1688 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1689 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1690 (bgp == bgp_get_evpn() &&
1691 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1692 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1693 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1694 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1695 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1696 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1697 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1698 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1699 (hashcount(tmp_bgp->vnihash))) {
1700 vty_out(vty,
1701 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1702 return CMD_WARNING_CONFIG_FAILED;
1703 }
1704 }
1705 }
1706 }
1707
1708 bgp_delete(bgp);
1709
1710 return CMD_SUCCESS;
1711 }
1712
1713 /* bgp session-dscp */
1714
1715 DEFPY (bgp_session_dscp,
1716 bgp_session_dscp_cmd,
1717 "bgp session-dscp (0-63)$dscp",
1718 BGP_STR
1719 "Override default (C6) bgp TCP session DSCP value\n"
1720 "Manually configured dscp parameter\n")
1721 {
1722 bm->tcp_dscp = dscp << 2;
1723
1724 return CMD_SUCCESS;
1725 }
1726
1727 DEFPY (no_bgp_session_dscp,
1728 no_bgp_session_dscp_cmd,
1729 "no bgp session-dscp [(0-63)]",
1730 NO_STR
1731 BGP_STR
1732 "Override default (C6) bgp TCP session DSCP value\n"
1733 "Manually configured dscp parameter\n")
1734 {
1735 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1736
1737 return CMD_SUCCESS;
1738 }
1739
1740 /* BGP router-id. */
1741
1742 DEFPY (bgp_router_id,
1743 bgp_router_id_cmd,
1744 "bgp router-id A.B.C.D",
1745 BGP_STR
1746 "Override configured router identifier\n"
1747 "Manually configured router identifier\n")
1748 {
1749 VTY_DECLVAR_CONTEXT(bgp, bgp);
1750 bgp_router_id_static_set(bgp, router_id);
1751 return CMD_SUCCESS;
1752 }
1753
1754 DEFPY (no_bgp_router_id,
1755 no_bgp_router_id_cmd,
1756 "no bgp router-id [A.B.C.D]",
1757 NO_STR
1758 BGP_STR
1759 "Override configured router identifier\n"
1760 "Manually configured router identifier\n")
1761 {
1762 VTY_DECLVAR_CONTEXT(bgp, bgp);
1763
1764 if (router_id_str) {
1765 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1766 vty_out(vty, "%% BGP router-id doesn't match\n");
1767 return CMD_WARNING_CONFIG_FAILED;
1768 }
1769 }
1770
1771 router_id.s_addr = 0;
1772 bgp_router_id_static_set(bgp, router_id);
1773
1774 return CMD_SUCCESS;
1775 }
1776
1777 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1778 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1779 NO_STR BGP_STR
1780 "Add community specific parameters\n"
1781 "Create an alias for a community\n"
1782 "Community (AA:BB or AA:BB:CC)\n"
1783 "Alias name\n")
1784 {
1785 struct community_alias ca = {};
1786 struct community_alias *lookup_community;
1787 struct community_alias *lookup_alias;
1788 struct community *comm;
1789 struct lcommunity *lcomm;
1790 uint8_t invalid = 0;
1791
1792 comm = community_str2com(community);
1793 if (!comm)
1794 invalid++;
1795 community_free(&comm);
1796
1797 lcomm = lcommunity_str2com(community);
1798 if (!lcomm)
1799 invalid++;
1800 lcommunity_free(&lcomm);
1801
1802 if (invalid > 1) {
1803 vty_out(vty, "Invalid community format\n");
1804 return CMD_WARNING;
1805 }
1806
1807 strlcpy(ca.community, community, sizeof(ca.community));
1808 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1809
1810 lookup_community = bgp_ca_community_lookup(&ca);
1811 lookup_alias = bgp_ca_alias_lookup(&ca);
1812
1813 if (no) {
1814 bgp_ca_alias_delete(&ca);
1815 bgp_ca_community_delete(&ca);
1816 } else {
1817 if (lookup_alias) {
1818 /* Lookup if community hash table has an item
1819 * with the same alias name.
1820 */
1821 strlcpy(ca.community, lookup_alias->community,
1822 sizeof(ca.community));
1823 if (bgp_ca_community_lookup(&ca)) {
1824 vty_out(vty,
1825 "community (%s) already has this alias (%s)\n",
1826 lookup_alias->community,
1827 lookup_alias->alias);
1828 return CMD_WARNING;
1829 }
1830 bgp_ca_alias_delete(&ca);
1831 }
1832
1833 if (lookup_community) {
1834 /* Lookup if alias hash table has an item
1835 * with the same community.
1836 */
1837 strlcpy(ca.alias, lookup_community->alias,
1838 sizeof(ca.alias));
1839 if (bgp_ca_alias_lookup(&ca)) {
1840 vty_out(vty,
1841 "alias (%s) already has this community (%s)\n",
1842 lookup_community->alias,
1843 lookup_community->community);
1844 return CMD_WARNING;
1845 }
1846 bgp_ca_community_delete(&ca);
1847 }
1848
1849 bgp_ca_alias_insert(&ca);
1850 bgp_ca_community_insert(&ca);
1851 }
1852
1853 return CMD_SUCCESS;
1854 }
1855
1856 DEFPY (bgp_global_suppress_fib_pending,
1857 bgp_global_suppress_fib_pending_cmd,
1858 "[no] bgp suppress-fib-pending",
1859 NO_STR
1860 BGP_STR
1861 "Advertise only routes that are programmed in kernel to peers globally\n")
1862 {
1863 bm_wait_for_fib_set(!no);
1864
1865 return CMD_SUCCESS;
1866 }
1867
1868 DEFPY (bgp_suppress_fib_pending,
1869 bgp_suppress_fib_pending_cmd,
1870 "[no] bgp suppress-fib-pending",
1871 NO_STR
1872 BGP_STR
1873 "Advertise only routes that are programmed in kernel to peers\n")
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876
1877 bgp_suppress_fib_pending_set(bgp, !no);
1878 return CMD_SUCCESS;
1879 }
1880
1881 /* BGP Cluster ID. */
1882 DEFUN (bgp_cluster_id,
1883 bgp_cluster_id_cmd,
1884 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1885 BGP_STR
1886 "Configure Route-Reflector Cluster-id\n"
1887 "Route-Reflector Cluster-id in IP address format\n"
1888 "Route-Reflector Cluster-id as 32 bit quantity\n")
1889 {
1890 VTY_DECLVAR_CONTEXT(bgp, bgp);
1891 int idx_ipv4 = 2;
1892 int ret;
1893 struct in_addr cluster;
1894
1895 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1896 if (!ret) {
1897 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1898 return CMD_WARNING_CONFIG_FAILED;
1899 }
1900
1901 bgp_cluster_id_set(bgp, &cluster);
1902 bgp_clear_star_soft_out(vty, bgp->name);
1903
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (no_bgp_cluster_id,
1908 no_bgp_cluster_id_cmd,
1909 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1910 NO_STR
1911 BGP_STR
1912 "Configure Route-Reflector Cluster-id\n"
1913 "Route-Reflector Cluster-id in IP address format\n"
1914 "Route-Reflector Cluster-id as 32 bit quantity\n")
1915 {
1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917 bgp_cluster_id_unset(bgp);
1918 bgp_clear_star_soft_out(vty, bgp->name);
1919
1920 return CMD_SUCCESS;
1921 }
1922
1923 DEFPY (bgp_norib,
1924 bgp_norib_cmd,
1925 "bgp no-rib",
1926 BGP_STR
1927 "Disable BGP route installation to RIB (Zebra)\n")
1928 {
1929 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1930 vty_out(vty,
1931 "%% No-RIB option is already set, nothing to do here.\n");
1932 return CMD_SUCCESS;
1933 }
1934
1935 bgp_option_norib_set_runtime();
1936
1937 return CMD_SUCCESS;
1938 }
1939
1940 DEFPY (no_bgp_norib,
1941 no_bgp_norib_cmd,
1942 "no bgp no-rib",
1943 NO_STR
1944 BGP_STR
1945 "Disable BGP route installation to RIB (Zebra)\n")
1946 {
1947 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1948 vty_out(vty,
1949 "%% No-RIB option is not set, nothing to do here.\n");
1950 return CMD_SUCCESS;
1951 }
1952
1953 bgp_option_norib_unset_runtime();
1954
1955 return CMD_SUCCESS;
1956 }
1957
1958 DEFPY (no_bgp_send_extra_data,
1959 no_bgp_send_extra_data_cmd,
1960 "[no] bgp send-extra-data zebra",
1961 NO_STR
1962 BGP_STR
1963 "Extra data to Zebra for display/use\n"
1964 "To zebra\n")
1965 {
1966 if (no)
1967 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1968 else
1969 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1970
1971 return CMD_SUCCESS;
1972 }
1973
1974 DEFUN (bgp_confederation_identifier,
1975 bgp_confederation_identifier_cmd,
1976 "bgp confederation identifier ASNUM",
1977 BGP_STR
1978 "AS confederation parameters\n"
1979 AS_STR
1980 "Set routing domain confederation AS\n")
1981 {
1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
1983 int idx_number = 3;
1984 as_t as;
1985
1986 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
1987 vty_out(vty, "%% BGP: No such AS %s\n", argv[idx_number]->arg);
1988 return CMD_WARNING_CONFIG_FAILED;
1989 }
1990
1991 bgp_confederation_id_set(bgp, as, argv[idx_number]->arg);
1992
1993 return CMD_SUCCESS;
1994 }
1995
1996 DEFUN (no_bgp_confederation_identifier,
1997 no_bgp_confederation_identifier_cmd,
1998 "no bgp confederation identifier [ASNUM]",
1999 NO_STR
2000 BGP_STR
2001 "AS confederation parameters\n"
2002 AS_STR
2003 "Set routing domain confederation AS\n")
2004 {
2005 VTY_DECLVAR_CONTEXT(bgp, bgp);
2006 bgp_confederation_id_unset(bgp);
2007
2008 return CMD_SUCCESS;
2009 }
2010
2011 DEFUN (bgp_confederation_peers,
2012 bgp_confederation_peers_cmd,
2013 "bgp confederation peers ASNUM...",
2014 BGP_STR
2015 "AS confederation parameters\n"
2016 "Peer ASs in BGP confederation\n"
2017 AS_STR)
2018 {
2019 VTY_DECLVAR_CONTEXT(bgp, bgp);
2020 int idx_asn = 3;
2021 as_t as;
2022 int i;
2023
2024 for (i = idx_asn; i < argc; i++) {
2025 if (!asn_str2asn(argv[i]->arg, &as)) {
2026 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2027 argv[i]->arg);
2028 continue;
2029 }
2030
2031 bgp_confederation_peers_add(bgp, as, argv[i]->arg);
2032 }
2033 return CMD_SUCCESS;
2034 }
2035
2036 DEFUN (no_bgp_confederation_peers,
2037 no_bgp_confederation_peers_cmd,
2038 "no bgp confederation peers ASNUM...",
2039 NO_STR
2040 BGP_STR
2041 "AS confederation parameters\n"
2042 "Peer ASs in BGP confederation\n"
2043 AS_STR)
2044 {
2045 VTY_DECLVAR_CONTEXT(bgp, bgp);
2046 int idx_asn = 4;
2047 as_t as;
2048 int i;
2049
2050 for (i = idx_asn; i < argc; i++) {
2051 if (!asn_str2asn(argv[i]->arg, &as)) {
2052 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2053 argv[i]->arg);
2054 continue;
2055 }
2056 bgp_confederation_peers_remove(bgp, as);
2057 }
2058 return CMD_SUCCESS;
2059 }
2060
2061 /**
2062 * Central routine for maximum-paths configuration.
2063 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
2064 * @set: 1 for setting values, 0 for removing the max-paths config.
2065 */
2066 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2067 const char *mpaths, uint16_t options,
2068 int set)
2069 {
2070 VTY_DECLVAR_CONTEXT(bgp, bgp);
2071 uint16_t maxpaths = 0;
2072 int ret;
2073 afi_t afi;
2074 safi_t safi;
2075
2076 afi = bgp_node_afi(vty);
2077 safi = bgp_node_safi(vty);
2078
2079 if (set) {
2080 maxpaths = strtol(mpaths, NULL, 10);
2081 if (maxpaths > multipath_num) {
2082 vty_out(vty,
2083 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2084 maxpaths, multipath_num);
2085 return CMD_WARNING_CONFIG_FAILED;
2086 }
2087 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2088 options);
2089 } else
2090 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2091
2092 if (ret < 0) {
2093 vty_out(vty,
2094 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2095 (set == 1) ? "" : "un",
2096 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2097 maxpaths, afi, safi);
2098 return CMD_WARNING_CONFIG_FAILED;
2099 }
2100
2101 bgp_recalculate_all_bestpaths(bgp);
2102
2103 return CMD_SUCCESS;
2104 }
2105
2106 DEFUN (bgp_maxmed_admin,
2107 bgp_maxmed_admin_cmd,
2108 "bgp max-med administrative ",
2109 BGP_STR
2110 "Advertise routes with max-med\n"
2111 "Administratively applied, for an indefinite period\n")
2112 {
2113 VTY_DECLVAR_CONTEXT(bgp, bgp);
2114
2115 bgp->v_maxmed_admin = 1;
2116 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2117
2118 bgp_maxmed_update(bgp);
2119
2120 return CMD_SUCCESS;
2121 }
2122
2123 DEFUN (bgp_maxmed_admin_medv,
2124 bgp_maxmed_admin_medv_cmd,
2125 "bgp max-med administrative (0-4294967295)",
2126 BGP_STR
2127 "Advertise routes with max-med\n"
2128 "Administratively applied, for an indefinite period\n"
2129 "Max MED value to be used\n")
2130 {
2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
2132 int idx_number = 3;
2133
2134 bgp->v_maxmed_admin = 1;
2135 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2136
2137 bgp_maxmed_update(bgp);
2138
2139 return CMD_SUCCESS;
2140 }
2141
2142 DEFUN (no_bgp_maxmed_admin,
2143 no_bgp_maxmed_admin_cmd,
2144 "no bgp max-med administrative [(0-4294967295)]",
2145 NO_STR
2146 BGP_STR
2147 "Advertise routes with max-med\n"
2148 "Administratively applied, for an indefinite period\n"
2149 "Max MED value to be used\n")
2150 {
2151 VTY_DECLVAR_CONTEXT(bgp, bgp);
2152 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2153 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2154 bgp_maxmed_update(bgp);
2155
2156 return CMD_SUCCESS;
2157 }
2158
2159 DEFUN (bgp_maxmed_onstartup,
2160 bgp_maxmed_onstartup_cmd,
2161 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2162 BGP_STR
2163 "Advertise routes with max-med\n"
2164 "Effective on a startup\n"
2165 "Time (seconds) period for max-med\n"
2166 "Max MED value to be used\n")
2167 {
2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
2169 int idx = 0;
2170
2171 if (argv_find(argv, argc, "(5-86400)", &idx))
2172 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2173 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2174 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2175 else
2176 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2177
2178 bgp_maxmed_update(bgp);
2179
2180 return CMD_SUCCESS;
2181 }
2182
2183 DEFUN (no_bgp_maxmed_onstartup,
2184 no_bgp_maxmed_onstartup_cmd,
2185 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2186 NO_STR
2187 BGP_STR
2188 "Advertise routes with max-med\n"
2189 "Effective on a startup\n"
2190 "Time (seconds) period for max-med\n"
2191 "Max MED value to be used\n")
2192 {
2193 VTY_DECLVAR_CONTEXT(bgp, bgp);
2194
2195 /* Cancel max-med onstartup if its on */
2196 if (bgp->t_maxmed_onstartup) {
2197 THREAD_OFF(bgp->t_maxmed_onstartup);
2198 bgp->maxmed_onstartup_over = 1;
2199 }
2200
2201 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2202 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2203
2204 bgp_maxmed_update(bgp);
2205
2206 return CMD_SUCCESS;
2207 }
2208
2209 static int bgp_global_update_delay_config_vty(struct vty *vty,
2210 uint16_t update_delay,
2211 uint16_t establish_wait)
2212 {
2213 struct listnode *node, *nnode;
2214 struct bgp *bgp;
2215 bool vrf_cfg = false;
2216
2217 /*
2218 * See if update-delay is set per-vrf and warn user to delete it
2219 * Note that we only need to check this if this is the first time
2220 * setting the global config.
2221 */
2222 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2223 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2224 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2225 vty_out(vty,
2226 "%% update-delay configuration found in vrf %s\n",
2227 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2228 ? VRF_DEFAULT_NAME
2229 : bgp->name);
2230 vrf_cfg = true;
2231 }
2232 }
2233 }
2234
2235 if (vrf_cfg) {
2236 vty_out(vty,
2237 "%%Failed: global update-delay config not permitted\n");
2238 return CMD_WARNING;
2239 }
2240
2241 if (!establish_wait) { /* update-delay <delay> */
2242 bm->v_update_delay = update_delay;
2243 bm->v_establish_wait = bm->v_update_delay;
2244 } else {
2245 /* update-delay <delay> <establish-wait> */
2246 if (update_delay < establish_wait) {
2247 vty_out(vty,
2248 "%%Failed: update-delay less than the establish-wait!\n");
2249 return CMD_WARNING_CONFIG_FAILED;
2250 }
2251
2252 bm->v_update_delay = update_delay;
2253 bm->v_establish_wait = establish_wait;
2254 }
2255
2256 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2257 bgp->v_update_delay = bm->v_update_delay;
2258 bgp->v_establish_wait = bm->v_establish_wait;
2259 }
2260
2261 return CMD_SUCCESS;
2262 }
2263
2264 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2265 {
2266 struct listnode *node, *nnode;
2267 struct bgp *bgp;
2268
2269 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2270 bm->v_establish_wait = bm->v_update_delay;
2271
2272 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2273 bgp->v_update_delay = bm->v_update_delay;
2274 bgp->v_establish_wait = bm->v_establish_wait;
2275 }
2276
2277 return CMD_SUCCESS;
2278 }
2279
2280 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2281 uint16_t establish_wait)
2282 {
2283 VTY_DECLVAR_CONTEXT(bgp, bgp);
2284
2285 /* if configured globally, per-instance config is not allowed */
2286 if (bm->v_update_delay) {
2287 vty_out(vty,
2288 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2289 return CMD_WARNING_CONFIG_FAILED;
2290 }
2291
2292
2293 if (!establish_wait) /* update-delay <delay> */
2294 {
2295 bgp->v_update_delay = update_delay;
2296 bgp->v_establish_wait = bgp->v_update_delay;
2297 return CMD_SUCCESS;
2298 }
2299
2300 /* update-delay <delay> <establish-wait> */
2301 if (update_delay < establish_wait) {
2302 vty_out(vty,
2303 "%%Failed: update-delay less than the establish-wait!\n");
2304 return CMD_WARNING_CONFIG_FAILED;
2305 }
2306
2307 bgp->v_update_delay = update_delay;
2308 bgp->v_establish_wait = establish_wait;
2309
2310 return CMD_SUCCESS;
2311 }
2312
2313 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2314 {
2315 VTY_DECLVAR_CONTEXT(bgp, bgp);
2316
2317 /* If configured globally, cannot remove from one bgp instance */
2318 if (bm->v_update_delay) {
2319 vty_out(vty,
2320 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2321 return CMD_WARNING_CONFIG_FAILED;
2322 }
2323 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2324 bgp->v_establish_wait = bgp->v_update_delay;
2325
2326 return CMD_SUCCESS;
2327 }
2328
2329 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2330 {
2331 /* If configured globally, no need to display per-instance value */
2332 if (bgp->v_update_delay != bm->v_update_delay) {
2333 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2334 if (bgp->v_update_delay != bgp->v_establish_wait)
2335 vty_out(vty, " %d", bgp->v_establish_wait);
2336 vty_out(vty, "\n");
2337 }
2338 }
2339
2340 /* Global update-delay configuration */
2341 DEFPY (bgp_global_update_delay,
2342 bgp_global_update_delay_cmd,
2343 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2344 BGP_STR
2345 "Force initial delay for best-path and updates for all bgp instances\n"
2346 "Max delay in seconds\n"
2347 "Establish wait in seconds\n")
2348 {
2349 return bgp_global_update_delay_config_vty(vty, delay, wait);
2350 }
2351
2352 /* Global update-delay deconfiguration */
2353 DEFPY (no_bgp_global_update_delay,
2354 no_bgp_global_update_delay_cmd,
2355 "no bgp update-delay [(0-3600) [(1-3600)]]",
2356 NO_STR
2357 BGP_STR
2358 "Force initial delay for best-path and updates\n"
2359 "Max delay in seconds\n"
2360 "Establish wait in seconds\n")
2361 {
2362 return bgp_global_update_delay_deconfig_vty(vty);
2363 }
2364
2365 /* Update-delay configuration */
2366
2367 DEFPY (bgp_update_delay,
2368 bgp_update_delay_cmd,
2369 "update-delay (0-3600)$delay [(1-3600)$wait]",
2370 "Force initial delay for best-path and updates\n"
2371 "Max delay in seconds\n"
2372 "Establish wait in seconds\n")
2373 {
2374 return bgp_update_delay_config_vty(vty, delay, wait);
2375 }
2376
2377 /* Update-delay deconfiguration */
2378 DEFPY (no_bgp_update_delay,
2379 no_bgp_update_delay_cmd,
2380 "no update-delay [(0-3600) [(1-3600)]]",
2381 NO_STR
2382 "Force initial delay for best-path and updates\n"
2383 "Max delay in seconds\n"
2384 "Establish wait in seconds\n")
2385 {
2386 return bgp_update_delay_deconfig_vty(vty);
2387 }
2388
2389
2390 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2391 bool set)
2392 {
2393 VTY_DECLVAR_CONTEXT(bgp, bgp);
2394
2395 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2396 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2397
2398 return CMD_SUCCESS;
2399 }
2400
2401 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2402 bool set)
2403 {
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405
2406 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2407 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2408
2409 return CMD_SUCCESS;
2410 }
2411
2412 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2413 {
2414 uint32_t quanta =
2415 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2416 if (quanta != BGP_WRITE_PACKET_MAX)
2417 vty_out(vty, " write-quanta %d\n", quanta);
2418 }
2419
2420 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2421 {
2422 uint32_t quanta =
2423 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2424 if (quanta != BGP_READ_PACKET_MAX)
2425 vty_out(vty, " read-quanta %d\n", quanta);
2426 }
2427
2428 /* Packet quanta configuration
2429 *
2430 * XXX: The value set here controls the size of a stack buffer in the IO
2431 * thread. When changing these limits be careful to prevent stack overflow.
2432 *
2433 * Furthermore, the maximums used here should correspond to
2434 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2435 */
2436 DEFPY (bgp_wpkt_quanta,
2437 bgp_wpkt_quanta_cmd,
2438 "[no] write-quanta (1-64)$quanta",
2439 NO_STR
2440 "How many packets to write to peer socket per run\n"
2441 "Number of packets\n")
2442 {
2443 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2444 }
2445
2446 DEFPY (bgp_rpkt_quanta,
2447 bgp_rpkt_quanta_cmd,
2448 "[no] read-quanta (1-10)$quanta",
2449 NO_STR
2450 "How many packets to read from peer socket per I/O cycle\n"
2451 "Number of packets\n")
2452 {
2453 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2454 }
2455
2456 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2457 {
2458 if (!bgp->heuristic_coalesce)
2459 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2460 }
2461
2462 /* BGP TCP keepalive */
2463 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2464 {
2465 if (bgp->tcp_keepalive_idle) {
2466 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2467 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2468 bgp->tcp_keepalive_probes);
2469 }
2470 }
2471
2472 DEFUN (bgp_coalesce_time,
2473 bgp_coalesce_time_cmd,
2474 "coalesce-time (0-4294967295)",
2475 "Subgroup coalesce timer\n"
2476 "Subgroup coalesce timer value (in ms)\n")
2477 {
2478 VTY_DECLVAR_CONTEXT(bgp, bgp);
2479
2480 int idx = 0;
2481
2482 bgp->heuristic_coalesce = false;
2483
2484 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2485 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2486
2487 return CMD_SUCCESS;
2488 }
2489
2490 DEFUN (no_bgp_coalesce_time,
2491 no_bgp_coalesce_time_cmd,
2492 "no coalesce-time (0-4294967295)",
2493 NO_STR
2494 "Subgroup coalesce timer\n"
2495 "Subgroup coalesce timer value (in ms)\n")
2496 {
2497 VTY_DECLVAR_CONTEXT(bgp, bgp);
2498
2499 bgp->heuristic_coalesce = true;
2500 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2501 return CMD_SUCCESS;
2502 }
2503
2504 /* Maximum-paths configuration */
2505 DEFUN (bgp_maxpaths,
2506 bgp_maxpaths_cmd,
2507 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2508 "Forward packets over multiple paths\n"
2509 "Number of paths\n")
2510 {
2511 int idx_number = 1;
2512 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2513 argv[idx_number]->arg, 0, 1);
2514 }
2515
2516 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2517 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2518 "Forward packets over multiple paths\n"
2519 "Number of paths\n")
2520
2521 DEFUN (bgp_maxpaths_ibgp,
2522 bgp_maxpaths_ibgp_cmd,
2523 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2524 "Forward packets over multiple paths\n"
2525 "iBGP-multipath\n"
2526 "Number of paths\n")
2527 {
2528 int idx_number = 2;
2529 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2530 argv[idx_number]->arg, 0, 1);
2531 }
2532
2533 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2534 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2535 "Forward packets over multiple paths\n"
2536 "iBGP-multipath\n"
2537 "Number of paths\n")
2538
2539 DEFUN (bgp_maxpaths_ibgp_cluster,
2540 bgp_maxpaths_ibgp_cluster_cmd,
2541 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2542 "Forward packets over multiple paths\n"
2543 "iBGP-multipath\n"
2544 "Number of paths\n"
2545 "Match the cluster length\n")
2546 {
2547 int idx_number = 2;
2548 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2549 argv[idx_number]->arg, true, 1);
2550 }
2551
2552 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2553 "maximum-paths ibgp " CMD_RANGE_STR(
2554 1, MULTIPATH_NUM) " equal-cluster-length",
2555 "Forward packets over multiple paths\n"
2556 "iBGP-multipath\n"
2557 "Number of paths\n"
2558 "Match the cluster length\n")
2559
2560 DEFUN (no_bgp_maxpaths,
2561 no_bgp_maxpaths_cmd,
2562 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2563 NO_STR
2564 "Forward packets over multiple paths\n"
2565 "Number of paths\n")
2566 {
2567 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2568 }
2569
2570 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2571 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2572 "Forward packets over multiple paths\n"
2573 "Number of paths\n")
2574
2575 DEFUN (no_bgp_maxpaths_ibgp,
2576 no_bgp_maxpaths_ibgp_cmd,
2577 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2578 NO_STR
2579 "Forward packets over multiple paths\n"
2580 "iBGP-multipath\n"
2581 "Number of paths\n"
2582 "Match the cluster length\n")
2583 {
2584 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2585 }
2586
2587 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2588 "no maximum-paths ibgp [" CMD_RANGE_STR(
2589 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2590 NO_STR
2591 "Forward packets over multiple paths\n"
2592 "iBGP-multipath\n"
2593 "Number of paths\n"
2594 "Match the cluster length\n")
2595
2596 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2597 afi_t afi, safi_t safi)
2598 {
2599 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2600 vty_out(vty, " maximum-paths %d\n",
2601 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2602 }
2603
2604 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2605 vty_out(vty, " maximum-paths ibgp %d",
2606 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2607 if (bgp->maxpaths[afi][safi].same_clusterlen)
2608 vty_out(vty, " equal-cluster-length");
2609 vty_out(vty, "\n");
2610 }
2611 }
2612
2613 /* BGP timers. */
2614
2615 DEFUN (bgp_timers,
2616 bgp_timers_cmd,
2617 "timers bgp (0-65535) (0-65535)",
2618 "Adjust routing timers\n"
2619 "BGP timers\n"
2620 "Keepalive interval\n"
2621 "Holdtime\n")
2622 {
2623 VTY_DECLVAR_CONTEXT(bgp, bgp);
2624 int idx_number = 2;
2625 int idx_number_2 = 3;
2626 unsigned long keepalive = 0;
2627 unsigned long holdtime = 0;
2628
2629 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2630 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2631
2632 /* Holdtime value check. */
2633 if (holdtime < 3 && holdtime != 0) {
2634 vty_out(vty,
2635 "%% hold time value must be either 0 or greater than 3\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2640 BGP_DEFAULT_DELAYOPEN);
2641
2642 return CMD_SUCCESS;
2643 }
2644
2645 DEFUN (no_bgp_timers,
2646 no_bgp_timers_cmd,
2647 "no timers bgp [(0-65535) (0-65535)]",
2648 NO_STR
2649 "Adjust routing timers\n"
2650 "BGP timers\n"
2651 "Keepalive interval\n"
2652 "Holdtime\n")
2653 {
2654 VTY_DECLVAR_CONTEXT(bgp, bgp);
2655 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2656 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2657
2658 return CMD_SUCCESS;
2659 }
2660
2661 /* BGP minimum holdtime. */
2662
2663 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2664 "bgp minimum-holdtime (1-65535)",
2665 "BGP specific commands\n"
2666 "BGP minimum holdtime\n"
2667 "Seconds\n")
2668 {
2669 VTY_DECLVAR_CONTEXT(bgp, bgp);
2670 int idx_number = 2;
2671 unsigned long min_holdtime;
2672
2673 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2674
2675 bgp->default_min_holdtime = min_holdtime;
2676
2677 return CMD_SUCCESS;
2678 }
2679
2680 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2681 "no bgp minimum-holdtime [(1-65535)]",
2682 NO_STR
2683 "BGP specific commands\n"
2684 "BGP minimum holdtime\n"
2685 "Seconds\n")
2686 {
2687 VTY_DECLVAR_CONTEXT(bgp, bgp);
2688
2689 bgp->default_min_holdtime = 0;
2690
2691 return CMD_SUCCESS;
2692 }
2693
2694 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2695 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2696 BGP_STR
2697 "TCP keepalive parameters\n"
2698 "TCP keepalive idle time (seconds)\n"
2699 "TCP keepalive interval (seconds)\n"
2700 "TCP keepalive maximum probes\n")
2701 {
2702 VTY_DECLVAR_CONTEXT(bgp, bgp);
2703
2704 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2705 (uint16_t)probes);
2706
2707 return CMD_SUCCESS;
2708 }
2709
2710 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2711 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2712 NO_STR
2713 BGP_STR
2714 "TCP keepalive parameters\n"
2715 "TCP keepalive idle time (seconds)\n"
2716 "TCP keepalive interval (seconds)\n"
2717 "TCP keepalive maximum probes\n")
2718 {
2719 VTY_DECLVAR_CONTEXT(bgp, bgp);
2720
2721 bgp_tcp_keepalive_unset(bgp);
2722
2723 return CMD_SUCCESS;
2724 }
2725
2726 DEFUN (bgp_client_to_client_reflection,
2727 bgp_client_to_client_reflection_cmd,
2728 "bgp client-to-client reflection",
2729 BGP_STR
2730 "Configure client to client route reflection\n"
2731 "reflection of routes allowed\n")
2732 {
2733 VTY_DECLVAR_CONTEXT(bgp, bgp);
2734 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2735 bgp_clear_star_soft_out(vty, bgp->name);
2736
2737 return CMD_SUCCESS;
2738 }
2739
2740 DEFUN (no_bgp_client_to_client_reflection,
2741 no_bgp_client_to_client_reflection_cmd,
2742 "no bgp client-to-client reflection",
2743 NO_STR
2744 BGP_STR
2745 "Configure client to client route reflection\n"
2746 "reflection of routes allowed\n")
2747 {
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2750 bgp_clear_star_soft_out(vty, bgp->name);
2751
2752 return CMD_SUCCESS;
2753 }
2754
2755 /* "bgp always-compare-med" configuration. */
2756 DEFUN (bgp_always_compare_med,
2757 bgp_always_compare_med_cmd,
2758 "bgp always-compare-med",
2759 BGP_STR
2760 "Allow comparing MED from different neighbors\n")
2761 {
2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
2763 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2764 bgp_recalculate_all_bestpaths(bgp);
2765
2766 return CMD_SUCCESS;
2767 }
2768
2769 DEFUN (no_bgp_always_compare_med,
2770 no_bgp_always_compare_med_cmd,
2771 "no bgp always-compare-med",
2772 NO_STR
2773 BGP_STR
2774 "Allow comparing MED from different neighbors\n")
2775 {
2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2778 bgp_recalculate_all_bestpaths(bgp);
2779
2780 return CMD_SUCCESS;
2781 }
2782
2783
2784 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2785 "bgp ebgp-requires-policy",
2786 BGP_STR
2787 "Require in and out policy for eBGP peers (RFC8212)\n")
2788 {
2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
2790 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2791 return CMD_SUCCESS;
2792 }
2793
2794 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2795 "no bgp ebgp-requires-policy",
2796 NO_STR
2797 BGP_STR
2798 "Require in and out policy for eBGP peers (RFC8212)\n")
2799 {
2800 VTY_DECLVAR_CONTEXT(bgp, bgp);
2801 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2802 return CMD_SUCCESS;
2803 }
2804
2805 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2806 "bgp suppress-duplicates",
2807 BGP_STR
2808 "Suppress duplicate updates if the route actually not changed\n")
2809 {
2810 VTY_DECLVAR_CONTEXT(bgp, bgp);
2811 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2812 return CMD_SUCCESS;
2813 }
2814
2815 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2816 "no bgp suppress-duplicates",
2817 NO_STR
2818 BGP_STR
2819 "Suppress duplicate updates if the route actually not changed\n")
2820 {
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2823 return CMD_SUCCESS;
2824 }
2825
2826 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2827 "bgp reject-as-sets",
2828 BGP_STR
2829 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2830 {
2831 VTY_DECLVAR_CONTEXT(bgp, bgp);
2832 struct listnode *node, *nnode;
2833 struct peer *peer;
2834
2835 bgp->reject_as_sets = true;
2836
2837 /* Reset existing BGP sessions to reject routes
2838 * with aspath containing AS_SET or AS_CONFED_SET.
2839 */
2840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2841 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2842 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2843 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2844 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2845 }
2846 }
2847
2848 return CMD_SUCCESS;
2849 }
2850
2851 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2852 "no bgp reject-as-sets",
2853 NO_STR
2854 BGP_STR
2855 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2856 {
2857 VTY_DECLVAR_CONTEXT(bgp, bgp);
2858 struct listnode *node, *nnode;
2859 struct peer *peer;
2860
2861 bgp->reject_as_sets = false;
2862
2863 /* Reset existing BGP sessions to reject routes
2864 * with aspath containing AS_SET or AS_CONFED_SET.
2865 */
2866 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2867 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2868 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2869 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2870 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2871 }
2872 }
2873
2874 return CMD_SUCCESS;
2875 }
2876
2877 /* "bgp deterministic-med" configuration. */
2878 DEFUN (bgp_deterministic_med,
2879 bgp_deterministic_med_cmd,
2880 "bgp deterministic-med",
2881 BGP_STR
2882 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2883 {
2884 VTY_DECLVAR_CONTEXT(bgp, bgp);
2885
2886 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2887 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2888 bgp_recalculate_all_bestpaths(bgp);
2889 }
2890
2891 return CMD_SUCCESS;
2892 }
2893
2894 DEFUN (no_bgp_deterministic_med,
2895 no_bgp_deterministic_med_cmd,
2896 "no bgp deterministic-med",
2897 NO_STR
2898 BGP_STR
2899 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2900 {
2901 VTY_DECLVAR_CONTEXT(bgp, bgp);
2902 int bestpath_per_as_used;
2903 afi_t afi;
2904 safi_t safi;
2905 struct peer *peer;
2906 struct listnode *node, *nnode;
2907
2908 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2909 bestpath_per_as_used = 0;
2910
2911 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2912 FOREACH_AFI_SAFI (afi, safi)
2913 if (bgp_addpath_dmed_required(
2914 peer->addpath_type[afi][safi])) {
2915 bestpath_per_as_used = 1;
2916 break;
2917 }
2918
2919 if (bestpath_per_as_used)
2920 break;
2921 }
2922
2923 if (bestpath_per_as_used) {
2924 vty_out(vty,
2925 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2926 return CMD_WARNING_CONFIG_FAILED;
2927 } else {
2928 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2929 bgp_recalculate_all_bestpaths(bgp);
2930 }
2931 }
2932
2933 return CMD_SUCCESS;
2934 }
2935
2936 /* "bgp graceful-restart mode" configuration. */
2937 DEFUN (bgp_graceful_restart,
2938 bgp_graceful_restart_cmd,
2939 "bgp graceful-restart",
2940 BGP_STR
2941 GR_CMD
2942 )
2943 {
2944 int ret = BGP_GR_FAILURE;
2945
2946 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2947 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2948
2949 VTY_DECLVAR_CONTEXT(bgp, bgp);
2950
2951 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2952
2953 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2954 ret);
2955
2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2957 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2958 vty_out(vty,
2959 "Graceful restart configuration changed, reset all peers to take effect\n");
2960 return bgp_vty_return(vty, ret);
2961 }
2962
2963 DEFUN (no_bgp_graceful_restart,
2964 no_bgp_graceful_restart_cmd,
2965 "no bgp graceful-restart",
2966 NO_STR
2967 BGP_STR
2968 NO_GR_CMD
2969 )
2970 {
2971 VTY_DECLVAR_CONTEXT(bgp, bgp);
2972
2973 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2974 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2975
2976 int ret = BGP_GR_FAILURE;
2977
2978 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2979
2980 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2981 ret);
2982
2983 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2984 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2985 vty_out(vty,
2986 "Graceful restart configuration changed, reset all peers to take effect\n");
2987
2988 return bgp_vty_return(vty, ret);
2989 }
2990
2991 DEFUN (bgp_graceful_restart_stalepath_time,
2992 bgp_graceful_restart_stalepath_time_cmd,
2993 "bgp graceful-restart stalepath-time (1-4095)",
2994 BGP_STR
2995 "Graceful restart capability parameters\n"
2996 "Set the max time to hold onto restarting peer's stale paths\n"
2997 "Delay value (seconds)\n")
2998 {
2999 VTY_DECLVAR_CONTEXT(bgp, bgp);
3000 int idx_number = 3;
3001 uint32_t stalepath;
3002
3003 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
3004 bgp->stalepath_time = stalepath;
3005 return CMD_SUCCESS;
3006 }
3007
3008 DEFUN (bgp_graceful_restart_restart_time,
3009 bgp_graceful_restart_restart_time_cmd,
3010 "bgp graceful-restart restart-time (0-4095)",
3011 BGP_STR
3012 "Graceful restart capability parameters\n"
3013 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3014 "Delay value (seconds)\n")
3015 {
3016 VTY_DECLVAR_CONTEXT(bgp, bgp);
3017 int idx_number = 3;
3018 uint32_t restart;
3019
3020 restart = strtoul(argv[idx_number]->arg, NULL, 10);
3021 bgp->restart_time = restart;
3022 return CMD_SUCCESS;
3023 }
3024
3025 DEFUN (bgp_graceful_restart_select_defer_time,
3026 bgp_graceful_restart_select_defer_time_cmd,
3027 "bgp graceful-restart select-defer-time (0-3600)",
3028 BGP_STR
3029 "Graceful restart capability parameters\n"
3030 "Set the time to defer the BGP route selection after restart\n"
3031 "Delay value (seconds, 0 - disable)\n")
3032 {
3033 VTY_DECLVAR_CONTEXT(bgp, bgp);
3034 int idx_number = 3;
3035 uint32_t defer_time;
3036
3037 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
3038 bgp->select_defer_time = defer_time;
3039 if (defer_time == 0)
3040 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3041 else
3042 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3043
3044 return CMD_SUCCESS;
3045 }
3046
3047 DEFUN (no_bgp_graceful_restart_stalepath_time,
3048 no_bgp_graceful_restart_stalepath_time_cmd,
3049 "no bgp graceful-restart stalepath-time [(1-4095)]",
3050 NO_STR
3051 BGP_STR
3052 "Graceful restart capability parameters\n"
3053 "Set the max time to hold onto restarting peer's stale paths\n"
3054 "Delay value (seconds)\n")
3055 {
3056 VTY_DECLVAR_CONTEXT(bgp, bgp);
3057
3058 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
3059 return CMD_SUCCESS;
3060 }
3061
3062 DEFUN (no_bgp_graceful_restart_restart_time,
3063 no_bgp_graceful_restart_restart_time_cmd,
3064 "no bgp graceful-restart restart-time [(0-4095)]",
3065 NO_STR
3066 BGP_STR
3067 "Graceful restart capability parameters\n"
3068 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3069 "Delay value (seconds)\n")
3070 {
3071 VTY_DECLVAR_CONTEXT(bgp, bgp);
3072
3073 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3074 return CMD_SUCCESS;
3075 }
3076
3077 DEFUN (no_bgp_graceful_restart_select_defer_time,
3078 no_bgp_graceful_restart_select_defer_time_cmd,
3079 "no bgp graceful-restart select-defer-time [(0-3600)]",
3080 NO_STR
3081 BGP_STR
3082 "Graceful restart capability parameters\n"
3083 "Set the time to defer the BGP route selection after restart\n"
3084 "Delay value (seconds)\n")
3085 {
3086 VTY_DECLVAR_CONTEXT(bgp, bgp);
3087
3088 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3089 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3090
3091 return CMD_SUCCESS;
3092 }
3093
3094 DEFUN (bgp_graceful_restart_preserve_fw,
3095 bgp_graceful_restart_preserve_fw_cmd,
3096 "bgp graceful-restart preserve-fw-state",
3097 BGP_STR
3098 "Graceful restart capability parameters\n"
3099 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3100 {
3101 VTY_DECLVAR_CONTEXT(bgp, bgp);
3102 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3103 return CMD_SUCCESS;
3104 }
3105
3106 DEFUN (no_bgp_graceful_restart_preserve_fw,
3107 no_bgp_graceful_restart_preserve_fw_cmd,
3108 "no bgp graceful-restart preserve-fw-state",
3109 NO_STR
3110 BGP_STR
3111 "Graceful restart capability parameters\n"
3112 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3113 {
3114 VTY_DECLVAR_CONTEXT(bgp, bgp);
3115 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3116 return CMD_SUCCESS;
3117 }
3118
3119 DEFPY (bgp_graceful_restart_notification,
3120 bgp_graceful_restart_notification_cmd,
3121 "[no$no] bgp graceful-restart notification",
3122 NO_STR
3123 BGP_STR
3124 "Graceful restart capability parameters\n"
3125 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3126 {
3127 VTY_DECLVAR_CONTEXT(bgp, bgp);
3128
3129 if (no)
3130 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3131 else
3132 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3133
3134 return CMD_SUCCESS;
3135 }
3136
3137 DEFPY (bgp_administrative_reset,
3138 bgp_administrative_reset_cmd,
3139 "[no$no] bgp hard-administrative-reset",
3140 NO_STR
3141 BGP_STR
3142 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3143 {
3144 VTY_DECLVAR_CONTEXT(bgp, bgp);
3145
3146 if (no)
3147 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3148 else
3149 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3150
3151 return CMD_SUCCESS;
3152 }
3153
3154 DEFUN (bgp_graceful_restart_disable,
3155 bgp_graceful_restart_disable_cmd,
3156 "bgp graceful-restart-disable",
3157 BGP_STR
3158 GR_DISABLE)
3159 {
3160 int ret = BGP_GR_FAILURE;
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
3164 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3165
3166 VTY_DECLVAR_CONTEXT(bgp, bgp);
3167
3168 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3169
3170 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3171 bgp->peer, ret);
3172
3173 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3174 zlog_debug(
3175 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3176 vty_out(vty,
3177 "Graceful restart configuration changed, reset all peers to take effect\n");
3178
3179 return bgp_vty_return(vty, ret);
3180 }
3181
3182 DEFUN (no_bgp_graceful_restart_disable,
3183 no_bgp_graceful_restart_disable_cmd,
3184 "no bgp graceful-restart-disable",
3185 NO_STR
3186 BGP_STR
3187 NO_GR_DISABLE
3188 )
3189 {
3190 VTY_DECLVAR_CONTEXT(bgp, bgp);
3191
3192 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3193 zlog_debug(
3194 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3195
3196 int ret = BGP_GR_FAILURE;
3197
3198 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3199
3200 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3201 ret);
3202
3203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3204 zlog_debug(
3205 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3206 vty_out(vty,
3207 "Graceful restart configuration changed, reset all peers to take effect\n");
3208
3209 return bgp_vty_return(vty, ret);
3210 }
3211
3212 DEFUN (bgp_neighbor_graceful_restart_set,
3213 bgp_neighbor_graceful_restart_set_cmd,
3214 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
3217 GR_NEIGHBOR_CMD
3218 )
3219 {
3220 int idx_peer = 1;
3221 struct peer *peer;
3222 int ret = BGP_GR_FAILURE;
3223
3224 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3225
3226 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3227 zlog_debug(
3228 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3229
3230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3231 if (!peer)
3232 return CMD_WARNING_CONFIG_FAILED;
3233
3234 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3235
3236 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3237 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3238
3239 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3240 zlog_debug(
3241 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3242 vty_out(vty,
3243 "Graceful restart configuration changed, reset this peer to take effect\n");
3244
3245 return bgp_vty_return(vty, ret);
3246 }
3247
3248 DEFUN (no_bgp_neighbor_graceful_restart,
3249 no_bgp_neighbor_graceful_restart_set_cmd,
3250 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3251 NO_STR
3252 NEIGHBOR_STR
3253 NEIGHBOR_ADDR_STR2
3254 NO_GR_NEIGHBOR_CMD
3255 )
3256 {
3257 int idx_peer = 2;
3258 int ret = BGP_GR_FAILURE;
3259 struct peer *peer;
3260
3261 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3262
3263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3264 if (!peer)
3265 return CMD_WARNING_CONFIG_FAILED;
3266
3267 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3268 zlog_debug(
3269 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3270
3271 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3272
3273 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3274 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3275
3276 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3277 zlog_debug(
3278 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3279 vty_out(vty,
3280 "Graceful restart configuration changed, reset this peer to take effect\n");
3281
3282 return bgp_vty_return(vty, ret);
3283 }
3284
3285 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3286 bgp_neighbor_graceful_restart_helper_set_cmd,
3287 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3288 NEIGHBOR_STR
3289 NEIGHBOR_ADDR_STR2
3290 GR_NEIGHBOR_HELPER_CMD
3291 )
3292 {
3293 int idx_peer = 1;
3294 struct peer *peer;
3295 int ret = BGP_GR_FAILURE;
3296
3297 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3298
3299 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3300 zlog_debug(
3301 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3302
3303 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3304
3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
3307
3308
3309 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3310
3311 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3312 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3313
3314 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3315 zlog_debug(
3316 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3317 vty_out(vty,
3318 "Graceful restart configuration changed, reset this peer to take effect\n");
3319
3320 return bgp_vty_return(vty, ret);
3321 }
3322
3323 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3324 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3325 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3326 NO_STR
3327 NEIGHBOR_STR
3328 NEIGHBOR_ADDR_STR2
3329 NO_GR_NEIGHBOR_HELPER_CMD
3330 )
3331 {
3332 int idx_peer = 2;
3333 int ret = BGP_GR_FAILURE;
3334 struct peer *peer;
3335
3336 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3337
3338 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3339 if (!peer)
3340 return CMD_WARNING_CONFIG_FAILED;
3341
3342 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3343 zlog_debug(
3344 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3345
3346 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3347
3348 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3349 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3350
3351 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3352 zlog_debug(
3353 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3354 vty_out(vty,
3355 "Graceful restart configuration changed, reset this peer to take effect\n");
3356
3357 return bgp_vty_return(vty, ret);
3358 }
3359
3360 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3361 bgp_neighbor_graceful_restart_disable_set_cmd,
3362 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 GR_NEIGHBOR_DISABLE_CMD
3366 )
3367 {
3368 int idx_peer = 1;
3369 struct peer *peer;
3370 int ret = BGP_GR_FAILURE;
3371
3372 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3373
3374 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3375 zlog_debug(
3376 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3377
3378 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3379 if (!peer)
3380 return CMD_WARNING_CONFIG_FAILED;
3381
3382 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3383
3384 if (peer->bgp->t_startup)
3385 bgp_peer_gr_flags_update(peer);
3386
3387 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3388 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3389
3390 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3391 zlog_debug(
3392 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3393 vty_out(vty,
3394 "Graceful restart configuration changed, reset this peer to take effect\n");
3395
3396 return bgp_vty_return(vty, ret);
3397 }
3398
3399 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3400 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3401 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3402 NO_STR
3403 NEIGHBOR_STR
3404 NEIGHBOR_ADDR_STR2
3405 NO_GR_NEIGHBOR_DISABLE_CMD
3406 )
3407 {
3408 int idx_peer = 2;
3409 int ret = BGP_GR_FAILURE;
3410 struct peer *peer;
3411
3412 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3413
3414 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3415 if (!peer)
3416 return CMD_WARNING_CONFIG_FAILED;
3417
3418 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3419 zlog_debug(
3420 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3421
3422 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3423
3424 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3425 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3426
3427 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3428 zlog_debug(
3429 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3430 vty_out(vty,
3431 "Graceful restart configuration changed, reset this peer to take effect\n");
3432
3433 return bgp_vty_return(vty, ret);
3434 }
3435
3436 DEFPY (neighbor_graceful_shutdown,
3437 neighbor_graceful_shutdown_cmd,
3438 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3439 NO_STR
3440 NEIGHBOR_STR
3441 NEIGHBOR_ADDR_STR2
3442 "Graceful shutdown\n")
3443 {
3444 afi_t afi;
3445 safi_t safi;
3446 struct peer *peer;
3447 VTY_DECLVAR_CONTEXT(bgp, bgp);
3448 int ret;
3449
3450 peer = peer_and_group_lookup_vty(vty, neighbor);
3451 if (!peer)
3452 return CMD_WARNING_CONFIG_FAILED;
3453
3454 if (no)
3455 ret = peer_flag_unset_vty(vty, neighbor,
3456 PEER_FLAG_GRACEFUL_SHUTDOWN);
3457 else
3458 ret = peer_flag_set_vty(vty, neighbor,
3459 PEER_FLAG_GRACEFUL_SHUTDOWN);
3460
3461 FOREACH_AFI_SAFI (afi, safi) {
3462 if (!peer->afc[afi][safi])
3463 continue;
3464
3465 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3466 neighbor);
3467 }
3468
3469 return ret;
3470 }
3471
3472 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3473 bgp_graceful_restart_disable_eor_cmd,
3474 "bgp graceful-restart disable-eor",
3475 BGP_STR
3476 "Graceful restart configuration parameters\n"
3477 "Disable EOR Check\n")
3478 {
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3481
3482 return CMD_SUCCESS;
3483 }
3484
3485 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3486 no_bgp_graceful_restart_disable_eor_cmd,
3487 "no bgp graceful-restart disable-eor",
3488 NO_STR
3489 BGP_STR
3490 "Graceful restart configuration parameters\n"
3491 "Disable EOR Check\n")
3492 {
3493 VTY_DECLVAR_CONTEXT(bgp, bgp);
3494 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3495
3496 return CMD_SUCCESS;
3497 }
3498
3499 DEFUN (bgp_graceful_restart_rib_stale_time,
3500 bgp_graceful_restart_rib_stale_time_cmd,
3501 "bgp graceful-restart rib-stale-time (1-3600)",
3502 BGP_STR
3503 "Graceful restart configuration parameters\n"
3504 "Specify the stale route removal timer in rib\n"
3505 "Delay value (seconds)\n")
3506 {
3507 VTY_DECLVAR_CONTEXT(bgp, bgp);
3508 int idx_number = 3;
3509 uint32_t stale_time;
3510
3511 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3512 bgp->rib_stale_time = stale_time;
3513 /* Send the stale timer update message to RIB */
3514 if (bgp_zebra_stale_timer_update(bgp))
3515 return CMD_WARNING;
3516
3517 return CMD_SUCCESS;
3518 }
3519
3520 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3521 no_bgp_graceful_restart_rib_stale_time_cmd,
3522 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3523 NO_STR
3524 BGP_STR
3525 "Graceful restart configuration parameters\n"
3526 "Specify the stale route removal timer in rib\n"
3527 "Delay value (seconds)\n")
3528 {
3529 VTY_DECLVAR_CONTEXT(bgp, bgp);
3530
3531 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3532 /* Send the stale timer update message to RIB */
3533 if (bgp_zebra_stale_timer_update(bgp))
3534 return CMD_WARNING;
3535
3536 return CMD_SUCCESS;
3537 }
3538
3539 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3540 "bgp long-lived-graceful-restart stale-time (1-16777215)",
3541 BGP_STR
3542 "Enable Long-lived Graceful Restart\n"
3543 "Specifies maximum time to wait before purging long-lived stale routes\n"
3544 "Stale time value (seconds)\n")
3545 {
3546 VTY_DECLVAR_CONTEXT(bgp, bgp);
3547
3548 uint32_t llgr_stale_time;
3549
3550 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3551 bgp->llgr_stale_time = llgr_stale_time;
3552
3553 return CMD_SUCCESS;
3554 }
3555
3556 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3557 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3558 NO_STR BGP_STR
3559 "Enable Long-lived Graceful Restart\n"
3560 "Specifies maximum time to wait before purging long-lived stale routes\n"
3561 "Stale time value (seconds)\n")
3562 {
3563 VTY_DECLVAR_CONTEXT(bgp, bgp);
3564
3565 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3566
3567 return CMD_SUCCESS;
3568 }
3569
3570 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3571 struct bgp *bgp)
3572 {
3573 bgp_static_redo_import_check(bgp);
3574 bgp_redistribute_redo(bgp);
3575 bgp_clear_star_soft_out(vty, bgp->name);
3576 bgp_clear_star_soft_in(vty, bgp->name);
3577 }
3578
3579 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3580 {
3581 struct listnode *node, *nnode;
3582 struct bgp *bgp;
3583 bool vrf_cfg = false;
3584
3585 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3586 return CMD_SUCCESS;
3587
3588 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3589 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3590 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3591 vty_out(vty,
3592 "%% graceful-shutdown configuration found in vrf %s\n",
3593 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3594 VRF_DEFAULT_NAME : bgp->name);
3595 vrf_cfg = true;
3596 }
3597 }
3598
3599 if (vrf_cfg) {
3600 vty_out(vty,
3601 "%%Failed: global graceful-shutdown not permitted\n");
3602 return CMD_WARNING;
3603 }
3604
3605 /* Set flag globally */
3606 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3607
3608 /* Initiate processing for all BGP instances. */
3609 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3610 bgp_initiate_graceful_shut_unshut(vty, bgp);
3611
3612 return CMD_SUCCESS;
3613 }
3614
3615 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3616 {
3617 struct listnode *node, *nnode;
3618 struct bgp *bgp;
3619
3620 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3621 return CMD_SUCCESS;
3622
3623 /* Unset flag globally */
3624 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3625
3626 /* Initiate processing for all BGP instances. */
3627 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3628 bgp_initiate_graceful_shut_unshut(vty, bgp);
3629
3630 return CMD_SUCCESS;
3631 }
3632
3633 /* "bgp graceful-shutdown" configuration */
3634 DEFUN (bgp_graceful_shutdown,
3635 bgp_graceful_shutdown_cmd,
3636 "bgp graceful-shutdown",
3637 BGP_STR
3638 "Graceful shutdown parameters\n")
3639 {
3640 if (vty->node == CONFIG_NODE)
3641 return bgp_global_graceful_shutdown_config_vty(vty);
3642
3643 VTY_DECLVAR_CONTEXT(bgp, bgp);
3644
3645 /* if configured globally, per-instance config is not allowed */
3646 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3647 vty_out(vty,
3648 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3649 return CMD_WARNING_CONFIG_FAILED;
3650 }
3651
3652 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3653 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3654 bgp_initiate_graceful_shut_unshut(vty, bgp);
3655 }
3656
3657 return CMD_SUCCESS;
3658 }
3659
3660 DEFUN (no_bgp_graceful_shutdown,
3661 no_bgp_graceful_shutdown_cmd,
3662 "no bgp graceful-shutdown",
3663 NO_STR
3664 BGP_STR
3665 "Graceful shutdown parameters\n")
3666 {
3667 if (vty->node == CONFIG_NODE)
3668 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3669
3670 VTY_DECLVAR_CONTEXT(bgp, bgp);
3671
3672 /* If configured globally, cannot remove from one bgp instance */
3673 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3674 vty_out(vty,
3675 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3676 return CMD_WARNING_CONFIG_FAILED;
3677 }
3678
3679 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3680 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3681 bgp_initiate_graceful_shut_unshut(vty, bgp);
3682 }
3683
3684 return CMD_SUCCESS;
3685 }
3686
3687 /* "bgp fast-external-failover" configuration. */
3688 DEFUN (bgp_fast_external_failover,
3689 bgp_fast_external_failover_cmd,
3690 "bgp fast-external-failover",
3691 BGP_STR
3692 "Immediately reset session if a link to a directly connected external peer goes down\n")
3693 {
3694 VTY_DECLVAR_CONTEXT(bgp, bgp);
3695 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3696 return CMD_SUCCESS;
3697 }
3698
3699 DEFUN (no_bgp_fast_external_failover,
3700 no_bgp_fast_external_failover_cmd,
3701 "no bgp fast-external-failover",
3702 NO_STR
3703 BGP_STR
3704 "Immediately reset session if a link to a directly connected external peer goes down\n")
3705 {
3706 VTY_DECLVAR_CONTEXT(bgp, bgp);
3707 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3708 return CMD_SUCCESS;
3709 }
3710
3711 DEFPY (bgp_bestpath_aigp,
3712 bgp_bestpath_aigp_cmd,
3713 "[no$no] bgp bestpath aigp",
3714 NO_STR
3715 BGP_STR
3716 "Change the default bestpath selection\n"
3717 "Evaluate the AIGP attribute during the best path selection process\n")
3718 {
3719 VTY_DECLVAR_CONTEXT(bgp, bgp);
3720
3721 if (no)
3722 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3723 else
3724 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3725
3726 bgp_recalculate_all_bestpaths(bgp);
3727
3728 return CMD_SUCCESS;
3729 }
3730
3731 /* "bgp bestpath compare-routerid" configuration. */
3732 DEFUN (bgp_bestpath_compare_router_id,
3733 bgp_bestpath_compare_router_id_cmd,
3734 "bgp bestpath compare-routerid",
3735 BGP_STR
3736 "Change the default bestpath selection\n"
3737 "Compare router-id for identical EBGP paths\n")
3738 {
3739 VTY_DECLVAR_CONTEXT(bgp, bgp);
3740 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3741 bgp_recalculate_all_bestpaths(bgp);
3742
3743 return CMD_SUCCESS;
3744 }
3745
3746 DEFUN (no_bgp_bestpath_compare_router_id,
3747 no_bgp_bestpath_compare_router_id_cmd,
3748 "no bgp bestpath compare-routerid",
3749 NO_STR
3750 BGP_STR
3751 "Change the default bestpath selection\n"
3752 "Compare router-id for identical EBGP paths\n")
3753 {
3754 VTY_DECLVAR_CONTEXT(bgp, bgp);
3755 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3756 bgp_recalculate_all_bestpaths(bgp);
3757
3758 return CMD_SUCCESS;
3759 }
3760
3761 /* "bgp bestpath as-path ignore" configuration. */
3762 DEFUN (bgp_bestpath_aspath_ignore,
3763 bgp_bestpath_aspath_ignore_cmd,
3764 "bgp bestpath as-path ignore",
3765 BGP_STR
3766 "Change the default bestpath selection\n"
3767 "AS-path attribute\n"
3768 "Ignore as-path length in selecting a route\n")
3769 {
3770 VTY_DECLVAR_CONTEXT(bgp, bgp);
3771 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3772 bgp_recalculate_all_bestpaths(bgp);
3773
3774 return CMD_SUCCESS;
3775 }
3776
3777 DEFUN (no_bgp_bestpath_aspath_ignore,
3778 no_bgp_bestpath_aspath_ignore_cmd,
3779 "no bgp bestpath as-path ignore",
3780 NO_STR
3781 BGP_STR
3782 "Change the default bestpath selection\n"
3783 "AS-path attribute\n"
3784 "Ignore as-path length in selecting a route\n")
3785 {
3786 VTY_DECLVAR_CONTEXT(bgp, bgp);
3787 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3788 bgp_recalculate_all_bestpaths(bgp);
3789
3790 return CMD_SUCCESS;
3791 }
3792
3793 /* "bgp bestpath as-path confed" configuration. */
3794 DEFUN (bgp_bestpath_aspath_confed,
3795 bgp_bestpath_aspath_confed_cmd,
3796 "bgp bestpath as-path confed",
3797 BGP_STR
3798 "Change the default bestpath selection\n"
3799 "AS-path attribute\n"
3800 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3801 {
3802 VTY_DECLVAR_CONTEXT(bgp, bgp);
3803 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3804 bgp_recalculate_all_bestpaths(bgp);
3805
3806 return CMD_SUCCESS;
3807 }
3808
3809 DEFUN (no_bgp_bestpath_aspath_confed,
3810 no_bgp_bestpath_aspath_confed_cmd,
3811 "no bgp bestpath as-path confed",
3812 NO_STR
3813 BGP_STR
3814 "Change the default bestpath selection\n"
3815 "AS-path attribute\n"
3816 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3817 {
3818 VTY_DECLVAR_CONTEXT(bgp, bgp);
3819 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3820 bgp_recalculate_all_bestpaths(bgp);
3821
3822 return CMD_SUCCESS;
3823 }
3824
3825 /* "bgp bestpath as-path multipath-relax" configuration. */
3826 DEFUN (bgp_bestpath_aspath_multipath_relax,
3827 bgp_bestpath_aspath_multipath_relax_cmd,
3828 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3829 BGP_STR
3830 "Change the default bestpath selection\n"
3831 "AS-path attribute\n"
3832 "Allow load sharing across routes that have different AS paths (but same length)\n"
3833 "Generate an AS_SET\n"
3834 "Do not generate an AS_SET\n")
3835 {
3836 VTY_DECLVAR_CONTEXT(bgp, bgp);
3837 int idx = 0;
3838 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3839
3840 /* no-as-set is now the default behavior so we can silently
3841 * ignore it */
3842 if (argv_find(argv, argc, "as-set", &idx))
3843 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3844 else
3845 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3846
3847 bgp_recalculate_all_bestpaths(bgp);
3848
3849 return CMD_SUCCESS;
3850 }
3851
3852 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3853 no_bgp_bestpath_aspath_multipath_relax_cmd,
3854 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3855 NO_STR
3856 BGP_STR
3857 "Change the default bestpath selection\n"
3858 "AS-path attribute\n"
3859 "Allow load sharing across routes that have different AS paths (but same length)\n"
3860 "Generate an AS_SET\n"
3861 "Do not generate an AS_SET\n")
3862 {
3863 VTY_DECLVAR_CONTEXT(bgp, bgp);
3864 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3865 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3866 bgp_recalculate_all_bestpaths(bgp);
3867
3868 return CMD_SUCCESS;
3869 }
3870
3871 /* "bgp bestpath peer-type multipath-relax" configuration. */
3872 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3873 bgp_bestpath_peer_type_multipath_relax_cmd,
3874 "bgp bestpath peer-type multipath-relax",
3875 BGP_STR
3876 "Change the default bestpath selection\n"
3877 "Peer type\n"
3878 "Allow load sharing across routes learned from different peer types\n")
3879 {
3880 VTY_DECLVAR_CONTEXT(bgp, bgp);
3881 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3882 bgp_recalculate_all_bestpaths(bgp);
3883
3884 return CMD_SUCCESS;
3885 }
3886
3887 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3888 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3889 "no bgp bestpath peer-type multipath-relax",
3890 NO_STR BGP_STR
3891 "Change the default bestpath selection\n"
3892 "Peer type\n"
3893 "Allow load sharing across routes learned from different peer types\n")
3894 {
3895 VTY_DECLVAR_CONTEXT(bgp, bgp);
3896 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3897 bgp_recalculate_all_bestpaths(bgp);
3898
3899 return CMD_SUCCESS;
3900 }
3901
3902 /* "bgp log-neighbor-changes" configuration. */
3903 DEFUN (bgp_log_neighbor_changes,
3904 bgp_log_neighbor_changes_cmd,
3905 "bgp log-neighbor-changes",
3906 BGP_STR
3907 "Log neighbor up/down and reset reason\n")
3908 {
3909 VTY_DECLVAR_CONTEXT(bgp, bgp);
3910 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3911 return CMD_SUCCESS;
3912 }
3913
3914 DEFUN (no_bgp_log_neighbor_changes,
3915 no_bgp_log_neighbor_changes_cmd,
3916 "no bgp log-neighbor-changes",
3917 NO_STR
3918 BGP_STR
3919 "Log neighbor up/down and reset reason\n")
3920 {
3921 VTY_DECLVAR_CONTEXT(bgp, bgp);
3922 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3923 return CMD_SUCCESS;
3924 }
3925
3926 /* "bgp bestpath med" configuration. */
3927 DEFUN (bgp_bestpath_med,
3928 bgp_bestpath_med_cmd,
3929 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3930 BGP_STR
3931 "Change the default bestpath selection\n"
3932 "MED attribute\n"
3933 "Compare MED among confederation paths\n"
3934 "Treat missing MED as the least preferred one\n"
3935 "Treat missing MED as the least preferred one\n"
3936 "Compare MED among confederation paths\n")
3937 {
3938 VTY_DECLVAR_CONTEXT(bgp, bgp);
3939
3940 int idx = 0;
3941 if (argv_find(argv, argc, "confed", &idx))
3942 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3943 idx = 0;
3944 if (argv_find(argv, argc, "missing-as-worst", &idx))
3945 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3946
3947 bgp_recalculate_all_bestpaths(bgp);
3948
3949 return CMD_SUCCESS;
3950 }
3951
3952 DEFUN (no_bgp_bestpath_med,
3953 no_bgp_bestpath_med_cmd,
3954 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3955 NO_STR
3956 BGP_STR
3957 "Change the default bestpath selection\n"
3958 "MED attribute\n"
3959 "Compare MED among confederation paths\n"
3960 "Treat missing MED as the least preferred one\n"
3961 "Treat missing MED as the least preferred one\n"
3962 "Compare MED among confederation paths\n")
3963 {
3964 VTY_DECLVAR_CONTEXT(bgp, bgp);
3965
3966 int idx = 0;
3967 if (argv_find(argv, argc, "confed", &idx))
3968 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3969 idx = 0;
3970 if (argv_find(argv, argc, "missing-as-worst", &idx))
3971 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3972
3973 bgp_recalculate_all_bestpaths(bgp);
3974
3975 return CMD_SUCCESS;
3976 }
3977
3978 /* "bgp bestpath bandwidth" configuration. */
3979 DEFPY (bgp_bestpath_bw,
3980 bgp_bestpath_bw_cmd,
3981 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3982 BGP_STR
3983 "Change the default bestpath selection\n"
3984 "Link Bandwidth attribute\n"
3985 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3986 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3987 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3988 {
3989 VTY_DECLVAR_CONTEXT(bgp, bgp);
3990 afi_t afi;
3991 safi_t safi;
3992
3993 if (!bw_cfg) {
3994 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3995 return CMD_ERR_INCOMPLETE;
3996 }
3997 if (!strcmp(bw_cfg, "ignore"))
3998 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3999 else if (!strcmp(bw_cfg, "skip-missing"))
4000 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
4001 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
4002 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
4003 else
4004 return CMD_ERR_NO_MATCH;
4005
4006 /* This config is used in route install, so redo that. */
4007 FOREACH_AFI_SAFI (afi, safi) {
4008 if (!bgp_fibupd_safi(safi))
4009 continue;
4010 bgp_zebra_announce_table(bgp, afi, safi);
4011 }
4012
4013 return CMD_SUCCESS;
4014 }
4015
4016 DEFPY (no_bgp_bestpath_bw,
4017 no_bgp_bestpath_bw_cmd,
4018 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
4019 NO_STR
4020 BGP_STR
4021 "Change the default bestpath selection\n"
4022 "Link Bandwidth attribute\n"
4023 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
4024 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
4025 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
4026 {
4027 VTY_DECLVAR_CONTEXT(bgp, bgp);
4028 afi_t afi;
4029 safi_t safi;
4030
4031 bgp->lb_handling = BGP_LINK_BW_ECMP;
4032
4033 /* This config is used in route install, so redo that. */
4034 FOREACH_AFI_SAFI (afi, safi) {
4035 if (!bgp_fibupd_safi(safi))
4036 continue;
4037 bgp_zebra_announce_table(bgp, afi, safi);
4038 }
4039 return CMD_SUCCESS;
4040 }
4041
4042 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
4043 "[no] bgp default <ipv4-unicast|"
4044 "ipv4-multicast|"
4045 "ipv4-vpn|"
4046 "ipv4-labeled-unicast|"
4047 "ipv4-flowspec|"
4048 "ipv6-unicast|"
4049 "ipv6-multicast|"
4050 "ipv6-vpn|"
4051 "ipv6-labeled-unicast|"
4052 "ipv6-flowspec|"
4053 "l2vpn-evpn>$afi_safi",
4054 NO_STR
4055 BGP_STR
4056 "Configure BGP defaults\n"
4057 "Activate ipv4-unicast for a peer by default\n"
4058 "Activate ipv4-multicast for a peer by default\n"
4059 "Activate ipv4-vpn for a peer by default\n"
4060 "Activate ipv4-labeled-unicast for a peer by default\n"
4061 "Activate ipv4-flowspec for a peer by default\n"
4062 "Activate ipv6-unicast for a peer by default\n"
4063 "Activate ipv6-multicast for a peer by default\n"
4064 "Activate ipv6-vpn for a peer by default\n"
4065 "Activate ipv6-labeled-unicast for a peer by default\n"
4066 "Activate ipv6-flowspec for a peer by default\n"
4067 "Activate l2vpn-evpn for a peer by default\n")
4068 {
4069 VTY_DECLVAR_CONTEXT(bgp, bgp);
4070 char afi_safi_str[strlen(afi_safi) + 1];
4071 char *afi_safi_str_tok;
4072
4073 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4074 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4075 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4076 afi_t afi = bgp_vty_afi_from_str(afi_str);
4077 safi_t safi;
4078
4079 /*
4080 * Impossible situation but making coverity happy
4081 */
4082 assert(afi != AFI_MAX);
4083
4084 if (strmatch(safi_str, "labeled"))
4085 safi = bgp_vty_safi_from_str("labeled-unicast");
4086 else
4087 safi = bgp_vty_safi_from_str(safi_str);
4088
4089 assert(safi != SAFI_MAX);
4090 if (no)
4091 bgp->default_af[afi][safi] = false;
4092 else {
4093 if ((safi == SAFI_LABELED_UNICAST
4094 && bgp->default_af[afi][SAFI_UNICAST])
4095 || (safi == SAFI_UNICAST
4096 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4097 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4098 else
4099 bgp->default_af[afi][safi] = true;
4100 }
4101
4102 return CMD_SUCCESS;
4103 }
4104
4105 /* Display hostname in certain command outputs */
4106 DEFUN (bgp_default_show_hostname,
4107 bgp_default_show_hostname_cmd,
4108 "bgp default show-hostname",
4109 BGP_STR
4110 "Configure BGP defaults\n"
4111 "Show hostname in certain command outputs\n")
4112 {
4113 VTY_DECLVAR_CONTEXT(bgp, bgp);
4114 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4115 return CMD_SUCCESS;
4116 }
4117
4118 DEFUN (no_bgp_default_show_hostname,
4119 no_bgp_default_show_hostname_cmd,
4120 "no bgp default show-hostname",
4121 NO_STR
4122 BGP_STR
4123 "Configure BGP defaults\n"
4124 "Show hostname in certain command outputs\n")
4125 {
4126 VTY_DECLVAR_CONTEXT(bgp, bgp);
4127 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4128 return CMD_SUCCESS;
4129 }
4130
4131 /* Display hostname in certain command outputs */
4132 DEFUN (bgp_default_show_nexthop_hostname,
4133 bgp_default_show_nexthop_hostname_cmd,
4134 "bgp default show-nexthop-hostname",
4135 BGP_STR
4136 "Configure BGP defaults\n"
4137 "Show hostname for nexthop in certain command outputs\n")
4138 {
4139 VTY_DECLVAR_CONTEXT(bgp, bgp);
4140 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4141 return CMD_SUCCESS;
4142 }
4143
4144 DEFUN (no_bgp_default_show_nexthop_hostname,
4145 no_bgp_default_show_nexthop_hostname_cmd,
4146 "no bgp default show-nexthop-hostname",
4147 NO_STR
4148 BGP_STR
4149 "Configure BGP defaults\n"
4150 "Show hostname for nexthop in certain command outputs\n")
4151 {
4152 VTY_DECLVAR_CONTEXT(bgp, bgp);
4153 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4154 return CMD_SUCCESS;
4155 }
4156
4157 /* "bgp network import-check" configuration. */
4158 DEFUN (bgp_network_import_check,
4159 bgp_network_import_check_cmd,
4160 "bgp network import-check",
4161 BGP_STR
4162 "BGP network command\n"
4163 "Check BGP network route exists in IGP\n")
4164 {
4165 VTY_DECLVAR_CONTEXT(bgp, bgp);
4166 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4167 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4168 bgp_static_redo_import_check(bgp);
4169 }
4170
4171 return CMD_SUCCESS;
4172 }
4173
4174 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4175 "bgp network import-check exact",
4176 BGP_STR
4177 "BGP network command\n"
4178 "Check BGP network route exists in IGP\n"
4179 "Match route precisely\n")
4180
4181 DEFUN (no_bgp_network_import_check,
4182 no_bgp_network_import_check_cmd,
4183 "no bgp network import-check",
4184 NO_STR
4185 BGP_STR
4186 "BGP network command\n"
4187 "Check BGP network route exists in IGP\n")
4188 {
4189 VTY_DECLVAR_CONTEXT(bgp, bgp);
4190 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4191 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4192 bgp_static_redo_import_check(bgp);
4193 }
4194
4195 return CMD_SUCCESS;
4196 }
4197
4198 DEFUN (bgp_default_local_preference,
4199 bgp_default_local_preference_cmd,
4200 "bgp default local-preference (0-4294967295)",
4201 BGP_STR
4202 "Configure BGP defaults\n"
4203 "local preference (higher=more preferred)\n"
4204 "Configure default local preference value\n")
4205 {
4206 VTY_DECLVAR_CONTEXT(bgp, bgp);
4207 int idx_number = 3;
4208 uint32_t local_pref;
4209
4210 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4211
4212 bgp_default_local_preference_set(bgp, local_pref);
4213 bgp_clear_star_soft_in(vty, bgp->name);
4214
4215 return CMD_SUCCESS;
4216 }
4217
4218 DEFUN (no_bgp_default_local_preference,
4219 no_bgp_default_local_preference_cmd,
4220 "no bgp default local-preference [(0-4294967295)]",
4221 NO_STR
4222 BGP_STR
4223 "Configure BGP defaults\n"
4224 "local preference (higher=more preferred)\n"
4225 "Configure default local preference value\n")
4226 {
4227 VTY_DECLVAR_CONTEXT(bgp, bgp);
4228 bgp_default_local_preference_unset(bgp);
4229 bgp_clear_star_soft_in(vty, bgp->name);
4230
4231 return CMD_SUCCESS;
4232 }
4233
4234
4235 DEFUN (bgp_default_subgroup_pkt_queue_max,
4236 bgp_default_subgroup_pkt_queue_max_cmd,
4237 "bgp default subgroup-pkt-queue-max (20-100)",
4238 BGP_STR
4239 "Configure BGP defaults\n"
4240 "subgroup-pkt-queue-max\n"
4241 "Configure subgroup packet queue max\n")
4242 {
4243 VTY_DECLVAR_CONTEXT(bgp, bgp);
4244 int idx_number = 3;
4245 uint32_t max_size;
4246
4247 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4248
4249 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4250
4251 return CMD_SUCCESS;
4252 }
4253
4254 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4255 no_bgp_default_subgroup_pkt_queue_max_cmd,
4256 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4257 NO_STR
4258 BGP_STR
4259 "Configure BGP defaults\n"
4260 "subgroup-pkt-queue-max\n"
4261 "Configure subgroup packet queue max\n")
4262 {
4263 VTY_DECLVAR_CONTEXT(bgp, bgp);
4264 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4265 return CMD_SUCCESS;
4266 }
4267
4268
4269 DEFUN (bgp_rr_allow_outbound_policy,
4270 bgp_rr_allow_outbound_policy_cmd,
4271 "bgp route-reflector allow-outbound-policy",
4272 BGP_STR
4273 "Allow modifications made by out route-map\n"
4274 "on ibgp neighbors\n")
4275 {
4276 VTY_DECLVAR_CONTEXT(bgp, bgp);
4277
4278 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4279 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4280 update_group_announce_rrclients(bgp);
4281 bgp_clear_star_soft_out(vty, bgp->name);
4282 }
4283
4284 return CMD_SUCCESS;
4285 }
4286
4287 DEFUN (no_bgp_rr_allow_outbound_policy,
4288 no_bgp_rr_allow_outbound_policy_cmd,
4289 "no bgp route-reflector allow-outbound-policy",
4290 NO_STR
4291 BGP_STR
4292 "Allow modifications made by out route-map\n"
4293 "on ibgp neighbors\n")
4294 {
4295 VTY_DECLVAR_CONTEXT(bgp, bgp);
4296
4297 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4298 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4299 update_group_announce_rrclients(bgp);
4300 bgp_clear_star_soft_out(vty, bgp->name);
4301 }
4302
4303 return CMD_SUCCESS;
4304 }
4305
4306 DEFUN (bgp_listen_limit,
4307 bgp_listen_limit_cmd,
4308 "bgp listen limit (1-65535)",
4309 BGP_STR
4310 "BGP Dynamic Neighbors listen commands\n"
4311 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4312 "Configure Dynamic Neighbors listen limit value\n")
4313 {
4314 VTY_DECLVAR_CONTEXT(bgp, bgp);
4315 int idx_number = 3;
4316 int listen_limit;
4317
4318 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4319
4320 bgp_listen_limit_set(bgp, listen_limit);
4321
4322 return CMD_SUCCESS;
4323 }
4324
4325 DEFUN (no_bgp_listen_limit,
4326 no_bgp_listen_limit_cmd,
4327 "no bgp listen limit [(1-65535)]",
4328 NO_STR
4329 BGP_STR
4330 "BGP Dynamic Neighbors listen commands\n"
4331 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4332 "Configure Dynamic Neighbors listen limit value\n")
4333 {
4334 VTY_DECLVAR_CONTEXT(bgp, bgp);
4335 bgp_listen_limit_unset(bgp);
4336 return CMD_SUCCESS;
4337 }
4338
4339
4340 /*
4341 * Check if this listen range is already configured. Check for exact
4342 * match or overlap based on input.
4343 */
4344 static struct peer_group *listen_range_exists(struct bgp *bgp,
4345 struct prefix *range, int exact)
4346 {
4347 struct listnode *node, *nnode;
4348 struct listnode *node1, *nnode1;
4349 struct peer_group *group;
4350 struct prefix *lr;
4351 afi_t afi;
4352 int match;
4353
4354 afi = family2afi(range->family);
4355 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4356 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4357 lr)) {
4358 if (exact)
4359 match = prefix_same(range, lr);
4360 else
4361 match = (prefix_match(range, lr)
4362 || prefix_match(lr, range));
4363 if (match)
4364 return group;
4365 }
4366 }
4367
4368 return NULL;
4369 }
4370
4371 DEFUN (bgp_listen_range,
4372 bgp_listen_range_cmd,
4373 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4374 BGP_STR
4375 "Configure BGP dynamic neighbors listen range\n"
4376 "Configure BGP dynamic neighbors listen range\n"
4377 NEIGHBOR_ADDR_STR
4378 "Member of the peer-group\n"
4379 "Peer-group name\n")
4380 {
4381 VTY_DECLVAR_CONTEXT(bgp, bgp);
4382 struct prefix range;
4383 struct peer_group *group, *existing_group;
4384 afi_t afi;
4385 int ret;
4386 int idx = 0;
4387
4388 argv_find(argv, argc, "A.B.C.D/M", &idx);
4389 argv_find(argv, argc, "X:X::X:X/M", &idx);
4390 char *prefix = argv[idx]->arg;
4391 argv_find(argv, argc, "PGNAME", &idx);
4392 char *peergroup = argv[idx]->arg;
4393
4394 /* Convert IP prefix string to struct prefix. */
4395 ret = str2prefix(prefix, &range);
4396 if (!ret) {
4397 vty_out(vty, "%% Malformed listen range\n");
4398 return CMD_WARNING_CONFIG_FAILED;
4399 }
4400
4401 afi = family2afi(range.family);
4402
4403 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4404 vty_out(vty,
4405 "%% Malformed listen range (link-local address)\n");
4406 return CMD_WARNING_CONFIG_FAILED;
4407 }
4408
4409 apply_mask(&range);
4410
4411 /* Check if same listen range is already configured. */
4412 existing_group = listen_range_exists(bgp, &range, 1);
4413 if (existing_group) {
4414 if (strcmp(existing_group->name, peergroup) == 0)
4415 return CMD_SUCCESS;
4416 else {
4417 vty_out(vty,
4418 "%% Same listen range is attached to peer-group %s\n",
4419 existing_group->name);
4420 return CMD_WARNING_CONFIG_FAILED;
4421 }
4422 }
4423
4424 /* Check if an overlapping listen range exists. */
4425 if (listen_range_exists(bgp, &range, 0)) {
4426 vty_out(vty,
4427 "%% Listen range overlaps with existing listen range\n");
4428 return CMD_WARNING_CONFIG_FAILED;
4429 }
4430
4431 group = peer_group_lookup(bgp, peergroup);
4432 if (!group) {
4433 vty_out(vty, "%% Configure the peer-group first\n");
4434 return CMD_WARNING_CONFIG_FAILED;
4435 }
4436
4437 ret = peer_group_listen_range_add(group, &range);
4438 return bgp_vty_return(vty, ret);
4439 }
4440
4441 DEFUN (no_bgp_listen_range,
4442 no_bgp_listen_range_cmd,
4443 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4444 NO_STR
4445 BGP_STR
4446 "Unconfigure BGP dynamic neighbors listen range\n"
4447 "Unconfigure BGP dynamic neighbors listen range\n"
4448 NEIGHBOR_ADDR_STR
4449 "Member of the peer-group\n"
4450 "Peer-group name\n")
4451 {
4452 VTY_DECLVAR_CONTEXT(bgp, bgp);
4453 struct prefix range;
4454 struct peer_group *group;
4455 afi_t afi;
4456 int ret;
4457 int idx = 0;
4458
4459 argv_find(argv, argc, "A.B.C.D/M", &idx);
4460 argv_find(argv, argc, "X:X::X:X/M", &idx);
4461 char *prefix = argv[idx]->arg;
4462 argv_find(argv, argc, "PGNAME", &idx);
4463 char *peergroup = argv[idx]->arg;
4464
4465 /* Convert IP prefix string to struct prefix. */
4466 ret = str2prefix(prefix, &range);
4467 if (!ret) {
4468 vty_out(vty, "%% Malformed listen range\n");
4469 return CMD_WARNING_CONFIG_FAILED;
4470 }
4471
4472 afi = family2afi(range.family);
4473
4474 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4475 vty_out(vty,
4476 "%% Malformed listen range (link-local address)\n");
4477 return CMD_WARNING_CONFIG_FAILED;
4478 }
4479
4480 apply_mask(&range);
4481
4482 group = peer_group_lookup(bgp, peergroup);
4483 if (!group) {
4484 vty_out(vty, "%% Peer-group does not exist\n");
4485 return CMD_WARNING_CONFIG_FAILED;
4486 }
4487
4488 ret = peer_group_listen_range_del(group, &range);
4489 return bgp_vty_return(vty, ret);
4490 }
4491
4492 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4493 {
4494 struct peer_group *group;
4495 struct listnode *node, *nnode, *rnode, *nrnode;
4496 struct prefix *range;
4497 afi_t afi;
4498
4499 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4500 vty_out(vty, " bgp listen limit %d\n",
4501 bgp->dynamic_neighbors_limit);
4502
4503 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4504 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4505 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4506 nrnode, range)) {
4507 vty_out(vty,
4508 " bgp listen range %pFX peer-group %s\n",
4509 range, group->name);
4510 }
4511 }
4512 }
4513 }
4514
4515
4516 DEFUN (bgp_disable_connected_route_check,
4517 bgp_disable_connected_route_check_cmd,
4518 "bgp disable-ebgp-connected-route-check",
4519 BGP_STR
4520 "Disable checking if nexthop is connected on ebgp sessions\n")
4521 {
4522 VTY_DECLVAR_CONTEXT(bgp, bgp);
4523 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4524 bgp_clear_star_soft_in(vty, bgp->name);
4525
4526 return CMD_SUCCESS;
4527 }
4528
4529 DEFUN (no_bgp_disable_connected_route_check,
4530 no_bgp_disable_connected_route_check_cmd,
4531 "no bgp disable-ebgp-connected-route-check",
4532 NO_STR
4533 BGP_STR
4534 "Disable checking if nexthop is connected on ebgp sessions\n")
4535 {
4536 VTY_DECLVAR_CONTEXT(bgp, bgp);
4537 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4538 bgp_clear_star_soft_in(vty, bgp->name);
4539
4540 return CMD_SUCCESS;
4541 }
4542
4543
4544 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4545 const char *as_str)
4546 {
4547 VTY_DECLVAR_CONTEXT(bgp, bgp);
4548 int ret;
4549 as_t as;
4550 int as_type = AS_SPECIFIED;
4551 union sockunion su;
4552
4553 if (as_str[0] == 'i') {
4554 as = 0;
4555 as_type = AS_INTERNAL;
4556 } else if (as_str[0] == 'e') {
4557 as = 0;
4558 as_type = AS_EXTERNAL;
4559 } else if (!asn_str2asn(as_str, &as))
4560 as_type = AS_UNSPECIFIED;
4561
4562 if (as_type == AS_UNSPECIFIED) {
4563 vty_out(vty, "%% Invalid peer AS: %s\n", as_str);
4564 return CMD_WARNING_CONFIG_FAILED;
4565 }
4566 /* If peer is peer group or interface peer, call proper function. */
4567 ret = str2sockunion(peer_str, &su);
4568 if (ret < 0) {
4569 struct peer *peer;
4570
4571 /* Check if existing interface peer */
4572 peer = peer_lookup_by_conf_if(bgp, peer_str);
4573
4574 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, as_str);
4575
4576 /* if not interface peer, check peer-group settings */
4577 if (ret < 0 && !peer) {
4578 ret = peer_group_remote_as(bgp, peer_str, &as, as_type,
4579 as_str);
4580 if (ret < 0) {
4581 vty_out(vty,
4582 "%% Create the peer-group or interface first\n");
4583 return CMD_WARNING_CONFIG_FAILED;
4584 }
4585 return CMD_SUCCESS;
4586 }
4587 } else {
4588 if (peer_address_self_check(bgp, &su)) {
4589 vty_out(vty,
4590 "%% Can not configure the local system as neighbor\n");
4591 return CMD_WARNING_CONFIG_FAILED;
4592 }
4593 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, as_str);
4594 }
4595
4596 return bgp_vty_return(vty, ret);
4597 }
4598
4599 DEFUN (bgp_default_shutdown,
4600 bgp_default_shutdown_cmd,
4601 "[no] bgp default shutdown",
4602 NO_STR
4603 BGP_STR
4604 "Configure BGP defaults\n"
4605 "Apply administrative shutdown to newly configured peers\n")
4606 {
4607 VTY_DECLVAR_CONTEXT(bgp, bgp);
4608 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4609 return CMD_SUCCESS;
4610 }
4611
4612 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4613 BGP_STR
4614 "Administrative shutdown of the BGP instance\n"
4615 "Add a shutdown message (RFC 8203)\n"
4616 "Shutdown message\n")
4617 {
4618 char *msgstr = NULL;
4619
4620 VTY_DECLVAR_CONTEXT(bgp, bgp);
4621
4622 if (argc > 3)
4623 msgstr = argv_concat(argv, argc, 3);
4624
4625 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4626 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4627 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4628 return CMD_WARNING_CONFIG_FAILED;
4629 }
4630
4631 bgp_shutdown_enable(bgp, msgstr);
4632 XFREE(MTYPE_TMP, msgstr);
4633
4634 return CMD_SUCCESS;
4635 }
4636
4637 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4638 BGP_STR "Administrative shutdown of the BGP instance\n")
4639 {
4640 VTY_DECLVAR_CONTEXT(bgp, bgp);
4641
4642 bgp_shutdown_enable(bgp, NULL);
4643
4644 return CMD_SUCCESS;
4645 }
4646
4647 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4648 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4649 {
4650 VTY_DECLVAR_CONTEXT(bgp, bgp);
4651
4652 bgp_shutdown_disable(bgp);
4653
4654 return CMD_SUCCESS;
4655 }
4656
4657 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4658 "no bgp shutdown message MSG...", NO_STR BGP_STR
4659 "Administrative shutdown of the BGP instance\n"
4660 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4661
4662 DEFUN (neighbor_remote_as,
4663 neighbor_remote_as_cmd,
4664 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <ASNUM|internal|external>",
4665 NEIGHBOR_STR
4666 NEIGHBOR_ADDR_STR2
4667 "Specify a BGP neighbor\n"
4668 AS_STR
4669 "Internal BGP peer\n"
4670 "External BGP peer\n")
4671 {
4672 int idx_peer = 1;
4673 int idx_remote_as = 3;
4674 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4675 argv[idx_remote_as]->arg);
4676 }
4677
4678 DEFPY (bgp_allow_martian,
4679 bgp_allow_martian_cmd,
4680 "[no]$no bgp allow-martian-nexthop",
4681 NO_STR
4682 BGP_STR
4683 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4684 {
4685 VTY_DECLVAR_CONTEXT(bgp, bgp);
4686
4687 if (no)
4688 bgp->allow_martian = false;
4689 else
4690 bgp->allow_martian = true;
4691
4692 return CMD_SUCCESS;
4693 }
4694
4695 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4696 * sessions do not wait for hold timer expiry to bring down the sessions
4697 * when nexthop becomes unreachable
4698 */
4699 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4700 BGP_STR "Fast convergence for bgp sessions\n")
4701 {
4702 VTY_DECLVAR_CONTEXT(bgp, bgp);
4703 bgp->fast_convergence = true;
4704
4705 return CMD_SUCCESS;
4706 }
4707
4708 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4709 "no bgp fast-convergence",
4710 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4711 {
4712 VTY_DECLVAR_CONTEXT(bgp, bgp);
4713 bgp->fast_convergence = false;
4714
4715 return CMD_SUCCESS;
4716 }
4717
4718 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4719 int v6only,
4720 const char *peer_group_name,
4721 const char *as_str)
4722 {
4723 VTY_DECLVAR_CONTEXT(bgp, bgp);
4724 as_t as = 0;
4725 int as_type = AS_UNSPECIFIED;
4726 struct peer *peer;
4727 struct peer_group *group;
4728 int ret = 0;
4729
4730 group = peer_group_lookup(bgp, conf_if);
4731
4732 if (group) {
4733 vty_out(vty, "%% Name conflict with peer-group \n");
4734 return CMD_WARNING_CONFIG_FAILED;
4735 }
4736
4737 if (as_str) {
4738 if (as_str[0] == 'i') {
4739 as_type = AS_INTERNAL;
4740 } else if (as_str[0] == 'e') {
4741 as_type = AS_EXTERNAL;
4742 } else {
4743 /* Get AS number. */
4744 if (asn_str2asn(as_str, &as))
4745 as_type = AS_SPECIFIED;
4746 }
4747 }
4748
4749 peer = peer_lookup_by_conf_if(bgp, conf_if);
4750 if (peer) {
4751 if (as_str)
4752 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4753 as_str);
4754 } else {
4755 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4756 NULL, true, as_str);
4757
4758 if (!peer) {
4759 vty_out(vty, "%% BGP failed to create peer\n");
4760 return CMD_WARNING_CONFIG_FAILED;
4761 }
4762
4763 if (v6only)
4764 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4765
4766 /* Request zebra to initiate IPv6 RAs on this interface. We do
4767 * this
4768 * any unnumbered peer in order to not worry about run-time
4769 * transitions
4770 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4771 * address
4772 * gets deleted later etc.)
4773 */
4774 if (peer->ifp)
4775 bgp_zebra_initiate_radv(bgp, peer);
4776 }
4777
4778 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4779 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4780 if (v6only)
4781 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4782 else
4783 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4784
4785 /* v6only flag changed. Reset bgp seesion */
4786 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4787 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4788 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4789 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4790 } else
4791 bgp_session_reset(peer);
4792 }
4793
4794 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4795 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4796 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4797 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4798 }
4799
4800 if (peer_group_name) {
4801 group = peer_group_lookup(bgp, peer_group_name);
4802 if (!group) {
4803 vty_out(vty, "%% Configure the peer-group first\n");
4804 return CMD_WARNING_CONFIG_FAILED;
4805 }
4806
4807 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4808 }
4809
4810 return bgp_vty_return(vty, ret);
4811 }
4812
4813 DEFUN (neighbor_interface_config,
4814 neighbor_interface_config_cmd,
4815 "neighbor WORD interface [peer-group PGNAME]",
4816 NEIGHBOR_STR
4817 "Interface name or neighbor tag\n"
4818 "Enable BGP on interface\n"
4819 "Member of the peer-group\n"
4820 "Peer-group name\n")
4821 {
4822 int idx_word = 1;
4823 int idx_peer_group_word = 4;
4824
4825 if (argc > idx_peer_group_word)
4826 return peer_conf_interface_get(
4827 vty, argv[idx_word]->arg, 0,
4828 argv[idx_peer_group_word]->arg, NULL);
4829 else
4830 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4831 NULL, NULL);
4832 }
4833
4834 DEFUN (neighbor_interface_config_v6only,
4835 neighbor_interface_config_v6only_cmd,
4836 "neighbor WORD interface v6only [peer-group PGNAME]",
4837 NEIGHBOR_STR
4838 "Interface name or neighbor tag\n"
4839 "Enable BGP on interface\n"
4840 "Enable BGP with v6 link-local only\n"
4841 "Member of the peer-group\n"
4842 "Peer-group name\n")
4843 {
4844 int idx_word = 1;
4845 int idx_peer_group_word = 5;
4846
4847 if (argc > idx_peer_group_word)
4848 return peer_conf_interface_get(
4849 vty, argv[idx_word]->arg, 1,
4850 argv[idx_peer_group_word]->arg, NULL);
4851
4852 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4853 }
4854
4855
4856 DEFUN (neighbor_interface_config_remote_as,
4857 neighbor_interface_config_remote_as_cmd,
4858 "neighbor WORD interface remote-as <ASNUM|internal|external>",
4859 NEIGHBOR_STR
4860 "Interface name or neighbor tag\n"
4861 "Enable BGP on interface\n"
4862 "Specify a BGP neighbor\n"
4863 AS_STR
4864 "Internal BGP peer\n"
4865 "External BGP peer\n")
4866 {
4867 int idx_word = 1;
4868 int idx_remote_as = 4;
4869 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4870 argv[idx_remote_as]->arg);
4871 }
4872
4873 DEFUN (neighbor_interface_v6only_config_remote_as,
4874 neighbor_interface_v6only_config_remote_as_cmd,
4875 "neighbor WORD interface v6only remote-as <ASNUM|internal|external>",
4876 NEIGHBOR_STR
4877 "Interface name or neighbor tag\n"
4878 "Enable BGP with v6 link-local only\n"
4879 "Enable BGP on interface\n"
4880 "Specify a BGP neighbor\n"
4881 AS_STR
4882 "Internal BGP peer\n"
4883 "External BGP peer\n")
4884 {
4885 int idx_word = 1;
4886 int idx_remote_as = 5;
4887 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4888 argv[idx_remote_as]->arg);
4889 }
4890
4891 DEFUN (neighbor_peer_group,
4892 neighbor_peer_group_cmd,
4893 "neighbor WORD peer-group",
4894 NEIGHBOR_STR
4895 "Interface name or neighbor tag\n"
4896 "Configure peer-group\n")
4897 {
4898 VTY_DECLVAR_CONTEXT(bgp, bgp);
4899 int idx_word = 1;
4900 struct peer *peer;
4901 struct peer_group *group;
4902
4903 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4904 if (peer) {
4905 vty_out(vty, "%% Name conflict with interface: \n");
4906 return CMD_WARNING_CONFIG_FAILED;
4907 }
4908
4909 group = peer_group_get(bgp, argv[idx_word]->arg);
4910 if (!group) {
4911 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4912 return CMD_WARNING_CONFIG_FAILED;
4913 }
4914
4915 return CMD_SUCCESS;
4916 }
4917
4918 DEFUN (no_neighbor,
4919 no_neighbor_cmd,
4920 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4921 NO_STR
4922 NEIGHBOR_STR
4923 NEIGHBOR_ADDR_STR2
4924 "Specify a BGP neighbor\n"
4925 AS_STR
4926 "Internal BGP peer\n"
4927 "External BGP peer\n")
4928 {
4929 VTY_DECLVAR_CONTEXT(bgp, bgp);
4930 int idx_peer = 2;
4931 int ret;
4932 union sockunion su;
4933 struct peer_group *group;
4934 struct peer *peer;
4935 struct peer *other;
4936
4937 ret = str2sockunion(argv[idx_peer]->arg, &su);
4938 if (ret < 0) {
4939 /* look up for neighbor by interface name config. */
4940 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4941 if (peer) {
4942 /* Request zebra to terminate IPv6 RAs on this
4943 * interface. */
4944 if (peer->ifp)
4945 bgp_zebra_terminate_radv(peer->bgp, peer);
4946 peer_notify_unconfig(peer);
4947 peer_delete(peer);
4948 return CMD_SUCCESS;
4949 }
4950
4951 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4952 if (group) {
4953 peer_group_notify_unconfig(group);
4954 peer_group_delete(group);
4955 } else {
4956 vty_out(vty, "%% Create the peer-group first\n");
4957 return CMD_WARNING_CONFIG_FAILED;
4958 }
4959 } else {
4960 peer = peer_lookup(bgp, &su);
4961 if (peer) {
4962 if (peer_dynamic_neighbor(peer)) {
4963 vty_out(vty,
4964 "%% Operation not allowed on a dynamic neighbor\n");
4965 return CMD_WARNING_CONFIG_FAILED;
4966 }
4967
4968 other = peer->doppelganger;
4969
4970 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4971 bgp_zebra_terminate_radv(peer->bgp, peer);
4972
4973 peer_notify_unconfig(peer);
4974 peer_delete(peer);
4975 if (other && other->status != Deleted) {
4976 peer_notify_unconfig(other);
4977 peer_delete(other);
4978 }
4979 }
4980 }
4981
4982 return CMD_SUCCESS;
4983 }
4984
4985 DEFUN (no_neighbor_interface_config,
4986 no_neighbor_interface_config_cmd,
4987 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4988 NO_STR
4989 NEIGHBOR_STR
4990 "Interface name\n"
4991 "Configure BGP on interface\n"
4992 "Enable BGP with v6 link-local only\n"
4993 "Member of the peer-group\n"
4994 "Peer-group name\n"
4995 "Specify a BGP neighbor\n"
4996 AS_STR
4997 "Internal BGP peer\n"
4998 "External BGP peer\n")
4999 {
5000 VTY_DECLVAR_CONTEXT(bgp, bgp);
5001 int idx_word = 2;
5002 struct peer *peer;
5003
5004 /* look up for neighbor by interface name config. */
5005 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5006 if (peer) {
5007 /* Request zebra to terminate IPv6 RAs on this interface. */
5008 if (peer->ifp)
5009 bgp_zebra_terminate_radv(peer->bgp, peer);
5010 peer_notify_unconfig(peer);
5011 peer_delete(peer);
5012 } else {
5013 vty_out(vty, "%% Create the bgp interface first\n");
5014 return CMD_WARNING_CONFIG_FAILED;
5015 }
5016 return CMD_SUCCESS;
5017 }
5018
5019 DEFUN (no_neighbor_peer_group,
5020 no_neighbor_peer_group_cmd,
5021 "no neighbor WORD peer-group",
5022 NO_STR
5023 NEIGHBOR_STR
5024 "Neighbor tag\n"
5025 "Configure peer-group\n")
5026 {
5027 VTY_DECLVAR_CONTEXT(bgp, bgp);
5028 int idx_word = 2;
5029 struct peer_group *group;
5030
5031 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5032 if (group) {
5033 peer_group_notify_unconfig(group);
5034 peer_group_delete(group);
5035 } else {
5036 vty_out(vty, "%% Create the peer-group first\n");
5037 return CMD_WARNING_CONFIG_FAILED;
5038 }
5039 return CMD_SUCCESS;
5040 }
5041
5042 DEFUN (no_neighbor_interface_peer_group_remote_as,
5043 no_neighbor_interface_peer_group_remote_as_cmd,
5044 "no neighbor WORD remote-as <ASNUM|internal|external>",
5045 NO_STR
5046 NEIGHBOR_STR
5047 "Interface name or neighbor tag\n"
5048 "Specify a BGP neighbor\n"
5049 AS_STR
5050 "Internal BGP peer\n"
5051 "External BGP peer\n")
5052 {
5053 VTY_DECLVAR_CONTEXT(bgp, bgp);
5054 int idx_word = 2;
5055 struct peer_group *group;
5056 struct peer *peer;
5057
5058 /* look up for neighbor by interface name config. */
5059 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5060 if (peer) {
5061 peer_as_change(peer, 0, AS_UNSPECIFIED, NULL);
5062 return CMD_SUCCESS;
5063 }
5064
5065 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5066 if (group)
5067 peer_group_remote_as_delete(group);
5068 else {
5069 vty_out(vty, "%% Create the peer-group or interface first\n");
5070 return CMD_WARNING_CONFIG_FAILED;
5071 }
5072 return CMD_SUCCESS;
5073 }
5074
5075 DEFUN (neighbor_local_as,
5076 neighbor_local_as_cmd,
5077 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM",
5078 NEIGHBOR_STR
5079 NEIGHBOR_ADDR_STR2
5080 "Specify a local-as number\n"
5081 "AS number expressed in dotted or plain format used as local AS\n")
5082 {
5083 int idx_peer = 1;
5084 int idx_number = 3;
5085 struct peer *peer;
5086 int ret;
5087 as_t as;
5088
5089 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5090 if (!peer)
5091 return CMD_WARNING_CONFIG_FAILED;
5092
5093 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5094 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5095 argv[idx_number]->arg);
5096 return CMD_WARNING_CONFIG_FAILED;
5097 }
5098
5099 ret = peer_local_as_set(peer, as, 0, 0, argv[idx_number]->arg);
5100 return bgp_vty_return(vty, ret);
5101 }
5102
5103 DEFUN (neighbor_local_as_no_prepend,
5104 neighbor_local_as_no_prepend_cmd,
5105 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend",
5106 NEIGHBOR_STR
5107 NEIGHBOR_ADDR_STR2
5108 "Specify a local-as number\n"
5109 "AS number expressed in dotted or plain format used as local AS\n"
5110 "Do not prepend local-as to updates from ebgp peers\n")
5111 {
5112 int idx_peer = 1;
5113 int idx_number = 3;
5114 struct peer *peer;
5115 int ret;
5116 as_t as;
5117
5118 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5119 if (!peer)
5120 return CMD_WARNING_CONFIG_FAILED;
5121
5122 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5123 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5124 argv[idx_number]->arg);
5125 return CMD_WARNING_CONFIG_FAILED;
5126 }
5127
5128 ret = peer_local_as_set(peer, as, 1, 0, argv[idx_number]->arg);
5129 return bgp_vty_return(vty, ret);
5130 }
5131
5132 DEFUN (neighbor_local_as_no_prepend_replace_as,
5133 neighbor_local_as_no_prepend_replace_as_cmd,
5134 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as",
5135 NEIGHBOR_STR
5136 NEIGHBOR_ADDR_STR2
5137 "Specify a local-as number\n"
5138 "AS number expressed in dotted or plain format used as local AS\n"
5139 "Do not prepend local-as to updates from ebgp peers\n"
5140 "Do not prepend local-as to updates from ibgp peers\n")
5141 {
5142 int idx_peer = 1;
5143 int idx_number = 3;
5144 struct peer *peer;
5145 int ret;
5146 as_t as;
5147
5148 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5149 if (!peer)
5150 return CMD_WARNING_CONFIG_FAILED;
5151
5152 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5153 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5154 argv[idx_number]->arg);
5155 return CMD_WARNING_CONFIG_FAILED;
5156 }
5157
5158 ret = peer_local_as_set(peer, as, 1, 1, argv[idx_number]->arg);
5159 return bgp_vty_return(vty, ret);
5160 }
5161
5162 DEFUN (no_neighbor_local_as,
5163 no_neighbor_local_as_cmd,
5164 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as]]]",
5165 NO_STR
5166 NEIGHBOR_STR
5167 NEIGHBOR_ADDR_STR2
5168 "Specify a local-as number\n"
5169 "AS number expressed in dotted or plain format used as local AS\n"
5170 "Do not prepend local-as to updates from ebgp peers\n"
5171 "Do not prepend local-as to updates from ibgp peers\n")
5172 {
5173 int idx_peer = 2;
5174 struct peer *peer;
5175 int ret;
5176
5177 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5178 if (!peer)
5179 return CMD_WARNING_CONFIG_FAILED;
5180
5181 ret = peer_local_as_unset(peer);
5182 return bgp_vty_return(vty, ret);
5183 }
5184
5185
5186 DEFUN (neighbor_solo,
5187 neighbor_solo_cmd,
5188 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5189 NEIGHBOR_STR
5190 NEIGHBOR_ADDR_STR2
5191 "Solo peer - part of its own update group\n")
5192 {
5193 int idx_peer = 1;
5194 struct peer *peer;
5195 int ret;
5196
5197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5198 if (!peer)
5199 return CMD_WARNING_CONFIG_FAILED;
5200
5201 ret = update_group_adjust_soloness(peer, 1);
5202 return bgp_vty_return(vty, ret);
5203 }
5204
5205 DEFUN (no_neighbor_solo,
5206 no_neighbor_solo_cmd,
5207 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5208 NO_STR
5209 NEIGHBOR_STR
5210 NEIGHBOR_ADDR_STR2
5211 "Solo peer - part of its own update group\n")
5212 {
5213 int idx_peer = 2;
5214 struct peer *peer;
5215 int ret;
5216
5217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5218 if (!peer)
5219 return CMD_WARNING_CONFIG_FAILED;
5220
5221 ret = update_group_adjust_soloness(peer, 0);
5222 return bgp_vty_return(vty, ret);
5223 }
5224
5225 DEFUN (neighbor_password,
5226 neighbor_password_cmd,
5227 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Set a password\n"
5231 "The password\n")
5232 {
5233 int idx_peer = 1;
5234 int idx_line = 3;
5235 struct peer *peer;
5236 int ret;
5237
5238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5239 if (!peer)
5240 return CMD_WARNING_CONFIG_FAILED;
5241
5242 ret = peer_password_set(peer, argv[idx_line]->arg);
5243 return bgp_vty_return(vty, ret);
5244 }
5245
5246 DEFUN (no_neighbor_password,
5247 no_neighbor_password_cmd,
5248 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5249 NO_STR
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "Set a password\n"
5253 "The password\n")
5254 {
5255 int idx_peer = 2;
5256 struct peer *peer;
5257 int ret;
5258
5259 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5260 if (!peer)
5261 return CMD_WARNING_CONFIG_FAILED;
5262
5263 ret = peer_password_unset(peer);
5264 return bgp_vty_return(vty, ret);
5265 }
5266
5267 DEFUN (neighbor_activate,
5268 neighbor_activate_cmd,
5269 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Enable the Address Family for this Neighbor\n")
5273 {
5274 int idx_peer = 1;
5275 int ret;
5276 struct peer *peer;
5277
5278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5279 if (!peer)
5280 return CMD_WARNING_CONFIG_FAILED;
5281
5282 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5283 return bgp_vty_return(vty, ret);
5284 }
5285
5286 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5287 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5289 "Enable the Address Family for this Neighbor\n")
5290
5291 DEFUN (no_neighbor_activate,
5292 no_neighbor_activate_cmd,
5293 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5294 NO_STR
5295 NEIGHBOR_STR
5296 NEIGHBOR_ADDR_STR2
5297 "Enable the Address Family for this Neighbor\n")
5298 {
5299 int idx_peer = 2;
5300 int ret;
5301 struct peer *peer;
5302
5303 /* Lookup peer. */
5304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5305 if (!peer)
5306 return CMD_WARNING_CONFIG_FAILED;
5307
5308 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5309 return bgp_vty_return(vty, ret);
5310 }
5311
5312 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5313 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5314 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5315 "Enable the Address Family for this Neighbor\n")
5316
5317 DEFUN (neighbor_set_peer_group,
5318 neighbor_set_peer_group_cmd,
5319 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5320 NEIGHBOR_STR
5321 NEIGHBOR_ADDR_STR2
5322 "Member of the peer-group\n"
5323 "Peer-group name\n")
5324 {
5325 VTY_DECLVAR_CONTEXT(bgp, bgp);
5326 int idx_peer = 1;
5327 int idx_word = 3;
5328 int ret;
5329 as_t as;
5330 union sockunion su;
5331 struct peer *peer;
5332 struct peer_group *group;
5333
5334 ret = str2sockunion(argv[idx_peer]->arg, &su);
5335 if (ret < 0) {
5336 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5337 if (!peer) {
5338 vty_out(vty, "%% Malformed address or name: %s\n",
5339 argv[idx_peer]->arg);
5340 return CMD_WARNING_CONFIG_FAILED;
5341 }
5342 } else {
5343 if (peer_address_self_check(bgp, &su)) {
5344 vty_out(vty,
5345 "%% Can not configure the local system as neighbor\n");
5346 return CMD_WARNING_CONFIG_FAILED;
5347 }
5348
5349 /* Disallow for dynamic neighbor. */
5350 peer = peer_lookup(bgp, &su);
5351 if (peer && peer_dynamic_neighbor(peer)) {
5352 vty_out(vty,
5353 "%% Operation not allowed on a dynamic neighbor\n");
5354 return CMD_WARNING_CONFIG_FAILED;
5355 }
5356 }
5357
5358 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5359 if (!group) {
5360 vty_out(vty, "%% Configure the peer-group first\n");
5361 return CMD_WARNING_CONFIG_FAILED;
5362 }
5363
5364 ret = peer_group_bind(bgp, &su, peer, group, &as);
5365
5366 return bgp_vty_return(vty, ret);
5367 }
5368
5369 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5370 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5371 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5372 "Member of the peer-group\n"
5373 "Peer-group name\n")
5374
5375 DEFUN (no_neighbor_set_peer_group,
5376 no_neighbor_set_peer_group_cmd,
5377 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5378 NO_STR
5379 NEIGHBOR_STR
5380 NEIGHBOR_ADDR_STR2
5381 "Member of the peer-group\n"
5382 "Peer-group name\n")
5383 {
5384 VTY_DECLVAR_CONTEXT(bgp, bgp);
5385 int idx_peer = 2;
5386 int idx_word = 4;
5387 int ret;
5388 struct peer *peer;
5389 struct peer_group *group;
5390
5391 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5392 if (!peer)
5393 return CMD_WARNING_CONFIG_FAILED;
5394
5395 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5396 if (!group) {
5397 vty_out(vty, "%% Configure the peer-group first\n");
5398 return CMD_WARNING_CONFIG_FAILED;
5399 }
5400
5401 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5402 bgp_zebra_terminate_radv(peer->bgp, peer);
5403
5404 peer_notify_unconfig(peer);
5405 ret = peer_delete(peer);
5406
5407 return bgp_vty_return(vty, ret);
5408 }
5409
5410 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5413 "Member of the peer-group\n"
5414 "Peer-group name\n")
5415
5416 /* neighbor passive. */
5417 DEFUN (neighbor_passive,
5418 neighbor_passive_cmd,
5419 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Don't send open messages to this neighbor\n")
5423 {
5424 int idx_peer = 1;
5425 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5426 }
5427
5428 DEFUN (no_neighbor_passive,
5429 no_neighbor_passive_cmd,
5430 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5431 NO_STR
5432 NEIGHBOR_STR
5433 NEIGHBOR_ADDR_STR2
5434 "Don't send open messages to this neighbor\n")
5435 {
5436 int idx_peer = 2;
5437 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5438 }
5439
5440 /* neighbor shutdown. */
5441 DEFUN (neighbor_shutdown_msg,
5442 neighbor_shutdown_msg_cmd,
5443 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Administratively shut down this neighbor\n"
5447 "Add a shutdown message (RFC 8203)\n"
5448 "Shutdown message\n")
5449 {
5450 int idx_peer = 1;
5451
5452 if (argc >= 5) {
5453 struct peer *peer =
5454 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5455 char *message;
5456
5457 if (!peer)
5458 return CMD_WARNING_CONFIG_FAILED;
5459 message = argv_concat(argv, argc, 4);
5460 peer_tx_shutdown_message_set(peer, message);
5461 XFREE(MTYPE_TMP, message);
5462 }
5463
5464 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5465 }
5466
5467 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5468 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5469 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5470 "Administratively shut down this neighbor\n")
5471
5472 DEFUN (no_neighbor_shutdown_msg,
5473 no_neighbor_shutdown_msg_cmd,
5474 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5475 NO_STR
5476 NEIGHBOR_STR
5477 NEIGHBOR_ADDR_STR2
5478 "Administratively shut down this neighbor\n"
5479 "Remove a shutdown message (RFC 8203)\n"
5480 "Shutdown message\n")
5481 {
5482 int idx_peer = 2;
5483
5484 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5485 PEER_FLAG_SHUTDOWN);
5486 }
5487
5488 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5489 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5490 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5491 "Administratively shut down this neighbor\n")
5492
5493 DEFUN(neighbor_shutdown_rtt,
5494 neighbor_shutdown_rtt_cmd,
5495 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5496 NEIGHBOR_STR
5497 NEIGHBOR_ADDR_STR2
5498 "Administratively shut down this neighbor\n"
5499 "Shutdown if round-trip-time is higher than expected\n"
5500 "Round-trip-time in milliseconds\n"
5501 "Specify the number of keepalives before shutdown\n"
5502 "The number of keepalives with higher RTT to shutdown\n")
5503 {
5504 int idx_peer = 1;
5505 int idx_rtt = 4;
5506 int idx_count = 0;
5507 struct peer *peer;
5508
5509 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5510
5511 if (!peer)
5512 return CMD_WARNING_CONFIG_FAILED;
5513
5514 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5515
5516 if (argv_find(argv, argc, "count", &idx_count))
5517 peer->rtt_keepalive_conf =
5518 strtol(argv[idx_count + 1]->arg, NULL, 10);
5519
5520 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5521 PEER_FLAG_RTT_SHUTDOWN);
5522 }
5523
5524 DEFUN(no_neighbor_shutdown_rtt,
5525 no_neighbor_shutdown_rtt_cmd,
5526 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5527 NO_STR
5528 NEIGHBOR_STR
5529 NEIGHBOR_ADDR_STR2
5530 "Administratively shut down this neighbor\n"
5531 "Shutdown if round-trip-time is higher than expected\n"
5532 "Round-trip-time in milliseconds\n"
5533 "Specify the number of keepalives before shutdown\n"
5534 "The number of keepalives with higher RTT to shutdown\n")
5535 {
5536 int idx_peer = 2;
5537 struct peer *peer;
5538
5539 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5540
5541 if (!peer)
5542 return CMD_WARNING_CONFIG_FAILED;
5543
5544 peer->rtt_expected = 0;
5545 peer->rtt_keepalive_conf = 1;
5546
5547 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5548 PEER_FLAG_RTT_SHUTDOWN);
5549 }
5550
5551 /* neighbor capability dynamic. */
5552 DEFUN (neighbor_capability_dynamic,
5553 neighbor_capability_dynamic_cmd,
5554 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Advertise capability to the peer\n"
5558 "Advertise dynamic capability to this neighbor\n")
5559 {
5560 int idx_peer = 1;
5561 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5562 PEER_FLAG_DYNAMIC_CAPABILITY);
5563 }
5564
5565 DEFUN (no_neighbor_capability_dynamic,
5566 no_neighbor_capability_dynamic_cmd,
5567 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5568 NO_STR
5569 NEIGHBOR_STR
5570 NEIGHBOR_ADDR_STR2
5571 "Advertise capability to the peer\n"
5572 "Advertise dynamic capability to this neighbor\n")
5573 {
5574 int idx_peer = 2;
5575 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5576 PEER_FLAG_DYNAMIC_CAPABILITY);
5577 }
5578
5579 /* neighbor dont-capability-negotiate */
5580 DEFUN (neighbor_dont_capability_negotiate,
5581 neighbor_dont_capability_negotiate_cmd,
5582 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5583 NEIGHBOR_STR
5584 NEIGHBOR_ADDR_STR2
5585 "Do not perform capability negotiation\n")
5586 {
5587 int idx_peer = 1;
5588 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5589 PEER_FLAG_DONT_CAPABILITY);
5590 }
5591
5592 DEFUN (no_neighbor_dont_capability_negotiate,
5593 no_neighbor_dont_capability_negotiate_cmd,
5594 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5595 NO_STR
5596 NEIGHBOR_STR
5597 NEIGHBOR_ADDR_STR2
5598 "Do not perform capability negotiation\n")
5599 {
5600 int idx_peer = 2;
5601 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5602 PEER_FLAG_DONT_CAPABILITY);
5603 }
5604
5605 /* neighbor capability extended next hop encoding */
5606 DEFUN (neighbor_capability_enhe,
5607 neighbor_capability_enhe_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5609 NEIGHBOR_STR
5610 NEIGHBOR_ADDR_STR2
5611 "Advertise capability to the peer\n"
5612 "Advertise extended next-hop capability to the peer\n")
5613 {
5614 int idx_peer = 1;
5615 struct peer *peer;
5616
5617 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5618 if (peer && peer->conf_if)
5619 return CMD_SUCCESS;
5620
5621 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5622 PEER_FLAG_CAPABILITY_ENHE);
5623 }
5624
5625 DEFUN (no_neighbor_capability_enhe,
5626 no_neighbor_capability_enhe_cmd,
5627 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5628 NO_STR
5629 NEIGHBOR_STR
5630 NEIGHBOR_ADDR_STR2
5631 "Advertise capability to the peer\n"
5632 "Advertise extended next-hop capability to the peer\n")
5633 {
5634 int idx_peer = 2;
5635 struct peer *peer;
5636
5637 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5638 if (peer && peer->conf_if) {
5639 vty_out(vty,
5640 "Peer %s cannot have capability extended-nexthop turned off\n",
5641 argv[idx_peer]->arg);
5642 return CMD_WARNING_CONFIG_FAILED;
5643 }
5644
5645 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5646 PEER_FLAG_CAPABILITY_ENHE);
5647 }
5648
5649 /* neighbor capability software-version */
5650 DEFPY(neighbor_capability_software_version,
5651 neighbor_capability_software_version_cmd,
5652 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor capability software-version",
5653 NO_STR
5654 NEIGHBOR_STR
5655 NEIGHBOR_ADDR_STR2
5656 "Advertise capability to the peer\n"
5657 "Advertise Software Version capability to the peer\n")
5658 {
5659 struct peer *peer;
5660
5661 peer = peer_and_group_lookup_vty(vty, neighbor);
5662 if (peer && peer->conf_if)
5663 return CMD_SUCCESS;
5664
5665 if (no)
5666 return peer_flag_unset_vty(vty, neighbor,
5667 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5668 else
5669 return peer_flag_set_vty(vty, neighbor,
5670 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5671 }
5672
5673 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5674 afi_t afi, safi_t safi, uint64_t flag,
5675 int set)
5676 {
5677 int ret;
5678 struct peer *peer;
5679
5680 peer = peer_and_group_lookup_vty(vty, peer_str);
5681 if (!peer)
5682 return CMD_WARNING_CONFIG_FAILED;
5683
5684 if (set)
5685 ret = peer_af_flag_set(peer, afi, safi, flag);
5686 else
5687 ret = peer_af_flag_unset(peer, afi, safi, flag);
5688
5689 return bgp_vty_return(vty, ret);
5690 }
5691
5692 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5693 afi_t afi, safi_t safi, uint64_t flag)
5694 {
5695 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5696 }
5697
5698 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5699 afi_t afi, safi_t safi, uint64_t flag)
5700 {
5701 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5702 }
5703
5704 /* neighbor capability orf prefix-list. */
5705 DEFUN (neighbor_capability_orf_prefix,
5706 neighbor_capability_orf_prefix_cmd,
5707 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5708 NEIGHBOR_STR
5709 NEIGHBOR_ADDR_STR2
5710 "Advertise capability to the peer\n"
5711 "Advertise ORF capability to the peer\n"
5712 "Advertise prefixlist ORF capability to this neighbor\n"
5713 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5714 "Capability to RECEIVE the ORF from this neighbor\n"
5715 "Capability to SEND the ORF to this neighbor\n")
5716 {
5717 int idx_send_recv = 5;
5718 char *peer_str = argv[1]->arg;
5719 struct peer *peer;
5720 afi_t afi = bgp_node_afi(vty);
5721 safi_t safi = bgp_node_safi(vty);
5722
5723 peer = peer_and_group_lookup_vty(vty, peer_str);
5724 if (!peer)
5725 return CMD_WARNING_CONFIG_FAILED;
5726
5727 if (strmatch(argv[idx_send_recv]->text, "send"))
5728 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5729 PEER_FLAG_ORF_PREFIX_SM);
5730
5731 if (strmatch(argv[idx_send_recv]->text, "receive"))
5732 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5733 PEER_FLAG_ORF_PREFIX_RM);
5734
5735 if (strmatch(argv[idx_send_recv]->text, "both"))
5736 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5737 PEER_FLAG_ORF_PREFIX_SM)
5738 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5739 PEER_FLAG_ORF_PREFIX_RM);
5740
5741 return CMD_WARNING_CONFIG_FAILED;
5742 }
5743
5744 ALIAS_HIDDEN(
5745 neighbor_capability_orf_prefix,
5746 neighbor_capability_orf_prefix_hidden_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5748 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5749 "Advertise capability to the peer\n"
5750 "Advertise ORF capability to the peer\n"
5751 "Advertise prefixlist ORF capability to this neighbor\n"
5752 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5753 "Capability to RECEIVE the ORF from this neighbor\n"
5754 "Capability to SEND the ORF to this neighbor\n")
5755
5756 DEFUN (no_neighbor_capability_orf_prefix,
5757 no_neighbor_capability_orf_prefix_cmd,
5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5759 NO_STR
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Advertise capability to the peer\n"
5763 "Advertise ORF capability to the peer\n"
5764 "Advertise prefixlist ORF capability to this neighbor\n"
5765 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5766 "Capability to RECEIVE the ORF from this neighbor\n"
5767 "Capability to SEND the ORF to this neighbor\n")
5768 {
5769 int idx_send_recv = 6;
5770 char *peer_str = argv[2]->arg;
5771 struct peer *peer;
5772 afi_t afi = bgp_node_afi(vty);
5773 safi_t safi = bgp_node_safi(vty);
5774
5775 peer = peer_and_group_lookup_vty(vty, peer_str);
5776 if (!peer)
5777 return CMD_WARNING_CONFIG_FAILED;
5778
5779 if (strmatch(argv[idx_send_recv]->text, "send"))
5780 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5781 PEER_FLAG_ORF_PREFIX_SM);
5782
5783 if (strmatch(argv[idx_send_recv]->text, "receive"))
5784 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5785 PEER_FLAG_ORF_PREFIX_RM);
5786
5787 if (strmatch(argv[idx_send_recv]->text, "both"))
5788 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5789 PEER_FLAG_ORF_PREFIX_SM)
5790 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5791 PEER_FLAG_ORF_PREFIX_RM);
5792
5793 return CMD_WARNING_CONFIG_FAILED;
5794 }
5795
5796 ALIAS_HIDDEN(
5797 no_neighbor_capability_orf_prefix,
5798 no_neighbor_capability_orf_prefix_hidden_cmd,
5799 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5801 "Advertise capability to the peer\n"
5802 "Advertise ORF capability to the peer\n"
5803 "Advertise prefixlist ORF capability to this neighbor\n"
5804 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5805 "Capability to RECEIVE the ORF from this neighbor\n"
5806 "Capability to SEND the ORF to this neighbor\n")
5807
5808 /* neighbor next-hop-self. */
5809 DEFUN (neighbor_nexthop_self,
5810 neighbor_nexthop_self_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Disable the next hop calculation for this neighbor\n")
5815 {
5816 int idx_peer = 1;
5817 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5818 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5819 }
5820
5821 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5822 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5823 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 "Disable the next hop calculation for this neighbor\n")
5825
5826 /* neighbor next-hop-self. */
5827 DEFUN (neighbor_nexthop_self_force,
5828 neighbor_nexthop_self_force_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Disable the next hop calculation for this neighbor\n"
5833 "Set the next hop to self for reflected routes\n")
5834 {
5835 int idx_peer = 1;
5836 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5837 bgp_node_safi(vty),
5838 PEER_FLAG_FORCE_NEXTHOP_SELF);
5839 }
5840
5841 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5842 neighbor_nexthop_self_force_hidden_cmd,
5843 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5844 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5845 "Disable the next hop calculation for this neighbor\n"
5846 "Set the next hop to self for reflected routes\n")
5847
5848 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5849 neighbor_nexthop_self_all_hidden_cmd,
5850 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5851 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5852 "Disable the next hop calculation for this neighbor\n"
5853 "Set the next hop to self for reflected routes\n")
5854
5855 DEFUN (no_neighbor_nexthop_self,
5856 no_neighbor_nexthop_self_cmd,
5857 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5858 NO_STR
5859 NEIGHBOR_STR
5860 NEIGHBOR_ADDR_STR2
5861 "Disable the next hop calculation for this neighbor\n")
5862 {
5863 int idx_peer = 2;
5864 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5865 bgp_node_afi(vty), bgp_node_safi(vty),
5866 PEER_FLAG_NEXTHOP_SELF);
5867 }
5868
5869 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5870 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5871 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5872 "Disable the next hop calculation for this neighbor\n")
5873
5874 DEFUN (no_neighbor_nexthop_self_force,
5875 no_neighbor_nexthop_self_force_cmd,
5876 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5877 NO_STR
5878 NEIGHBOR_STR
5879 NEIGHBOR_ADDR_STR2
5880 "Disable the next hop calculation for this neighbor\n"
5881 "Set the next hop to self for reflected routes\n")
5882 {
5883 int idx_peer = 2;
5884 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5885 bgp_node_afi(vty), bgp_node_safi(vty),
5886 PEER_FLAG_FORCE_NEXTHOP_SELF);
5887 }
5888
5889 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5890 no_neighbor_nexthop_self_force_hidden_cmd,
5891 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5892 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5893 "Disable the next hop calculation for this neighbor\n"
5894 "Set the next hop to self for reflected routes\n")
5895
5896 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5897 no_neighbor_nexthop_self_all_hidden_cmd,
5898 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5899 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5900 "Disable the next hop calculation for this neighbor\n"
5901 "Set the next hop to self for reflected routes\n")
5902
5903 /* neighbor as-override */
5904 DEFUN (neighbor_as_override,
5905 neighbor_as_override_cmd,
5906 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Override ASNs in outbound updates if aspath equals remote-as\n")
5910 {
5911 int idx_peer = 1;
5912 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5913 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5914 }
5915
5916 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5918 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5919 "Override ASNs in outbound updates if aspath equals remote-as\n")
5920
5921 DEFUN (no_neighbor_as_override,
5922 no_neighbor_as_override_cmd,
5923 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5924 NO_STR
5925 NEIGHBOR_STR
5926 NEIGHBOR_ADDR_STR2
5927 "Override ASNs in outbound updates if aspath equals remote-as\n")
5928 {
5929 int idx_peer = 2;
5930 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5931 bgp_node_afi(vty), bgp_node_safi(vty),
5932 PEER_FLAG_AS_OVERRIDE);
5933 }
5934
5935 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5936 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5938 "Override ASNs in outbound updates if aspath equals remote-as\n")
5939
5940 /* neighbor remove-private-AS. */
5941 DEFUN (neighbor_remove_private_as,
5942 neighbor_remove_private_as_cmd,
5943 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5944 NEIGHBOR_STR
5945 NEIGHBOR_ADDR_STR2
5946 "Remove private ASNs in outbound updates\n")
5947 {
5948 int idx_peer = 1;
5949 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5950 bgp_node_safi(vty),
5951 PEER_FLAG_REMOVE_PRIVATE_AS);
5952 }
5953
5954 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5955 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n")
5958
5959 DEFUN (neighbor_remove_private_as_all,
5960 neighbor_remove_private_as_all_cmd,
5961 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5962 NEIGHBOR_STR
5963 NEIGHBOR_ADDR_STR2
5964 "Remove private ASNs in outbound updates\n"
5965 "Apply to all AS numbers\n")
5966 {
5967 int idx_peer = 1;
5968 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5969 bgp_node_safi(vty),
5970 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5971 }
5972
5973 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5974 neighbor_remove_private_as_all_hidden_cmd,
5975 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5976 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5977 "Remove private ASNs in outbound updates\n"
5978 "Apply to all AS numbers\n")
5979
5980 DEFUN (neighbor_remove_private_as_replace_as,
5981 neighbor_remove_private_as_replace_as_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
5985 "Remove private ASNs in outbound updates\n"
5986 "Replace private ASNs with our ASN in outbound updates\n")
5987 {
5988 int idx_peer = 1;
5989 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5990 bgp_node_safi(vty),
5991 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5992 }
5993
5994 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5995 neighbor_remove_private_as_replace_as_hidden_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5998 "Remove private ASNs in outbound updates\n"
5999 "Replace private ASNs with our ASN in outbound updates\n")
6000
6001 DEFUN (neighbor_remove_private_as_all_replace_as,
6002 neighbor_remove_private_as_all_replace_as_cmd,
6003 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6004 NEIGHBOR_STR
6005 NEIGHBOR_ADDR_STR2
6006 "Remove private ASNs in outbound updates\n"
6007 "Apply to all AS numbers\n"
6008 "Replace private ASNs with our ASN in outbound updates\n")
6009 {
6010 int idx_peer = 1;
6011 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6012 bgp_node_safi(vty),
6013 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
6014 }
6015
6016 ALIAS_HIDDEN(
6017 neighbor_remove_private_as_all_replace_as,
6018 neighbor_remove_private_as_all_replace_as_hidden_cmd,
6019 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6020 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6021 "Remove private ASNs in outbound updates\n"
6022 "Apply to all AS numbers\n"
6023 "Replace private ASNs with our ASN in outbound updates\n")
6024
6025 DEFUN (no_neighbor_remove_private_as,
6026 no_neighbor_remove_private_as_cmd,
6027 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6028 NO_STR
6029 NEIGHBOR_STR
6030 NEIGHBOR_ADDR_STR2
6031 "Remove private ASNs in outbound updates\n")
6032 {
6033 int idx_peer = 2;
6034 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6035 bgp_node_afi(vty), bgp_node_safi(vty),
6036 PEER_FLAG_REMOVE_PRIVATE_AS);
6037 }
6038
6039 ALIAS_HIDDEN(no_neighbor_remove_private_as,
6040 no_neighbor_remove_private_as_hidden_cmd,
6041 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6042 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6043 "Remove private ASNs in outbound updates\n")
6044
6045 DEFUN (no_neighbor_remove_private_as_all,
6046 no_neighbor_remove_private_as_all_cmd,
6047 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6048 NO_STR
6049 NEIGHBOR_STR
6050 NEIGHBOR_ADDR_STR2
6051 "Remove private ASNs in outbound updates\n"
6052 "Apply to all AS numbers\n")
6053 {
6054 int idx_peer = 2;
6055 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6056 bgp_node_afi(vty), bgp_node_safi(vty),
6057 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
6058 }
6059
6060 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6061 no_neighbor_remove_private_as_all_hidden_cmd,
6062 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6063 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6064 "Remove private ASNs in outbound updates\n"
6065 "Apply to all AS numbers\n")
6066
6067 DEFUN (no_neighbor_remove_private_as_replace_as,
6068 no_neighbor_remove_private_as_replace_as_cmd,
6069 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6070 NO_STR
6071 NEIGHBOR_STR
6072 NEIGHBOR_ADDR_STR2
6073 "Remove private ASNs in outbound updates\n"
6074 "Replace private ASNs with our ASN in outbound updates\n")
6075 {
6076 int idx_peer = 2;
6077 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6078 bgp_node_afi(vty), bgp_node_safi(vty),
6079 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
6080 }
6081
6082 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6083 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6084 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6085 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6086 "Remove private ASNs in outbound updates\n"
6087 "Replace private ASNs with our ASN in outbound updates\n")
6088
6089 DEFUN (no_neighbor_remove_private_as_all_replace_as,
6090 no_neighbor_remove_private_as_all_replace_as_cmd,
6091 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6092 NO_STR
6093 NEIGHBOR_STR
6094 NEIGHBOR_ADDR_STR2
6095 "Remove private ASNs in outbound updates\n"
6096 "Apply to all AS numbers\n"
6097 "Replace private ASNs with our ASN in outbound updates\n")
6098 {
6099 int idx_peer = 2;
6100 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6101 bgp_node_afi(vty), bgp_node_safi(vty),
6102 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
6103 }
6104
6105 ALIAS_HIDDEN(
6106 no_neighbor_remove_private_as_all_replace_as,
6107 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6110 "Remove private ASNs in outbound updates\n"
6111 "Apply to all AS numbers\n"
6112 "Replace private ASNs with our ASN in outbound updates\n")
6113
6114
6115 /* neighbor send-community. */
6116 DEFUN (neighbor_send_community,
6117 neighbor_send_community_cmd,
6118 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6119 NEIGHBOR_STR
6120 NEIGHBOR_ADDR_STR2
6121 "Send Community attribute to this neighbor\n")
6122 {
6123 int idx_peer = 1;
6124
6125 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6126 bgp_node_safi(vty),
6127 PEER_FLAG_SEND_COMMUNITY);
6128 }
6129
6130 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6131 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6132 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Send Community attribute to this neighbor\n")
6134
6135 DEFUN (no_neighbor_send_community,
6136 no_neighbor_send_community_cmd,
6137 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6138 NO_STR
6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
6141 "Send Community attribute to this neighbor\n")
6142 {
6143 int idx_peer = 2;
6144
6145 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6146 bgp_node_afi(vty), bgp_node_safi(vty),
6147 PEER_FLAG_SEND_COMMUNITY);
6148 }
6149
6150 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6151 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6152 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6153 "Send Community attribute to this neighbor\n")
6154
6155 /* neighbor send-community extended. */
6156 DEFUN (neighbor_send_community_type,
6157 neighbor_send_community_type_cmd,
6158 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6159 NEIGHBOR_STR
6160 NEIGHBOR_ADDR_STR2
6161 "Send Community attribute to this neighbor\n"
6162 "Send Standard and Extended Community attributes\n"
6163 "Send Standard, Large and Extended Community attributes\n"
6164 "Send Extended Community attributes\n"
6165 "Send Standard Community attributes\n"
6166 "Send Large Community attributes\n")
6167 {
6168 const char *type = argv[argc - 1]->text;
6169 char *peer_str = argv[1]->arg;
6170 struct peer *peer;
6171 afi_t afi = bgp_node_afi(vty);
6172 safi_t safi = bgp_node_safi(vty);
6173
6174 peer = peer_and_group_lookup_vty(vty, peer_str);
6175 if (!peer)
6176 return CMD_WARNING_CONFIG_FAILED;
6177
6178 if (strmatch(type, "standard"))
6179 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6180 PEER_FLAG_SEND_COMMUNITY);
6181
6182 if (strmatch(type, "extended"))
6183 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6184 PEER_FLAG_SEND_EXT_COMMUNITY);
6185
6186 if (strmatch(type, "large"))
6187 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6188 PEER_FLAG_SEND_LARGE_COMMUNITY);
6189
6190 if (strmatch(type, "both")) {
6191 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6192 PEER_FLAG_SEND_COMMUNITY)
6193 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6194 PEER_FLAG_SEND_EXT_COMMUNITY);
6195 }
6196 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6197 PEER_FLAG_SEND_COMMUNITY)
6198 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6199 PEER_FLAG_SEND_EXT_COMMUNITY)
6200 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6201 PEER_FLAG_SEND_LARGE_COMMUNITY);
6202 }
6203
6204 ALIAS_HIDDEN(
6205 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6206 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6207 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6208 "Send Community attribute to this neighbor\n"
6209 "Send Standard and Extended Community attributes\n"
6210 "Send Standard, Large and Extended Community attributes\n"
6211 "Send Extended Community attributes\n"
6212 "Send Standard Community attributes\n"
6213 "Send Large Community attributes\n")
6214
6215 DEFUN (no_neighbor_send_community_type,
6216 no_neighbor_send_community_type_cmd,
6217 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6218 NO_STR
6219 NEIGHBOR_STR
6220 NEIGHBOR_ADDR_STR2
6221 "Send Community attribute to this neighbor\n"
6222 "Send Standard and Extended Community attributes\n"
6223 "Send Standard, Large and Extended Community attributes\n"
6224 "Send Extended Community attributes\n"
6225 "Send Standard Community attributes\n"
6226 "Send Large Community attributes\n")
6227 {
6228 const char *type = argv[argc - 1]->text;
6229 char *peer_str = argv[2]->arg;
6230 struct peer *peer;
6231 afi_t afi = bgp_node_afi(vty);
6232 safi_t safi = bgp_node_safi(vty);
6233
6234 peer = peer_and_group_lookup_vty(vty, peer_str);
6235 if (!peer)
6236 return CMD_WARNING_CONFIG_FAILED;
6237
6238 if (strmatch(type, "standard"))
6239 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6240 PEER_FLAG_SEND_COMMUNITY);
6241
6242 if (strmatch(type, "extended"))
6243 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6244 PEER_FLAG_SEND_EXT_COMMUNITY);
6245
6246 if (strmatch(type, "large"))
6247 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6248 PEER_FLAG_SEND_LARGE_COMMUNITY);
6249
6250 if (strmatch(type, "both")) {
6251
6252 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6253 PEER_FLAG_SEND_COMMUNITY)
6254 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6255 PEER_FLAG_SEND_EXT_COMMUNITY);
6256 }
6257
6258 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6259 PEER_FLAG_SEND_COMMUNITY)
6260 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6261 PEER_FLAG_SEND_EXT_COMMUNITY)
6262 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6263 PEER_FLAG_SEND_LARGE_COMMUNITY);
6264 }
6265
6266 ALIAS_HIDDEN(
6267 no_neighbor_send_community_type,
6268 no_neighbor_send_community_type_hidden_cmd,
6269 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6270 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6271 "Send Community attribute to this neighbor\n"
6272 "Send Standard and Extended Community attributes\n"
6273 "Send Standard, Large and Extended Community attributes\n"
6274 "Send Extended Community attributes\n"
6275 "Send Standard Community attributes\n"
6276 "Send Large Community attributes\n")
6277
6278 /* neighbor soft-reconfig. */
6279 DEFUN (neighbor_soft_reconfiguration,
6280 neighbor_soft_reconfiguration_cmd,
6281 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6282 NEIGHBOR_STR
6283 NEIGHBOR_ADDR_STR2
6284 "Per neighbor soft reconfiguration\n"
6285 "Allow inbound soft reconfiguration for this neighbor\n")
6286 {
6287 int idx_peer = 1;
6288 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6289 bgp_node_safi(vty),
6290 PEER_FLAG_SOFT_RECONFIG);
6291 }
6292
6293 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6294 neighbor_soft_reconfiguration_hidden_cmd,
6295 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6296 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6297 "Per neighbor soft reconfiguration\n"
6298 "Allow inbound soft reconfiguration for this neighbor\n")
6299
6300 DEFUN (no_neighbor_soft_reconfiguration,
6301 no_neighbor_soft_reconfiguration_cmd,
6302 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6303 NO_STR
6304 NEIGHBOR_STR
6305 NEIGHBOR_ADDR_STR2
6306 "Per neighbor soft reconfiguration\n"
6307 "Allow inbound soft reconfiguration for this neighbor\n")
6308 {
6309 int idx_peer = 2;
6310 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6311 bgp_node_afi(vty), bgp_node_safi(vty),
6312 PEER_FLAG_SOFT_RECONFIG);
6313 }
6314
6315 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6316 no_neighbor_soft_reconfiguration_hidden_cmd,
6317 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6318 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6319 "Per neighbor soft reconfiguration\n"
6320 "Allow inbound soft reconfiguration for this neighbor\n")
6321
6322 DEFUN (neighbor_route_reflector_client,
6323 neighbor_route_reflector_client_cmd,
6324 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6325 NEIGHBOR_STR
6326 NEIGHBOR_ADDR_STR2
6327 "Configure a neighbor as Route Reflector client\n")
6328 {
6329 int idx_peer = 1;
6330 struct peer *peer;
6331
6332
6333 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6334 if (!peer)
6335 return CMD_WARNING_CONFIG_FAILED;
6336
6337 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6338 bgp_node_safi(vty),
6339 PEER_FLAG_REFLECTOR_CLIENT);
6340 }
6341
6342 ALIAS_HIDDEN(neighbor_route_reflector_client,
6343 neighbor_route_reflector_client_hidden_cmd,
6344 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6345 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6346 "Configure a neighbor as Route Reflector client\n")
6347
6348 DEFUN (no_neighbor_route_reflector_client,
6349 no_neighbor_route_reflector_client_cmd,
6350 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6351 NO_STR
6352 NEIGHBOR_STR
6353 NEIGHBOR_ADDR_STR2
6354 "Configure a neighbor as Route Reflector client\n")
6355 {
6356 int idx_peer = 2;
6357 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6358 bgp_node_afi(vty), bgp_node_safi(vty),
6359 PEER_FLAG_REFLECTOR_CLIENT);
6360 }
6361
6362 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6363 no_neighbor_route_reflector_client_hidden_cmd,
6364 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6366 "Configure a neighbor as Route Reflector client\n")
6367
6368 /* neighbor route-server-client. */
6369 DEFUN (neighbor_route_server_client,
6370 neighbor_route_server_client_cmd,
6371 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6372 NEIGHBOR_STR
6373 NEIGHBOR_ADDR_STR2
6374 "Configure a neighbor as Route Server client\n")
6375 {
6376 int idx_peer = 1;
6377 struct peer *peer;
6378
6379 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6380 if (!peer)
6381 return CMD_WARNING_CONFIG_FAILED;
6382 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6383 bgp_node_safi(vty),
6384 PEER_FLAG_RSERVER_CLIENT);
6385 }
6386
6387 ALIAS_HIDDEN(neighbor_route_server_client,
6388 neighbor_route_server_client_hidden_cmd,
6389 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6390 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6391 "Configure a neighbor as Route Server client\n")
6392
6393 DEFUN (no_neighbor_route_server_client,
6394 no_neighbor_route_server_client_cmd,
6395 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6396 NO_STR
6397 NEIGHBOR_STR
6398 NEIGHBOR_ADDR_STR2
6399 "Configure a neighbor as Route Server client\n")
6400 {
6401 int idx_peer = 2;
6402 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6403 bgp_node_afi(vty), bgp_node_safi(vty),
6404 PEER_FLAG_RSERVER_CLIENT);
6405 }
6406
6407 ALIAS_HIDDEN(no_neighbor_route_server_client,
6408 no_neighbor_route_server_client_hidden_cmd,
6409 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6410 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6411 "Configure a neighbor as Route Server client\n")
6412
6413 DEFUN (neighbor_nexthop_local_unchanged,
6414 neighbor_nexthop_local_unchanged_cmd,
6415 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6416 NEIGHBOR_STR
6417 NEIGHBOR_ADDR_STR2
6418 "Configure treatment of outgoing link-local nexthop attribute\n"
6419 "Leave link-local nexthop unchanged for this peer\n")
6420 {
6421 int idx_peer = 1;
6422 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6423 bgp_node_safi(vty),
6424 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6425 }
6426
6427 DEFUN (no_neighbor_nexthop_local_unchanged,
6428 no_neighbor_nexthop_local_unchanged_cmd,
6429 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6430 NO_STR
6431 NEIGHBOR_STR
6432 NEIGHBOR_ADDR_STR2
6433 "Configure treatment of outgoing link-local-nexthop attribute\n"
6434 "Leave link-local nexthop unchanged for this peer\n")
6435 {
6436 int idx_peer = 2;
6437 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6438 bgp_node_afi(vty), bgp_node_safi(vty),
6439 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6440 }
6441
6442 DEFUN (neighbor_attr_unchanged,
6443 neighbor_attr_unchanged_cmd,
6444 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6445 NEIGHBOR_STR
6446 NEIGHBOR_ADDR_STR2
6447 "BGP attribute is propagated unchanged to this neighbor\n"
6448 "As-path attribute\n"
6449 "Nexthop attribute\n"
6450 "Med attribute\n")
6451 {
6452 int idx = 0;
6453 char *peer_str = argv[1]->arg;
6454 struct peer *peer;
6455 bool aspath = false;
6456 bool nexthop = false;
6457 bool med = false;
6458 afi_t afi = bgp_node_afi(vty);
6459 safi_t safi = bgp_node_safi(vty);
6460 int ret = 0;
6461
6462 peer = peer_and_group_lookup_vty(vty, peer_str);
6463 if (!peer)
6464 return CMD_WARNING_CONFIG_FAILED;
6465
6466 if (argv_find(argv, argc, "as-path", &idx))
6467 aspath = true;
6468
6469 idx = 0;
6470 if (argv_find(argv, argc, "next-hop", &idx))
6471 nexthop = true;
6472
6473 idx = 0;
6474 if (argv_find(argv, argc, "med", &idx))
6475 med = true;
6476
6477 /* no flags means all of them! */
6478 if (!aspath && !nexthop && !med) {
6479 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6480 PEER_FLAG_AS_PATH_UNCHANGED);
6481 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6482 PEER_FLAG_NEXTHOP_UNCHANGED);
6483 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6484 PEER_FLAG_MED_UNCHANGED);
6485 } else {
6486 if (!aspath) {
6487 if (peer_af_flag_check(peer, afi, safi,
6488 PEER_FLAG_AS_PATH_UNCHANGED)) {
6489 ret |= peer_af_flag_unset_vty(
6490 vty, peer_str, afi, safi,
6491 PEER_FLAG_AS_PATH_UNCHANGED);
6492 }
6493 } else
6494 ret |= peer_af_flag_set_vty(
6495 vty, peer_str, afi, safi,
6496 PEER_FLAG_AS_PATH_UNCHANGED);
6497
6498 if (!nexthop) {
6499 if (peer_af_flag_check(peer, afi, safi,
6500 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6501 ret |= peer_af_flag_unset_vty(
6502 vty, peer_str, afi, safi,
6503 PEER_FLAG_NEXTHOP_UNCHANGED);
6504 }
6505 } else
6506 ret |= peer_af_flag_set_vty(
6507 vty, peer_str, afi, safi,
6508 PEER_FLAG_NEXTHOP_UNCHANGED);
6509
6510 if (!med) {
6511 if (peer_af_flag_check(peer, afi, safi,
6512 PEER_FLAG_MED_UNCHANGED)) {
6513 ret |= peer_af_flag_unset_vty(
6514 vty, peer_str, afi, safi,
6515 PEER_FLAG_MED_UNCHANGED);
6516 }
6517 } else
6518 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6519 PEER_FLAG_MED_UNCHANGED);
6520 }
6521
6522 return ret;
6523 }
6524
6525 ALIAS_HIDDEN(
6526 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6527 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6528 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6529 "BGP attribute is propagated unchanged to this neighbor\n"
6530 "As-path attribute\n"
6531 "Nexthop attribute\n"
6532 "Med attribute\n")
6533
6534 DEFUN (no_neighbor_attr_unchanged,
6535 no_neighbor_attr_unchanged_cmd,
6536 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6537 NO_STR
6538 NEIGHBOR_STR
6539 NEIGHBOR_ADDR_STR2
6540 "BGP attribute is propagated unchanged to this neighbor\n"
6541 "As-path attribute\n"
6542 "Nexthop attribute\n"
6543 "Med attribute\n")
6544 {
6545 int idx = 0;
6546 char *peer_str = argv[2]->arg;
6547 struct peer *peer;
6548 bool aspath = false;
6549 bool nexthop = false;
6550 bool med = false;
6551 afi_t afi = bgp_node_afi(vty);
6552 safi_t safi = bgp_node_safi(vty);
6553 int ret = 0;
6554
6555 peer = peer_and_group_lookup_vty(vty, peer_str);
6556 if (!peer)
6557 return CMD_WARNING_CONFIG_FAILED;
6558
6559 if (argv_find(argv, argc, "as-path", &idx))
6560 aspath = true;
6561
6562 idx = 0;
6563 if (argv_find(argv, argc, "next-hop", &idx))
6564 nexthop = true;
6565
6566 idx = 0;
6567 if (argv_find(argv, argc, "med", &idx))
6568 med = true;
6569
6570 if (!aspath && !nexthop && !med) // no flags means all of them!
6571 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6572 PEER_FLAG_AS_PATH_UNCHANGED)
6573 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6574 PEER_FLAG_NEXTHOP_UNCHANGED)
6575 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6576 PEER_FLAG_MED_UNCHANGED);
6577
6578 if (aspath)
6579 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6580 PEER_FLAG_AS_PATH_UNCHANGED);
6581
6582 if (nexthop)
6583 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6584 PEER_FLAG_NEXTHOP_UNCHANGED);
6585
6586 if (med)
6587 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6588 PEER_FLAG_MED_UNCHANGED);
6589
6590 return ret;
6591 }
6592
6593 ALIAS_HIDDEN(
6594 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6595 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6596 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6597 "BGP attribute is propagated unchanged to this neighbor\n"
6598 "As-path attribute\n"
6599 "Nexthop attribute\n"
6600 "Med attribute\n")
6601
6602 /* EBGP multihop configuration. */
6603 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6604 const char *ttl_str)
6605 {
6606 struct peer *peer;
6607 unsigned int ttl;
6608
6609 peer = peer_and_group_lookup_vty(vty, ip_str);
6610 if (!peer)
6611 return CMD_WARNING_CONFIG_FAILED;
6612
6613 if (peer->conf_if)
6614 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6615
6616 if (!ttl_str)
6617 ttl = MAXTTL;
6618 else
6619 ttl = strtoul(ttl_str, NULL, 10);
6620
6621 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6622 }
6623
6624 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6625 {
6626 struct peer *peer;
6627
6628 peer = peer_and_group_lookup_vty(vty, ip_str);
6629 if (!peer)
6630 return CMD_WARNING_CONFIG_FAILED;
6631
6632 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6633 }
6634
6635 /* neighbor ebgp-multihop. */
6636 DEFUN (neighbor_ebgp_multihop,
6637 neighbor_ebgp_multihop_cmd,
6638 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6639 NEIGHBOR_STR
6640 NEIGHBOR_ADDR_STR2
6641 "Allow EBGP neighbors not on directly connected networks\n")
6642 {
6643 int idx_peer = 1;
6644 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6645 }
6646
6647 DEFUN (neighbor_ebgp_multihop_ttl,
6648 neighbor_ebgp_multihop_ttl_cmd,
6649 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6650 NEIGHBOR_STR
6651 NEIGHBOR_ADDR_STR2
6652 "Allow EBGP neighbors not on directly connected networks\n"
6653 "maximum hop count\n")
6654 {
6655 int idx_peer = 1;
6656 int idx_number = 3;
6657 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6658 argv[idx_number]->arg);
6659 }
6660
6661 DEFUN (no_neighbor_ebgp_multihop,
6662 no_neighbor_ebgp_multihop_cmd,
6663 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6664 NO_STR
6665 NEIGHBOR_STR
6666 NEIGHBOR_ADDR_STR2
6667 "Allow EBGP neighbors not on directly connected networks\n"
6668 "maximum hop count\n")
6669 {
6670 int idx_peer = 2;
6671 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6672 }
6673
6674 DEFPY (neighbor_aigp,
6675 neighbor_aigp_cmd,
6676 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6677 NO_STR
6678 NEIGHBOR_STR
6679 NEIGHBOR_ADDR_STR2
6680 "Enable send and receive of the AIGP attribute per neighbor\n")
6681 {
6682 struct peer *peer;
6683
6684 peer = peer_and_group_lookup_vty(vty, neighbor);
6685 if (!peer)
6686 return CMD_WARNING_CONFIG_FAILED;
6687
6688 if (no)
6689 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6690 else
6691 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6692 }
6693
6694 static uint8_t get_role_by_name(const char *role_str)
6695 {
6696 if (strncmp(role_str, "peer", 2) == 0)
6697 return ROLE_PEER;
6698 if (strncmp(role_str, "provider", 2) == 0)
6699 return ROLE_PROVIDER;
6700 if (strncmp(role_str, "customer", 2) == 0)
6701 return ROLE_CUSTOMER;
6702 if (strncmp(role_str, "rs-server", 4) == 0)
6703 return ROLE_RS_SERVER;
6704 if (strncmp(role_str, "rs-client", 4) == 0)
6705 return ROLE_RS_CLIENT;
6706 return ROLE_UNDEFINED;
6707 }
6708
6709 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6710 const char *role_str, bool strict_mode)
6711 {
6712 struct peer *peer;
6713
6714 peer = peer_and_group_lookup_vty(vty, ip_str);
6715 if (!peer)
6716 return CMD_WARNING_CONFIG_FAILED;
6717 uint8_t role = get_role_by_name(role_str);
6718
6719 if (role == ROLE_UNDEFINED)
6720 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6721 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6722 }
6723
6724 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6725 {
6726 struct peer *peer;
6727
6728 peer = peer_and_group_lookup_vty(vty, ip_str);
6729 if (!peer)
6730 return CMD_WARNING_CONFIG_FAILED;
6731 return bgp_vty_return(vty, peer_role_unset(peer));
6732 }
6733
6734 DEFPY(neighbor_role,
6735 neighbor_role_cmd,
6736 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6737 NEIGHBOR_STR
6738 NEIGHBOR_ADDR_STR2
6739 "Set session role\n"
6740 ROLE_STR)
6741 {
6742 int idx_peer = 1;
6743 int idx_role = 3;
6744
6745 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6746 false);
6747 }
6748
6749 DEFPY(neighbor_role_strict,
6750 neighbor_role_strict_cmd,
6751 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6752 NEIGHBOR_STR
6753 NEIGHBOR_ADDR_STR2
6754 "Set session role\n"
6755 ROLE_STR
6756 "Use additional restriction on peer\n")
6757 {
6758 int idx_peer = 1;
6759 int idx_role = 3;
6760
6761 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6762 true);
6763 }
6764
6765 DEFPY(no_neighbor_role,
6766 no_neighbor_role_cmd,
6767 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6768 NO_STR
6769 NEIGHBOR_STR
6770 NEIGHBOR_ADDR_STR2
6771 "Set session role\n"
6772 ROLE_STR
6773 "Use additional restriction on peer\n")
6774 {
6775 int idx_peer = 2;
6776
6777 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6778 }
6779
6780 /* disable-connected-check */
6781 DEFUN (neighbor_disable_connected_check,
6782 neighbor_disable_connected_check_cmd,
6783 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6784 NEIGHBOR_STR
6785 NEIGHBOR_ADDR_STR2
6786 "one-hop away EBGP peer using loopback address\n"
6787 "Enforce EBGP neighbors perform multihop\n")
6788 {
6789 int idx_peer = 1;
6790 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6791 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6792 }
6793
6794 DEFUN (no_neighbor_disable_connected_check,
6795 no_neighbor_disable_connected_check_cmd,
6796 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6797 NO_STR
6798 NEIGHBOR_STR
6799 NEIGHBOR_ADDR_STR2
6800 "one-hop away EBGP peer using loopback address\n"
6801 "Enforce EBGP neighbors perform multihop\n")
6802 {
6803 int idx_peer = 2;
6804 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6805 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6806 }
6807
6808 /* disable-link-bw-encoding-ieee */
6809 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6810 neighbor_disable_link_bw_encoding_ieee_cmd,
6811 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6813 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6814 {
6815 int idx_peer = 1;
6816
6817 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6818 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6819 }
6820
6821 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6822 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6823 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6824 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6825 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6826 {
6827 int idx_peer = 2;
6828
6829 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6830 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6831 }
6832
6833 /* extended-optional-parameters */
6834 DEFUN(neighbor_extended_optional_parameters,
6835 neighbor_extended_optional_parameters_cmd,
6836 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6837 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6838 "Force the extended optional parameters format for OPEN messages\n")
6839 {
6840 int idx_peer = 1;
6841
6842 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6843 PEER_FLAG_EXTENDED_OPT_PARAMS);
6844 }
6845
6846 DEFUN(no_neighbor_extended_optional_parameters,
6847 no_neighbor_extended_optional_parameters_cmd,
6848 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6849 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6850 "Force the extended optional parameters format for OPEN messages\n")
6851 {
6852 int idx_peer = 2;
6853
6854 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6855 PEER_FLAG_EXTENDED_OPT_PARAMS);
6856 }
6857
6858 /* enforce-first-as */
6859 DEFUN (neighbor_enforce_first_as,
6860 neighbor_enforce_first_as_cmd,
6861 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6862 NEIGHBOR_STR
6863 NEIGHBOR_ADDR_STR2
6864 "Enforce the first AS for EBGP routes\n")
6865 {
6866 int idx_peer = 1;
6867
6868 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6869 PEER_FLAG_ENFORCE_FIRST_AS);
6870 }
6871
6872 DEFUN (no_neighbor_enforce_first_as,
6873 no_neighbor_enforce_first_as_cmd,
6874 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6875 NO_STR
6876 NEIGHBOR_STR
6877 NEIGHBOR_ADDR_STR2
6878 "Enforce the first AS for EBGP routes\n")
6879 {
6880 int idx_peer = 2;
6881
6882 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6883 PEER_FLAG_ENFORCE_FIRST_AS);
6884 }
6885
6886
6887 DEFUN (neighbor_description,
6888 neighbor_description_cmd,
6889 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6890 NEIGHBOR_STR
6891 NEIGHBOR_ADDR_STR2
6892 "Neighbor specific description\n"
6893 "Up to 80 characters describing this neighbor\n")
6894 {
6895 int idx_peer = 1;
6896 int idx_line = 3;
6897 struct peer *peer;
6898 char *str;
6899
6900 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6901 if (!peer)
6902 return CMD_WARNING_CONFIG_FAILED;
6903
6904 str = argv_concat(argv, argc, idx_line);
6905
6906 peer_description_set(peer, str);
6907
6908 XFREE(MTYPE_TMP, str);
6909
6910 return CMD_SUCCESS;
6911 }
6912
6913 DEFUN (no_neighbor_description,
6914 no_neighbor_description_cmd,
6915 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6916 NO_STR
6917 NEIGHBOR_STR
6918 NEIGHBOR_ADDR_STR2
6919 "Neighbor specific description\n")
6920 {
6921 int idx_peer = 2;
6922 struct peer *peer;
6923
6924 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6925 if (!peer)
6926 return CMD_WARNING_CONFIG_FAILED;
6927
6928 peer_description_unset(peer);
6929
6930 return CMD_SUCCESS;
6931 }
6932
6933 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6934 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6935 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6936 "Neighbor specific description\n"
6937 "Up to 80 characters describing this neighbor\n")
6938
6939 /* Neighbor update-source. */
6940 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6941 const char *source_str)
6942 {
6943 struct peer *peer;
6944 struct prefix p;
6945 union sockunion su;
6946
6947 peer = peer_and_group_lookup_vty(vty, peer_str);
6948 if (!peer)
6949 return CMD_WARNING_CONFIG_FAILED;
6950
6951 if (peer->conf_if)
6952 return CMD_WARNING;
6953
6954 if (source_str) {
6955 if (str2sockunion(source_str, &su) == 0)
6956 peer_update_source_addr_set(peer, &su);
6957 else {
6958 if (str2prefix(source_str, &p)) {
6959 vty_out(vty,
6960 "%% Invalid update-source, remove prefix length \n");
6961 return CMD_WARNING_CONFIG_FAILED;
6962 } else
6963 peer_update_source_if_set(peer, source_str);
6964 }
6965 } else
6966 peer_update_source_unset(peer);
6967
6968 return CMD_SUCCESS;
6969 }
6970
6971 #define BGP_UPDATE_SOURCE_HELP_STR \
6972 "IPv4 address\n" \
6973 "IPv6 address\n" \
6974 "Interface name (requires zebra to be running)\n"
6975
6976 DEFUN (neighbor_update_source,
6977 neighbor_update_source_cmd,
6978 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6979 NEIGHBOR_STR
6980 NEIGHBOR_ADDR_STR2
6981 "Source of routing updates\n"
6982 BGP_UPDATE_SOURCE_HELP_STR)
6983 {
6984 int idx_peer = 1;
6985 int idx_peer_2 = 3;
6986 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6987 argv[idx_peer_2]->arg);
6988 }
6989
6990 DEFUN (no_neighbor_update_source,
6991 no_neighbor_update_source_cmd,
6992 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6993 NO_STR
6994 NEIGHBOR_STR
6995 NEIGHBOR_ADDR_STR2
6996 "Source of routing updates\n"
6997 BGP_UPDATE_SOURCE_HELP_STR)
6998 {
6999 int idx_peer = 2;
7000 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
7001 }
7002
7003 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7004 afi_t afi, safi_t safi,
7005 const char *rmap, int set)
7006 {
7007 int ret;
7008 struct peer *peer;
7009 struct route_map *route_map = NULL;
7010
7011 peer = peer_and_group_lookup_vty(vty, peer_str);
7012 if (!peer)
7013 return CMD_WARNING_CONFIG_FAILED;
7014
7015 if (set) {
7016 if (rmap)
7017 route_map = route_map_lookup_warn_noexist(vty, rmap);
7018 ret = peer_default_originate_set(peer, afi, safi,
7019 rmap, route_map);
7020 } else
7021 ret = peer_default_originate_unset(peer, afi, safi);
7022
7023 return bgp_vty_return(vty, ret);
7024 }
7025
7026 /* neighbor default-originate. */
7027 DEFUN (neighbor_default_originate,
7028 neighbor_default_originate_cmd,
7029 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7030 NEIGHBOR_STR
7031 NEIGHBOR_ADDR_STR2
7032 "Originate default route to this neighbor\n")
7033 {
7034 int idx_peer = 1;
7035 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7036 bgp_node_afi(vty),
7037 bgp_node_safi(vty), NULL, 1);
7038 }
7039
7040 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7041 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7043 "Originate default route to this neighbor\n")
7044
7045 DEFUN (neighbor_default_originate_rmap,
7046 neighbor_default_originate_rmap_cmd,
7047 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
7048 NEIGHBOR_STR
7049 NEIGHBOR_ADDR_STR2
7050 "Originate default route to this neighbor\n"
7051 "Route-map to specify criteria to originate default\n"
7052 "route-map name\n")
7053 {
7054 int idx_peer = 1;
7055 int idx_word = 4;
7056 return peer_default_originate_set_vty(
7057 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7058 argv[idx_word]->arg, 1);
7059 }
7060
7061 ALIAS_HIDDEN(
7062 neighbor_default_originate_rmap,
7063 neighbor_default_originate_rmap_hidden_cmd,
7064 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
7065 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7066 "Originate default route to this neighbor\n"
7067 "Route-map to specify criteria to originate default\n"
7068 "route-map name\n")
7069
7070 DEFUN (no_neighbor_default_originate,
7071 no_neighbor_default_originate_cmd,
7072 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
7073 NO_STR
7074 NEIGHBOR_STR
7075 NEIGHBOR_ADDR_STR2
7076 "Originate default route to this neighbor\n"
7077 "Route-map to specify criteria to originate default\n"
7078 "route-map name\n")
7079 {
7080 int idx_peer = 2;
7081 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7082 bgp_node_afi(vty),
7083 bgp_node_safi(vty), NULL, 0);
7084 }
7085
7086 ALIAS_HIDDEN(
7087 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7088 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
7089 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7090 "Originate default route to this neighbor\n"
7091 "Route-map to specify criteria to originate default\n"
7092 "route-map name\n")
7093
7094
7095 /* Set neighbor's BGP port. */
7096 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7097 const char *port_str)
7098 {
7099 struct peer *peer;
7100 uint16_t port;
7101 struct servent *sp;
7102
7103 peer = peer_and_group_lookup_vty(vty, ip_str);
7104 if (!peer)
7105 return CMD_WARNING_CONFIG_FAILED;
7106
7107 if (!port_str) {
7108 sp = getservbyname("bgp", "tcp");
7109 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7110 } else {
7111 port = strtoul(port_str, NULL, 10);
7112 }
7113
7114 peer_port_set(peer, port);
7115
7116 return CMD_SUCCESS;
7117 }
7118
7119 /* Set specified peer's BGP port. */
7120 DEFUN (neighbor_port,
7121 neighbor_port_cmd,
7122 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7123 NEIGHBOR_STR
7124 NEIGHBOR_ADDR_STR2
7125 "Neighbor's BGP port\n"
7126 "TCP port number\n")
7127 {
7128 int idx_ip = 1;
7129 int idx_number = 3;
7130 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7131 argv[idx_number]->arg);
7132 }
7133
7134 DEFUN (no_neighbor_port,
7135 no_neighbor_port_cmd,
7136 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7137 NO_STR
7138 NEIGHBOR_STR
7139 NEIGHBOR_ADDR_STR2
7140 "Neighbor's BGP port\n"
7141 "TCP port number\n")
7142 {
7143 int idx_ip = 2;
7144 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7145 }
7146
7147
7148 /* neighbor weight. */
7149 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7150 safi_t safi, const char *weight_str)
7151 {
7152 int ret;
7153 struct peer *peer;
7154 unsigned long weight;
7155
7156 peer = peer_and_group_lookup_vty(vty, ip_str);
7157 if (!peer)
7158 return CMD_WARNING_CONFIG_FAILED;
7159
7160 weight = strtoul(weight_str, NULL, 10);
7161
7162 ret = peer_weight_set(peer, afi, safi, weight);
7163 return bgp_vty_return(vty, ret);
7164 }
7165
7166 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7167 safi_t safi)
7168 {
7169 int ret;
7170 struct peer *peer;
7171
7172 peer = peer_and_group_lookup_vty(vty, ip_str);
7173 if (!peer)
7174 return CMD_WARNING_CONFIG_FAILED;
7175
7176 ret = peer_weight_unset(peer, afi, safi);
7177 return bgp_vty_return(vty, ret);
7178 }
7179
7180 DEFUN (neighbor_weight,
7181 neighbor_weight_cmd,
7182 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7183 NEIGHBOR_STR
7184 NEIGHBOR_ADDR_STR2
7185 "Set default weight for routes from this neighbor\n"
7186 "default weight\n")
7187 {
7188 int idx_peer = 1;
7189 int idx_number = 3;
7190 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7191 bgp_node_safi(vty), argv[idx_number]->arg);
7192 }
7193
7194 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7195 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7196 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7197 "Set default weight for routes from this neighbor\n"
7198 "default weight\n")
7199
7200 DEFUN (no_neighbor_weight,
7201 no_neighbor_weight_cmd,
7202 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7203 NO_STR
7204 NEIGHBOR_STR
7205 NEIGHBOR_ADDR_STR2
7206 "Set default weight for routes from this neighbor\n"
7207 "default weight\n")
7208 {
7209 int idx_peer = 2;
7210 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7211 bgp_node_afi(vty), bgp_node_safi(vty));
7212 }
7213
7214 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7215 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7216 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7217 "Set default weight for routes from this neighbor\n"
7218 "default weight\n")
7219
7220
7221 /* Override capability negotiation. */
7222 DEFUN (neighbor_override_capability,
7223 neighbor_override_capability_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7225 NEIGHBOR_STR
7226 NEIGHBOR_ADDR_STR2
7227 "Override capability negotiation result\n")
7228 {
7229 int idx_peer = 1;
7230 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7231 PEER_FLAG_OVERRIDE_CAPABILITY);
7232 }
7233
7234 DEFUN (no_neighbor_override_capability,
7235 no_neighbor_override_capability_cmd,
7236 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7237 NO_STR
7238 NEIGHBOR_STR
7239 NEIGHBOR_ADDR_STR2
7240 "Override capability negotiation result\n")
7241 {
7242 int idx_peer = 2;
7243 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7244 PEER_FLAG_OVERRIDE_CAPABILITY);
7245 }
7246
7247 DEFUN (neighbor_strict_capability,
7248 neighbor_strict_capability_cmd,
7249 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7250 NEIGHBOR_STR
7251 NEIGHBOR_ADDR_STR2
7252 "Strict capability negotiation match\n")
7253 {
7254 int idx_peer = 1;
7255
7256 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7257 PEER_FLAG_STRICT_CAP_MATCH);
7258 }
7259
7260 DEFUN (no_neighbor_strict_capability,
7261 no_neighbor_strict_capability_cmd,
7262 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7263 NO_STR
7264 NEIGHBOR_STR
7265 NEIGHBOR_ADDR_STR2
7266 "Strict capability negotiation match\n")
7267 {
7268 int idx_peer = 2;
7269
7270 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7271 PEER_FLAG_STRICT_CAP_MATCH);
7272 }
7273
7274 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7275 const char *keep_str, const char *hold_str)
7276 {
7277 int ret;
7278 struct peer *peer;
7279 uint32_t keepalive;
7280 uint32_t holdtime;
7281
7282 peer = peer_and_group_lookup_vty(vty, ip_str);
7283 if (!peer)
7284 return CMD_WARNING_CONFIG_FAILED;
7285
7286 keepalive = strtoul(keep_str, NULL, 10);
7287 holdtime = strtoul(hold_str, NULL, 10);
7288
7289 ret = peer_timers_set(peer, keepalive, holdtime);
7290
7291 return bgp_vty_return(vty, ret);
7292 }
7293
7294 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7295 {
7296 int ret;
7297 struct peer *peer;
7298
7299 peer = peer_and_group_lookup_vty(vty, ip_str);
7300 if (!peer)
7301 return CMD_WARNING_CONFIG_FAILED;
7302
7303 ret = peer_timers_unset(peer);
7304
7305 return bgp_vty_return(vty, ret);
7306 }
7307
7308 DEFUN (neighbor_timers,
7309 neighbor_timers_cmd,
7310 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7311 NEIGHBOR_STR
7312 NEIGHBOR_ADDR_STR2
7313 "BGP per neighbor timers\n"
7314 "Keepalive interval\n"
7315 "Holdtime\n")
7316 {
7317 int idx_peer = 1;
7318 int idx_number = 3;
7319 int idx_number_2 = 4;
7320 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7321 argv[idx_number]->arg,
7322 argv[idx_number_2]->arg);
7323 }
7324
7325 DEFUN (no_neighbor_timers,
7326 no_neighbor_timers_cmd,
7327 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7328 NO_STR
7329 NEIGHBOR_STR
7330 NEIGHBOR_ADDR_STR2
7331 "BGP per neighbor timers\n"
7332 "Keepalive interval\n"
7333 "Holdtime\n")
7334 {
7335 int idx_peer = 2;
7336 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7337 }
7338
7339
7340 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7341 const char *time_str)
7342 {
7343 int ret;
7344 struct peer *peer;
7345 uint32_t connect;
7346
7347 peer = peer_and_group_lookup_vty(vty, ip_str);
7348 if (!peer)
7349 return CMD_WARNING_CONFIG_FAILED;
7350
7351 connect = strtoul(time_str, NULL, 10);
7352
7353 ret = peer_timers_connect_set(peer, connect);
7354
7355 return bgp_vty_return(vty, ret);
7356 }
7357
7358 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7359 {
7360 int ret;
7361 struct peer *peer;
7362
7363 peer = peer_and_group_lookup_vty(vty, ip_str);
7364 if (!peer)
7365 return CMD_WARNING_CONFIG_FAILED;
7366
7367 ret = peer_timers_connect_unset(peer);
7368
7369 return bgp_vty_return(vty, ret);
7370 }
7371
7372 DEFUN (neighbor_timers_connect,
7373 neighbor_timers_connect_cmd,
7374 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7375 NEIGHBOR_STR
7376 NEIGHBOR_ADDR_STR2
7377 "BGP per neighbor timers\n"
7378 "BGP connect timer\n"
7379 "Connect timer\n")
7380 {
7381 int idx_peer = 1;
7382 int idx_number = 4;
7383 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7384 argv[idx_number]->arg);
7385 }
7386
7387 DEFUN (no_neighbor_timers_connect,
7388 no_neighbor_timers_connect_cmd,
7389 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7390 NO_STR
7391 NEIGHBOR_STR
7392 NEIGHBOR_ADDR_STR2
7393 "BGP per neighbor timers\n"
7394 "BGP connect timer\n"
7395 "Connect timer\n")
7396 {
7397 int idx_peer = 2;
7398 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7399 }
7400
7401 DEFPY (neighbor_timers_delayopen,
7402 neighbor_timers_delayopen_cmd,
7403 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7404 NEIGHBOR_STR
7405 NEIGHBOR_ADDR_STR2
7406 "BGP per neighbor timers\n"
7407 "RFC 4271 DelayOpenTimer\n"
7408 "DelayOpenTime timer interval\n")
7409 {
7410 struct peer *peer;
7411
7412 peer = peer_and_group_lookup_vty(vty, neighbor);
7413 if (!peer)
7414 return CMD_WARNING_CONFIG_FAILED;
7415
7416 if (!interval) {
7417 if (peer_timers_delayopen_unset(peer))
7418 return CMD_WARNING_CONFIG_FAILED;
7419 } else {
7420 if (peer_timers_delayopen_set(peer, interval))
7421 return CMD_WARNING_CONFIG_FAILED;
7422 }
7423
7424 return CMD_SUCCESS;
7425 }
7426
7427 DEFPY (no_neighbor_timers_delayopen,
7428 no_neighbor_timers_delayopen_cmd,
7429 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7430 NO_STR
7431 NEIGHBOR_STR
7432 NEIGHBOR_ADDR_STR2
7433 "BGP per neighbor timers\n"
7434 "RFC 4271 DelayOpenTimer\n"
7435 "DelayOpenTime timer interval\n")
7436 {
7437 struct peer *peer;
7438
7439 peer = peer_and_group_lookup_vty(vty, neighbor);
7440 if (!peer)
7441 return CMD_WARNING_CONFIG_FAILED;
7442
7443 if (peer_timers_delayopen_unset(peer))
7444 return CMD_WARNING_CONFIG_FAILED;
7445
7446 return CMD_SUCCESS;
7447 }
7448
7449 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7450 const char *time_str, int set)
7451 {
7452 int ret;
7453 struct peer *peer;
7454 uint32_t routeadv = 0;
7455
7456 peer = peer_and_group_lookup_vty(vty, ip_str);
7457 if (!peer)
7458 return CMD_WARNING_CONFIG_FAILED;
7459
7460 if (time_str)
7461 routeadv = strtoul(time_str, NULL, 10);
7462
7463 if (set)
7464 ret = peer_advertise_interval_set(peer, routeadv);
7465 else
7466 ret = peer_advertise_interval_unset(peer);
7467
7468 return bgp_vty_return(vty, ret);
7469 }
7470
7471 DEFUN (neighbor_advertise_interval,
7472 neighbor_advertise_interval_cmd,
7473 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7474 NEIGHBOR_STR
7475 NEIGHBOR_ADDR_STR2
7476 "Minimum interval between sending BGP routing updates\n"
7477 "time in seconds\n")
7478 {
7479 int idx_peer = 1;
7480 int idx_number = 3;
7481 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7482 argv[idx_number]->arg, 1);
7483 }
7484
7485 DEFUN (no_neighbor_advertise_interval,
7486 no_neighbor_advertise_interval_cmd,
7487 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7488 NO_STR
7489 NEIGHBOR_STR
7490 NEIGHBOR_ADDR_STR2
7491 "Minimum interval between sending BGP routing updates\n"
7492 "time in seconds\n")
7493 {
7494 int idx_peer = 2;
7495 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7496 }
7497
7498
7499 /* Time to wait before processing route-map updates */
7500 DEFUN (bgp_set_route_map_delay_timer,
7501 bgp_set_route_map_delay_timer_cmd,
7502 "bgp route-map delay-timer (0-600)",
7503 SET_STR
7504 "BGP route-map delay timer\n"
7505 "Time in secs to wait before processing route-map changes\n"
7506 "0 disables the timer, no route updates happen when route-maps change\n")
7507 {
7508 int idx_number = 3;
7509 uint32_t rmap_delay_timer;
7510
7511 if (argv[idx_number]->arg) {
7512 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7513 bm->rmap_update_timer = rmap_delay_timer;
7514
7515 /* if the dynamic update handling is being disabled, and a timer
7516 * is
7517 * running, stop the timer and act as if the timer has already
7518 * fired.
7519 */
7520 if (!rmap_delay_timer && bm->t_rmap_update) {
7521 THREAD_OFF(bm->t_rmap_update);
7522 thread_execute(bm->master, bgp_route_map_update_timer,
7523 NULL, 0);
7524 }
7525 return CMD_SUCCESS;
7526 } else {
7527 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7528 return CMD_WARNING_CONFIG_FAILED;
7529 }
7530 }
7531
7532 DEFUN (no_bgp_set_route_map_delay_timer,
7533 no_bgp_set_route_map_delay_timer_cmd,
7534 "no bgp route-map delay-timer [(0-600)]",
7535 NO_STR
7536 BGP_STR
7537 "Default BGP route-map delay timer\n"
7538 "Reset to default time to wait for processing route-map changes\n"
7539 "0 disables the timer, no route updates happen when route-maps change\n")
7540 {
7541
7542 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7543
7544 return CMD_SUCCESS;
7545 }
7546
7547 /* neighbor interface */
7548 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7549 const char *str)
7550 {
7551 struct peer *peer;
7552
7553 peer = peer_lookup_vty(vty, ip_str);
7554 if (!peer || peer->conf_if) {
7555 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7556 return CMD_WARNING_CONFIG_FAILED;
7557 }
7558
7559 if (str)
7560 peer_interface_set(peer, str);
7561 else
7562 peer_interface_unset(peer);
7563
7564 return CMD_SUCCESS;
7565 }
7566
7567 DEFUN (neighbor_interface,
7568 neighbor_interface_cmd,
7569 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7570 NEIGHBOR_STR
7571 NEIGHBOR_ADDR_STR
7572 "Interface\n"
7573 "Interface name\n")
7574 {
7575 int idx_ip = 1;
7576 int idx_word = 3;
7577
7578 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7579 }
7580
7581 DEFUN (no_neighbor_interface,
7582 no_neighbor_interface_cmd,
7583 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7584 NO_STR
7585 NEIGHBOR_STR
7586 NEIGHBOR_ADDR_STR
7587 "Interface\n"
7588 "Interface name\n")
7589 {
7590 int idx_peer = 2;
7591
7592 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7593 }
7594
7595 DEFUN (neighbor_distribute_list,
7596 neighbor_distribute_list_cmd,
7597 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7598 NEIGHBOR_STR
7599 NEIGHBOR_ADDR_STR2
7600 "Filter updates to/from this neighbor\n"
7601 "IP Access-list name\n"
7602 "Filter incoming updates\n"
7603 "Filter outgoing updates\n")
7604 {
7605 int idx_peer = 1;
7606 int idx_acl = 3;
7607 int direct, ret;
7608 struct peer *peer;
7609
7610 const char *pstr = argv[idx_peer]->arg;
7611 const char *acl = argv[idx_acl]->arg;
7612 const char *inout = argv[argc - 1]->text;
7613
7614 peer = peer_and_group_lookup_vty(vty, pstr);
7615 if (!peer)
7616 return CMD_WARNING_CONFIG_FAILED;
7617
7618 /* Check filter direction. */
7619 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7620 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7621 direct, acl);
7622
7623 return bgp_vty_return(vty, ret);
7624 }
7625
7626 ALIAS_HIDDEN(
7627 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7628 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7629 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7630 "Filter updates to/from this neighbor\n"
7631 "IP Access-list name\n"
7632 "Filter incoming updates\n"
7633 "Filter outgoing updates\n")
7634
7635 DEFUN (no_neighbor_distribute_list,
7636 no_neighbor_distribute_list_cmd,
7637 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7638 NO_STR
7639 NEIGHBOR_STR
7640 NEIGHBOR_ADDR_STR2
7641 "Filter updates to/from this neighbor\n"
7642 "IP Access-list name\n"
7643 "Filter incoming updates\n"
7644 "Filter outgoing updates\n")
7645 {
7646 int idx_peer = 2;
7647 int direct, ret;
7648 struct peer *peer;
7649
7650 const char *pstr = argv[idx_peer]->arg;
7651 const char *inout = argv[argc - 1]->text;
7652
7653 peer = peer_and_group_lookup_vty(vty, pstr);
7654 if (!peer)
7655 return CMD_WARNING_CONFIG_FAILED;
7656
7657 /* Check filter direction. */
7658 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7659 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7660 direct);
7661
7662 return bgp_vty_return(vty, ret);
7663 }
7664
7665 ALIAS_HIDDEN(
7666 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7667 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7669 "Filter updates to/from this neighbor\n"
7670 "IP Access-list name\n"
7671 "Filter incoming updates\n"
7672 "Filter outgoing updates\n")
7673
7674 /* Set prefix list to the peer. */
7675 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7676 afi_t afi, safi_t safi,
7677 const char *name_str,
7678 const char *direct_str)
7679 {
7680 int ret;
7681 int direct = FILTER_IN;
7682 struct peer *peer;
7683
7684 peer = peer_and_group_lookup_vty(vty, ip_str);
7685 if (!peer)
7686 return CMD_WARNING_CONFIG_FAILED;
7687
7688 /* Check filter direction. */
7689 if (strncmp(direct_str, "i", 1) == 0)
7690 direct = FILTER_IN;
7691 else if (strncmp(direct_str, "o", 1) == 0)
7692 direct = FILTER_OUT;
7693
7694 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7695
7696 return bgp_vty_return(vty, ret);
7697 }
7698
7699 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7700 afi_t afi, safi_t safi,
7701 const char *direct_str)
7702 {
7703 int ret;
7704 struct peer *peer;
7705 int direct = FILTER_IN;
7706
7707 peer = peer_and_group_lookup_vty(vty, ip_str);
7708 if (!peer)
7709 return CMD_WARNING_CONFIG_FAILED;
7710
7711 /* Check filter direction. */
7712 if (strncmp(direct_str, "i", 1) == 0)
7713 direct = FILTER_IN;
7714 else if (strncmp(direct_str, "o", 1) == 0)
7715 direct = FILTER_OUT;
7716
7717 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7718
7719 return bgp_vty_return(vty, ret);
7720 }
7721
7722 DEFUN (neighbor_prefix_list,
7723 neighbor_prefix_list_cmd,
7724 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7725 NEIGHBOR_STR
7726 NEIGHBOR_ADDR_STR2
7727 "Filter updates to/from this neighbor\n"
7728 "Name of a prefix list\n"
7729 "Filter incoming updates\n"
7730 "Filter outgoing updates\n")
7731 {
7732 int idx_peer = 1;
7733 int idx_word = 3;
7734 int idx_in_out = 4;
7735 return peer_prefix_list_set_vty(
7736 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7737 argv[idx_word]->arg, argv[idx_in_out]->arg);
7738 }
7739
7740 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7741 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7742 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7743 "Filter updates to/from this neighbor\n"
7744 "Name of a prefix list\n"
7745 "Filter incoming updates\n"
7746 "Filter outgoing updates\n")
7747
7748 DEFUN (no_neighbor_prefix_list,
7749 no_neighbor_prefix_list_cmd,
7750 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7751 NO_STR
7752 NEIGHBOR_STR
7753 NEIGHBOR_ADDR_STR2
7754 "Filter updates to/from this neighbor\n"
7755 "Name of a prefix list\n"
7756 "Filter incoming updates\n"
7757 "Filter outgoing updates\n")
7758 {
7759 int idx_peer = 2;
7760 int idx_in_out = 5;
7761 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7762 bgp_node_afi(vty), bgp_node_safi(vty),
7763 argv[idx_in_out]->arg);
7764 }
7765
7766 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7767 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7768 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7769 "Filter updates to/from this neighbor\n"
7770 "Name of a prefix list\n"
7771 "Filter incoming updates\n"
7772 "Filter outgoing updates\n")
7773
7774 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7775 safi_t safi, const char *name_str,
7776 const char *direct_str)
7777 {
7778 int ret;
7779 struct peer *peer;
7780 int direct = FILTER_IN;
7781
7782 peer = peer_and_group_lookup_vty(vty, ip_str);
7783 if (!peer)
7784 return CMD_WARNING_CONFIG_FAILED;
7785
7786 /* Check filter direction. */
7787 if (strncmp(direct_str, "i", 1) == 0)
7788 direct = FILTER_IN;
7789 else if (strncmp(direct_str, "o", 1) == 0)
7790 direct = FILTER_OUT;
7791
7792 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7793
7794 return bgp_vty_return(vty, ret);
7795 }
7796
7797 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7798 safi_t safi, const char *direct_str)
7799 {
7800 int ret;
7801 struct peer *peer;
7802 int direct = FILTER_IN;
7803
7804 peer = peer_and_group_lookup_vty(vty, ip_str);
7805 if (!peer)
7806 return CMD_WARNING_CONFIG_FAILED;
7807
7808 /* Check filter direction. */
7809 if (strncmp(direct_str, "i", 1) == 0)
7810 direct = FILTER_IN;
7811 else if (strncmp(direct_str, "o", 1) == 0)
7812 direct = FILTER_OUT;
7813
7814 ret = peer_aslist_unset(peer, afi, safi, direct);
7815
7816 return bgp_vty_return(vty, ret);
7817 }
7818
7819 DEFUN (neighbor_filter_list,
7820 neighbor_filter_list_cmd,
7821 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7822 NEIGHBOR_STR
7823 NEIGHBOR_ADDR_STR2
7824 "Establish BGP filters\n"
7825 "AS path access-list name\n"
7826 "Filter incoming routes\n"
7827 "Filter outgoing routes\n")
7828 {
7829 int idx_peer = 1;
7830 int idx_word = 3;
7831 int idx_in_out = 4;
7832 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7833 bgp_node_safi(vty), argv[idx_word]->arg,
7834 argv[idx_in_out]->arg);
7835 }
7836
7837 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7838 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7839 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7840 "Establish BGP filters\n"
7841 "AS path access-list name\n"
7842 "Filter incoming routes\n"
7843 "Filter outgoing routes\n")
7844
7845 DEFUN (no_neighbor_filter_list,
7846 no_neighbor_filter_list_cmd,
7847 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7848 NO_STR
7849 NEIGHBOR_STR
7850 NEIGHBOR_ADDR_STR2
7851 "Establish BGP filters\n"
7852 "AS path access-list name\n"
7853 "Filter incoming routes\n"
7854 "Filter outgoing routes\n")
7855 {
7856 int idx_peer = 2;
7857 int idx_in_out = 5;
7858 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7859 bgp_node_afi(vty), bgp_node_safi(vty),
7860 argv[idx_in_out]->arg);
7861 }
7862
7863 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7864 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7865 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7866 "Establish BGP filters\n"
7867 "AS path access-list name\n"
7868 "Filter incoming routes\n"
7869 "Filter outgoing routes\n")
7870
7871 /* Set advertise-map to the peer. */
7872 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7873 afi_t afi, safi_t safi,
7874 const char *advertise_str,
7875 const char *condition_str, bool condition,
7876 bool set)
7877 {
7878 int ret = CMD_WARNING_CONFIG_FAILED;
7879 struct peer *peer;
7880 struct route_map *advertise_map;
7881 struct route_map *condition_map;
7882
7883 peer = peer_and_group_lookup_vty(vty, ip_str);
7884 if (!peer)
7885 return ret;
7886
7887 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7888 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7889
7890 if (set)
7891 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7892 advertise_map, condition_str,
7893 condition_map, condition);
7894 else
7895 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7896 advertise_map, condition_str,
7897 condition_map, condition);
7898
7899 return bgp_vty_return(vty, ret);
7900 }
7901
7902 DEFPY (bgp_condadv_period,
7903 bgp_condadv_period_cmd,
7904 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7905 NO_STR
7906 BGP_STR
7907 "Conditional advertisement settings\n"
7908 "Set period to rescan BGP table to check if condition is met\n"
7909 "Period between BGP table scans, in seconds; default 60\n")
7910 {
7911 VTY_DECLVAR_CONTEXT(bgp, bgp);
7912
7913 bgp->condition_check_period =
7914 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7915
7916 return CMD_SUCCESS;
7917 }
7918
7919 DEFPY (neighbor_advertise_map,
7920 neighbor_advertise_map_cmd,
7921 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7922 NO_STR
7923 NEIGHBOR_STR
7924 NEIGHBOR_ADDR_STR2
7925 "Route-map to conditionally advertise routes\n"
7926 "Name of advertise map\n"
7927 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7928 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7929 "Name of the exist or non exist map\n")
7930 {
7931 bool condition = CONDITION_EXIST;
7932
7933 if (!strcmp(exist, "non-exist-map"))
7934 condition = CONDITION_NON_EXIST;
7935
7936 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7937 bgp_node_safi(vty), advertise_str,
7938 condition_str, condition, !no);
7939 }
7940
7941 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7942 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7943 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7944 "Route-map to conditionally advertise routes\n"
7945 "Name of advertise map\n"
7946 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7947 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7948 "Name of the exist or non exist map\n")
7949
7950 /* Set route-map to the peer. */
7951 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7952 afi_t afi, safi_t safi, const char *name_str,
7953 const char *direct_str)
7954 {
7955 int ret;
7956 struct peer *peer;
7957 int direct = RMAP_IN;
7958 struct route_map *route_map;
7959
7960 peer = peer_and_group_lookup_vty(vty, ip_str);
7961 if (!peer)
7962 return CMD_WARNING_CONFIG_FAILED;
7963
7964 /* Check filter direction. */
7965 if (strncmp(direct_str, "in", 2) == 0)
7966 direct = RMAP_IN;
7967 else if (strncmp(direct_str, "o", 1) == 0)
7968 direct = RMAP_OUT;
7969
7970 route_map = route_map_lookup_warn_noexist(vty, name_str);
7971 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7972
7973 return bgp_vty_return(vty, ret);
7974 }
7975
7976 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7977 afi_t afi, safi_t safi,
7978 const char *direct_str)
7979 {
7980 int ret;
7981 struct peer *peer;
7982 int direct = RMAP_IN;
7983
7984 peer = peer_and_group_lookup_vty(vty, ip_str);
7985 if (!peer)
7986 return CMD_WARNING_CONFIG_FAILED;
7987
7988 /* Check filter direction. */
7989 if (strncmp(direct_str, "in", 2) == 0)
7990 direct = RMAP_IN;
7991 else if (strncmp(direct_str, "o", 1) == 0)
7992 direct = RMAP_OUT;
7993
7994 ret = peer_route_map_unset(peer, afi, safi, direct);
7995
7996 return bgp_vty_return(vty, ret);
7997 }
7998
7999 DEFUN (neighbor_route_map,
8000 neighbor_route_map_cmd,
8001 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
8002 NEIGHBOR_STR
8003 NEIGHBOR_ADDR_STR2
8004 "Apply route map to neighbor\n"
8005 "Name of route map\n"
8006 "Apply map to incoming routes\n"
8007 "Apply map to outbound routes\n")
8008 {
8009 int idx_peer = 1;
8010 int idx_word = 3;
8011 int idx_in_out = 4;
8012 return peer_route_map_set_vty(
8013 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8014 argv[idx_word]->arg, argv[idx_in_out]->arg);
8015 }
8016
8017 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
8018 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
8019 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8020 "Apply route map to neighbor\n"
8021 "Name of route map\n"
8022 "Apply map to incoming routes\n"
8023 "Apply map to outbound routes\n")
8024
8025 DEFUN (no_neighbor_route_map,
8026 no_neighbor_route_map_cmd,
8027 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
8028 NO_STR
8029 NEIGHBOR_STR
8030 NEIGHBOR_ADDR_STR2
8031 "Apply route map to neighbor\n"
8032 "Name of route map\n"
8033 "Apply map to incoming routes\n"
8034 "Apply map to outbound routes\n")
8035 {
8036 int idx_peer = 2;
8037 int idx_in_out = 5;
8038 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8039 bgp_node_afi(vty), bgp_node_safi(vty),
8040 argv[idx_in_out]->arg);
8041 }
8042
8043 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
8044 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
8045 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8046 "Apply route map to neighbor\n"
8047 "Name of route map\n"
8048 "Apply map to incoming routes\n"
8049 "Apply map to outbound routes\n")
8050
8051 /* Set unsuppress-map to the peer. */
8052 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8053 afi_t afi, safi_t safi,
8054 const char *name_str)
8055 {
8056 int ret;
8057 struct peer *peer;
8058 struct route_map *route_map;
8059
8060 peer = peer_and_group_lookup_vty(vty, ip_str);
8061 if (!peer)
8062 return CMD_WARNING_CONFIG_FAILED;
8063
8064 route_map = route_map_lookup_warn_noexist(vty, name_str);
8065 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8066
8067 return bgp_vty_return(vty, ret);
8068 }
8069
8070 /* Unset route-map from the peer. */
8071 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8072 afi_t afi, safi_t safi)
8073 {
8074 int ret;
8075 struct peer *peer;
8076
8077 peer = peer_and_group_lookup_vty(vty, ip_str);
8078 if (!peer)
8079 return CMD_WARNING_CONFIG_FAILED;
8080
8081 ret = peer_unsuppress_map_unset(peer, afi, safi);
8082
8083 return bgp_vty_return(vty, ret);
8084 }
8085
8086 DEFUN (neighbor_unsuppress_map,
8087 neighbor_unsuppress_map_cmd,
8088 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8089 NEIGHBOR_STR
8090 NEIGHBOR_ADDR_STR2
8091 "Route-map to selectively unsuppress suppressed routes\n"
8092 "Name of route map\n")
8093 {
8094 int idx_peer = 1;
8095 int idx_word = 3;
8096 return peer_unsuppress_map_set_vty(
8097 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8098 argv[idx_word]->arg);
8099 }
8100
8101 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8102 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8104 "Route-map to selectively unsuppress suppressed routes\n"
8105 "Name of route map\n")
8106
8107 DEFUN (no_neighbor_unsuppress_map,
8108 no_neighbor_unsuppress_map_cmd,
8109 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8110 NO_STR
8111 NEIGHBOR_STR
8112 NEIGHBOR_ADDR_STR2
8113 "Route-map to selectively unsuppress suppressed routes\n"
8114 "Name of route map\n")
8115 {
8116 int idx_peer = 2;
8117 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8118 bgp_node_afi(vty),
8119 bgp_node_safi(vty));
8120 }
8121
8122 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8123 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8124 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8125 "Route-map to selectively unsuppress suppressed routes\n"
8126 "Name of route map\n")
8127
8128 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8129 afi_t afi, safi_t safi,
8130 const char *num_str,
8131 const char *threshold_str, int warning,
8132 const char *restart_str,
8133 const char *force_str)
8134 {
8135 int ret;
8136 struct peer *peer;
8137 uint32_t max;
8138 uint8_t threshold;
8139 uint16_t restart;
8140
8141 peer = peer_and_group_lookup_vty(vty, ip_str);
8142 if (!peer)
8143 return CMD_WARNING_CONFIG_FAILED;
8144
8145 max = strtoul(num_str, NULL, 10);
8146 if (threshold_str)
8147 threshold = atoi(threshold_str);
8148 else
8149 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8150
8151 if (restart_str)
8152 restart = atoi(restart_str);
8153 else
8154 restart = 0;
8155
8156 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8157 restart, force_str ? true : false);
8158
8159 return bgp_vty_return(vty, ret);
8160 }
8161
8162 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8163 afi_t afi, safi_t safi)
8164 {
8165 int ret;
8166 struct peer *peer;
8167
8168 peer = peer_and_group_lookup_vty(vty, ip_str);
8169 if (!peer)
8170 return CMD_WARNING_CONFIG_FAILED;
8171
8172 ret = peer_maximum_prefix_unset(peer, afi, safi);
8173
8174 return bgp_vty_return(vty, ret);
8175 }
8176
8177 /* Maximum number of prefix to be sent to the neighbor. */
8178 DEFUN(neighbor_maximum_prefix_out,
8179 neighbor_maximum_prefix_out_cmd,
8180 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8181 NEIGHBOR_STR
8182 NEIGHBOR_ADDR_STR2
8183 "Maximum number of prefixes to be sent to this peer\n"
8184 "Maximum no. of prefix limit\n")
8185 {
8186 int ret;
8187 int idx_peer = 1;
8188 int idx_number = 3;
8189 struct peer *peer;
8190 uint32_t max;
8191 afi_t afi = bgp_node_afi(vty);
8192 safi_t safi = bgp_node_safi(vty);
8193
8194 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8195 if (!peer)
8196 return CMD_WARNING_CONFIG_FAILED;
8197
8198 max = strtoul(argv[idx_number]->arg, NULL, 10);
8199
8200 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8201
8202 return bgp_vty_return(vty, ret);
8203 }
8204
8205 DEFUN(no_neighbor_maximum_prefix_out,
8206 no_neighbor_maximum_prefix_out_cmd,
8207 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8208 NO_STR
8209 NEIGHBOR_STR
8210 NEIGHBOR_ADDR_STR2
8211 "Maximum number of prefixes to be sent to this peer\n"
8212 "Maximum no. of prefix limit\n")
8213 {
8214 int ret;
8215 int idx_peer = 2;
8216 struct peer *peer;
8217 afi_t afi = bgp_node_afi(vty);
8218 safi_t safi = bgp_node_safi(vty);
8219
8220 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8221 if (!peer)
8222 return CMD_WARNING_CONFIG_FAILED;
8223
8224 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8225
8226 return bgp_vty_return(vty, ret);
8227 }
8228
8229 /* Maximum number of prefix configuration. Prefix count is different
8230 for each peer configuration. So this configuration can be set for
8231 each peer configuration. */
8232 DEFUN (neighbor_maximum_prefix,
8233 neighbor_maximum_prefix_cmd,
8234 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8235 NEIGHBOR_STR
8236 NEIGHBOR_ADDR_STR2
8237 "Maximum number of prefix accept from this peer\n"
8238 "maximum no. of prefix limit\n"
8239 "Force checking all received routes not only accepted\n")
8240 {
8241 int idx_peer = 1;
8242 int idx_number = 3;
8243 int idx_force = 0;
8244 char *force = NULL;
8245
8246 if (argv_find(argv, argc, "force", &idx_force))
8247 force = argv[idx_force]->arg;
8248
8249 return peer_maximum_prefix_set_vty(
8250 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8251 argv[idx_number]->arg, NULL, 0, NULL, force);
8252 }
8253
8254 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8255 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8256 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8257 "Maximum number of prefix accept from this peer\n"
8258 "maximum no. of prefix limit\n"
8259 "Force checking all received routes not only accepted\n")
8260
8261 DEFUN (neighbor_maximum_prefix_threshold,
8262 neighbor_maximum_prefix_threshold_cmd,
8263 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8264 NEIGHBOR_STR
8265 NEIGHBOR_ADDR_STR2
8266 "Maximum number of prefix accept from this peer\n"
8267 "maximum no. of prefix limit\n"
8268 "Threshold value (%) at which to generate a warning msg\n"
8269 "Force checking all received routes not only accepted\n")
8270 {
8271 int idx_peer = 1;
8272 int idx_number = 3;
8273 int idx_number_2 = 4;
8274 int idx_force = 0;
8275 char *force = NULL;
8276
8277 if (argv_find(argv, argc, "force", &idx_force))
8278 force = argv[idx_force]->arg;
8279
8280 return peer_maximum_prefix_set_vty(
8281 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8282 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8283 }
8284
8285 ALIAS_HIDDEN(
8286 neighbor_maximum_prefix_threshold,
8287 neighbor_maximum_prefix_threshold_hidden_cmd,
8288 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8290 "Maximum number of prefix accept from this peer\n"
8291 "maximum no. of prefix limit\n"
8292 "Threshold value (%) at which to generate a warning msg\n"
8293 "Force checking all received routes not only accepted\n")
8294
8295 DEFUN (neighbor_maximum_prefix_warning,
8296 neighbor_maximum_prefix_warning_cmd,
8297 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8298 NEIGHBOR_STR
8299 NEIGHBOR_ADDR_STR2
8300 "Maximum number of prefix accept from this peer\n"
8301 "maximum no. of prefix limit\n"
8302 "Only give warning message when limit is exceeded\n"
8303 "Force checking all received routes not only accepted\n")
8304 {
8305 int idx_peer = 1;
8306 int idx_number = 3;
8307 int idx_force = 0;
8308 char *force = NULL;
8309
8310 if (argv_find(argv, argc, "force", &idx_force))
8311 force = argv[idx_force]->arg;
8312
8313 return peer_maximum_prefix_set_vty(
8314 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8315 argv[idx_number]->arg, NULL, 1, NULL, force);
8316 }
8317
8318 ALIAS_HIDDEN(
8319 neighbor_maximum_prefix_warning,
8320 neighbor_maximum_prefix_warning_hidden_cmd,
8321 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8322 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8323 "Maximum number of prefix accept from this peer\n"
8324 "maximum no. of prefix limit\n"
8325 "Only give warning message when limit is exceeded\n"
8326 "Force checking all received routes not only accepted\n")
8327
8328 DEFUN (neighbor_maximum_prefix_threshold_warning,
8329 neighbor_maximum_prefix_threshold_warning_cmd,
8330 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8331 NEIGHBOR_STR
8332 NEIGHBOR_ADDR_STR2
8333 "Maximum number of prefix accept from this peer\n"
8334 "maximum no. of prefix limit\n"
8335 "Threshold value (%) at which to generate a warning msg\n"
8336 "Only give warning message when limit is exceeded\n"
8337 "Force checking all received routes not only accepted\n")
8338 {
8339 int idx_peer = 1;
8340 int idx_number = 3;
8341 int idx_number_2 = 4;
8342 int idx_force = 0;
8343 char *force = NULL;
8344
8345 if (argv_find(argv, argc, "force", &idx_force))
8346 force = argv[idx_force]->arg;
8347
8348 return peer_maximum_prefix_set_vty(
8349 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8350 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8351 }
8352
8353 ALIAS_HIDDEN(
8354 neighbor_maximum_prefix_threshold_warning,
8355 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8356 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8357 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8358 "Maximum number of prefix accept from this peer\n"
8359 "maximum no. of prefix limit\n"
8360 "Threshold value (%) at which to generate a warning msg\n"
8361 "Only give warning message when limit is exceeded\n"
8362 "Force checking all received routes not only accepted\n")
8363
8364 DEFUN (neighbor_maximum_prefix_restart,
8365 neighbor_maximum_prefix_restart_cmd,
8366 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8367 NEIGHBOR_STR
8368 NEIGHBOR_ADDR_STR2
8369 "Maximum number of prefix accept from this peer\n"
8370 "maximum no. of prefix limit\n"
8371 "Restart bgp connection after limit is exceeded\n"
8372 "Restart interval in minutes\n"
8373 "Force checking all received routes not only accepted\n")
8374 {
8375 int idx_peer = 1;
8376 int idx_number = 3;
8377 int idx_number_2 = 5;
8378 int idx_force = 0;
8379 char *force = NULL;
8380
8381 if (argv_find(argv, argc, "force", &idx_force))
8382 force = argv[idx_force]->arg;
8383
8384 return peer_maximum_prefix_set_vty(
8385 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8386 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8387 }
8388
8389 ALIAS_HIDDEN(
8390 neighbor_maximum_prefix_restart,
8391 neighbor_maximum_prefix_restart_hidden_cmd,
8392 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8393 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8394 "Maximum number of prefix accept from this peer\n"
8395 "maximum no. of prefix limit\n"
8396 "Restart bgp connection after limit is exceeded\n"
8397 "Restart interval in minutes\n"
8398 "Force checking all received routes not only accepted\n")
8399
8400 DEFUN (neighbor_maximum_prefix_threshold_restart,
8401 neighbor_maximum_prefix_threshold_restart_cmd,
8402 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8403 NEIGHBOR_STR
8404 NEIGHBOR_ADDR_STR2
8405 "Maximum number of prefixes to accept from this peer\n"
8406 "maximum no. of prefix limit\n"
8407 "Threshold value (%) at which to generate a warning msg\n"
8408 "Restart bgp connection after limit is exceeded\n"
8409 "Restart interval in minutes\n"
8410 "Force checking all received routes not only accepted\n")
8411 {
8412 int idx_peer = 1;
8413 int idx_number = 3;
8414 int idx_number_2 = 4;
8415 int idx_number_3 = 6;
8416 int idx_force = 0;
8417 char *force = NULL;
8418
8419 if (argv_find(argv, argc, "force", &idx_force))
8420 force = argv[idx_force]->arg;
8421
8422 return peer_maximum_prefix_set_vty(
8423 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8424 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8425 argv[idx_number_3]->arg, force);
8426 }
8427
8428 ALIAS_HIDDEN(
8429 neighbor_maximum_prefix_threshold_restart,
8430 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8431 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8432 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8433 "Maximum number of prefixes to accept from this peer\n"
8434 "maximum no. of prefix limit\n"
8435 "Threshold value (%) at which to generate a warning msg\n"
8436 "Restart bgp connection after limit is exceeded\n"
8437 "Restart interval in minutes\n"
8438 "Force checking all received routes not only accepted\n")
8439
8440 DEFUN (no_neighbor_maximum_prefix,
8441 no_neighbor_maximum_prefix_cmd,
8442 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8443 NO_STR
8444 NEIGHBOR_STR
8445 NEIGHBOR_ADDR_STR2
8446 "Maximum number of prefixes to accept from this peer\n"
8447 "maximum no. of prefix limit\n"
8448 "Threshold value (%) at which to generate a warning msg\n"
8449 "Restart bgp connection after limit is exceeded\n"
8450 "Restart interval in minutes\n"
8451 "Only give warning message when limit is exceeded\n"
8452 "Force checking all received routes not only accepted\n")
8453 {
8454 int idx_peer = 2;
8455 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8456 bgp_node_afi(vty),
8457 bgp_node_safi(vty));
8458 }
8459
8460 ALIAS_HIDDEN(
8461 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8462 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8463 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8464 "Maximum number of prefixes to accept from this peer\n"
8465 "maximum no. of prefix limit\n"
8466 "Threshold value (%) at which to generate a warning msg\n"
8467 "Restart bgp connection after limit is exceeded\n"
8468 "Restart interval in minutes\n"
8469 "Only give warning message when limit is exceeded\n"
8470 "Force checking all received routes not only accepted\n")
8471
8472 /* "neighbor accept-own" */
8473 DEFPY (neighbor_accept_own,
8474 neighbor_accept_own_cmd,
8475 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8476 NO_STR
8477 NEIGHBOR_STR
8478 NEIGHBOR_ADDR_STR2
8479 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8480 {
8481 struct peer *peer;
8482 afi_t afi = bgp_node_afi(vty);
8483 safi_t safi = bgp_node_safi(vty);
8484 int ret;
8485
8486 peer = peer_and_group_lookup_vty(vty, neighbor);
8487 if (!peer)
8488 return CMD_WARNING_CONFIG_FAILED;
8489
8490 if (no)
8491 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8492 else
8493 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8494
8495 return bgp_vty_return(vty, ret);
8496 }
8497
8498 /* "neighbor soo" */
8499 DEFPY (neighbor_soo,
8500 neighbor_soo_cmd,
8501 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8502 NEIGHBOR_STR
8503 NEIGHBOR_ADDR_STR2
8504 "Set the Site-of-Origin (SoO) extended community\n"
8505 "VPN extended community\n")
8506 {
8507 struct peer *peer;
8508 afi_t afi = bgp_node_afi(vty);
8509 safi_t safi = bgp_node_safi(vty);
8510 struct ecommunity *ecomm_soo;
8511
8512 peer = peer_and_group_lookup_vty(vty, neighbor);
8513 if (!peer)
8514 return CMD_WARNING_CONFIG_FAILED;
8515
8516 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8517 if (!ecomm_soo) {
8518 vty_out(vty, "%% Malformed SoO extended community\n");
8519 return CMD_WARNING;
8520 }
8521 ecommunity_str(ecomm_soo);
8522
8523 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8524 ecommunity_free(&peer->soo[afi][safi]);
8525 peer->soo[afi][safi] = ecomm_soo;
8526 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8527 }
8528
8529 return bgp_vty_return(vty,
8530 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8531 }
8532
8533 DEFPY (no_neighbor_soo,
8534 no_neighbor_soo_cmd,
8535 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8536 NO_STR
8537 NEIGHBOR_STR
8538 NEIGHBOR_ADDR_STR2
8539 "Set the Site-of-Origin (SoO) extended community\n"
8540 "VPN extended community\n")
8541 {
8542 struct peer *peer;
8543 afi_t afi = bgp_node_afi(vty);
8544 safi_t safi = bgp_node_safi(vty);
8545
8546 peer = peer_and_group_lookup_vty(vty, neighbor);
8547 if (!peer)
8548 return CMD_WARNING_CONFIG_FAILED;
8549
8550 ecommunity_free(&peer->soo[afi][safi]);
8551
8552 return bgp_vty_return(
8553 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8554 }
8555
8556 /* "neighbor allowas-in" */
8557 DEFUN (neighbor_allowas_in,
8558 neighbor_allowas_in_cmd,
8559 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8560 NEIGHBOR_STR
8561 NEIGHBOR_ADDR_STR2
8562 "Accept as-path with my AS present in it\n"
8563 "Number of occurrences of AS number\n"
8564 "Only accept my AS in the as-path if the route was originated in my AS\n")
8565 {
8566 int idx_peer = 1;
8567 int idx_number_origin = 3;
8568 int ret;
8569 int origin = 0;
8570 struct peer *peer;
8571 int allow_num = 0;
8572
8573 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8574 if (!peer)
8575 return CMD_WARNING_CONFIG_FAILED;
8576
8577 if (argc <= idx_number_origin)
8578 allow_num = 3;
8579 else {
8580 if (argv[idx_number_origin]->type == WORD_TKN)
8581 origin = 1;
8582 else
8583 allow_num = atoi(argv[idx_number_origin]->arg);
8584 }
8585
8586 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8587 allow_num, origin);
8588
8589 return bgp_vty_return(vty, ret);
8590 }
8591
8592 ALIAS_HIDDEN(
8593 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8594 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8595 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8596 "Accept as-path with my AS present in it\n"
8597 "Number of occurrences of AS number\n"
8598 "Only accept my AS in the as-path if the route was originated in my AS\n")
8599
8600 DEFUN (no_neighbor_allowas_in,
8601 no_neighbor_allowas_in_cmd,
8602 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8603 NO_STR
8604 NEIGHBOR_STR
8605 NEIGHBOR_ADDR_STR2
8606 "allow local ASN appears in aspath attribute\n"
8607 "Number of occurrences of AS number\n"
8608 "Only accept my AS in the as-path if the route was originated in my AS\n")
8609 {
8610 int idx_peer = 2;
8611 int ret;
8612 struct peer *peer;
8613
8614 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8615 if (!peer)
8616 return CMD_WARNING_CONFIG_FAILED;
8617
8618 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8619 bgp_node_safi(vty));
8620
8621 return bgp_vty_return(vty, ret);
8622 }
8623
8624 ALIAS_HIDDEN(
8625 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8626 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8627 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8628 "allow local ASN appears in aspath attribute\n"
8629 "Number of occurrences of AS number\n"
8630 "Only accept my AS in the as-path if the route was originated in my AS\n")
8631
8632 DEFUN (neighbor_ttl_security,
8633 neighbor_ttl_security_cmd,
8634 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8635 NEIGHBOR_STR
8636 NEIGHBOR_ADDR_STR2
8637 "BGP ttl-security parameters\n"
8638 "Specify the maximum number of hops to the BGP peer\n"
8639 "Number of hops to BGP peer\n")
8640 {
8641 int idx_peer = 1;
8642 int idx_number = 4;
8643 struct peer *peer;
8644 int gtsm_hops;
8645
8646 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8647 if (!peer)
8648 return CMD_WARNING_CONFIG_FAILED;
8649
8650 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8651
8652 /*
8653 * If 'neighbor swpX', then this is for directly connected peers,
8654 * we should not accept a ttl-security hops value greater than 1.
8655 */
8656 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8657 vty_out(vty,
8658 "%s is directly connected peer, hops cannot exceed 1\n",
8659 argv[idx_peer]->arg);
8660 return CMD_WARNING_CONFIG_FAILED;
8661 }
8662
8663 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8664 }
8665
8666 DEFUN (no_neighbor_ttl_security,
8667 no_neighbor_ttl_security_cmd,
8668 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8669 NO_STR
8670 NEIGHBOR_STR
8671 NEIGHBOR_ADDR_STR2
8672 "BGP ttl-security parameters\n"
8673 "Specify the maximum number of hops to the BGP peer\n"
8674 "Number of hops to BGP peer\n")
8675 {
8676 int idx_peer = 2;
8677 struct peer *peer;
8678
8679 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8680 if (!peer)
8681 return CMD_WARNING_CONFIG_FAILED;
8682
8683 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8684 }
8685
8686 /* disable-addpath-rx */
8687 DEFUN(neighbor_disable_addpath_rx,
8688 neighbor_disable_addpath_rx_cmd,
8689 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8690 NEIGHBOR_STR
8691 NEIGHBOR_ADDR_STR2
8692 "Do not accept additional paths\n")
8693 {
8694 char *peer_str = argv[1]->arg;
8695 struct peer *peer;
8696 afi_t afi = bgp_node_afi(vty);
8697 safi_t safi = bgp_node_safi(vty);
8698
8699 peer = peer_and_group_lookup_vty(vty, peer_str);
8700 if (!peer)
8701 return CMD_WARNING_CONFIG_FAILED;
8702
8703 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8704 PEER_FLAG_DISABLE_ADDPATH_RX);
8705 }
8706
8707 DEFUN(no_neighbor_disable_addpath_rx,
8708 no_neighbor_disable_addpath_rx_cmd,
8709 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8710 NO_STR
8711 NEIGHBOR_STR
8712 NEIGHBOR_ADDR_STR2
8713 "Do not accept additional paths\n")
8714 {
8715 char *peer_str = argv[2]->arg;
8716 struct peer *peer;
8717 afi_t afi = bgp_node_afi(vty);
8718 safi_t safi = bgp_node_safi(vty);
8719
8720 peer = peer_and_group_lookup_vty(vty, peer_str);
8721 if (!peer)
8722 return CMD_WARNING_CONFIG_FAILED;
8723
8724 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8725 PEER_FLAG_DISABLE_ADDPATH_RX);
8726 }
8727
8728 DEFUN (neighbor_addpath_tx_all_paths,
8729 neighbor_addpath_tx_all_paths_cmd,
8730 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8731 NEIGHBOR_STR
8732 NEIGHBOR_ADDR_STR2
8733 "Use addpath to advertise all paths to a neighbor\n")
8734 {
8735 int idx_peer = 1;
8736 struct peer *peer;
8737
8738 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8739 if (!peer)
8740 return CMD_WARNING_CONFIG_FAILED;
8741
8742 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8743 BGP_ADDPATH_ALL);
8744 return CMD_SUCCESS;
8745 }
8746
8747 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8748 neighbor_addpath_tx_all_paths_hidden_cmd,
8749 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8751 "Use addpath to advertise all paths to a neighbor\n")
8752
8753 DEFUN (no_neighbor_addpath_tx_all_paths,
8754 no_neighbor_addpath_tx_all_paths_cmd,
8755 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8756 NO_STR
8757 NEIGHBOR_STR
8758 NEIGHBOR_ADDR_STR2
8759 "Use addpath to advertise all paths to a neighbor\n")
8760 {
8761 int idx_peer = 2;
8762 struct peer *peer;
8763
8764 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8765 if (!peer)
8766 return CMD_WARNING_CONFIG_FAILED;
8767
8768 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8769 != BGP_ADDPATH_ALL) {
8770 vty_out(vty,
8771 "%% Peer not currently configured to transmit all paths.");
8772 return CMD_WARNING_CONFIG_FAILED;
8773 }
8774
8775 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8776 BGP_ADDPATH_NONE);
8777
8778 return CMD_SUCCESS;
8779 }
8780
8781 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8782 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8783 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8784 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8785 "Use addpath to advertise all paths to a neighbor\n")
8786
8787 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8788 neighbor_addpath_tx_bestpath_per_as_cmd,
8789 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8790 NEIGHBOR_STR
8791 NEIGHBOR_ADDR_STR2
8792 "Use addpath to advertise the bestpath per each neighboring AS\n")
8793 {
8794 int idx_peer = 1;
8795 struct peer *peer;
8796
8797 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8798 if (!peer)
8799 return CMD_WARNING_CONFIG_FAILED;
8800
8801 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8802 BGP_ADDPATH_BEST_PER_AS);
8803
8804 return CMD_SUCCESS;
8805 }
8806
8807 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8808 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8809 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8810 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8811 "Use addpath to advertise the bestpath per each neighboring AS\n")
8812
8813 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8814 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8815 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8816 NO_STR
8817 NEIGHBOR_STR
8818 NEIGHBOR_ADDR_STR2
8819 "Use addpath to advertise the bestpath per each neighboring AS\n")
8820 {
8821 int idx_peer = 2;
8822 struct peer *peer;
8823
8824 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8825 if (!peer)
8826 return CMD_WARNING_CONFIG_FAILED;
8827
8828 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8829 != BGP_ADDPATH_BEST_PER_AS) {
8830 vty_out(vty,
8831 "%% Peer not currently configured to transmit all best path per as.");
8832 return CMD_WARNING_CONFIG_FAILED;
8833 }
8834
8835 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8836 BGP_ADDPATH_NONE);
8837
8838 return CMD_SUCCESS;
8839 }
8840
8841 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8842 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8843 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8844 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8845 "Use addpath to advertise the bestpath per each neighboring AS\n")
8846
8847 DEFPY(
8848 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8849 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8850 NEIGHBOR_STR
8851 NEIGHBOR_ADDR_STR2
8852 "Detect AS loops before sending to neighbor\n")
8853 {
8854 struct peer *peer;
8855
8856 peer = peer_and_group_lookup_vty(vty, neighbor);
8857 if (!peer)
8858 return CMD_WARNING_CONFIG_FAILED;
8859
8860 peer->as_path_loop_detection = true;
8861
8862 return CMD_SUCCESS;
8863 }
8864
8865 DEFPY(
8866 no_neighbor_aspath_loop_detection,
8867 no_neighbor_aspath_loop_detection_cmd,
8868 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8869 NO_STR
8870 NEIGHBOR_STR
8871 NEIGHBOR_ADDR_STR2
8872 "Detect AS loops before sending to neighbor\n")
8873 {
8874 struct peer *peer;
8875
8876 peer = peer_and_group_lookup_vty(vty, neighbor);
8877 if (!peer)
8878 return CMD_WARNING_CONFIG_FAILED;
8879
8880 peer->as_path_loop_detection = false;
8881
8882 return CMD_SUCCESS;
8883 }
8884
8885 DEFPY(neighbor_path_attribute_discard,
8886 neighbor_path_attribute_discard_cmd,
8887 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8888 NEIGHBOR_STR
8889 NEIGHBOR_ADDR_STR2
8890 "Manipulate path attributes from incoming UPDATE messages\n"
8891 "Drop specified attributes from incoming UPDATE messages\n"
8892 "Attribute number\n")
8893 {
8894 struct peer *peer;
8895 int idx = 0;
8896 char *discard_attrs = NULL;
8897
8898 peer = peer_and_group_lookup_vty(vty, neighbor);
8899 if (!peer)
8900 return CMD_WARNING_CONFIG_FAILED;
8901
8902 argv_find(argv, argc, "(1-255)", &idx);
8903 if (idx)
8904 discard_attrs = argv_concat(argv, argc, idx);
8905
8906 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8907
8908 XFREE(MTYPE_TMP, discard_attrs);
8909
8910 return CMD_SUCCESS;
8911 }
8912
8913 DEFPY(no_neighbor_path_attribute_discard,
8914 no_neighbor_path_attribute_discard_cmd,
8915 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8916 NO_STR
8917 NEIGHBOR_STR
8918 NEIGHBOR_ADDR_STR2
8919 "Manipulate path attributes from incoming UPDATE messages\n"
8920 "Drop specified attributes from incoming UPDATE messages\n"
8921 "Attribute number\n")
8922 {
8923 struct peer *peer;
8924 int idx = 0;
8925 char *discard_attrs = NULL;
8926
8927 peer = peer_and_group_lookup_vty(vty, neighbor);
8928 if (!peer)
8929 return CMD_WARNING_CONFIG_FAILED;
8930
8931 argv_find(argv, argc, "(1-255)", &idx);
8932 if (idx)
8933 discard_attrs = argv[idx]->arg;
8934
8935 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
8936
8937 XFREE(MTYPE_TMP, discard_attrs);
8938
8939 return CMD_SUCCESS;
8940 }
8941
8942 DEFPY(neighbor_path_attribute_treat_as_withdraw,
8943 neighbor_path_attribute_treat_as_withdraw_cmd,
8944 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8945 NEIGHBOR_STR
8946 NEIGHBOR_ADDR_STR2
8947 "Manipulate path attributes from incoming UPDATE messages\n"
8948 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8949 "Attribute number\n")
8950 {
8951 struct peer *peer;
8952 int idx = 0;
8953 char *withdraw_attrs = NULL;
8954
8955 peer = peer_and_group_lookup_vty(vty, neighbor);
8956 if (!peer)
8957 return CMD_WARNING_CONFIG_FAILED;
8958
8959 argv_find(argv, argc, "(1-255)", &idx);
8960 if (idx)
8961 withdraw_attrs = argv_concat(argv, argc, idx);
8962
8963 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, true);
8964
8965 XFREE(MTYPE_TMP, withdraw_attrs);
8966
8967 return CMD_SUCCESS;
8968 }
8969
8970 DEFPY(no_neighbor_path_attribute_treat_as_withdraw,
8971 no_neighbor_path_attribute_treat_as_withdraw_cmd,
8972 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8973 NO_STR
8974 NEIGHBOR_STR
8975 NEIGHBOR_ADDR_STR2
8976 "Manipulate path attributes from incoming UPDATE messages\n"
8977 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8978 "Attribute number\n")
8979 {
8980 struct peer *peer;
8981 int idx = 0;
8982 char *withdraw_attrs = NULL;
8983
8984 peer = peer_and_group_lookup_vty(vty, neighbor);
8985 if (!peer)
8986 return CMD_WARNING_CONFIG_FAILED;
8987
8988 argv_find(argv, argc, "(1-255)", &idx);
8989 if (idx)
8990 withdraw_attrs = argv_concat(argv, argc, idx);
8991
8992 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, false);
8993
8994 XFREE(MTYPE_TMP, withdraw_attrs);
8995
8996 return CMD_SUCCESS;
8997 }
8998
8999 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
9000 struct ecommunity **list, bool is_rt6)
9001 {
9002 struct ecommunity *ecom = NULL;
9003 struct ecommunity *ecomadd;
9004
9005 for (; argc; --argc, ++argv) {
9006 if (is_rt6)
9007 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9008 ECOMMUNITY_ROUTE_TARGET,
9009 0);
9010 else
9011 ecomadd = ecommunity_str2com(argv[0]->arg,
9012 ECOMMUNITY_ROUTE_TARGET,
9013 0);
9014 if (!ecomadd) {
9015 vty_out(vty, "Malformed community-list value\n");
9016 if (ecom)
9017 ecommunity_free(&ecom);
9018 return CMD_WARNING_CONFIG_FAILED;
9019 }
9020
9021 if (ecom) {
9022 ecommunity_merge(ecom, ecomadd);
9023 ecommunity_free(&ecomadd);
9024 } else {
9025 ecom = ecomadd;
9026 }
9027 }
9028
9029 if (*list) {
9030 ecommunity_free(&*list);
9031 }
9032 *list = ecom;
9033
9034 return CMD_SUCCESS;
9035 }
9036
9037 /*
9038 * v2vimport is true if we are handling a `import vrf ...` command
9039 */
9040 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
9041 {
9042 afi_t afi;
9043
9044 switch (vty->node) {
9045 case BGP_IPV4_NODE:
9046 afi = AFI_IP;
9047 break;
9048 case BGP_IPV6_NODE:
9049 afi = AFI_IP6;
9050 break;
9051 default:
9052 vty_out(vty,
9053 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
9054 return AFI_MAX;
9055 }
9056
9057 if (!v2vimport) {
9058 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9059 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9060 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9061 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9062 vty_out(vty,
9063 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9064 return AFI_MAX;
9065 }
9066 } else {
9067 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9068 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9069 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9070 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9071 vty_out(vty,
9072 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9073 return AFI_MAX;
9074 }
9075 }
9076 return afi;
9077 }
9078
9079 DEFPY (af_rd_vpn_export,
9080 af_rd_vpn_export_cmd,
9081 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9082 NO_STR
9083 "Specify route distinguisher\n"
9084 "Between current address-family and vpn\n"
9085 "For routes leaked from current address-family to vpn\n"
9086 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9087 {
9088 VTY_DECLVAR_CONTEXT(bgp, bgp);
9089 struct prefix_rd prd;
9090 int ret;
9091 afi_t afi;
9092 int idx = 0;
9093 bool yes = true;
9094
9095 if (argv_find(argv, argc, "no", &idx))
9096 yes = false;
9097
9098 if (yes) {
9099 ret = str2prefix_rd(rd_str, &prd);
9100 if (!ret) {
9101 vty_out(vty, "%% Malformed rd\n");
9102 return CMD_WARNING_CONFIG_FAILED;
9103 }
9104 }
9105
9106 afi = vpn_policy_getafi(vty, bgp, false);
9107 if (afi == AFI_MAX)
9108 return CMD_WARNING_CONFIG_FAILED;
9109
9110 /*
9111 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9112 */
9113 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9114 bgp_get_default(), bgp);
9115
9116 if (yes) {
9117 bgp->vpn_policy[afi].tovpn_rd_pretty =
9118 XSTRDUP(MTYPE_BGP, rd_str);
9119 bgp->vpn_policy[afi].tovpn_rd = prd;
9120 SET_FLAG(bgp->vpn_policy[afi].flags,
9121 BGP_VPN_POLICY_TOVPN_RD_SET);
9122 } else {
9123 XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty);
9124 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9125 BGP_VPN_POLICY_TOVPN_RD_SET);
9126 }
9127
9128 /* post-change: re-export vpn routes */
9129 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9130 bgp_get_default(), bgp);
9131
9132 return CMD_SUCCESS;
9133 }
9134
9135 ALIAS (af_rd_vpn_export,
9136 af_no_rd_vpn_export_cmd,
9137 "no rd vpn export",
9138 NO_STR
9139 "Specify route distinguisher\n"
9140 "Between current address-family and vpn\n"
9141 "For routes leaked from current address-family to vpn\n")
9142
9143 DEFPY (af_label_vpn_export,
9144 af_label_vpn_export_cmd,
9145 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9146 NO_STR
9147 "label value for VRF\n"
9148 "Between current address-family and vpn\n"
9149 "For routes leaked from current address-family to vpn\n"
9150 "Label Value <0-1048575>\n"
9151 "Automatically assign a label\n")
9152 {
9153 VTY_DECLVAR_CONTEXT(bgp, bgp);
9154 mpls_label_t label = MPLS_LABEL_NONE;
9155 afi_t afi;
9156 int idx = 0;
9157 bool yes = true;
9158
9159 if (argv_find(argv, argc, "no", &idx))
9160 yes = false;
9161
9162 /* If "no ...", squash trailing parameter */
9163 if (!yes)
9164 label_auto = NULL;
9165
9166 if (yes) {
9167 if (!label_auto)
9168 label = label_val; /* parser should force unsigned */
9169 }
9170
9171 afi = vpn_policy_getafi(vty, bgp, false);
9172 if (afi == AFI_MAX)
9173 return CMD_WARNING_CONFIG_FAILED;
9174
9175
9176 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9177 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9178 /* no change */
9179 return CMD_SUCCESS;
9180
9181 /*
9182 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9183 */
9184 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9185 bgp_get_default(), bgp);
9186
9187 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9188 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9189
9190 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9191
9192 /*
9193 * label has previously been automatically
9194 * assigned by labelpool: release it
9195 *
9196 * NB if tovpn_label == MPLS_LABEL_NONE it
9197 * means the automatic assignment is in flight
9198 * and therefore the labelpool callback must
9199 * detect that the auto label is not needed.
9200 */
9201
9202 bgp_lp_release(LP_TYPE_VRF,
9203 &bgp->vpn_policy[afi],
9204 bgp->vpn_policy[afi].tovpn_label);
9205 }
9206 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9207 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9208 }
9209
9210 bgp->vpn_policy[afi].tovpn_label = label;
9211 if (label_auto) {
9212 SET_FLAG(bgp->vpn_policy[afi].flags,
9213 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9214 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9215 vpn_leak_label_callback);
9216 }
9217
9218 /* post-change: re-export vpn routes */
9219 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9220 bgp_get_default(), bgp);
9221
9222 hook_call(bgp_snmp_update_last_changed, bgp);
9223 return CMD_SUCCESS;
9224 }
9225
9226 DEFPY (af_sid_vpn_export,
9227 af_sid_vpn_export_cmd,
9228 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9229 NO_STR
9230 "sid value for VRF\n"
9231 "Between current address-family and vpn\n"
9232 "For routes leaked from current address-family to vpn\n"
9233 "Sid allocation index\n"
9234 "Automatically assign a label\n")
9235 {
9236 VTY_DECLVAR_CONTEXT(bgp, bgp);
9237 afi_t afi;
9238 int debug = 0;
9239 int idx = 0;
9240 bool yes = true;
9241
9242 if (argv_find(argv, argc, "no", &idx))
9243 yes = false;
9244 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9245 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9246
9247 afi = vpn_policy_getafi(vty, bgp, false);
9248 if (afi == AFI_MAX)
9249 return CMD_WARNING_CONFIG_FAILED;
9250
9251 if (!yes) {
9252 /* implement me */
9253 vty_out(vty, "It's not implemented\n");
9254 return CMD_WARNING_CONFIG_FAILED;
9255 }
9256
9257 if (bgp->tovpn_sid_index != 0 ||
9258 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9259 vty_out(vty,
9260 "per-vrf sid and per-af sid are mutually exclusive\n"
9261 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9262 return CMD_WARNING_CONFIG_FAILED;
9263 }
9264
9265 /* skip when it's already configured */
9266 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9267 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9268 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9269 return CMD_SUCCESS;
9270
9271 /*
9272 * mode change between sid_idx and sid_auto isn't supported.
9273 * user must negate sid vpn export when they want to change the mode
9274 */
9275 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9276 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9277 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9278 vty_out(vty, "it's already configured as %s.\n",
9279 sid_auto ? "auto-mode" : "idx-mode");
9280 return CMD_WARNING_CONFIG_FAILED;
9281 }
9282
9283 /* pre-change */
9284 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9285 bgp_get_default(), bgp);
9286
9287 if (sid_auto) {
9288 /* SID allocation auto-mode */
9289 if (debug)
9290 zlog_debug("%s: auto sid alloc.", __func__);
9291 SET_FLAG(bgp->vpn_policy[afi].flags,
9292 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9293 } else {
9294 /* SID allocation index-mode */
9295 if (debug)
9296 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9297 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9298 }
9299
9300 /* post-change */
9301 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9302 bgp_get_default(), bgp);
9303 return CMD_SUCCESS;
9304 }
9305
9306 DEFPY (bgp_sid_vpn_export,
9307 bgp_sid_vpn_export_cmd,
9308 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9309 NO_STR
9310 "sid value for VRF\n"
9311 "Between current vrf and vpn\n"
9312 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9313 "For routes leaked from current vrf to vpn\n"
9314 "Sid allocation index\n"
9315 "Automatically assign a label\n")
9316 {
9317 VTY_DECLVAR_CONTEXT(bgp, bgp);
9318 int debug;
9319
9320 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9321 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9322
9323 if (no) {
9324 /* when per-VRF SID is not set, do nothing */
9325 if (bgp->tovpn_sid_index == 0 &&
9326 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9327 return CMD_SUCCESS;
9328
9329 sid_idx = 0;
9330 sid_auto = false;
9331 bgp->tovpn_sid_index = 0;
9332 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9333 }
9334
9335 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9336 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9337 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9338 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9339 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9340 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9341 vty_out(vty,
9342 "per-vrf sid and per-af sid are mutually exclusive\n"
9343 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9344 return CMD_WARNING_CONFIG_FAILED;
9345 }
9346
9347 /* skip when it's already configured */
9348 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9349 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9350 return CMD_SUCCESS;
9351
9352 /*
9353 * mode change between sid_idx and sid_auto isn't supported.
9354 * user must negate sid vpn export when they want to change the mode
9355 */
9356 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9357 (sid_idx != 0 &&
9358 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9359 vty_out(vty, "it's already configured as %s.\n",
9360 sid_auto ? "auto-mode" : "idx-mode");
9361 return CMD_WARNING_CONFIG_FAILED;
9362 }
9363
9364 /* pre-change */
9365 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9366 bgp);
9367 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9368 bgp);
9369
9370 if (sid_auto) {
9371 /* SID allocation auto-mode */
9372 if (debug)
9373 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9374 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9375 } else if (sid_idx != 0) {
9376 /* SID allocation index-mode */
9377 if (debug)
9378 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9379 sid_idx);
9380 bgp->tovpn_sid_index = sid_idx;
9381 }
9382
9383 /* post-change */
9384 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9385 bgp);
9386 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9387 bgp_get_default(), bgp);
9388
9389 return CMD_SUCCESS;
9390 }
9391
9392 ALIAS (af_label_vpn_export,
9393 af_no_label_vpn_export_cmd,
9394 "no label vpn export",
9395 NO_STR
9396 "label value for VRF\n"
9397 "Between current address-family and vpn\n"
9398 "For routes leaked from current address-family to vpn\n")
9399
9400 ALIAS (bgp_sid_vpn_export,
9401 no_bgp_sid_vpn_export_cmd,
9402 "no$no sid vpn per-vrf export",
9403 NO_STR
9404 "sid value for VRF\n"
9405 "Between current vrf and vpn\n"
9406 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9407 "For routes leaked from current vrf to vpn\n")
9408
9409 DEFPY (af_nexthop_vpn_export,
9410 af_nexthop_vpn_export_cmd,
9411 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9412 NO_STR
9413 "Specify next hop to use for VRF advertised prefixes\n"
9414 "Between current address-family and vpn\n"
9415 "For routes leaked from current address-family to vpn\n"
9416 "IPv4 prefix\n"
9417 "IPv6 prefix\n")
9418 {
9419 VTY_DECLVAR_CONTEXT(bgp, bgp);
9420 afi_t afi;
9421 struct prefix p;
9422
9423 if (!no) {
9424 if (!nexthop_su) {
9425 vty_out(vty, "%% Nexthop required\n");
9426 return CMD_WARNING_CONFIG_FAILED;
9427 }
9428 if (!sockunion2hostprefix(nexthop_su, &p))
9429 return CMD_WARNING_CONFIG_FAILED;
9430 }
9431
9432 afi = vpn_policy_getafi(vty, bgp, false);
9433 if (afi == AFI_MAX)
9434 return CMD_WARNING_CONFIG_FAILED;
9435
9436 /*
9437 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9438 */
9439 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9440 bgp_get_default(), bgp);
9441
9442 if (!no) {
9443 bgp->vpn_policy[afi].tovpn_nexthop = p;
9444 SET_FLAG(bgp->vpn_policy[afi].flags,
9445 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9446 } else {
9447 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9448 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9449 }
9450
9451 /* post-change: re-export vpn routes */
9452 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9453 bgp_get_default(), bgp);
9454
9455 return CMD_SUCCESS;
9456 }
9457
9458 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9459 {
9460 if (!strcmp(dstr, "import")) {
9461 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9462 } else if (!strcmp(dstr, "export")) {
9463 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9464 } else if (!strcmp(dstr, "both")) {
9465 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9466 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9467 } else {
9468 vty_out(vty, "%% direction parse error\n");
9469 return CMD_WARNING_CONFIG_FAILED;
9470 }
9471 return CMD_SUCCESS;
9472 }
9473
9474 DEFPY (af_rt_vpn_imexport,
9475 af_rt_vpn_imexport_cmd,
9476 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9477 NO_STR
9478 "Specify route target list\n"
9479 "Specify route target list\n"
9480 "Between current address-family and vpn\n"
9481 "For routes leaked from vpn to current address-family: match any\n"
9482 "For routes leaked from current address-family to vpn: set\n"
9483 "both import: match any and export: set\n"
9484 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9485 {
9486 VTY_DECLVAR_CONTEXT(bgp, bgp);
9487 int ret;
9488 struct ecommunity *ecom = NULL;
9489 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9490 enum vpn_policy_direction dir;
9491 afi_t afi;
9492 int idx = 0;
9493 bool yes = true;
9494
9495 if (argv_find(argv, argc, "no", &idx))
9496 yes = false;
9497
9498 afi = vpn_policy_getafi(vty, bgp, false);
9499 if (afi == AFI_MAX)
9500 return CMD_WARNING_CONFIG_FAILED;
9501
9502 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9503 if (ret != CMD_SUCCESS)
9504 return ret;
9505
9506 if (yes) {
9507 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9508 vty_out(vty, "%% Missing RTLIST\n");
9509 return CMD_WARNING_CONFIG_FAILED;
9510 }
9511 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9512 if (ret != CMD_SUCCESS) {
9513 return ret;
9514 }
9515 }
9516
9517 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9518 if (!dodir[dir])
9519 continue;
9520
9521 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9522
9523 if (yes) {
9524 if (bgp->vpn_policy[afi].rtlist[dir])
9525 ecommunity_free(
9526 &bgp->vpn_policy[afi].rtlist[dir]);
9527 bgp->vpn_policy[afi].rtlist[dir] =
9528 ecommunity_dup(ecom);
9529 } else {
9530 if (bgp->vpn_policy[afi].rtlist[dir])
9531 ecommunity_free(
9532 &bgp->vpn_policy[afi].rtlist[dir]);
9533 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9534 }
9535
9536 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9537 }
9538
9539 if (ecom)
9540 ecommunity_free(&ecom);
9541
9542 return CMD_SUCCESS;
9543 }
9544
9545 ALIAS (af_rt_vpn_imexport,
9546 af_no_rt_vpn_imexport_cmd,
9547 "no <rt|route-target> vpn <import|export|both>$direction_str",
9548 NO_STR
9549 "Specify route target list\n"
9550 "Specify route target list\n"
9551 "Between current address-family and vpn\n"
9552 "For routes leaked from vpn to current address-family\n"
9553 "For routes leaked from current address-family to vpn\n"
9554 "both import and export\n")
9555
9556 DEFPY (af_route_map_vpn_imexport,
9557 af_route_map_vpn_imexport_cmd,
9558 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9559 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9560 NO_STR
9561 "Specify route map\n"
9562 "Between current address-family and vpn\n"
9563 "For routes leaked from vpn to current address-family\n"
9564 "For routes leaked from current address-family to vpn\n"
9565 "name of route-map\n")
9566 {
9567 VTY_DECLVAR_CONTEXT(bgp, bgp);
9568 int ret;
9569 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9570 enum vpn_policy_direction dir;
9571 afi_t afi;
9572 int idx = 0;
9573 bool yes = true;
9574
9575 if (argv_find(argv, argc, "no", &idx))
9576 yes = false;
9577
9578 afi = vpn_policy_getafi(vty, bgp, false);
9579 if (afi == AFI_MAX)
9580 return CMD_WARNING_CONFIG_FAILED;
9581
9582 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9583 if (ret != CMD_SUCCESS)
9584 return ret;
9585
9586 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9587 if (!dodir[dir])
9588 continue;
9589
9590 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9591
9592 if (yes) {
9593 if (bgp->vpn_policy[afi].rmap_name[dir])
9594 XFREE(MTYPE_ROUTE_MAP_NAME,
9595 bgp->vpn_policy[afi].rmap_name[dir]);
9596 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9597 MTYPE_ROUTE_MAP_NAME, rmap_str);
9598 bgp->vpn_policy[afi].rmap[dir] =
9599 route_map_lookup_warn_noexist(vty, rmap_str);
9600 if (!bgp->vpn_policy[afi].rmap[dir])
9601 return CMD_SUCCESS;
9602 } else {
9603 if (bgp->vpn_policy[afi].rmap_name[dir])
9604 XFREE(MTYPE_ROUTE_MAP_NAME,
9605 bgp->vpn_policy[afi].rmap_name[dir]);
9606 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9607 bgp->vpn_policy[afi].rmap[dir] = NULL;
9608 }
9609
9610 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9611 }
9612
9613 return CMD_SUCCESS;
9614 }
9615
9616 ALIAS (af_route_map_vpn_imexport,
9617 af_no_route_map_vpn_imexport_cmd,
9618 "no route-map vpn <import|export>$direction_str",
9619 NO_STR
9620 "Specify route map\n"
9621 "Between current address-family and vpn\n"
9622 "For routes leaked from vpn to current address-family\n"
9623 "For routes leaked from current address-family to vpn\n")
9624
9625 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9626 "import vrf route-map RMAP$rmap_str",
9627 "Import routes from another VRF\n"
9628 "Vrf routes being filtered\n"
9629 "Specify route map\n"
9630 "name of route-map\n")
9631 {
9632 VTY_DECLVAR_CONTEXT(bgp, bgp);
9633 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9634 afi_t afi;
9635 struct bgp *bgp_default;
9636
9637 afi = vpn_policy_getafi(vty, bgp, true);
9638 if (afi == AFI_MAX)
9639 return CMD_WARNING_CONFIG_FAILED;
9640
9641 bgp_default = bgp_get_default();
9642 if (!bgp_default) {
9643 int32_t ret;
9644 as_t as = bgp->as;
9645
9646 /* Auto-create assuming the same AS */
9647 ret = bgp_get_vty(&bgp_default, &as, NULL,
9648 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9649 ASNOTATION_UNDEFINED);
9650
9651 if (ret) {
9652 vty_out(vty,
9653 "VRF default is not configured as a bgp instance\n");
9654 return CMD_WARNING;
9655 }
9656 }
9657
9658 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9659
9660 if (bgp->vpn_policy[afi].rmap_name[dir])
9661 XFREE(MTYPE_ROUTE_MAP_NAME,
9662 bgp->vpn_policy[afi].rmap_name[dir]);
9663 bgp->vpn_policy[afi].rmap_name[dir] =
9664 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9665 bgp->vpn_policy[afi].rmap[dir] =
9666 route_map_lookup_warn_noexist(vty, rmap_str);
9667 if (!bgp->vpn_policy[afi].rmap[dir])
9668 return CMD_SUCCESS;
9669
9670 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9671 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9672
9673 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9674
9675 return CMD_SUCCESS;
9676 }
9677
9678 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9679 "no import vrf route-map [RMAP$rmap_str]",
9680 NO_STR
9681 "Import routes from another VRF\n"
9682 "Vrf routes being filtered\n"
9683 "Specify route map\n"
9684 "name of route-map\n")
9685 {
9686 VTY_DECLVAR_CONTEXT(bgp, bgp);
9687 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9688 afi_t afi;
9689
9690 afi = vpn_policy_getafi(vty, bgp, true);
9691 if (afi == AFI_MAX)
9692 return CMD_WARNING_CONFIG_FAILED;
9693
9694 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9695
9696 if (bgp->vpn_policy[afi].rmap_name[dir])
9697 XFREE(MTYPE_ROUTE_MAP_NAME,
9698 bgp->vpn_policy[afi].rmap_name[dir]);
9699 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9700 bgp->vpn_policy[afi].rmap[dir] = NULL;
9701
9702 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9703 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9704 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9705
9706 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9707
9708 return CMD_SUCCESS;
9709 }
9710
9711 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9712 "[no] import vrf VIEWVRFNAME$import_name",
9713 NO_STR
9714 "Import routes from another VRF\n"
9715 "VRF to import from\n"
9716 "The name of the VRF\n")
9717 {
9718 VTY_DECLVAR_CONTEXT(bgp, bgp);
9719 struct listnode *node;
9720 struct bgp *vrf_bgp, *bgp_default;
9721 int32_t ret = 0;
9722 as_t as = bgp->as;
9723 bool remove = false;
9724 int32_t idx = 0;
9725 char *vname;
9726 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9727 safi_t safi;
9728 afi_t afi;
9729
9730 if (import_name == NULL) {
9731 vty_out(vty, "%% Missing import name\n");
9732 return CMD_WARNING;
9733 }
9734
9735 if (strcmp(import_name, "route-map") == 0) {
9736 vty_out(vty, "%% Must include route-map name\n");
9737 return CMD_WARNING;
9738 }
9739
9740 if (argv_find(argv, argc, "no", &idx))
9741 remove = true;
9742
9743 afi = vpn_policy_getafi(vty, bgp, true);
9744 if (afi == AFI_MAX)
9745 return CMD_WARNING_CONFIG_FAILED;
9746
9747 safi = bgp_node_safi(vty);
9748
9749 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9750 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9751 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9752 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9753 remove ? "unimport" : "import", import_name);
9754 return CMD_WARNING;
9755 }
9756
9757 bgp_default = bgp_get_default();
9758 if (!bgp_default) {
9759 /* Auto-create assuming the same AS */
9760 ret = bgp_get_vty(&bgp_default, &as, NULL,
9761 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9762 ASNOTATION_UNDEFINED);
9763
9764 if (ret) {
9765 vty_out(vty,
9766 "VRF default is not configured as a bgp instance\n");
9767 return CMD_WARNING;
9768 }
9769 }
9770
9771 vrf_bgp = bgp_lookup_by_name(import_name);
9772 if (!vrf_bgp) {
9773 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9774 vrf_bgp = bgp_default;
9775 else
9776 /* Auto-create assuming the same AS */
9777 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
9778 NULL, ASNOTATION_UNDEFINED);
9779 if (ret) {
9780 vty_out(vty,
9781 "VRF %s is not configured as a bgp instance\n",
9782 import_name);
9783 return CMD_WARNING;
9784 }
9785 }
9786
9787 if (remove) {
9788 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9789 } else {
9790 /* Already importing from "import_vrf"? */
9791 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9792 vname)) {
9793 if (strcmp(vname, import_name) == 0)
9794 return CMD_WARNING;
9795 }
9796
9797 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9798 }
9799
9800 return CMD_SUCCESS;
9801 }
9802
9803 /* This command is valid only in a bgp vrf instance or the default instance */
9804 DEFPY (bgp_imexport_vpn,
9805 bgp_imexport_vpn_cmd,
9806 "[no] <import|export>$direction_str vpn",
9807 NO_STR
9808 "Import routes to this address-family\n"
9809 "Export routes from this address-family\n"
9810 "to/from default instance VPN RIB\n")
9811 {
9812 VTY_DECLVAR_CONTEXT(bgp, bgp);
9813 int previous_state;
9814 afi_t afi;
9815 safi_t safi;
9816 int idx = 0;
9817 bool yes = true;
9818 int flag;
9819 enum vpn_policy_direction dir;
9820
9821 if (argv_find(argv, argc, "no", &idx))
9822 yes = false;
9823
9824 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9825 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9826
9827 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9828 return CMD_WARNING_CONFIG_FAILED;
9829 }
9830
9831 afi = bgp_node_afi(vty);
9832 safi = bgp_node_safi(vty);
9833 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9834 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9835 return CMD_WARNING_CONFIG_FAILED;
9836 }
9837
9838 if (!strcmp(direction_str, "import")) {
9839 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9840 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9841 } else if (!strcmp(direction_str, "export")) {
9842 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9843 dir = BGP_VPN_POLICY_DIR_TOVPN;
9844 } else {
9845 vty_out(vty, "%% unknown direction %s\n", direction_str);
9846 return CMD_WARNING_CONFIG_FAILED;
9847 }
9848
9849 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9850
9851 if (yes) {
9852 SET_FLAG(bgp->af_flags[afi][safi], flag);
9853 if (!previous_state) {
9854 /* trigger export current vrf */
9855 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9856 }
9857 } else {
9858 if (previous_state) {
9859 /* trigger un-export current vrf */
9860 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9861 }
9862 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9863 }
9864
9865 hook_call(bgp_snmp_init_stats, bgp);
9866
9867 return CMD_SUCCESS;
9868 }
9869
9870 DEFPY (af_routetarget_import,
9871 af_routetarget_import_cmd,
9872 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9873 NO_STR
9874 "Specify route target list\n"
9875 "Specify route target list\n"
9876 "Specify route target list\n"
9877 "Specify route target list\n"
9878 "Flow-spec redirect type route target\n"
9879 "Import routes to this address-family\n"
9880 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9881 {
9882 VTY_DECLVAR_CONTEXT(bgp, bgp);
9883 int ret;
9884 struct ecommunity *ecom = NULL;
9885 afi_t afi;
9886 int idx = 0, idx_unused = 0;
9887 bool yes = true;
9888 bool rt6 = false;
9889
9890 if (argv_find(argv, argc, "no", &idx))
9891 yes = false;
9892
9893 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9894 argv_find(argv, argc, "route-target6", &idx_unused))
9895 rt6 = true;
9896
9897 afi = vpn_policy_getafi(vty, bgp, false);
9898 if (afi == AFI_MAX)
9899 return CMD_WARNING_CONFIG_FAILED;
9900
9901 if (rt6 && afi != AFI_IP6)
9902 return CMD_WARNING_CONFIG_FAILED;
9903
9904 if (yes) {
9905 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9906 vty_out(vty, "%% Missing RTLIST\n");
9907 return CMD_WARNING_CONFIG_FAILED;
9908 }
9909 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9910 if (ret != CMD_SUCCESS)
9911 return ret;
9912 }
9913
9914 if (yes) {
9915 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9916 ecommunity_free(&bgp->vpn_policy[afi]
9917 .import_redirect_rtlist);
9918 bgp->vpn_policy[afi].import_redirect_rtlist =
9919 ecommunity_dup(ecom);
9920 } else {
9921 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9922 ecommunity_free(&bgp->vpn_policy[afi]
9923 .import_redirect_rtlist);
9924 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9925 }
9926
9927 if (ecom)
9928 ecommunity_free(&ecom);
9929
9930 return CMD_SUCCESS;
9931 }
9932
9933 DEFUN_NOSH (address_family_ipv4_safi,
9934 address_family_ipv4_safi_cmd,
9935 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9936 "Enter Address Family command mode\n"
9937 BGP_AF_STR
9938 BGP_SAFI_WITH_LABEL_HELP_STR)
9939 {
9940
9941 if (argc == 3) {
9942 VTY_DECLVAR_CONTEXT(bgp, bgp);
9943 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9944 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9945 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9946 && safi != SAFI_EVPN) {
9947 vty_out(vty,
9948 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9949 return CMD_WARNING_CONFIG_FAILED;
9950 }
9951 vty->node = bgp_node_type(AFI_IP, safi);
9952 } else
9953 vty->node = BGP_IPV4_NODE;
9954
9955 return CMD_SUCCESS;
9956 }
9957
9958 DEFUN_NOSH (address_family_ipv6_safi,
9959 address_family_ipv6_safi_cmd,
9960 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9961 "Enter Address Family command mode\n"
9962 BGP_AF_STR
9963 BGP_SAFI_WITH_LABEL_HELP_STR)
9964 {
9965 if (argc == 3) {
9966 VTY_DECLVAR_CONTEXT(bgp, bgp);
9967 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9968 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9969 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9970 && safi != SAFI_EVPN) {
9971 vty_out(vty,
9972 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9973 return CMD_WARNING_CONFIG_FAILED;
9974 }
9975 vty->node = bgp_node_type(AFI_IP6, safi);
9976 } else
9977 vty->node = BGP_IPV6_NODE;
9978
9979 return CMD_SUCCESS;
9980 }
9981
9982 #ifdef KEEP_OLD_VPN_COMMANDS
9983 DEFUN_NOSH (address_family_vpnv4,
9984 address_family_vpnv4_cmd,
9985 "address-family vpnv4 [unicast]",
9986 "Enter Address Family command mode\n"
9987 BGP_AF_STR
9988 BGP_AF_MODIFIER_STR)
9989 {
9990 vty->node = BGP_VPNV4_NODE;
9991 return CMD_SUCCESS;
9992 }
9993
9994 DEFUN_NOSH (address_family_vpnv6,
9995 address_family_vpnv6_cmd,
9996 "address-family vpnv6 [unicast]",
9997 "Enter Address Family command mode\n"
9998 BGP_AF_STR
9999 BGP_AF_MODIFIER_STR)
10000 {
10001 vty->node = BGP_VPNV6_NODE;
10002 return CMD_SUCCESS;
10003 }
10004 #endif /* KEEP_OLD_VPN_COMMANDS */
10005
10006 DEFUN_NOSH (address_family_evpn,
10007 address_family_evpn_cmd,
10008 "address-family l2vpn evpn",
10009 "Enter Address Family command mode\n"
10010 BGP_AF_STR
10011 BGP_AF_MODIFIER_STR)
10012 {
10013 VTY_DECLVAR_CONTEXT(bgp, bgp);
10014 vty->node = BGP_EVPN_NODE;
10015 return CMD_SUCCESS;
10016 }
10017
10018 DEFUN_NOSH (bgp_segment_routing_srv6,
10019 bgp_segment_routing_srv6_cmd,
10020 "segment-routing srv6",
10021 "Segment-Routing configuration\n"
10022 "Segment-Routing SRv6 configuration\n")
10023 {
10024 VTY_DECLVAR_CONTEXT(bgp, bgp);
10025 bgp->srv6_enabled = true;
10026 vty->node = BGP_SRV6_NODE;
10027 return CMD_SUCCESS;
10028 }
10029
10030 DEFUN (no_bgp_segment_routing_srv6,
10031 no_bgp_segment_routing_srv6_cmd,
10032 "no segment-routing srv6",
10033 NO_STR
10034 "Segment-Routing configuration\n"
10035 "Segment-Routing SRv6 configuration\n")
10036 {
10037 VTY_DECLVAR_CONTEXT(bgp, bgp);
10038
10039 if (strlen(bgp->srv6_locator_name) > 0)
10040 if (bgp_srv6_locator_unset(bgp) < 0)
10041 return CMD_WARNING_CONFIG_FAILED;
10042
10043 bgp->srv6_enabled = false;
10044 return CMD_SUCCESS;
10045 }
10046
10047 DEFPY (bgp_srv6_locator,
10048 bgp_srv6_locator_cmd,
10049 "locator NAME$name",
10050 "Specify SRv6 locator\n"
10051 "Specify SRv6 locator\n")
10052 {
10053 VTY_DECLVAR_CONTEXT(bgp, bgp);
10054 int ret;
10055
10056 if (strlen(bgp->srv6_locator_name) > 0
10057 && strcmp(name, bgp->srv6_locator_name) != 0) {
10058 vty_out(vty, "srv6 locator is already configured\n");
10059 return CMD_WARNING_CONFIG_FAILED;
10060 }
10061
10062 snprintf(bgp->srv6_locator_name,
10063 sizeof(bgp->srv6_locator_name), "%s", name);
10064
10065 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
10066 if (ret < 0)
10067 return CMD_WARNING_CONFIG_FAILED;
10068
10069 return CMD_SUCCESS;
10070 }
10071
10072 DEFPY (no_bgp_srv6_locator,
10073 no_bgp_srv6_locator_cmd,
10074 "no locator NAME$name",
10075 NO_STR
10076 "Specify SRv6 locator\n"
10077 "Specify SRv6 locator\n")
10078 {
10079 VTY_DECLVAR_CONTEXT(bgp, bgp);
10080
10081 /* when locator isn't configured, do nothing */
10082 if (strlen(bgp->srv6_locator_name) < 1)
10083 return CMD_SUCCESS;
10084
10085 /* name validation */
10086 if (strcmp(name, bgp->srv6_locator_name) != 0) {
10087 vty_out(vty, "%% No srv6 locator is configured\n");
10088 return CMD_WARNING_CONFIG_FAILED;
10089 }
10090
10091 /* unset locator */
10092 if (bgp_srv6_locator_unset(bgp) < 0)
10093 return CMD_WARNING_CONFIG_FAILED;
10094
10095 return CMD_SUCCESS;
10096 }
10097
10098 DEFPY (show_bgp_srv6,
10099 show_bgp_srv6_cmd,
10100 "show bgp segment-routing srv6",
10101 SHOW_STR
10102 BGP_STR
10103 "BGP Segment Routing\n"
10104 "BGP Segment Routing SRv6\n")
10105 {
10106 struct bgp *bgp;
10107 struct listnode *node;
10108 struct srv6_locator_chunk *chunk;
10109 struct bgp_srv6_function *func;
10110
10111 bgp = bgp_get_default();
10112 if (!bgp)
10113 return CMD_SUCCESS;
10114
10115 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10116 vty_out(vty, "locator_chunks:\n");
10117 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
10118 vty_out(vty, "- %pFX\n", &chunk->prefix);
10119 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10120 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10121 vty_out(vty, " func-length: %d\n",
10122 chunk->function_bits_length);
10123 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10124 }
10125
10126 vty_out(vty, "functions:\n");
10127 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
10128 vty_out(vty, "- sid: %pI6\n", &func->sid);
10129 vty_out(vty, " locator: %s\n", func->locator_name);
10130 }
10131
10132 vty_out(vty, "bgps:\n");
10133 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10134 vty_out(vty, "- name: %s\n",
10135 bgp->name ? bgp->name : "default");
10136
10137 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10138 bgp->vpn_policy[AFI_IP].tovpn_sid);
10139 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10140 bgp->vpn_policy[AFI_IP6].tovpn_sid);
10141 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
10142 }
10143
10144 return CMD_SUCCESS;
10145 }
10146
10147 DEFUN_NOSH (exit_address_family,
10148 exit_address_family_cmd,
10149 "exit-address-family",
10150 "Exit from Address Family configuration mode\n")
10151 {
10152 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10153 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10154 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10155 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
10156 || vty->node == BGP_EVPN_NODE
10157 || vty->node == BGP_FLOWSPECV4_NODE
10158 || vty->node == BGP_FLOWSPECV6_NODE)
10159 vty->node = BGP_NODE;
10160 return CMD_SUCCESS;
10161 }
10162
10163 /* Recalculate bestpath and re-advertise a prefix */
10164 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10165 const char *ip_str, afi_t afi, safi_t safi,
10166 struct prefix_rd *prd)
10167 {
10168 int ret;
10169 struct prefix match;
10170 struct bgp_dest *dest;
10171 struct bgp_dest *rm;
10172 struct bgp *bgp;
10173 struct bgp_table *table;
10174 struct bgp_table *rib;
10175
10176 /* BGP structure lookup. */
10177 if (view_name) {
10178 bgp = bgp_lookup_by_name(view_name);
10179 if (bgp == NULL) {
10180 vty_out(vty, "%% Can't find BGP instance %s\n",
10181 view_name);
10182 return CMD_WARNING;
10183 }
10184 } else {
10185 bgp = bgp_get_default();
10186 if (bgp == NULL) {
10187 vty_out(vty, "%% No BGP process is configured\n");
10188 return CMD_WARNING;
10189 }
10190 }
10191
10192 /* Check IP address argument. */
10193 ret = str2prefix(ip_str, &match);
10194 if (!ret) {
10195 vty_out(vty, "%% address is malformed\n");
10196 return CMD_WARNING;
10197 }
10198
10199 match.family = afi2family(afi);
10200 rib = bgp->rib[afi][safi];
10201
10202 if (safi == SAFI_MPLS_VPN) {
10203 for (dest = bgp_table_top(rib); dest;
10204 dest = bgp_route_next(dest)) {
10205 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10206
10207 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10208 continue;
10209
10210 table = bgp_dest_get_bgp_table_info(dest);
10211 if (table == NULL)
10212 continue;
10213
10214 rm = bgp_node_match(table, &match);
10215 if (rm != NULL) {
10216 const struct prefix *rm_p =
10217 bgp_dest_get_prefix(rm);
10218
10219 if (rm_p->prefixlen == match.prefixlen) {
10220 SET_FLAG(rm->flags,
10221 BGP_NODE_USER_CLEAR);
10222 bgp_process(bgp, rm, afi, safi);
10223 }
10224 bgp_dest_unlock_node(rm);
10225 }
10226 }
10227 } else {
10228 dest = bgp_node_match(rib, &match);
10229 if (dest != NULL) {
10230 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10231
10232 if (dest_p->prefixlen == match.prefixlen) {
10233 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10234 bgp_process(bgp, dest, afi, safi);
10235 }
10236 bgp_dest_unlock_node(dest);
10237 }
10238 }
10239
10240 return CMD_SUCCESS;
10241 }
10242
10243 /* one clear bgp command to rule them all */
10244 DEFUN (clear_ip_bgp_all,
10245 clear_ip_bgp_all_cmd,
10246 "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|ASNUM|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
10247 CLEAR_STR
10248 IP_STR
10249 BGP_STR
10250 BGP_INSTANCE_HELP_STR
10251 BGP_AFI_HELP_STR
10252 BGP_AF_STR
10253 BGP_SAFI_WITH_LABEL_HELP_STR
10254 BGP_AF_MODIFIER_STR
10255 "Clear all peers\n"
10256 "BGP IPv4 neighbor to clear\n"
10257 "BGP IPv6 neighbor to clear\n"
10258 "BGP neighbor on interface to clear\n"
10259 "Clear peers with the AS number in plain or dotted format\n"
10260 "Clear all external peers\n"
10261 "Clear all members of peer-group\n"
10262 "BGP peer-group name\n"
10263 BGP_SOFT_STR
10264 BGP_SOFT_IN_STR
10265 BGP_SOFT_OUT_STR
10266 BGP_SOFT_IN_STR
10267 "Push out prefix-list ORF and do inbound soft reconfig\n"
10268 BGP_SOFT_OUT_STR
10269 "Reset message statistics\n")
10270 {
10271 char *vrf = NULL;
10272
10273 afi_t afi = AFI_UNSPEC;
10274 safi_t safi = SAFI_UNSPEC;
10275 enum clear_sort clr_sort = clear_peer;
10276 enum bgp_clear_type clr_type;
10277 char *clr_arg = NULL;
10278
10279 int idx = 0;
10280
10281 /* clear [ip] bgp */
10282 if (argv_find(argv, argc, "ip", &idx))
10283 afi = AFI_IP;
10284
10285 /* [<vrf> VIEWVRFNAME] */
10286 if (argv_find(argv, argc, "vrf", &idx)) {
10287 vrf = argv[idx + 1]->arg;
10288 idx += 2;
10289 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10290 vrf = NULL;
10291 } else if (argv_find(argv, argc, "view", &idx)) {
10292 /* [<view> VIEWVRFNAME] */
10293 vrf = argv[idx + 1]->arg;
10294 idx += 2;
10295 }
10296 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10297 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10298 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10299
10300 /* <*|A.B.C.D|X:X::X:X|WORD|ASNUM|external|peer-group PGNAME> */
10301 if (argv_find(argv, argc, "*", &idx)) {
10302 clr_sort = clear_all;
10303 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10304 clr_sort = clear_peer;
10305 clr_arg = argv[idx]->arg;
10306 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10307 clr_sort = clear_peer;
10308 clr_arg = argv[idx]->arg;
10309 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10310 clr_sort = clear_group;
10311 idx++;
10312 clr_arg = argv[idx]->arg;
10313 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10314 clr_sort = clear_peer;
10315 clr_arg = argv[idx]->arg;
10316 } else if (argv_find(argv, argc, "WORD", &idx)) {
10317 clr_sort = clear_peer;
10318 clr_arg = argv[idx]->arg;
10319 } else if (argv_find(argv, argc, "ASNUM", &idx)) {
10320 clr_sort = clear_as;
10321 clr_arg = argv[idx]->arg;
10322 } else if (argv_find(argv, argc, "external", &idx)) {
10323 clr_sort = clear_external;
10324 }
10325
10326 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10327 if (argv_find(argv, argc, "soft", &idx)) {
10328 if (argv_find(argv, argc, "in", &idx)
10329 || argv_find(argv, argc, "out", &idx))
10330 clr_type = strmatch(argv[idx]->text, "in")
10331 ? BGP_CLEAR_SOFT_IN
10332 : BGP_CLEAR_SOFT_OUT;
10333 else
10334 clr_type = BGP_CLEAR_SOFT_BOTH;
10335 } else if (argv_find(argv, argc, "in", &idx)) {
10336 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10337 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10338 : BGP_CLEAR_SOFT_IN;
10339 } else if (argv_find(argv, argc, "out", &idx)) {
10340 clr_type = BGP_CLEAR_SOFT_OUT;
10341 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10342 clr_type = BGP_CLEAR_MESSAGE_STATS;
10343 } else
10344 clr_type = BGP_CLEAR_SOFT_NONE;
10345
10346 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10347 }
10348
10349 DEFUN (clear_ip_bgp_prefix,
10350 clear_ip_bgp_prefix_cmd,
10351 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10352 CLEAR_STR
10353 IP_STR
10354 BGP_STR
10355 BGP_INSTANCE_HELP_STR
10356 "Clear bestpath and re-advertise\n"
10357 "IPv4 prefix\n")
10358 {
10359 char *vrf = NULL;
10360 char *prefix = NULL;
10361
10362 int idx = 0;
10363
10364 /* [<view|vrf> VIEWVRFNAME] */
10365 if (argv_find(argv, argc, "vrf", &idx)) {
10366 vrf = argv[idx + 1]->arg;
10367 idx += 2;
10368 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10369 vrf = NULL;
10370 } else if (argv_find(argv, argc, "view", &idx)) {
10371 /* [<view> VIEWVRFNAME] */
10372 vrf = argv[idx + 1]->arg;
10373 idx += 2;
10374 }
10375
10376 prefix = argv[argc - 1]->arg;
10377
10378 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10379 }
10380
10381 DEFUN (clear_bgp_ipv6_safi_prefix,
10382 clear_bgp_ipv6_safi_prefix_cmd,
10383 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10384 CLEAR_STR
10385 IP_STR
10386 BGP_STR
10387 BGP_AF_STR
10388 BGP_SAFI_HELP_STR
10389 "Clear bestpath and re-advertise\n"
10390 "IPv6 prefix\n")
10391 {
10392 int idx_safi = 0;
10393 int idx_ipv6_prefix = 0;
10394 safi_t safi = SAFI_UNICAST;
10395 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10396 argv[idx_ipv6_prefix]->arg : NULL;
10397
10398 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10399 return bgp_clear_prefix(
10400 vty, NULL, prefix, AFI_IP6,
10401 safi, NULL);
10402 }
10403
10404 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10405 clear_bgp_instance_ipv6_safi_prefix_cmd,
10406 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10407 CLEAR_STR
10408 IP_STR
10409 BGP_STR
10410 BGP_INSTANCE_HELP_STR
10411 BGP_AF_STR
10412 BGP_SAFI_HELP_STR
10413 "Clear bestpath and re-advertise\n"
10414 "IPv6 prefix\n")
10415 {
10416 int idx_safi = 0;
10417 int idx_vrfview = 0;
10418 int idx_ipv6_prefix = 0;
10419 safi_t safi = SAFI_UNICAST;
10420 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10421 argv[idx_ipv6_prefix]->arg : NULL;
10422 char *vrfview = NULL;
10423
10424 /* [<view|vrf> VIEWVRFNAME] */
10425 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10426 vrfview = argv[idx_vrfview + 1]->arg;
10427 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10428 vrfview = NULL;
10429 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10430 /* [<view> VIEWVRFNAME] */
10431 vrfview = argv[idx_vrfview + 1]->arg;
10432 }
10433 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10434
10435 return bgp_clear_prefix(
10436 vty, vrfview, prefix,
10437 AFI_IP6, safi, NULL);
10438 }
10439
10440 DEFUN (show_bgp_views,
10441 show_bgp_views_cmd,
10442 "show [ip] bgp views",
10443 SHOW_STR
10444 IP_STR
10445 BGP_STR
10446 "Show the defined BGP views\n")
10447 {
10448 struct list *inst = bm->bgp;
10449 struct listnode *node;
10450 struct bgp *bgp;
10451
10452 vty_out(vty, "Defined BGP views:\n");
10453 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10454 /* Skip VRFs. */
10455 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10456 continue;
10457 vty_out(vty, "\t%s (AS%s)\n", bgp->name ? bgp->name : "(null)",
10458 bgp->as_pretty);
10459 }
10460
10461 return CMD_SUCCESS;
10462 }
10463
10464 static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10465 int *peers_estbd)
10466 {
10467 struct peer *peer;
10468 struct listnode *node;
10469
10470 *peers_cfgd = *peers_estbd = 0;
10471 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10472 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10473 continue;
10474 (*peers_cfgd)++;
10475 if (peer_established(peer))
10476 (*peers_estbd)++;
10477 }
10478 }
10479
10480 static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10481 const char *type)
10482 {
10483 int peers_cfg, peers_estb;
10484
10485 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10486
10487 if (json) {
10488 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10489 ? -1
10490 : (int64_t)bgp->vrf_id;
10491 json_object_string_add(json, "type", type);
10492 json_object_int_add(json, "vrfId", vrf_id_ui);
10493 json_object_string_addf(json, "routerId", "%pI4",
10494 &bgp->router_id);
10495 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10496 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10497 json_object_int_add(json, "l3vni", bgp->l3vni);
10498 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10499 json_object_string_add(
10500 json, "interface",
10501 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10502 }
10503 }
10504
10505 static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10506 json_object *json, const char *name,
10507 const char *type, bool use_vrf)
10508 {
10509 int peers_cfg, peers_estb;
10510
10511 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10512
10513 if (use_vrf) {
10514 if (json) {
10515 print_bgp_vrfs(bgp, vty, json, type);
10516 } else {
10517 vty_out(vty, "BGP instance %s VRF id %d\n",
10518 bgp->name_pretty,
10519 bgp->vrf_id == VRF_UNKNOWN ? -1
10520 : (int)bgp->vrf_id);
10521 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10522 vty_out(vty,
10523 "Num Configured Peers %d, Established %d\n",
10524 peers_cfg, peers_estb);
10525 if (bgp->l3vni) {
10526 vty_out(vty,
10527 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10528 bgp->l3vni,
10529 ifindex2ifname(bgp->l3vni_svi_ifindex,
10530 bgp->vrf_id),
10531 &bgp->rmac);
10532 }
10533 }
10534 } else {
10535 if (json) {
10536 print_bgp_vrfs(bgp, vty, json, type);
10537 } else {
10538 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10539 type,
10540 bgp->vrf_id == VRF_UNKNOWN ? -1
10541 : (int)bgp->vrf_id,
10542 &bgp->router_id, peers_cfg, peers_estb, name);
10543 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10544 bgp->l3vni, &bgp->rmac,
10545 ifindex2ifname(bgp->l3vni_svi_ifindex,
10546 bgp->vrf_id));
10547 }
10548 }
10549
10550 return CMD_SUCCESS;
10551 }
10552
10553 DEFPY (show_bgp_vrfs,
10554 show_bgp_vrfs_cmd,
10555 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10556 SHOW_STR
10557 IP_STR
10558 BGP_STR
10559 "Show BGP VRFs\n"
10560 "Specific VRF name\n"
10561 JSON_STR)
10562 {
10563 struct list *inst = bm->bgp;
10564 struct listnode *node;
10565 struct bgp *bgp;
10566 bool uj = use_json(argc, argv);
10567 json_object *json = NULL;
10568 json_object *json_vrfs = NULL;
10569 json_object *json_vrf = NULL;
10570 int count = 0;
10571 const char *name = vrf_name;
10572 const char *type;
10573
10574 if (uj)
10575 json = json_object_new_object();
10576
10577 if (name) {
10578 if (strmatch(name, VRF_DEFAULT_NAME)) {
10579 bgp = bgp_get_default();
10580 type = "DFLT";
10581 } else {
10582 bgp = bgp_lookup_by_name(name);
10583 type = "VRF";
10584 }
10585 if (!bgp) {
10586 if (uj)
10587 vty_json(vty, json);
10588 else
10589 vty_out(vty,
10590 "%% Specified BGP instance not found\n");
10591
10592 return CMD_WARNING;
10593 }
10594 }
10595
10596 if (vrf_name) {
10597 if (uj)
10598 json_vrf = json_object_new_object();
10599
10600 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10601 true);
10602
10603 if (uj) {
10604 json_object_object_add(json, name, json_vrf);
10605 vty_json(vty, json);
10606 }
10607
10608 return CMD_SUCCESS;
10609 }
10610
10611 if (uj)
10612 json_vrfs = json_object_new_object();
10613
10614 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10615 const char *name;
10616
10617 /* Skip Views. */
10618 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10619 continue;
10620
10621 count++;
10622 if (!uj && count == 1) {
10623 vty_out(vty,
10624 "%4s %-5s %-16s %9s %10s %-37s\n",
10625 "Type", "Id", "routerId", "#PeersCfg",
10626 "#PeersEstb", "Name");
10627 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10628 "L3-VNI", "RouterMAC", "Interface");
10629 }
10630 if (uj)
10631 json_vrf = json_object_new_object();
10632
10633 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10634 name = VRF_DEFAULT_NAME;
10635 type = "DFLT";
10636 } else {
10637 name = bgp->name;
10638 type = "VRF";
10639 }
10640
10641 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10642 false);
10643
10644 if (uj)
10645 json_object_object_add(json_vrfs, name, json_vrf);
10646 }
10647
10648 if (uj) {
10649 json_object_object_add(json, "vrfs", json_vrfs);
10650 json_object_int_add(json, "totalVrfs", count);
10651 vty_json(vty, json);
10652 } else {
10653 if (count)
10654 vty_out(vty,
10655 "\nTotal number of VRFs (including default): %d\n",
10656 count);
10657 }
10658
10659 return CMD_SUCCESS;
10660 }
10661
10662 DEFUN (show_bgp_mac_hash,
10663 show_bgp_mac_hash_cmd,
10664 "show bgp mac hash",
10665 SHOW_STR
10666 BGP_STR
10667 "Mac Address\n"
10668 "Mac Address database\n")
10669 {
10670 bgp_mac_dump_table(vty);
10671
10672 return CMD_SUCCESS;
10673 }
10674
10675 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10676 {
10677 struct vty *vty = (struct vty *)args;
10678 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10679
10680 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10681 }
10682
10683 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10684 {
10685 vty_out(vty, "self nexthop database:\n");
10686 bgp_nexthop_show_address_hash(vty, bgp);
10687
10688 vty_out(vty, "Tunnel-ip database:\n");
10689 hash_iterate(bgp->tip_hash,
10690 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10691 vty);
10692 }
10693
10694 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10695 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10696 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10697 "martian next-hops\n"
10698 "martian next-hop database\n")
10699 {
10700 struct bgp *bgp = NULL;
10701 int idx = 0;
10702 char *name = NULL;
10703
10704 /* [<vrf> VIEWVRFNAME] */
10705 if (argv_find(argv, argc, "vrf", &idx)) {
10706 name = argv[idx + 1]->arg;
10707 if (name && strmatch(name, VRF_DEFAULT_NAME))
10708 name = NULL;
10709 } else if (argv_find(argv, argc, "view", &idx))
10710 /* [<view> VIEWVRFNAME] */
10711 name = argv[idx + 1]->arg;
10712 if (name)
10713 bgp = bgp_lookup_by_name(name);
10714 else
10715 bgp = bgp_get_default();
10716
10717 if (!bgp) {
10718 vty_out(vty, "%% No BGP process is configured\n");
10719 return CMD_WARNING;
10720 }
10721 bgp_show_martian_nexthops(vty, bgp);
10722
10723 return CMD_SUCCESS;
10724 }
10725
10726 DEFUN (show_bgp_memory,
10727 show_bgp_memory_cmd,
10728 "show [ip] bgp memory",
10729 SHOW_STR
10730 IP_STR
10731 BGP_STR
10732 "Global BGP memory statistics\n")
10733 {
10734 char memstrbuf[MTYPE_MEMSTR_LEN];
10735 unsigned long count;
10736
10737 /* RIB related usage stats */
10738 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10739 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10740 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10741 count * sizeof(struct bgp_dest)));
10742
10743 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10744 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10746 count * sizeof(struct bgp_path_info)));
10747 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10748 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10749 count,
10750 mtype_memstr(
10751 memstrbuf, sizeof(memstrbuf),
10752 count * sizeof(struct bgp_path_info_extra)));
10753
10754 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10755 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10756 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10757 count * sizeof(struct bgp_static)));
10758
10759 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10760 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10761 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10762 count * sizeof(struct bpacket)));
10763
10764 /* Adj-In/Out */
10765 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10766 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10767 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10768 count * sizeof(struct bgp_adj_in)));
10769 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10770 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10771 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10772 count * sizeof(struct bgp_adj_out)));
10773
10774 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10775 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10776 count,
10777 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10778 count * sizeof(struct bgp_nexthop_cache)));
10779
10780 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10781 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10782 count,
10783 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10784 count * sizeof(struct bgp_damp_info)));
10785
10786 /* Attributes */
10787 count = attr_count();
10788 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10789 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10790 count * sizeof(struct attr)));
10791
10792 if ((count = attr_unknown_count()))
10793 vty_out(vty, "%ld unknown attributes\n", count);
10794
10795 /* AS_PATH attributes */
10796 count = aspath_count();
10797 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10798 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10799 count * sizeof(struct aspath)));
10800
10801 count = mtype_stats_alloc(MTYPE_AS_SEG);
10802 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10803 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10804 count * sizeof(struct assegment)));
10805
10806 /* Other attributes */
10807 if ((count = community_count()))
10808 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10809 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10810 count * sizeof(struct community)));
10811 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10812 vty_out(vty,
10813 "%ld BGP ext-community entries, using %s of memory\n",
10814 count,
10815 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10816 count * sizeof(struct ecommunity)));
10817 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10818 vty_out(vty,
10819 "%ld BGP large-community entries, using %s of memory\n",
10820 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10821 count * sizeof(struct lcommunity)));
10822
10823 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10824 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10825 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10826 count * sizeof(struct cluster_list)));
10827
10828 /* Peer related usage */
10829 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10830 vty_out(vty, "%ld peers, using %s of memory\n", count,
10831 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10832 count * sizeof(struct peer)));
10833
10834 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10835 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10836 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10837 count * sizeof(struct peer_group)));
10838
10839 /* Other */
10840 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10841 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10842 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10843 count * sizeof(regex_t)));
10844 return CMD_SUCCESS;
10845 }
10846
10847 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10848 {
10849 json_object *bestpath = json_object_new_object();
10850
10851 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10852 json_object_string_add(bestpath, "asPath", "ignore");
10853
10854 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10855 json_object_string_add(bestpath, "asPath", "confed");
10856
10857 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10858 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10859 json_object_string_add(bestpath, "multiPathRelax",
10860 "as-set");
10861 else
10862 json_object_string_add(bestpath, "multiPathRelax",
10863 "true");
10864 } else
10865 json_object_string_add(bestpath, "multiPathRelax", "false");
10866
10867 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10868 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10869
10870 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10871 json_object_string_add(bestpath, "compareRouterId", "true");
10872 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10873 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10874 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10875 json_object_string_add(bestpath, "med", "confed");
10876 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10877 json_object_string_add(bestpath, "med",
10878 "missing-as-worst");
10879 else
10880 json_object_string_add(bestpath, "med", "true");
10881 }
10882
10883 json_object_object_add(json, "bestPath", bestpath);
10884 }
10885
10886 /* Print the error code/subcode for why the peer is down */
10887 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10888 json_object *json_peer, bool use_json)
10889 {
10890 const char *code_str;
10891 const char *subcode_str;
10892
10893 if (use_json) {
10894 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10895 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10896 char errorcodesubcode_hexstr[5];
10897 char errorcodesubcode_str[256];
10898
10899 code_str = bgp_notify_code_str(peer->notify.code);
10900 subcode_str = bgp_notify_subcode_str(
10901 peer->notify.code,
10902 peer->notify.subcode);
10903
10904 snprintf(errorcodesubcode_hexstr,
10905 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10906 peer->notify.code, peer->notify.subcode);
10907 json_object_string_add(json_peer,
10908 "lastErrorCodeSubcode",
10909 errorcodesubcode_hexstr);
10910 snprintf(errorcodesubcode_str, 255, "%s%s",
10911 code_str, subcode_str);
10912 json_object_string_add(json_peer,
10913 "lastNotificationReason",
10914 errorcodesubcode_str);
10915 json_object_boolean_add(json_peer,
10916 "lastNotificationHardReset",
10917 peer->notify.hard_reset);
10918 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10919 && peer->notify.code == BGP_NOTIFY_CEASE
10920 && (peer->notify.subcode
10921 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10922 || peer->notify.subcode
10923 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10924 && peer->notify.length) {
10925 char msgbuf[1024];
10926 const char *msg_str;
10927
10928 msg_str = bgp_notify_admin_message(
10929 msgbuf, sizeof(msgbuf),
10930 (uint8_t *)peer->notify.data,
10931 peer->notify.length);
10932 if (msg_str)
10933 json_object_string_add(
10934 json_peer,
10935 "lastShutdownDescription",
10936 msg_str);
10937 }
10938
10939 }
10940 json_object_string_add(json_peer, "lastResetDueTo",
10941 peer_down_str[(int)peer->last_reset]);
10942 json_object_int_add(json_peer, "lastResetCode",
10943 peer->last_reset);
10944 json_object_string_add(json_peer, "softwareVersion",
10945 peer->soft_version ? peer->soft_version
10946 : "n/a");
10947 } else {
10948 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10949 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10950 code_str = bgp_notify_code_str(peer->notify.code);
10951 subcode_str =
10952 bgp_notify_subcode_str(peer->notify.code,
10953 peer->notify.subcode);
10954 vty_out(vty, " Notification %s (%s%s%s)\n",
10955 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10956 ? "sent"
10957 : "received",
10958 code_str, subcode_str,
10959 peer->notify.hard_reset
10960 ? bgp_notify_subcode_str(
10961 BGP_NOTIFY_CEASE,
10962 BGP_NOTIFY_CEASE_HARD_RESET)
10963 : "");
10964 } else {
10965 vty_out(vty, " %s (%s)\n",
10966 peer_down_str[(int)peer->last_reset],
10967 peer->soft_version ? peer->soft_version
10968 : "n/a");
10969 }
10970 }
10971 }
10972
10973 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10974 safi_t safi)
10975 {
10976 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10977 }
10978
10979 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10980 struct peer *peer, json_object *json_peer,
10981 int max_neighbor_width, bool use_json)
10982 {
10983 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10984 int len;
10985
10986 if (use_json) {
10987 if (peer_dynamic_neighbor(peer))
10988 json_object_boolean_true_add(json_peer,
10989 "dynamicPeer");
10990 if (peer->hostname)
10991 json_object_string_add(json_peer, "hostname",
10992 peer->hostname);
10993
10994 if (peer->domainname)
10995 json_object_string_add(json_peer, "domainname",
10996 peer->domainname);
10997 json_object_int_add(json_peer, "connectionsEstablished",
10998 peer->established);
10999 json_object_int_add(json_peer, "connectionsDropped",
11000 peer->dropped);
11001 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11002 use_json, json_peer);
11003 if (peer_established(peer))
11004 json_object_string_add(json_peer, "lastResetDueTo",
11005 "AFI/SAFI Not Negotiated");
11006 else
11007 bgp_show_peer_reset(NULL, peer, json_peer, true);
11008 } else {
11009 dn_flag[1] = '\0';
11010 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
11011 if (peer->hostname
11012 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
11013 len = vty_out(vty, "%s%s(%s)", dn_flag,
11014 peer->hostname, peer->host);
11015 else
11016 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11017
11018 /* pad the neighbor column with spaces */
11019 if (len < max_neighbor_width)
11020 vty_out(vty, "%*s", max_neighbor_width - len,
11021 " ");
11022 vty_out(vty, "%7d %7d %9s", peer->established,
11023 peer->dropped,
11024 peer_uptime(peer->uptime, timebuf,
11025 BGP_UPTIME_LEN, 0, NULL));
11026 if (peer_established(peer))
11027 vty_out(vty, " AFI/SAFI Not Negotiated\n");
11028 else
11029 bgp_show_peer_reset(vty, peer, NULL,
11030 false);
11031 }
11032 }
11033
11034 /* Strip peer's description to the given size. */
11035 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
11036 {
11037 static char stripped[BUFSIZ];
11038 uint32_t i = 0;
11039 uint32_t last_space = 0;
11040
11041 while (i < size) {
11042 if (*(desc + i) == 0) {
11043 stripped[i] = '\0';
11044 return stripped;
11045 }
11046 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
11047 last_space = i;
11048 stripped[i] = *(desc + i);
11049 i++;
11050 }
11051
11052 if (last_space > size)
11053 stripped[size + 1] = '\0';
11054 else
11055 stripped[last_space] = '\0';
11056
11057 return stripped;
11058 }
11059
11060 /* Determine whether var peer should be filtered out of the summary. */
11061 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
11062 struct peer *fpeer, int as_type,
11063 as_t as)
11064 {
11065
11066 /* filter neighbor XXXX */
11067 if (fpeer && fpeer != peer)
11068 return true;
11069
11070 /* filter remote-as (internal|external) */
11071 if (as_type != AS_UNSPECIFIED) {
11072 if (peer->as_type == AS_SPECIFIED) {
11073 if (as_type == AS_INTERNAL) {
11074 if (peer->as != peer->local_as)
11075 return true;
11076 } else if (peer->as == peer->local_as)
11077 return true;
11078 } else if (as_type != peer->as_type)
11079 return true;
11080 } else if (as && as != peer->as) /* filter remote-as XXX */
11081 return true;
11082
11083 return false;
11084 }
11085
11086 /* Show BGP peer's summary information.
11087 *
11088 * Peer's description is stripped according to if `wide` option is given
11089 * or not.
11090 *
11091 * When adding new columns to `show bgp summary` output, please make
11092 * sure `Desc` is the lastest column to show because it can contain
11093 * whitespaces and the whole output will be tricky.
11094 */
11095 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
11096 struct peer *fpeer, int as_type, as_t as,
11097 uint16_t show_flags)
11098 {
11099 struct peer *peer;
11100 struct listnode *node, *nnode;
11101 unsigned int count = 0, dn_count = 0;
11102 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11103 char neighbor_buf[VTY_BUFSIZ];
11104 int neighbor_col_default_width = 16;
11105 int len, failed_count = 0;
11106 unsigned int filtered_count = 0;
11107 int max_neighbor_width = 0;
11108 int pfx_rcd_safi;
11109 json_object *json = NULL;
11110 json_object *json_peer = NULL;
11111 json_object *json_peers = NULL;
11112 struct peer_af *paf;
11113 struct bgp_filter *filter;
11114 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11115 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11116 bool show_established =
11117 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11118 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11119 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11120
11121 /* labeled-unicast routes are installed in the unicast table so in order
11122 * to
11123 * display the correct PfxRcd value we must look at SAFI_UNICAST
11124 */
11125
11126 if (safi == SAFI_LABELED_UNICAST)
11127 pfx_rcd_safi = SAFI_UNICAST;
11128 else
11129 pfx_rcd_safi = safi;
11130
11131 if (use_json) {
11132 json = json_object_new_object();
11133 json_peers = json_object_new_object();
11134 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11135 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11136 as_type, as)) {
11137 filtered_count++;
11138 count++;
11139 continue;
11140 }
11141
11142 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11143 continue;
11144
11145 if (peer->afc[afi][safi]) {
11146 /* See if we have at least a single failed peer */
11147 if (bgp_has_peer_failed(peer, afi, safi))
11148 failed_count++;
11149 count++;
11150 }
11151 if (peer_dynamic_neighbor(peer))
11152 dn_count++;
11153 }
11154
11155 } else {
11156 /* Loop over all neighbors that will be displayed to determine
11157 * how many
11158 * characters are needed for the Neighbor column
11159 */
11160 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11161 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11162 as_type, as)) {
11163 filtered_count++;
11164 count++;
11165 continue;
11166 }
11167
11168 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11169 continue;
11170
11171 if (peer->afc[afi][safi]) {
11172 memset(dn_flag, '\0', sizeof(dn_flag));
11173 if (peer_dynamic_neighbor(peer))
11174 dn_flag[0] = '*';
11175
11176 if (peer->hostname
11177 && CHECK_FLAG(bgp->flags,
11178 BGP_FLAG_SHOW_HOSTNAME))
11179 snprintf(neighbor_buf,
11180 sizeof(neighbor_buf),
11181 "%s%s(%s) ", dn_flag,
11182 peer->hostname, peer->host);
11183 else
11184 snprintf(neighbor_buf,
11185 sizeof(neighbor_buf), "%s%s ",
11186 dn_flag, peer->host);
11187
11188 len = strlen(neighbor_buf);
11189
11190 if (len > max_neighbor_width)
11191 max_neighbor_width = len;
11192
11193 /* See if we have at least a single failed peer */
11194 if (bgp_has_peer_failed(peer, afi, safi))
11195 failed_count++;
11196 count++;
11197 }
11198 }
11199
11200 /* Originally we displayed the Neighbor column as 16
11201 * characters wide so make that the default
11202 */
11203 if (max_neighbor_width < neighbor_col_default_width)
11204 max_neighbor_width = neighbor_col_default_width;
11205 }
11206
11207 if (show_failed && !failed_count) {
11208 if (use_json) {
11209 json_object_int_add(json, "failedPeersCount", 0);
11210 json_object_int_add(json, "dynamicPeers", dn_count);
11211 json_object_int_add(json, "totalPeers", count);
11212
11213 vty_json(vty, json);
11214 } else {
11215 vty_out(vty, "%% No failed BGP neighbors found\n");
11216 }
11217 return CMD_SUCCESS;
11218 }
11219
11220 count = 0; /* Reset the value as its used again */
11221 filtered_count = 0;
11222 dn_count = 0;
11223 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11224 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11225 continue;
11226
11227 if (!peer->afc[afi][safi])
11228 continue;
11229
11230 if (!count) {
11231 unsigned long ents;
11232 char memstrbuf[MTYPE_MEMSTR_LEN];
11233 int64_t vrf_id_ui;
11234
11235 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11236 ? -1
11237 : (int64_t)bgp->vrf_id;
11238
11239 /* Usage summary and header */
11240 if (use_json) {
11241 json_object_string_addf(json, "routerId",
11242 "%pI4",
11243 &bgp->router_id);
11244 asn_asn2json(json, "as", bgp->as,
11245 bgp->asnotation);
11246 json_object_int_add(json, "vrfId", vrf_id_ui);
11247 json_object_string_add(
11248 json, "vrfName",
11249 (bgp->inst_type
11250 == BGP_INSTANCE_TYPE_DEFAULT)
11251 ? VRF_DEFAULT_NAME
11252 : bgp->name);
11253 } else {
11254 vty_out(vty,
11255 "BGP router identifier %pI4, local AS number %s vrf-id %d",
11256 &bgp->router_id, bgp->as_pretty,
11257 bgp->vrf_id == VRF_UNKNOWN
11258 ? -1
11259 : (int)bgp->vrf_id);
11260 vty_out(vty, "\n");
11261 }
11262
11263 if (bgp_update_delay_configured(bgp)) {
11264 if (use_json) {
11265 json_object_int_add(
11266 json, "updateDelayLimit",
11267 bgp->v_update_delay);
11268
11269 if (bgp->v_update_delay
11270 != bgp->v_establish_wait)
11271 json_object_int_add(
11272 json,
11273 "updateDelayEstablishWait",
11274 bgp->v_establish_wait);
11275
11276 if (bgp_update_delay_active(bgp)) {
11277 json_object_string_add(
11278 json,
11279 "updateDelayFirstNeighbor",
11280 bgp->update_delay_begin_time);
11281 json_object_boolean_true_add(
11282 json,
11283 "updateDelayInProgress");
11284 } else {
11285 if (bgp->update_delay_over) {
11286 json_object_string_add(
11287 json,
11288 "updateDelayFirstNeighbor",
11289 bgp->update_delay_begin_time);
11290 json_object_string_add(
11291 json,
11292 "updateDelayBestpathResumed",
11293 bgp->update_delay_end_time);
11294 json_object_string_add(
11295 json,
11296 "updateDelayZebraUpdateResume",
11297 bgp->update_delay_zebra_resume_time);
11298 json_object_string_add(
11299 json,
11300 "updateDelayPeerUpdateResume",
11301 bgp->update_delay_peers_resume_time);
11302 }
11303 }
11304 } else {
11305 vty_out(vty,
11306 "Read-only mode update-delay limit: %d seconds\n",
11307 bgp->v_update_delay);
11308 if (bgp->v_update_delay
11309 != bgp->v_establish_wait)
11310 vty_out(vty,
11311 " Establish wait: %d seconds\n",
11312 bgp->v_establish_wait);
11313
11314 if (bgp_update_delay_active(bgp)) {
11315 vty_out(vty,
11316 " First neighbor established: %s\n",
11317 bgp->update_delay_begin_time);
11318 vty_out(vty,
11319 " Delay in progress\n");
11320 } else {
11321 if (bgp->update_delay_over) {
11322 vty_out(vty,
11323 " First neighbor established: %s\n",
11324 bgp->update_delay_begin_time);
11325 vty_out(vty,
11326 " Best-paths resumed: %s\n",
11327 bgp->update_delay_end_time);
11328 vty_out(vty,
11329 " zebra update resumed: %s\n",
11330 bgp->update_delay_zebra_resume_time);
11331 vty_out(vty,
11332 " peers update resumed: %s\n",
11333 bgp->update_delay_peers_resume_time);
11334 }
11335 }
11336 }
11337 }
11338
11339 if (use_json) {
11340 if (bgp_maxmed_onstartup_configured(bgp)
11341 && bgp->maxmed_active)
11342 json_object_boolean_true_add(
11343 json, "maxMedOnStartup");
11344 if (bgp->v_maxmed_admin)
11345 json_object_boolean_true_add(
11346 json, "maxMedAdministrative");
11347
11348 json_object_int_add(
11349 json, "tableVersion",
11350 bgp_table_version(bgp->rib[afi][safi]));
11351
11352 ents = bgp_table_count(bgp->rib[afi][safi]);
11353 json_object_int_add(json, "ribCount", ents);
11354 json_object_int_add(
11355 json, "ribMemory",
11356 ents * sizeof(struct bgp_dest));
11357
11358 ents = bgp->af_peer_count[afi][safi];
11359 json_object_int_add(json, "peerCount", ents);
11360 json_object_int_add(json, "peerMemory",
11361 ents * sizeof(struct peer));
11362
11363 if ((ents = listcount(bgp->group))) {
11364 json_object_int_add(
11365 json, "peerGroupCount", ents);
11366 json_object_int_add(
11367 json, "peerGroupMemory",
11368 ents * sizeof(struct
11369 peer_group));
11370 }
11371
11372 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11373 BGP_CONFIG_DAMPENING))
11374 json_object_boolean_true_add(
11375 json, "dampeningEnabled");
11376 } else {
11377 if (!show_terse) {
11378 if (bgp_maxmed_onstartup_configured(bgp)
11379 && bgp->maxmed_active)
11380 vty_out(vty,
11381 "Max-med on-startup active\n");
11382 if (bgp->v_maxmed_admin)
11383 vty_out(vty,
11384 "Max-med administrative active\n");
11385
11386 vty_out(vty,
11387 "BGP table version %" PRIu64
11388 "\n",
11389 bgp_table_version(
11390 bgp->rib[afi][safi]));
11391
11392 ents = bgp_table_count(
11393 bgp->rib[afi][safi]);
11394 vty_out(vty,
11395 "RIB entries %ld, using %s of memory\n",
11396 ents,
11397 mtype_memstr(
11398 memstrbuf,
11399 sizeof(memstrbuf),
11400 ents
11401 * sizeof(
11402 struct
11403 bgp_dest)));
11404
11405 /* Peer related usage */
11406 ents = bgp->af_peer_count[afi][safi];
11407 vty_out(vty,
11408 "Peers %ld, using %s of memory\n",
11409 ents,
11410 mtype_memstr(
11411 memstrbuf,
11412 sizeof(memstrbuf),
11413 ents
11414 * sizeof(
11415 struct
11416 peer)));
11417
11418 if ((ents = listcount(bgp->group)))
11419 vty_out(vty,
11420 "Peer groups %ld, using %s of memory\n",
11421 ents,
11422 mtype_memstr(
11423 memstrbuf,
11424 sizeof(memstrbuf),
11425 ents
11426 * sizeof(
11427 struct
11428 peer_group)));
11429
11430 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11431 BGP_CONFIG_DAMPENING))
11432 vty_out(vty,
11433 "Dampening enabled.\n");
11434 }
11435 if (show_failed) {
11436 vty_out(vty, "\n");
11437
11438 /* Subtract 8 here because 'Neighbor' is
11439 * 8 characters */
11440 vty_out(vty, "Neighbor");
11441 vty_out(vty, "%*s",
11442 max_neighbor_width - 8, " ");
11443 vty_out(vty,
11444 BGP_SHOW_SUMMARY_HEADER_FAILED);
11445 }
11446 }
11447 }
11448
11449 paf = peer_af_find(peer, afi, safi);
11450 filter = &peer->filter[afi][safi];
11451
11452 count++;
11453 /* Works for both failed & successful cases */
11454 if (peer_dynamic_neighbor(peer))
11455 dn_count++;
11456
11457 if (use_json) {
11458 json_peer = NULL;
11459 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11460 as_type, as)) {
11461 filtered_count++;
11462 continue;
11463 }
11464 if (show_failed &&
11465 bgp_has_peer_failed(peer, afi, safi)) {
11466 json_peer = json_object_new_object();
11467 bgp_show_failed_summary(vty, bgp, peer,
11468 json_peer, 0, use_json);
11469 } else if (!show_failed) {
11470 if (show_established
11471 && bgp_has_peer_failed(peer, afi, safi)) {
11472 filtered_count++;
11473 continue;
11474 }
11475
11476 json_peer = json_object_new_object();
11477 if (peer_dynamic_neighbor(peer)) {
11478 json_object_boolean_true_add(json_peer,
11479 "dynamicPeer");
11480 }
11481
11482 if (peer->hostname)
11483 json_object_string_add(json_peer, "hostname",
11484 peer->hostname);
11485
11486 if (peer->domainname)
11487 json_object_string_add(json_peer, "domainname",
11488 peer->domainname);
11489
11490 asn_asn2json(json_peer, "remoteAs", peer->as,
11491 bgp->asnotation);
11492 asn_asn2json(json_peer, "localAs",
11493 peer->change_local_as
11494 ? peer->change_local_as
11495 : peer->local_as,
11496 bgp->asnotation);
11497 json_object_int_add(json_peer, "version", 4);
11498 json_object_int_add(json_peer, "msgRcvd",
11499 PEER_TOTAL_RX(peer));
11500 json_object_int_add(json_peer, "msgSent",
11501 PEER_TOTAL_TX(peer));
11502
11503 atomic_size_t outq_count, inq_count;
11504 outq_count = atomic_load_explicit(
11505 &peer->obuf->count,
11506 memory_order_relaxed);
11507 inq_count = atomic_load_explicit(
11508 &peer->ibuf->count,
11509 memory_order_relaxed);
11510
11511 json_object_int_add(json_peer, "tableVersion",
11512 peer->version[afi][safi]);
11513 json_object_int_add(json_peer, "outq",
11514 outq_count);
11515 json_object_int_add(json_peer, "inq",
11516 inq_count);
11517 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11518 use_json, json_peer);
11519
11520 json_object_int_add(json_peer, "pfxRcd",
11521 peer->pcount[afi][pfx_rcd_safi]);
11522
11523 if (paf && PAF_SUBGRP(paf))
11524 json_object_int_add(
11525 json_peer, "pfxSnt",
11526 (PAF_SUBGRP(paf))->scount);
11527 else
11528 json_object_int_add(json_peer, "pfxSnt",
11529 0);
11530
11531 /* BGP FSM state */
11532 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11533 || CHECK_FLAG(peer->bgp->flags,
11534 BGP_FLAG_SHUTDOWN))
11535 json_object_string_add(json_peer,
11536 "state",
11537 "Idle (Admin)");
11538 else if (peer->afc_recv[afi][safi])
11539 json_object_string_add(
11540 json_peer, "state",
11541 lookup_msg(bgp_status_msg,
11542 peer->status, NULL));
11543 else if (CHECK_FLAG(
11544 peer->sflags,
11545 PEER_STATUS_PREFIX_OVERFLOW))
11546 json_object_string_add(json_peer,
11547 "state",
11548 "Idle (PfxCt)");
11549 else
11550 json_object_string_add(
11551 json_peer, "state",
11552 lookup_msg(bgp_status_msg,
11553 peer->status, NULL));
11554
11555 /* BGP peer state */
11556 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11557 || CHECK_FLAG(peer->bgp->flags,
11558 BGP_FLAG_SHUTDOWN))
11559 json_object_string_add(json_peer,
11560 "peerState",
11561 "Admin");
11562 else if (CHECK_FLAG(
11563 peer->sflags,
11564 PEER_STATUS_PREFIX_OVERFLOW))
11565 json_object_string_add(json_peer,
11566 "peerState",
11567 "PfxCt");
11568 else if (CHECK_FLAG(peer->flags,
11569 PEER_FLAG_PASSIVE))
11570 json_object_string_add(json_peer,
11571 "peerState",
11572 "Passive");
11573 else if (CHECK_FLAG(peer->sflags,
11574 PEER_STATUS_NSF_WAIT))
11575 json_object_string_add(json_peer,
11576 "peerState",
11577 "NSF passive");
11578 else if (CHECK_FLAG(
11579 peer->bgp->flags,
11580 BGP_FLAG_EBGP_REQUIRES_POLICY)
11581 && (!bgp_inbound_policy_exists(peer,
11582 filter)
11583 || !bgp_outbound_policy_exists(
11584 peer, filter)))
11585 json_object_string_add(json_peer,
11586 "peerState",
11587 "Policy");
11588 else
11589 json_object_string_add(
11590 json_peer, "peerState", "OK");
11591
11592 json_object_int_add(json_peer, "connectionsEstablished",
11593 peer->established);
11594 json_object_int_add(json_peer, "connectionsDropped",
11595 peer->dropped);
11596 if (peer->desc)
11597 json_object_string_add(
11598 json_peer, "desc", peer->desc);
11599 }
11600 /* Avoid creating empty peer dicts in JSON */
11601 if (json_peer == NULL)
11602 continue;
11603
11604 if (peer->conf_if)
11605 json_object_string_add(json_peer, "idType",
11606 "interface");
11607 else if (peer->su.sa.sa_family == AF_INET)
11608 json_object_string_add(json_peer, "idType",
11609 "ipv4");
11610 else if (peer->su.sa.sa_family == AF_INET6)
11611 json_object_string_add(json_peer, "idType",
11612 "ipv6");
11613 json_object_object_add(json_peers, peer->host,
11614 json_peer);
11615 } else {
11616 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11617 as_type, as)) {
11618 filtered_count++;
11619 continue;
11620 }
11621 if (show_failed &&
11622 bgp_has_peer_failed(peer, afi, safi)) {
11623 bgp_show_failed_summary(vty, bgp, peer, NULL,
11624 max_neighbor_width,
11625 use_json);
11626 } else if (!show_failed) {
11627 if (show_established
11628 && bgp_has_peer_failed(peer, afi, safi)) {
11629 filtered_count++;
11630 continue;
11631 }
11632
11633 if ((count - filtered_count) == 1) {
11634 /* display headline before the first
11635 * neighbor line */
11636 vty_out(vty, "\n");
11637
11638 /* Subtract 8 here because 'Neighbor' is
11639 * 8 characters */
11640 vty_out(vty, "Neighbor");
11641 vty_out(vty, "%*s",
11642 max_neighbor_width - 8, " ");
11643 vty_out(vty,
11644 show_wide
11645 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11646 : BGP_SHOW_SUMMARY_HEADER_ALL);
11647 }
11648
11649 memset(dn_flag, '\0', sizeof(dn_flag));
11650 if (peer_dynamic_neighbor(peer)) {
11651 dn_flag[0] = '*';
11652 }
11653
11654 if (peer->hostname
11655 && CHECK_FLAG(bgp->flags,
11656 BGP_FLAG_SHOW_HOSTNAME))
11657 len = vty_out(vty, "%s%s(%s)", dn_flag,
11658 peer->hostname,
11659 peer->host);
11660 else
11661 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11662
11663 /* pad the neighbor column with spaces */
11664 if (len < max_neighbor_width)
11665 vty_out(vty, "%*s", max_neighbor_width - len,
11666 " ");
11667
11668 atomic_size_t outq_count, inq_count;
11669 outq_count = atomic_load_explicit(
11670 &peer->obuf->count,
11671 memory_order_relaxed);
11672 inq_count = atomic_load_explicit(
11673 &peer->ibuf->count,
11674 memory_order_relaxed);
11675
11676 vty_out(vty, "4 ");
11677 vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation),
11678 &peer->as);
11679 if (show_wide) {
11680 vty_out(vty,
11681 ASN_FORMAT_SPACE(
11682 bgp->asnotation),
11683 peer->change_local_as
11684 ? &peer->change_local_as
11685 : &peer->local_as);
11686 vty_out(vty,
11687 " %9u %9u %8" PRIu64
11688 " %4zu %4zu %8s",
11689 PEER_TOTAL_RX(peer),
11690 PEER_TOTAL_TX(peer),
11691 peer->version[afi][safi],
11692 inq_count, outq_count,
11693 peer_uptime(peer->uptime,
11694 timebuf,
11695 BGP_UPTIME_LEN, 0,
11696 NULL));
11697 } else {
11698 vty_out(vty,
11699 " %9u %9u %8" PRIu64
11700 " %4zu %4zu %8s",
11701 PEER_TOTAL_RX(peer),
11702 PEER_TOTAL_TX(peer),
11703 peer->version[afi][safi],
11704 inq_count, outq_count,
11705 peer_uptime(peer->uptime,
11706 timebuf,
11707 BGP_UPTIME_LEN, 0,
11708 NULL));
11709 }
11710 if (peer_established(peer)) {
11711 if (peer->afc_recv[afi][safi]) {
11712 if (CHECK_FLAG(
11713 bgp->flags,
11714 BGP_FLAG_EBGP_REQUIRES_POLICY)
11715 && !bgp_inbound_policy_exists(
11716 peer, filter))
11717 vty_out(vty, " %12s",
11718 "(Policy)");
11719 else
11720 vty_out(vty,
11721 " %12u",
11722 peer->pcount
11723 [afi]
11724 [pfx_rcd_safi]);
11725 } else {
11726 vty_out(vty, " NoNeg");
11727 }
11728
11729 if (paf && PAF_SUBGRP(paf)) {
11730 if (CHECK_FLAG(
11731 bgp->flags,
11732 BGP_FLAG_EBGP_REQUIRES_POLICY)
11733 && !bgp_outbound_policy_exists(
11734 peer, filter))
11735 vty_out(vty, " %8s",
11736 "(Policy)");
11737 else
11738 vty_out(vty,
11739 " %8u",
11740 (PAF_SUBGRP(
11741 paf))
11742 ->scount);
11743 } else {
11744 vty_out(vty, " NoNeg");
11745 }
11746 } else {
11747 if (CHECK_FLAG(peer->flags,
11748 PEER_FLAG_SHUTDOWN)
11749 || CHECK_FLAG(peer->bgp->flags,
11750 BGP_FLAG_SHUTDOWN))
11751 vty_out(vty, " Idle (Admin)");
11752 else if (CHECK_FLAG(
11753 peer->sflags,
11754 PEER_STATUS_PREFIX_OVERFLOW))
11755 vty_out(vty, " Idle (PfxCt)");
11756 else
11757 vty_out(vty, " %12s",
11758 lookup_msg(bgp_status_msg,
11759 peer->status, NULL));
11760
11761 vty_out(vty, " %8u", 0);
11762 }
11763 /* Make sure `Desc` column is the lastest in
11764 * the output.
11765 */
11766 if (peer->desc)
11767 vty_out(vty, " %s",
11768 bgp_peer_description_stripped(
11769 peer->desc,
11770 show_wide ? 64 : 20));
11771 else
11772 vty_out(vty, " N/A");
11773 vty_out(vty, "\n");
11774 }
11775
11776 }
11777 }
11778
11779 if (use_json) {
11780 json_object_object_add(json, "peers", json_peers);
11781 json_object_int_add(json, "failedPeers", failed_count);
11782 json_object_int_add(json, "displayedPeers",
11783 count - filtered_count);
11784 json_object_int_add(json, "totalPeers", count);
11785 json_object_int_add(json, "dynamicPeers", dn_count);
11786
11787 if (!show_failed)
11788 bgp_show_bestpath_json(bgp, json);
11789
11790 vty_json(vty, json);
11791 } else {
11792 if (count) {
11793 if (filtered_count == count)
11794 vty_out(vty, "\n%% No matching neighbor\n");
11795 else {
11796 if (show_failed)
11797 vty_out(vty, "\nDisplayed neighbors %d",
11798 failed_count);
11799 else if (as_type != AS_UNSPECIFIED || as
11800 || fpeer || show_established)
11801 vty_out(vty, "\nDisplayed neighbors %d",
11802 count - filtered_count);
11803
11804 vty_out(vty, "\nTotal number of neighbors %d\n",
11805 count);
11806 }
11807 } else {
11808 vty_out(vty, "No %s neighbor is configured\n",
11809 get_afi_safi_str(afi, safi, false));
11810 }
11811
11812 if (dn_count) {
11813 vty_out(vty, "* - dynamic neighbor\n");
11814 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11815 dn_count, bgp->dynamic_neighbors_limit);
11816 }
11817 }
11818
11819 return CMD_SUCCESS;
11820 }
11821
11822 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11823 int safi, struct peer *fpeer, int as_type,
11824 as_t as, uint16_t show_flags)
11825 {
11826 int is_first = 1;
11827 int afi_wildcard = (afi == AFI_MAX);
11828 int safi_wildcard = (safi == SAFI_MAX);
11829 int is_wildcard = (afi_wildcard || safi_wildcard);
11830 bool nbr_output = false;
11831 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11832
11833 if (use_json && is_wildcard)
11834 vty_out(vty, "{\n");
11835 if (afi_wildcard)
11836 afi = 1; /* AFI_IP */
11837 while (afi < AFI_MAX) {
11838 if (safi_wildcard)
11839 safi = 1; /* SAFI_UNICAST */
11840 while (safi < SAFI_MAX) {
11841 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11842 nbr_output = true;
11843
11844 if (is_wildcard) {
11845 /*
11846 * So limit output to those afi/safi
11847 * pairs that
11848 * actualy have something interesting in
11849 * them
11850 */
11851 if (use_json) {
11852 if (!is_first)
11853 vty_out(vty, ",\n");
11854 else
11855 is_first = 0;
11856
11857 vty_out(vty, "\"%s\":",
11858 get_afi_safi_str(afi,
11859 safi,
11860 true));
11861 } else {
11862 vty_out(vty,
11863 "\n%s Summary (%s):\n",
11864 get_afi_safi_str(afi,
11865 safi,
11866 false),
11867 bgp->name_pretty);
11868 }
11869 }
11870 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11871 as_type, as, show_flags);
11872 }
11873 safi++;
11874 if (!safi_wildcard)
11875 safi = SAFI_MAX;
11876 }
11877 afi++;
11878 if (!afi_wildcard)
11879 afi = AFI_MAX;
11880 }
11881
11882 if (use_json && is_wildcard)
11883 vty_out(vty, "}\n");
11884 else if (!nbr_output) {
11885 if (use_json)
11886 vty_out(vty, "{}\n");
11887 else
11888 vty_out(vty, "%% No BGP neighbors found in %s\n",
11889 bgp->name_pretty);
11890 }
11891 }
11892
11893 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11894 safi_t safi,
11895 const char *neighbor,
11896 int as_type, as_t as,
11897 uint16_t show_flags)
11898 {
11899 struct listnode *node, *nnode;
11900 struct bgp *bgp;
11901 struct peer *fpeer = NULL;
11902 int is_first = 1;
11903 bool nbr_output = false;
11904 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11905
11906 if (use_json)
11907 vty_out(vty, "{\n");
11908
11909 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11910 nbr_output = true;
11911 if (use_json) {
11912 if (!is_first)
11913 vty_out(vty, ",\n");
11914 else
11915 is_first = 0;
11916
11917 vty_out(vty, "\"%s\":",
11918 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11919 ? VRF_DEFAULT_NAME
11920 : bgp->name);
11921 }
11922 if (neighbor) {
11923 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11924 use_json);
11925 if (!fpeer)
11926 continue;
11927 }
11928 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11929 as, show_flags);
11930 }
11931
11932 if (use_json)
11933 vty_out(vty, "}\n");
11934 else if (!nbr_output)
11935 vty_out(vty, "%% BGP instance not found\n");
11936 }
11937
11938 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11939 safi_t safi, const char *neighbor, int as_type,
11940 as_t as, uint16_t show_flags)
11941 {
11942 struct bgp *bgp;
11943 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11944 struct peer *fpeer = NULL;
11945
11946 if (name) {
11947 if (strmatch(name, "all")) {
11948 bgp_show_all_instances_summary_vty(vty, afi, safi,
11949 neighbor, as_type,
11950 as, show_flags);
11951 return CMD_SUCCESS;
11952 } else {
11953 bgp = bgp_lookup_by_name(name);
11954
11955 if (!bgp) {
11956 if (use_json)
11957 vty_out(vty, "{}\n");
11958 else
11959 vty_out(vty,
11960 "%% BGP instance not found\n");
11961 return CMD_WARNING;
11962 }
11963
11964 if (neighbor) {
11965 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11966 use_json);
11967 if (!fpeer)
11968 return CMD_WARNING;
11969 }
11970 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11971 as_type, as, show_flags);
11972 return CMD_SUCCESS;
11973 }
11974 }
11975
11976 bgp = bgp_get_default();
11977
11978 if (bgp) {
11979 if (neighbor) {
11980 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11981 use_json);
11982 if (!fpeer)
11983 return CMD_WARNING;
11984 }
11985 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11986 as, show_flags);
11987 } else {
11988 if (use_json)
11989 vty_out(vty, "{}\n");
11990 else
11991 vty_out(vty, "%% BGP instance not found\n");
11992 return CMD_WARNING;
11993 }
11994
11995 return CMD_SUCCESS;
11996 }
11997
11998 /* `show [ip] bgp summary' commands. */
11999 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
12000 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
12001 " [" BGP_SAFI_WITH_LABEL_CMD_STR
12002 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <ASNUM|internal|external>>] [terse] [wide] [json$uj]",
12003 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
12004 BGP_SAFI_WITH_LABEL_HELP_STR
12005 "Display the entries for all address families\n"
12006 "Summary of BGP neighbor status\n"
12007 "Show only sessions in Established state\n"
12008 "Show only sessions not in Established state\n"
12009 "Show only the specified neighbor session\n"
12010 "Neighbor to display information about\n"
12011 "Neighbor to display information about\n"
12012 "Neighbor on BGP configured interface\n"
12013 "Show only the specified remote AS sessions\n" AS_STR
12014 "Internal (iBGP) AS sessions\n"
12015 "External (eBGP) AS sessions\n"
12016 "Shorten the information on BGP instances\n"
12017 "Increase table width for longer output\n" JSON_STR)
12018 {
12019 char *vrf = NULL;
12020 afi_t afi = AFI_MAX;
12021 safi_t safi = SAFI_MAX;
12022 as_t as = 0; /* 0 means AS filter not set */
12023 int as_type = AS_UNSPECIFIED;
12024 uint16_t show_flags = 0;
12025
12026 int idx = 0;
12027
12028 /* show [ip] bgp */
12029 if (!all && argv_find(argv, argc, "ip", &idx))
12030 afi = AFI_IP;
12031 /* [<vrf> VIEWVRFNAME] */
12032 if (argv_find(argv, argc, "vrf", &idx)) {
12033 vrf = argv[idx + 1]->arg;
12034 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12035 vrf = NULL;
12036 } else if (argv_find(argv, argc, "view", &idx))
12037 /* [<view> VIEWVRFNAME] */
12038 vrf = argv[idx + 1]->arg;
12039 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
12040 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
12041 argv_find_and_parse_safi(argv, argc, &idx, &safi);
12042 }
12043
12044 if (argv_find(argv, argc, "failed", &idx))
12045 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
12046
12047 if (argv_find(argv, argc, "established", &idx))
12048 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
12049
12050 if (argv_find(argv, argc, "remote-as", &idx)) {
12051 if (argv[idx + 1]->arg[0] == 'i')
12052 as_type = AS_INTERNAL;
12053 else if (argv[idx + 1]->arg[0] == 'e')
12054 as_type = AS_EXTERNAL;
12055 else if (!asn_str2asn(argv[idx + 1]->arg, &as)) {
12056 vty_out(vty,
12057 "%% Invalid neighbor remote-as value: %s\n",
12058 argv[idx + 1]->arg);
12059 return CMD_SUCCESS;
12060 }
12061 }
12062
12063 if (argv_find(argv, argc, "terse", &idx))
12064 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
12065
12066 if (argv_find(argv, argc, "wide", &idx))
12067 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
12068
12069 if (argv_find(argv, argc, "json", &idx))
12070 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
12071
12072 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
12073 show_flags);
12074 }
12075
12076 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
12077 {
12078 if (for_json)
12079 return get_afi_safi_json_str(afi, safi);
12080 else
12081 return get_afi_safi_vty_str(afi, safi);
12082 }
12083
12084
12085 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
12086 afi_t afi, safi_t safi,
12087 uint16_t adv_smcap, uint16_t adv_rmcap,
12088 uint16_t rcv_smcap, uint16_t rcv_rmcap,
12089 bool use_json, json_object *json_pref)
12090 {
12091 /* Send-Mode */
12092 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12093 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
12094 if (use_json) {
12095 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12096 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12097 json_object_string_add(json_pref, "sendMode",
12098 "advertisedAndReceived");
12099 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12100 json_object_string_add(json_pref, "sendMode",
12101 "advertised");
12102 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12103 json_object_string_add(json_pref, "sendMode",
12104 "received");
12105 } else {
12106 vty_out(vty, " Send-mode: ");
12107 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12108 vty_out(vty, "advertised");
12109 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12110 vty_out(vty, "%sreceived",
12111 CHECK_FLAG(p->af_cap[afi][safi],
12112 adv_smcap)
12113 ? ", "
12114 : "");
12115 vty_out(vty, "\n");
12116 }
12117 }
12118
12119 /* Receive-Mode */
12120 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12121 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
12122 if (use_json) {
12123 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12124 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12125 json_object_string_add(json_pref, "recvMode",
12126 "advertisedAndReceived");
12127 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12128 json_object_string_add(json_pref, "recvMode",
12129 "advertised");
12130 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12131 json_object_string_add(json_pref, "recvMode",
12132 "received");
12133 } else {
12134 vty_out(vty, " Receive-mode: ");
12135 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12136 vty_out(vty, "advertised");
12137 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12138 vty_out(vty, "%sreceived",
12139 CHECK_FLAG(p->af_cap[afi][safi],
12140 adv_rmcap)
12141 ? ", "
12142 : "");
12143 vty_out(vty, "\n");
12144 }
12145 }
12146 }
12147
12148 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12149 struct peer *p,
12150 json_object *json)
12151 {
12152 bool rbit = false;
12153 bool nbit = false;
12154
12155 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12156 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
12157 && (peer_established(p))) {
12158 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12159 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
12160 }
12161
12162 if (json) {
12163 json_object_boolean_add(json, "rBit", rbit);
12164 json_object_boolean_add(json, "nBit", nbit);
12165 } else {
12166 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12167 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
12168 }
12169 }
12170
12171 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12172 struct peer *peer,
12173 json_object *json)
12174 {
12175 const char *mode = "NotApplicable";
12176
12177 if (!json)
12178 vty_out(vty, "\n Remote GR Mode: ");
12179
12180 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12181 && (peer_established(peer))) {
12182
12183 if ((peer->nsf_af_count == 0)
12184 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12185
12186 mode = "Disable";
12187
12188 } else if (peer->nsf_af_count == 0
12189 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12190
12191 mode = "Helper";
12192
12193 } else if (peer->nsf_af_count != 0
12194 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12195
12196 mode = "Restart";
12197 }
12198 }
12199
12200 if (json)
12201 json_object_string_add(json, "remoteGrMode", mode);
12202 else
12203 vty_out(vty, "%s\n", mode);
12204 }
12205
12206 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12207 struct peer *p,
12208 json_object *json)
12209 {
12210 const char *mode = "Invalid";
12211
12212 if (!json)
12213 vty_out(vty, " Local GR Mode: ");
12214
12215 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12216 mode = "Helper";
12217 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12218 mode = "Restart";
12219 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12220 mode = "Disable";
12221 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12222 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12223 mode = "Helper*";
12224 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12225 mode = "Restart*";
12226 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12227 mode = "Disable*";
12228 else
12229 mode = "Invalid*";
12230 }
12231
12232 if (json)
12233 json_object_string_add(json, "localGrMode", mode);
12234 else
12235 vty_out(vty, "%s\n", mode);
12236 }
12237
12238 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12239 struct vty *vty, struct peer *peer, json_object *json)
12240 {
12241 afi_t afi;
12242 safi_t safi;
12243 json_object *json_afi_safi = NULL;
12244 json_object *json_timer = NULL;
12245 json_object *json_endofrib_status = NULL;
12246 bool eor_flag = false;
12247
12248 FOREACH_AFI_SAFI_NSF (afi, safi) {
12249 if (!peer->afc[afi][safi])
12250 continue;
12251
12252 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12253 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12254 continue;
12255
12256 if (json) {
12257 json_afi_safi = json_object_new_object();
12258 json_endofrib_status = json_object_new_object();
12259 json_timer = json_object_new_object();
12260 }
12261
12262 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12263 eor_flag = true;
12264 else
12265 eor_flag = false;
12266
12267 if (!json) {
12268 vty_out(vty, " %s:\n",
12269 get_afi_safi_str(afi, safi, false));
12270
12271 vty_out(vty, " F bit: ");
12272 }
12273
12274 if (peer->nsf[afi][safi] &&
12275 CHECK_FLAG(peer->af_cap[afi][safi],
12276 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12277
12278 if (json) {
12279 json_object_boolean_true_add(json_afi_safi,
12280 "fBit");
12281 } else
12282 vty_out(vty, "True\n");
12283 } else {
12284 if (json)
12285 json_object_boolean_false_add(json_afi_safi,
12286 "fBit");
12287 else
12288 vty_out(vty, "False\n");
12289 }
12290
12291 if (!json)
12292 vty_out(vty, " End-of-RIB sent: ");
12293
12294 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12295 PEER_STATUS_EOR_SEND)) {
12296 if (json) {
12297 json_object_boolean_true_add(
12298 json_endofrib_status, "endOfRibSend");
12299
12300 PRINT_EOR_JSON(eor_flag);
12301 } else {
12302 vty_out(vty, "Yes\n");
12303 vty_out(vty,
12304 " End-of-RIB sent after update: ");
12305
12306 PRINT_EOR(eor_flag);
12307 }
12308 } else {
12309 if (json) {
12310 json_object_boolean_false_add(
12311 json_endofrib_status, "endOfRibSend");
12312 json_object_boolean_false_add(
12313 json_endofrib_status,
12314 "endOfRibSentAfterUpdate");
12315 } else {
12316 vty_out(vty, "No\n");
12317 vty_out(vty,
12318 " End-of-RIB sent after update: ");
12319 vty_out(vty, "No\n");
12320 }
12321 }
12322
12323 if (!json)
12324 vty_out(vty, " End-of-RIB received: ");
12325
12326 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12327 PEER_STATUS_EOR_RECEIVED)) {
12328 if (json)
12329 json_object_boolean_true_add(
12330 json_endofrib_status, "endOfRibRecv");
12331 else
12332 vty_out(vty, "Yes\n");
12333 } else {
12334 if (json)
12335 json_object_boolean_false_add(
12336 json_endofrib_status, "endOfRibRecv");
12337 else
12338 vty_out(vty, "No\n");
12339 }
12340
12341 if (json) {
12342 json_object_int_add(json_timer, "stalePathTimer",
12343 peer->bgp->stalepath_time);
12344
12345 if (peer->t_gr_stale != NULL) {
12346 json_object_int_add(json_timer,
12347 "stalePathTimerRemaining",
12348 thread_timer_remain_second(
12349 peer->t_gr_stale));
12350 }
12351
12352 /* Display Configured Selection
12353 * Deferral only when when
12354 * Gr mode is enabled.
12355 */
12356 if (CHECK_FLAG(peer->flags,
12357 PEER_FLAG_GRACEFUL_RESTART)) {
12358 json_object_int_add(json_timer,
12359 "selectionDeferralTimer",
12360 peer->bgp->stalepath_time);
12361 }
12362
12363 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12364 NULL) {
12365
12366 json_object_int_add(
12367 json_timer,
12368 "selectionDeferralTimerRemaining",
12369 thread_timer_remain_second(
12370 peer->bgp->gr_info[afi][safi]
12371 .t_select_deferral));
12372 }
12373 } else {
12374 vty_out(vty, " Timers:\n");
12375 vty_out(vty,
12376 " Configured Stale Path Time(sec): %u\n",
12377 peer->bgp->stalepath_time);
12378
12379 if (peer->t_gr_stale != NULL)
12380 vty_out(vty,
12381 " Stale Path Remaining(sec): %ld\n",
12382 thread_timer_remain_second(
12383 peer->t_gr_stale));
12384 /* Display Configured Selection
12385 * Deferral only when when
12386 * Gr mode is enabled.
12387 */
12388 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12389 vty_out(vty,
12390 " Configured Selection Deferral Time(sec): %u\n",
12391 peer->bgp->select_defer_time);
12392
12393 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12394 NULL)
12395 vty_out(vty,
12396 " Selection Deferral Time Remaining(sec): %ld\n",
12397 thread_timer_remain_second(
12398 peer->bgp->gr_info[afi][safi]
12399 .t_select_deferral));
12400 }
12401 if (json) {
12402 json_object_object_add(json_afi_safi, "endOfRibStatus",
12403 json_endofrib_status);
12404 json_object_object_add(json_afi_safi, "timers",
12405 json_timer);
12406 json_object_object_add(
12407 json, get_afi_safi_str(afi, safi, true),
12408 json_afi_safi);
12409 }
12410 }
12411 }
12412
12413 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12414 struct peer *p,
12415 json_object *json)
12416 {
12417 if (json) {
12418 json_object *json_timer = NULL;
12419
12420 json_timer = json_object_new_object();
12421
12422 json_object_int_add(json_timer, "configuredRestartTimer",
12423 p->bgp->restart_time);
12424
12425 json_object_int_add(json_timer, "receivedRestartTimer",
12426 p->v_gr_restart);
12427
12428 if (p->t_gr_restart != NULL)
12429 json_object_int_add(
12430 json_timer, "restartTimerRemaining",
12431 thread_timer_remain_second(p->t_gr_restart));
12432
12433 json_object_object_add(json, "timers", json_timer);
12434 } else {
12435
12436 vty_out(vty, " Timers:\n");
12437 vty_out(vty, " Configured Restart Time(sec): %u\n",
12438 p->bgp->restart_time);
12439
12440 vty_out(vty, " Received Restart Time(sec): %u\n",
12441 p->v_gr_restart);
12442 if (p->t_gr_restart != NULL)
12443 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12444 thread_timer_remain_second(p->t_gr_restart));
12445 if (p->t_gr_restart != NULL) {
12446 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12447 thread_timer_remain_second(p->t_gr_restart));
12448 }
12449 }
12450 }
12451
12452 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12453 json_object *json)
12454 {
12455 char dn_flag[2] = {0};
12456 /* '*' + v6 address of neighbor */
12457 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12458
12459 if (!p->conf_if && peer_dynamic_neighbor(p))
12460 dn_flag[0] = '*';
12461
12462 if (p->conf_if) {
12463 if (json)
12464 json_object_string_addf(json, "neighborAddr", "%pSU",
12465 &p->su);
12466 else
12467 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12468 &p->su);
12469 } else {
12470 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12471 p->host);
12472
12473 if (json)
12474 json_object_string_add(json, "neighborAddr",
12475 neighborAddr);
12476 else
12477 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12478 }
12479
12480 /* more gr info in new format */
12481 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12482 }
12483
12484 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12485 safi_t safi, bool use_json,
12486 json_object *json_neigh)
12487 {
12488 struct bgp_filter *filter;
12489 struct peer_af *paf;
12490 char orf_pfx_name[BUFSIZ];
12491 int orf_pfx_count;
12492 json_object *json_af = NULL;
12493 json_object *json_prefA = NULL;
12494 json_object *json_prefB = NULL;
12495 json_object *json_addr = NULL;
12496 json_object *json_advmap = NULL;
12497
12498 if (use_json) {
12499 json_addr = json_object_new_object();
12500 json_af = json_object_new_object();
12501 filter = &p->filter[afi][safi];
12502
12503 if (peer_group_active(p))
12504 json_object_string_add(json_addr, "peerGroupMember",
12505 p->group->name);
12506
12507 paf = peer_af_find(p, afi, safi);
12508 if (paf && PAF_SUBGRP(paf)) {
12509 json_object_int_add(json_addr, "updateGroupId",
12510 PAF_UPDGRP(paf)->id);
12511 json_object_int_add(json_addr, "subGroupId",
12512 PAF_SUBGRP(paf)->id);
12513 json_object_int_add(json_addr, "packetQueueLength",
12514 bpacket_queue_virtual_length(paf));
12515 }
12516
12517 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12518 || CHECK_FLAG(p->af_cap[afi][safi],
12519 PEER_CAP_ORF_PREFIX_SM_RCV)
12520 || CHECK_FLAG(p->af_cap[afi][safi],
12521 PEER_CAP_ORF_PREFIX_RM_ADV)
12522 || CHECK_FLAG(p->af_cap[afi][safi],
12523 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12524 json_object_int_add(json_af, "orfType",
12525 ORF_TYPE_PREFIX);
12526 json_prefA = json_object_new_object();
12527 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12528 PEER_CAP_ORF_PREFIX_SM_ADV,
12529 PEER_CAP_ORF_PREFIX_RM_ADV,
12530 PEER_CAP_ORF_PREFIX_SM_RCV,
12531 PEER_CAP_ORF_PREFIX_RM_RCV,
12532 use_json, json_prefA);
12533 json_object_object_add(json_af, "orfPrefixList",
12534 json_prefA);
12535 }
12536
12537 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12538 || CHECK_FLAG(p->af_cap[afi][safi],
12539 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12540 || CHECK_FLAG(p->af_cap[afi][safi],
12541 PEER_CAP_ORF_PREFIX_RM_ADV)
12542 || CHECK_FLAG(p->af_cap[afi][safi],
12543 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12544 json_object_int_add(json_af, "orfOldType",
12545 ORF_TYPE_PREFIX_OLD);
12546 json_prefB = json_object_new_object();
12547 bgp_show_peer_afi_orf_cap(
12548 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12549 PEER_CAP_ORF_PREFIX_RM_ADV,
12550 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12551 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12552 json_prefB);
12553 json_object_object_add(json_af, "orfOldPrefixList",
12554 json_prefB);
12555 }
12556
12557 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12558 || CHECK_FLAG(p->af_cap[afi][safi],
12559 PEER_CAP_ORF_PREFIX_SM_RCV)
12560 || CHECK_FLAG(p->af_cap[afi][safi],
12561 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12562 || CHECK_FLAG(p->af_cap[afi][safi],
12563 PEER_CAP_ORF_PREFIX_RM_ADV)
12564 || CHECK_FLAG(p->af_cap[afi][safi],
12565 PEER_CAP_ORF_PREFIX_RM_RCV)
12566 || CHECK_FLAG(p->af_cap[afi][safi],
12567 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12568 json_object_object_add(json_addr, "afDependentCap",
12569 json_af);
12570 else
12571 json_object_free(json_af);
12572
12573 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12574 p->host, afi, safi);
12575 orf_pfx_count = prefix_bgp_show_prefix_list(
12576 NULL, afi, orf_pfx_name, use_json);
12577
12578 if (CHECK_FLAG(p->af_sflags[afi][safi],
12579 PEER_STATUS_ORF_PREFIX_SEND)
12580 || orf_pfx_count) {
12581 if (CHECK_FLAG(p->af_sflags[afi][safi],
12582 PEER_STATUS_ORF_PREFIX_SEND))
12583 json_object_boolean_true_add(json_neigh,
12584 "orfSent");
12585 if (orf_pfx_count)
12586 json_object_int_add(json_addr, "orfRecvCounter",
12587 orf_pfx_count);
12588 }
12589 if (CHECK_FLAG(p->af_sflags[afi][safi],
12590 PEER_STATUS_ORF_WAIT_REFRESH))
12591 json_object_string_add(
12592 json_addr, "orfFirstUpdate",
12593 "deferredUntilORFOrRouteRefreshRecvd");
12594
12595 if (CHECK_FLAG(p->af_flags[afi][safi],
12596 PEER_FLAG_REFLECTOR_CLIENT))
12597 json_object_boolean_true_add(json_addr,
12598 "routeReflectorClient");
12599 if (CHECK_FLAG(p->af_flags[afi][safi],
12600 PEER_FLAG_RSERVER_CLIENT))
12601 json_object_boolean_true_add(json_addr,
12602 "routeServerClient");
12603 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12604 json_object_boolean_true_add(json_addr,
12605 "inboundSoftConfigPermit");
12606
12607 if (CHECK_FLAG(p->af_flags[afi][safi],
12608 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12609 json_object_boolean_true_add(
12610 json_addr,
12611 "privateAsNumsAllReplacedInUpdatesToNbr");
12612 else if (CHECK_FLAG(p->af_flags[afi][safi],
12613 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12614 json_object_boolean_true_add(
12615 json_addr,
12616 "privateAsNumsReplacedInUpdatesToNbr");
12617 else if (CHECK_FLAG(p->af_flags[afi][safi],
12618 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12619 json_object_boolean_true_add(
12620 json_addr,
12621 "privateAsNumsAllRemovedInUpdatesToNbr");
12622 else if (CHECK_FLAG(p->af_flags[afi][safi],
12623 PEER_FLAG_REMOVE_PRIVATE_AS))
12624 json_object_boolean_true_add(
12625 json_addr,
12626 "privateAsNumsRemovedInUpdatesToNbr");
12627
12628 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12629 if (CHECK_FLAG(p->af_flags[afi][safi],
12630 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12631 json_object_boolean_true_add(json_addr,
12632 "allowAsInOrigin");
12633 else
12634 json_object_int_add(json_addr, "allowAsInCount",
12635 p->allowas_in[afi][safi]);
12636 }
12637
12638 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12639 json_object_boolean_true_add(
12640 json_addr,
12641 bgp_addpath_names(p->addpath_type[afi][safi])
12642 ->type_json_name);
12643
12644 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12645 json_object_string_add(json_addr,
12646 "overrideASNsInOutboundUpdates",
12647 "ifAspathEqualRemoteAs");
12648
12649 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12650 || CHECK_FLAG(p->af_flags[afi][safi],
12651 PEER_FLAG_FORCE_NEXTHOP_SELF))
12652 json_object_boolean_true_add(json_addr,
12653 "routerAlwaysNextHop");
12654 if (CHECK_FLAG(p->af_flags[afi][safi],
12655 PEER_FLAG_AS_PATH_UNCHANGED))
12656 json_object_boolean_true_add(
12657 json_addr, "unchangedAsPathPropogatedToNbr");
12658 if (CHECK_FLAG(p->af_flags[afi][safi],
12659 PEER_FLAG_NEXTHOP_UNCHANGED))
12660 json_object_boolean_true_add(
12661 json_addr, "unchangedNextHopPropogatedToNbr");
12662 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12663 json_object_boolean_true_add(
12664 json_addr, "unchangedMedPropogatedToNbr");
12665 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12666 || CHECK_FLAG(p->af_flags[afi][safi],
12667 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12668 if (CHECK_FLAG(p->af_flags[afi][safi],
12669 PEER_FLAG_SEND_COMMUNITY)
12670 && CHECK_FLAG(p->af_flags[afi][safi],
12671 PEER_FLAG_SEND_EXT_COMMUNITY))
12672 json_object_string_add(json_addr,
12673 "commAttriSentToNbr",
12674 "extendedAndStandard");
12675 else if (CHECK_FLAG(p->af_flags[afi][safi],
12676 PEER_FLAG_SEND_EXT_COMMUNITY))
12677 json_object_string_add(json_addr,
12678 "commAttriSentToNbr",
12679 "extended");
12680 else
12681 json_object_string_add(json_addr,
12682 "commAttriSentToNbr",
12683 "standard");
12684 }
12685 if (CHECK_FLAG(p->af_flags[afi][safi],
12686 PEER_FLAG_DEFAULT_ORIGINATE)) {
12687 if (p->default_rmap[afi][safi].name)
12688 json_object_string_add(
12689 json_addr, "defaultRouteMap",
12690 p->default_rmap[afi][safi].name);
12691
12692 if (paf && PAF_SUBGRP(paf)
12693 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12694 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12695 json_object_boolean_true_add(json_addr,
12696 "defaultSent");
12697 else
12698 json_object_boolean_true_add(json_addr,
12699 "defaultNotSent");
12700 }
12701
12702 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12703 if (is_evpn_enabled())
12704 json_object_boolean_true_add(
12705 json_addr, "advertiseAllVnis");
12706 }
12707
12708 if (filter->plist[FILTER_IN].name
12709 || filter->dlist[FILTER_IN].name
12710 || filter->aslist[FILTER_IN].name
12711 || filter->map[RMAP_IN].name)
12712 json_object_boolean_true_add(json_addr,
12713 "inboundPathPolicyConfig");
12714 if (filter->plist[FILTER_OUT].name
12715 || filter->dlist[FILTER_OUT].name
12716 || filter->aslist[FILTER_OUT].name
12717 || filter->map[RMAP_OUT].name || filter->usmap.name)
12718 json_object_boolean_true_add(
12719 json_addr, "outboundPathPolicyConfig");
12720
12721 /* prefix-list */
12722 if (filter->plist[FILTER_IN].name)
12723 json_object_string_add(json_addr,
12724 "incomingUpdatePrefixFilterList",
12725 filter->plist[FILTER_IN].name);
12726 if (filter->plist[FILTER_OUT].name)
12727 json_object_string_add(json_addr,
12728 "outgoingUpdatePrefixFilterList",
12729 filter->plist[FILTER_OUT].name);
12730
12731 /* distribute-list */
12732 if (filter->dlist[FILTER_IN].name)
12733 json_object_string_add(
12734 json_addr, "incomingUpdateNetworkFilterList",
12735 filter->dlist[FILTER_IN].name);
12736 if (filter->dlist[FILTER_OUT].name)
12737 json_object_string_add(
12738 json_addr, "outgoingUpdateNetworkFilterList",
12739 filter->dlist[FILTER_OUT].name);
12740
12741 /* filter-list. */
12742 if (filter->aslist[FILTER_IN].name)
12743 json_object_string_add(json_addr,
12744 "incomingUpdateAsPathFilterList",
12745 filter->aslist[FILTER_IN].name);
12746 if (filter->aslist[FILTER_OUT].name)
12747 json_object_string_add(json_addr,
12748 "outgoingUpdateAsPathFilterList",
12749 filter->aslist[FILTER_OUT].name);
12750
12751 /* route-map. */
12752 if (filter->map[RMAP_IN].name)
12753 json_object_string_add(
12754 json_addr, "routeMapForIncomingAdvertisements",
12755 filter->map[RMAP_IN].name);
12756 if (filter->map[RMAP_OUT].name)
12757 json_object_string_add(
12758 json_addr, "routeMapForOutgoingAdvertisements",
12759 filter->map[RMAP_OUT].name);
12760
12761 /* ebgp-requires-policy (inbound) */
12762 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12763 && !bgp_inbound_policy_exists(p, filter))
12764 json_object_string_add(
12765 json_addr, "inboundEbgpRequiresPolicy",
12766 "Inbound updates discarded due to missing policy");
12767
12768 /* ebgp-requires-policy (outbound) */
12769 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12770 && (!bgp_outbound_policy_exists(p, filter)))
12771 json_object_string_add(
12772 json_addr, "outboundEbgpRequiresPolicy",
12773 "Outbound updates discarded due to missing policy");
12774
12775 /* unsuppress-map */
12776 if (filter->usmap.name)
12777 json_object_string_add(json_addr,
12778 "selectiveUnsuppressRouteMap",
12779 filter->usmap.name);
12780
12781 /* advertise-map */
12782 if (filter->advmap.aname) {
12783 json_advmap = json_object_new_object();
12784 json_object_string_add(json_advmap, "condition",
12785 filter->advmap.condition
12786 ? "EXIST"
12787 : "NON_EXIST");
12788 json_object_string_add(json_advmap, "conditionMap",
12789 filter->advmap.cname);
12790 json_object_string_add(json_advmap, "advertiseMap",
12791 filter->advmap.aname);
12792 json_object_string_add(
12793 json_advmap, "advertiseStatus",
12794 filter->advmap.update_type ==
12795 UPDATE_TYPE_ADVERTISE
12796 ? "Advertise"
12797 : "Withdraw");
12798 json_object_object_add(json_addr, "advertiseMap",
12799 json_advmap);
12800 }
12801
12802 /* Receive prefix count */
12803 json_object_int_add(json_addr, "acceptedPrefixCounter",
12804 p->pcount[afi][safi]);
12805 if (paf && PAF_SUBGRP(paf))
12806 json_object_int_add(json_addr, "sentPrefixCounter",
12807 (PAF_SUBGRP(paf))->scount);
12808
12809 /* Maximum prefix */
12810 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12811 json_object_int_add(json_addr, "prefixOutAllowedMax",
12812 p->pmax_out[afi][safi]);
12813
12814 /* Maximum prefix */
12815 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12816 json_object_int_add(json_addr, "prefixAllowedMax",
12817 p->pmax[afi][safi]);
12818 if (CHECK_FLAG(p->af_flags[afi][safi],
12819 PEER_FLAG_MAX_PREFIX_WARNING))
12820 json_object_boolean_true_add(
12821 json_addr, "prefixAllowedMaxWarning");
12822 json_object_int_add(json_addr,
12823 "prefixAllowedWarningThresh",
12824 p->pmax_threshold[afi][safi]);
12825 if (p->pmax_restart[afi][safi])
12826 json_object_int_add(
12827 json_addr,
12828 "prefixAllowedRestartIntervalMsecs",
12829 p->pmax_restart[afi][safi] * 60000);
12830 }
12831 json_object_object_add(json_neigh,
12832 get_afi_safi_str(afi, safi, true),
12833 json_addr);
12834
12835 } else {
12836 filter = &p->filter[afi][safi];
12837
12838 vty_out(vty, " For address family: %s\n",
12839 get_afi_safi_str(afi, safi, false));
12840
12841 if (peer_group_active(p))
12842 vty_out(vty, " %s peer-group member\n",
12843 p->group->name);
12844
12845 paf = peer_af_find(p, afi, safi);
12846 if (paf && PAF_SUBGRP(paf)) {
12847 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12848 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12849 vty_out(vty, " Packet Queue length %d\n",
12850 bpacket_queue_virtual_length(paf));
12851 } else {
12852 vty_out(vty, " Not part of any update group\n");
12853 }
12854 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12855 || CHECK_FLAG(p->af_cap[afi][safi],
12856 PEER_CAP_ORF_PREFIX_SM_RCV)
12857 || CHECK_FLAG(p->af_cap[afi][safi],
12858 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12859 || CHECK_FLAG(p->af_cap[afi][safi],
12860 PEER_CAP_ORF_PREFIX_RM_ADV)
12861 || CHECK_FLAG(p->af_cap[afi][safi],
12862 PEER_CAP_ORF_PREFIX_RM_RCV)
12863 || CHECK_FLAG(p->af_cap[afi][safi],
12864 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12865 vty_out(vty, " AF-dependant capabilities:\n");
12866
12867 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12868 || CHECK_FLAG(p->af_cap[afi][safi],
12869 PEER_CAP_ORF_PREFIX_SM_RCV)
12870 || CHECK_FLAG(p->af_cap[afi][safi],
12871 PEER_CAP_ORF_PREFIX_RM_ADV)
12872 || CHECK_FLAG(p->af_cap[afi][safi],
12873 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12874 vty_out(vty,
12875 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12876 ORF_TYPE_PREFIX);
12877 bgp_show_peer_afi_orf_cap(
12878 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12879 PEER_CAP_ORF_PREFIX_RM_ADV,
12880 PEER_CAP_ORF_PREFIX_SM_RCV,
12881 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12882 }
12883 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12884 || CHECK_FLAG(p->af_cap[afi][safi],
12885 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12886 || CHECK_FLAG(p->af_cap[afi][safi],
12887 PEER_CAP_ORF_PREFIX_RM_ADV)
12888 || CHECK_FLAG(p->af_cap[afi][safi],
12889 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12890 vty_out(vty,
12891 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12892 ORF_TYPE_PREFIX_OLD);
12893 bgp_show_peer_afi_orf_cap(
12894 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12895 PEER_CAP_ORF_PREFIX_RM_ADV,
12896 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12897 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12898 }
12899
12900 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12901 p->host, afi, safi);
12902 orf_pfx_count = prefix_bgp_show_prefix_list(
12903 NULL, afi, orf_pfx_name, use_json);
12904
12905 if (CHECK_FLAG(p->af_sflags[afi][safi],
12906 PEER_STATUS_ORF_PREFIX_SEND)
12907 || orf_pfx_count) {
12908 vty_out(vty, " Outbound Route Filter (ORF):");
12909 if (CHECK_FLAG(p->af_sflags[afi][safi],
12910 PEER_STATUS_ORF_PREFIX_SEND))
12911 vty_out(vty, " sent;");
12912 if (orf_pfx_count)
12913 vty_out(vty, " received (%d entries)",
12914 orf_pfx_count);
12915 vty_out(vty, "\n");
12916 }
12917 if (CHECK_FLAG(p->af_sflags[afi][safi],
12918 PEER_STATUS_ORF_WAIT_REFRESH))
12919 vty_out(vty,
12920 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12921
12922 if (CHECK_FLAG(p->af_flags[afi][safi],
12923 PEER_FLAG_REFLECTOR_CLIENT))
12924 vty_out(vty, " Route-Reflector Client\n");
12925 if (CHECK_FLAG(p->af_flags[afi][safi],
12926 PEER_FLAG_RSERVER_CLIENT))
12927 vty_out(vty, " Route-Server Client\n");
12928 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12929 vty_out(vty,
12930 " Inbound soft reconfiguration allowed\n");
12931
12932 if (CHECK_FLAG(p->af_flags[afi][safi],
12933 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12934 vty_out(vty,
12935 " Private AS numbers (all) replaced in updates to this neighbor\n");
12936 else if (CHECK_FLAG(p->af_flags[afi][safi],
12937 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12938 vty_out(vty,
12939 " Private AS numbers replaced in updates to this neighbor\n");
12940 else if (CHECK_FLAG(p->af_flags[afi][safi],
12941 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12942 vty_out(vty,
12943 " Private AS numbers (all) removed in updates to this neighbor\n");
12944 else if (CHECK_FLAG(p->af_flags[afi][safi],
12945 PEER_FLAG_REMOVE_PRIVATE_AS))
12946 vty_out(vty,
12947 " Private AS numbers removed in updates to this neighbor\n");
12948
12949 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12950 if (CHECK_FLAG(p->af_flags[afi][safi],
12951 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12952 vty_out(vty,
12953 " Local AS allowed as path origin\n");
12954 else
12955 vty_out(vty,
12956 " Local AS allowed in path, %d occurrences\n",
12957 p->allowas_in[afi][safi]);
12958 }
12959
12960 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12961 vty_out(vty, " %s\n",
12962 bgp_addpath_names(p->addpath_type[afi][safi])
12963 ->human_description);
12964
12965 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12966 vty_out(vty,
12967 " Override ASNs in outbound updates if aspath equals remote-as\n");
12968
12969 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12970 || CHECK_FLAG(p->af_flags[afi][safi],
12971 PEER_FLAG_FORCE_NEXTHOP_SELF))
12972 vty_out(vty, " NEXT_HOP is always this router\n");
12973 if (CHECK_FLAG(p->af_flags[afi][safi],
12974 PEER_FLAG_AS_PATH_UNCHANGED))
12975 vty_out(vty,
12976 " AS_PATH is propagated unchanged to this neighbor\n");
12977 if (CHECK_FLAG(p->af_flags[afi][safi],
12978 PEER_FLAG_NEXTHOP_UNCHANGED))
12979 vty_out(vty,
12980 " NEXT_HOP is propagated unchanged to this neighbor\n");
12981 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12982 vty_out(vty,
12983 " MED is propagated unchanged to this neighbor\n");
12984 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12985 || CHECK_FLAG(p->af_flags[afi][safi],
12986 PEER_FLAG_SEND_EXT_COMMUNITY)
12987 || CHECK_FLAG(p->af_flags[afi][safi],
12988 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12989 vty_out(vty,
12990 " Community attribute sent to this neighbor");
12991 if (CHECK_FLAG(p->af_flags[afi][safi],
12992 PEER_FLAG_SEND_COMMUNITY)
12993 && CHECK_FLAG(p->af_flags[afi][safi],
12994 PEER_FLAG_SEND_EXT_COMMUNITY)
12995 && CHECK_FLAG(p->af_flags[afi][safi],
12996 PEER_FLAG_SEND_LARGE_COMMUNITY))
12997 vty_out(vty, "(all)\n");
12998 else if (CHECK_FLAG(p->af_flags[afi][safi],
12999 PEER_FLAG_SEND_LARGE_COMMUNITY))
13000 vty_out(vty, "(large)\n");
13001 else if (CHECK_FLAG(p->af_flags[afi][safi],
13002 PEER_FLAG_SEND_EXT_COMMUNITY))
13003 vty_out(vty, "(extended)\n");
13004 else
13005 vty_out(vty, "(standard)\n");
13006 }
13007 if (CHECK_FLAG(p->af_flags[afi][safi],
13008 PEER_FLAG_DEFAULT_ORIGINATE)) {
13009 vty_out(vty, " Default information originate,");
13010
13011 if (p->default_rmap[afi][safi].name)
13012 vty_out(vty, " default route-map %s%s,",
13013 p->default_rmap[afi][safi].map ? "*"
13014 : "",
13015 p->default_rmap[afi][safi].name);
13016 if (paf && PAF_SUBGRP(paf)
13017 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
13018 SUBGRP_STATUS_DEFAULT_ORIGINATE))
13019 vty_out(vty, " default sent\n");
13020 else
13021 vty_out(vty, " default not sent\n");
13022 }
13023
13024 /* advertise-vni-all */
13025 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
13026 if (is_evpn_enabled())
13027 vty_out(vty, " advertise-all-vni\n");
13028 }
13029
13030 if (filter->plist[FILTER_IN].name
13031 || filter->dlist[FILTER_IN].name
13032 || filter->aslist[FILTER_IN].name
13033 || filter->map[RMAP_IN].name)
13034 vty_out(vty, " Inbound path policy configured\n");
13035 if (filter->plist[FILTER_OUT].name
13036 || filter->dlist[FILTER_OUT].name
13037 || filter->aslist[FILTER_OUT].name
13038 || filter->map[RMAP_OUT].name || filter->usmap.name)
13039 vty_out(vty, " Outbound path policy configured\n");
13040
13041 /* prefix-list */
13042 if (filter->plist[FILTER_IN].name)
13043 vty_out(vty,
13044 " Incoming update prefix filter list is %s%s\n",
13045 filter->plist[FILTER_IN].plist ? "*" : "",
13046 filter->plist[FILTER_IN].name);
13047 if (filter->plist[FILTER_OUT].name)
13048 vty_out(vty,
13049 " Outgoing update prefix filter list is %s%s\n",
13050 filter->plist[FILTER_OUT].plist ? "*" : "",
13051 filter->plist[FILTER_OUT].name);
13052
13053 /* distribute-list */
13054 if (filter->dlist[FILTER_IN].name)
13055 vty_out(vty,
13056 " Incoming update network filter list is %s%s\n",
13057 filter->dlist[FILTER_IN].alist ? "*" : "",
13058 filter->dlist[FILTER_IN].name);
13059 if (filter->dlist[FILTER_OUT].name)
13060 vty_out(vty,
13061 " Outgoing update network filter list is %s%s\n",
13062 filter->dlist[FILTER_OUT].alist ? "*" : "",
13063 filter->dlist[FILTER_OUT].name);
13064
13065 /* filter-list. */
13066 if (filter->aslist[FILTER_IN].name)
13067 vty_out(vty,
13068 " Incoming update AS path filter list is %s%s\n",
13069 filter->aslist[FILTER_IN].aslist ? "*" : "",
13070 filter->aslist[FILTER_IN].name);
13071 if (filter->aslist[FILTER_OUT].name)
13072 vty_out(vty,
13073 " Outgoing update AS path filter list is %s%s\n",
13074 filter->aslist[FILTER_OUT].aslist ? "*" : "",
13075 filter->aslist[FILTER_OUT].name);
13076
13077 /* route-map. */
13078 if (filter->map[RMAP_IN].name)
13079 vty_out(vty,
13080 " Route map for incoming advertisements is %s%s\n",
13081 filter->map[RMAP_IN].map ? "*" : "",
13082 filter->map[RMAP_IN].name);
13083 if (filter->map[RMAP_OUT].name)
13084 vty_out(vty,
13085 " Route map for outgoing advertisements is %s%s\n",
13086 filter->map[RMAP_OUT].map ? "*" : "",
13087 filter->map[RMAP_OUT].name);
13088
13089 /* ebgp-requires-policy (inbound) */
13090 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
13091 && !bgp_inbound_policy_exists(p, filter))
13092 vty_out(vty,
13093 " Inbound updates discarded due to missing policy\n");
13094
13095 /* ebgp-requires-policy (outbound) */
13096 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
13097 && !bgp_outbound_policy_exists(p, filter))
13098 vty_out(vty,
13099 " Outbound updates discarded due to missing policy\n");
13100
13101 /* unsuppress-map */
13102 if (filter->usmap.name)
13103 vty_out(vty,
13104 " Route map for selective unsuppress is %s%s\n",
13105 filter->usmap.map ? "*" : "",
13106 filter->usmap.name);
13107
13108 /* advertise-map */
13109 if (filter->advmap.aname && filter->advmap.cname)
13110 vty_out(vty,
13111 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13112 filter->advmap.condition ? "EXIST"
13113 : "NON_EXIST",
13114 filter->advmap.cmap ? "*" : "",
13115 filter->advmap.cname,
13116 filter->advmap.amap ? "*" : "",
13117 filter->advmap.aname,
13118 filter->advmap.update_type ==
13119 UPDATE_TYPE_ADVERTISE
13120 ? "Advertise"
13121 : "Withdraw");
13122
13123 /* Receive prefix count */
13124 vty_out(vty, " %u accepted prefixes\n",
13125 p->pcount[afi][safi]);
13126
13127 /* maximum-prefix-out */
13128 if (CHECK_FLAG(p->af_flags[afi][safi],
13129 PEER_FLAG_MAX_PREFIX_OUT))
13130 vty_out(vty,
13131 " Maximum allowed prefixes sent %u\n",
13132 p->pmax_out[afi][safi]);
13133
13134 /* Maximum prefix */
13135 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
13136 vty_out(vty,
13137 " Maximum prefixes allowed %u%s\n",
13138 p->pmax[afi][safi],
13139 CHECK_FLAG(p->af_flags[afi][safi],
13140 PEER_FLAG_MAX_PREFIX_WARNING)
13141 ? " (warning-only)"
13142 : "");
13143 vty_out(vty, " Threshold for warning message %d%%",
13144 p->pmax_threshold[afi][safi]);
13145 if (p->pmax_restart[afi][safi])
13146 vty_out(vty, ", restart interval %d min",
13147 p->pmax_restart[afi][safi]);
13148 vty_out(vty, "\n");
13149 }
13150
13151 vty_out(vty, "\n");
13152 }
13153 }
13154
13155 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
13156 json_object *json)
13157 {
13158 struct bgp *bgp;
13159 char timebuf[BGP_UPTIME_LEN];
13160 char dn_flag[2];
13161 afi_t afi;
13162 safi_t safi;
13163 uint16_t i;
13164 uint8_t *msg;
13165 json_object *json_neigh = NULL;
13166 time_t epoch_tbuf;
13167 uint32_t sync_tcp_mss;
13168
13169 bgp = p->bgp;
13170
13171 if (use_json)
13172 json_neigh = json_object_new_object();
13173
13174 memset(dn_flag, '\0', sizeof(dn_flag));
13175 if (!p->conf_if && peer_dynamic_neighbor(p))
13176 dn_flag[0] = '*';
13177
13178 if (!use_json) {
13179 if (p->conf_if) /* Configured interface name. */
13180 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13181 &p->su);
13182 else /* Configured IP address. */
13183 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13184 p->host);
13185 }
13186
13187 if (use_json) {
13188 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13189 json_object_string_add(json_neigh, "bgpNeighborAddr",
13190 "none");
13191 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13192 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13193 "%pSU", &p->su);
13194
13195 asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation);
13196
13197 if (p->change_local_as)
13198 asn_asn2json(json_neigh, "localAs", p->change_local_as,
13199 bgp->asnotation);
13200 else
13201 asn_asn2json(json_neigh, "localAs", p->local_as,
13202 bgp->asnotation);
13203
13204 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13205 json_object_boolean_true_add(json_neigh,
13206 "localAsNoPrepend");
13207
13208 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13209 json_object_boolean_true_add(json_neigh,
13210 "localAsReplaceAs");
13211 } else {
13212 if ((p->as_type == AS_SPECIFIED) ||
13213 (p->as_type == AS_EXTERNAL) ||
13214 (p->as_type == AS_INTERNAL)) {
13215 vty_out(vty, "remote AS ");
13216 vty_out(vty, ASN_FORMAT(bgp->asnotation), &p->as);
13217 vty_out(vty, ", ");
13218 } else
13219 vty_out(vty, "remote AS Unspecified, ");
13220 vty_out(vty, "local AS ");
13221 vty_out(vty, ASN_FORMAT(bgp->asnotation),
13222 p->change_local_as ? &p->change_local_as
13223 : &p->local_as);
13224 vty_out(vty, "%s%s, ",
13225 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13226 ? " no-prepend"
13227 : "",
13228 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13229 ? " replace-as"
13230 : "");
13231 }
13232 /* peer type internal or confed-internal */
13233 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13234 if (use_json) {
13235 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13236 json_object_boolean_true_add(
13237 json_neigh, "nbrConfedInternalLink");
13238 else
13239 json_object_boolean_true_add(json_neigh,
13240 "nbrInternalLink");
13241 } else {
13242 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13243 vty_out(vty, "confed-internal link\n");
13244 else
13245 vty_out(vty, "internal link\n");
13246 }
13247 /* peer type external or confed-external */
13248 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13249 if (use_json) {
13250 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13251 json_object_boolean_true_add(
13252 json_neigh, "nbrConfedExternalLink");
13253 else
13254 json_object_boolean_true_add(json_neigh,
13255 "nbrExternalLink");
13256 } else {
13257 if (bgp_confederation_peers_check(bgp, p->as))
13258 vty_out(vty, "confed-external link\n");
13259 else
13260 vty_out(vty, "external link\n");
13261 }
13262 } else {
13263 if (use_json)
13264 json_object_boolean_true_add(json_neigh,
13265 "nbrUnspecifiedLink");
13266 else
13267 vty_out(vty, "unspecified link\n");
13268 }
13269
13270 /* Roles */
13271 if (use_json) {
13272 json_object_string_add(json_neigh, "localRole",
13273 bgp_get_name_by_role(p->local_role));
13274 json_object_string_add(json_neigh, "remoteRole",
13275 bgp_get_name_by_role(p->remote_role));
13276 } else {
13277 vty_out(vty, " Local Role: %s\n",
13278 bgp_get_name_by_role(p->local_role));
13279 vty_out(vty, " Remote Role: %s\n",
13280 bgp_get_name_by_role(p->remote_role));
13281 }
13282
13283
13284 /* Description. */
13285 if (p->desc) {
13286 if (use_json)
13287 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13288 else
13289 vty_out(vty, " Description: %s\n", p->desc);
13290 }
13291
13292 if (p->hostname) {
13293 if (use_json) {
13294 json_object_string_add(json_neigh, "hostname",
13295 p->hostname);
13296
13297 if (p->domainname)
13298 json_object_string_add(json_neigh, "domainname",
13299 p->domainname);
13300 } else {
13301 if (p->domainname && (p->domainname[0] != '\0'))
13302 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13303 p->domainname);
13304 else
13305 vty_out(vty, "Hostname: %s\n", p->hostname);
13306 }
13307 } else {
13308 if (use_json)
13309 json_object_string_add(json_neigh, "hostname",
13310 "Unknown");
13311 }
13312
13313 /* Peer-group */
13314 if (p->group) {
13315 if (use_json) {
13316 json_object_string_add(json_neigh, "peerGroup",
13317 p->group->name);
13318
13319 if (dn_flag[0]) {
13320 struct prefix prefix, *range = NULL;
13321
13322 if (sockunion2hostprefix(&(p->su), &prefix))
13323 range = peer_group_lookup_dynamic_neighbor_range(
13324 p->group, &prefix);
13325
13326 if (range) {
13327 json_object_string_addf(
13328 json_neigh,
13329 "peerSubnetRangeGroup", "%pFX",
13330 range);
13331 }
13332 }
13333 } else {
13334 vty_out(vty,
13335 " Member of peer-group %s for session parameters\n",
13336 p->group->name);
13337
13338 if (dn_flag[0]) {
13339 struct prefix prefix, *range = NULL;
13340
13341 if (sockunion2hostprefix(&(p->su), &prefix))
13342 range = peer_group_lookup_dynamic_neighbor_range(
13343 p->group, &prefix);
13344
13345 if (range) {
13346 vty_out(vty,
13347 " Belongs to the subnet range group: %pFX\n",
13348 range);
13349 }
13350 }
13351 }
13352 }
13353
13354 if (use_json) {
13355 /* Administrative shutdown. */
13356 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13357 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13358 json_object_boolean_true_add(json_neigh,
13359 "adminShutDown");
13360
13361 /* BGP Version. */
13362 json_object_int_add(json_neigh, "bgpVersion", 4);
13363 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13364 &p->remote_id);
13365 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13366 &bgp->router_id);
13367
13368 /* Confederation */
13369 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13370 && bgp_confederation_peers_check(bgp, p->as))
13371 json_object_boolean_true_add(json_neigh,
13372 "nbrCommonAdmin");
13373
13374 /* Status. */
13375 json_object_string_add(
13376 json_neigh, "bgpState",
13377 lookup_msg(bgp_status_msg, p->status, NULL));
13378
13379 if (peer_established(p)) {
13380 time_t uptime;
13381
13382 uptime = monotime(NULL);
13383 uptime -= p->uptime;
13384 epoch_tbuf = time(NULL) - uptime;
13385
13386 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13387 uptime * 1000);
13388 json_object_string_add(json_neigh, "bgpTimerUpString",
13389 peer_uptime(p->uptime, timebuf,
13390 BGP_UPTIME_LEN, 0,
13391 NULL));
13392 json_object_int_add(json_neigh,
13393 "bgpTimerUpEstablishedEpoch",
13394 epoch_tbuf);
13395 }
13396
13397 else if (p->status == Active) {
13398 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13399 json_object_string_add(json_neigh, "bgpStateIs",
13400 "passive");
13401 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13402 json_object_string_add(json_neigh, "bgpStateIs",
13403 "passiveNSF");
13404 }
13405
13406 /* read timer */
13407 time_t uptime;
13408 struct tm tm;
13409
13410 uptime = monotime(NULL);
13411 uptime -= p->readtime;
13412 gmtime_r(&uptime, &tm);
13413
13414 json_object_int_add(json_neigh, "bgpTimerLastRead",
13415 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13416 + (tm.tm_hour * 3600000));
13417
13418 uptime = monotime(NULL);
13419 uptime -= p->last_write;
13420 gmtime_r(&uptime, &tm);
13421
13422 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13423 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13424 + (tm.tm_hour * 3600000));
13425
13426 uptime = monotime(NULL);
13427 uptime -= p->update_time;
13428 gmtime_r(&uptime, &tm);
13429
13430 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13431 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13432 + (tm.tm_hour * 3600000));
13433
13434 /* Configured timer values. */
13435 json_object_int_add(json_neigh,
13436 "bgpTimerConfiguredHoldTimeMsecs",
13437 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13438 ? p->holdtime * 1000
13439 : bgp->default_holdtime * 1000);
13440 json_object_int_add(json_neigh,
13441 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13442 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13443 ? p->keepalive * 1000
13444 : bgp->default_keepalive * 1000);
13445 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13446 p->v_holdtime * 1000);
13447 json_object_int_add(json_neigh,
13448 "bgpTimerKeepAliveIntervalMsecs",
13449 p->v_keepalive * 1000);
13450 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13451 json_object_int_add(json_neigh,
13452 "bgpTimerDelayOpenTimeMsecs",
13453 p->v_delayopen * 1000);
13454 }
13455
13456 /* Configured and Synced tcp-mss value for peer */
13457 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13458 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13459 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13460 p->tcp_mss);
13461 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13462 sync_tcp_mss);
13463 }
13464
13465 /* Extended Optional Parameters Length for BGP OPEN Message */
13466 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13467 json_object_boolean_true_add(
13468 json_neigh, "extendedOptionalParametersLength");
13469 else
13470 json_object_boolean_false_add(
13471 json_neigh, "extendedOptionalParametersLength");
13472
13473 /* Conditional advertisements */
13474 json_object_int_add(
13475 json_neigh,
13476 "bgpTimerConfiguredConditionalAdvertisementsSec",
13477 bgp->condition_check_period);
13478 if (thread_is_scheduled(bgp->t_condition_check))
13479 json_object_int_add(
13480 json_neigh,
13481 "bgpTimerUntilConditionalAdvertisementsSec",
13482 thread_timer_remain_second(
13483 bgp->t_condition_check));
13484 } else {
13485 /* Administrative shutdown. */
13486 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13487 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13488 vty_out(vty, " Administratively shut down\n");
13489
13490 /* BGP Version. */
13491 vty_out(vty, " BGP version 4");
13492 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13493 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13494
13495 /* Confederation */
13496 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13497 && bgp_confederation_peers_check(bgp, p->as))
13498 vty_out(vty,
13499 " Neighbor under common administration\n");
13500
13501 /* Status. */
13502 vty_out(vty, " BGP state = %s",
13503 lookup_msg(bgp_status_msg, p->status, NULL));
13504
13505 if (peer_established(p))
13506 vty_out(vty, ", up for %8s",
13507 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13508 0, NULL));
13509
13510 else if (p->status == Active) {
13511 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13512 vty_out(vty, " (passive)");
13513 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13514 vty_out(vty, " (NSF passive)");
13515 }
13516 vty_out(vty, "\n");
13517
13518 /* read timer */
13519 vty_out(vty, " Last read %s",
13520 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13521 NULL));
13522 vty_out(vty, ", Last write %s\n",
13523 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13524 NULL));
13525
13526 /* Configured timer values. */
13527 vty_out(vty,
13528 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13529 p->v_holdtime, p->v_keepalive);
13530 vty_out(vty, " Configured hold time is %d seconds",
13531 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13532 ? p->holdtime
13533 : bgp->default_holdtime);
13534 vty_out(vty, ", keepalive interval is %d seconds\n",
13535 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13536 ? p->keepalive
13537 : bgp->default_keepalive);
13538 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13539 vty_out(vty,
13540 " Configured DelayOpenTime is %d seconds\n",
13541 p->delayopen);
13542
13543 /* Configured and synced tcp-mss value for peer */
13544 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13545 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13546 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13547 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13548 }
13549
13550 /* Extended Optional Parameters Length for BGP OPEN Message */
13551 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13552 vty_out(vty,
13553 " Extended Optional Parameters Length is enabled\n");
13554
13555 /* Conditional advertisements */
13556 vty_out(vty,
13557 " Configured conditional advertisements interval is %d seconds\n",
13558 bgp->condition_check_period);
13559 if (thread_is_scheduled(bgp->t_condition_check))
13560 vty_out(vty,
13561 " Time until conditional advertisements begin is %lu seconds\n",
13562 thread_timer_remain_second(
13563 bgp->t_condition_check));
13564 }
13565 /* Capability. */
13566 if (peer_established(p) &&
13567 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13568 if (use_json) {
13569 json_object *json_cap = NULL;
13570
13571 json_cap = json_object_new_object();
13572
13573 /* AS4 */
13574 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13575 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13576 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13577 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13578 json_object_string_add(
13579 json_cap, "4byteAs",
13580 "advertisedAndReceived");
13581 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13582 json_object_string_add(json_cap,
13583 "4byteAs",
13584 "advertised");
13585 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13586 json_object_string_add(json_cap,
13587 "4byteAs",
13588 "received");
13589 }
13590
13591 /* Extended Message Support */
13592 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13593 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13594 json_object_string_add(json_cap,
13595 "extendedMessage",
13596 "advertisedAndReceived");
13597 else if (CHECK_FLAG(p->cap,
13598 PEER_CAP_EXTENDED_MESSAGE_ADV))
13599 json_object_string_add(json_cap,
13600 "extendedMessage",
13601 "advertised");
13602 else if (CHECK_FLAG(p->cap,
13603 PEER_CAP_EXTENDED_MESSAGE_RCV))
13604 json_object_string_add(json_cap,
13605 "extendedMessage",
13606 "received");
13607
13608 /* AddPath */
13609 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13610 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13611 json_object *json_add = NULL;
13612 const char *print_store;
13613
13614 json_add = json_object_new_object();
13615
13616 FOREACH_AFI_SAFI (afi, safi) {
13617 json_object *json_sub = NULL;
13618 json_sub = json_object_new_object();
13619 print_store = get_afi_safi_str(
13620 afi, safi, true);
13621
13622 if (CHECK_FLAG(
13623 p->af_cap[afi][safi],
13624 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13625 CHECK_FLAG(
13626 p->af_cap[afi][safi],
13627 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13628 if (CHECK_FLAG(
13629 p->af_cap[afi]
13630 [safi],
13631 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13632 CHECK_FLAG(
13633 p->af_cap[afi]
13634 [safi],
13635 PEER_CAP_ADDPATH_AF_TX_RCV))
13636 json_object_boolean_true_add(
13637 json_sub,
13638 "txAdvertisedAndReceived");
13639 else if (
13640 CHECK_FLAG(
13641 p->af_cap[afi]
13642 [safi],
13643 PEER_CAP_ADDPATH_AF_TX_ADV))
13644 json_object_boolean_true_add(
13645 json_sub,
13646 "txAdvertised");
13647 else if (
13648 CHECK_FLAG(
13649 p->af_cap[afi]
13650 [safi],
13651 PEER_CAP_ADDPATH_AF_TX_RCV))
13652 json_object_boolean_true_add(
13653 json_sub,
13654 "txReceived");
13655 }
13656
13657 if (CHECK_FLAG(
13658 p->af_cap[afi][safi],
13659 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13660 CHECK_FLAG(
13661 p->af_cap[afi][safi],
13662 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13663 if (CHECK_FLAG(
13664 p->af_cap[afi]
13665 [safi],
13666 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13667 CHECK_FLAG(
13668 p->af_cap[afi]
13669 [safi],
13670 PEER_CAP_ADDPATH_AF_RX_RCV))
13671 json_object_boolean_true_add(
13672 json_sub,
13673 "rxAdvertisedAndReceived");
13674 else if (
13675 CHECK_FLAG(
13676 p->af_cap[afi]
13677 [safi],
13678 PEER_CAP_ADDPATH_AF_RX_ADV))
13679 json_object_boolean_true_add(
13680 json_sub,
13681 "rxAdvertised");
13682 else if (
13683 CHECK_FLAG(
13684 p->af_cap[afi]
13685 [safi],
13686 PEER_CAP_ADDPATH_AF_RX_RCV))
13687 json_object_boolean_true_add(
13688 json_sub,
13689 "rxReceived");
13690 }
13691
13692 if (CHECK_FLAG(
13693 p->af_cap[afi][safi],
13694 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13695 CHECK_FLAG(
13696 p->af_cap[afi][safi],
13697 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13698 CHECK_FLAG(
13699 p->af_cap[afi][safi],
13700 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13701 CHECK_FLAG(
13702 p->af_cap[afi][safi],
13703 PEER_CAP_ADDPATH_AF_RX_RCV))
13704 json_object_object_add(
13705 json_add, print_store,
13706 json_sub);
13707 else
13708 json_object_free(json_sub);
13709 }
13710
13711 json_object_object_add(json_cap, "addPath",
13712 json_add);
13713 }
13714
13715 /* Dynamic */
13716 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13717 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13718 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13719 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13720 json_object_string_add(
13721 json_cap, "dynamic",
13722 "advertisedAndReceived");
13723 else if (CHECK_FLAG(p->cap,
13724 PEER_CAP_DYNAMIC_ADV))
13725 json_object_string_add(json_cap,
13726 "dynamic",
13727 "advertised");
13728 else if (CHECK_FLAG(p->cap,
13729 PEER_CAP_DYNAMIC_RCV))
13730 json_object_string_add(json_cap,
13731 "dynamic",
13732 "received");
13733 }
13734
13735 /* Role */
13736 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13737 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13738 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13739 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13740 json_object_string_add(
13741 json_cap, "role",
13742 "advertisedAndReceived");
13743 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13744 json_object_string_add(json_cap, "role",
13745 "advertised");
13746 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13747 json_object_string_add(json_cap, "role",
13748 "received");
13749 }
13750
13751 /* Extended nexthop */
13752 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13753 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13754 json_object *json_nxt = NULL;
13755 const char *print_store;
13756
13757
13758 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13759 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13760 json_object_string_add(
13761 json_cap, "extendedNexthop",
13762 "advertisedAndReceived");
13763 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13764 json_object_string_add(
13765 json_cap, "extendedNexthop",
13766 "advertised");
13767 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13768 json_object_string_add(
13769 json_cap, "extendedNexthop",
13770 "received");
13771
13772 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13773 json_nxt = json_object_new_object();
13774
13775 for (safi = SAFI_UNICAST;
13776 safi < SAFI_MAX; safi++) {
13777 if (CHECK_FLAG(
13778 p->af_cap[AFI_IP]
13779 [safi],
13780 PEER_CAP_ENHE_AF_RCV)) {
13781 print_store =
13782 get_afi_safi_str(
13783 AFI_IP,
13784 safi,
13785 true);
13786 json_object_string_add(
13787 json_nxt,
13788 print_store,
13789 "recieved"); /* misspelled for compatibility */
13790 }
13791 }
13792 json_object_object_add(
13793 json_cap,
13794 "extendedNexthopFamililesByPeer",
13795 json_nxt);
13796 }
13797 }
13798
13799 /* Long-lived Graceful Restart */
13800 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13801 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13802 json_object *json_llgr = NULL;
13803 const char *afi_safi_str;
13804
13805 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13806 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13807 json_object_string_add(
13808 json_cap,
13809 "longLivedGracefulRestart",
13810 "advertisedAndReceived");
13811 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13812 json_object_string_add(
13813 json_cap,
13814 "longLivedGracefulRestart",
13815 "advertised");
13816 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13817 json_object_string_add(
13818 json_cap,
13819 "longLivedGracefulRestart",
13820 "received");
13821
13822 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13823 json_llgr = json_object_new_object();
13824
13825 FOREACH_AFI_SAFI (afi, safi) {
13826 if (CHECK_FLAG(
13827 p->af_cap[afi]
13828 [safi],
13829 PEER_CAP_ENHE_AF_RCV)) {
13830 afi_safi_str =
13831 get_afi_safi_str(
13832 afi,
13833 safi,
13834 true);
13835 json_object_string_add(
13836 json_llgr,
13837 afi_safi_str,
13838 "received");
13839 }
13840 }
13841 json_object_object_add(
13842 json_cap,
13843 "longLivedGracefulRestartByPeer",
13844 json_llgr);
13845 }
13846 }
13847
13848 /* Route Refresh */
13849 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13850 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13851 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13852 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13853 (CHECK_FLAG(p->cap,
13854 PEER_CAP_REFRESH_NEW_RCV) ||
13855 CHECK_FLAG(p->cap,
13856 PEER_CAP_REFRESH_OLD_RCV))) {
13857 if (CHECK_FLAG(
13858 p->cap,
13859 PEER_CAP_REFRESH_OLD_RCV) &&
13860 CHECK_FLAG(
13861 p->cap,
13862 PEER_CAP_REFRESH_NEW_RCV))
13863 json_object_string_add(
13864 json_cap,
13865 "routeRefresh",
13866 "advertisedAndReceivedOldNew");
13867 else {
13868 if (CHECK_FLAG(
13869 p->cap,
13870 PEER_CAP_REFRESH_OLD_RCV))
13871 json_object_string_add(
13872 json_cap,
13873 "routeRefresh",
13874 "advertisedAndReceivedOld");
13875 else
13876 json_object_string_add(
13877 json_cap,
13878 "routeRefresh",
13879 "advertisedAndReceivedNew");
13880 }
13881 } else if (CHECK_FLAG(p->cap,
13882 PEER_CAP_REFRESH_ADV))
13883 json_object_string_add(json_cap,
13884 "routeRefresh",
13885 "advertised");
13886 else if (CHECK_FLAG(p->cap,
13887 PEER_CAP_REFRESH_NEW_RCV) ||
13888 CHECK_FLAG(p->cap,
13889 PEER_CAP_REFRESH_OLD_RCV))
13890 json_object_string_add(json_cap,
13891 "routeRefresh",
13892 "received");
13893 }
13894
13895 /* Enhanced Route Refresh */
13896 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13897 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13898 if (CHECK_FLAG(p->cap,
13899 PEER_CAP_ENHANCED_RR_ADV) &&
13900 CHECK_FLAG(p->cap,
13901 PEER_CAP_ENHANCED_RR_RCV))
13902 json_object_string_add(
13903 json_cap,
13904 "enhancedRouteRefresh",
13905 "advertisedAndReceived");
13906 else if (CHECK_FLAG(p->cap,
13907 PEER_CAP_ENHANCED_RR_ADV))
13908 json_object_string_add(
13909 json_cap,
13910 "enhancedRouteRefresh",
13911 "advertised");
13912 else if (CHECK_FLAG(p->cap,
13913 PEER_CAP_ENHANCED_RR_RCV))
13914 json_object_string_add(
13915 json_cap,
13916 "enhancedRouteRefresh",
13917 "received");
13918 }
13919
13920 /* Multiprotocol Extensions */
13921 json_object *json_multi = NULL;
13922
13923 json_multi = json_object_new_object();
13924
13925 FOREACH_AFI_SAFI (afi, safi) {
13926 if (p->afc_adv[afi][safi] ||
13927 p->afc_recv[afi][safi]) {
13928 json_object *json_exten = NULL;
13929 json_exten = json_object_new_object();
13930
13931 if (p->afc_adv[afi][safi] &&
13932 p->afc_recv[afi][safi])
13933 json_object_boolean_true_add(
13934 json_exten,
13935 "advertisedAndReceived");
13936 else if (p->afc_adv[afi][safi])
13937 json_object_boolean_true_add(
13938 json_exten,
13939 "advertised");
13940 else if (p->afc_recv[afi][safi])
13941 json_object_boolean_true_add(
13942 json_exten, "received");
13943
13944 json_object_object_add(
13945 json_multi,
13946 get_afi_safi_str(afi, safi,
13947 true),
13948 json_exten);
13949 }
13950 }
13951 json_object_object_add(json_cap,
13952 "multiprotocolExtensions",
13953 json_multi);
13954
13955 /* Hostname capabilities */
13956 json_object *json_hname = NULL;
13957
13958 json_hname = json_object_new_object();
13959
13960 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13961 json_object_string_add(
13962 json_hname, "advHostName",
13963 bgp->peer_self->hostname
13964 ? bgp->peer_self->hostname
13965 : "n/a");
13966 json_object_string_add(
13967 json_hname, "advDomainName",
13968 bgp->peer_self->domainname
13969 ? bgp->peer_self->domainname
13970 : "n/a");
13971 }
13972
13973
13974 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13975 json_object_string_add(
13976 json_hname, "rcvHostName",
13977 p->hostname ? p->hostname : "n/a");
13978 json_object_string_add(
13979 json_hname, "rcvDomainName",
13980 p->domainname ? p->domainname : "n/a");
13981 }
13982
13983 json_object_object_add(json_cap, "hostName",
13984 json_hname);
13985
13986 /* Software Version capability */
13987 json_object *json_soft_version = NULL;
13988
13989 json_soft_version = json_object_new_object();
13990
13991 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV))
13992 json_object_string_add(
13993 json_soft_version,
13994 "advertisedSoftwareVersion",
13995 cmd_software_version_get());
13996
13997 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV))
13998 json_object_string_add(
13999 json_soft_version,
14000 "receivedSoftwareVersion",
14001 p->soft_version ? p->soft_version
14002 : "n/a");
14003
14004 json_object_object_add(json_cap, "softwareVersion",
14005 json_soft_version);
14006
14007 /* Graceful Restart */
14008 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14009 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14010 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
14011 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14012 json_object_string_add(
14013 json_cap, "gracefulRestart",
14014 "advertisedAndReceived");
14015 else if (CHECK_FLAG(p->cap,
14016 PEER_CAP_RESTART_ADV))
14017 json_object_string_add(
14018 json_cap,
14019 "gracefulRestartCapability",
14020 "advertised");
14021 else if (CHECK_FLAG(p->cap,
14022 PEER_CAP_RESTART_RCV))
14023 json_object_string_add(
14024 json_cap,
14025 "gracefulRestartCapability",
14026 "received");
14027
14028 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14029 int restart_af_count = 0;
14030 json_object *json_restart = NULL;
14031 json_restart = json_object_new_object();
14032
14033 json_object_int_add(
14034 json_cap,
14035 "gracefulRestartRemoteTimerMsecs",
14036 p->v_gr_restart * 1000);
14037
14038 FOREACH_AFI_SAFI (afi, safi) {
14039 if (CHECK_FLAG(
14040 p->af_cap[afi]
14041 [safi],
14042 PEER_CAP_RESTART_AF_RCV)) {
14043 json_object *json_sub =
14044 NULL;
14045 json_sub =
14046 json_object_new_object();
14047
14048 if (CHECK_FLAG(
14049 p->af_cap
14050 [afi]
14051 [safi],
14052 PEER_CAP_RESTART_AF_PRESERVE_RCV))
14053 json_object_boolean_true_add(
14054 json_sub,
14055 "preserved");
14056 restart_af_count++;
14057 json_object_object_add(
14058 json_restart,
14059 get_afi_safi_str(
14060 afi,
14061 safi,
14062 true),
14063 json_sub);
14064 }
14065 }
14066 if (!restart_af_count) {
14067 json_object_string_add(
14068 json_cap,
14069 "addressFamiliesByPeer",
14070 "none");
14071 json_object_free(json_restart);
14072 } else
14073 json_object_object_add(
14074 json_cap,
14075 "addressFamiliesByPeer",
14076 json_restart);
14077 }
14078 }
14079 json_object_object_add(
14080 json_neigh, "neighborCapabilities", json_cap);
14081 } else {
14082 vty_out(vty, " Neighbor capabilities:\n");
14083
14084 /* AS4 */
14085 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
14086 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
14087 vty_out(vty, " 4 Byte AS:");
14088 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
14089 vty_out(vty, " advertised");
14090 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
14091 vty_out(vty, " %sreceived",
14092 CHECK_FLAG(p->cap,
14093 PEER_CAP_AS4_ADV)
14094 ? "and "
14095 : "");
14096 vty_out(vty, "\n");
14097 }
14098
14099 /* Extended Message Support */
14100 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
14101 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
14102 vty_out(vty, " Extended Message:");
14103 if (CHECK_FLAG(p->cap,
14104 PEER_CAP_EXTENDED_MESSAGE_ADV))
14105 vty_out(vty, " advertised");
14106 if (CHECK_FLAG(p->cap,
14107 PEER_CAP_EXTENDED_MESSAGE_RCV))
14108 vty_out(vty, " %sreceived",
14109 CHECK_FLAG(
14110 p->cap,
14111 PEER_CAP_EXTENDED_MESSAGE_ADV)
14112 ? "and "
14113 : "");
14114 vty_out(vty, "\n");
14115 }
14116
14117 /* AddPath */
14118 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
14119 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
14120 vty_out(vty, " AddPath:\n");
14121
14122 FOREACH_AFI_SAFI (afi, safi) {
14123 if (CHECK_FLAG(
14124 p->af_cap[afi][safi],
14125 PEER_CAP_ADDPATH_AF_TX_ADV) ||
14126 CHECK_FLAG(
14127 p->af_cap[afi][safi],
14128 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14129 vty_out(vty, " %s: TX ",
14130 get_afi_safi_str(
14131 afi, safi,
14132 false));
14133
14134 if (CHECK_FLAG(
14135 p->af_cap[afi]
14136 [safi],
14137 PEER_CAP_ADDPATH_AF_TX_ADV))
14138 vty_out(vty,
14139 "advertised");
14140
14141 if (CHECK_FLAG(
14142 p->af_cap[afi]
14143 [safi],
14144 PEER_CAP_ADDPATH_AF_TX_RCV))
14145 vty_out(vty,
14146 "%sreceived",
14147 CHECK_FLAG(
14148 p->af_cap
14149 [afi]
14150 [safi],
14151 PEER_CAP_ADDPATH_AF_TX_ADV)
14152 ? " and "
14153 : "");
14154
14155 vty_out(vty, "\n");
14156 }
14157
14158 if (CHECK_FLAG(
14159 p->af_cap[afi][safi],
14160 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14161 CHECK_FLAG(
14162 p->af_cap[afi][safi],
14163 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14164 vty_out(vty, " %s: RX ",
14165 get_afi_safi_str(
14166 afi, safi,
14167 false));
14168
14169 if (CHECK_FLAG(
14170 p->af_cap[afi]
14171 [safi],
14172 PEER_CAP_ADDPATH_AF_RX_ADV))
14173 vty_out(vty,
14174 "advertised");
14175
14176 if (CHECK_FLAG(
14177 p->af_cap[afi]
14178 [safi],
14179 PEER_CAP_ADDPATH_AF_RX_RCV))
14180 vty_out(vty,
14181 "%sreceived",
14182 CHECK_FLAG(
14183 p->af_cap
14184 [afi]
14185 [safi],
14186 PEER_CAP_ADDPATH_AF_RX_ADV)
14187 ? " and "
14188 : "");
14189
14190 vty_out(vty, "\n");
14191 }
14192 }
14193 }
14194
14195 /* Dynamic */
14196 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14197 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14198 vty_out(vty, " Dynamic:");
14199 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14200 vty_out(vty, " advertised");
14201 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14202 vty_out(vty, " %sreceived",
14203 CHECK_FLAG(p->cap,
14204 PEER_CAP_DYNAMIC_ADV)
14205 ? "and "
14206 : "");
14207 vty_out(vty, "\n");
14208 }
14209
14210 /* Role */
14211 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14212 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14213 vty_out(vty, " Role:");
14214 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14215 vty_out(vty, " advertised");
14216 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14217 vty_out(vty, " %sreceived",
14218 CHECK_FLAG(p->cap,
14219 PEER_CAP_ROLE_ADV)
14220 ? "and "
14221 : "");
14222 vty_out(vty, "\n");
14223 }
14224
14225 /* Extended nexthop */
14226 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14227 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14228 vty_out(vty, " Extended nexthop:");
14229 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14230 vty_out(vty, " advertised");
14231 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14232 vty_out(vty, " %sreceived",
14233 CHECK_FLAG(p->cap,
14234 PEER_CAP_ENHE_ADV)
14235 ? "and "
14236 : "");
14237 vty_out(vty, "\n");
14238
14239 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
14240 vty_out(vty,
14241 " Address families by peer:\n ");
14242 for (safi = SAFI_UNICAST;
14243 safi < SAFI_MAX; safi++)
14244 if (CHECK_FLAG(
14245 p->af_cap[AFI_IP]
14246 [safi],
14247 PEER_CAP_ENHE_AF_RCV))
14248 vty_out(vty,
14249 " %s\n",
14250 get_afi_safi_str(
14251 AFI_IP,
14252 safi,
14253 false));
14254 }
14255 }
14256
14257 /* Long-lived Graceful Restart */
14258 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14259 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14260 vty_out(vty,
14261 " Long-lived Graceful Restart:");
14262 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14263 vty_out(vty, " advertised");
14264 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14265 vty_out(vty, " %sreceived",
14266 CHECK_FLAG(p->cap,
14267 PEER_CAP_LLGR_ADV)
14268 ? "and "
14269 : "");
14270 vty_out(vty, "\n");
14271
14272 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14273 vty_out(vty,
14274 " Address families by peer:\n");
14275 FOREACH_AFI_SAFI (afi, safi)
14276 if (CHECK_FLAG(
14277 p->af_cap[afi]
14278 [safi],
14279 PEER_CAP_LLGR_AF_RCV))
14280 vty_out(vty,
14281 " %s\n",
14282 get_afi_safi_str(
14283 afi,
14284 safi,
14285 false));
14286 }
14287 }
14288
14289 /* Route Refresh */
14290 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14291 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14292 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14293 vty_out(vty, " Route refresh:");
14294 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14295 vty_out(vty, " advertised");
14296 if (CHECK_FLAG(p->cap,
14297 PEER_CAP_REFRESH_NEW_RCV) ||
14298 CHECK_FLAG(p->cap,
14299 PEER_CAP_REFRESH_OLD_RCV))
14300 vty_out(vty, " %sreceived(%s)",
14301 CHECK_FLAG(p->cap,
14302 PEER_CAP_REFRESH_ADV)
14303 ? "and "
14304 : "",
14305 (CHECK_FLAG(
14306 p->cap,
14307 PEER_CAP_REFRESH_OLD_RCV) &&
14308 CHECK_FLAG(
14309 p->cap,
14310 PEER_CAP_REFRESH_NEW_RCV))
14311 ? "old & new"
14312 : CHECK_FLAG(
14313 p->cap,
14314 PEER_CAP_REFRESH_OLD_RCV)
14315 ? "old"
14316 : "new");
14317
14318 vty_out(vty, "\n");
14319 }
14320
14321 /* Enhanced Route Refresh */
14322 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14323 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14324 vty_out(vty, " Enhanced Route Refresh:");
14325 if (CHECK_FLAG(p->cap,
14326 PEER_CAP_ENHANCED_RR_ADV))
14327 vty_out(vty, " advertised");
14328 if (CHECK_FLAG(p->cap,
14329 PEER_CAP_ENHANCED_RR_RCV))
14330 vty_out(vty, " %sreceived",
14331 CHECK_FLAG(p->cap,
14332 PEER_CAP_REFRESH_ADV)
14333 ? "and "
14334 : "");
14335 vty_out(vty, "\n");
14336 }
14337
14338 /* Multiprotocol Extensions */
14339 FOREACH_AFI_SAFI (afi, safi)
14340 if (p->afc_adv[afi][safi] ||
14341 p->afc_recv[afi][safi]) {
14342 vty_out(vty, " Address Family %s:",
14343 get_afi_safi_str(afi, safi,
14344 false));
14345 if (p->afc_adv[afi][safi])
14346 vty_out(vty, " advertised");
14347 if (p->afc_recv[afi][safi])
14348 vty_out(vty, " %sreceived",
14349 p->afc_adv[afi][safi]
14350 ? "and "
14351 : "");
14352 vty_out(vty, "\n");
14353 }
14354
14355 /* Hostname capability */
14356 vty_out(vty, " Hostname Capability:");
14357
14358 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14359 vty_out(vty,
14360 " advertised (name: %s,domain name: %s)",
14361 bgp->peer_self->hostname
14362 ? bgp->peer_self->hostname
14363 : "n/a",
14364 bgp->peer_self->domainname
14365 ? bgp->peer_self->domainname
14366 : "n/a");
14367 } else {
14368 vty_out(vty, " not advertised");
14369 }
14370
14371 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14372 vty_out(vty,
14373 " received (name: %s,domain name: %s)",
14374 p->hostname ? p->hostname : "n/a",
14375 p->domainname ? p->domainname : "n/a");
14376 } else {
14377 vty_out(vty, " not received");
14378 }
14379
14380 vty_out(vty, "\n");
14381
14382 /* Software Version capability */
14383 vty_out(vty, " Version Capability:");
14384
14385 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV)) {
14386 vty_out(vty,
14387 " advertised software version (%s)",
14388 cmd_software_version_get());
14389 } else
14390 vty_out(vty, " not advertised");
14391
14392 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV)) {
14393 vty_out(vty, " received software version (%s)",
14394 p->soft_version ? p->soft_version
14395 : "n/a");
14396 } else
14397 vty_out(vty, " not received");
14398
14399 vty_out(vty, "\n");
14400
14401 /* Graceful Restart */
14402 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14403 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14404 vty_out(vty,
14405 " Graceful Restart Capability:");
14406 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14407 vty_out(vty, " advertised");
14408 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14409 vty_out(vty, " %sreceived",
14410 CHECK_FLAG(p->cap,
14411 PEER_CAP_RESTART_ADV)
14412 ? "and "
14413 : "");
14414 vty_out(vty, "\n");
14415
14416 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14417 int restart_af_count = 0;
14418
14419 vty_out(vty,
14420 " Remote Restart timer is %d seconds\n",
14421 p->v_gr_restart);
14422 vty_out(vty,
14423 " Address families by peer:\n ");
14424
14425 FOREACH_AFI_SAFI (afi, safi)
14426 if (CHECK_FLAG(
14427 p->af_cap[afi]
14428 [safi],
14429 PEER_CAP_RESTART_AF_RCV)) {
14430 vty_out(vty, "%s%s(%s)",
14431 restart_af_count
14432 ? ", "
14433 : "",
14434 get_afi_safi_str(
14435 afi,
14436 safi,
14437 false),
14438 CHECK_FLAG(
14439 p->af_cap
14440 [afi]
14441 [safi],
14442 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14443 ? "preserved"
14444 : "not preserved");
14445 restart_af_count++;
14446 }
14447 if (!restart_af_count)
14448 vty_out(vty, "none");
14449 vty_out(vty, "\n");
14450 }
14451 } /* Graceful Restart */
14452 }
14453 }
14454
14455 /* graceful restart information */
14456 json_object *json_grace = NULL;
14457 json_object *json_grace_send = NULL;
14458 json_object *json_grace_recv = NULL;
14459 int eor_send_af_count = 0;
14460 int eor_receive_af_count = 0;
14461
14462 if (use_json) {
14463 json_grace = json_object_new_object();
14464 json_grace_send = json_object_new_object();
14465 json_grace_recv = json_object_new_object();
14466
14467 if ((peer_established(p)) &&
14468 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14469 FOREACH_AFI_SAFI (afi, safi) {
14470 if (CHECK_FLAG(p->af_sflags[afi][safi],
14471 PEER_STATUS_EOR_SEND)) {
14472 json_object_boolean_true_add(
14473 json_grace_send,
14474 get_afi_safi_str(afi, safi,
14475 true));
14476 eor_send_af_count++;
14477 }
14478 }
14479 FOREACH_AFI_SAFI (afi, safi) {
14480 if (CHECK_FLAG(p->af_sflags[afi][safi],
14481 PEER_STATUS_EOR_RECEIVED)) {
14482 json_object_boolean_true_add(
14483 json_grace_recv,
14484 get_afi_safi_str(afi, safi,
14485 true));
14486 eor_receive_af_count++;
14487 }
14488 }
14489 }
14490 json_object_object_add(json_grace, "endOfRibSend",
14491 json_grace_send);
14492 json_object_object_add(json_grace, "endOfRibRecv",
14493 json_grace_recv);
14494
14495
14496 if (p->t_gr_restart)
14497 json_object_int_add(
14498 json_grace, "gracefulRestartTimerMsecs",
14499 thread_timer_remain_second(p->t_gr_restart) *
14500 1000);
14501
14502 if (p->t_gr_stale)
14503 json_object_int_add(
14504 json_grace, "gracefulStalepathTimerMsecs",
14505 thread_timer_remain_second(p->t_gr_stale) *
14506 1000);
14507 /* more gr info in new format */
14508 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14509 json_object_object_add(json_neigh, "gracefulRestartInfo",
14510 json_grace);
14511 } else {
14512 vty_out(vty, " Graceful restart information:\n");
14513 if ((peer_established(p)) &&
14514 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14515
14516 vty_out(vty, " End-of-RIB send: ");
14517 FOREACH_AFI_SAFI (afi, safi) {
14518 if (CHECK_FLAG(p->af_sflags[afi][safi],
14519 PEER_STATUS_EOR_SEND)) {
14520 vty_out(vty, "%s%s",
14521 eor_send_af_count ? ", " : "",
14522 get_afi_safi_str(afi, safi,
14523 false));
14524 eor_send_af_count++;
14525 }
14526 }
14527 vty_out(vty, "\n");
14528 vty_out(vty, " End-of-RIB received: ");
14529 FOREACH_AFI_SAFI (afi, safi) {
14530 if (CHECK_FLAG(p->af_sflags[afi][safi],
14531 PEER_STATUS_EOR_RECEIVED)) {
14532 vty_out(vty, "%s%s",
14533 eor_receive_af_count ? ", "
14534 : "",
14535 get_afi_safi_str(afi, safi,
14536 false));
14537 eor_receive_af_count++;
14538 }
14539 }
14540 vty_out(vty, "\n");
14541 }
14542
14543 if (p->t_gr_restart)
14544 vty_out(vty,
14545 " The remaining time of restart timer is %ld\n",
14546 thread_timer_remain_second(p->t_gr_restart));
14547
14548 if (p->t_gr_stale)
14549 vty_out(vty,
14550 " The remaining time of stalepath timer is %ld\n",
14551 thread_timer_remain_second(p->t_gr_stale));
14552
14553 /* more gr info in new format */
14554 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14555 }
14556
14557 if (use_json) {
14558 json_object *json_stat = NULL;
14559 json_stat = json_object_new_object();
14560 /* Packet counts. */
14561
14562 atomic_size_t outq_count, inq_count;
14563 outq_count = atomic_load_explicit(&p->obuf->count,
14564 memory_order_relaxed);
14565 inq_count = atomic_load_explicit(&p->ibuf->count,
14566 memory_order_relaxed);
14567
14568 json_object_int_add(json_stat, "depthInq",
14569 (unsigned long)inq_count);
14570 json_object_int_add(json_stat, "depthOutq",
14571 (unsigned long)outq_count);
14572 json_object_int_add(json_stat, "opensSent",
14573 atomic_load_explicit(&p->open_out,
14574 memory_order_relaxed));
14575 json_object_int_add(json_stat, "opensRecv",
14576 atomic_load_explicit(&p->open_in,
14577 memory_order_relaxed));
14578 json_object_int_add(json_stat, "notificationsSent",
14579 atomic_load_explicit(&p->notify_out,
14580 memory_order_relaxed));
14581 json_object_int_add(json_stat, "notificationsRecv",
14582 atomic_load_explicit(&p->notify_in,
14583 memory_order_relaxed));
14584 json_object_int_add(json_stat, "updatesSent",
14585 atomic_load_explicit(&p->update_out,
14586 memory_order_relaxed));
14587 json_object_int_add(json_stat, "updatesRecv",
14588 atomic_load_explicit(&p->update_in,
14589 memory_order_relaxed));
14590 json_object_int_add(json_stat, "keepalivesSent",
14591 atomic_load_explicit(&p->keepalive_out,
14592 memory_order_relaxed));
14593 json_object_int_add(json_stat, "keepalivesRecv",
14594 atomic_load_explicit(&p->keepalive_in,
14595 memory_order_relaxed));
14596 json_object_int_add(json_stat, "routeRefreshSent",
14597 atomic_load_explicit(&p->refresh_out,
14598 memory_order_relaxed));
14599 json_object_int_add(json_stat, "routeRefreshRecv",
14600 atomic_load_explicit(&p->refresh_in,
14601 memory_order_relaxed));
14602 json_object_int_add(json_stat, "capabilitySent",
14603 atomic_load_explicit(&p->dynamic_cap_out,
14604 memory_order_relaxed));
14605 json_object_int_add(json_stat, "capabilityRecv",
14606 atomic_load_explicit(&p->dynamic_cap_in,
14607 memory_order_relaxed));
14608 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14609 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14610 json_object_object_add(json_neigh, "messageStats", json_stat);
14611 } else {
14612 atomic_size_t outq_count, inq_count, open_out, open_in,
14613 notify_out, notify_in, update_out, update_in,
14614 keepalive_out, keepalive_in, refresh_out, refresh_in,
14615 dynamic_cap_out, dynamic_cap_in;
14616 outq_count = atomic_load_explicit(&p->obuf->count,
14617 memory_order_relaxed);
14618 inq_count = atomic_load_explicit(&p->ibuf->count,
14619 memory_order_relaxed);
14620 open_out = atomic_load_explicit(&p->open_out,
14621 memory_order_relaxed);
14622 open_in =
14623 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14624 notify_out = atomic_load_explicit(&p->notify_out,
14625 memory_order_relaxed);
14626 notify_in = atomic_load_explicit(&p->notify_in,
14627 memory_order_relaxed);
14628 update_out = atomic_load_explicit(&p->update_out,
14629 memory_order_relaxed);
14630 update_in = atomic_load_explicit(&p->update_in,
14631 memory_order_relaxed);
14632 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14633 memory_order_relaxed);
14634 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14635 memory_order_relaxed);
14636 refresh_out = atomic_load_explicit(&p->refresh_out,
14637 memory_order_relaxed);
14638 refresh_in = atomic_load_explicit(&p->refresh_in,
14639 memory_order_relaxed);
14640 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14641 memory_order_relaxed);
14642 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14643 memory_order_relaxed);
14644
14645 /* Packet counts. */
14646 vty_out(vty, " Message statistics:\n");
14647 vty_out(vty, " Inq depth is %zu\n", inq_count);
14648 vty_out(vty, " Outq depth is %zu\n", outq_count);
14649 vty_out(vty, " Sent Rcvd\n");
14650 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14651 open_in);
14652 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14653 notify_in);
14654 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14655 update_in);
14656 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14657 keepalive_in);
14658 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14659 refresh_in);
14660 vty_out(vty, " Capability: %10zu %10zu\n",
14661 dynamic_cap_out, dynamic_cap_in);
14662 vty_out(vty, " Total: %10u %10u\n",
14663 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14664 }
14665
14666 if (use_json) {
14667 /* advertisement-interval */
14668 json_object_int_add(json_neigh,
14669 "minBtwnAdvertisementRunsTimerMsecs",
14670 p->v_routeadv * 1000);
14671
14672 /* Update-source. */
14673 if (p->update_if || p->update_source) {
14674 if (p->update_if)
14675 json_object_string_add(json_neigh,
14676 "updateSource",
14677 p->update_if);
14678 else if (p->update_source)
14679 json_object_string_addf(json_neigh,
14680 "updateSource", "%pSU",
14681 p->update_source);
14682 }
14683 } else {
14684 /* advertisement-interval */
14685 vty_out(vty,
14686 " Minimum time between advertisement runs is %d seconds\n",
14687 p->v_routeadv);
14688
14689 /* Update-source. */
14690 if (p->update_if || p->update_source) {
14691 vty_out(vty, " Update source is ");
14692 if (p->update_if)
14693 vty_out(vty, "%s", p->update_if);
14694 else if (p->update_source)
14695 vty_out(vty, "%pSU", p->update_source);
14696 vty_out(vty, "\n");
14697 }
14698
14699 vty_out(vty, "\n");
14700 }
14701
14702 /* Address Family Information */
14703 json_object *json_hold = NULL;
14704
14705 if (use_json)
14706 json_hold = json_object_new_object();
14707
14708 FOREACH_AFI_SAFI (afi, safi)
14709 if (p->afc[afi][safi])
14710 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14711 json_hold);
14712
14713 if (use_json) {
14714 json_object_object_add(json_neigh, "addressFamilyInfo",
14715 json_hold);
14716 json_object_int_add(json_neigh, "connectionsEstablished",
14717 p->established);
14718 json_object_int_add(json_neigh, "connectionsDropped",
14719 p->dropped);
14720 } else
14721 vty_out(vty, " Connections established %d; dropped %d\n",
14722 p->established, p->dropped);
14723
14724 if (!p->last_reset) {
14725 if (use_json)
14726 json_object_string_add(json_neigh, "lastReset",
14727 "never");
14728 else
14729 vty_out(vty, " Last reset never\n");
14730 } else {
14731 if (use_json) {
14732 time_t uptime;
14733 struct tm tm;
14734
14735 uptime = monotime(NULL);
14736 uptime -= p->resettime;
14737 gmtime_r(&uptime, &tm);
14738
14739 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14740 (tm.tm_sec * 1000)
14741 + (tm.tm_min * 60000)
14742 + (tm.tm_hour * 3600000));
14743 bgp_show_peer_reset(NULL, p, json_neigh, true);
14744 } else {
14745 vty_out(vty, " Last reset %s, ",
14746 peer_uptime(p->resettime, timebuf,
14747 BGP_UPTIME_LEN, 0, NULL));
14748
14749 bgp_show_peer_reset(vty, p, NULL, false);
14750 if (p->last_reset_cause_size) {
14751 msg = p->last_reset_cause;
14752 vty_out(vty,
14753 " Message received that caused BGP to send a NOTIFICATION:\n ");
14754 for (i = 1; i <= p->last_reset_cause_size;
14755 i++) {
14756 vty_out(vty, "%02X", *msg++);
14757
14758 if (i != p->last_reset_cause_size) {
14759 if (i % 16 == 0) {
14760 vty_out(vty, "\n ");
14761 } else if (i % 4 == 0) {
14762 vty_out(vty, " ");
14763 }
14764 }
14765 }
14766 vty_out(vty, "\n");
14767 }
14768 }
14769 }
14770
14771 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14772 if (use_json)
14773 json_object_boolean_true_add(json_neigh,
14774 "prefixesConfigExceedMax");
14775 else
14776 vty_out(vty,
14777 " Peer had exceeded the max. no. of prefixes configured.\n");
14778
14779 if (p->t_pmax_restart) {
14780 if (use_json) {
14781 json_object_boolean_true_add(
14782 json_neigh, "reducePrefixNumFrom");
14783 json_object_int_add(json_neigh,
14784 "restartInTimerMsec",
14785 thread_timer_remain_second(
14786 p->t_pmax_restart)
14787 * 1000);
14788 } else
14789 vty_out(vty,
14790 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14791 p->host, thread_timer_remain_second(
14792 p->t_pmax_restart));
14793 } else {
14794 if (use_json)
14795 json_object_boolean_true_add(
14796 json_neigh,
14797 "reducePrefixNumAndClearIpBgp");
14798 else
14799 vty_out(vty,
14800 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14801 p->host);
14802 }
14803 }
14804
14805 /* EBGP Multihop and GTSM */
14806 if (p->sort != BGP_PEER_IBGP) {
14807 if (use_json) {
14808 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14809 json_object_int_add(json_neigh,
14810 "externalBgpNbrMaxHopsAway",
14811 p->gtsm_hops);
14812 else
14813 json_object_int_add(json_neigh,
14814 "externalBgpNbrMaxHopsAway",
14815 p->ttl);
14816 } else {
14817 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14818 vty_out(vty,
14819 " External BGP neighbor may be up to %d hops away.\n",
14820 p->gtsm_hops);
14821 else
14822 vty_out(vty,
14823 " External BGP neighbor may be up to %d hops away.\n",
14824 p->ttl);
14825 }
14826 } else {
14827 if (use_json) {
14828 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14829 json_object_int_add(json_neigh,
14830 "internalBgpNbrMaxHopsAway",
14831 p->gtsm_hops);
14832 else
14833 json_object_int_add(json_neigh,
14834 "internalBgpNbrMaxHopsAway",
14835 p->ttl);
14836 } else {
14837 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14838 vty_out(vty,
14839 " Internal BGP neighbor may be up to %d hops away.\n",
14840 p->gtsm_hops);
14841 else
14842 vty_out(vty,
14843 " Internal BGP neighbor may be up to %d hops away.\n",
14844 p->ttl);
14845 }
14846 }
14847
14848 /* Local address. */
14849 if (p->su_local) {
14850 if (use_json) {
14851 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14852 p->su_local);
14853 json_object_int_add(json_neigh, "portLocal",
14854 ntohs(p->su_local->sin.sin_port));
14855 } else
14856 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14857 p->su_local, ntohs(p->su_local->sin.sin_port));
14858 } else {
14859 if (use_json) {
14860 json_object_string_add(json_neigh, "hostLocal",
14861 "Unknown");
14862 json_object_int_add(json_neigh, "portLocal", -1);
14863 }
14864 }
14865
14866 /* Remote address. */
14867 if (p->su_remote) {
14868 if (use_json) {
14869 json_object_string_addf(json_neigh, "hostForeign",
14870 "%pSU", p->su_remote);
14871 json_object_int_add(json_neigh, "portForeign",
14872 ntohs(p->su_remote->sin.sin_port));
14873 } else
14874 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14875 p->su_remote,
14876 ntohs(p->su_remote->sin.sin_port));
14877 } else {
14878 if (use_json) {
14879 json_object_string_add(json_neigh, "hostForeign",
14880 "Unknown");
14881 json_object_int_add(json_neigh, "portForeign", -1);
14882 }
14883 }
14884
14885 /* Nexthop display. */
14886 if (p->su_local) {
14887 if (use_json) {
14888 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14889 &p->nexthop.v4);
14890 json_object_string_addf(json_neigh, "nexthopGlobal",
14891 "%pI6", &p->nexthop.v6_global);
14892 json_object_string_addf(json_neigh, "nexthopLocal",
14893 "%pI6", &p->nexthop.v6_local);
14894 if (p->shared_network)
14895 json_object_string_add(json_neigh,
14896 "bgpConnection",
14897 "sharedNetwork");
14898 else
14899 json_object_string_add(json_neigh,
14900 "bgpConnection",
14901 "nonSharedNetwork");
14902 } else {
14903 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14904 vty_out(vty, "Nexthop global: %pI6\n",
14905 &p->nexthop.v6_global);
14906 vty_out(vty, "Nexthop local: %pI6\n",
14907 &p->nexthop.v6_local);
14908 vty_out(vty, "BGP connection: %s\n",
14909 p->shared_network ? "shared network"
14910 : "non shared network");
14911 }
14912 } else {
14913 if (use_json) {
14914 json_object_string_add(json_neigh, "nexthop",
14915 "Unknown");
14916 json_object_string_add(json_neigh, "nexthopGlobal",
14917 "Unknown");
14918 json_object_string_add(json_neigh, "nexthopLocal",
14919 "Unknown");
14920 json_object_string_add(json_neigh, "bgpConnection",
14921 "Unknown");
14922 }
14923 }
14924
14925 /* Timer information. */
14926 if (use_json) {
14927 json_object_int_add(json_neigh, "connectRetryTimer",
14928 p->v_connect);
14929 if (peer_established(p)) {
14930 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14931 p->rtt);
14932 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14933 json_object_int_add(json_neigh,
14934 "shutdownRttInMsecs",
14935 p->rtt_expected);
14936 json_object_int_add(json_neigh,
14937 "shutdownRttAfterCount",
14938 p->rtt_keepalive_rcv);
14939 }
14940 }
14941 if (p->t_start)
14942 json_object_int_add(
14943 json_neigh, "nextStartTimerDueInMsecs",
14944 thread_timer_remain_second(p->t_start) * 1000);
14945 if (p->t_connect)
14946 json_object_int_add(
14947 json_neigh, "nextConnectTimerDueInMsecs",
14948 thread_timer_remain_second(p->t_connect)
14949 * 1000);
14950 if (p->t_routeadv) {
14951 json_object_int_add(json_neigh, "mraiInterval",
14952 p->v_routeadv);
14953 json_object_int_add(
14954 json_neigh, "mraiTimerExpireInMsecs",
14955 thread_timer_remain_second(p->t_routeadv)
14956 * 1000);
14957 }
14958 if (p->password)
14959 json_object_int_add(json_neigh, "authenticationEnabled",
14960 1);
14961
14962 if (p->t_read)
14963 json_object_string_add(json_neigh, "readThread", "on");
14964 else
14965 json_object_string_add(json_neigh, "readThread", "off");
14966
14967 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14968 json_object_string_add(json_neigh, "writeThread", "on");
14969 else
14970 json_object_string_add(json_neigh, "writeThread",
14971 "off");
14972 } else {
14973 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14974 p->v_connect);
14975 if (peer_established(p)) {
14976 vty_out(vty, "Estimated round trip time: %d ms\n",
14977 p->rtt);
14978 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14979 vty_out(vty,
14980 "Shutdown when RTT > %dms, count > %u\n",
14981 p->rtt_expected, p->rtt_keepalive_rcv);
14982 }
14983 if (p->t_start)
14984 vty_out(vty, "Next start timer due in %ld seconds\n",
14985 thread_timer_remain_second(p->t_start));
14986 if (p->t_connect)
14987 vty_out(vty, "Next connect timer due in %ld seconds\n",
14988 thread_timer_remain_second(p->t_connect));
14989 if (p->t_routeadv)
14990 vty_out(vty,
14991 "MRAI (interval %u) timer expires in %ld seconds\n",
14992 p->v_routeadv,
14993 thread_timer_remain_second(p->t_routeadv));
14994 if (p->password)
14995 vty_out(vty, "Peer Authentication Enabled\n");
14996
14997 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14998 p->t_read ? "on" : "off",
14999 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
15000 ? "on"
15001 : "off", p->fd);
15002 }
15003
15004 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
15005 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
15006 bgp_capability_vty_out(vty, p, use_json, json_neigh);
15007
15008 if (!use_json)
15009 vty_out(vty, "\n");
15010
15011 /* BFD information. */
15012 if (p->bfd_config)
15013 bgp_bfd_show_info(vty, p, json_neigh);
15014
15015 if (use_json) {
15016 if (p->conf_if) /* Configured interface name. */
15017 json_object_object_add(json, p->conf_if, json_neigh);
15018 else /* Configured IP address. */
15019 json_object_object_add(json, p->host, json_neigh);
15020 }
15021 }
15022
15023 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
15024 enum show_type type,
15025 union sockunion *su,
15026 const char *conf_if, afi_t afi,
15027 json_object *json)
15028 {
15029 struct listnode *node, *nnode;
15030 struct peer *peer;
15031 bool found = false;
15032 safi_t safi = SAFI_UNICAST;
15033 json_object *json_neighbor = NULL;
15034
15035 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15036
15037 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15038 continue;
15039
15040 if ((peer->afc[afi][safi]) == 0)
15041 continue;
15042
15043 if (json)
15044 json_neighbor = json_object_new_object();
15045
15046 if (type == show_all) {
15047 bgp_show_peer_gr_status(vty, peer, json_neighbor);
15048
15049 if (json)
15050 json_object_object_add(json, peer->host,
15051 json_neighbor);
15052
15053 } else if (type == show_peer) {
15054 if (conf_if) {
15055 if ((peer->conf_if
15056 && !strcmp(peer->conf_if, conf_if))
15057 || (peer->hostname
15058 && !strcmp(peer->hostname, conf_if))) {
15059 found = true;
15060 bgp_show_peer_gr_status(vty, peer,
15061 json_neighbor);
15062 }
15063 } else {
15064 if (sockunion_same(&peer->su, su)) {
15065 found = true;
15066 bgp_show_peer_gr_status(vty, peer,
15067 json_neighbor);
15068 }
15069 }
15070 if (json) {
15071 if (found)
15072 json_object_object_add(json, peer->host,
15073 json_neighbor);
15074 else
15075 json_object_free(json_neighbor);
15076 }
15077 }
15078
15079 if (found)
15080 break;
15081 }
15082
15083 if (type == show_peer && !found) {
15084 if (json)
15085 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15086 else
15087 vty_out(vty, "%% No such neighbor\n");
15088 }
15089
15090 if (!json)
15091 vty_out(vty, "\n");
15092
15093 return CMD_SUCCESS;
15094 }
15095
15096 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
15097 enum show_type type, union sockunion *su,
15098 const char *conf_if, bool use_json,
15099 json_object *json)
15100 {
15101 struct listnode *node, *nnode;
15102 struct peer *peer;
15103 int find = 0;
15104 bool nbr_output = false;
15105 afi_t afi = AFI_MAX;
15106 safi_t safi = SAFI_MAX;
15107
15108 if (type == show_ipv4_peer || type == show_ipv4_all) {
15109 afi = AFI_IP;
15110 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
15111 afi = AFI_IP6;
15112 }
15113
15114 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15115 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15116 continue;
15117
15118 switch (type) {
15119 case show_all:
15120 bgp_show_peer(vty, peer, use_json, json);
15121 nbr_output = true;
15122 break;
15123 case show_peer:
15124 if (conf_if) {
15125 if ((peer->conf_if
15126 && !strcmp(peer->conf_if, conf_if))
15127 || (peer->hostname
15128 && !strcmp(peer->hostname, conf_if))) {
15129 find = 1;
15130 bgp_show_peer(vty, peer, use_json,
15131 json);
15132 }
15133 } else {
15134 if (sockunion_same(&peer->su, su)) {
15135 find = 1;
15136 bgp_show_peer(vty, peer, use_json,
15137 json);
15138 }
15139 }
15140 break;
15141 case show_ipv4_peer:
15142 case show_ipv6_peer:
15143 FOREACH_SAFI (safi) {
15144 if (peer->afc[afi][safi]) {
15145 if (conf_if) {
15146 if ((peer->conf_if
15147 && !strcmp(peer->conf_if, conf_if))
15148 || (peer->hostname
15149 && !strcmp(peer->hostname, conf_if))) {
15150 find = 1;
15151 bgp_show_peer(vty, peer, use_json,
15152 json);
15153 break;
15154 }
15155 } else {
15156 if (sockunion_same(&peer->su, su)) {
15157 find = 1;
15158 bgp_show_peer(vty, peer, use_json,
15159 json);
15160 break;
15161 }
15162 }
15163 }
15164 }
15165 break;
15166 case show_ipv4_all:
15167 case show_ipv6_all:
15168 FOREACH_SAFI (safi) {
15169 if (peer->afc[afi][safi]) {
15170 bgp_show_peer(vty, peer, use_json, json);
15171 nbr_output = true;
15172 break;
15173 }
15174 }
15175 break;
15176 }
15177 }
15178
15179 if ((type == show_peer || type == show_ipv4_peer ||
15180 type == show_ipv6_peer) && !find) {
15181 if (use_json)
15182 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15183 else
15184 vty_out(vty, "%% No such neighbor in this view/vrf\n");
15185 }
15186
15187 if (type != show_peer && type != show_ipv4_peer &&
15188 type != show_ipv6_peer && !nbr_output && !use_json)
15189 vty_out(vty, "%% No BGP neighbors found\n");
15190
15191 if (use_json) {
15192 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15193 json, JSON_C_TO_STRING_PRETTY));
15194 } else {
15195 vty_out(vty, "\n");
15196 }
15197
15198 return CMD_SUCCESS;
15199 }
15200
15201 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15202 enum show_type type,
15203 const char *ip_str,
15204 afi_t afi, json_object *json)
15205 {
15206
15207 int ret;
15208 struct bgp *bgp;
15209 union sockunion su;
15210
15211 bgp = bgp_get_default();
15212
15213 if (!bgp)
15214 return;
15215
15216 if (!json)
15217 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
15218
15219 if (ip_str) {
15220 ret = str2sockunion(ip_str, &su);
15221 if (ret < 0)
15222 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15223 ip_str, afi, json);
15224 else
15225 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15226 NULL, afi, json);
15227 } else
15228 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15229 afi, json);
15230 }
15231
15232 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15233 enum show_type type,
15234 const char *ip_str,
15235 bool use_json)
15236 {
15237 struct listnode *node, *nnode;
15238 struct bgp *bgp;
15239 union sockunion su;
15240 json_object *json = NULL;
15241 int ret, is_first = 1;
15242 bool nbr_output = false;
15243
15244 if (use_json)
15245 vty_out(vty, "{\n");
15246
15247 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15248 nbr_output = true;
15249 if (use_json) {
15250 if (!(json = json_object_new_object())) {
15251 flog_err(
15252 EC_BGP_JSON_MEM_ERROR,
15253 "Unable to allocate memory for JSON object");
15254 vty_out(vty,
15255 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15256 return;
15257 }
15258
15259 json_object_int_add(json, "vrfId",
15260 (bgp->vrf_id == VRF_UNKNOWN)
15261 ? -1
15262 : (int64_t)bgp->vrf_id);
15263 json_object_string_add(
15264 json, "vrfName",
15265 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15266 ? VRF_DEFAULT_NAME
15267 : bgp->name);
15268
15269 if (!is_first)
15270 vty_out(vty, ",\n");
15271 else
15272 is_first = 0;
15273
15274 vty_out(vty, "\"%s\":",
15275 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15276 ? VRF_DEFAULT_NAME
15277 : bgp->name);
15278 } else {
15279 vty_out(vty, "\nInstance %s:\n",
15280 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15281 ? VRF_DEFAULT_NAME
15282 : bgp->name);
15283 }
15284
15285 if (type == show_peer || type == show_ipv4_peer ||
15286 type == show_ipv6_peer) {
15287 ret = str2sockunion(ip_str, &su);
15288 if (ret < 0)
15289 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15290 use_json, json);
15291 else
15292 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15293 use_json, json);
15294 } else {
15295 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15296 use_json, json);
15297 }
15298 json_object_free(json);
15299 json = NULL;
15300 }
15301
15302 if (use_json)
15303 vty_out(vty, "}\n");
15304 else if (!nbr_output)
15305 vty_out(vty, "%% BGP instance not found\n");
15306 }
15307
15308 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15309 enum show_type type, const char *ip_str,
15310 bool use_json)
15311 {
15312 int ret;
15313 struct bgp *bgp;
15314 union sockunion su;
15315 json_object *json = NULL;
15316
15317 if (name) {
15318 if (strmatch(name, "all")) {
15319 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15320 use_json);
15321 return CMD_SUCCESS;
15322 } else {
15323 bgp = bgp_lookup_by_name(name);
15324 if (!bgp) {
15325 if (use_json) {
15326 json = json_object_new_object();
15327 vty_json(vty, json);
15328 } else
15329 vty_out(vty,
15330 "%% BGP instance not found\n");
15331
15332 return CMD_WARNING;
15333 }
15334 }
15335 } else {
15336 bgp = bgp_get_default();
15337 }
15338
15339 if (bgp) {
15340 json = json_object_new_object();
15341 if (ip_str) {
15342 ret = str2sockunion(ip_str, &su);
15343 if (ret < 0)
15344 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15345 use_json, json);
15346 else
15347 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15348 use_json, json);
15349 } else {
15350 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15351 json);
15352 }
15353 json_object_free(json);
15354 } else {
15355 if (use_json)
15356 vty_out(vty, "{}\n");
15357 else
15358 vty_out(vty, "%% BGP instance not found\n");
15359 }
15360
15361 return CMD_SUCCESS;
15362 }
15363
15364
15365
15366 /* "show [ip] bgp neighbors graceful-restart" commands. */
15367 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15368 show_ip_bgp_neighbors_graceful_restart_cmd,
15369 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15370 SHOW_STR
15371 BGP_STR
15372 IP_STR
15373 IPV6_STR
15374 NEIGHBOR_STR
15375 "Neighbor to display information about\n"
15376 "Neighbor to display information about\n"
15377 "Neighbor on BGP configured interface\n"
15378 GR_SHOW
15379 JSON_STR)
15380 {
15381 char *sh_arg = NULL;
15382 enum show_type sh_type;
15383 int idx = 0;
15384 afi_t afi = AFI_MAX;
15385 bool uj = use_json(argc, argv);
15386
15387 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15388 afi = AFI_MAX;
15389
15390 idx++;
15391
15392 if (argv_find(argv, argc, "A.B.C.D", &idx)
15393 || argv_find(argv, argc, "X:X::X:X", &idx)
15394 || argv_find(argv, argc, "WORD", &idx)) {
15395 sh_type = show_peer;
15396 sh_arg = argv[idx]->arg;
15397 } else
15398 sh_type = show_all;
15399
15400 if (!argv_find(argv, argc, "graceful-restart", &idx))
15401 return CMD_SUCCESS;
15402
15403
15404 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15405 afi, uj);
15406 }
15407
15408 /* "show [ip] bgp neighbors" commands. */
15409 DEFUN (show_ip_bgp_neighbors,
15410 show_ip_bgp_neighbors_cmd,
15411 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15412 SHOW_STR
15413 IP_STR
15414 BGP_STR
15415 BGP_INSTANCE_HELP_STR
15416 BGP_AF_STR
15417 BGP_AF_STR
15418 "Detailed information on TCP and BGP neighbor connections\n"
15419 "Neighbor to display information about\n"
15420 "Neighbor to display information about\n"
15421 "Neighbor on BGP configured interface\n"
15422 JSON_STR)
15423 {
15424 char *vrf = NULL;
15425 char *sh_arg = NULL;
15426 enum show_type sh_type;
15427 afi_t afi = AFI_MAX;
15428
15429 bool uj = use_json(argc, argv);
15430
15431 int idx = 0;
15432
15433 /* [<vrf> VIEWVRFNAME] */
15434 if (argv_find(argv, argc, "vrf", &idx)) {
15435 vrf = argv[idx + 1]->arg;
15436 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15437 vrf = NULL;
15438 } else if (argv_find(argv, argc, "view", &idx))
15439 /* [<view> VIEWVRFNAME] */
15440 vrf = argv[idx + 1]->arg;
15441
15442 idx++;
15443
15444 if (argv_find(argv, argc, "ipv4", &idx)) {
15445 sh_type = show_ipv4_all;
15446 afi = AFI_IP;
15447 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15448 sh_type = show_ipv6_all;
15449 afi = AFI_IP6;
15450 } else {
15451 sh_type = show_all;
15452 }
15453
15454 if (argv_find(argv, argc, "A.B.C.D", &idx)
15455 || argv_find(argv, argc, "X:X::X:X", &idx)
15456 || argv_find(argv, argc, "WORD", &idx)) {
15457 sh_type = show_peer;
15458 sh_arg = argv[idx]->arg;
15459 }
15460
15461 if (sh_type == show_peer && afi == AFI_IP) {
15462 sh_type = show_ipv4_peer;
15463 } else if (sh_type == show_peer && afi == AFI_IP6) {
15464 sh_type = show_ipv6_peer;
15465 }
15466
15467 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15468 }
15469
15470 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15471 paths' and `show ip mbgp paths'. Those functions results are the
15472 same.*/
15473 DEFUN (show_ip_bgp_paths,
15474 show_ip_bgp_paths_cmd,
15475 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15476 SHOW_STR
15477 IP_STR
15478 BGP_STR
15479 BGP_SAFI_HELP_STR
15480 "Path information\n")
15481 {
15482 vty_out(vty, "Address Refcnt Path\n");
15483 aspath_print_all_vty(vty);
15484 return CMD_SUCCESS;
15485 }
15486
15487 #include "hash.h"
15488
15489 static void community_show_all_iterator(struct hash_bucket *bucket,
15490 struct vty *vty)
15491 {
15492 struct community *com;
15493
15494 com = (struct community *)bucket->data;
15495 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15496 community_str(com, false, false));
15497 }
15498
15499 /* Show BGP's community internal data. */
15500 DEFUN (show_ip_bgp_community_info,
15501 show_ip_bgp_community_info_cmd,
15502 "show [ip] bgp community-info",
15503 SHOW_STR
15504 IP_STR
15505 BGP_STR
15506 "List all bgp community information\n")
15507 {
15508 vty_out(vty, "Address Refcnt Community\n");
15509
15510 hash_iterate(community_hash(),
15511 (void (*)(struct hash_bucket *,
15512 void *))community_show_all_iterator,
15513 vty);
15514
15515 return CMD_SUCCESS;
15516 }
15517
15518 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15519 struct vty *vty)
15520 {
15521 struct lcommunity *lcom;
15522
15523 lcom = (struct lcommunity *)bucket->data;
15524 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15525 lcommunity_str(lcom, false, false));
15526 }
15527
15528 /* Show BGP's community internal data. */
15529 DEFUN (show_ip_bgp_lcommunity_info,
15530 show_ip_bgp_lcommunity_info_cmd,
15531 "show ip bgp large-community-info",
15532 SHOW_STR
15533 IP_STR
15534 BGP_STR
15535 "List all bgp large-community information\n")
15536 {
15537 vty_out(vty, "Address Refcnt Large-community\n");
15538
15539 hash_iterate(lcommunity_hash(),
15540 (void (*)(struct hash_bucket *,
15541 void *))lcommunity_show_all_iterator,
15542 vty);
15543
15544 return CMD_SUCCESS;
15545 }
15546 /* Graceful Restart */
15547
15548 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15549 struct bgp *bgp)
15550 {
15551
15552
15553 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15554
15555 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15556
15557 switch (bgp_global_gr_mode) {
15558
15559 case GLOBAL_HELPER:
15560 vty_out(vty, "Global BGP GR Mode : Helper\n");
15561 break;
15562
15563 case GLOBAL_GR:
15564 vty_out(vty, "Global BGP GR Mode : Restart\n");
15565 break;
15566
15567 case GLOBAL_DISABLE:
15568 vty_out(vty, "Global BGP GR Mode : Disable\n");
15569 break;
15570
15571 case GLOBAL_INVALID:
15572 vty_out(vty,
15573 "Global BGP GR Mode Invalid\n");
15574 break;
15575 }
15576 vty_out(vty, "\n");
15577 }
15578
15579 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15580 enum show_type type,
15581 const char *ip_str,
15582 afi_t afi, bool use_json)
15583 {
15584 json_object *json = NULL;
15585
15586 if (use_json)
15587 json = json_object_new_object();
15588
15589 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15590 afi = AFI_IP;
15591
15592 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15593
15594 bgp_show_neighbor_graceful_restart_vty(
15595 vty, type, ip_str, afi, json);
15596 afi++;
15597 }
15598 } else if (afi != AFI_MAX) {
15599 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15600 json);
15601 } else {
15602 if (json)
15603 json_object_free(json);
15604 return CMD_ERR_INCOMPLETE;
15605 }
15606
15607 if (json)
15608 vty_json(vty, json);
15609
15610 return CMD_SUCCESS;
15611 }
15612 /* Graceful Restart */
15613
15614 DEFUN (show_ip_bgp_attr_info,
15615 show_ip_bgp_attr_info_cmd,
15616 "show [ip] bgp attribute-info",
15617 SHOW_STR
15618 IP_STR
15619 BGP_STR
15620 "List all bgp attribute information\n")
15621 {
15622 attr_show_all(vty);
15623 return CMD_SUCCESS;
15624 }
15625
15626 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15627 afi_t afi, safi_t safi,
15628 bool use_json, json_object *json)
15629 {
15630 struct bgp *bgp;
15631 struct listnode *node;
15632 char *vname;
15633 char *ecom_str;
15634 enum vpn_policy_direction dir;
15635
15636 if (json) {
15637 json_object *json_import_vrfs = NULL;
15638 json_object *json_export_vrfs = NULL;
15639
15640 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15641
15642 if (!bgp) {
15643 vty_json(vty, json);
15644
15645 return CMD_WARNING;
15646 }
15647
15648 /* Provide context for the block */
15649 json_object_string_add(json, "vrf", name ? name : "default");
15650 json_object_string_add(json, "afiSafi",
15651 get_afi_safi_str(afi, safi, true));
15652
15653 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15654 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15655 json_object_string_add(json, "importFromVrfs", "none");
15656 json_object_string_add(json, "importRts", "none");
15657 } else {
15658 json_import_vrfs = json_object_new_array();
15659
15660 for (ALL_LIST_ELEMENTS_RO(
15661 bgp->vpn_policy[afi].import_vrf,
15662 node, vname))
15663 json_object_array_add(json_import_vrfs,
15664 json_object_new_string(vname));
15665
15666 json_object_object_add(json, "importFromVrfs",
15667 json_import_vrfs);
15668 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15669 if (bgp->vpn_policy[afi].rtlist[dir]) {
15670 ecom_str = ecommunity_ecom2str(
15671 bgp->vpn_policy[afi].rtlist[dir],
15672 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15673 json_object_string_add(json, "importRts",
15674 ecom_str);
15675 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15676 } else
15677 json_object_string_add(json, "importRts",
15678 "none");
15679 }
15680
15681 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15682 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15683 json_object_string_add(json, "exportToVrfs", "none");
15684 json_object_string_add(json, "routeDistinguisher",
15685 "none");
15686 json_object_string_add(json, "exportRts", "none");
15687 } else {
15688 json_export_vrfs = json_object_new_array();
15689
15690 for (ALL_LIST_ELEMENTS_RO(
15691 bgp->vpn_policy[afi].export_vrf,
15692 node, vname))
15693 json_object_array_add(json_export_vrfs,
15694 json_object_new_string(vname));
15695 json_object_object_add(json, "exportToVrfs",
15696 json_export_vrfs);
15697 json_object_string_addf(
15698 json, "routeDistinguisher", "%s",
15699 bgp->vpn_policy[afi].tovpn_rd_pretty);
15700 dir = BGP_VPN_POLICY_DIR_TOVPN;
15701 if (bgp->vpn_policy[afi].rtlist[dir]) {
15702 ecom_str = ecommunity_ecom2str(
15703 bgp->vpn_policy[afi].rtlist[dir],
15704 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15705 json_object_string_add(json, "exportRts",
15706 ecom_str);
15707 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15708 } else
15709 json_object_string_add(json, "exportRts",
15710 "none");
15711 }
15712
15713 if (use_json) {
15714 vty_json(vty, json);
15715 }
15716 } else {
15717 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15718
15719 if (!bgp) {
15720 vty_out(vty, "%% No such BGP instance exist\n");
15721 return CMD_WARNING;
15722 }
15723
15724 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15725 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15726 vty_out(vty,
15727 "This VRF is not importing %s routes from any other VRF\n",
15728 get_afi_safi_str(afi, safi, false));
15729 else {
15730 vty_out(vty,
15731 "This VRF is importing %s routes from the following VRFs:\n",
15732 get_afi_safi_str(afi, safi, false));
15733
15734 for (ALL_LIST_ELEMENTS_RO(
15735 bgp->vpn_policy[afi].import_vrf,
15736 node, vname))
15737 vty_out(vty, " %s\n", vname);
15738
15739 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15740 ecom_str = NULL;
15741 if (bgp->vpn_policy[afi].rtlist[dir]) {
15742 ecom_str = ecommunity_ecom2str(
15743 bgp->vpn_policy[afi].rtlist[dir],
15744 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15745 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15746
15747 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15748 } else
15749 vty_out(vty, "Import RT(s):\n");
15750 }
15751
15752 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15753 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15754 vty_out(vty,
15755 "This VRF is not exporting %s routes to any other VRF\n",
15756 get_afi_safi_str(afi, safi, false));
15757 else {
15758 vty_out(vty,
15759 "This VRF is exporting %s routes to the following VRFs:\n",
15760 get_afi_safi_str(afi, safi, false));
15761
15762 for (ALL_LIST_ELEMENTS_RO(
15763 bgp->vpn_policy[afi].export_vrf,
15764 node, vname))
15765 vty_out(vty, " %s\n", vname);
15766
15767 vty_out(vty, "RD: ");
15768 vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
15769 &bgp->vpn_policy[afi].tovpn_rd);
15770 vty_out(vty, "\n");
15771
15772 dir = BGP_VPN_POLICY_DIR_TOVPN;
15773 if (bgp->vpn_policy[afi].rtlist[dir]) {
15774 ecom_str = ecommunity_ecom2str(
15775 bgp->vpn_policy[afi].rtlist[dir],
15776 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15777 vty_out(vty, "Export RT: %s\n", ecom_str);
15778 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15779 } else
15780 vty_out(vty, "Import RT(s):\n");
15781 }
15782 }
15783
15784 return CMD_SUCCESS;
15785 }
15786
15787 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15788 safi_t safi, bool use_json)
15789 {
15790 struct listnode *node, *nnode;
15791 struct bgp *bgp;
15792 char *vrf_name = NULL;
15793 json_object *json = NULL;
15794 json_object *json_vrf = NULL;
15795 json_object *json_vrfs = NULL;
15796
15797 if (use_json) {
15798 json = json_object_new_object();
15799 json_vrfs = json_object_new_object();
15800 }
15801
15802 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15803
15804 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15805 vrf_name = bgp->name;
15806
15807 if (use_json) {
15808 json_vrf = json_object_new_object();
15809 } else {
15810 vty_out(vty, "\nInstance %s:\n",
15811 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15812 ? VRF_DEFAULT_NAME : bgp->name);
15813 }
15814 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15815 if (use_json) {
15816 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15817 json_object_object_add(json_vrfs,
15818 VRF_DEFAULT_NAME, json_vrf);
15819 else
15820 json_object_object_add(json_vrfs, vrf_name,
15821 json_vrf);
15822 }
15823 }
15824
15825 if (use_json) {
15826 json_object_object_add(json, "vrfs", json_vrfs);
15827 vty_json(vty, json);
15828 }
15829
15830 return CMD_SUCCESS;
15831 }
15832
15833 /* "show [ip] bgp route-leak" command. */
15834 DEFUN (show_ip_bgp_route_leak,
15835 show_ip_bgp_route_leak_cmd,
15836 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15837 SHOW_STR
15838 IP_STR
15839 BGP_STR
15840 BGP_INSTANCE_HELP_STR
15841 BGP_AFI_HELP_STR
15842 BGP_SAFI_HELP_STR
15843 "Route leaking information\n"
15844 JSON_STR)
15845 {
15846 char *vrf = NULL;
15847 afi_t afi = AFI_MAX;
15848 safi_t safi = SAFI_MAX;
15849
15850 bool uj = use_json(argc, argv);
15851 int idx = 0;
15852 json_object *json = NULL;
15853
15854 /* show [ip] bgp */
15855 if (argv_find(argv, argc, "ip", &idx)) {
15856 afi = AFI_IP;
15857 safi = SAFI_UNICAST;
15858 }
15859 /* [vrf VIEWVRFNAME] */
15860 if (argv_find(argv, argc, "view", &idx)) {
15861 vty_out(vty,
15862 "%% This command is not applicable to BGP views\n");
15863 return CMD_WARNING;
15864 }
15865
15866 if (argv_find(argv, argc, "vrf", &idx)) {
15867 vrf = argv[idx + 1]->arg;
15868 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15869 vrf = NULL;
15870 }
15871 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15872 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15873 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15874
15875 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15876 vty_out(vty,
15877 "%% This command is applicable only for unicast ipv4|ipv6\n");
15878 return CMD_WARNING;
15879 }
15880
15881 if (vrf && strmatch(vrf, "all"))
15882 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15883
15884 if (uj)
15885 json = json_object_new_object();
15886
15887 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15888 }
15889
15890 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15891 safi_t safi, bool uj)
15892 {
15893 struct listnode *node, *nnode;
15894 struct bgp *bgp;
15895
15896 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15897 if (!uj)
15898 vty_out(vty, "\nInstance %s:\n",
15899 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15900 ? VRF_DEFAULT_NAME
15901 : bgp->name);
15902
15903 update_group_show(bgp, afi, safi, vty, 0, uj);
15904 }
15905 }
15906
15907 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15908 int safi, uint64_t subgrp_id, bool uj)
15909 {
15910 struct bgp *bgp;
15911
15912 if (name) {
15913 if (strmatch(name, "all")) {
15914 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15915 return CMD_SUCCESS;
15916 } else {
15917 bgp = bgp_lookup_by_name(name);
15918 }
15919 } else {
15920 bgp = bgp_get_default();
15921 }
15922
15923 if (bgp)
15924 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15925 return CMD_SUCCESS;
15926 }
15927
15928 DEFUN (show_ip_bgp_updgrps,
15929 show_ip_bgp_updgrps_cmd,
15930 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15931 SHOW_STR
15932 IP_STR
15933 BGP_STR
15934 BGP_INSTANCE_HELP_STR
15935 BGP_AFI_HELP_STR
15936 BGP_SAFI_WITH_LABEL_HELP_STR
15937 "Detailed info about dynamic update groups\n"
15938 "Specific subgroup to display detailed info for\n"
15939 JSON_STR)
15940 {
15941 char *vrf = NULL;
15942 afi_t afi = AFI_IP6;
15943 safi_t safi = SAFI_UNICAST;
15944 uint64_t subgrp_id = 0;
15945
15946 int idx = 0;
15947
15948 bool uj = use_json(argc, argv);
15949
15950 /* show [ip] bgp */
15951 if (argv_find(argv, argc, "ip", &idx))
15952 afi = AFI_IP;
15953 /* [<vrf> VIEWVRFNAME] */
15954 if (argv_find(argv, argc, "vrf", &idx)) {
15955 vrf = argv[idx + 1]->arg;
15956 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15957 vrf = NULL;
15958 } else if (argv_find(argv, argc, "view", &idx))
15959 /* [<view> VIEWVRFNAME] */
15960 vrf = argv[idx + 1]->arg;
15961 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15962 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15963 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15964 }
15965
15966 /* get subgroup id, if provided */
15967 idx = argc - 1;
15968 if (argv[idx]->type == VARIABLE_TKN)
15969 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15970
15971 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15972 }
15973
15974 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15975 show_bgp_instance_all_ipv6_updgrps_cmd,
15976 "show [ip] bgp <view|vrf> all update-groups [json]",
15977 SHOW_STR
15978 IP_STR
15979 BGP_STR
15980 BGP_INSTANCE_ALL_HELP_STR
15981 "Detailed info about dynamic update groups\n"
15982 JSON_STR)
15983 {
15984 bool uj = use_json(argc, argv);
15985
15986 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15987 return CMD_SUCCESS;
15988 }
15989
15990 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15991 show_bgp_l2vpn_evpn_updgrps_cmd,
15992 "show [ip] bgp l2vpn evpn update-groups",
15993 SHOW_STR
15994 IP_STR
15995 BGP_STR
15996 "l2vpn address family\n"
15997 "evpn sub-address family\n"
15998 "Detailed info about dynamic update groups\n")
15999 {
16000 char *vrf = NULL;
16001 uint64_t subgrp_id = 0;
16002
16003 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
16004 return CMD_SUCCESS;
16005 }
16006
16007 DEFUN (show_bgp_updgrps_stats,
16008 show_bgp_updgrps_stats_cmd,
16009 "show [ip] bgp update-groups statistics",
16010 SHOW_STR
16011 IP_STR
16012 BGP_STR
16013 "Detailed info about dynamic update groups\n"
16014 "Statistics\n")
16015 {
16016 struct bgp *bgp;
16017
16018 bgp = bgp_get_default();
16019 if (bgp)
16020 update_group_show_stats(bgp, vty);
16021
16022 return CMD_SUCCESS;
16023 }
16024
16025 DEFUN (show_bgp_instance_updgrps_stats,
16026 show_bgp_instance_updgrps_stats_cmd,
16027 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
16028 SHOW_STR
16029 IP_STR
16030 BGP_STR
16031 BGP_INSTANCE_HELP_STR
16032 "Detailed info about dynamic update groups\n"
16033 "Statistics\n")
16034 {
16035 int idx_word = 3;
16036 struct bgp *bgp;
16037
16038 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
16039 if (bgp)
16040 update_group_show_stats(bgp, vty);
16041
16042 return CMD_SUCCESS;
16043 }
16044
16045 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
16046 afi_t afi, safi_t safi,
16047 const char *what, uint64_t subgrp_id)
16048 {
16049 struct bgp *bgp;
16050
16051 if (name)
16052 bgp = bgp_lookup_by_name(name);
16053 else
16054 bgp = bgp_get_default();
16055
16056 if (bgp) {
16057 if (!strcmp(what, "advertise-queue"))
16058 update_group_show_adj_queue(bgp, afi, safi, vty,
16059 subgrp_id);
16060 else if (!strcmp(what, "advertised-routes"))
16061 update_group_show_advertised(bgp, afi, safi, vty,
16062 subgrp_id);
16063 else if (!strcmp(what, "packet-queue"))
16064 update_group_show_packet_queue(bgp, afi, safi, vty,
16065 subgrp_id);
16066 }
16067 }
16068
16069 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
16070 show_ip_bgp_instance_updgrps_adj_s_cmd,
16071 "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",
16072 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
16073 BGP_SAFI_HELP_STR
16074 "Detailed info about dynamic update groups\n"
16075 "Specific subgroup to display info for\n"
16076 "Advertisement queue\n"
16077 "Announced routes\n"
16078 "Packet queue\n")
16079 {
16080 uint64_t subgrp_id = 0;
16081 afi_t afiz;
16082 safi_t safiz;
16083 if (sgid)
16084 subgrp_id = strtoull(sgid, NULL, 10);
16085
16086 if (!ip && !afi)
16087 afiz = AFI_IP6;
16088 if (!ip && afi)
16089 afiz = bgp_vty_afi_from_str(afi);
16090 if (ip && !afi)
16091 afiz = AFI_IP;
16092 if (ip && afi) {
16093 afiz = bgp_vty_afi_from_str(afi);
16094 if (afiz != AFI_IP)
16095 vty_out(vty,
16096 "%% Cannot specify both 'ip' and 'ipv6'\n");
16097 return CMD_WARNING;
16098 }
16099
16100 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
16101
16102 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
16103 return CMD_SUCCESS;
16104 }
16105
16106 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
16107 json_object *json)
16108 {
16109 struct listnode *node, *nnode;
16110 struct prefix *range;
16111 struct peer *conf;
16112 struct peer *peer;
16113 afi_t afi;
16114 safi_t safi;
16115 const char *peer_status;
16116 int lr_count;
16117 int dynamic;
16118 bool af_cfgd;
16119 json_object *json_peer_group = NULL;
16120 json_object *json_peer_group_afc = NULL;
16121 json_object *json_peer_group_members = NULL;
16122 json_object *json_peer_group_dynamic = NULL;
16123 json_object *json_peer_group_dynamic_af = NULL;
16124 json_object *json_peer_group_ranges = NULL;
16125
16126 conf = group->conf;
16127
16128 if (json) {
16129 json_peer_group = json_object_new_object();
16130 json_peer_group_afc = json_object_new_array();
16131 }
16132
16133 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
16134 if (json)
16135 asn_asn2json(json_peer_group, "remoteAs", conf->as,
16136 bgp_get_asnotation(conf->bgp));
16137 else {
16138 vty_out(vty, "\nBGP peer-group %s, remote AS ",
16139 group->name);
16140 vty_out(vty, ASN_FORMAT(bgp_get_asnotation(conf->bgp)),
16141 &conf->as);
16142 vty_out(vty, "\n");
16143 }
16144 } else if (conf->as_type == AS_INTERNAL) {
16145 if (json)
16146 asn_asn2json(json, "remoteAs", group->bgp->as,
16147 group->bgp->asnotation);
16148 else
16149 vty_out(vty, "\nBGP peer-group %s, remote AS %s\n",
16150 group->name, group->bgp->as_pretty);
16151 } else {
16152 if (!json)
16153 vty_out(vty, "\nBGP peer-group %s\n", group->name);
16154 }
16155
16156 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16157 if (json)
16158 json_object_string_add(json_peer_group, "type",
16159 "internal");
16160 else
16161 vty_out(vty, " Peer-group type is internal\n");
16162 } else {
16163 if (json)
16164 json_object_string_add(json_peer_group, "type",
16165 "external");
16166 else
16167 vty_out(vty, " Peer-group type is external\n");
16168 }
16169
16170 /* Display AFs configured. */
16171 if (!json)
16172 vty_out(vty, " Configured address-families:");
16173
16174 FOREACH_AFI_SAFI (afi, safi) {
16175 if (conf->afc[afi][safi]) {
16176 af_cfgd = true;
16177 if (json)
16178 json_object_array_add(
16179 json_peer_group_afc,
16180 json_object_new_string(get_afi_safi_str(
16181 afi, safi, false)));
16182 else
16183 vty_out(vty, " %s;",
16184 get_afi_safi_str(afi, safi, false));
16185 }
16186 }
16187
16188 if (json) {
16189 json_object_object_add(json_peer_group,
16190 "addressFamiliesConfigured",
16191 json_peer_group_afc);
16192 } else {
16193 if (!af_cfgd)
16194 vty_out(vty, " none\n");
16195 else
16196 vty_out(vty, "\n");
16197 }
16198
16199 /* Display listen ranges (for dynamic neighbors), if any */
16200 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
16201 lr_count = listcount(group->listen_range[afi]);
16202 if (lr_count) {
16203 if (json) {
16204 if (!json_peer_group_dynamic)
16205 json_peer_group_dynamic =
16206 json_object_new_object();
16207
16208 json_peer_group_dynamic_af =
16209 json_object_new_object();
16210 json_peer_group_ranges =
16211 json_object_new_array();
16212 json_object_int_add(json_peer_group_dynamic_af,
16213 "count", lr_count);
16214 } else {
16215 vty_out(vty, " %d %s listen range(s)\n",
16216 lr_count, afi2str(afi));
16217 }
16218
16219 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
16220 nnode, range)) {
16221 if (json) {
16222 char buf[BUFSIZ];
16223
16224 snprintfrr(buf, sizeof(buf), "%pFX",
16225 range);
16226
16227 json_object_array_add(
16228 json_peer_group_ranges,
16229 json_object_new_string(buf));
16230 } else {
16231 vty_out(vty, " %pFX\n", range);
16232 }
16233 }
16234
16235 if (json) {
16236 json_object_object_add(
16237 json_peer_group_dynamic_af, "ranges",
16238 json_peer_group_ranges);
16239
16240 json_object_object_add(
16241 json_peer_group_dynamic, afi2str(afi),
16242 json_peer_group_dynamic_af);
16243 }
16244 }
16245 }
16246
16247 if (json_peer_group_dynamic)
16248 json_object_object_add(json_peer_group, "dynamicRanges",
16249 json_peer_group_dynamic);
16250
16251 /* Display group members and their status */
16252 if (listcount(group->peer)) {
16253 if (json)
16254 json_peer_group_members = json_object_new_object();
16255 else
16256 vty_out(vty, " Peer-group members:\n");
16257 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16258 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16259 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16260 peer_status = "Idle (Admin)";
16261 else if (CHECK_FLAG(peer->sflags,
16262 PEER_STATUS_PREFIX_OVERFLOW))
16263 peer_status = "Idle (PfxCt)";
16264 else
16265 peer_status = lookup_msg(bgp_status_msg,
16266 peer->status, NULL);
16267
16268 dynamic = peer_dynamic_neighbor(peer);
16269
16270 if (json) {
16271 json_object *json_peer_group_member =
16272 json_object_new_object();
16273
16274 json_object_string_add(json_peer_group_member,
16275 "status", peer_status);
16276
16277 if (dynamic)
16278 json_object_boolean_true_add(
16279 json_peer_group_member,
16280 "dynamic");
16281
16282 json_object_object_add(json_peer_group_members,
16283 peer->host,
16284 json_peer_group_member);
16285 } else {
16286 vty_out(vty, " %s %s %s \n", peer->host,
16287 dynamic ? "(dynamic)" : "",
16288 peer_status);
16289 }
16290 }
16291 if (json)
16292 json_object_object_add(json_peer_group, "members",
16293 json_peer_group_members);
16294 }
16295
16296 if (json)
16297 json_object_object_add(json, group->name, json_peer_group);
16298
16299 return CMD_SUCCESS;
16300 }
16301
16302 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16303 const char *group_name, bool uj)
16304 {
16305 struct bgp *bgp;
16306 struct listnode *node, *nnode;
16307 struct peer_group *group;
16308 bool found = false;
16309 json_object *json = NULL;
16310
16311 if (uj)
16312 json = json_object_new_object();
16313
16314 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16315
16316 if (!bgp) {
16317 if (uj)
16318 vty_json(vty, json);
16319 else
16320 vty_out(vty, "%% BGP instance not found\n");
16321
16322 return CMD_WARNING;
16323 }
16324
16325 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16326 if (group_name) {
16327 if (strmatch(group->name, group_name)) {
16328 bgp_show_one_peer_group(vty, group, json);
16329 found = true;
16330 break;
16331 }
16332 } else {
16333 bgp_show_one_peer_group(vty, group, json);
16334 }
16335 }
16336
16337 if (group_name && !found && !uj)
16338 vty_out(vty, "%% No such peer-group\n");
16339
16340 if (uj)
16341 vty_json(vty, json);
16342
16343 return CMD_SUCCESS;
16344 }
16345
16346 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16347 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16348 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16349 "Detailed information on BGP peer groups\n"
16350 "Peer group name\n" JSON_STR)
16351 {
16352 char *vrf, *pg;
16353 int idx = 0;
16354 bool uj = use_json(argc, argv);
16355
16356 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16357 : NULL;
16358 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16359
16360 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16361 }
16362
16363
16364 /* Redistribute VTY commands. */
16365
16366 DEFUN (bgp_redistribute_ipv4,
16367 bgp_redistribute_ipv4_cmd,
16368 "redistribute " FRR_IP_REDIST_STR_BGPD,
16369 "Redistribute information from another routing protocol\n"
16370 FRR_IP_REDIST_HELP_STR_BGPD)
16371 {
16372 VTY_DECLVAR_CONTEXT(bgp, bgp);
16373 int idx_protocol = 1;
16374 int type;
16375
16376 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16377 if (type < 0) {
16378 vty_out(vty, "%% Invalid route type\n");
16379 return CMD_WARNING_CONFIG_FAILED;
16380 }
16381
16382 bgp_redist_add(bgp, AFI_IP, type, 0);
16383 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16384 }
16385
16386 ALIAS_HIDDEN(
16387 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16388 "redistribute " FRR_IP_REDIST_STR_BGPD,
16389 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16390
16391 DEFUN (bgp_redistribute_ipv4_rmap,
16392 bgp_redistribute_ipv4_rmap_cmd,
16393 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16394 "Redistribute information from another routing protocol\n"
16395 FRR_IP_REDIST_HELP_STR_BGPD
16396 "Route map reference\n"
16397 "Pointer to route-map entries\n")
16398 {
16399 VTY_DECLVAR_CONTEXT(bgp, bgp);
16400 int idx_protocol = 1;
16401 int idx_word = 3;
16402 int type;
16403 struct bgp_redist *red;
16404 bool changed;
16405 struct route_map *route_map = route_map_lookup_warn_noexist(
16406 vty, argv[idx_word]->arg);
16407
16408 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16409 if (type < 0) {
16410 vty_out(vty, "%% Invalid route type\n");
16411 return CMD_WARNING_CONFIG_FAILED;
16412 }
16413
16414 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16415 changed =
16416 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16417 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16418 }
16419
16420 ALIAS_HIDDEN(
16421 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16422 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16423 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16424 "Route map reference\n"
16425 "Pointer to route-map entries\n")
16426
16427 DEFUN (bgp_redistribute_ipv4_metric,
16428 bgp_redistribute_ipv4_metric_cmd,
16429 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16430 "Redistribute information from another routing protocol\n"
16431 FRR_IP_REDIST_HELP_STR_BGPD
16432 "Metric for redistributed routes\n"
16433 "Default metric\n")
16434 {
16435 VTY_DECLVAR_CONTEXT(bgp, bgp);
16436 int idx_protocol = 1;
16437 int idx_number = 3;
16438 int type;
16439 uint32_t metric;
16440 struct bgp_redist *red;
16441 bool changed;
16442
16443 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16444 if (type < 0) {
16445 vty_out(vty, "%% Invalid route type\n");
16446 return CMD_WARNING_CONFIG_FAILED;
16447 }
16448 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16449
16450 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16451 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16452 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16453 }
16454
16455 ALIAS_HIDDEN(
16456 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16457 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16458 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16459 "Metric for redistributed routes\n"
16460 "Default metric\n")
16461
16462 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16463 bgp_redistribute_ipv4_rmap_metric_cmd,
16464 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16465 "Redistribute information from another routing protocol\n"
16466 FRR_IP_REDIST_HELP_STR_BGPD
16467 "Route map reference\n"
16468 "Pointer to route-map entries\n"
16469 "Metric for redistributed routes\n"
16470 "Default metric\n")
16471 {
16472 VTY_DECLVAR_CONTEXT(bgp, bgp);
16473 int idx_protocol = 1;
16474 int idx_word = 3;
16475 int idx_number = 5;
16476 int type;
16477 uint32_t metric;
16478 struct bgp_redist *red;
16479 bool changed;
16480 struct route_map *route_map =
16481 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16482
16483 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16484 if (type < 0) {
16485 vty_out(vty, "%% Invalid route type\n");
16486 return CMD_WARNING_CONFIG_FAILED;
16487 }
16488 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16489
16490 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16491 changed =
16492 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16493 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16494 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16495 }
16496
16497 ALIAS_HIDDEN(
16498 bgp_redistribute_ipv4_rmap_metric,
16499 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16500 "redistribute " FRR_IP_REDIST_STR_BGPD
16501 " route-map RMAP_NAME metric (0-4294967295)",
16502 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16503 "Route map reference\n"
16504 "Pointer to route-map entries\n"
16505 "Metric for redistributed routes\n"
16506 "Default metric\n")
16507
16508 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16509 bgp_redistribute_ipv4_metric_rmap_cmd,
16510 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16511 "Redistribute information from another routing protocol\n"
16512 FRR_IP_REDIST_HELP_STR_BGPD
16513 "Metric for redistributed routes\n"
16514 "Default metric\n"
16515 "Route map reference\n"
16516 "Pointer to route-map entries\n")
16517 {
16518 VTY_DECLVAR_CONTEXT(bgp, bgp);
16519 int idx_protocol = 1;
16520 int idx_number = 3;
16521 int idx_word = 5;
16522 int type;
16523 uint32_t metric;
16524 struct bgp_redist *red;
16525 bool changed;
16526 struct route_map *route_map =
16527 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16528
16529 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16530 if (type < 0) {
16531 vty_out(vty, "%% Invalid route type\n");
16532 return CMD_WARNING_CONFIG_FAILED;
16533 }
16534 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16535
16536 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16537 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16538 changed |=
16539 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16540 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16541 }
16542
16543 ALIAS_HIDDEN(
16544 bgp_redistribute_ipv4_metric_rmap,
16545 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16546 "redistribute " FRR_IP_REDIST_STR_BGPD
16547 " metric (0-4294967295) route-map RMAP_NAME",
16548 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16549 "Metric for redistributed routes\n"
16550 "Default metric\n"
16551 "Route map reference\n"
16552 "Pointer to route-map entries\n")
16553
16554 DEFUN (bgp_redistribute_ipv4_ospf,
16555 bgp_redistribute_ipv4_ospf_cmd,
16556 "redistribute <ospf|table> (1-65535)",
16557 "Redistribute information from another routing protocol\n"
16558 "Open Shortest Path First (OSPFv2)\n"
16559 "Non-main Kernel Routing Table\n"
16560 "Instance ID/Table ID\n")
16561 {
16562 VTY_DECLVAR_CONTEXT(bgp, bgp);
16563 int idx_ospf_table = 1;
16564 int idx_number = 2;
16565 unsigned short instance;
16566 unsigned short protocol;
16567
16568 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16569
16570 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16571 protocol = ZEBRA_ROUTE_OSPF;
16572 else
16573 protocol = ZEBRA_ROUTE_TABLE;
16574
16575 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16576 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16577 }
16578
16579 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16580 "redistribute <ospf|table> (1-65535)",
16581 "Redistribute information from another routing protocol\n"
16582 "Open Shortest Path First (OSPFv2)\n"
16583 "Non-main Kernel Routing Table\n"
16584 "Instance ID/Table ID\n")
16585
16586 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16587 bgp_redistribute_ipv4_ospf_rmap_cmd,
16588 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16589 "Redistribute information from another routing protocol\n"
16590 "Open Shortest Path First (OSPFv2)\n"
16591 "Non-main Kernel Routing Table\n"
16592 "Instance ID/Table ID\n"
16593 "Route map reference\n"
16594 "Pointer to route-map entries\n")
16595 {
16596 VTY_DECLVAR_CONTEXT(bgp, bgp);
16597 int idx_ospf_table = 1;
16598 int idx_number = 2;
16599 int idx_word = 4;
16600 struct bgp_redist *red;
16601 unsigned short instance;
16602 int protocol;
16603 bool changed;
16604 struct route_map *route_map =
16605 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16606
16607 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16608 protocol = ZEBRA_ROUTE_OSPF;
16609 else
16610 protocol = ZEBRA_ROUTE_TABLE;
16611
16612 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16613 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16614 changed =
16615 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16616 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16617 }
16618
16619 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16620 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16621 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16622 "Redistribute information from another routing protocol\n"
16623 "Open Shortest Path First (OSPFv2)\n"
16624 "Non-main Kernel Routing Table\n"
16625 "Instance ID/Table ID\n"
16626 "Route map reference\n"
16627 "Pointer to route-map entries\n")
16628
16629 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16630 bgp_redistribute_ipv4_ospf_metric_cmd,
16631 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16632 "Redistribute information from another routing protocol\n"
16633 "Open Shortest Path First (OSPFv2)\n"
16634 "Non-main Kernel Routing Table\n"
16635 "Instance ID/Table ID\n"
16636 "Metric for redistributed routes\n"
16637 "Default metric\n")
16638 {
16639 VTY_DECLVAR_CONTEXT(bgp, bgp);
16640 int idx_ospf_table = 1;
16641 int idx_number = 2;
16642 int idx_number_2 = 4;
16643 uint32_t metric;
16644 struct bgp_redist *red;
16645 unsigned short instance;
16646 int protocol;
16647 bool changed;
16648
16649 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16650 protocol = ZEBRA_ROUTE_OSPF;
16651 else
16652 protocol = ZEBRA_ROUTE_TABLE;
16653
16654 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16655 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16656
16657 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16658 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16659 metric);
16660 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16661 }
16662
16663 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16664 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16665 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16666 "Redistribute information from another routing protocol\n"
16667 "Open Shortest Path First (OSPFv2)\n"
16668 "Non-main Kernel Routing Table\n"
16669 "Instance ID/Table ID\n"
16670 "Metric for redistributed routes\n"
16671 "Default metric\n")
16672
16673 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16674 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16675 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16676 "Redistribute information from another routing protocol\n"
16677 "Open Shortest Path First (OSPFv2)\n"
16678 "Non-main Kernel Routing Table\n"
16679 "Instance ID/Table ID\n"
16680 "Route map reference\n"
16681 "Pointer to route-map entries\n"
16682 "Metric for redistributed routes\n"
16683 "Default metric\n")
16684 {
16685 VTY_DECLVAR_CONTEXT(bgp, bgp);
16686 int idx_ospf_table = 1;
16687 int idx_number = 2;
16688 int idx_word = 4;
16689 int idx_number_2 = 6;
16690 uint32_t metric;
16691 struct bgp_redist *red;
16692 unsigned short instance;
16693 int protocol;
16694 bool changed;
16695 struct route_map *route_map =
16696 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16697
16698 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16699 protocol = ZEBRA_ROUTE_OSPF;
16700 else
16701 protocol = ZEBRA_ROUTE_TABLE;
16702
16703 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16704 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16705
16706 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16707 changed =
16708 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16709 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16710 metric);
16711 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16712 }
16713
16714 ALIAS_HIDDEN(
16715 bgp_redistribute_ipv4_ospf_rmap_metric,
16716 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16717 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16718 "Redistribute information from another routing protocol\n"
16719 "Open Shortest Path First (OSPFv2)\n"
16720 "Non-main Kernel Routing Table\n"
16721 "Instance ID/Table ID\n"
16722 "Route map reference\n"
16723 "Pointer to route-map entries\n"
16724 "Metric for redistributed routes\n"
16725 "Default metric\n")
16726
16727 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16728 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16729 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16730 "Redistribute information from another routing protocol\n"
16731 "Open Shortest Path First (OSPFv2)\n"
16732 "Non-main Kernel Routing Table\n"
16733 "Instance ID/Table ID\n"
16734 "Metric for redistributed routes\n"
16735 "Default metric\n"
16736 "Route map reference\n"
16737 "Pointer to route-map entries\n")
16738 {
16739 VTY_DECLVAR_CONTEXT(bgp, bgp);
16740 int idx_ospf_table = 1;
16741 int idx_number = 2;
16742 int idx_number_2 = 4;
16743 int idx_word = 6;
16744 uint32_t metric;
16745 struct bgp_redist *red;
16746 unsigned short instance;
16747 int protocol;
16748 bool changed;
16749 struct route_map *route_map =
16750 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16751
16752 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16753 protocol = ZEBRA_ROUTE_OSPF;
16754 else
16755 protocol = ZEBRA_ROUTE_TABLE;
16756
16757 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16758 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16759
16760 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16761 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16762 metric);
16763 changed |=
16764 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16765 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16766 }
16767
16768 ALIAS_HIDDEN(
16769 bgp_redistribute_ipv4_ospf_metric_rmap,
16770 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16771 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16772 "Redistribute information from another routing protocol\n"
16773 "Open Shortest Path First (OSPFv2)\n"
16774 "Non-main Kernel Routing Table\n"
16775 "Instance ID/Table ID\n"
16776 "Metric for redistributed routes\n"
16777 "Default metric\n"
16778 "Route map reference\n"
16779 "Pointer to route-map entries\n")
16780
16781 DEFUN (no_bgp_redistribute_ipv4_ospf,
16782 no_bgp_redistribute_ipv4_ospf_cmd,
16783 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16784 NO_STR
16785 "Redistribute information from another routing protocol\n"
16786 "Open Shortest Path First (OSPFv2)\n"
16787 "Non-main Kernel Routing Table\n"
16788 "Instance ID/Table ID\n"
16789 "Metric for redistributed routes\n"
16790 "Default metric\n"
16791 "Route map reference\n"
16792 "Pointer to route-map entries\n")
16793 {
16794 VTY_DECLVAR_CONTEXT(bgp, bgp);
16795 int idx_ospf_table = 2;
16796 int idx_number = 3;
16797 unsigned short instance;
16798 int protocol;
16799
16800 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16801 protocol = ZEBRA_ROUTE_OSPF;
16802 else
16803 protocol = ZEBRA_ROUTE_TABLE;
16804
16805 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16806 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16807 }
16808
16809 ALIAS_HIDDEN(
16810 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16811 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16812 NO_STR
16813 "Redistribute information from another routing protocol\n"
16814 "Open Shortest Path First (OSPFv2)\n"
16815 "Non-main Kernel Routing Table\n"
16816 "Instance ID/Table ID\n"
16817 "Metric for redistributed routes\n"
16818 "Default metric\n"
16819 "Route map reference\n"
16820 "Pointer to route-map entries\n")
16821
16822 DEFUN (no_bgp_redistribute_ipv4,
16823 no_bgp_redistribute_ipv4_cmd,
16824 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16825 NO_STR
16826 "Redistribute information from another routing protocol\n"
16827 FRR_IP_REDIST_HELP_STR_BGPD
16828 "Metric for redistributed routes\n"
16829 "Default metric\n"
16830 "Route map reference\n"
16831 "Pointer to route-map entries\n")
16832 {
16833 VTY_DECLVAR_CONTEXT(bgp, bgp);
16834 int idx_protocol = 2;
16835 int type;
16836
16837 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16838 if (type < 0) {
16839 vty_out(vty, "%% Invalid route type\n");
16840 return CMD_WARNING_CONFIG_FAILED;
16841 }
16842 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16843 }
16844
16845 ALIAS_HIDDEN(
16846 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16847 "no redistribute " FRR_IP_REDIST_STR_BGPD
16848 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16849 NO_STR
16850 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16851 "Metric for redistributed routes\n"
16852 "Default metric\n"
16853 "Route map reference\n"
16854 "Pointer to route-map entries\n")
16855
16856 DEFUN (bgp_redistribute_ipv6,
16857 bgp_redistribute_ipv6_cmd,
16858 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16859 "Redistribute information from another routing protocol\n"
16860 FRR_IP6_REDIST_HELP_STR_BGPD)
16861 {
16862 VTY_DECLVAR_CONTEXT(bgp, bgp);
16863 int idx_protocol = 1;
16864 int type;
16865
16866 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16867 if (type < 0) {
16868 vty_out(vty, "%% Invalid route type\n");
16869 return CMD_WARNING_CONFIG_FAILED;
16870 }
16871
16872 bgp_redist_add(bgp, AFI_IP6, type, 0);
16873 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16874 }
16875
16876 DEFUN (bgp_redistribute_ipv6_rmap,
16877 bgp_redistribute_ipv6_rmap_cmd,
16878 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16879 "Redistribute information from another routing protocol\n"
16880 FRR_IP6_REDIST_HELP_STR_BGPD
16881 "Route map reference\n"
16882 "Pointer to route-map entries\n")
16883 {
16884 VTY_DECLVAR_CONTEXT(bgp, bgp);
16885 int idx_protocol = 1;
16886 int idx_word = 3;
16887 int type;
16888 struct bgp_redist *red;
16889 bool changed;
16890 struct route_map *route_map =
16891 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16892
16893 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16894 if (type < 0) {
16895 vty_out(vty, "%% Invalid route type\n");
16896 return CMD_WARNING_CONFIG_FAILED;
16897 }
16898
16899 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16900 changed =
16901 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16902 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16903 }
16904
16905 DEFUN (bgp_redistribute_ipv6_metric,
16906 bgp_redistribute_ipv6_metric_cmd,
16907 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16908 "Redistribute information from another routing protocol\n"
16909 FRR_IP6_REDIST_HELP_STR_BGPD
16910 "Metric for redistributed routes\n"
16911 "Default metric\n")
16912 {
16913 VTY_DECLVAR_CONTEXT(bgp, bgp);
16914 int idx_protocol = 1;
16915 int idx_number = 3;
16916 int type;
16917 uint32_t metric;
16918 struct bgp_redist *red;
16919 bool changed;
16920
16921 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16922 if (type < 0) {
16923 vty_out(vty, "%% Invalid route type\n");
16924 return CMD_WARNING_CONFIG_FAILED;
16925 }
16926 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16927
16928 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16929 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16930 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16931 }
16932
16933 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16934 bgp_redistribute_ipv6_rmap_metric_cmd,
16935 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16936 "Redistribute information from another routing protocol\n"
16937 FRR_IP6_REDIST_HELP_STR_BGPD
16938 "Route map reference\n"
16939 "Pointer to route-map entries\n"
16940 "Metric for redistributed routes\n"
16941 "Default metric\n")
16942 {
16943 VTY_DECLVAR_CONTEXT(bgp, bgp);
16944 int idx_protocol = 1;
16945 int idx_word = 3;
16946 int idx_number = 5;
16947 int type;
16948 uint32_t metric;
16949 struct bgp_redist *red;
16950 bool changed;
16951 struct route_map *route_map =
16952 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16953
16954 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16955 if (type < 0) {
16956 vty_out(vty, "%% Invalid route type\n");
16957 return CMD_WARNING_CONFIG_FAILED;
16958 }
16959 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16960
16961 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16962 changed =
16963 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16964 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16965 metric);
16966 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16967 }
16968
16969 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16970 bgp_redistribute_ipv6_metric_rmap_cmd,
16971 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16972 "Redistribute information from another routing protocol\n"
16973 FRR_IP6_REDIST_HELP_STR_BGPD
16974 "Metric for redistributed routes\n"
16975 "Default metric\n"
16976 "Route map reference\n"
16977 "Pointer to route-map entries\n")
16978 {
16979 VTY_DECLVAR_CONTEXT(bgp, bgp);
16980 int idx_protocol = 1;
16981 int idx_number = 3;
16982 int idx_word = 5;
16983 int type;
16984 uint32_t metric;
16985 struct bgp_redist *red;
16986 bool changed;
16987 struct route_map *route_map =
16988 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16989
16990 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16991 if (type < 0) {
16992 vty_out(vty, "%% Invalid route type\n");
16993 return CMD_WARNING_CONFIG_FAILED;
16994 }
16995 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16996
16997 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16998 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16999 metric);
17000 changed |=
17001 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
17002 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
17003 }
17004
17005 DEFUN (no_bgp_redistribute_ipv6,
17006 no_bgp_redistribute_ipv6_cmd,
17007 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
17008 NO_STR
17009 "Redistribute information from another routing protocol\n"
17010 FRR_IP6_REDIST_HELP_STR_BGPD
17011 "Metric for redistributed routes\n"
17012 "Default metric\n"
17013 "Route map reference\n"
17014 "Pointer to route-map entries\n")
17015 {
17016 VTY_DECLVAR_CONTEXT(bgp, bgp);
17017 int idx_protocol = 2;
17018 int type;
17019
17020 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
17021 if (type < 0) {
17022 vty_out(vty, "%% Invalid route type\n");
17023 return CMD_WARNING_CONFIG_FAILED;
17024 }
17025
17026 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
17027 }
17028
17029 /* Neighbor update tcp-mss. */
17030 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
17031 const char *tcp_mss_str)
17032 {
17033 struct peer *peer;
17034 uint32_t tcp_mss_val = 0;
17035
17036 peer = peer_and_group_lookup_vty(vty, peer_str);
17037 if (!peer)
17038 return CMD_WARNING_CONFIG_FAILED;
17039
17040 if (tcp_mss_str) {
17041 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
17042 peer_tcp_mss_set(peer, tcp_mss_val);
17043 } else {
17044 peer_tcp_mss_unset(peer);
17045 }
17046
17047 return CMD_SUCCESS;
17048 }
17049
17050 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
17051 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
17052 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17053 "TCP max segment size\n"
17054 "TCP MSS value\n")
17055 {
17056 int peer_index = 1;
17057 int mss_index = 3;
17058
17059 vty_out(vty,
17060 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17061 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
17062 argv[mss_index]->arg);
17063 }
17064
17065 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
17066 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
17067 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
17068 "TCP max segment size\n"
17069 "TCP MSS value\n")
17070 {
17071 int peer_index = 2;
17072
17073 vty_out(vty,
17074 " Warning: Reset BGP session for tcp-mss value to take effect\n");
17075 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
17076 }
17077
17078 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
17079 "[no$no] bgp retain route-target all",
17080 NO_STR BGP_STR
17081 "Retain BGP updates\n"
17082 "Retain BGP updates based on route-target values\n"
17083 "Retain all BGP updates\n")
17084 {
17085 bool check;
17086 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
17087
17088 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
17089 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17090 if (check != !no) {
17091 if (!no)
17092 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17093 [bgp_node_safi(vty)],
17094 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17095 else
17096 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
17097 [bgp_node_safi(vty)],
17098 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
17099 /* trigger a flush to re-sync with ADJ-RIB-in */
17100 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
17101 clear_all, BGP_CLEAR_SOFT_IN, NULL);
17102 }
17103 return CMD_SUCCESS;
17104 }
17105
17106 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
17107 afi_t afi, safi_t safi)
17108 {
17109 int i;
17110
17111 /* Unicast redistribution only. */
17112 if (safi != SAFI_UNICAST)
17113 return;
17114
17115 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
17116 /* Redistribute BGP does not make sense. */
17117 if (i != ZEBRA_ROUTE_BGP) {
17118 struct list *red_list;
17119 struct listnode *node;
17120 struct bgp_redist *red;
17121
17122 red_list = bgp->redist[afi][i];
17123 if (!red_list)
17124 continue;
17125
17126 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
17127 /* "redistribute" configuration. */
17128 vty_out(vty, " redistribute %s",
17129 zebra_route_string(i));
17130 if (red->instance)
17131 vty_out(vty, " %d", red->instance);
17132 if (red->redist_metric_flag)
17133 vty_out(vty, " metric %u",
17134 red->redist_metric);
17135 if (red->rmap.name)
17136 vty_out(vty, " route-map %s",
17137 red->rmap.name);
17138 vty_out(vty, "\n");
17139 }
17140 }
17141 }
17142 }
17143
17144 /* peer-group helpers for config-write */
17145
17146 bool peergroup_flag_check(struct peer *peer, uint64_t flag)
17147 {
17148 if (!peer_group_active(peer)) {
17149 if (CHECK_FLAG(peer->flags_invert, flag))
17150 return !CHECK_FLAG(peer->flags, flag);
17151 else
17152 return !!CHECK_FLAG(peer->flags, flag);
17153 }
17154
17155 return !!CHECK_FLAG(peer->flags_override, flag);
17156 }
17157
17158 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
17159 uint64_t flag)
17160 {
17161 if (!peer_group_active(peer)) {
17162 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
17163 return !peer_af_flag_check(peer, afi, safi, flag);
17164 else
17165 return peer_af_flag_check(peer, afi, safi, flag);
17166 }
17167
17168 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
17169 }
17170
17171 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
17172 uint8_t type, int direct)
17173 {
17174 struct bgp_filter *filter;
17175
17176 if (peer_group_active(peer))
17177 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
17178 type);
17179
17180 filter = &peer->filter[afi][safi];
17181 switch (type) {
17182 case PEER_FT_DISTRIBUTE_LIST:
17183 return !!(filter->dlist[direct].name);
17184 case PEER_FT_FILTER_LIST:
17185 return !!(filter->aslist[direct].name);
17186 case PEER_FT_PREFIX_LIST:
17187 return !!(filter->plist[direct].name);
17188 case PEER_FT_ROUTE_MAP:
17189 return !!(filter->map[direct].name);
17190 case PEER_FT_UNSUPPRESS_MAP:
17191 return !!(filter->usmap.name);
17192 case PEER_FT_ADVERTISE_MAP:
17193 return !!(filter->advmap.aname
17194 && ((filter->advmap.condition == direct)
17195 && filter->advmap.cname));
17196 default:
17197 return false;
17198 }
17199 }
17200
17201 /* Return true if the addpath type is set for peer and different from
17202 * peer-group.
17203 */
17204 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17205 safi_t safi)
17206 {
17207 enum bgp_addpath_strat type, g_type;
17208
17209 type = peer->addpath_type[afi][safi];
17210
17211 if (type != BGP_ADDPATH_NONE) {
17212 if (peer_group_active(peer)) {
17213 g_type = peer->group->conf->addpath_type[afi][safi];
17214
17215 if (type != g_type)
17216 return true;
17217 else
17218 return false;
17219 }
17220
17221 return true;
17222 }
17223
17224 return false;
17225 }
17226
17227 /* This is part of the address-family block (unicast only) */
17228 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17229 afi_t afi)
17230 {
17231 int indent = 2;
17232 uint32_t tovpn_sid_index = 0;
17233
17234 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17235 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17236 BGP_CONFIG_VRF_TO_VRF_IMPORT))
17237 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17238 bgp->vpn_policy[afi]
17239 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17240 else
17241 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17242 bgp->vpn_policy[afi]
17243 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17244 }
17245 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17246 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17247 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17248 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17249 return;
17250
17251 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17252 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17253
17254 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17255
17256 } else {
17257 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17258 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17259 bgp->vpn_policy[afi].tovpn_label);
17260 }
17261 }
17262
17263 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17264 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17265 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17266 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17267 } else if (tovpn_sid_index != 0) {
17268 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17269 tovpn_sid_index);
17270 }
17271
17272 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17273 vty_out(vty, "%*srd vpn export %s\n", indent, "",
17274 bgp->vpn_policy[afi].tovpn_rd_pretty);
17275
17276 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17277 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17278
17279 char buf[PREFIX_STRLEN];
17280 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17281 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17282 sizeof(buf))) {
17283
17284 vty_out(vty, "%*snexthop vpn export %s\n",
17285 indent, "", buf);
17286 }
17287 }
17288 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17289 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17290 && ecommunity_cmp(
17291 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17292 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17293
17294 char *b = ecommunity_ecom2str(
17295 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17296 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17297 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17298 XFREE(MTYPE_ECOMMUNITY_STR, b);
17299 } else {
17300 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17301 char *b = ecommunity_ecom2str(
17302 bgp->vpn_policy[afi]
17303 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17304 ECOMMUNITY_FORMAT_ROUTE_MAP,
17305 ECOMMUNITY_ROUTE_TARGET);
17306 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17307 XFREE(MTYPE_ECOMMUNITY_STR, b);
17308 }
17309 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17310 char *b = ecommunity_ecom2str(
17311 bgp->vpn_policy[afi]
17312 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17313 ECOMMUNITY_FORMAT_ROUTE_MAP,
17314 ECOMMUNITY_ROUTE_TARGET);
17315 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17316 XFREE(MTYPE_ECOMMUNITY_STR, b);
17317 }
17318 }
17319
17320 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17321 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17322 bgp->vpn_policy[afi]
17323 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17324
17325 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17326 char *b = ecommunity_ecom2str(
17327 bgp->vpn_policy[afi]
17328 .import_redirect_rtlist,
17329 ECOMMUNITY_FORMAT_ROUTE_MAP,
17330 ECOMMUNITY_ROUTE_TARGET);
17331
17332 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17333 != ECOMMUNITY_SIZE)
17334 vty_out(vty, "%*srt6 redirect import %s\n",
17335 indent, "", b);
17336 else
17337 vty_out(vty, "%*srt redirect import %s\n",
17338 indent, "", b);
17339 XFREE(MTYPE_ECOMMUNITY_STR, b);
17340 }
17341 }
17342
17343 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17344 afi_t afi, safi_t safi)
17345 {
17346 struct bgp_filter *filter;
17347 char *addr;
17348
17349 addr = peer->host;
17350 filter = &peer->filter[afi][safi];
17351
17352 /* distribute-list. */
17353 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17354 FILTER_IN))
17355 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17356 filter->dlist[FILTER_IN].name);
17357
17358 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17359 FILTER_OUT))
17360 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17361 filter->dlist[FILTER_OUT].name);
17362
17363 /* prefix-list. */
17364 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17365 FILTER_IN))
17366 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17367 filter->plist[FILTER_IN].name);
17368
17369 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17370 FILTER_OUT))
17371 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17372 filter->plist[FILTER_OUT].name);
17373
17374 /* route-map. */
17375 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17376 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17377 filter->map[RMAP_IN].name);
17378
17379 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17380 RMAP_OUT))
17381 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17382 filter->map[RMAP_OUT].name);
17383
17384 /* unsuppress-map */
17385 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17386 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17387 filter->usmap.name);
17388
17389 /* advertise-map : always applied in OUT direction*/
17390 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17391 CONDITION_NON_EXIST))
17392 vty_out(vty,
17393 " neighbor %s advertise-map %s non-exist-map %s\n",
17394 addr, filter->advmap.aname, filter->advmap.cname);
17395
17396 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17397 CONDITION_EXIST))
17398 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17399 addr, filter->advmap.aname, filter->advmap.cname);
17400
17401 /* filter-list. */
17402 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17403 FILTER_IN))
17404 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17405 filter->aslist[FILTER_IN].name);
17406
17407 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17408 FILTER_OUT))
17409 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17410 filter->aslist[FILTER_OUT].name);
17411 }
17412
17413 /* BGP peer configuration display function. */
17414 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17415 struct peer *peer)
17416 {
17417 struct peer *g_peer = NULL;
17418 char *addr;
17419 int if_pg_printed = false;
17420 int if_ras_printed = false;
17421
17422 /* Skip dynamic neighbors. */
17423 if (peer_dynamic_neighbor(peer))
17424 return;
17425
17426 if (peer->conf_if)
17427 addr = peer->conf_if;
17428 else
17429 addr = peer->host;
17430
17431 /************************************
17432 ****** Global to the neighbor ******
17433 ************************************/
17434 if (peer->conf_if) {
17435 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17436 vty_out(vty, " neighbor %s interface v6only", addr);
17437 else
17438 vty_out(vty, " neighbor %s interface", addr);
17439
17440 if (peer_group_active(peer)) {
17441 vty_out(vty, " peer-group %s", peer->group->name);
17442 if_pg_printed = true;
17443 } else if (peer->as_type == AS_SPECIFIED) {
17444 vty_out(vty, " remote-as %s", peer->as_pretty);
17445 if_ras_printed = true;
17446 } else if (peer->as_type == AS_INTERNAL) {
17447 vty_out(vty, " remote-as internal");
17448 if_ras_printed = true;
17449 } else if (peer->as_type == AS_EXTERNAL) {
17450 vty_out(vty, " remote-as external");
17451 if_ras_printed = true;
17452 }
17453
17454 vty_out(vty, "\n");
17455 }
17456
17457 /* remote-as and peer-group */
17458 /* peer is a member of a peer-group */
17459 if (peer_group_active(peer)) {
17460 g_peer = peer->group->conf;
17461
17462 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17463 if (peer->as_type == AS_SPECIFIED) {
17464 vty_out(vty, " neighbor %s remote-as %s\n",
17465 addr, peer->as_pretty);
17466 } else if (peer->as_type == AS_INTERNAL) {
17467 vty_out(vty,
17468 " neighbor %s remote-as internal\n",
17469 addr);
17470 } else if (peer->as_type == AS_EXTERNAL) {
17471 vty_out(vty,
17472 " neighbor %s remote-as external\n",
17473 addr);
17474 }
17475 }
17476
17477 /* For swpX peers we displayed the peer-group
17478 * via 'neighbor swpX interface peer-group PGNAME' */
17479 if (!if_pg_printed)
17480 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17481 peer->group->name);
17482 }
17483
17484 /* peer is NOT a member of a peer-group */
17485 else {
17486 /* peer is a peer-group, declare the peer-group */
17487 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17488 vty_out(vty, " neighbor %s peer-group\n", addr);
17489 }
17490
17491 if (!if_ras_printed) {
17492 if (peer->as_type == AS_SPECIFIED) {
17493 vty_out(vty, " neighbor %s remote-as %s\n",
17494 addr, peer->as_pretty);
17495 } else if (peer->as_type == AS_INTERNAL) {
17496 vty_out(vty,
17497 " neighbor %s remote-as internal\n",
17498 addr);
17499 } else if (peer->as_type == AS_EXTERNAL) {
17500 vty_out(vty,
17501 " neighbor %s remote-as external\n",
17502 addr);
17503 }
17504 }
17505 }
17506
17507 /* local-as */
17508 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17509 vty_out(vty, " neighbor %s local-as %s", addr,
17510 peer->change_local_as_pretty);
17511 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17512 vty_out(vty, " no-prepend");
17513 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17514 vty_out(vty, " replace-as");
17515 vty_out(vty, "\n");
17516 }
17517
17518 /* description */
17519 if (peer->desc) {
17520 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17521 }
17522
17523 /* shutdown */
17524 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17525 if (peer->tx_shutdown_message)
17526 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17527 peer->tx_shutdown_message);
17528 else
17529 vty_out(vty, " neighbor %s shutdown\n", addr);
17530 }
17531
17532 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17533 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17534 peer->rtt_expected, peer->rtt_keepalive_conf);
17535
17536 /* bfd */
17537 if (peer->bfd_config)
17538 bgp_bfd_peer_config_write(vty, peer, addr);
17539
17540 /* password */
17541 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17542 vty_out(vty, " neighbor %s password %s\n", addr,
17543 peer->password);
17544
17545 /* neighbor solo */
17546 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17547 if (!peer_group_active(peer)) {
17548 vty_out(vty, " neighbor %s solo\n", addr);
17549 }
17550 }
17551
17552 /* BGP port */
17553 if (peer->port != BGP_PORT_DEFAULT) {
17554 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17555 }
17556
17557 /* Local interface name */
17558 if (peer->ifname) {
17559 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17560 }
17561
17562 /* TCP max segment size */
17563 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17564 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17565
17566 /* passive */
17567 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17568 vty_out(vty, " neighbor %s passive\n", addr);
17569
17570 /* ebgp-multihop */
17571 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17572 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17573 && peer->ttl == MAXTTL)) {
17574 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17575 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17576 peer->ttl);
17577 }
17578 }
17579
17580 /* aigp */
17581 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17582 vty_out(vty, " neighbor %s aigp\n", addr);
17583
17584 /* graceful-shutdown */
17585 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17586 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17587
17588 /* role */
17589 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17590 peer->local_role != ROLE_UNDEFINED)
17591 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17592 bgp_get_name_by_role(peer->local_role),
17593 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17594 ? " strict-mode"
17595 : "");
17596
17597 /* ttl-security hops */
17598 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17599 if (!peer_group_active(peer)
17600 || g_peer->gtsm_hops != peer->gtsm_hops) {
17601 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17602 addr, peer->gtsm_hops);
17603 }
17604 }
17605
17606 /* disable-connected-check */
17607 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17608 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17609
17610 /* link-bw-encoding-ieee */
17611 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17612 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17613 addr);
17614
17615 /* extended-optional-parameters */
17616 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17617 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17618 addr);
17619
17620 /* enforce-first-as */
17621 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17622 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17623
17624 /* update-source */
17625 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17626 if (peer->update_source)
17627 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17628 peer->update_source);
17629 else if (peer->update_if)
17630 vty_out(vty, " neighbor %s update-source %s\n", addr,
17631 peer->update_if);
17632 }
17633
17634 /* advertisement-interval */
17635 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17636 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17637 peer->routeadv);
17638
17639 /* timers */
17640 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17641 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17642 peer->keepalive, peer->holdtime);
17643
17644 /* timers connect */
17645 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17646 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17647 peer->connect);
17648 /* need special-case handling for changed default values due to
17649 * config profile / version (because there is no "timers bgp connect"
17650 * command, we need to save this per-peer :/)
17651 */
17652 else if (!peer_group_active(peer) && !peer->connect &&
17653 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17654 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17655 peer->bgp->default_connect_retry);
17656
17657 /* timers delayopen */
17658 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17659 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17660 peer->delayopen);
17661 /* Save config even though flag is not set if default values have been
17662 * changed
17663 */
17664 else if (!peer_group_active(peer) && !peer->delayopen
17665 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17666 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17667 peer->bgp->default_delayopen);
17668
17669 /* capability dynamic */
17670 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17671 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17672
17673 /* capability extended-nexthop */
17674 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17675 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17676 !peer->conf_if)
17677 vty_out(vty,
17678 " no neighbor %s capability extended-nexthop\n",
17679 addr);
17680 else if (!peer->conf_if)
17681 vty_out(vty,
17682 " neighbor %s capability extended-nexthop\n",
17683 addr);
17684 }
17685
17686 /* capability software-version */
17687 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION))
17688 vty_out(vty, " neighbor %s capability software-version\n",
17689 addr);
17690
17691 /* dont-capability-negotiation */
17692 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17693 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17694
17695 /* override-capability */
17696 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17697 vty_out(vty, " neighbor %s override-capability\n", addr);
17698
17699 /* strict-capability-match */
17700 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17701 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17702
17703 /* Sender side AS path loop detection. */
17704 if (peer->as_path_loop_detection)
17705 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17706 addr);
17707
17708 /* path-attribute discard */
17709 char discard_attrs_str[BUFSIZ] = {0};
17710 bool discard_attrs = bgp_path_attribute_discard(
17711 peer, discard_attrs_str, sizeof(discard_attrs_str));
17712
17713 if (discard_attrs)
17714 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17715 discard_attrs_str);
17716
17717 /* path-attribute treat-as-withdraw */
17718 char withdraw_attrs_str[BUFSIZ] = {0};
17719 bool withdraw_attrs = bgp_path_attribute_treat_as_withdraw(
17720 peer, withdraw_attrs_str, sizeof(withdraw_attrs_str));
17721
17722 if (withdraw_attrs)
17723 vty_out(vty,
17724 " neighbor %s path-attribute treat-as-withdraw %s\n",
17725 addr, withdraw_attrs_str);
17726
17727 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17728 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17729
17730 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17731 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17732 vty_out(vty,
17733 " neighbor %s graceful-restart-helper\n", addr);
17734 } else if (CHECK_FLAG(
17735 peer->peer_gr_new_status_flag,
17736 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17737 vty_out(vty,
17738 " neighbor %s graceful-restart\n", addr);
17739 } else if (
17740 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17741 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17742 && !(CHECK_FLAG(
17743 peer->peer_gr_new_status_flag,
17744 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17745 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17746 addr);
17747 }
17748 }
17749 }
17750
17751 /* BGP peer configuration display function. */
17752 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17753 struct peer *peer, afi_t afi, safi_t safi)
17754 {
17755 struct peer *g_peer = NULL;
17756 char *addr;
17757 bool flag_scomm, flag_secomm, flag_slcomm;
17758
17759 /* Skip dynamic neighbors. */
17760 if (peer_dynamic_neighbor(peer))
17761 return;
17762
17763 if (peer->conf_if)
17764 addr = peer->conf_if;
17765 else
17766 addr = peer->host;
17767
17768 /************************************
17769 ****** Per AF to the neighbor ******
17770 ************************************/
17771 if (peer_group_active(peer)) {
17772 g_peer = peer->group->conf;
17773
17774 /* If the peer-group is active but peer is not, print a 'no
17775 * activate' */
17776 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17777 vty_out(vty, " no neighbor %s activate\n", addr);
17778 }
17779
17780 /* If the peer-group is not active but peer is, print an
17781 'activate' */
17782 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17783 vty_out(vty, " neighbor %s activate\n", addr);
17784 }
17785 } else {
17786 if (peer->afc[afi][safi]) {
17787 if (safi == SAFI_ENCAP)
17788 vty_out(vty, " neighbor %s activate\n", addr);
17789 else if (!bgp->default_af[afi][safi])
17790 vty_out(vty, " neighbor %s activate\n", addr);
17791 } else {
17792 if (bgp->default_af[afi][safi])
17793 vty_out(vty, " no neighbor %s activate\n",
17794 addr);
17795 }
17796 }
17797
17798 /* addpath TX knobs */
17799 if (peergroup_af_addpath_check(peer, afi, safi)) {
17800 switch (peer->addpath_type[afi][safi]) {
17801 case BGP_ADDPATH_ALL:
17802 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17803 addr);
17804 break;
17805 case BGP_ADDPATH_BEST_PER_AS:
17806 vty_out(vty,
17807 " neighbor %s addpath-tx-bestpath-per-AS\n",
17808 addr);
17809 break;
17810 case BGP_ADDPATH_MAX:
17811 case BGP_ADDPATH_NONE:
17812 break;
17813 }
17814 }
17815
17816 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17817 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17818
17819 /* ORF capability. */
17820 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17821 || peergroup_af_flag_check(peer, afi, safi,
17822 PEER_FLAG_ORF_PREFIX_RM)) {
17823 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17824
17825 if (peergroup_af_flag_check(peer, afi, safi,
17826 PEER_FLAG_ORF_PREFIX_SM)
17827 && peergroup_af_flag_check(peer, afi, safi,
17828 PEER_FLAG_ORF_PREFIX_RM))
17829 vty_out(vty, " both");
17830 else if (peergroup_af_flag_check(peer, afi, safi,
17831 PEER_FLAG_ORF_PREFIX_SM))
17832 vty_out(vty, " send");
17833 else
17834 vty_out(vty, " receive");
17835 vty_out(vty, "\n");
17836 }
17837
17838 /* Route reflector client. */
17839 if (peergroup_af_flag_check(peer, afi, safi,
17840 PEER_FLAG_REFLECTOR_CLIENT)) {
17841 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17842 }
17843
17844 /* next-hop-self force */
17845 if (peergroup_af_flag_check(peer, afi, safi,
17846 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17847 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17848 }
17849
17850 /* next-hop-self */
17851 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17852 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17853 }
17854
17855 /* remove-private-AS */
17856 if (peergroup_af_flag_check(peer, afi, safi,
17857 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17858 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17859 addr);
17860 }
17861
17862 else if (peergroup_af_flag_check(peer, afi, safi,
17863 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17864 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17865 addr);
17866 }
17867
17868 else if (peergroup_af_flag_check(peer, afi, safi,
17869 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17870 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17871 }
17872
17873 else if (peergroup_af_flag_check(peer, afi, safi,
17874 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17875 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17876 }
17877
17878 /* as-override */
17879 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17880 vty_out(vty, " neighbor %s as-override\n", addr);
17881 }
17882
17883 /* send-community print. */
17884 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17885 PEER_FLAG_SEND_COMMUNITY);
17886 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17887 PEER_FLAG_SEND_EXT_COMMUNITY);
17888 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17889 PEER_FLAG_SEND_LARGE_COMMUNITY);
17890
17891 if (flag_scomm && flag_secomm && flag_slcomm) {
17892 vty_out(vty, " no neighbor %s send-community all\n", addr);
17893 } else {
17894 if (flag_scomm)
17895 vty_out(vty, " no neighbor %s send-community\n", addr);
17896 if (flag_secomm)
17897 vty_out(vty,
17898 " no neighbor %s send-community extended\n",
17899 addr);
17900
17901 if (flag_slcomm)
17902 vty_out(vty, " no neighbor %s send-community large\n",
17903 addr);
17904 }
17905
17906 /* Default information */
17907 if (peergroup_af_flag_check(peer, afi, safi,
17908 PEER_FLAG_DEFAULT_ORIGINATE)) {
17909 vty_out(vty, " neighbor %s default-originate", addr);
17910
17911 if (peer->default_rmap[afi][safi].name)
17912 vty_out(vty, " route-map %s",
17913 peer->default_rmap[afi][safi].name);
17914
17915 vty_out(vty, "\n");
17916 }
17917
17918 /* Soft reconfiguration inbound. */
17919 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17920 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17921 addr);
17922 }
17923
17924 /* maximum-prefix. */
17925 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17926 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17927 peer->pmax[afi][safi]);
17928
17929 if (peer->pmax_threshold[afi][safi]
17930 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17931 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17932 if (peer_af_flag_check(peer, afi, safi,
17933 PEER_FLAG_MAX_PREFIX_WARNING))
17934 vty_out(vty, " warning-only");
17935 if (peer->pmax_restart[afi][safi])
17936 vty_out(vty, " restart %u",
17937 peer->pmax_restart[afi][safi]);
17938 if (peer_af_flag_check(peer, afi, safi,
17939 PEER_FLAG_MAX_PREFIX_FORCE))
17940 vty_out(vty, " force");
17941
17942 vty_out(vty, "\n");
17943 }
17944
17945 /* maximum-prefix-out */
17946 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17947 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17948 addr, peer->pmax_out[afi][safi]);
17949
17950 /* Route server client. */
17951 if (peergroup_af_flag_check(peer, afi, safi,
17952 PEER_FLAG_RSERVER_CLIENT)) {
17953 vty_out(vty, " neighbor %s route-server-client\n", addr);
17954 }
17955
17956 /* Nexthop-local unchanged. */
17957 if (peergroup_af_flag_check(peer, afi, safi,
17958 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17959 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17960 }
17961
17962 /* allowas-in <1-10> */
17963 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17964 if (peer_af_flag_check(peer, afi, safi,
17965 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17966 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17967 } else if (peer->allowas_in[afi][safi] == 3) {
17968 vty_out(vty, " neighbor %s allowas-in\n", addr);
17969 } else {
17970 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17971 peer->allowas_in[afi][safi]);
17972 }
17973 }
17974
17975 /* accept-own */
17976 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17977 vty_out(vty, " neighbor %s accept-own\n", addr);
17978
17979 /* soo */
17980 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17981 char *soo_str = ecommunity_ecom2str(
17982 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17983
17984 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17985 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17986 }
17987
17988 /* weight */
17989 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17990 vty_out(vty, " neighbor %s weight %lu\n", addr,
17991 peer->weight[afi][safi]);
17992
17993 /* Filter. */
17994 bgp_config_write_filter(vty, peer, afi, safi);
17995
17996 /* atribute-unchanged. */
17997 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17998 || (safi != SAFI_EVPN
17999 && peer_af_flag_check(peer, afi, safi,
18000 PEER_FLAG_NEXTHOP_UNCHANGED))
18001 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
18002
18003 if (!peer_group_active(peer)
18004 || peergroup_af_flag_check(peer, afi, safi,
18005 PEER_FLAG_AS_PATH_UNCHANGED)
18006 || peergroup_af_flag_check(peer, afi, safi,
18007 PEER_FLAG_NEXTHOP_UNCHANGED)
18008 || peergroup_af_flag_check(peer, afi, safi,
18009 PEER_FLAG_MED_UNCHANGED)) {
18010
18011 vty_out(vty,
18012 " neighbor %s attribute-unchanged%s%s%s\n",
18013 addr,
18014 peer_af_flag_check(peer, afi, safi,
18015 PEER_FLAG_AS_PATH_UNCHANGED)
18016 ? " as-path"
18017 : "",
18018 peer_af_flag_check(peer, afi, safi,
18019 PEER_FLAG_NEXTHOP_UNCHANGED)
18020 ? " next-hop"
18021 : "",
18022 peer_af_flag_check(peer, afi, safi,
18023 PEER_FLAG_MED_UNCHANGED)
18024 ? " med"
18025 : "");
18026 }
18027 }
18028 }
18029
18030 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
18031 safi_t safi)
18032 {
18033 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
18034 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
18035 vty_out(vty, " no bgp retain route-target all\n");
18036 }
18037
18038 /* Address family based peer configuration display. */
18039 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
18040 safi_t safi)
18041 {
18042 struct peer *peer;
18043 struct peer_group *group;
18044 struct listnode *node, *nnode;
18045
18046
18047 vty_frame(vty, " !\n address-family ");
18048 if (afi == AFI_IP) {
18049 if (safi == SAFI_UNICAST)
18050 vty_frame(vty, "ipv4 unicast");
18051 else if (safi == SAFI_LABELED_UNICAST)
18052 vty_frame(vty, "ipv4 labeled-unicast");
18053 else if (safi == SAFI_MULTICAST)
18054 vty_frame(vty, "ipv4 multicast");
18055 else if (safi == SAFI_MPLS_VPN)
18056 vty_frame(vty, "ipv4 vpn");
18057 else if (safi == SAFI_ENCAP)
18058 vty_frame(vty, "ipv4 encap");
18059 else if (safi == SAFI_FLOWSPEC)
18060 vty_frame(vty, "ipv4 flowspec");
18061 } else if (afi == AFI_IP6) {
18062 if (safi == SAFI_UNICAST)
18063 vty_frame(vty, "ipv6 unicast");
18064 else if (safi == SAFI_LABELED_UNICAST)
18065 vty_frame(vty, "ipv6 labeled-unicast");
18066 else if (safi == SAFI_MULTICAST)
18067 vty_frame(vty, "ipv6 multicast");
18068 else if (safi == SAFI_MPLS_VPN)
18069 vty_frame(vty, "ipv6 vpn");
18070 else if (safi == SAFI_ENCAP)
18071 vty_frame(vty, "ipv6 encap");
18072 else if (safi == SAFI_FLOWSPEC)
18073 vty_frame(vty, "ipv6 flowspec");
18074 } else if (afi == AFI_L2VPN) {
18075 if (safi == SAFI_EVPN)
18076 vty_frame(vty, "l2vpn evpn");
18077 }
18078 vty_frame(vty, "\n");
18079
18080 bgp_config_write_distance(vty, bgp, afi, safi);
18081
18082 bgp_config_write_network(vty, bgp, afi, safi);
18083
18084 bgp_config_write_redistribute(vty, bgp, afi, safi);
18085
18086 /* BGP flag dampening. */
18087 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
18088 bgp_config_write_damp(vty, afi, safi);
18089
18090 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
18091 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
18092
18093 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18094 /* Do not display doppelganger peers */
18095 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18096 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
18097 }
18098
18099 bgp_config_write_maxpaths(vty, bgp, afi, safi);
18100 bgp_config_write_table_map(vty, bgp, afi, safi);
18101
18102 if (safi == SAFI_EVPN)
18103 bgp_config_write_evpn_info(vty, bgp, afi, safi);
18104
18105 if (safi == SAFI_FLOWSPEC)
18106 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
18107
18108 if (safi == SAFI_MPLS_VPN)
18109 bgp_vpn_config_write(vty, bgp, afi, safi);
18110
18111 if (safi == SAFI_UNICAST) {
18112 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
18113 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18114 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
18115
18116 vty_out(vty, " export vpn\n");
18117 }
18118 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18119 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
18120
18121 vty_out(vty, " import vpn\n");
18122 }
18123 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18124 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
18125 char *name;
18126
18127 for (ALL_LIST_ELEMENTS_RO(
18128 bgp->vpn_policy[afi].import_vrf, node,
18129 name))
18130 vty_out(vty, " import vrf %s\n", name);
18131 }
18132 }
18133
18134 vty_endframe(vty, " exit-address-family\n");
18135 }
18136
18137 int bgp_config_write(struct vty *vty)
18138 {
18139 struct bgp *bgp;
18140 struct peer_group *group;
18141 struct peer *peer;
18142 struct listnode *node, *nnode;
18143 struct listnode *mnode, *mnnode;
18144 afi_t afi;
18145 safi_t safi;
18146 uint32_t tovpn_sid_index = 0;
18147
18148 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
18149 vty_out(vty, "bgp route-map delay-timer %u\n",
18150 bm->rmap_update_timer);
18151
18152 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
18153 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
18154 if (bm->v_update_delay != bm->v_establish_wait)
18155 vty_out(vty, " %d", bm->v_establish_wait);
18156 vty_out(vty, "\n");
18157 }
18158
18159 if (bm->wait_for_fib)
18160 vty_out(vty, "bgp suppress-fib-pending\n");
18161
18162 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18163 vty_out(vty, "bgp graceful-shutdown\n");
18164
18165 /* No-RIB (Zebra) option flag configuration */
18166 if (bgp_option_check(BGP_OPT_NO_FIB))
18167 vty_out(vty, "bgp no-rib\n");
18168
18169 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
18170 vty_out(vty, "bgp send-extra-data zebra\n");
18171
18172 /* BGP session DSCP value */
18173 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
18174 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
18175
18176 /* BGP InQ limit */
18177 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
18178 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
18179
18180 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
18181 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
18182
18183 /* BGP configuration. */
18184 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
18185
18186 /* skip all auto created vrf as they dont have user config */
18187 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
18188 continue;
18189
18190 /* Router bgp ASN */
18191 vty_out(vty, "router bgp %s", bgp->as_pretty);
18192
18193 if (bgp->name)
18194 vty_out(vty, " %s %s",
18195 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
18196 ? "view" : "vrf", bgp->name);
18197 if (CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION))
18198 vty_out(vty, " as-notation %s",
18199 asn_mode2str(bgp->asnotation));
18200
18201 vty_out(vty, "\n");
18202
18203 /* BGP fast-external-failover. */
18204 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18205 vty_out(vty, " no bgp fast-external-failover\n");
18206
18207 /* BGP router ID. */
18208 if (bgp->router_id_static.s_addr != INADDR_ANY)
18209 vty_out(vty, " bgp router-id %pI4\n",
18210 &bgp->router_id_static);
18211
18212 /* Suppress fib pending */
18213 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18214 vty_out(vty, " bgp suppress-fib-pending\n");
18215
18216 /* BGP log-neighbor-changes. */
18217 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18218 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
18219 vty_out(vty, " %sbgp log-neighbor-changes\n",
18220 CHECK_FLAG(bgp->flags,
18221 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18222 ? ""
18223 : "no ");
18224
18225 /* BGP configuration. */
18226 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
18227 vty_out(vty, " bgp always-compare-med\n");
18228
18229 /* RFC8212 default eBGP policy. */
18230 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18231 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18232 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18233 CHECK_FLAG(bgp->flags,
18234 BGP_FLAG_EBGP_REQUIRES_POLICY)
18235 ? ""
18236 : "no ");
18237
18238 /* draft-ietf-idr-deprecate-as-set-confed-set */
18239 if (bgp->reject_as_sets)
18240 vty_out(vty, " bgp reject-as-sets\n");
18241
18242 /* Suppress duplicate updates if the route actually not changed
18243 */
18244 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18245 != SAVE_BGP_SUPPRESS_DUPLICATES)
18246 vty_out(vty, " %sbgp suppress-duplicates\n",
18247 CHECK_FLAG(bgp->flags,
18248 BGP_FLAG_SUPPRESS_DUPLICATES)
18249 ? ""
18250 : "no ");
18251
18252 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18253 */
18254 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18255 SAVE_BGP_HARD_ADMIN_RESET)
18256 vty_out(vty, " %sbgp hard-administrative-reset\n",
18257 CHECK_FLAG(bgp->flags,
18258 BGP_FLAG_HARD_ADMIN_RESET)
18259 ? ""
18260 : "no ");
18261
18262 /* BGP default <afi>-<safi> */
18263 FOREACH_AFI_SAFI (afi, safi) {
18264 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18265 if (!bgp->default_af[afi][safi])
18266 vty_out(vty, " no bgp default %s\n",
18267 get_bgp_default_af_flag(afi,
18268 safi));
18269 } else if (bgp->default_af[afi][safi])
18270 vty_out(vty, " bgp default %s\n",
18271 get_bgp_default_af_flag(afi, safi));
18272 }
18273
18274 /* BGP default local-preference. */
18275 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18276 vty_out(vty, " bgp default local-preference %u\n",
18277 bgp->default_local_pref);
18278
18279 /* BGP default show-hostname */
18280 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18281 != SAVE_BGP_SHOW_HOSTNAME)
18282 vty_out(vty, " %sbgp default show-hostname\n",
18283 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18284 ? ""
18285 : "no ");
18286
18287 /* BGP default show-nexthop-hostname */
18288 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18289 != SAVE_BGP_SHOW_HOSTNAME)
18290 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18291 CHECK_FLAG(bgp->flags,
18292 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18293 ? ""
18294 : "no ");
18295
18296 /* BGP default subgroup-pkt-queue-max. */
18297 if (bgp->default_subgroup_pkt_queue_max
18298 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18299 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18300 bgp->default_subgroup_pkt_queue_max);
18301
18302 /* BGP client-to-client reflection. */
18303 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18304 vty_out(vty, " no bgp client-to-client reflection\n");
18305
18306 /* BGP cluster ID. */
18307 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18308 vty_out(vty, " bgp cluster-id %pI4\n",
18309 &bgp->cluster_id);
18310
18311 /* Disable ebgp connected nexthop check */
18312 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18313 vty_out(vty,
18314 " bgp disable-ebgp-connected-route-check\n");
18315
18316 /* Confederation identifier*/
18317 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18318 vty_out(vty, " bgp confederation identifier %s\n",
18319 bgp->confed_id_pretty);
18320
18321 /* Confederation peer */
18322 if (bgp->confed_peers_cnt > 0) {
18323 int i;
18324
18325 vty_out(vty, " bgp confederation peers");
18326
18327 for (i = 0; i < bgp->confed_peers_cnt; i++)
18328 vty_out(vty, " %s",
18329 bgp->confed_peers[i].as_pretty);
18330
18331 vty_out(vty, "\n");
18332 }
18333
18334 /* BGP deterministic-med. */
18335 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18336 != SAVE_BGP_DETERMINISTIC_MED)
18337 vty_out(vty, " %sbgp deterministic-med\n",
18338 CHECK_FLAG(bgp->flags,
18339 BGP_FLAG_DETERMINISTIC_MED)
18340 ? ""
18341 : "no ");
18342
18343 /* BGP update-delay. */
18344 bgp_config_write_update_delay(vty, bgp);
18345
18346 if (bgp->v_maxmed_onstartup
18347 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18348 vty_out(vty, " bgp max-med on-startup %u",
18349 bgp->v_maxmed_onstartup);
18350 if (bgp->maxmed_onstartup_value
18351 != BGP_MAXMED_VALUE_DEFAULT)
18352 vty_out(vty, " %u",
18353 bgp->maxmed_onstartup_value);
18354 vty_out(vty, "\n");
18355 }
18356 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18357 vty_out(vty, " bgp max-med administrative");
18358 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18359 vty_out(vty, " %u", bgp->maxmed_admin_value);
18360 vty_out(vty, "\n");
18361 }
18362
18363 /* write quanta */
18364 bgp_config_write_wpkt_quanta(vty, bgp);
18365 /* read quanta */
18366 bgp_config_write_rpkt_quanta(vty, bgp);
18367
18368 /* coalesce time */
18369 bgp_config_write_coalesce_time(vty, bgp);
18370
18371 /* BGP per-instance graceful-shutdown */
18372 /* BGP-wide settings and per-instance settings are mutually
18373 * exclusive.
18374 */
18375 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18376 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18377 vty_out(vty, " bgp graceful-shutdown\n");
18378
18379 /* Long-lived Graceful Restart */
18380 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18381 vty_out(vty,
18382 " bgp long-lived-graceful-restart stale-time %u\n",
18383 bgp->llgr_stale_time);
18384
18385 /* BGP graceful-restart. */
18386 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18387 vty_out(vty,
18388 " bgp graceful-restart stalepath-time %u\n",
18389 bgp->stalepath_time);
18390
18391 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18392 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18393 bgp->restart_time);
18394
18395 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18396 SAVE_BGP_GRACEFUL_NOTIFICATION)
18397 vty_out(vty, " %sbgp graceful-restart notification\n",
18398 CHECK_FLAG(bgp->flags,
18399 BGP_FLAG_GRACEFUL_NOTIFICATION)
18400 ? ""
18401 : "no ");
18402
18403 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18404 vty_out(vty,
18405 " bgp graceful-restart select-defer-time %u\n",
18406 bgp->select_defer_time);
18407
18408 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18409 vty_out(vty, " bgp graceful-restart\n");
18410
18411 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18412 vty_out(vty, " bgp graceful-restart-disable\n");
18413
18414 /* BGP graceful-restart Preserve State F bit. */
18415 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18416 vty_out(vty,
18417 " bgp graceful-restart preserve-fw-state\n");
18418
18419 /* BGP TCP keepalive */
18420 bgp_config_tcp_keepalive(vty, bgp);
18421
18422 /* Stale timer for RIB */
18423 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18424 vty_out(vty,
18425 " bgp graceful-restart rib-stale-time %u\n",
18426 bgp->rib_stale_time);
18427
18428 /* BGP bestpath method. */
18429 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18430 vty_out(vty, " bgp bestpath as-path ignore\n");
18431 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18432 vty_out(vty, " bgp bestpath as-path confed\n");
18433
18434 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18435 if (CHECK_FLAG(bgp->flags,
18436 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18437 vty_out(vty,
18438 " bgp bestpath as-path multipath-relax as-set\n");
18439 } else {
18440 vty_out(vty,
18441 " bgp bestpath as-path multipath-relax\n");
18442 }
18443 }
18444
18445 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18446 vty_out(vty,
18447 " bgp route-reflector allow-outbound-policy\n");
18448 }
18449 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18450 vty_out(vty, " bgp bestpath compare-routerid\n");
18451 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18452 vty_out(vty, " bgp bestpath aigp\n");
18453 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18454 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18455 vty_out(vty, " bgp bestpath med");
18456 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18457 vty_out(vty, " confed");
18458 if (CHECK_FLAG(bgp->flags,
18459 BGP_FLAG_MED_MISSING_AS_WORST))
18460 vty_out(vty, " missing-as-worst");
18461 vty_out(vty, "\n");
18462 }
18463
18464 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18465 vty_out(vty,
18466 " bgp bestpath peer-type multipath-relax\n");
18467
18468 /* Link bandwidth handling. */
18469 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18470 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18471 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18472 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18473 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18474 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18475
18476 /* BGP network import check. */
18477 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18478 != SAVE_BGP_IMPORT_CHECK)
18479 vty_out(vty, " %sbgp network import-check\n",
18480 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18481 ? ""
18482 : "no ");
18483
18484 /* BGP timers configuration. */
18485 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18486 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18487 vty_out(vty, " timers bgp %u %u\n",
18488 bgp->default_keepalive, bgp->default_holdtime);
18489
18490 /* BGP minimum holdtime configuration. */
18491 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18492 && bgp->default_min_holdtime != 0)
18493 vty_out(vty, " bgp minimum-holdtime %u\n",
18494 bgp->default_min_holdtime);
18495
18496 /* Conditional advertisement timer configuration */
18497 if (bgp->condition_check_period
18498 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18499 vty_out(vty,
18500 " bgp conditional-advertisement timer %u\n",
18501 bgp->condition_check_period);
18502
18503 /* peer-group */
18504 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18505 bgp_config_write_peer_global(vty, bgp, group->conf);
18506 }
18507
18508 /* Normal neighbor configuration. */
18509 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18510 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18511 bgp_config_write_peer_global(vty, bgp, peer);
18512 }
18513
18514 /* listen range and limit for dynamic BGP neighbors */
18515 bgp_config_write_listen(vty, bgp);
18516
18517 /*
18518 * BGP default autoshutdown neighbors
18519 *
18520 * This must be placed after any peer and peer-group
18521 * configuration, to avoid setting all peers to shutdown after
18522 * a daemon restart, which is undesired behavior. (see #2286)
18523 */
18524 if (bgp->autoshutdown)
18525 vty_out(vty, " bgp default shutdown\n");
18526
18527 /* BGP instance administrative shutdown */
18528 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18529 vty_out(vty, " bgp shutdown\n");
18530
18531 if (bgp->allow_martian)
18532 vty_out(vty, " bgp allow-martian-nexthop\n");
18533
18534 if (bgp->fast_convergence)
18535 vty_out(vty, " bgp fast-convergence\n");
18536
18537 if (bgp->srv6_enabled) {
18538 vty_frame(vty, " !\n segment-routing srv6\n");
18539 if (strlen(bgp->srv6_locator_name))
18540 vty_out(vty, " locator %s\n",
18541 bgp->srv6_locator_name);
18542 vty_endframe(vty, " exit\n");
18543 }
18544
18545 tovpn_sid_index = bgp->tovpn_sid_index;
18546 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18547 vty_out(vty, " sid vpn per-vrf export auto\n");
18548 } else if (tovpn_sid_index != 0) {
18549 vty_out(vty, " sid vpn per-vrf export %d\n",
18550 tovpn_sid_index);
18551 }
18552
18553 /* IPv4 unicast configuration. */
18554 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18555
18556 /* IPv4 multicast configuration. */
18557 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18558
18559 /* IPv4 labeled-unicast configuration. */
18560 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18561
18562 /* IPv4 VPN configuration. */
18563 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18564
18565 /* ENCAPv4 configuration. */
18566 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18567
18568 /* FLOWSPEC v4 configuration. */
18569 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18570
18571 /* IPv6 unicast configuration. */
18572 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18573
18574 /* IPv6 multicast configuration. */
18575 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18576
18577 /* IPv6 labeled-unicast configuration. */
18578 bgp_config_write_family(vty, bgp, AFI_IP6,
18579 SAFI_LABELED_UNICAST);
18580
18581 /* IPv6 VPN configuration. */
18582 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18583
18584 /* ENCAPv6 configuration. */
18585 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18586
18587 /* FLOWSPEC v6 configuration. */
18588 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18589
18590 /* EVPN configuration. */
18591 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18592
18593 hook_call(bgp_inst_config_write, bgp, vty);
18594
18595 #ifdef ENABLE_BGP_VNC
18596 bgp_rfapi_cfg_write(vty, bgp);
18597 #endif
18598
18599 vty_out(vty, "exit\n");
18600 vty_out(vty, "!\n");
18601 }
18602 return 0;
18603 }
18604
18605
18606 /* BGP node structure. */
18607 static struct cmd_node bgp_node = {
18608 .name = "bgp",
18609 .node = BGP_NODE,
18610 .parent_node = CONFIG_NODE,
18611 .prompt = "%s(config-router)# ",
18612 .config_write = bgp_config_write,
18613 };
18614
18615 static struct cmd_node bgp_ipv4_unicast_node = {
18616 .name = "bgp ipv4 unicast",
18617 .node = BGP_IPV4_NODE,
18618 .parent_node = BGP_NODE,
18619 .prompt = "%s(config-router-af)# ",
18620 .no_xpath = true,
18621 };
18622
18623 static struct cmd_node bgp_ipv4_multicast_node = {
18624 .name = "bgp ipv4 multicast",
18625 .node = BGP_IPV4M_NODE,
18626 .parent_node = BGP_NODE,
18627 .prompt = "%s(config-router-af)# ",
18628 .no_xpath = true,
18629 };
18630
18631 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18632 .name = "bgp ipv4 labeled unicast",
18633 .node = BGP_IPV4L_NODE,
18634 .parent_node = BGP_NODE,
18635 .prompt = "%s(config-router-af)# ",
18636 .no_xpath = true,
18637 };
18638
18639 static struct cmd_node bgp_ipv6_unicast_node = {
18640 .name = "bgp ipv6 unicast",
18641 .node = BGP_IPV6_NODE,
18642 .parent_node = BGP_NODE,
18643 .prompt = "%s(config-router-af)# ",
18644 .no_xpath = true,
18645 };
18646
18647 static struct cmd_node bgp_ipv6_multicast_node = {
18648 .name = "bgp ipv6 multicast",
18649 .node = BGP_IPV6M_NODE,
18650 .parent_node = BGP_NODE,
18651 .prompt = "%s(config-router-af)# ",
18652 .no_xpath = true,
18653 };
18654
18655 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18656 .name = "bgp ipv6 labeled unicast",
18657 .node = BGP_IPV6L_NODE,
18658 .parent_node = BGP_NODE,
18659 .prompt = "%s(config-router-af)# ",
18660 .no_xpath = true,
18661 };
18662
18663 static struct cmd_node bgp_vpnv4_node = {
18664 .name = "bgp vpnv4",
18665 .node = BGP_VPNV4_NODE,
18666 .parent_node = BGP_NODE,
18667 .prompt = "%s(config-router-af)# ",
18668 .no_xpath = true,
18669 };
18670
18671 static struct cmd_node bgp_vpnv6_node = {
18672 .name = "bgp vpnv6",
18673 .node = BGP_VPNV6_NODE,
18674 .parent_node = BGP_NODE,
18675 .prompt = "%s(config-router-af-vpnv6)# ",
18676 .no_xpath = true,
18677 };
18678
18679 static struct cmd_node bgp_evpn_node = {
18680 .name = "bgp evpn",
18681 .node = BGP_EVPN_NODE,
18682 .parent_node = BGP_NODE,
18683 .prompt = "%s(config-router-evpn)# ",
18684 .no_xpath = true,
18685 };
18686
18687 static struct cmd_node bgp_evpn_vni_node = {
18688 .name = "bgp evpn vni",
18689 .node = BGP_EVPN_VNI_NODE,
18690 .parent_node = BGP_EVPN_NODE,
18691 .prompt = "%s(config-router-af-vni)# ",
18692 };
18693
18694 static struct cmd_node bgp_flowspecv4_node = {
18695 .name = "bgp ipv4 flowspec",
18696 .node = BGP_FLOWSPECV4_NODE,
18697 .parent_node = BGP_NODE,
18698 .prompt = "%s(config-router-af)# ",
18699 .no_xpath = true,
18700 };
18701
18702 static struct cmd_node bgp_flowspecv6_node = {
18703 .name = "bgp ipv6 flowspec",
18704 .node = BGP_FLOWSPECV6_NODE,
18705 .parent_node = BGP_NODE,
18706 .prompt = "%s(config-router-af-vpnv6)# ",
18707 .no_xpath = true,
18708 };
18709
18710 static struct cmd_node bgp_srv6_node = {
18711 .name = "bgp srv6",
18712 .node = BGP_SRV6_NODE,
18713 .parent_node = BGP_NODE,
18714 .prompt = "%s(config-router-srv6)# ",
18715 };
18716
18717 static void community_list_vty(void);
18718
18719 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18720 {
18721 struct bgp *bgp;
18722 struct peer_group *group;
18723 struct listnode *lnbgp, *lnpeer;
18724
18725 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18726 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18727 vector_set(comps,
18728 XSTRDUP(MTYPE_COMPLETION, group->name));
18729 }
18730 }
18731
18732 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18733 {
18734 struct bgp *bgp;
18735 struct peer *peer;
18736 struct listnode *lnbgp, *lnpeer;
18737
18738 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18739 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18740 /* only provide suggestions on the appropriate input
18741 * token type,
18742 * they'll otherwise show up multiple times */
18743 enum cmd_token_type match_type;
18744 char *name = peer->host;
18745
18746 if (peer->conf_if) {
18747 match_type = VARIABLE_TKN;
18748 name = peer->conf_if;
18749 } else if (strchr(peer->host, ':'))
18750 match_type = IPV6_TKN;
18751 else
18752 match_type = IPV4_TKN;
18753
18754 if (token->type != match_type)
18755 continue;
18756
18757 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18758 }
18759 }
18760 }
18761
18762 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18763 {
18764 bgp_ac_peer(comps, token);
18765
18766 if (token->type == VARIABLE_TKN)
18767 bgp_ac_peergroup(comps, token);
18768 }
18769
18770 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18771 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18772 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18773 {.varname = "peer", .completions = bgp_ac_neighbor},
18774 {.completions = NULL}};
18775
18776 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18777 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18778 {.completions = NULL} };
18779
18780 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18781
18782 static struct thread *t_bgp_cfg;
18783
18784 bool bgp_config_inprocess(void)
18785 {
18786 return thread_is_scheduled(t_bgp_cfg);
18787 }
18788
18789 static void bgp_config_finish(struct thread *t)
18790 {
18791 struct listnode *node;
18792 struct bgp *bgp;
18793
18794 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18795 hook_call(bgp_config_end, bgp);
18796 }
18797
18798 static void bgp_config_start(void)
18799 {
18800 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18801 THREAD_OFF(t_bgp_cfg);
18802 thread_add_timer(bm->master, bgp_config_finish, NULL,
18803 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18804 }
18805
18806 /* When we receive a hook the configuration is read,
18807 * we start a timer to make sure we postpone sending
18808 * EoR before route-maps are processed.
18809 * This is especially valid if using `bgp route-map delay-timer`.
18810 */
18811 static void bgp_config_end(void)
18812 {
18813 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18814 uint32_t bgp_post_config_delay =
18815 thread_is_scheduled(bm->t_rmap_update)
18816 ? thread_timer_remain_second(bm->t_rmap_update)
18817 : BGP_POST_CONFIG_DELAY_SECONDS;
18818
18819 /* If BGP config processing thread isn't running, then
18820 * we can return and rely it's properly handled.
18821 */
18822 if (!bgp_config_inprocess())
18823 return;
18824
18825 THREAD_OFF(t_bgp_cfg);
18826
18827 /* Start a new timer to make sure we don't send EoR
18828 * before route-maps are processed.
18829 */
18830 thread_add_timer(bm->master, bgp_config_finish, NULL,
18831 bgp_post_config_delay, &t_bgp_cfg);
18832 }
18833
18834 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18835 {
18836 int write = 0;
18837 struct interface *ifp;
18838 struct bgp_interface *iifp;
18839
18840 FOR_ALL_INTERFACES (vrf, ifp) {
18841 iifp = ifp->info;
18842 if (!iifp)
18843 continue;
18844
18845 if_vty_config_start(vty, ifp);
18846
18847 if (CHECK_FLAG(iifp->flags,
18848 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18849 vty_out(vty, " mpls bgp forwarding\n");
18850 write++;
18851 }
18852
18853 if_vty_config_end(vty);
18854 }
18855
18856 return write;
18857 }
18858
18859 /* Configuration write function for bgpd. */
18860 static int config_write_interface(struct vty *vty)
18861 {
18862 int write = 0;
18863 struct vrf *vrf = NULL;
18864
18865 /* Display all VRF aware OSPF interface configuration */
18866 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18867 write += config_write_interface_one(vty, vrf);
18868 }
18869
18870 return write;
18871 }
18872
18873 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18874 "[no$no] mpls bgp forwarding",
18875 NO_STR MPLS_STR BGP_STR
18876 "Enable MPLS forwarding for eBGP directly connected peers\n")
18877 {
18878 bool check;
18879 struct bgp_interface *iifp;
18880
18881 VTY_DECLVAR_CONTEXT(interface, ifp);
18882 iifp = ifp->info;
18883 if (!iifp) {
18884 vty_out(vty, "Interface %s not available\n", ifp->name);
18885 return CMD_WARNING_CONFIG_FAILED;
18886 }
18887 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18888 if (check != !no) {
18889 if (no)
18890 UNSET_FLAG(iifp->flags,
18891 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18892 else
18893 SET_FLAG(iifp->flags,
18894 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18895 /* trigger a nht update on eBGP sessions */
18896 if (if_is_operative(ifp))
18897 bgp_nht_ifp_up(ifp);
18898 }
18899 return CMD_SUCCESS;
18900 }
18901
18902 DEFPY (bgp_inq_limit,
18903 bgp_inq_limit_cmd,
18904 "bgp input-queue-limit (1-4294967295)$limit",
18905 BGP_STR
18906 "Set the BGP Input Queue limit for all peers when message parsing\n"
18907 "Input-Queue limit\n")
18908 {
18909 bm->inq_limit = limit;
18910
18911 return CMD_SUCCESS;
18912 }
18913
18914 DEFPY (no_bgp_inq_limit,
18915 no_bgp_inq_limit_cmd,
18916 "no bgp input-queue-limit [(1-4294967295)$limit]",
18917 NO_STR
18918 BGP_STR
18919 "Set the BGP Input Queue limit for all peers when message parsing\n"
18920 "Input-Queue limit\n")
18921 {
18922 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18923
18924 return CMD_SUCCESS;
18925 }
18926
18927 DEFPY (bgp_outq_limit,
18928 bgp_outq_limit_cmd,
18929 "bgp output-queue-limit (1-4294967295)$limit",
18930 BGP_STR
18931 "Set the BGP Output Queue limit for all peers when message parsing\n"
18932 "Output-Queue limit\n")
18933 {
18934 bm->outq_limit = limit;
18935
18936 return CMD_SUCCESS;
18937 }
18938
18939 DEFPY (no_bgp_outq_limit,
18940 no_bgp_outq_limit_cmd,
18941 "no bgp output-queue-limit [(1-4294967295)$limit]",
18942 NO_STR
18943 BGP_STR
18944 "Set the BGP Output Queue limit for all peers when message parsing\n"
18945 "Output-Queue limit\n")
18946 {
18947 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18948
18949 return CMD_SUCCESS;
18950 }
18951
18952
18953 /* Initialization of BGP interface. */
18954 static void bgp_vty_if_init(void)
18955 {
18956 /* Install interface node. */
18957 if_cmd_init(config_write_interface);
18958
18959 /* "mpls bgp forwarding" commands. */
18960 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18961 }
18962
18963 void bgp_vty_init(void)
18964 {
18965 cmd_variable_handler_register(bgp_var_neighbor);
18966 cmd_variable_handler_register(bgp_var_peergroup);
18967
18968 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18969
18970 /* Install bgp top node. */
18971 install_node(&bgp_node);
18972 install_node(&bgp_ipv4_unicast_node);
18973 install_node(&bgp_ipv4_multicast_node);
18974 install_node(&bgp_ipv4_labeled_unicast_node);
18975 install_node(&bgp_ipv6_unicast_node);
18976 install_node(&bgp_ipv6_multicast_node);
18977 install_node(&bgp_ipv6_labeled_unicast_node);
18978 install_node(&bgp_vpnv4_node);
18979 install_node(&bgp_vpnv6_node);
18980 install_node(&bgp_evpn_node);
18981 install_node(&bgp_evpn_vni_node);
18982 install_node(&bgp_flowspecv4_node);
18983 install_node(&bgp_flowspecv6_node);
18984 install_node(&bgp_srv6_node);
18985
18986 /* Install default VTY commands to new nodes. */
18987 install_default(BGP_NODE);
18988 install_default(BGP_IPV4_NODE);
18989 install_default(BGP_IPV4M_NODE);
18990 install_default(BGP_IPV4L_NODE);
18991 install_default(BGP_IPV6_NODE);
18992 install_default(BGP_IPV6M_NODE);
18993 install_default(BGP_IPV6L_NODE);
18994 install_default(BGP_VPNV4_NODE);
18995 install_default(BGP_VPNV6_NODE);
18996 install_default(BGP_FLOWSPECV4_NODE);
18997 install_default(BGP_FLOWSPECV6_NODE);
18998 install_default(BGP_EVPN_NODE);
18999 install_default(BGP_EVPN_VNI_NODE);
19000 install_default(BGP_SRV6_NODE);
19001
19002 /* "global bgp inq-limit command */
19003 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
19004 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
19005 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
19006 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
19007
19008 /* "bgp local-mac" hidden commands. */
19009 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
19010 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
19011
19012 /* "bgp suppress-fib-pending" global */
19013 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
19014
19015 /* bgp route-map delay-timer commands. */
19016 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
19017 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19018
19019 install_element(BGP_NODE, &bgp_allow_martian_cmd);
19020
19021 /* bgp fast-convergence command */
19022 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
19023 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
19024
19025 /* global bgp update-delay command */
19026 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
19027 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
19028
19029 /* global bgp graceful-shutdown command */
19030 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
19031 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
19032
19033 /* Dummy commands (Currently not supported) */
19034 install_element(BGP_NODE, &no_synchronization_cmd);
19035 install_element(BGP_NODE, &no_auto_summary_cmd);
19036
19037 /* "router bgp" commands. */
19038 install_element(CONFIG_NODE, &router_bgp_cmd);
19039
19040 /* "no router bgp" commands. */
19041 install_element(CONFIG_NODE, &no_router_bgp_cmd);
19042
19043 /* "bgp session-dscp command */
19044 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
19045 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
19046
19047 /* "bgp router-id" commands. */
19048 install_element(BGP_NODE, &bgp_router_id_cmd);
19049 install_element(BGP_NODE, &no_bgp_router_id_cmd);
19050
19051 /* "bgp suppress-fib-pending" command */
19052 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
19053
19054 /* "bgp cluster-id" commands. */
19055 install_element(BGP_NODE, &bgp_cluster_id_cmd);
19056 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
19057
19058 /* "bgp no-rib" commands. */
19059 install_element(CONFIG_NODE, &bgp_norib_cmd);
19060 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
19061
19062 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
19063
19064 /* "bgp confederation" commands. */
19065 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
19066 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
19067
19068 /* "bgp confederation peers" commands. */
19069 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
19070 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
19071
19072 /* bgp max-med command */
19073 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
19074 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
19075 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
19076 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
19077 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
19078
19079 /* "neighbor role" commands. */
19080 install_element(BGP_NODE, &neighbor_role_cmd);
19081 install_element(BGP_NODE, &neighbor_role_strict_cmd);
19082 install_element(BGP_NODE, &no_neighbor_role_cmd);
19083
19084 /* "neighbor aigp" commands. */
19085 install_element(BGP_NODE, &neighbor_aigp_cmd);
19086
19087 /* "neighbor graceful-shutdown" command */
19088 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
19089
19090 /* bgp disable-ebgp-connected-nh-check */
19091 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
19092 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
19093
19094 /* bgp update-delay command */
19095 install_element(BGP_NODE, &bgp_update_delay_cmd);
19096 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
19097
19098 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
19099 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
19100
19101 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
19102 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
19103
19104 /* "maximum-paths" commands. */
19105 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
19106 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
19107 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
19108 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
19109 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
19110 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
19111 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
19112 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
19113 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
19114 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
19115 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19116 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
19117 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
19118 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19119 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
19120
19121 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
19122 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
19123 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
19124 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19125 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
19126 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
19127 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
19128 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
19129 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19130 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
19131
19132 /* "timers bgp" commands. */
19133 install_element(BGP_NODE, &bgp_timers_cmd);
19134 install_element(BGP_NODE, &no_bgp_timers_cmd);
19135
19136 /* "minimum-holdtime" commands. */
19137 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
19138 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
19139
19140 /* route-map delay-timer commands - per instance for backwards compat.
19141 */
19142 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
19143 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19144
19145 /* "bgp client-to-client reflection" commands */
19146 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
19147 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
19148
19149 /* "bgp always-compare-med" commands */
19150 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
19151 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
19152
19153 /* bgp ebgp-requires-policy */
19154 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
19155 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
19156
19157 /* bgp suppress-duplicates */
19158 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
19159 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
19160
19161 /* bgp reject-as-sets */
19162 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
19163 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
19164
19165 /* "bgp deterministic-med" commands */
19166 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
19167 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
19168
19169 /* "bgp graceful-restart" command */
19170 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
19171 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
19172
19173 /* "bgp graceful-restart-disable" command */
19174 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
19175 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
19176
19177 /* "neighbor a:b:c:d graceful-restart" command */
19178 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
19179 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
19180
19181 /* "neighbor a:b:c:d graceful-restart-disable" command */
19182 install_element(BGP_NODE,
19183 &bgp_neighbor_graceful_restart_disable_set_cmd);
19184 install_element(BGP_NODE,
19185 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
19186
19187 /* "neighbor a:b:c:d graceful-restart-helper" command */
19188 install_element(BGP_NODE,
19189 &bgp_neighbor_graceful_restart_helper_set_cmd);
19190 install_element(BGP_NODE,
19191 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
19192
19193 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
19194 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
19195 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
19196 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
19197 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
19198 install_element(BGP_NODE,
19199 &no_bgp_graceful_restart_select_defer_time_cmd);
19200 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
19201 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
19202 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
19203
19204 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19205 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
19206 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19207 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
19208
19209 /* "bgp graceful-shutdown" commands */
19210 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19211 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19212
19213 /* "bgp hard-administrative-reset" commands */
19214 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19215
19216 /* "bgp long-lived-graceful-restart" commands */
19217 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19218 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19219
19220 /* "bgp fast-external-failover" commands */
19221 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19222 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19223
19224 /* "bgp bestpath aigp" commands */
19225 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19226
19227 /* "bgp bestpath compare-routerid" commands */
19228 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19229 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19230
19231 /* "bgp bestpath as-path ignore" commands */
19232 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19233 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19234
19235 /* "bgp bestpath as-path confed" commands */
19236 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19237 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19238
19239 /* "bgp bestpath as-path multipath-relax" commands */
19240 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19241 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19242
19243 /* "bgp bestpath peer-type multipath-relax" commands */
19244 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19245 install_element(BGP_NODE,
19246 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19247
19248 /* "bgp log-neighbor-changes" commands */
19249 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19250 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19251
19252 /* "bgp bestpath med" commands */
19253 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19254 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19255
19256 /* "bgp bestpath bandwidth" commands */
19257 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
19258 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
19259
19260 /* "no bgp default <afi>-<safi>" commands. */
19261 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
19262
19263 /* "bgp network import-check" commands. */
19264 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19265 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19266 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19267
19268 /* "bgp default local-preference" commands. */
19269 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19270 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19271
19272 /* bgp default show-hostname */
19273 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19274 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19275
19276 /* bgp default show-nexthop-hostname */
19277 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19278 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19279
19280 /* "bgp default subgroup-pkt-queue-max" commands. */
19281 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19282 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19283
19284 /* bgp ibgp-allow-policy-mods command */
19285 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19286 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19287
19288 /* "bgp listen limit" commands. */
19289 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19290 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19291
19292 /* "bgp listen range" commands. */
19293 install_element(BGP_NODE, &bgp_listen_range_cmd);
19294 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19295
19296 /* "bgp default shutdown" command */
19297 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19298
19299 /* "bgp shutdown" commands */
19300 install_element(BGP_NODE, &bgp_shutdown_cmd);
19301 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19302 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19303 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19304
19305 /* "neighbor remote-as" commands. */
19306 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19307 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19308 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19309 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19310 install_element(BGP_NODE,
19311 &neighbor_interface_v6only_config_remote_as_cmd);
19312 install_element(BGP_NODE, &no_neighbor_cmd);
19313 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19314
19315 /* "neighbor peer-group" commands. */
19316 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19317 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19318 install_element(BGP_NODE,
19319 &no_neighbor_interface_peer_group_remote_as_cmd);
19320
19321 /* "neighbor local-as" commands. */
19322 install_element(BGP_NODE, &neighbor_local_as_cmd);
19323 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19324 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19325 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19326
19327 /* "neighbor solo" commands. */
19328 install_element(BGP_NODE, &neighbor_solo_cmd);
19329 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19330
19331 /* "neighbor password" commands. */
19332 install_element(BGP_NODE, &neighbor_password_cmd);
19333 install_element(BGP_NODE, &no_neighbor_password_cmd);
19334
19335 /* "neighbor activate" commands. */
19336 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19337 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19338 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19339 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19340 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19341 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19342 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19343 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19344 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19345 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19346 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19347 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19348
19349 /* "no neighbor activate" commands. */
19350 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19351 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19352 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19353 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19354 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19355 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19356 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19357 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19358 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19359 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19360 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19361 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19362
19363 /* "neighbor peer-group" set commands. */
19364 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19365 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19366 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19367 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19368 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19369 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19370 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19371 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19372 install_element(BGP_FLOWSPECV4_NODE,
19373 &neighbor_set_peer_group_hidden_cmd);
19374 install_element(BGP_FLOWSPECV6_NODE,
19375 &neighbor_set_peer_group_hidden_cmd);
19376
19377 /* "no neighbor peer-group unset" commands. */
19378 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19379 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19380 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19381 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19382 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19383 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19384 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19385 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19386 install_element(BGP_FLOWSPECV4_NODE,
19387 &no_neighbor_set_peer_group_hidden_cmd);
19388 install_element(BGP_FLOWSPECV6_NODE,
19389 &no_neighbor_set_peer_group_hidden_cmd);
19390
19391 /* "neighbor softreconfiguration inbound" commands.*/
19392 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19393 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19394 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19395 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19396 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19397 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19398 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19399 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19400 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19401 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19402 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19403 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19404 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19405 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19406 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19407 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19408 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19409 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19410 install_element(BGP_FLOWSPECV4_NODE,
19411 &neighbor_soft_reconfiguration_cmd);
19412 install_element(BGP_FLOWSPECV4_NODE,
19413 &no_neighbor_soft_reconfiguration_cmd);
19414 install_element(BGP_FLOWSPECV6_NODE,
19415 &neighbor_soft_reconfiguration_cmd);
19416 install_element(BGP_FLOWSPECV6_NODE,
19417 &no_neighbor_soft_reconfiguration_cmd);
19418 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19419 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19420
19421 /* "neighbor attribute-unchanged" commands. */
19422 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19423 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19424 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19425 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19426 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19427 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19428 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19429 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19430 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19431 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19432 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19433 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19434 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19435 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19436 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19437 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19438 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19439 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19440
19441 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19442 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19443
19444 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19445 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19446 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19447 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19448
19449 /* "nexthop-local unchanged" commands */
19450 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19451 install_element(BGP_IPV6_NODE,
19452 &no_neighbor_nexthop_local_unchanged_cmd);
19453
19454 /* "neighbor next-hop-self" commands. */
19455 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19456 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19457 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19458 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19459 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19460 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19461 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19462 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19463 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19464 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19465 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19466 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19467 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19468 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19469 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19470 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19471 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19472 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19473 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19474 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19475
19476 /* "neighbor next-hop-self force" commands. */
19477 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19478 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19479 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19480 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19481 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19482 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19483 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19484 install_element(BGP_IPV4_NODE,
19485 &no_neighbor_nexthop_self_all_hidden_cmd);
19486 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19487 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19488 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19489 install_element(BGP_IPV4M_NODE,
19490 &no_neighbor_nexthop_self_all_hidden_cmd);
19491 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19492 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19493 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19494 install_element(BGP_IPV4L_NODE,
19495 &no_neighbor_nexthop_self_all_hidden_cmd);
19496 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19497 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19498 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19499 install_element(BGP_IPV6_NODE,
19500 &no_neighbor_nexthop_self_all_hidden_cmd);
19501 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19502 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19503 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19504 install_element(BGP_IPV6M_NODE,
19505 &no_neighbor_nexthop_self_all_hidden_cmd);
19506 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19507 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19508 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19509 install_element(BGP_IPV6L_NODE,
19510 &no_neighbor_nexthop_self_all_hidden_cmd);
19511 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19512 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19513 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19514 install_element(BGP_VPNV4_NODE,
19515 &no_neighbor_nexthop_self_all_hidden_cmd);
19516 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19517 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19518 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19519 install_element(BGP_VPNV6_NODE,
19520 &no_neighbor_nexthop_self_all_hidden_cmd);
19521 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19522 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19523
19524 /* "neighbor as-override" commands. */
19525 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19526 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19527 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19528 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19529 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19530 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19531 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19532 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19533 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19534 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19535 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19536 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19537 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19538 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19539 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19540 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19541 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19542 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19543
19544 /* "neighbor remove-private-AS" commands. */
19545 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19546 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19547 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19548 install_element(BGP_NODE,
19549 &no_neighbor_remove_private_as_all_hidden_cmd);
19550 install_element(BGP_NODE,
19551 &neighbor_remove_private_as_replace_as_hidden_cmd);
19552 install_element(BGP_NODE,
19553 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19554 install_element(BGP_NODE,
19555 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19556 install_element(
19557 BGP_NODE,
19558 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19559 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19560 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19561 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19562 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19563 install_element(BGP_IPV4_NODE,
19564 &neighbor_remove_private_as_replace_as_cmd);
19565 install_element(BGP_IPV4_NODE,
19566 &no_neighbor_remove_private_as_replace_as_cmd);
19567 install_element(BGP_IPV4_NODE,
19568 &neighbor_remove_private_as_all_replace_as_cmd);
19569 install_element(BGP_IPV4_NODE,
19570 &no_neighbor_remove_private_as_all_replace_as_cmd);
19571 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19572 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19573 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19574 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19575 install_element(BGP_IPV4M_NODE,
19576 &neighbor_remove_private_as_replace_as_cmd);
19577 install_element(BGP_IPV4M_NODE,
19578 &no_neighbor_remove_private_as_replace_as_cmd);
19579 install_element(BGP_IPV4M_NODE,
19580 &neighbor_remove_private_as_all_replace_as_cmd);
19581 install_element(BGP_IPV4M_NODE,
19582 &no_neighbor_remove_private_as_all_replace_as_cmd);
19583 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19584 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19585 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19586 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19587 install_element(BGP_IPV4L_NODE,
19588 &neighbor_remove_private_as_replace_as_cmd);
19589 install_element(BGP_IPV4L_NODE,
19590 &no_neighbor_remove_private_as_replace_as_cmd);
19591 install_element(BGP_IPV4L_NODE,
19592 &neighbor_remove_private_as_all_replace_as_cmd);
19593 install_element(BGP_IPV4L_NODE,
19594 &no_neighbor_remove_private_as_all_replace_as_cmd);
19595 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19596 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19597 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19598 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19599 install_element(BGP_IPV6_NODE,
19600 &neighbor_remove_private_as_replace_as_cmd);
19601 install_element(BGP_IPV6_NODE,
19602 &no_neighbor_remove_private_as_replace_as_cmd);
19603 install_element(BGP_IPV6_NODE,
19604 &neighbor_remove_private_as_all_replace_as_cmd);
19605 install_element(BGP_IPV6_NODE,
19606 &no_neighbor_remove_private_as_all_replace_as_cmd);
19607 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19608 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19609 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19610 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19611 install_element(BGP_IPV6M_NODE,
19612 &neighbor_remove_private_as_replace_as_cmd);
19613 install_element(BGP_IPV6M_NODE,
19614 &no_neighbor_remove_private_as_replace_as_cmd);
19615 install_element(BGP_IPV6M_NODE,
19616 &neighbor_remove_private_as_all_replace_as_cmd);
19617 install_element(BGP_IPV6M_NODE,
19618 &no_neighbor_remove_private_as_all_replace_as_cmd);
19619 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19620 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19621 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19622 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19623 install_element(BGP_IPV6L_NODE,
19624 &neighbor_remove_private_as_replace_as_cmd);
19625 install_element(BGP_IPV6L_NODE,
19626 &no_neighbor_remove_private_as_replace_as_cmd);
19627 install_element(BGP_IPV6L_NODE,
19628 &neighbor_remove_private_as_all_replace_as_cmd);
19629 install_element(BGP_IPV6L_NODE,
19630 &no_neighbor_remove_private_as_all_replace_as_cmd);
19631 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19632 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19633 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19634 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19635 install_element(BGP_VPNV4_NODE,
19636 &neighbor_remove_private_as_replace_as_cmd);
19637 install_element(BGP_VPNV4_NODE,
19638 &no_neighbor_remove_private_as_replace_as_cmd);
19639 install_element(BGP_VPNV4_NODE,
19640 &neighbor_remove_private_as_all_replace_as_cmd);
19641 install_element(BGP_VPNV4_NODE,
19642 &no_neighbor_remove_private_as_all_replace_as_cmd);
19643 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19644 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19645 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19646 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19647 install_element(BGP_VPNV6_NODE,
19648 &neighbor_remove_private_as_replace_as_cmd);
19649 install_element(BGP_VPNV6_NODE,
19650 &no_neighbor_remove_private_as_replace_as_cmd);
19651 install_element(BGP_VPNV6_NODE,
19652 &neighbor_remove_private_as_all_replace_as_cmd);
19653 install_element(BGP_VPNV6_NODE,
19654 &no_neighbor_remove_private_as_all_replace_as_cmd);
19655
19656 /* "neighbor send-community" commands.*/
19657 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19658 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19659 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19660 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19661 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19662 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19663 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19664 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19665 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19666 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19667 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19668 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19669 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19670 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19671 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19672 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19673 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19674 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19675 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19676 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19677 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19678 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19679 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19680 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19681 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19682 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19683 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19684 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19685 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19686 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19687 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19688 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19689 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19690 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19691 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19692 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19693
19694 /* "neighbor route-reflector" commands.*/
19695 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19696 install_element(BGP_NODE,
19697 &no_neighbor_route_reflector_client_hidden_cmd);
19698 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19699 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19700 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19701 install_element(BGP_IPV4M_NODE,
19702 &no_neighbor_route_reflector_client_cmd);
19703 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19704 install_element(BGP_IPV4L_NODE,
19705 &no_neighbor_route_reflector_client_cmd);
19706 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19707 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19708 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19709 install_element(BGP_IPV6M_NODE,
19710 &no_neighbor_route_reflector_client_cmd);
19711 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19712 install_element(BGP_IPV6L_NODE,
19713 &no_neighbor_route_reflector_client_cmd);
19714 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19715 install_element(BGP_VPNV4_NODE,
19716 &no_neighbor_route_reflector_client_cmd);
19717 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19718 install_element(BGP_VPNV6_NODE,
19719 &no_neighbor_route_reflector_client_cmd);
19720 install_element(BGP_FLOWSPECV4_NODE,
19721 &neighbor_route_reflector_client_cmd);
19722 install_element(BGP_FLOWSPECV4_NODE,
19723 &no_neighbor_route_reflector_client_cmd);
19724 install_element(BGP_FLOWSPECV6_NODE,
19725 &neighbor_route_reflector_client_cmd);
19726 install_element(BGP_FLOWSPECV6_NODE,
19727 &no_neighbor_route_reflector_client_cmd);
19728 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19729 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19730
19731 /* "neighbor route-server" commands.*/
19732 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19733 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19734 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19735 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19736 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19737 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19738 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19739 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19740 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19741 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19742 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19743 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19744 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19745 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19746 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19747 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19748 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19749 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19750 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19751 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19752 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19753 install_element(BGP_FLOWSPECV4_NODE,
19754 &no_neighbor_route_server_client_cmd);
19755 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19756 install_element(BGP_FLOWSPECV6_NODE,
19757 &no_neighbor_route_server_client_cmd);
19758
19759 /* "neighbor disable-addpath-rx" commands. */
19760 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19761 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19762 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19763 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19764 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19765 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19766 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19767 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19768 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19769 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19770 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19771 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19772 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19773 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19774 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19775 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19776
19777 /* "neighbor addpath-tx-all-paths" commands.*/
19778 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19779 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19780 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19781 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19782 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19783 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19784 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19785 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19786 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19787 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19788 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19789 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19790 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19791 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19792 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19793 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19794 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19795 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19796
19797 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19798 install_element(BGP_NODE,
19799 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19800 install_element(BGP_NODE,
19801 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19802 install_element(BGP_IPV4_NODE,
19803 &neighbor_addpath_tx_bestpath_per_as_cmd);
19804 install_element(BGP_IPV4_NODE,
19805 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19806 install_element(BGP_IPV4M_NODE,
19807 &neighbor_addpath_tx_bestpath_per_as_cmd);
19808 install_element(BGP_IPV4M_NODE,
19809 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19810 install_element(BGP_IPV4L_NODE,
19811 &neighbor_addpath_tx_bestpath_per_as_cmd);
19812 install_element(BGP_IPV4L_NODE,
19813 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19814 install_element(BGP_IPV6_NODE,
19815 &neighbor_addpath_tx_bestpath_per_as_cmd);
19816 install_element(BGP_IPV6_NODE,
19817 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19818 install_element(BGP_IPV6M_NODE,
19819 &neighbor_addpath_tx_bestpath_per_as_cmd);
19820 install_element(BGP_IPV6M_NODE,
19821 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19822 install_element(BGP_IPV6L_NODE,
19823 &neighbor_addpath_tx_bestpath_per_as_cmd);
19824 install_element(BGP_IPV6L_NODE,
19825 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19826 install_element(BGP_VPNV4_NODE,
19827 &neighbor_addpath_tx_bestpath_per_as_cmd);
19828 install_element(BGP_VPNV4_NODE,
19829 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19830 install_element(BGP_VPNV6_NODE,
19831 &neighbor_addpath_tx_bestpath_per_as_cmd);
19832 install_element(BGP_VPNV6_NODE,
19833 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19834
19835 /* "neighbor sender-as-path-loop-detection" commands. */
19836 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19837 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19838
19839 /* "neighbor path-attribute discard" commands. */
19840 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19841 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
19842
19843 /* "neighbor path-attribute treat-as-withdraw" commands. */
19844 install_element(BGP_NODE,
19845 &neighbor_path_attribute_treat_as_withdraw_cmd);
19846 install_element(BGP_NODE,
19847 &no_neighbor_path_attribute_treat_as_withdraw_cmd);
19848
19849 /* "neighbor passive" commands. */
19850 install_element(BGP_NODE, &neighbor_passive_cmd);
19851 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19852
19853
19854 /* "neighbor shutdown" commands. */
19855 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19856 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19857 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19858 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19859 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19860 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19861
19862 /* "neighbor capability extended-nexthop" commands.*/
19863 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19864 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19865
19866 /* "neighbor capability software-version" commands.*/
19867 install_element(BGP_NODE, &neighbor_capability_software_version_cmd);
19868
19869 /* "neighbor capability orf prefix-list" commands.*/
19870 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19871 install_element(BGP_NODE,
19872 &no_neighbor_capability_orf_prefix_hidden_cmd);
19873 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19874 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19875 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19876 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19877 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19878 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19879 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19880 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19881 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19882 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19883 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19884 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19885
19886 /* "neighbor capability dynamic" commands.*/
19887 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19888 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19889
19890 /* "neighbor dont-capability-negotiate" commands. */
19891 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19892 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19893
19894 /* "neighbor ebgp-multihop" commands. */
19895 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19896 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19897 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19898
19899 /* "neighbor disable-connected-check" commands. */
19900 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19901 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19902
19903 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19904 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19905 install_element(BGP_NODE,
19906 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19907
19908 /* "neighbor extended-optional-parameters" commands. */
19909 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19910 install_element(BGP_NODE,
19911 &no_neighbor_extended_optional_parameters_cmd);
19912
19913 /* "neighbor enforce-first-as" commands. */
19914 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19915 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19916
19917 /* "neighbor description" commands. */
19918 install_element(BGP_NODE, &neighbor_description_cmd);
19919 install_element(BGP_NODE, &no_neighbor_description_cmd);
19920 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19921
19922 /* "neighbor update-source" commands. "*/
19923 install_element(BGP_NODE, &neighbor_update_source_cmd);
19924 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19925
19926 /* "neighbor default-originate" commands. */
19927 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19928 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19929 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19930 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19931 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19932 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19933 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19934 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19935 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19936 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19937 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19938 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19939 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19940 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19941 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19942 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19943 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19944 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19945 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19946 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19947 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19948
19949 /* "neighbor port" commands. */
19950 install_element(BGP_NODE, &neighbor_port_cmd);
19951 install_element(BGP_NODE, &no_neighbor_port_cmd);
19952
19953 /* "neighbor weight" commands. */
19954 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19955 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19956
19957 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19958 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19959 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19960 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19961 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19962 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19963 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19964 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19965 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19966 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19967 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19968 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19969 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19970 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19971 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19972 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19973
19974 /* "neighbor override-capability" commands. */
19975 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19976 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19977
19978 /* "neighbor strict-capability-match" commands. */
19979 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19980 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19981
19982 /* "neighbor timers" commands. */
19983 install_element(BGP_NODE, &neighbor_timers_cmd);
19984 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19985
19986 /* "neighbor timers connect" commands. */
19987 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19988 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19989
19990 /* "neighbor timers delayopen" commands. */
19991 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19992 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19993
19994 /* "neighbor advertisement-interval" commands. */
19995 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19996 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19997
19998 /* "neighbor interface" commands. */
19999 install_element(BGP_NODE, &neighbor_interface_cmd);
20000 install_element(BGP_NODE, &no_neighbor_interface_cmd);
20001
20002 /* "neighbor distribute" commands. */
20003 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
20004 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
20005 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
20006 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
20007 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
20008 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
20009 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
20010 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
20011 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
20012 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
20013 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
20014 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
20015 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
20016 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
20017 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
20018 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
20019 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
20020 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
20021
20022 /* "neighbor prefix-list" commands. */
20023 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
20024 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
20025 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
20026 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
20027 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
20028 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
20029 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
20030 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
20031 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
20032 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
20033 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
20034 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
20035 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
20036 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
20037 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
20038 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
20039 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
20040 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
20041 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
20042 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
20043 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
20044 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
20045
20046 /* "neighbor filter-list" commands. */
20047 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
20048 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
20049 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
20050 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
20051 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
20052 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
20053 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
20054 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
20055 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
20056 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
20057 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
20058 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
20059 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
20060 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
20061 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
20062 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
20063 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
20064 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
20065 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
20066 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
20067 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
20068 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
20069
20070 /* "neighbor route-map" commands. */
20071 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
20072 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
20073 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
20074 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
20075 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
20076 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
20077 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
20078 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
20079 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
20080 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
20081 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
20082 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
20083 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
20084 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
20085 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
20086 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
20087 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
20088 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
20089 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
20090 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
20091 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
20092 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
20093 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
20094 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
20095
20096 /* "neighbor unsuppress-map" commands. */
20097 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
20098 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
20099 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
20100 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
20101 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
20102 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
20103 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
20104 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
20105 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
20106 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
20107 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
20108 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
20109 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
20110 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
20111 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
20112 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
20113 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
20114 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
20115
20116 /* "neighbor advertise-map" commands. */
20117 install_element(BGP_NODE, &bgp_condadv_period_cmd);
20118 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
20119 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
20120 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
20121 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
20122 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
20123 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
20124 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
20125 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
20126 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
20127
20128 /* neighbor maximum-prefix-out commands. */
20129 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
20130 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
20131 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
20132 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20133 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
20134 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20135 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
20136 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20137 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
20138 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20139 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
20140 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20141 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
20142 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20143 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
20144 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20145 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
20146 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20147
20148 /* "neighbor maximum-prefix" commands. */
20149 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
20150 install_element(BGP_NODE,
20151 &neighbor_maximum_prefix_threshold_hidden_cmd);
20152 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
20153 install_element(BGP_NODE,
20154 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
20155 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
20156 install_element(BGP_NODE,
20157 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
20158 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
20159 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
20160 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20161 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20162 install_element(BGP_IPV4_NODE,
20163 &neighbor_maximum_prefix_threshold_warning_cmd);
20164 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20165 install_element(BGP_IPV4_NODE,
20166 &neighbor_maximum_prefix_threshold_restart_cmd);
20167 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
20168 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
20169 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20170 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
20171 install_element(BGP_IPV4M_NODE,
20172 &neighbor_maximum_prefix_threshold_warning_cmd);
20173 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
20174 install_element(BGP_IPV4M_NODE,
20175 &neighbor_maximum_prefix_threshold_restart_cmd);
20176 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
20177 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
20178 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20179 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
20180 install_element(BGP_IPV4L_NODE,
20181 &neighbor_maximum_prefix_threshold_warning_cmd);
20182 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
20183 install_element(BGP_IPV4L_NODE,
20184 &neighbor_maximum_prefix_threshold_restart_cmd);
20185 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
20186 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
20187 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20188 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20189 install_element(BGP_IPV6_NODE,
20190 &neighbor_maximum_prefix_threshold_warning_cmd);
20191 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20192 install_element(BGP_IPV6_NODE,
20193 &neighbor_maximum_prefix_threshold_restart_cmd);
20194 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
20195 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
20196 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20197 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
20198 install_element(BGP_IPV6M_NODE,
20199 &neighbor_maximum_prefix_threshold_warning_cmd);
20200 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
20201 install_element(BGP_IPV6M_NODE,
20202 &neighbor_maximum_prefix_threshold_restart_cmd);
20203 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
20204 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
20205 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20206 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
20207 install_element(BGP_IPV6L_NODE,
20208 &neighbor_maximum_prefix_threshold_warning_cmd);
20209 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
20210 install_element(BGP_IPV6L_NODE,
20211 &neighbor_maximum_prefix_threshold_restart_cmd);
20212 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20213 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20214 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20215 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20216 install_element(BGP_VPNV4_NODE,
20217 &neighbor_maximum_prefix_threshold_warning_cmd);
20218 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20219 install_element(BGP_VPNV4_NODE,
20220 &neighbor_maximum_prefix_threshold_restart_cmd);
20221 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20222 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20223 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20224 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20225 install_element(BGP_VPNV6_NODE,
20226 &neighbor_maximum_prefix_threshold_warning_cmd);
20227 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20228 install_element(BGP_VPNV6_NODE,
20229 &neighbor_maximum_prefix_threshold_restart_cmd);
20230 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20231
20232 /* "neighbor allowas-in" */
20233 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20234 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20235 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20236 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20237 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20238 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20239 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20240 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20241 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20242 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20243 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20244 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20245 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20246 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20247 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20248 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20249 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20250 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20251 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20252 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20253
20254 /* neighbor accept-own */
20255 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20256 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20257
20258 /* "neighbor soo" */
20259 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20260 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20261 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20262 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20263 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20264 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20265 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20266 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20267 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20268 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20269 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20270 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20271 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20272 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20273 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20274 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20275 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20276 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20277
20278 /* address-family commands. */
20279 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20280 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
20281 #ifdef KEEP_OLD_VPN_COMMANDS
20282 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20283 install_element(BGP_NODE, &address_family_vpnv6_cmd);
20284 #endif /* KEEP_OLD_VPN_COMMANDS */
20285
20286 install_element(BGP_NODE, &address_family_evpn_cmd);
20287
20288 /* "exit-address-family" command. */
20289 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20290 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20291 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20292 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20293 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20294 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20295 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20296 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
20297 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20298 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
20299 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20300
20301 /* BGP retain all route-target */
20302 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20303 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20304
20305 /* "clear ip bgp commands" */
20306 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20307
20308 /* clear ip bgp prefix */
20309 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20310 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20311 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20312
20313 /* "show [ip] bgp summary" commands. */
20314 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20315 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20316 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20317 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20318 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20319 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20320 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20321
20322 /* "show [ip] bgp neighbors" commands. */
20323 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20324
20325 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20326
20327 /* "show [ip] bgp peer-group" commands. */
20328 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20329
20330 /* "show [ip] bgp paths" commands. */
20331 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20332
20333 /* "show [ip] bgp community" commands. */
20334 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20335
20336 /* "show ip bgp large-community" commands. */
20337 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20338 /* "show [ip] bgp attribute-info" commands. */
20339 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20340 /* "show [ip] bgp route-leak" command */
20341 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20342
20343 /* "redistribute" commands. */
20344 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20345 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20346 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20347 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20348 install_element(BGP_NODE,
20349 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20350 install_element(BGP_NODE,
20351 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20352 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20353 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20354 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20355 install_element(BGP_NODE,
20356 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20357 install_element(BGP_NODE,
20358 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20359 install_element(BGP_NODE,
20360 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20361 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20362 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20363 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20364 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20365 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20366 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20367 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20368 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20369 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20370 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20371 install_element(BGP_IPV4_NODE,
20372 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20373 install_element(BGP_IPV4_NODE,
20374 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20375 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20376 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20377 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20378 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20379 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20380 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20381
20382 /* import|export vpn [route-map RMAP_NAME] */
20383 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20384 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20385
20386 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20387 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20388
20389 /* ttl_security commands */
20390 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20391 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20392
20393 /* "bgp tcp-keepalive" commands */
20394 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20395 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20396
20397 /* "show [ip] bgp memory" commands. */
20398 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20399
20400 /* "show bgp martian next-hop" */
20401 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20402
20403 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20404
20405 /* "show [ip] bgp views" commands. */
20406 install_element(VIEW_NODE, &show_bgp_views_cmd);
20407
20408 /* "show [ip] bgp vrfs" commands. */
20409 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20410
20411 /* Community-list. */
20412 community_list_vty();
20413
20414 community_alias_vty();
20415
20416 /* vpn-policy commands */
20417 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20418 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20419 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20420 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20421 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20422 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20423 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20424 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20425 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20426 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20427 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20428 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20429
20430 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20431 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20432
20433 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20434 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20435 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20436 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20437 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20438 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20439 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20440 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20441 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20442 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20443
20444 /* tcp-mss command */
20445 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20446 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20447
20448 /* srv6 commands */
20449 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20450 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20451 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20452 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20453 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20454 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20455 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20456 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20457 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20458
20459 bgp_vty_if_init();
20460 }
20461
20462 #include "memory.h"
20463 #include "bgp_regex.h"
20464 #include "bgp_clist.h"
20465 #include "bgp_ecommunity.h"
20466
20467 /* VTY functions. */
20468
20469 /* Direction value to string conversion. */
20470 static const char *community_direct_str(int direct)
20471 {
20472 switch (direct) {
20473 case COMMUNITY_DENY:
20474 return "deny";
20475 case COMMUNITY_PERMIT:
20476 return "permit";
20477 default:
20478 return "unknown";
20479 }
20480 }
20481
20482 /* Display error string. */
20483 static void community_list_perror(struct vty *vty, int ret)
20484 {
20485 switch (ret) {
20486 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20487 vty_out(vty, "%% Can't find community-list\n");
20488 break;
20489 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20490 vty_out(vty, "%% Malformed community-list value\n");
20491 break;
20492 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20493 vty_out(vty,
20494 "%% Community name conflict, previously defined as standard community\n");
20495 break;
20496 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20497 vty_out(vty,
20498 "%% Community name conflict, previously defined as expanded community\n");
20499 break;
20500 }
20501 }
20502
20503 /* "community-list" keyword help string. */
20504 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20505
20506 /*community-list standard */
20507 DEFUN (community_list_standard,
20508 bgp_community_list_standard_cmd,
20509 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20510 BGP_STR
20511 COMMUNITY_LIST_STR
20512 "Community list number (standard)\n"
20513 "Add an standard community-list entry\n"
20514 "Community list name\n"
20515 "Sequence number of an entry\n"
20516 "Sequence number\n"
20517 "Specify community to reject\n"
20518 "Specify community to accept\n"
20519 COMMUNITY_VAL_STR)
20520 {
20521 char *cl_name_or_number = NULL;
20522 char *seq = NULL;
20523 int direct = 0;
20524 int style = COMMUNITY_LIST_STANDARD;
20525 int idx = 0;
20526
20527 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20528 seq = argv[idx]->arg;
20529
20530 idx = 0;
20531 argv_find(argv, argc, "(1-99)", &idx);
20532 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20533 cl_name_or_number = argv[idx]->arg;
20534 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20535 : COMMUNITY_DENY;
20536 argv_find(argv, argc, "AA:NN", &idx);
20537 char *str = argv_concat(argv, argc, idx);
20538
20539 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20540 direct, style);
20541
20542 XFREE(MTYPE_TMP, str);
20543
20544 if (ret < 0) {
20545 /* Display error string. */
20546 community_list_perror(vty, ret);
20547 return CMD_WARNING_CONFIG_FAILED;
20548 }
20549
20550 return CMD_SUCCESS;
20551 }
20552
20553 DEFUN (no_community_list_standard_all,
20554 no_bgp_community_list_standard_all_cmd,
20555 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20556 NO_STR
20557 BGP_STR
20558 COMMUNITY_LIST_STR
20559 "Community list number (standard)\n"
20560 "Add an standard community-list entry\n"
20561 "Community list name\n"
20562 "Sequence number of an entry\n"
20563 "Sequence number\n"
20564 "Specify community to reject\n"
20565 "Specify community to accept\n"
20566 COMMUNITY_VAL_STR)
20567 {
20568 char *cl_name_or_number = NULL;
20569 char *str = NULL;
20570 int direct = 0;
20571 int style = COMMUNITY_LIST_STANDARD;
20572 char *seq = NULL;
20573 int idx = 0;
20574
20575 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20576 seq = argv[idx]->arg;
20577
20578 idx = 0;
20579 argv_find(argv, argc, "permit", &idx);
20580 argv_find(argv, argc, "deny", &idx);
20581
20582 if (idx) {
20583 direct = argv_find(argv, argc, "permit", &idx)
20584 ? COMMUNITY_PERMIT
20585 : COMMUNITY_DENY;
20586
20587 idx = 0;
20588 argv_find(argv, argc, "AA:NN", &idx);
20589 str = argv_concat(argv, argc, idx);
20590 }
20591
20592 idx = 0;
20593 argv_find(argv, argc, "(1-99)", &idx);
20594 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20595 cl_name_or_number = argv[idx]->arg;
20596
20597 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20598 direct, style);
20599
20600 XFREE(MTYPE_TMP, str);
20601
20602 if (ret < 0) {
20603 community_list_perror(vty, ret);
20604 return CMD_WARNING_CONFIG_FAILED;
20605 }
20606
20607 return CMD_SUCCESS;
20608 }
20609
20610 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20611 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20612 NO_STR BGP_STR COMMUNITY_LIST_STR
20613 "Community list number (standard)\n"
20614 "Add an standard community-list entry\n"
20615 "Community list name\n")
20616
20617 /*community-list expanded */
20618 DEFUN (community_list_expanded_all,
20619 bgp_community_list_expanded_all_cmd,
20620 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20621 BGP_STR
20622 COMMUNITY_LIST_STR
20623 "Community list number (expanded)\n"
20624 "Add an expanded community-list entry\n"
20625 "Community list name\n"
20626 "Sequence number of an entry\n"
20627 "Sequence number\n"
20628 "Specify community to reject\n"
20629 "Specify community to accept\n"
20630 COMMUNITY_VAL_STR)
20631 {
20632 char *cl_name_or_number = NULL;
20633 char *seq = NULL;
20634 int direct = 0;
20635 int style = COMMUNITY_LIST_EXPANDED;
20636 int idx = 0;
20637
20638 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20639 seq = argv[idx]->arg;
20640
20641 idx = 0;
20642
20643 argv_find(argv, argc, "(100-500)", &idx);
20644 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20645 cl_name_or_number = argv[idx]->arg;
20646 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20647 : COMMUNITY_DENY;
20648 argv_find(argv, argc, "AA:NN", &idx);
20649 char *str = argv_concat(argv, argc, idx);
20650
20651 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20652 direct, style);
20653
20654 XFREE(MTYPE_TMP, str);
20655
20656 if (ret < 0) {
20657 /* Display error string. */
20658 community_list_perror(vty, ret);
20659 return CMD_WARNING_CONFIG_FAILED;
20660 }
20661
20662 return CMD_SUCCESS;
20663 }
20664
20665 DEFUN (no_community_list_expanded_all,
20666 no_bgp_community_list_expanded_all_cmd,
20667 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20668 NO_STR
20669 BGP_STR
20670 COMMUNITY_LIST_STR
20671 "Community list number (expanded)\n"
20672 "Add an expanded community-list entry\n"
20673 "Community list name\n"
20674 "Sequence number of an entry\n"
20675 "Sequence number\n"
20676 "Specify community to reject\n"
20677 "Specify community to accept\n"
20678 COMMUNITY_VAL_STR)
20679 {
20680 char *cl_name_or_number = NULL;
20681 char *seq = NULL;
20682 char *str = NULL;
20683 int direct = 0;
20684 int style = COMMUNITY_LIST_EXPANDED;
20685 int idx = 0;
20686
20687 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20688 seq = argv[idx]->arg;
20689
20690 idx = 0;
20691 argv_find(argv, argc, "permit", &idx);
20692 argv_find(argv, argc, "deny", &idx);
20693
20694 if (idx) {
20695 direct = argv_find(argv, argc, "permit", &idx)
20696 ? COMMUNITY_PERMIT
20697 : COMMUNITY_DENY;
20698
20699 idx = 0;
20700 argv_find(argv, argc, "AA:NN", &idx);
20701 str = argv_concat(argv, argc, idx);
20702 }
20703
20704 idx = 0;
20705 argv_find(argv, argc, "(100-500)", &idx);
20706 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20707 cl_name_or_number = argv[idx]->arg;
20708
20709 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20710 direct, style);
20711
20712 XFREE(MTYPE_TMP, str);
20713
20714 if (ret < 0) {
20715 community_list_perror(vty, ret);
20716 return CMD_WARNING_CONFIG_FAILED;
20717 }
20718
20719 return CMD_SUCCESS;
20720 }
20721
20722 ALIAS(no_community_list_expanded_all,
20723 no_bgp_community_list_expanded_all_list_cmd,
20724 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20725 NO_STR BGP_STR COMMUNITY_LIST_STR
20726 "Community list number (expanded)\n"
20727 "Add an expanded community-list entry\n"
20728 "Community list name\n")
20729
20730 /* Return configuration string of community-list entry. */
20731 static const char *community_list_config_str(struct community_entry *entry)
20732 {
20733 const char *str;
20734
20735 if (entry->any)
20736 str = "";
20737 else {
20738 if (entry->style == COMMUNITY_LIST_STANDARD)
20739 str = community_str(entry->u.com, false, false);
20740 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20741 str = lcommunity_str(entry->u.lcom, false, false);
20742 else
20743 str = entry->config;
20744 }
20745 return str;
20746 }
20747
20748 static void community_list_show(struct vty *vty, struct community_list *list)
20749 {
20750 struct community_entry *entry;
20751
20752 for (entry = list->head; entry; entry = entry->next) {
20753 if (entry == list->head) {
20754 if (all_digit(list->name))
20755 vty_out(vty, "Community %s list %s\n",
20756 entry->style == COMMUNITY_LIST_STANDARD
20757 ? "standard"
20758 : "(expanded) access",
20759 list->name);
20760 else
20761 vty_out(vty, "Named Community %s list %s\n",
20762 entry->style == COMMUNITY_LIST_STANDARD
20763 ? "standard"
20764 : "expanded",
20765 list->name);
20766 }
20767 if (entry->any)
20768 vty_out(vty, " %s\n",
20769 community_direct_str(entry->direct));
20770 else
20771 vty_out(vty, " %s %s\n",
20772 community_direct_str(entry->direct),
20773 community_list_config_str(entry));
20774 }
20775 }
20776
20777 DEFUN (show_community_list,
20778 show_bgp_community_list_cmd,
20779 "show bgp community-list",
20780 SHOW_STR
20781 BGP_STR
20782 "List community-list\n")
20783 {
20784 struct community_list *list;
20785 struct community_list_master *cm;
20786
20787 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20788 if (!cm)
20789 return CMD_SUCCESS;
20790
20791 for (list = cm->num.head; list; list = list->next)
20792 community_list_show(vty, list);
20793
20794 for (list = cm->str.head; list; list = list->next)
20795 community_list_show(vty, list);
20796
20797 return CMD_SUCCESS;
20798 }
20799
20800 DEFUN (show_community_list_arg,
20801 show_bgp_community_list_arg_cmd,
20802 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20803 SHOW_STR
20804 BGP_STR
20805 "List community-list\n"
20806 "Community-list number\n"
20807 "Community-list name\n"
20808 "Detailed information on community-list\n")
20809 {
20810 int idx_comm_list = 3;
20811 struct community_list *list;
20812
20813 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20814 COMMUNITY_LIST_MASTER);
20815 if (!list) {
20816 vty_out(vty, "%% Can't find community-list\n");
20817 return CMD_WARNING;
20818 }
20819
20820 community_list_show(vty, list);
20821
20822 return CMD_SUCCESS;
20823 }
20824
20825 /*
20826 * Large Community code.
20827 */
20828 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20829 struct cmd_token **argv, int style,
20830 int reject_all_digit_name)
20831 {
20832 int ret;
20833 int direct;
20834 char *str;
20835 int idx = 0;
20836 char *cl_name;
20837 char *seq = NULL;
20838
20839 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20840 seq = argv[idx]->arg;
20841
20842 idx = 0;
20843 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20844 : COMMUNITY_DENY;
20845
20846 /* All digit name check. */
20847 idx = 0;
20848 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20849 argv_find(argv, argc, "(1-99)", &idx);
20850 argv_find(argv, argc, "(100-500)", &idx);
20851 cl_name = argv[idx]->arg;
20852 if (reject_all_digit_name && all_digit(cl_name)) {
20853 vty_out(vty, "%% Community name cannot have all digits\n");
20854 return CMD_WARNING_CONFIG_FAILED;
20855 }
20856
20857 idx = 0;
20858 argv_find(argv, argc, "AA:BB:CC", &idx);
20859 argv_find(argv, argc, "LINE", &idx);
20860 /* Concat community string argument. */
20861 if (idx)
20862 str = argv_concat(argv, argc, idx);
20863 else
20864 str = NULL;
20865
20866 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20867
20868 /* Free temporary community list string allocated by
20869 argv_concat(). */
20870 XFREE(MTYPE_TMP, str);
20871
20872 if (ret < 0) {
20873 community_list_perror(vty, ret);
20874 return CMD_WARNING_CONFIG_FAILED;
20875 }
20876 return CMD_SUCCESS;
20877 }
20878
20879 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20880 struct cmd_token **argv, int style)
20881 {
20882 int ret;
20883 int direct = 0;
20884 char *str = NULL;
20885 int idx = 0;
20886 char *seq = NULL;
20887
20888 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20889 seq = argv[idx]->arg;
20890
20891 idx = 0;
20892 argv_find(argv, argc, "permit", &idx);
20893 argv_find(argv, argc, "deny", &idx);
20894
20895 if (idx) {
20896 /* Check the list direct. */
20897 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20898 direct = COMMUNITY_PERMIT;
20899 else
20900 direct = COMMUNITY_DENY;
20901
20902 idx = 0;
20903 argv_find(argv, argc, "LINE", &idx);
20904 argv_find(argv, argc, "AA:AA:NN", &idx);
20905 /* Concat community string argument. */
20906 str = argv_concat(argv, argc, idx);
20907 }
20908
20909 idx = 0;
20910 argv_find(argv, argc, "(1-99)", &idx);
20911 argv_find(argv, argc, "(100-500)", &idx);
20912 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20913
20914 /* Unset community list. */
20915 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20916 style);
20917
20918 /* Free temporary community list string allocated by
20919 argv_concat(). */
20920 XFREE(MTYPE_TMP, str);
20921
20922 if (ret < 0) {
20923 community_list_perror(vty, ret);
20924 return CMD_WARNING_CONFIG_FAILED;
20925 }
20926
20927 return CMD_SUCCESS;
20928 }
20929
20930 /* "large-community-list" keyword help string. */
20931 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20932 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20933
20934 DEFUN (lcommunity_list_standard,
20935 bgp_lcommunity_list_standard_cmd,
20936 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20937 BGP_STR
20938 LCOMMUNITY_LIST_STR
20939 "Large Community list number (standard)\n"
20940 "Sequence number of an entry\n"
20941 "Sequence number\n"
20942 "Specify large community to reject\n"
20943 "Specify large community to accept\n"
20944 LCOMMUNITY_VAL_STR)
20945 {
20946 return lcommunity_list_set_vty(vty, argc, argv,
20947 LARGE_COMMUNITY_LIST_STANDARD, 0);
20948 }
20949
20950 DEFUN (lcommunity_list_expanded,
20951 bgp_lcommunity_list_expanded_cmd,
20952 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20953 BGP_STR
20954 LCOMMUNITY_LIST_STR
20955 "Large Community list number (expanded)\n"
20956 "Sequence number of an entry\n"
20957 "Sequence number\n"
20958 "Specify large community to reject\n"
20959 "Specify large community to accept\n"
20960 "An ordered list as a regular-expression\n")
20961 {
20962 return lcommunity_list_set_vty(vty, argc, argv,
20963 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20964 }
20965
20966 DEFUN (lcommunity_list_name_standard,
20967 bgp_lcommunity_list_name_standard_cmd,
20968 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20969 BGP_STR
20970 LCOMMUNITY_LIST_STR
20971 "Specify standard large-community-list\n"
20972 "Large Community list name\n"
20973 "Sequence number of an entry\n"
20974 "Sequence number\n"
20975 "Specify large community to reject\n"
20976 "Specify large community to accept\n"
20977 LCOMMUNITY_VAL_STR)
20978 {
20979 return lcommunity_list_set_vty(vty, argc, argv,
20980 LARGE_COMMUNITY_LIST_STANDARD, 1);
20981 }
20982
20983 DEFUN (lcommunity_list_name_expanded,
20984 bgp_lcommunity_list_name_expanded_cmd,
20985 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20986 BGP_STR
20987 LCOMMUNITY_LIST_STR
20988 "Specify expanded large-community-list\n"
20989 "Large Community list name\n"
20990 "Sequence number of an entry\n"
20991 "Sequence number\n"
20992 "Specify large community to reject\n"
20993 "Specify large community to accept\n"
20994 "An ordered list as a regular-expression\n")
20995 {
20996 return lcommunity_list_set_vty(vty, argc, argv,
20997 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20998 }
20999
21000 DEFUN (no_lcommunity_list_all,
21001 no_bgp_lcommunity_list_all_cmd,
21002 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
21003 NO_STR
21004 BGP_STR
21005 LCOMMUNITY_LIST_STR
21006 "Large Community list number (standard)\n"
21007 "Large Community list number (expanded)\n"
21008 "Large Community list name\n")
21009 {
21010 return lcommunity_list_unset_vty(vty, argc, argv,
21011 LARGE_COMMUNITY_LIST_STANDARD);
21012 }
21013
21014 DEFUN (no_lcommunity_list_name_standard_all,
21015 no_bgp_lcommunity_list_name_standard_all_cmd,
21016 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
21017 NO_STR
21018 BGP_STR
21019 LCOMMUNITY_LIST_STR
21020 "Specify standard large-community-list\n"
21021 "Large Community list name\n")
21022 {
21023 return lcommunity_list_unset_vty(vty, argc, argv,
21024 LARGE_COMMUNITY_LIST_STANDARD);
21025 }
21026
21027 DEFUN (no_lcommunity_list_name_expanded_all,
21028 no_bgp_lcommunity_list_name_expanded_all_cmd,
21029 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
21030 NO_STR
21031 BGP_STR
21032 LCOMMUNITY_LIST_STR
21033 "Specify expanded large-community-list\n"
21034 "Large Community list name\n")
21035 {
21036 return lcommunity_list_unset_vty(vty, argc, argv,
21037 LARGE_COMMUNITY_LIST_EXPANDED);
21038 }
21039
21040 DEFUN (no_lcommunity_list_standard,
21041 no_bgp_lcommunity_list_standard_cmd,
21042 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
21043 NO_STR
21044 BGP_STR
21045 LCOMMUNITY_LIST_STR
21046 "Large Community list number (standard)\n"
21047 "Sequence number of an entry\n"
21048 "Sequence number\n"
21049 "Specify large community to reject\n"
21050 "Specify large community to accept\n"
21051 LCOMMUNITY_VAL_STR)
21052 {
21053 return lcommunity_list_unset_vty(vty, argc, argv,
21054 LARGE_COMMUNITY_LIST_STANDARD);
21055 }
21056
21057 DEFUN (no_lcommunity_list_expanded,
21058 no_bgp_lcommunity_list_expanded_cmd,
21059 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
21060 NO_STR
21061 BGP_STR
21062 LCOMMUNITY_LIST_STR
21063 "Large Community list number (expanded)\n"
21064 "Sequence number of an entry\n"
21065 "Sequence number\n"
21066 "Specify large community to reject\n"
21067 "Specify large community to accept\n"
21068 "An ordered list as a regular-expression\n")
21069 {
21070 return lcommunity_list_unset_vty(vty, argc, argv,
21071 LARGE_COMMUNITY_LIST_EXPANDED);
21072 }
21073
21074 DEFUN (no_lcommunity_list_name_standard,
21075 no_bgp_lcommunity_list_name_standard_cmd,
21076 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
21077 NO_STR
21078 BGP_STR
21079 LCOMMUNITY_LIST_STR
21080 "Specify standard large-community-list\n"
21081 "Large Community list name\n"
21082 "Sequence number of an entry\n"
21083 "Sequence number\n"
21084 "Specify large community to reject\n"
21085 "Specify large community to accept\n"
21086 LCOMMUNITY_VAL_STR)
21087 {
21088 return lcommunity_list_unset_vty(vty, argc, argv,
21089 LARGE_COMMUNITY_LIST_STANDARD);
21090 }
21091
21092 DEFUN (no_lcommunity_list_name_expanded,
21093 no_bgp_lcommunity_list_name_expanded_cmd,
21094 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
21095 NO_STR
21096 BGP_STR
21097 LCOMMUNITY_LIST_STR
21098 "Specify expanded large-community-list\n"
21099 "Large community list name\n"
21100 "Sequence number of an entry\n"
21101 "Sequence number\n"
21102 "Specify large community to reject\n"
21103 "Specify large community to accept\n"
21104 "An ordered list as a regular-expression\n")
21105 {
21106 return lcommunity_list_unset_vty(vty, argc, argv,
21107 LARGE_COMMUNITY_LIST_EXPANDED);
21108 }
21109
21110 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
21111 {
21112 struct community_entry *entry;
21113
21114 for (entry = list->head; entry; entry = entry->next) {
21115 if (entry == list->head) {
21116 if (all_digit(list->name))
21117 vty_out(vty, "Large community %s list %s\n",
21118 entry->style ==
21119 LARGE_COMMUNITY_LIST_STANDARD
21120 ? "standard"
21121 : "(expanded) access",
21122 list->name);
21123 else
21124 vty_out(vty,
21125 "Named large community %s list %s\n",
21126 entry->style ==
21127 LARGE_COMMUNITY_LIST_STANDARD
21128 ? "standard"
21129 : "expanded",
21130 list->name);
21131 }
21132 if (entry->any)
21133 vty_out(vty, " %s\n",
21134 community_direct_str(entry->direct));
21135 else
21136 vty_out(vty, " %s %s\n",
21137 community_direct_str(entry->direct),
21138 community_list_config_str(entry));
21139 }
21140 }
21141
21142 DEFUN (show_lcommunity_list,
21143 show_bgp_lcommunity_list_cmd,
21144 "show bgp large-community-list",
21145 SHOW_STR
21146 BGP_STR
21147 "List large-community list\n")
21148 {
21149 struct community_list *list;
21150 struct community_list_master *cm;
21151
21152 cm = community_list_master_lookup(bgp_clist,
21153 LARGE_COMMUNITY_LIST_MASTER);
21154 if (!cm)
21155 return CMD_SUCCESS;
21156
21157 for (list = cm->num.head; list; list = list->next)
21158 lcommunity_list_show(vty, list);
21159
21160 for (list = cm->str.head; list; list = list->next)
21161 lcommunity_list_show(vty, list);
21162
21163 return CMD_SUCCESS;
21164 }
21165
21166 DEFUN (show_lcommunity_list_arg,
21167 show_bgp_lcommunity_list_arg_cmd,
21168 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
21169 SHOW_STR
21170 BGP_STR
21171 "List large-community list\n"
21172 "Large-community-list number\n"
21173 "Large-community-list name\n"
21174 "Detailed information on large-community-list\n")
21175 {
21176 struct community_list *list;
21177
21178 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
21179 LARGE_COMMUNITY_LIST_MASTER);
21180 if (!list) {
21181 vty_out(vty, "%% Can't find large-community-list\n");
21182 return CMD_WARNING;
21183 }
21184
21185 lcommunity_list_show(vty, list);
21186
21187 return CMD_SUCCESS;
21188 }
21189
21190 /* "extcommunity-list" keyword help string. */
21191 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
21192 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
21193
21194 DEFUN (extcommunity_list_standard,
21195 bgp_extcommunity_list_standard_cmd,
21196 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21197 BGP_STR
21198 EXTCOMMUNITY_LIST_STR
21199 "Extended Community list number (standard)\n"
21200 "Specify standard extcommunity-list\n"
21201 "Community list name\n"
21202 "Sequence number of an entry\n"
21203 "Sequence number\n"
21204 "Specify community to reject\n"
21205 "Specify community to accept\n"
21206 EXTCOMMUNITY_VAL_STR)
21207 {
21208 int style = EXTCOMMUNITY_LIST_STANDARD;
21209 int direct = 0;
21210 char *cl_number_or_name = NULL;
21211 char *seq = NULL;
21212
21213 int idx = 0;
21214
21215 argv_find(argv, argc, "(1-99)", &idx);
21216 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21217 cl_number_or_name = argv[idx]->arg;
21218
21219 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21220 seq = argv[idx]->arg;
21221
21222 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21223 : COMMUNITY_DENY;
21224 argv_find(argv, argc, "AA:NN", &idx);
21225 char *str = argv_concat(argv, argc, idx);
21226
21227 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21228 direct, style);
21229
21230 XFREE(MTYPE_TMP, str);
21231
21232 if (ret < 0) {
21233 community_list_perror(vty, ret);
21234 return CMD_WARNING_CONFIG_FAILED;
21235 }
21236
21237 return CMD_SUCCESS;
21238 }
21239
21240 DEFUN (extcommunity_list_name_expanded,
21241 bgp_extcommunity_list_name_expanded_cmd,
21242 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21243 BGP_STR
21244 EXTCOMMUNITY_LIST_STR
21245 "Extended Community list number (expanded)\n"
21246 "Specify expanded extcommunity-list\n"
21247 "Extended Community list name\n"
21248 "Sequence number of an entry\n"
21249 "Sequence number\n"
21250 "Specify community to reject\n"
21251 "Specify community to accept\n"
21252 "An ordered list as a regular-expression\n")
21253 {
21254 int style = EXTCOMMUNITY_LIST_EXPANDED;
21255 int direct = 0;
21256 char *cl_number_or_name = NULL;
21257 char *seq = NULL;
21258 int idx = 0;
21259
21260 argv_find(argv, argc, "(100-500)", &idx);
21261 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21262 cl_number_or_name = argv[idx]->arg;
21263
21264 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21265 seq = argv[idx]->arg;
21266
21267 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21268 : COMMUNITY_DENY;
21269 argv_find(argv, argc, "LINE", &idx);
21270 char *str = argv_concat(argv, argc, idx);
21271
21272 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21273 direct, style);
21274
21275 XFREE(MTYPE_TMP, str);
21276
21277 if (ret < 0) {
21278 community_list_perror(vty, ret);
21279 return CMD_WARNING_CONFIG_FAILED;
21280 }
21281
21282 return CMD_SUCCESS;
21283 }
21284
21285 DEFUN (no_extcommunity_list_standard_all,
21286 no_bgp_extcommunity_list_standard_all_cmd,
21287 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21288 NO_STR
21289 BGP_STR
21290 EXTCOMMUNITY_LIST_STR
21291 "Extended Community list number (standard)\n"
21292 "Specify standard extcommunity-list\n"
21293 "Community list name\n"
21294 "Sequence number of an entry\n"
21295 "Sequence number\n"
21296 "Specify community to reject\n"
21297 "Specify community to accept\n"
21298 EXTCOMMUNITY_VAL_STR)
21299 {
21300 int style = EXTCOMMUNITY_LIST_STANDARD;
21301 int direct = 0;
21302 char *cl_number_or_name = NULL;
21303 char *str = NULL;
21304 char *seq = NULL;
21305 int idx = 0;
21306
21307 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21308 seq = argv[idx]->arg;
21309
21310 idx = 0;
21311 argv_find(argv, argc, "permit", &idx);
21312 argv_find(argv, argc, "deny", &idx);
21313 if (idx) {
21314 direct = argv_find(argv, argc, "permit", &idx)
21315 ? COMMUNITY_PERMIT
21316 : COMMUNITY_DENY;
21317
21318 idx = 0;
21319 argv_find(argv, argc, "AA:NN", &idx);
21320 str = argv_concat(argv, argc, idx);
21321 }
21322
21323 idx = 0;
21324 argv_find(argv, argc, "(1-99)", &idx);
21325 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21326 cl_number_or_name = argv[idx]->arg;
21327
21328 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21329 seq, direct, style);
21330
21331 XFREE(MTYPE_TMP, str);
21332
21333 if (ret < 0) {
21334 community_list_perror(vty, ret);
21335 return CMD_WARNING_CONFIG_FAILED;
21336 }
21337
21338 return CMD_SUCCESS;
21339 }
21340
21341 ALIAS(no_extcommunity_list_standard_all,
21342 no_bgp_extcommunity_list_standard_all_list_cmd,
21343 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21344 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21345 "Extended Community list number (standard)\n"
21346 "Specify standard extcommunity-list\n"
21347 "Community list name\n")
21348
21349 DEFUN (no_extcommunity_list_expanded_all,
21350 no_bgp_extcommunity_list_expanded_all_cmd,
21351 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21352 NO_STR
21353 BGP_STR
21354 EXTCOMMUNITY_LIST_STR
21355 "Extended Community list number (expanded)\n"
21356 "Specify expanded extcommunity-list\n"
21357 "Extended Community list name\n"
21358 "Sequence number of an entry\n"
21359 "Sequence number\n"
21360 "Specify community to reject\n"
21361 "Specify community to accept\n"
21362 "An ordered list as a regular-expression\n")
21363 {
21364 int style = EXTCOMMUNITY_LIST_EXPANDED;
21365 int direct = 0;
21366 char *cl_number_or_name = NULL;
21367 char *str = NULL;
21368 char *seq = NULL;
21369 int idx = 0;
21370
21371 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21372 seq = argv[idx]->arg;
21373
21374 idx = 0;
21375 argv_find(argv, argc, "permit", &idx);
21376 argv_find(argv, argc, "deny", &idx);
21377
21378 if (idx) {
21379 direct = argv_find(argv, argc, "permit", &idx)
21380 ? COMMUNITY_PERMIT
21381 : COMMUNITY_DENY;
21382
21383 idx = 0;
21384 argv_find(argv, argc, "LINE", &idx);
21385 str = argv_concat(argv, argc, idx);
21386 }
21387
21388 idx = 0;
21389 argv_find(argv, argc, "(100-500)", &idx);
21390 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21391 cl_number_or_name = argv[idx]->arg;
21392
21393 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21394 seq, direct, style);
21395
21396 XFREE(MTYPE_TMP, str);
21397
21398 if (ret < 0) {
21399 community_list_perror(vty, ret);
21400 return CMD_WARNING_CONFIG_FAILED;
21401 }
21402
21403 return CMD_SUCCESS;
21404 }
21405
21406 ALIAS(no_extcommunity_list_expanded_all,
21407 no_bgp_extcommunity_list_expanded_all_list_cmd,
21408 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21409 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21410 "Extended Community list number (expanded)\n"
21411 "Specify expanded extcommunity-list\n"
21412 "Extended Community list name\n")
21413
21414 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21415 {
21416 struct community_entry *entry;
21417
21418 for (entry = list->head; entry; entry = entry->next) {
21419 if (entry == list->head) {
21420 if (all_digit(list->name))
21421 vty_out(vty, "Extended community %s list %s\n",
21422 entry->style == EXTCOMMUNITY_LIST_STANDARD
21423 ? "standard"
21424 : "(expanded) access",
21425 list->name);
21426 else
21427 vty_out(vty,
21428 "Named extended community %s list %s\n",
21429 entry->style == EXTCOMMUNITY_LIST_STANDARD
21430 ? "standard"
21431 : "expanded",
21432 list->name);
21433 }
21434 if (entry->any)
21435 vty_out(vty, " %s\n",
21436 community_direct_str(entry->direct));
21437 else
21438 vty_out(vty, " %s %s\n",
21439 community_direct_str(entry->direct),
21440 community_list_config_str(entry));
21441 }
21442 }
21443
21444 DEFUN (show_extcommunity_list,
21445 show_bgp_extcommunity_list_cmd,
21446 "show bgp extcommunity-list",
21447 SHOW_STR
21448 BGP_STR
21449 "List extended-community list\n")
21450 {
21451 struct community_list *list;
21452 struct community_list_master *cm;
21453
21454 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21455 if (!cm)
21456 return CMD_SUCCESS;
21457
21458 for (list = cm->num.head; list; list = list->next)
21459 extcommunity_list_show(vty, list);
21460
21461 for (list = cm->str.head; list; list = list->next)
21462 extcommunity_list_show(vty, list);
21463
21464 return CMD_SUCCESS;
21465 }
21466
21467 DEFUN (show_extcommunity_list_arg,
21468 show_bgp_extcommunity_list_arg_cmd,
21469 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21470 SHOW_STR
21471 BGP_STR
21472 "List extended-community list\n"
21473 "Extcommunity-list number\n"
21474 "Extcommunity-list name\n"
21475 "Detailed information on extcommunity-list\n")
21476 {
21477 int idx_comm_list = 3;
21478 struct community_list *list;
21479
21480 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21481 EXTCOMMUNITY_LIST_MASTER);
21482 if (!list) {
21483 vty_out(vty, "%% Can't find extcommunity-list\n");
21484 return CMD_WARNING;
21485 }
21486
21487 extcommunity_list_show(vty, list);
21488
21489 return CMD_SUCCESS;
21490 }
21491
21492 /* Display community-list and extcommunity-list configuration. */
21493 static int community_list_config_write(struct vty *vty)
21494 {
21495 struct community_list *list;
21496 struct community_entry *entry;
21497 struct community_list_master *cm;
21498 int write = 0;
21499
21500 /* Community-list. */
21501 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21502
21503 for (list = cm->num.head; list; list = list->next)
21504 for (entry = list->head; entry; entry = entry->next) {
21505 vty_out(vty,
21506 "bgp community-list %s seq %" PRId64 " %s %s\n",
21507 list->name, entry->seq,
21508 community_direct_str(entry->direct),
21509 community_list_config_str(entry));
21510 write++;
21511 }
21512 for (list = cm->str.head; list; list = list->next)
21513 for (entry = list->head; entry; entry = entry->next) {
21514 vty_out(vty,
21515 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21516 entry->style == COMMUNITY_LIST_STANDARD
21517 ? "standard"
21518 : "expanded",
21519 list->name, entry->seq,
21520 community_direct_str(entry->direct),
21521 community_list_config_str(entry));
21522 write++;
21523 }
21524
21525 /* Extcommunity-list. */
21526 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21527
21528 for (list = cm->num.head; list; list = list->next)
21529 for (entry = list->head; entry; entry = entry->next) {
21530 vty_out(vty,
21531 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21532 list->name, entry->seq,
21533 community_direct_str(entry->direct),
21534 community_list_config_str(entry));
21535 write++;
21536 }
21537 for (list = cm->str.head; list; list = list->next)
21538 for (entry = list->head; entry; entry = entry->next) {
21539 vty_out(vty,
21540 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21541 entry->style == EXTCOMMUNITY_LIST_STANDARD
21542 ? "standard"
21543 : "expanded",
21544 list->name, entry->seq,
21545 community_direct_str(entry->direct),
21546 community_list_config_str(entry));
21547 write++;
21548 }
21549
21550
21551 /* lcommunity-list. */
21552 cm = community_list_master_lookup(bgp_clist,
21553 LARGE_COMMUNITY_LIST_MASTER);
21554
21555 for (list = cm->num.head; list; list = list->next)
21556 for (entry = list->head; entry; entry = entry->next) {
21557 vty_out(vty,
21558 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21559 list->name, entry->seq,
21560 community_direct_str(entry->direct),
21561 community_list_config_str(entry));
21562 write++;
21563 }
21564 for (list = cm->str.head; list; list = list->next)
21565 for (entry = list->head; entry; entry = entry->next) {
21566 vty_out(vty,
21567 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21568
21569 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21570 ? "standard"
21571 : "expanded",
21572 list->name, entry->seq, community_direct_str(entry->direct),
21573 community_list_config_str(entry));
21574 write++;
21575 }
21576
21577 return write;
21578 }
21579
21580 static int community_list_config_write(struct vty *vty);
21581 static struct cmd_node community_list_node = {
21582 .name = "community list",
21583 .node = COMMUNITY_LIST_NODE,
21584 .prompt = "",
21585 .config_write = community_list_config_write,
21586 };
21587
21588 static void community_list_vty(void)
21589 {
21590 install_node(&community_list_node);
21591
21592 /* Community-list. */
21593 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21594 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21595 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21596 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21597 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21598 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21599 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21600 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21601
21602 /* Extcommunity-list. */
21603 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21604 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21605 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21606 install_element(CONFIG_NODE,
21607 &no_bgp_extcommunity_list_standard_all_list_cmd);
21608 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21609 install_element(CONFIG_NODE,
21610 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21611 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21612 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21613
21614 /* Large Community List */
21615 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21616 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21617 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21618 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21619 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21620 install_element(CONFIG_NODE,
21621 &no_bgp_lcommunity_list_name_standard_all_cmd);
21622 install_element(CONFIG_NODE,
21623 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21624 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21625 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21626 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21627 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21628 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21629 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21630
21631 bgp_community_list_command_completion_setup();
21632 }
21633
21634 static struct cmd_node community_alias_node = {
21635 .name = "community alias",
21636 .node = COMMUNITY_ALIAS_NODE,
21637 .prompt = "",
21638 .config_write = bgp_community_alias_write,
21639 };
21640
21641 void community_alias_vty(void)
21642 {
21643 install_node(&community_alias_node);
21644
21645 /* Community-list. */
21646 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21647
21648 bgp_community_alias_command_completion_setup();
21649 }