]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12830 from anlancs/fix/doc-ripd-rst
[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
28 #include "bgpd/bgpd.h"
29 #include "bgpd/bgp_attr_evpn.h"
30 #include "bgpd/bgp_advertise.h"
31 #include "bgpd/bgp_attr.h"
32 #include "bgpd/bgp_aspath.h"
33 #include "bgpd/bgp_community.h"
34 #include "bgpd/bgp_community_alias.h"
35 #include "bgpd/bgp_ecommunity.h"
36 #include "bgpd/bgp_lcommunity.h"
37 #include "bgpd/bgp_damp.h"
38 #include "bgpd/bgp_debug.h"
39 #include "bgpd/bgp_errors.h"
40 #include "bgpd/bgp_fsm.h"
41 #include "bgpd/bgp_nht.h"
42 #include "bgpd/bgp_nexthop.h"
43 #include "bgpd/bgp_network.h"
44 #include "bgpd/bgp_open.h"
45 #include "bgpd/bgp_regex.h"
46 #include "bgpd/bgp_route.h"
47 #include "bgpd/bgp_mplsvpn.h"
48 #include "bgpd/bgp_zebra.h"
49 #include "bgpd/bgp_table.h"
50 #include "bgpd/bgp_vty.h"
51 #include "bgpd/bgp_mpath.h"
52 #include "bgpd/bgp_packet.h"
53 #include "bgpd/bgp_updgrp.h"
54 #include "bgpd/bgp_bfd.h"
55 #include "bgpd/bgp_io.h"
56 #include "bgpd/bgp_evpn.h"
57 #include "bgpd/bgp_evpn_vty.h"
58 #include "bgpd/bgp_evpn_mh.h"
59 #include "bgpd/bgp_addpath.h"
60 #include "bgpd/bgp_mac.h"
61 #include "bgpd/bgp_flowspec.h"
62 #include "bgpd/bgp_conditional_adv.h"
63 #ifdef ENABLE_BGP_VNC
64 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
65 #endif
66
67 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
68 {
69 .val_bool = false,
70 .match_profile = "traditional",
71 .match_version = "< 7.4",
72 },
73 { .val_bool = true },
74 );
75 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
76 { .val_bool = true, .match_profile = "datacenter", },
77 { .val_bool = false },
78 );
79 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
80 { .val_bool = true, .match_profile = "datacenter", },
81 { .val_bool = false },
82 );
83 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
84 { .val_bool = true, .match_profile = "datacenter", },
85 { .val_bool = false },
86 );
87 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
88 { .val_bool = true, .match_profile = "datacenter", },
89 { .val_bool = false },
90 );
91 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
92 { .val_ulong = 10, .match_profile = "datacenter", },
93 { .val_ulong = 120 },
94 );
95 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
96 { .val_ulong = 9, .match_profile = "datacenter", },
97 { .val_ulong = 180 },
98 );
99 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
100 { .val_ulong = 3, .match_profile = "datacenter", },
101 { .val_ulong = 60 },
102 );
103 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
104 { .val_bool = false, .match_profile = "datacenter", },
105 { .val_bool = false, .match_version = "< 7.4", },
106 { .val_bool = true },
107 );
108 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
109 { .val_bool = false, .match_version = "< 7.6", },
110 { .val_bool = true },
111 );
112 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
113 { .val_bool = false, .match_version = "< 8.3", },
114 { .val_bool = true },
115 );
116 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
117 { .val_bool = false, .match_version = "< 8.3", },
118 { .val_bool = true },
119 );
120
121 DEFINE_HOOK(bgp_inst_config_write,
122 (struct bgp *bgp, struct vty *vty),
123 (bgp, vty));
124 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
125 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
126
127 static struct peer_group *listen_range_exists(struct bgp *bgp,
128 struct prefix *range, int exact);
129
130 /* Show BGP peer's information. */
131 enum show_type {
132 show_all,
133 show_peer,
134 show_ipv4_all,
135 show_ipv6_all,
136 show_ipv4_peer,
137 show_ipv6_peer
138 };
139
140 static struct peer_group *listen_range_exists(struct bgp *bgp,
141 struct prefix *range, int exact);
142
143 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
144 struct bgp *bgp);
145
146 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
147 enum show_type type,
148 const char *ip_str,
149 afi_t afi, bool use_json);
150
151 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
152 {
153 switch (afi) {
154 case AFI_IP:
155 switch (safi) {
156 case SAFI_UNICAST:
157 return BGP_IPV4_NODE;
158 case SAFI_MULTICAST:
159 return BGP_IPV4M_NODE;
160 case SAFI_LABELED_UNICAST:
161 return BGP_IPV4L_NODE;
162 case SAFI_MPLS_VPN:
163 return BGP_VPNV4_NODE;
164 case SAFI_FLOWSPEC:
165 return BGP_FLOWSPECV4_NODE;
166 case SAFI_UNSPEC:
167 case SAFI_ENCAP:
168 case SAFI_EVPN:
169 case SAFI_MAX:
170 /* not expected */
171 return BGP_IPV4_NODE;
172 }
173 break;
174 case AFI_IP6:
175 switch (safi) {
176 case SAFI_UNICAST:
177 return BGP_IPV6_NODE;
178 case SAFI_MULTICAST:
179 return BGP_IPV6M_NODE;
180 case SAFI_LABELED_UNICAST:
181 return BGP_IPV6L_NODE;
182 case SAFI_MPLS_VPN:
183 return BGP_VPNV6_NODE;
184 case SAFI_FLOWSPEC:
185 return BGP_FLOWSPECV6_NODE;
186 case SAFI_UNSPEC:
187 case SAFI_ENCAP:
188 case SAFI_EVPN:
189 case SAFI_MAX:
190 /* not expected and the return value seems wrong */
191 return BGP_IPV4_NODE;
192 }
193 break;
194 case AFI_L2VPN:
195 return BGP_EVPN_NODE;
196 case AFI_UNSPEC:
197 case AFI_MAX:
198 // We should never be here but to clarify the switch statement..
199 return BGP_IPV4_NODE;
200 }
201
202 // Impossible to happen
203 return BGP_IPV4_NODE;
204 }
205
206 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
207 {
208 if (afi == AFI_IP) {
209 if (safi == SAFI_UNICAST)
210 return "IPv4 Unicast";
211 if (safi == SAFI_MULTICAST)
212 return "IPv4 Multicast";
213 if (safi == SAFI_LABELED_UNICAST)
214 return "IPv4 Labeled Unicast";
215 if (safi == SAFI_MPLS_VPN)
216 return "IPv4 VPN";
217 if (safi == SAFI_ENCAP)
218 return "IPv4 Encap";
219 if (safi == SAFI_FLOWSPEC)
220 return "IPv4 Flowspec";
221 } else if (afi == AFI_IP6) {
222 if (safi == SAFI_UNICAST)
223 return "IPv6 Unicast";
224 if (safi == SAFI_MULTICAST)
225 return "IPv6 Multicast";
226 if (safi == SAFI_LABELED_UNICAST)
227 return "IPv6 Labeled Unicast";
228 if (safi == SAFI_MPLS_VPN)
229 return "IPv6 VPN";
230 if (safi == SAFI_ENCAP)
231 return "IPv6 Encap";
232 if (safi == SAFI_FLOWSPEC)
233 return "IPv6 Flowspec";
234 } else if (afi == AFI_L2VPN) {
235 if (safi == SAFI_EVPN)
236 return "L2VPN EVPN";
237 }
238
239 return "Unknown";
240 }
241
242 /*
243 * Please note that we have intentionally camelCased
244 * the return strings here. So if you want
245 * to use this function, please ensure you
246 * are doing this within json output
247 */
248 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
249 {
250 if (afi == AFI_IP) {
251 if (safi == SAFI_UNICAST)
252 return "ipv4Unicast";
253 if (safi == SAFI_MULTICAST)
254 return "ipv4Multicast";
255 if (safi == SAFI_LABELED_UNICAST)
256 return "ipv4LabeledUnicast";
257 if (safi == SAFI_MPLS_VPN)
258 return "ipv4Vpn";
259 if (safi == SAFI_ENCAP)
260 return "ipv4Encap";
261 if (safi == SAFI_FLOWSPEC)
262 return "ipv4Flowspec";
263 } else if (afi == AFI_IP6) {
264 if (safi == SAFI_UNICAST)
265 return "ipv6Unicast";
266 if (safi == SAFI_MULTICAST)
267 return "ipv6Multicast";
268 if (safi == SAFI_LABELED_UNICAST)
269 return "ipv6LabeledUnicast";
270 if (safi == SAFI_MPLS_VPN)
271 return "ipv6Vpn";
272 if (safi == SAFI_ENCAP)
273 return "ipv6Encap";
274 if (safi == SAFI_FLOWSPEC)
275 return "ipv6Flowspec";
276 } else if (afi == AFI_L2VPN) {
277 if (safi == SAFI_EVPN)
278 return "l2VpnEvpn";
279 }
280
281 return "Unknown";
282 }
283
284 /* unset srv6 locator */
285 static int bgp_srv6_locator_unset(struct bgp *bgp)
286 {
287 int ret;
288 struct listnode *node, *nnode;
289 struct srv6_locator_chunk *chunk;
290 struct bgp_srv6_function *func;
291 struct bgp *bgp_vrf;
292
293 /* release chunk notification via ZAPI */
294 ret = bgp_zebra_srv6_manager_release_locator_chunk(
295 bgp->srv6_locator_name);
296 if (ret < 0)
297 return -1;
298
299 /* refresh chunks */
300 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
301 listnode_delete(bgp->srv6_locator_chunks, chunk);
302 srv6_locator_chunk_free(&chunk);
303 }
304
305 /* refresh functions */
306 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
307 listnode_delete(bgp->srv6_functions, func);
308 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
309 }
310
311 /* refresh tovpn_sid */
312 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
313 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
314 continue;
315
316 /* refresh vpnv4 tovpn_sid */
317 XFREE(MTYPE_BGP_SRV6_SID,
318 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
319
320 /* refresh vpnv6 tovpn_sid */
321 XFREE(MTYPE_BGP_SRV6_SID,
322 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
323
324 /* refresh per-vrf tovpn_sid */
325 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
326 }
327
328 /* update vpn bgp processes */
329 vpn_leak_postchange_all();
330
331 /* refresh tovpn_sid_locator */
332 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
333 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
334 continue;
335
336 /* refresh vpnv4 tovpn_sid_locator */
337 srv6_locator_chunk_free(
338 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
339
340 /* refresh vpnv6 tovpn_sid_locator */
341 srv6_locator_chunk_free(
342 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
343
344 /* refresh per-vrf tovpn_sid_locator */
345 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
346 }
347
348 /* clear locator name */
349 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
350
351 return 0;
352 }
353
354 /* Utility function to get address family from current node. */
355 afi_t bgp_node_afi(struct vty *vty)
356 {
357 afi_t afi;
358 switch (vty->node) {
359 case BGP_IPV6_NODE:
360 case BGP_IPV6M_NODE:
361 case BGP_IPV6L_NODE:
362 case BGP_VPNV6_NODE:
363 case BGP_FLOWSPECV6_NODE:
364 afi = AFI_IP6;
365 break;
366 case BGP_EVPN_NODE:
367 afi = AFI_L2VPN;
368 break;
369 default:
370 afi = AFI_IP;
371 break;
372 }
373 return afi;
374 }
375
376 /* Utility function to get subsequent address family from current
377 node. */
378 safi_t bgp_node_safi(struct vty *vty)
379 {
380 safi_t safi;
381 switch (vty->node) {
382 case BGP_VPNV4_NODE:
383 case BGP_VPNV6_NODE:
384 safi = SAFI_MPLS_VPN;
385 break;
386 case BGP_IPV4M_NODE:
387 case BGP_IPV6M_NODE:
388 safi = SAFI_MULTICAST;
389 break;
390 case BGP_EVPN_NODE:
391 safi = SAFI_EVPN;
392 break;
393 case BGP_IPV4L_NODE:
394 case BGP_IPV6L_NODE:
395 safi = SAFI_LABELED_UNICAST;
396 break;
397 case BGP_FLOWSPECV4_NODE:
398 case BGP_FLOWSPECV6_NODE:
399 safi = SAFI_FLOWSPEC;
400 break;
401 default:
402 safi = SAFI_UNICAST;
403 break;
404 }
405 return safi;
406 }
407
408 /**
409 * Converts an AFI in string form to afi_t
410 *
411 * @param afi string, one of
412 * - "ipv4"
413 * - "ipv6"
414 * - "l2vpn"
415 * @return the corresponding afi_t
416 */
417 afi_t bgp_vty_afi_from_str(const char *afi_str)
418 {
419 afi_t afi = AFI_MAX; /* unknown */
420 if (strmatch(afi_str, "ipv4"))
421 afi = AFI_IP;
422 else if (strmatch(afi_str, "ipv6"))
423 afi = AFI_IP6;
424 else if (strmatch(afi_str, "l2vpn"))
425 afi = AFI_L2VPN;
426 return afi;
427 }
428
429 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
430 afi_t *afi)
431 {
432 int ret = 0;
433 if (argv_find(argv, argc, "ipv4", index)) {
434 ret = 1;
435 if (afi)
436 *afi = AFI_IP;
437 } else if (argv_find(argv, argc, "ipv6", index)) {
438 ret = 1;
439 if (afi)
440 *afi = AFI_IP6;
441 } else if (argv_find(argv, argc, "l2vpn", index)) {
442 ret = 1;
443 if (afi)
444 *afi = AFI_L2VPN;
445 }
446 return ret;
447 }
448
449 /* supports <unicast|multicast|vpn|labeled-unicast> */
450 safi_t bgp_vty_safi_from_str(const char *safi_str)
451 {
452 safi_t safi = SAFI_MAX; /* unknown */
453 if (strmatch(safi_str, "multicast"))
454 safi = SAFI_MULTICAST;
455 else if (strmatch(safi_str, "unicast"))
456 safi = SAFI_UNICAST;
457 else if (strmatch(safi_str, "vpn"))
458 safi = SAFI_MPLS_VPN;
459 else if (strmatch(safi_str, "evpn"))
460 safi = SAFI_EVPN;
461 else if (strmatch(safi_str, "labeled-unicast"))
462 safi = SAFI_LABELED_UNICAST;
463 else if (strmatch(safi_str, "flowspec"))
464 safi = SAFI_FLOWSPEC;
465 return safi;
466 }
467
468 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
469 safi_t *safi)
470 {
471 int ret = 0;
472 if (argv_find(argv, argc, "unicast", index)) {
473 ret = 1;
474 if (safi)
475 *safi = SAFI_UNICAST;
476 } else if (argv_find(argv, argc, "multicast", index)) {
477 ret = 1;
478 if (safi)
479 *safi = SAFI_MULTICAST;
480 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
481 ret = 1;
482 if (safi)
483 *safi = SAFI_LABELED_UNICAST;
484 } else if (argv_find(argv, argc, "vpn", index)) {
485 ret = 1;
486 if (safi)
487 *safi = SAFI_MPLS_VPN;
488 } else if (argv_find(argv, argc, "evpn", index)) {
489 ret = 1;
490 if (safi)
491 *safi = SAFI_EVPN;
492 } else if (argv_find(argv, argc, "flowspec", index)) {
493 ret = 1;
494 if (safi)
495 *safi = SAFI_FLOWSPEC;
496 }
497 return ret;
498 }
499
500 /*
501 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
502 *
503 * afi
504 * address-family identifier
505 *
506 * safi
507 * subsequent address-family identifier
508 *
509 * Returns:
510 * default_af string corresponding to the supplied afi/safi pair.
511 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
512 * return -1.
513 */
514 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
515 {
516 switch (afi) {
517 case AFI_IP:
518 switch (safi) {
519 case SAFI_UNICAST:
520 return "ipv4-unicast";
521 case SAFI_MULTICAST:
522 return "ipv4-multicast";
523 case SAFI_MPLS_VPN:
524 return "ipv4-vpn";
525 case SAFI_ENCAP:
526 return "ipv4-encap";
527 case SAFI_LABELED_UNICAST:
528 return "ipv4-labeled-unicast";
529 case SAFI_FLOWSPEC:
530 return "ipv4-flowspec";
531 case SAFI_UNSPEC:
532 case SAFI_EVPN:
533 case SAFI_MAX:
534 return "unknown-afi/safi";
535 }
536 break;
537 case AFI_IP6:
538 switch (safi) {
539 case SAFI_UNICAST:
540 return "ipv6-unicast";
541 case SAFI_MULTICAST:
542 return "ipv6-multicast";
543 case SAFI_MPLS_VPN:
544 return "ipv6-vpn";
545 case SAFI_ENCAP:
546 return "ipv6-encap";
547 case SAFI_LABELED_UNICAST:
548 return "ipv6-labeled-unicast";
549 case SAFI_FLOWSPEC:
550 return "ipv6-flowspec";
551 case SAFI_UNSPEC:
552 case SAFI_EVPN:
553 case SAFI_MAX:
554 return "unknown-afi/safi";
555 }
556 break;
557 case AFI_L2VPN:
558 switch (safi) {
559 case SAFI_EVPN:
560 return "l2vpn-evpn";
561 case SAFI_UNICAST:
562 case SAFI_MULTICAST:
563 case SAFI_MPLS_VPN:
564 case SAFI_ENCAP:
565 case SAFI_LABELED_UNICAST:
566 case SAFI_FLOWSPEC:
567 case SAFI_UNSPEC:
568 case SAFI_MAX:
569 return "unknown-afi/safi";
570 }
571 break;
572 case AFI_UNSPEC:
573 case AFI_MAX:
574 return "unknown-afi/safi";
575 }
576 /* all AFIs are accounted for above, so this shouldn't happen */
577
578 assert(!"Reached end of function where we did not expect to");
579 }
580
581 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
582 enum bgp_instance_type inst_type)
583 {
584 int ret = bgp_get(bgp, as, name, inst_type);
585
586 if (ret == BGP_CREATED) {
587 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
588 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
589
590 if (DFLT_BGP_IMPORT_CHECK)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
592 if (DFLT_BGP_SHOW_HOSTNAME)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
594 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
596 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
598 if (DFLT_BGP_DETERMINISTIC_MED)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
600 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
602 if (DFLT_BGP_SUPPRESS_DUPLICATES)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
604 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
606 if (DFLT_BGP_HARD_ADMIN_RESET)
607 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
608
609 ret = BGP_SUCCESS;
610 }
611 return ret;
612 }
613
614 /*
615 * bgp_vty_find_and_parse_afi_safi_bgp
616 *
617 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
618 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
619 * to appropriate values for the calling function. This is to allow the
620 * calling function to make decisions appropriate for the show command
621 * that is being parsed.
622 *
623 * The show commands are generally of the form:
624 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
625 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
626 *
627 * Since we use argv_find if the show command in particular doesn't have:
628 * [ip]
629 * [<view|vrf> VIEWVRFNAME]
630 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
631 * The command parsing should still be ok.
632 *
633 * vty -> The vty for the command so we can output some useful data in
634 * the event of a parse error in the vrf.
635 * argv -> The command tokens
636 * argc -> How many command tokens we have
637 * idx -> The current place in the command, generally should be 0 for this
638 * function
639 * afi -> The parsed afi if it was included in the show command, returned here
640 * safi -> The parsed safi if it was included in the show command, returned here
641 * bgp -> Pointer to the bgp data structure we need to fill in.
642 * use_json -> json is configured or not
643 *
644 * The function returns the correct location in the parse tree for the
645 * last token found.
646 *
647 * Returns 0 for failure to parse correctly, else the idx position of where
648 * it found the last token.
649 */
650 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
651 struct cmd_token **argv, int argc,
652 int *idx, afi_t *afi, safi_t *safi,
653 struct bgp **bgp, bool use_json)
654 {
655 char *vrf_name = NULL;
656
657 assert(afi);
658 assert(safi);
659 assert(bgp);
660
661 if (argv_find(argv, argc, "ip", idx))
662 *afi = AFI_IP;
663
664 if (argv_find(argv, argc, "view", idx))
665 vrf_name = argv[*idx + 1]->arg;
666 else if (argv_find(argv, argc, "vrf", idx)) {
667 vrf_name = argv[*idx + 1]->arg;
668 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
669 vrf_name = NULL;
670 }
671 if (vrf_name) {
672 if (strmatch(vrf_name, "all"))
673 *bgp = NULL;
674 else {
675 *bgp = bgp_lookup_by_name(vrf_name);
676 if (!*bgp) {
677 if (use_json) {
678 json_object *json = NULL;
679 json = json_object_new_object();
680 json_object_string_add(
681 json, "warning",
682 "View/Vrf is unknown");
683 vty_json(vty, json);
684 }
685 else
686 vty_out(vty, "View/Vrf %s is unknown\n",
687 vrf_name);
688 *idx = 0;
689 return 0;
690 }
691 }
692 } else {
693 *bgp = bgp_get_default();
694 if (!*bgp) {
695 if (use_json) {
696 json_object *json = NULL;
697 json = json_object_new_object();
698 json_object_string_add(
699 json, "warning",
700 "Default BGP instance not found");
701 vty_json(vty, json);
702 }
703 else
704 vty_out(vty,
705 "Default BGP instance not found\n");
706 *idx = 0;
707 return 0;
708 }
709 }
710
711 if (argv_find_and_parse_afi(argv, argc, idx, afi))
712 argv_find_and_parse_safi(argv, argc, idx, safi);
713
714 *idx += 1;
715 return *idx;
716 }
717
718 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
719 {
720 struct interface *ifp = NULL;
721 struct listnode *node;
722 struct bgp_listener *listener;
723 union sockunion all_su;
724
725 if (su->sa.sa_family == AF_INET) {
726 (void)str2sockunion("0.0.0.0", &all_su);
727 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
728 } else if (su->sa.sa_family == AF_INET6) {
729 (void)str2sockunion("::", &all_su);
730 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
731 su->sin6.sin6_scope_id,
732 bgp->vrf_id);
733 }
734
735 if (ifp) {
736 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
737 if (sockunion_family(su) !=
738 sockunion_family(&listener->su))
739 continue;
740
741 /* If 0.0.0.0/:: is a listener, then treat as self and
742 * reject.
743 */
744 if (!sockunion_cmp(&listener->su, su) ||
745 !sockunion_cmp(&listener->su, &all_su))
746 return true;
747 }
748 }
749
750 return false;
751 }
752
753 /* Utility function for looking up peer from VTY. */
754 /* This is used only for configuration, so disallow if attempted on
755 * a dynamic neighbor.
756 */
757 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
758 {
759 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
760 int ret;
761 union sockunion su;
762 struct peer *peer;
763
764 if (!bgp) {
765 return NULL;
766 }
767
768 ret = str2sockunion(ip_str, &su);
769 if (ret < 0) {
770 peer = peer_lookup_by_conf_if(bgp, ip_str);
771 if (!peer) {
772 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
773 == NULL) {
774 vty_out(vty,
775 "%% Malformed address or name: %s\n",
776 ip_str);
777 return NULL;
778 }
779 }
780 } else {
781 peer = peer_lookup(bgp, &su);
782 if (!peer) {
783 vty_out(vty,
784 "%% Specify remote-as or peer-group commands first\n");
785 return NULL;
786 }
787 if (peer_dynamic_neighbor(peer)) {
788 vty_out(vty,
789 "%% Operation not allowed on a dynamic neighbor\n");
790 return NULL;
791 }
792 }
793 return peer;
794 }
795
796 /* Utility function for looking up peer or peer group. */
797 /* This is used only for configuration, so disallow if attempted on
798 * a dynamic neighbor.
799 */
800 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
801 {
802 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
803 int ret;
804 union sockunion su;
805 struct peer *peer = NULL;
806 struct peer_group *group = NULL;
807
808 if (!bgp) {
809 return NULL;
810 }
811
812 ret = str2sockunion(peer_str, &su);
813 if (ret == 0) {
814 /* IP address, locate peer. */
815 peer = peer_lookup(bgp, &su);
816 } else {
817 /* Not IP, could match either peer configured on interface or a
818 * group. */
819 peer = peer_lookup_by_conf_if(bgp, peer_str);
820 if (!peer)
821 group = peer_group_lookup(bgp, peer_str);
822 }
823
824 if (peer) {
825 if (peer_dynamic_neighbor(peer)) {
826 zlog_warn(
827 "%pBP: Operation not allowed on a dynamic neighbor",
828 peer);
829 vty_out(vty,
830 "%% Operation not allowed on a dynamic neighbor\n");
831 return NULL;
832 }
833
834 return peer;
835 }
836
837 if (group)
838 return group->conf;
839
840 zlog_warn("Specify remote-as or peer-group commands first before: %s",
841 vty->buf);
842 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
843
844 return NULL;
845 }
846
847 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
848 {
849 const char *str = NULL;
850
851 switch (ret) {
852 case BGP_SUCCESS:
853 case BGP_CREATED:
854 case BGP_GR_NO_OPERATION:
855 break;
856 case BGP_ERR_INVALID_VALUE:
857 str = "Invalid value";
858 break;
859 case BGP_ERR_INVALID_FLAG:
860 str = "Invalid flag";
861 break;
862 case BGP_ERR_PEER_GROUP_SHUTDOWN:
863 str = "Peer-group has been shutdown. Activate the peer-group first";
864 break;
865 case BGP_ERR_PEER_FLAG_CONFLICT:
866 str = "Can't set override-capability and strict-capability-match at the same time";
867 break;
868 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
869 str = "Specify remote-as or peer-group remote AS first";
870 break;
871 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
872 str = "Cannot change the peer-group. Deconfigure first";
873 break;
874 case BGP_ERR_PEER_GROUP_MISMATCH:
875 str = "Peer is not a member of this peer-group";
876 break;
877 case BGP_ERR_PEER_FILTER_CONFLICT:
878 str = "Prefix/distribute list can not co-exist";
879 break;
880 case BGP_ERR_NOT_INTERNAL_PEER:
881 str = "Invalid command. Not an internal neighbor";
882 break;
883 case BGP_ERR_REMOVE_PRIVATE_AS:
884 str = "remove-private-AS cannot be configured for IBGP peers";
885 break;
886 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
887 str = "Cannot have local-as same as BGP AS number";
888 break;
889 case BGP_ERR_TCPSIG_FAILED:
890 str = "Error while applying TCP-Sig to session(s)";
891 break;
892 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
893 str = "ebgp-multihop and ttl-security cannot be configured together";
894 break;
895 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
896 str = "ttl-security only allowed for EBGP peers";
897 break;
898 case BGP_ERR_AS_OVERRIDE:
899 str = "as-override cannot be configured for IBGP peers";
900 break;
901 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
902 str = "Invalid limit for number of dynamic neighbors";
903 break;
904 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
905 str = "Dynamic neighbor listen range already exists";
906 break;
907 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
908 str = "Operation not allowed on a dynamic neighbor";
909 break;
910 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
911 str = "Operation not allowed on a directly connected neighbor";
912 break;
913 case BGP_ERR_PEER_SAFI_CONFLICT:
914 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
915 break;
916 case BGP_ERR_GR_INVALID_CMD:
917 str = "The Graceful Restart command used is not valid at this moment.";
918 break;
919 case BGP_ERR_GR_OPERATION_FAILED:
920 str = "The Graceful Restart Operation failed due to an err.";
921 break;
922 case BGP_ERR_PEER_GROUP_MEMBER:
923 str = "Peer-group member cannot override remote-as of peer-group.";
924 break;
925 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
926 str = "Peer-group members must be all internal or all external.";
927 break;
928 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
929 str = "Range specified cannot be deleted because it is not part of current config.";
930 break;
931 case BGP_ERR_INSTANCE_MISMATCH:
932 str = "Instance specified does not match the current instance.";
933 break;
934 case BGP_ERR_NO_INTERFACE_CONFIG:
935 str = "Interface specified is not being used for interface based peer.";
936 break;
937 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
938 str = "No configuration already specified for soft reconfiguration.";
939 break;
940 case BGP_ERR_AS_MISMATCH:
941 str = "BGP is already running.";
942 break;
943 case BGP_ERR_AF_UNCONFIGURED:
944 str = "AFI/SAFI specified is not currently configured.";
945 break;
946 case BGP_ERR_INVALID_AS:
947 str = "Confederation AS specified is the same AS as our AS.";
948 break;
949 case BGP_ERR_INVALID_ROLE_NAME:
950 str = "Invalid role name";
951 break;
952 case BGP_ERR_INVALID_INTERNAL_ROLE:
953 str = "External roles can be set only on eBGP session";
954 break;
955 }
956 if (str) {
957 vty_out(vty, "%% %s\n", str);
958 return CMD_WARNING_CONFIG_FAILED;
959 }
960 return CMD_SUCCESS;
961 }
962
963 /* BGP clear sort. */
964 enum clear_sort {
965 clear_all,
966 clear_peer,
967 clear_group,
968 clear_external,
969 clear_as
970 };
971
972 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
973 safi_t safi, int error)
974 {
975 switch (error) {
976 case BGP_ERR_AF_UNCONFIGURED:
977 if (vty)
978 vty_out(vty,
979 "%% BGP: Enable %s address family for the neighbor %s\n",
980 get_afi_safi_str(afi, safi, false), peer->host);
981 else
982 zlog_warn(
983 "%% BGP: Enable %s address family for the neighbor %s",
984 get_afi_safi_str(afi, safi, false), peer->host);
985 break;
986 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
987 if (vty)
988 vty_out(vty,
989 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
990 peer->host);
991 else
992 zlog_warn(
993 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
994 peer->host);
995 break;
996 default:
997 break;
998 }
999 }
1000
1001 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
1002 struct listnode **nnode, enum bgp_clear_type stype)
1003 {
1004 int ret = 0;
1005 struct peer_af *paf;
1006
1007 /* if afi/.safi not specified, spin thru all of them */
1008 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1009 afi_t tmp_afi;
1010 safi_t tmp_safi;
1011 enum bgp_af_index index;
1012
1013 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1014 paf = peer->peer_af_array[index];
1015 if (!paf)
1016 continue;
1017
1018 if (paf && paf->subgroup)
1019 SET_FLAG(paf->subgroup->sflags,
1020 SUBGRP_STATUS_FORCE_UPDATES);
1021
1022 tmp_afi = paf->afi;
1023 tmp_safi = paf->safi;
1024 if (!peer->afc[tmp_afi][tmp_safi])
1025 continue;
1026
1027 if (stype == BGP_CLEAR_SOFT_NONE)
1028 ret = peer_clear(peer, nnode);
1029 else
1030 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1031 stype);
1032 }
1033 /* if afi specified and safi not, spin thru safis on this afi */
1034 } else if (safi == SAFI_UNSPEC) {
1035 safi_t tmp_safi;
1036
1037 for (tmp_safi = SAFI_UNICAST;
1038 tmp_safi < SAFI_MAX; tmp_safi++) {
1039 if (!peer->afc[afi][tmp_safi])
1040 continue;
1041
1042 paf = peer_af_find(peer, afi, tmp_safi);
1043 if (paf && paf->subgroup)
1044 SET_FLAG(paf->subgroup->sflags,
1045 SUBGRP_STATUS_FORCE_UPDATES);
1046
1047 if (stype == BGP_CLEAR_SOFT_NONE)
1048 ret = peer_clear(peer, nnode);
1049 else
1050 ret = peer_clear_soft(peer, afi,
1051 tmp_safi, stype);
1052 }
1053 /* both afi/safi specified, let the caller know if not defined */
1054 } else {
1055 if (!peer->afc[afi][safi])
1056 return 1;
1057
1058 paf = peer_af_find(peer, afi, safi);
1059 if (paf && paf->subgroup)
1060 SET_FLAG(paf->subgroup->sflags,
1061 SUBGRP_STATUS_FORCE_UPDATES);
1062
1063 if (stype == BGP_CLEAR_SOFT_NONE)
1064 ret = peer_clear(peer, nnode);
1065 else
1066 ret = peer_clear_soft(peer, afi, safi, stype);
1067 }
1068
1069 return ret;
1070 }
1071
1072 /* `clear ip bgp' functions. */
1073 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1074 enum clear_sort sort, enum bgp_clear_type stype,
1075 const char *arg)
1076 {
1077 int ret = 0;
1078 bool found = false;
1079 struct peer *peer;
1080
1081 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1082
1083 /* Clear all neighbors. */
1084 /*
1085 * Pass along pointer to next node to peer_clear() when walking all
1086 * nodes on the BGP instance as that may get freed if it is a
1087 * doppelganger
1088 */
1089 if (sort == clear_all) {
1090 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1091
1092 bgp_peer_gr_flags_update(peer);
1093
1094 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1095 gr_router_detected = true;
1096
1097 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1098 stype);
1099
1100 if (ret < 0)
1101 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1102 }
1103
1104 if (gr_router_detected
1105 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1106 bgp_zebra_send_capabilities(bgp, false);
1107 } else if (!gr_router_detected
1108 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1109 bgp_zebra_send_capabilities(bgp, true);
1110 }
1111
1112 /* This is to apply read-only mode on this clear. */
1113 if (stype == BGP_CLEAR_SOFT_NONE)
1114 bgp->update_delay_over = 0;
1115
1116 return CMD_SUCCESS;
1117 }
1118
1119 /* Clear specified neighbor. */
1120 if (sort == clear_peer) {
1121 union sockunion su;
1122
1123 /* Make sockunion for lookup. */
1124 ret = str2sockunion(arg, &su);
1125 if (ret < 0) {
1126 peer = peer_lookup_by_conf_if(bgp, arg);
1127 if (!peer) {
1128 peer = peer_lookup_by_hostname(bgp, arg);
1129 if (!peer) {
1130 vty_out(vty,
1131 "Malformed address or name: %s\n",
1132 arg);
1133 return CMD_WARNING;
1134 }
1135 }
1136 } else {
1137 peer = peer_lookup(bgp, &su);
1138 if (!peer) {
1139 vty_out(vty,
1140 "%% BGP: Unknown neighbor - \"%s\"\n",
1141 arg);
1142 return CMD_WARNING;
1143 }
1144 }
1145
1146 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1147 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1148
1149 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1150
1151 /* if afi/safi not defined for this peer, let caller know */
1152 if (ret == 1)
1153 ret = BGP_ERR_AF_UNCONFIGURED;
1154
1155 if (ret < 0)
1156 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1157
1158 return CMD_SUCCESS;
1159 }
1160
1161 /* Clear all neighbors belonging to a specific peer-group. */
1162 if (sort == clear_group) {
1163 struct peer_group *group;
1164
1165 group = peer_group_lookup(bgp, arg);
1166 if (!group) {
1167 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1168 return CMD_WARNING;
1169 }
1170
1171 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1172 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1173
1174 if (ret < 0)
1175 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1176 else
1177 found = true;
1178 }
1179
1180 if (!found)
1181 vty_out(vty,
1182 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1183 get_afi_safi_str(afi, safi, false), arg);
1184
1185 return CMD_SUCCESS;
1186 }
1187
1188 /* Clear all external (eBGP) neighbors. */
1189 if (sort == clear_external) {
1190 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1191 if (peer->sort == BGP_PEER_IBGP)
1192 continue;
1193
1194 bgp_peer_gr_flags_update(peer);
1195
1196 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1197 gr_router_detected = true;
1198
1199 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1200
1201 if (ret < 0)
1202 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1203 else
1204 found = true;
1205 }
1206
1207 if (gr_router_detected
1208 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1209 bgp_zebra_send_capabilities(bgp, false);
1210 } else if (!gr_router_detected
1211 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1212 bgp_zebra_send_capabilities(bgp, true);
1213 }
1214
1215 if (!found)
1216 vty_out(vty,
1217 "%% BGP: No external %s peer is configured\n",
1218 get_afi_safi_str(afi, safi, false));
1219
1220 return CMD_SUCCESS;
1221 }
1222
1223 /* Clear all neighbors belonging to a specific AS. */
1224 if (sort == clear_as) {
1225 as_t as = strtoul(arg, NULL, 10);
1226
1227 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1228 if (peer->as != as)
1229 continue;
1230
1231 bgp_peer_gr_flags_update(peer);
1232
1233 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1234 gr_router_detected = true;
1235
1236 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1237
1238 if (ret < 0)
1239 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1240 else
1241 found = true;
1242 }
1243
1244 if (gr_router_detected
1245 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1246 bgp_zebra_send_capabilities(bgp, false);
1247 } else if (!gr_router_detected
1248 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1249 bgp_zebra_send_capabilities(bgp, true);
1250 }
1251
1252 if (!found)
1253 vty_out(vty,
1254 "%% BGP: No %s peer is configured with AS %s\n",
1255 get_afi_safi_str(afi, safi, false), arg);
1256
1257 return CMD_SUCCESS;
1258 }
1259
1260 return CMD_SUCCESS;
1261 }
1262
1263 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1264 safi_t safi, enum clear_sort sort,
1265 enum bgp_clear_type stype, const char *arg)
1266 {
1267 struct bgp *bgp;
1268
1269 /* BGP structure lookup. */
1270 if (name) {
1271 bgp = bgp_lookup_by_name(name);
1272 if (bgp == NULL) {
1273 vty_out(vty, "Can't find BGP instance %s\n", name);
1274 return CMD_WARNING;
1275 }
1276 } else {
1277 bgp = bgp_get_default();
1278 if (bgp == NULL) {
1279 vty_out(vty, "No BGP process is configured\n");
1280 return CMD_WARNING;
1281 }
1282 }
1283
1284 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1285 }
1286
1287 /* clear soft inbound */
1288 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1289 {
1290 afi_t afi;
1291 safi_t safi;
1292
1293 FOREACH_AFI_SAFI (afi, safi)
1294 bgp_clear_vty(vty, name, afi, safi, clear_all,
1295 BGP_CLEAR_SOFT_IN, NULL);
1296 }
1297
1298 /* clear soft outbound */
1299 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1300 {
1301 afi_t afi;
1302 safi_t safi;
1303
1304 FOREACH_AFI_SAFI (afi, safi)
1305 bgp_clear_vty(vty, name, afi, safi, clear_all,
1306 BGP_CLEAR_SOFT_OUT, NULL);
1307 }
1308
1309
1310 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1311 {
1312 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1313 }
1314
1315 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1316 uint64_t flag, int set)
1317 {
1318 int ret;
1319 struct peer *peer;
1320
1321 peer = peer_and_group_lookup_vty(vty, ip_str);
1322 if (!peer)
1323 return CMD_WARNING_CONFIG_FAILED;
1324
1325 /*
1326 * If 'neighbor <interface>', then this is for directly connected peers,
1327 * we should not accept disable-connected-check.
1328 */
1329 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1330 vty_out(vty,
1331 "%s is directly connected peer, cannot accept disable-connected-check\n",
1332 ip_str);
1333 return CMD_WARNING_CONFIG_FAILED;
1334 }
1335
1336 if (!set && flag == PEER_FLAG_SHUTDOWN)
1337 peer_tx_shutdown_message_unset(peer);
1338
1339 if (set)
1340 ret = peer_flag_set(peer, flag);
1341 else
1342 ret = peer_flag_unset(peer, flag);
1343
1344 return bgp_vty_return(vty, ret);
1345 }
1346
1347 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1348 {
1349 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1350 }
1351
1352 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1353 uint64_t flag)
1354 {
1355 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1356 }
1357
1358 #include "bgpd/bgp_vty_clippy.c"
1359
1360 DEFUN_HIDDEN (bgp_local_mac,
1361 bgp_local_mac_cmd,
1362 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1363 BGP_STR
1364 "Local MAC config\n"
1365 "VxLAN Network Identifier\n"
1366 "VNI number\n"
1367 "local mac\n"
1368 "mac address\n"
1369 "mac-mobility sequence\n"
1370 "seq number\n")
1371 {
1372 int rv;
1373 vni_t vni;
1374 struct ethaddr mac;
1375 struct ipaddr ip;
1376 uint32_t seq;
1377 struct bgp *bgp;
1378
1379 vni = strtoul(argv[3]->arg, NULL, 10);
1380 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1381 vty_out(vty, "%% Malformed MAC address\n");
1382 return CMD_WARNING;
1383 }
1384 memset(&ip, 0, sizeof(ip));
1385 seq = strtoul(argv[7]->arg, NULL, 10);
1386
1387 bgp = bgp_get_default();
1388 if (!bgp) {
1389 vty_out(vty, "Default BGP instance is not there\n");
1390 return CMD_WARNING;
1391 }
1392
1393 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1394 zero_esi);
1395 if (rv < 0) {
1396 vty_out(vty, "Internal error\n");
1397 return CMD_WARNING;
1398 }
1399
1400 return CMD_SUCCESS;
1401 }
1402
1403 DEFUN_HIDDEN (no_bgp_local_mac,
1404 no_bgp_local_mac_cmd,
1405 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1406 NO_STR
1407 BGP_STR
1408 "Local MAC config\n"
1409 "VxLAN Network Identifier\n"
1410 "VNI number\n"
1411 "local mac\n"
1412 "mac address\n")
1413 {
1414 int rv;
1415 vni_t vni;
1416 struct ethaddr mac;
1417 struct ipaddr ip;
1418 struct bgp *bgp;
1419
1420 vni = strtoul(argv[4]->arg, NULL, 10);
1421 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1422 vty_out(vty, "%% Malformed MAC address\n");
1423 return CMD_WARNING;
1424 }
1425 memset(&ip, 0, sizeof(ip));
1426
1427 bgp = bgp_get_default();
1428 if (!bgp) {
1429 vty_out(vty, "Default BGP instance is not there\n");
1430 return CMD_WARNING;
1431 }
1432
1433 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1434 if (rv < 0) {
1435 vty_out(vty, "Internal error\n");
1436 return CMD_WARNING;
1437 }
1438
1439 return CMD_SUCCESS;
1440 }
1441
1442 DEFUN (no_synchronization,
1443 no_synchronization_cmd,
1444 "no synchronization",
1445 NO_STR
1446 "Perform IGP synchronization\n")
1447 {
1448 return CMD_SUCCESS;
1449 }
1450
1451 DEFUN (no_auto_summary,
1452 no_auto_summary_cmd,
1453 "no auto-summary",
1454 NO_STR
1455 "Enable automatic network number summarization\n")
1456 {
1457 return CMD_SUCCESS;
1458 }
1459
1460 /* "router bgp" commands. */
1461 DEFUN_NOSH (router_bgp,
1462 router_bgp_cmd,
1463 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1464 ROUTER_STR
1465 BGP_STR
1466 AS_STR
1467 BGP_INSTANCE_HELP_STR)
1468 {
1469 int idx_asn = 2;
1470 int idx_view_vrf = 3;
1471 int idx_vrf = 4;
1472 int is_new_bgp = 0;
1473 int ret;
1474 as_t as;
1475 struct bgp *bgp;
1476 const char *name = NULL;
1477 enum bgp_instance_type inst_type;
1478
1479 // "router bgp" without an ASN
1480 if (argc == 2) {
1481 // Pending: Make VRF option available for ASN less config
1482 bgp = bgp_get_default();
1483
1484 if (bgp == NULL) {
1485 vty_out(vty, "%% No BGP process is configured\n");
1486 return CMD_WARNING_CONFIG_FAILED;
1487 }
1488
1489 if (listcount(bm->bgp) > 1) {
1490 vty_out(vty, "%% Please specify ASN and VRF\n");
1491 return CMD_WARNING_CONFIG_FAILED;
1492 }
1493 }
1494
1495 // "router bgp X"
1496 else {
1497 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1498
1499 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1500 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1501 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1502
1503 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1504 if (argc > 3) {
1505 name = argv[idx_vrf]->arg;
1506
1507 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1508 if (strmatch(name, VRF_DEFAULT_NAME))
1509 name = NULL;
1510 else
1511 inst_type = BGP_INSTANCE_TYPE_VRF;
1512 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1513 inst_type = BGP_INSTANCE_TYPE_VIEW;
1514 }
1515
1516 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1517 is_new_bgp = (bgp_lookup(as, name) == NULL);
1518
1519 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1520 switch (ret) {
1521 case BGP_ERR_AS_MISMATCH:
1522 vty_out(vty, "BGP is already running; AS is %u\n", as);
1523 return CMD_WARNING_CONFIG_FAILED;
1524 case BGP_ERR_INSTANCE_MISMATCH:
1525 vty_out(vty,
1526 "BGP instance name and AS number mismatch\n");
1527 vty_out(vty,
1528 "BGP instance is already running; AS is %u\n",
1529 as);
1530 return CMD_WARNING_CONFIG_FAILED;
1531 }
1532
1533 /*
1534 * If we just instantiated the default instance, complete
1535 * any pending VRF-VPN leaking that was configured via
1536 * earlier "router bgp X vrf FOO" blocks.
1537 */
1538 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1539 vpn_leak_postchange_all();
1540
1541 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1542 bgp_vpn_leak_export(bgp);
1543 /* Pending: handle when user tries to change a view to vrf n vv.
1544 */
1545 }
1546
1547 /* unset the auto created flag as the user config is now present */
1548 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1549 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1550
1551 return CMD_SUCCESS;
1552 }
1553
1554 /* "no router bgp" commands. */
1555 DEFUN (no_router_bgp,
1556 no_router_bgp_cmd,
1557 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1558 NO_STR
1559 ROUTER_STR
1560 BGP_STR
1561 AS_STR
1562 BGP_INSTANCE_HELP_STR)
1563 {
1564 int idx_asn = 3;
1565 int idx_vrf = 5;
1566 as_t as;
1567 struct bgp *bgp;
1568 const char *name = NULL;
1569
1570 // "no router bgp" without an ASN
1571 if (argc == 3) {
1572 // Pending: Make VRF option available for ASN less config
1573 bgp = bgp_get_default();
1574
1575 if (bgp == NULL) {
1576 vty_out(vty, "%% No BGP process is configured\n");
1577 return CMD_WARNING_CONFIG_FAILED;
1578 }
1579
1580 if (listcount(bm->bgp) > 1) {
1581 vty_out(vty, "%% Please specify ASN and VRF\n");
1582 return CMD_WARNING_CONFIG_FAILED;
1583 }
1584
1585 if (bgp->l3vni) {
1586 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1587 bgp->l3vni);
1588 return CMD_WARNING_CONFIG_FAILED;
1589 }
1590 } else {
1591 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1592
1593 if (argc > 4) {
1594 name = argv[idx_vrf]->arg;
1595 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1596 && strmatch(name, VRF_DEFAULT_NAME))
1597 name = NULL;
1598 }
1599
1600 /* Lookup bgp structure. */
1601 bgp = bgp_lookup(as, name);
1602 if (!bgp) {
1603 vty_out(vty, "%% Can't find BGP instance\n");
1604 return CMD_WARNING_CONFIG_FAILED;
1605 }
1606
1607 if (bgp->l3vni) {
1608 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1609 bgp->l3vni);
1610 return CMD_WARNING_CONFIG_FAILED;
1611 }
1612
1613 /* Cannot delete default instance if vrf instances exist */
1614 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1615 struct listnode *node;
1616 struct bgp *tmp_bgp;
1617
1618 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1619 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1620 continue;
1621 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1622 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1623 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1624 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1625 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1626 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1627 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1628 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1629 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1630 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1631 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1632 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1633 (bgp == bgp_get_evpn() &&
1634 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1635 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1636 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1637 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1638 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1639 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1640 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1641 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1642 (hashcount(tmp_bgp->vnihash))) {
1643 vty_out(vty,
1644 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1645 return CMD_WARNING_CONFIG_FAILED;
1646 }
1647 }
1648 }
1649 }
1650
1651 bgp_delete(bgp);
1652
1653 return CMD_SUCCESS;
1654 }
1655
1656 /* bgp session-dscp */
1657
1658 DEFPY (bgp_session_dscp,
1659 bgp_session_dscp_cmd,
1660 "bgp session-dscp (0-63)$dscp",
1661 BGP_STR
1662 "Override default (C6) bgp TCP session DSCP value\n"
1663 "Manually configured dscp parameter\n")
1664 {
1665 bm->tcp_dscp = dscp << 2;
1666
1667 return CMD_SUCCESS;
1668 }
1669
1670 DEFPY (no_bgp_session_dscp,
1671 no_bgp_session_dscp_cmd,
1672 "no bgp session-dscp [(0-63)]",
1673 NO_STR
1674 BGP_STR
1675 "Override default (C6) bgp TCP session DSCP value\n"
1676 "Manually configured dscp parameter\n")
1677 {
1678 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1679
1680 return CMD_SUCCESS;
1681 }
1682
1683 /* BGP router-id. */
1684
1685 DEFPY (bgp_router_id,
1686 bgp_router_id_cmd,
1687 "bgp router-id A.B.C.D",
1688 BGP_STR
1689 "Override configured router identifier\n"
1690 "Manually configured router identifier\n")
1691 {
1692 VTY_DECLVAR_CONTEXT(bgp, bgp);
1693 bgp_router_id_static_set(bgp, router_id);
1694 return CMD_SUCCESS;
1695 }
1696
1697 DEFPY (no_bgp_router_id,
1698 no_bgp_router_id_cmd,
1699 "no bgp router-id [A.B.C.D]",
1700 NO_STR
1701 BGP_STR
1702 "Override configured router identifier\n"
1703 "Manually configured router identifier\n")
1704 {
1705 VTY_DECLVAR_CONTEXT(bgp, bgp);
1706
1707 if (router_id_str) {
1708 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1709 vty_out(vty, "%% BGP router-id doesn't match\n");
1710 return CMD_WARNING_CONFIG_FAILED;
1711 }
1712 }
1713
1714 router_id.s_addr = 0;
1715 bgp_router_id_static_set(bgp, router_id);
1716
1717 return CMD_SUCCESS;
1718 }
1719
1720 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1721 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1722 NO_STR BGP_STR
1723 "Add community specific parameters\n"
1724 "Create an alias for a community\n"
1725 "Community (AA:BB or AA:BB:CC)\n"
1726 "Alias name\n")
1727 {
1728 struct community_alias ca = {};
1729 struct community_alias *lookup_community;
1730 struct community_alias *lookup_alias;
1731 struct community *comm;
1732 struct lcommunity *lcomm;
1733 uint8_t invalid = 0;
1734
1735 comm = community_str2com(community);
1736 if (!comm)
1737 invalid++;
1738 community_free(&comm);
1739
1740 lcomm = lcommunity_str2com(community);
1741 if (!lcomm)
1742 invalid++;
1743 lcommunity_free(&lcomm);
1744
1745 if (invalid > 1) {
1746 vty_out(vty, "Invalid community format\n");
1747 return CMD_WARNING;
1748 }
1749
1750 strlcpy(ca.community, community, sizeof(ca.community));
1751 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1752
1753 lookup_community = bgp_ca_community_lookup(&ca);
1754 lookup_alias = bgp_ca_alias_lookup(&ca);
1755
1756 if (no) {
1757 bgp_ca_alias_delete(&ca);
1758 bgp_ca_community_delete(&ca);
1759 } else {
1760 if (lookup_alias) {
1761 /* Lookup if community hash table has an item
1762 * with the same alias name.
1763 */
1764 strlcpy(ca.community, lookup_alias->community,
1765 sizeof(ca.community));
1766 if (bgp_ca_community_lookup(&ca)) {
1767 vty_out(vty,
1768 "community (%s) already has this alias (%s)\n",
1769 lookup_alias->community,
1770 lookup_alias->alias);
1771 return CMD_WARNING;
1772 }
1773 bgp_ca_alias_delete(&ca);
1774 }
1775
1776 if (lookup_community) {
1777 /* Lookup if alias hash table has an item
1778 * with the same community.
1779 */
1780 strlcpy(ca.alias, lookup_community->alias,
1781 sizeof(ca.alias));
1782 if (bgp_ca_alias_lookup(&ca)) {
1783 vty_out(vty,
1784 "alias (%s) already has this community (%s)\n",
1785 lookup_community->alias,
1786 lookup_community->community);
1787 return CMD_WARNING;
1788 }
1789 bgp_ca_community_delete(&ca);
1790 }
1791
1792 bgp_ca_alias_insert(&ca);
1793 bgp_ca_community_insert(&ca);
1794 }
1795
1796 return CMD_SUCCESS;
1797 }
1798
1799 DEFPY (bgp_global_suppress_fib_pending,
1800 bgp_global_suppress_fib_pending_cmd,
1801 "[no] bgp suppress-fib-pending",
1802 NO_STR
1803 BGP_STR
1804 "Advertise only routes that are programmed in kernel to peers globally\n")
1805 {
1806 bm_wait_for_fib_set(!no);
1807
1808 return CMD_SUCCESS;
1809 }
1810
1811 DEFPY (bgp_suppress_fib_pending,
1812 bgp_suppress_fib_pending_cmd,
1813 "[no] bgp suppress-fib-pending",
1814 NO_STR
1815 BGP_STR
1816 "Advertise only routes that are programmed in kernel to peers\n")
1817 {
1818 VTY_DECLVAR_CONTEXT(bgp, bgp);
1819
1820 bgp_suppress_fib_pending_set(bgp, !no);
1821 return CMD_SUCCESS;
1822 }
1823
1824
1825 /* BGP Cluster ID. */
1826 DEFUN (bgp_cluster_id,
1827 bgp_cluster_id_cmd,
1828 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1829 BGP_STR
1830 "Configure Route-Reflector Cluster-id\n"
1831 "Route-Reflector Cluster-id in IP address format\n"
1832 "Route-Reflector Cluster-id as 32 bit quantity\n")
1833 {
1834 VTY_DECLVAR_CONTEXT(bgp, bgp);
1835 int idx_ipv4 = 2;
1836 int ret;
1837 struct in_addr cluster;
1838
1839 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1840 if (!ret) {
1841 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1842 return CMD_WARNING_CONFIG_FAILED;
1843 }
1844
1845 bgp_cluster_id_set(bgp, &cluster);
1846 bgp_clear_star_soft_out(vty, bgp->name);
1847
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFUN (no_bgp_cluster_id,
1852 no_bgp_cluster_id_cmd,
1853 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1854 NO_STR
1855 BGP_STR
1856 "Configure Route-Reflector Cluster-id\n"
1857 "Route-Reflector Cluster-id in IP address format\n"
1858 "Route-Reflector Cluster-id as 32 bit quantity\n")
1859 {
1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
1861 bgp_cluster_id_unset(bgp);
1862 bgp_clear_star_soft_out(vty, bgp->name);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867 DEFPY (bgp_norib,
1868 bgp_norib_cmd,
1869 "bgp no-rib",
1870 BGP_STR
1871 "Disable BGP route installation to RIB (Zebra)\n")
1872 {
1873 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1874 vty_out(vty,
1875 "%% No-RIB option is already set, nothing to do here.\n");
1876 return CMD_SUCCESS;
1877 }
1878
1879 bgp_option_norib_set_runtime();
1880
1881 return CMD_SUCCESS;
1882 }
1883
1884 DEFPY (no_bgp_norib,
1885 no_bgp_norib_cmd,
1886 "no bgp no-rib",
1887 NO_STR
1888 BGP_STR
1889 "Disable BGP route installation to RIB (Zebra)\n")
1890 {
1891 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1892 vty_out(vty,
1893 "%% No-RIB option is not set, nothing to do here.\n");
1894 return CMD_SUCCESS;
1895 }
1896
1897 bgp_option_norib_unset_runtime();
1898
1899 return CMD_SUCCESS;
1900 }
1901
1902 DEFPY (no_bgp_send_extra_data,
1903 no_bgp_send_extra_data_cmd,
1904 "[no] bgp send-extra-data zebra",
1905 NO_STR
1906 BGP_STR
1907 "Extra data to Zebra for display/use\n"
1908 "To zebra\n")
1909 {
1910 if (no)
1911 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1912 else
1913 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1914
1915 return CMD_SUCCESS;
1916 }
1917
1918 DEFUN (bgp_confederation_identifier,
1919 bgp_confederation_identifier_cmd,
1920 "bgp confederation identifier (1-4294967295)",
1921 BGP_STR
1922 "AS confederation parameters\n"
1923 "AS number\n"
1924 "Set routing domain confederation AS\n")
1925 {
1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927 int idx_number = 3;
1928 as_t as;
1929
1930 as = strtoul(argv[idx_number]->arg, NULL, 10);
1931
1932 bgp_confederation_id_set(bgp, as);
1933
1934 return CMD_SUCCESS;
1935 }
1936
1937 DEFUN (no_bgp_confederation_identifier,
1938 no_bgp_confederation_identifier_cmd,
1939 "no bgp confederation identifier [(1-4294967295)]",
1940 NO_STR
1941 BGP_STR
1942 "AS confederation parameters\n"
1943 "AS number\n"
1944 "Set routing domain confederation AS\n")
1945 {
1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 bgp_confederation_id_unset(bgp);
1948
1949 return CMD_SUCCESS;
1950 }
1951
1952 DEFUN (bgp_confederation_peers,
1953 bgp_confederation_peers_cmd,
1954 "bgp confederation peers (1-4294967295)...",
1955 BGP_STR
1956 "AS confederation parameters\n"
1957 "Peer ASs in BGP confederation\n"
1958 AS_STR)
1959 {
1960 VTY_DECLVAR_CONTEXT(bgp, bgp);
1961 int idx_asn = 3;
1962 as_t as;
1963 int i;
1964
1965 for (i = idx_asn; i < argc; i++) {
1966 as = strtoul(argv[i]->arg, NULL, 10);
1967 bgp_confederation_peers_add(bgp, as);
1968 }
1969 return CMD_SUCCESS;
1970 }
1971
1972 DEFUN (no_bgp_confederation_peers,
1973 no_bgp_confederation_peers_cmd,
1974 "no bgp confederation peers (1-4294967295)...",
1975 NO_STR
1976 BGP_STR
1977 "AS confederation parameters\n"
1978 "Peer ASs in BGP confederation\n"
1979 AS_STR)
1980 {
1981 VTY_DECLVAR_CONTEXT(bgp, bgp);
1982 int idx_asn = 4;
1983 as_t as;
1984 int i;
1985
1986 for (i = idx_asn; i < argc; i++) {
1987 as = strtoul(argv[i]->arg, NULL, 10);
1988
1989 bgp_confederation_peers_remove(bgp, as);
1990 }
1991 return CMD_SUCCESS;
1992 }
1993
1994 /**
1995 * Central routine for maximum-paths configuration.
1996 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1997 * @set: 1 for setting values, 0 for removing the max-paths config.
1998 */
1999 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2000 const char *mpaths, uint16_t options,
2001 int set)
2002 {
2003 VTY_DECLVAR_CONTEXT(bgp, bgp);
2004 uint16_t maxpaths = 0;
2005 int ret;
2006 afi_t afi;
2007 safi_t safi;
2008
2009 afi = bgp_node_afi(vty);
2010 safi = bgp_node_safi(vty);
2011
2012 if (set) {
2013 maxpaths = strtol(mpaths, NULL, 10);
2014 if (maxpaths > multipath_num) {
2015 vty_out(vty,
2016 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2017 maxpaths, multipath_num);
2018 return CMD_WARNING_CONFIG_FAILED;
2019 }
2020 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2021 options);
2022 } else
2023 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2024
2025 if (ret < 0) {
2026 vty_out(vty,
2027 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2028 (set == 1) ? "" : "un",
2029 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2030 maxpaths, afi, safi);
2031 return CMD_WARNING_CONFIG_FAILED;
2032 }
2033
2034 bgp_recalculate_all_bestpaths(bgp);
2035
2036 return CMD_SUCCESS;
2037 }
2038
2039 DEFUN (bgp_maxmed_admin,
2040 bgp_maxmed_admin_cmd,
2041 "bgp max-med administrative ",
2042 BGP_STR
2043 "Advertise routes with max-med\n"
2044 "Administratively applied, for an indefinite period\n")
2045 {
2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047
2048 bgp->v_maxmed_admin = 1;
2049 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2050
2051 bgp_maxmed_update(bgp);
2052
2053 return CMD_SUCCESS;
2054 }
2055
2056 DEFUN (bgp_maxmed_admin_medv,
2057 bgp_maxmed_admin_medv_cmd,
2058 "bgp max-med administrative (0-4294967295)",
2059 BGP_STR
2060 "Advertise routes with max-med\n"
2061 "Administratively applied, for an indefinite period\n"
2062 "Max MED value to be used\n")
2063 {
2064 VTY_DECLVAR_CONTEXT(bgp, bgp);
2065 int idx_number = 3;
2066
2067 bgp->v_maxmed_admin = 1;
2068 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2069
2070 bgp_maxmed_update(bgp);
2071
2072 return CMD_SUCCESS;
2073 }
2074
2075 DEFUN (no_bgp_maxmed_admin,
2076 no_bgp_maxmed_admin_cmd,
2077 "no bgp max-med administrative [(0-4294967295)]",
2078 NO_STR
2079 BGP_STR
2080 "Advertise routes with max-med\n"
2081 "Administratively applied, for an indefinite period\n"
2082 "Max MED value to be used\n")
2083 {
2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
2085 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2086 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2087 bgp_maxmed_update(bgp);
2088
2089 return CMD_SUCCESS;
2090 }
2091
2092 DEFUN (bgp_maxmed_onstartup,
2093 bgp_maxmed_onstartup_cmd,
2094 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2095 BGP_STR
2096 "Advertise routes with max-med\n"
2097 "Effective on a startup\n"
2098 "Time (seconds) period for max-med\n"
2099 "Max MED value to be used\n")
2100 {
2101 VTY_DECLVAR_CONTEXT(bgp, bgp);
2102 int idx = 0;
2103
2104 if (argv_find(argv, argc, "(5-86400)", &idx))
2105 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2106 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2107 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2108 else
2109 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2110
2111 bgp_maxmed_update(bgp);
2112
2113 return CMD_SUCCESS;
2114 }
2115
2116 DEFUN (no_bgp_maxmed_onstartup,
2117 no_bgp_maxmed_onstartup_cmd,
2118 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2119 NO_STR
2120 BGP_STR
2121 "Advertise routes with max-med\n"
2122 "Effective on a startup\n"
2123 "Time (seconds) period for max-med\n"
2124 "Max MED value to be used\n")
2125 {
2126 VTY_DECLVAR_CONTEXT(bgp, bgp);
2127
2128 /* Cancel max-med onstartup if its on */
2129 if (bgp->t_maxmed_onstartup) {
2130 THREAD_OFF(bgp->t_maxmed_onstartup);
2131 bgp->maxmed_onstartup_over = 1;
2132 }
2133
2134 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2135 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2136
2137 bgp_maxmed_update(bgp);
2138
2139 return CMD_SUCCESS;
2140 }
2141
2142 static int bgp_global_update_delay_config_vty(struct vty *vty,
2143 uint16_t update_delay,
2144 uint16_t establish_wait)
2145 {
2146 struct listnode *node, *nnode;
2147 struct bgp *bgp;
2148 bool vrf_cfg = false;
2149
2150 /*
2151 * See if update-delay is set per-vrf and warn user to delete it
2152 * Note that we only need to check this if this is the first time
2153 * setting the global config.
2154 */
2155 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2156 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2157 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2158 vty_out(vty,
2159 "%% update-delay configuration found in vrf %s\n",
2160 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2161 ? VRF_DEFAULT_NAME
2162 : bgp->name);
2163 vrf_cfg = true;
2164 }
2165 }
2166 }
2167
2168 if (vrf_cfg) {
2169 vty_out(vty,
2170 "%%Failed: global update-delay config not permitted\n");
2171 return CMD_WARNING;
2172 }
2173
2174 if (!establish_wait) { /* update-delay <delay> */
2175 bm->v_update_delay = update_delay;
2176 bm->v_establish_wait = bm->v_update_delay;
2177 } else {
2178 /* update-delay <delay> <establish-wait> */
2179 if (update_delay < establish_wait) {
2180 vty_out(vty,
2181 "%%Failed: update-delay less than the establish-wait!\n");
2182 return CMD_WARNING_CONFIG_FAILED;
2183 }
2184
2185 bm->v_update_delay = update_delay;
2186 bm->v_establish_wait = establish_wait;
2187 }
2188
2189 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2190 bgp->v_update_delay = bm->v_update_delay;
2191 bgp->v_establish_wait = bm->v_establish_wait;
2192 }
2193
2194 return CMD_SUCCESS;
2195 }
2196
2197 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2198 {
2199 struct listnode *node, *nnode;
2200 struct bgp *bgp;
2201
2202 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2203 bm->v_establish_wait = bm->v_update_delay;
2204
2205 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2206 bgp->v_update_delay = bm->v_update_delay;
2207 bgp->v_establish_wait = bm->v_establish_wait;
2208 }
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2214 uint16_t establish_wait)
2215 {
2216 VTY_DECLVAR_CONTEXT(bgp, bgp);
2217
2218 /* if configured globally, per-instance config is not allowed */
2219 if (bm->v_update_delay) {
2220 vty_out(vty,
2221 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2222 return CMD_WARNING_CONFIG_FAILED;
2223 }
2224
2225
2226 if (!establish_wait) /* update-delay <delay> */
2227 {
2228 bgp->v_update_delay = update_delay;
2229 bgp->v_establish_wait = bgp->v_update_delay;
2230 return CMD_SUCCESS;
2231 }
2232
2233 /* update-delay <delay> <establish-wait> */
2234 if (update_delay < establish_wait) {
2235 vty_out(vty,
2236 "%%Failed: update-delay less than the establish-wait!\n");
2237 return CMD_WARNING_CONFIG_FAILED;
2238 }
2239
2240 bgp->v_update_delay = update_delay;
2241 bgp->v_establish_wait = establish_wait;
2242
2243 return CMD_SUCCESS;
2244 }
2245
2246 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2247 {
2248 VTY_DECLVAR_CONTEXT(bgp, bgp);
2249
2250 /* If configured globally, cannot remove from one bgp instance */
2251 if (bm->v_update_delay) {
2252 vty_out(vty,
2253 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2254 return CMD_WARNING_CONFIG_FAILED;
2255 }
2256 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2257 bgp->v_establish_wait = bgp->v_update_delay;
2258
2259 return CMD_SUCCESS;
2260 }
2261
2262 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2263 {
2264 /* If configured globally, no need to display per-instance value */
2265 if (bgp->v_update_delay != bm->v_update_delay) {
2266 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2267 if (bgp->v_update_delay != bgp->v_establish_wait)
2268 vty_out(vty, " %d", bgp->v_establish_wait);
2269 vty_out(vty, "\n");
2270 }
2271 }
2272
2273 /* Global update-delay configuration */
2274 DEFPY (bgp_global_update_delay,
2275 bgp_global_update_delay_cmd,
2276 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2277 BGP_STR
2278 "Force initial delay for best-path and updates for all bgp instances\n"
2279 "Max delay in seconds\n"
2280 "Establish wait in seconds\n")
2281 {
2282 return bgp_global_update_delay_config_vty(vty, delay, wait);
2283 }
2284
2285 /* Global update-delay deconfiguration */
2286 DEFPY (no_bgp_global_update_delay,
2287 no_bgp_global_update_delay_cmd,
2288 "no bgp update-delay [(0-3600) [(1-3600)]]",
2289 NO_STR
2290 BGP_STR
2291 "Force initial delay for best-path and updates\n"
2292 "Max delay in seconds\n"
2293 "Establish wait in seconds\n")
2294 {
2295 return bgp_global_update_delay_deconfig_vty(vty);
2296 }
2297
2298 /* Update-delay configuration */
2299
2300 DEFPY (bgp_update_delay,
2301 bgp_update_delay_cmd,
2302 "update-delay (0-3600)$delay [(1-3600)$wait]",
2303 "Force initial delay for best-path and updates\n"
2304 "Max delay in seconds\n"
2305 "Establish wait in seconds\n")
2306 {
2307 return bgp_update_delay_config_vty(vty, delay, wait);
2308 }
2309
2310 /* Update-delay deconfiguration */
2311 DEFPY (no_bgp_update_delay,
2312 no_bgp_update_delay_cmd,
2313 "no update-delay [(0-3600) [(1-3600)]]",
2314 NO_STR
2315 "Force initial delay for best-path and updates\n"
2316 "Max delay in seconds\n"
2317 "Establish wait in seconds\n")
2318 {
2319 return bgp_update_delay_deconfig_vty(vty);
2320 }
2321
2322
2323 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2324 bool set)
2325 {
2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327
2328 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2329 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2330
2331 return CMD_SUCCESS;
2332 }
2333
2334 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2335 bool set)
2336 {
2337 VTY_DECLVAR_CONTEXT(bgp, bgp);
2338
2339 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2340 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2341
2342 return CMD_SUCCESS;
2343 }
2344
2345 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2346 {
2347 uint32_t quanta =
2348 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2349 if (quanta != BGP_WRITE_PACKET_MAX)
2350 vty_out(vty, " write-quanta %d\n", quanta);
2351 }
2352
2353 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2354 {
2355 uint32_t quanta =
2356 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2357 if (quanta != BGP_READ_PACKET_MAX)
2358 vty_out(vty, " read-quanta %d\n", quanta);
2359 }
2360
2361 /* Packet quanta configuration
2362 *
2363 * XXX: The value set here controls the size of a stack buffer in the IO
2364 * thread. When changing these limits be careful to prevent stack overflow.
2365 *
2366 * Furthermore, the maximums used here should correspond to
2367 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2368 */
2369 DEFPY (bgp_wpkt_quanta,
2370 bgp_wpkt_quanta_cmd,
2371 "[no] write-quanta (1-64)$quanta",
2372 NO_STR
2373 "How many packets to write to peer socket per run\n"
2374 "Number of packets\n")
2375 {
2376 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2377 }
2378
2379 DEFPY (bgp_rpkt_quanta,
2380 bgp_rpkt_quanta_cmd,
2381 "[no] read-quanta (1-10)$quanta",
2382 NO_STR
2383 "How many packets to read from peer socket per I/O cycle\n"
2384 "Number of packets\n")
2385 {
2386 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2387 }
2388
2389 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2390 {
2391 if (!bgp->heuristic_coalesce)
2392 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2393 }
2394
2395 /* BGP TCP keepalive */
2396 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2397 {
2398 if (bgp->tcp_keepalive_idle) {
2399 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2400 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2401 bgp->tcp_keepalive_probes);
2402 }
2403 }
2404
2405 DEFUN (bgp_coalesce_time,
2406 bgp_coalesce_time_cmd,
2407 "coalesce-time (0-4294967295)",
2408 "Subgroup coalesce timer\n"
2409 "Subgroup coalesce timer value (in ms)\n")
2410 {
2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
2412
2413 int idx = 0;
2414
2415 bgp->heuristic_coalesce = false;
2416
2417 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2418 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2419
2420 return CMD_SUCCESS;
2421 }
2422
2423 DEFUN (no_bgp_coalesce_time,
2424 no_bgp_coalesce_time_cmd,
2425 "no coalesce-time (0-4294967295)",
2426 NO_STR
2427 "Subgroup coalesce timer\n"
2428 "Subgroup coalesce timer value (in ms)\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431
2432 bgp->heuristic_coalesce = true;
2433 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2434 return CMD_SUCCESS;
2435 }
2436
2437 /* Maximum-paths configuration */
2438 DEFUN (bgp_maxpaths,
2439 bgp_maxpaths_cmd,
2440 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2441 "Forward packets over multiple paths\n"
2442 "Number of paths\n")
2443 {
2444 int idx_number = 1;
2445 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2446 argv[idx_number]->arg, 0, 1);
2447 }
2448
2449 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2450 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2451 "Forward packets over multiple paths\n"
2452 "Number of paths\n")
2453
2454 DEFUN (bgp_maxpaths_ibgp,
2455 bgp_maxpaths_ibgp_cmd,
2456 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2457 "Forward packets over multiple paths\n"
2458 "iBGP-multipath\n"
2459 "Number of paths\n")
2460 {
2461 int idx_number = 2;
2462 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2463 argv[idx_number]->arg, 0, 1);
2464 }
2465
2466 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2467 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2468 "Forward packets over multiple paths\n"
2469 "iBGP-multipath\n"
2470 "Number of paths\n")
2471
2472 DEFUN (bgp_maxpaths_ibgp_cluster,
2473 bgp_maxpaths_ibgp_cluster_cmd,
2474 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2475 "Forward packets over multiple paths\n"
2476 "iBGP-multipath\n"
2477 "Number of paths\n"
2478 "Match the cluster length\n")
2479 {
2480 int idx_number = 2;
2481 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2482 argv[idx_number]->arg, true, 1);
2483 }
2484
2485 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2486 "maximum-paths ibgp " CMD_RANGE_STR(
2487 1, MULTIPATH_NUM) " equal-cluster-length",
2488 "Forward packets over multiple paths\n"
2489 "iBGP-multipath\n"
2490 "Number of paths\n"
2491 "Match the cluster length\n")
2492
2493 DEFUN (no_bgp_maxpaths,
2494 no_bgp_maxpaths_cmd,
2495 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2496 NO_STR
2497 "Forward packets over multiple paths\n"
2498 "Number of paths\n")
2499 {
2500 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2501 }
2502
2503 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2504 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2505 "Forward packets over multiple paths\n"
2506 "Number of paths\n")
2507
2508 DEFUN (no_bgp_maxpaths_ibgp,
2509 no_bgp_maxpaths_ibgp_cmd,
2510 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2511 NO_STR
2512 "Forward packets over multiple paths\n"
2513 "iBGP-multipath\n"
2514 "Number of paths\n"
2515 "Match the cluster length\n")
2516 {
2517 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2518 }
2519
2520 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2521 "no maximum-paths ibgp [" CMD_RANGE_STR(
2522 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2523 NO_STR
2524 "Forward packets over multiple paths\n"
2525 "iBGP-multipath\n"
2526 "Number of paths\n"
2527 "Match the cluster length\n")
2528
2529 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2530 afi_t afi, safi_t safi)
2531 {
2532 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2533 vty_out(vty, " maximum-paths %d\n",
2534 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2535 }
2536
2537 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2538 vty_out(vty, " maximum-paths ibgp %d",
2539 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2540 if (bgp->maxpaths[afi][safi].same_clusterlen)
2541 vty_out(vty, " equal-cluster-length");
2542 vty_out(vty, "\n");
2543 }
2544 }
2545
2546 /* BGP timers. */
2547
2548 DEFUN (bgp_timers,
2549 bgp_timers_cmd,
2550 "timers bgp (0-65535) (0-65535)",
2551 "Adjust routing timers\n"
2552 "BGP timers\n"
2553 "Keepalive interval\n"
2554 "Holdtime\n")
2555 {
2556 VTY_DECLVAR_CONTEXT(bgp, bgp);
2557 int idx_number = 2;
2558 int idx_number_2 = 3;
2559 unsigned long keepalive = 0;
2560 unsigned long holdtime = 0;
2561
2562 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2563 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2564
2565 /* Holdtime value check. */
2566 if (holdtime < 3 && holdtime != 0) {
2567 vty_out(vty,
2568 "%% hold time value must be either 0 or greater than 3\n");
2569 return CMD_WARNING_CONFIG_FAILED;
2570 }
2571
2572 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2573 BGP_DEFAULT_DELAYOPEN);
2574
2575 return CMD_SUCCESS;
2576 }
2577
2578 DEFUN (no_bgp_timers,
2579 no_bgp_timers_cmd,
2580 "no timers bgp [(0-65535) (0-65535)]",
2581 NO_STR
2582 "Adjust routing timers\n"
2583 "BGP timers\n"
2584 "Keepalive interval\n"
2585 "Holdtime\n")
2586 {
2587 VTY_DECLVAR_CONTEXT(bgp, bgp);
2588 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2589 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2590
2591 return CMD_SUCCESS;
2592 }
2593
2594 /* BGP minimum holdtime. */
2595
2596 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2597 "bgp minimum-holdtime (1-65535)",
2598 "BGP specific commands\n"
2599 "BGP minimum holdtime\n"
2600 "Seconds\n")
2601 {
2602 VTY_DECLVAR_CONTEXT(bgp, bgp);
2603 int idx_number = 2;
2604 unsigned long min_holdtime;
2605
2606 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2607
2608 bgp->default_min_holdtime = min_holdtime;
2609
2610 return CMD_SUCCESS;
2611 }
2612
2613 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2614 "no bgp minimum-holdtime [(1-65535)]",
2615 NO_STR
2616 "BGP specific commands\n"
2617 "BGP minimum holdtime\n"
2618 "Seconds\n")
2619 {
2620 VTY_DECLVAR_CONTEXT(bgp, bgp);
2621
2622 bgp->default_min_holdtime = 0;
2623
2624 return CMD_SUCCESS;
2625 }
2626
2627 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2628 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2629 BGP_STR
2630 "TCP keepalive parameters\n"
2631 "TCP keepalive idle time (seconds)\n"
2632 "TCP keepalive interval (seconds)\n"
2633 "TCP keepalive maximum probes\n")
2634 {
2635 VTY_DECLVAR_CONTEXT(bgp, bgp);
2636
2637 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2638 (uint16_t)probes);
2639
2640 return CMD_SUCCESS;
2641 }
2642
2643 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2644 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2645 NO_STR
2646 BGP_STR
2647 "TCP keepalive parameters\n"
2648 "TCP keepalive idle time (seconds)\n"
2649 "TCP keepalive interval (seconds)\n"
2650 "TCP keepalive maximum probes\n")
2651 {
2652 VTY_DECLVAR_CONTEXT(bgp, bgp);
2653
2654 bgp_tcp_keepalive_unset(bgp);
2655
2656 return CMD_SUCCESS;
2657 }
2658
2659 DEFUN (bgp_client_to_client_reflection,
2660 bgp_client_to_client_reflection_cmd,
2661 "bgp client-to-client reflection",
2662 BGP_STR
2663 "Configure client to client route reflection\n"
2664 "reflection of routes allowed\n")
2665 {
2666 VTY_DECLVAR_CONTEXT(bgp, bgp);
2667 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2668 bgp_clear_star_soft_out(vty, bgp->name);
2669
2670 return CMD_SUCCESS;
2671 }
2672
2673 DEFUN (no_bgp_client_to_client_reflection,
2674 no_bgp_client_to_client_reflection_cmd,
2675 "no bgp client-to-client reflection",
2676 NO_STR
2677 BGP_STR
2678 "Configure client to client route reflection\n"
2679 "reflection of routes allowed\n")
2680 {
2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
2682 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2683 bgp_clear_star_soft_out(vty, bgp->name);
2684
2685 return CMD_SUCCESS;
2686 }
2687
2688 /* "bgp always-compare-med" configuration. */
2689 DEFUN (bgp_always_compare_med,
2690 bgp_always_compare_med_cmd,
2691 "bgp always-compare-med",
2692 BGP_STR
2693 "Allow comparing MED from different neighbors\n")
2694 {
2695 VTY_DECLVAR_CONTEXT(bgp, bgp);
2696 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2697 bgp_recalculate_all_bestpaths(bgp);
2698
2699 return CMD_SUCCESS;
2700 }
2701
2702 DEFUN (no_bgp_always_compare_med,
2703 no_bgp_always_compare_med_cmd,
2704 "no bgp always-compare-med",
2705 NO_STR
2706 BGP_STR
2707 "Allow comparing MED from different neighbors\n")
2708 {
2709 VTY_DECLVAR_CONTEXT(bgp, bgp);
2710 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2711 bgp_recalculate_all_bestpaths(bgp);
2712
2713 return CMD_SUCCESS;
2714 }
2715
2716
2717 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2718 "bgp ebgp-requires-policy",
2719 BGP_STR
2720 "Require in and out policy for eBGP peers (RFC8212)\n")
2721 {
2722 VTY_DECLVAR_CONTEXT(bgp, bgp);
2723 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2724 return CMD_SUCCESS;
2725 }
2726
2727 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2728 "no bgp ebgp-requires-policy",
2729 NO_STR
2730 BGP_STR
2731 "Require in and out policy for eBGP peers (RFC8212)\n")
2732 {
2733 VTY_DECLVAR_CONTEXT(bgp, bgp);
2734 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2735 return CMD_SUCCESS;
2736 }
2737
2738 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2739 "bgp suppress-duplicates",
2740 BGP_STR
2741 "Suppress duplicate updates if the route actually not changed\n")
2742 {
2743 VTY_DECLVAR_CONTEXT(bgp, bgp);
2744 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2745 return CMD_SUCCESS;
2746 }
2747
2748 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2749 "no bgp suppress-duplicates",
2750 NO_STR
2751 BGP_STR
2752 "Suppress duplicate updates if the route actually not changed\n")
2753 {
2754 VTY_DECLVAR_CONTEXT(bgp, bgp);
2755 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2756 return CMD_SUCCESS;
2757 }
2758
2759 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2760 "bgp reject-as-sets",
2761 BGP_STR
2762 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2763 {
2764 VTY_DECLVAR_CONTEXT(bgp, bgp);
2765 struct listnode *node, *nnode;
2766 struct peer *peer;
2767
2768 bgp->reject_as_sets = true;
2769
2770 /* Reset existing BGP sessions to reject routes
2771 * with aspath containing AS_SET or AS_CONFED_SET.
2772 */
2773 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2774 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2775 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2776 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2777 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2778 }
2779 }
2780
2781 return CMD_SUCCESS;
2782 }
2783
2784 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2785 "no bgp reject-as-sets",
2786 NO_STR
2787 BGP_STR
2788 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2789 {
2790 VTY_DECLVAR_CONTEXT(bgp, bgp);
2791 struct listnode *node, *nnode;
2792 struct peer *peer;
2793
2794 bgp->reject_as_sets = false;
2795
2796 /* Reset existing BGP sessions to reject routes
2797 * with aspath containing AS_SET or AS_CONFED_SET.
2798 */
2799 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2800 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2801 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2802 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2803 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2804 }
2805 }
2806
2807 return CMD_SUCCESS;
2808 }
2809
2810 /* "bgp deterministic-med" configuration. */
2811 DEFUN (bgp_deterministic_med,
2812 bgp_deterministic_med_cmd,
2813 "bgp deterministic-med",
2814 BGP_STR
2815 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2816 {
2817 VTY_DECLVAR_CONTEXT(bgp, bgp);
2818
2819 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2820 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2821 bgp_recalculate_all_bestpaths(bgp);
2822 }
2823
2824 return CMD_SUCCESS;
2825 }
2826
2827 DEFUN (no_bgp_deterministic_med,
2828 no_bgp_deterministic_med_cmd,
2829 "no bgp deterministic-med",
2830 NO_STR
2831 BGP_STR
2832 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2833 {
2834 VTY_DECLVAR_CONTEXT(bgp, bgp);
2835 int bestpath_per_as_used;
2836 afi_t afi;
2837 safi_t safi;
2838 struct peer *peer;
2839 struct listnode *node, *nnode;
2840
2841 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2842 bestpath_per_as_used = 0;
2843
2844 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2845 FOREACH_AFI_SAFI (afi, safi)
2846 if (bgp_addpath_dmed_required(
2847 peer->addpath_type[afi][safi])) {
2848 bestpath_per_as_used = 1;
2849 break;
2850 }
2851
2852 if (bestpath_per_as_used)
2853 break;
2854 }
2855
2856 if (bestpath_per_as_used) {
2857 vty_out(vty,
2858 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2859 return CMD_WARNING_CONFIG_FAILED;
2860 } else {
2861 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2862 bgp_recalculate_all_bestpaths(bgp);
2863 }
2864 }
2865
2866 return CMD_SUCCESS;
2867 }
2868
2869 /* "bgp graceful-restart mode" configuration. */
2870 DEFUN (bgp_graceful_restart,
2871 bgp_graceful_restart_cmd,
2872 "bgp graceful-restart",
2873 BGP_STR
2874 GR_CMD
2875 )
2876 {
2877 int ret = BGP_GR_FAILURE;
2878
2879 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2880 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2881
2882 VTY_DECLVAR_CONTEXT(bgp, bgp);
2883
2884 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2885
2886 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2887 ret);
2888
2889 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2890 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2891 vty_out(vty,
2892 "Graceful restart configuration changed, reset all peers to take effect\n");
2893 return bgp_vty_return(vty, ret);
2894 }
2895
2896 DEFUN (no_bgp_graceful_restart,
2897 no_bgp_graceful_restart_cmd,
2898 "no bgp graceful-restart",
2899 NO_STR
2900 BGP_STR
2901 NO_GR_CMD
2902 )
2903 {
2904 VTY_DECLVAR_CONTEXT(bgp, bgp);
2905
2906 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2907 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2908
2909 int ret = BGP_GR_FAILURE;
2910
2911 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2912
2913 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2914 ret);
2915
2916 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2917 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2918 vty_out(vty,
2919 "Graceful restart configuration changed, reset all peers to take effect\n");
2920
2921 return bgp_vty_return(vty, ret);
2922 }
2923
2924 DEFUN (bgp_graceful_restart_stalepath_time,
2925 bgp_graceful_restart_stalepath_time_cmd,
2926 "bgp graceful-restart stalepath-time (1-4095)",
2927 BGP_STR
2928 "Graceful restart capability parameters\n"
2929 "Set the max time to hold onto restarting peer's stale paths\n"
2930 "Delay value (seconds)\n")
2931 {
2932 VTY_DECLVAR_CONTEXT(bgp, bgp);
2933 int idx_number = 3;
2934 uint32_t stalepath;
2935
2936 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2937 bgp->stalepath_time = stalepath;
2938 return CMD_SUCCESS;
2939 }
2940
2941 DEFUN (bgp_graceful_restart_restart_time,
2942 bgp_graceful_restart_restart_time_cmd,
2943 "bgp graceful-restart restart-time (0-4095)",
2944 BGP_STR
2945 "Graceful restart capability parameters\n"
2946 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2947 "Delay value (seconds)\n")
2948 {
2949 VTY_DECLVAR_CONTEXT(bgp, bgp);
2950 int idx_number = 3;
2951 uint32_t restart;
2952
2953 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2954 bgp->restart_time = restart;
2955 return CMD_SUCCESS;
2956 }
2957
2958 DEFUN (bgp_graceful_restart_select_defer_time,
2959 bgp_graceful_restart_select_defer_time_cmd,
2960 "bgp graceful-restart select-defer-time (0-3600)",
2961 BGP_STR
2962 "Graceful restart capability parameters\n"
2963 "Set the time to defer the BGP route selection after restart\n"
2964 "Delay value (seconds, 0 - disable)\n")
2965 {
2966 VTY_DECLVAR_CONTEXT(bgp, bgp);
2967 int idx_number = 3;
2968 uint32_t defer_time;
2969
2970 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2971 bgp->select_defer_time = defer_time;
2972 if (defer_time == 0)
2973 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2974 else
2975 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2976
2977 return CMD_SUCCESS;
2978 }
2979
2980 DEFUN (no_bgp_graceful_restart_stalepath_time,
2981 no_bgp_graceful_restart_stalepath_time_cmd,
2982 "no bgp graceful-restart stalepath-time [(1-4095)]",
2983 NO_STR
2984 BGP_STR
2985 "Graceful restart capability parameters\n"
2986 "Set the max time to hold onto restarting peer's stale paths\n"
2987 "Delay value (seconds)\n")
2988 {
2989 VTY_DECLVAR_CONTEXT(bgp, bgp);
2990
2991 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2992 return CMD_SUCCESS;
2993 }
2994
2995 DEFUN (no_bgp_graceful_restart_restart_time,
2996 no_bgp_graceful_restart_restart_time_cmd,
2997 "no bgp graceful-restart restart-time [(0-4095)]",
2998 NO_STR
2999 BGP_STR
3000 "Graceful restart capability parameters\n"
3001 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3002 "Delay value (seconds)\n")
3003 {
3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
3005
3006 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3007 return CMD_SUCCESS;
3008 }
3009
3010 DEFUN (no_bgp_graceful_restart_select_defer_time,
3011 no_bgp_graceful_restart_select_defer_time_cmd,
3012 "no bgp graceful-restart select-defer-time [(0-3600)]",
3013 NO_STR
3014 BGP_STR
3015 "Graceful restart capability parameters\n"
3016 "Set the time to defer the BGP route selection after restart\n"
3017 "Delay value (seconds)\n")
3018 {
3019 VTY_DECLVAR_CONTEXT(bgp, bgp);
3020
3021 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3022 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3023
3024 return CMD_SUCCESS;
3025 }
3026
3027 DEFUN (bgp_graceful_restart_preserve_fw,
3028 bgp_graceful_restart_preserve_fw_cmd,
3029 "bgp graceful-restart preserve-fw-state",
3030 BGP_STR
3031 "Graceful restart capability parameters\n"
3032 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3033 {
3034 VTY_DECLVAR_CONTEXT(bgp, bgp);
3035 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3036 return CMD_SUCCESS;
3037 }
3038
3039 DEFUN (no_bgp_graceful_restart_preserve_fw,
3040 no_bgp_graceful_restart_preserve_fw_cmd,
3041 "no bgp graceful-restart preserve-fw-state",
3042 NO_STR
3043 BGP_STR
3044 "Graceful restart capability parameters\n"
3045 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3046 {
3047 VTY_DECLVAR_CONTEXT(bgp, bgp);
3048 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3049 return CMD_SUCCESS;
3050 }
3051
3052 DEFPY (bgp_graceful_restart_notification,
3053 bgp_graceful_restart_notification_cmd,
3054 "[no$no] bgp graceful-restart notification",
3055 NO_STR
3056 BGP_STR
3057 "Graceful restart capability parameters\n"
3058 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3059 {
3060 VTY_DECLVAR_CONTEXT(bgp, bgp);
3061
3062 if (no)
3063 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3064 else
3065 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3066
3067 return CMD_SUCCESS;
3068 }
3069
3070 DEFPY (bgp_administrative_reset,
3071 bgp_administrative_reset_cmd,
3072 "[no$no] bgp hard-administrative-reset",
3073 NO_STR
3074 BGP_STR
3075 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3076 {
3077 VTY_DECLVAR_CONTEXT(bgp, bgp);
3078
3079 if (no)
3080 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3081 else
3082 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3083
3084 return CMD_SUCCESS;
3085 }
3086
3087 DEFUN (bgp_graceful_restart_disable,
3088 bgp_graceful_restart_disable_cmd,
3089 "bgp graceful-restart-disable",
3090 BGP_STR
3091 GR_DISABLE)
3092 {
3093 int ret = BGP_GR_FAILURE;
3094
3095 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3096 zlog_debug(
3097 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3098
3099 VTY_DECLVAR_CONTEXT(bgp, bgp);
3100
3101 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3102
3103 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3104 bgp->peer, ret);
3105
3106 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3107 zlog_debug(
3108 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3109 vty_out(vty,
3110 "Graceful restart configuration changed, reset all peers to take effect\n");
3111
3112 return bgp_vty_return(vty, ret);
3113 }
3114
3115 DEFUN (no_bgp_graceful_restart_disable,
3116 no_bgp_graceful_restart_disable_cmd,
3117 "no bgp graceful-restart-disable",
3118 NO_STR
3119 BGP_STR
3120 NO_GR_DISABLE
3121 )
3122 {
3123 VTY_DECLVAR_CONTEXT(bgp, bgp);
3124
3125 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3126 zlog_debug(
3127 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3128
3129 int ret = BGP_GR_FAILURE;
3130
3131 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3132
3133 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3134 ret);
3135
3136 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3137 zlog_debug(
3138 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3139 vty_out(vty,
3140 "Graceful restart configuration changed, reset all peers to take effect\n");
3141
3142 return bgp_vty_return(vty, ret);
3143 }
3144
3145 DEFUN (bgp_neighbor_graceful_restart_set,
3146 bgp_neighbor_graceful_restart_set_cmd,
3147 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3148 NEIGHBOR_STR
3149 NEIGHBOR_ADDR_STR2
3150 GR_NEIGHBOR_CMD
3151 )
3152 {
3153 int idx_peer = 1;
3154 struct peer *peer;
3155 int ret = BGP_GR_FAILURE;
3156
3157 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3158
3159 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3160 zlog_debug(
3161 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3162
3163 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3164 if (!peer)
3165 return CMD_WARNING_CONFIG_FAILED;
3166
3167 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3168
3169 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3170 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3171
3172 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3173 zlog_debug(
3174 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3175 vty_out(vty,
3176 "Graceful restart configuration changed, reset this peer to take effect\n");
3177
3178 return bgp_vty_return(vty, ret);
3179 }
3180
3181 DEFUN (no_bgp_neighbor_graceful_restart,
3182 no_bgp_neighbor_graceful_restart_set_cmd,
3183 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3184 NO_STR
3185 NEIGHBOR_STR
3186 NEIGHBOR_ADDR_STR2
3187 NO_GR_NEIGHBOR_CMD
3188 )
3189 {
3190 int idx_peer = 2;
3191 int ret = BGP_GR_FAILURE;
3192 struct peer *peer;
3193
3194 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3195
3196 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3197 if (!peer)
3198 return CMD_WARNING_CONFIG_FAILED;
3199
3200 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3201 zlog_debug(
3202 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3203
3204 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3205
3206 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3207 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3208
3209 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3210 zlog_debug(
3211 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3212 vty_out(vty,
3213 "Graceful restart configuration changed, reset this peer to take effect\n");
3214
3215 return bgp_vty_return(vty, ret);
3216 }
3217
3218 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3219 bgp_neighbor_graceful_restart_helper_set_cmd,
3220 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3221 NEIGHBOR_STR
3222 NEIGHBOR_ADDR_STR2
3223 GR_NEIGHBOR_HELPER_CMD
3224 )
3225 {
3226 int idx_peer = 1;
3227 struct peer *peer;
3228 int ret = BGP_GR_FAILURE;
3229
3230 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3231
3232 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3233 zlog_debug(
3234 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3235
3236 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3237
3238 if (!peer)
3239 return CMD_WARNING_CONFIG_FAILED;
3240
3241
3242 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3243
3244 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3245 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3246
3247 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3248 zlog_debug(
3249 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3250 vty_out(vty,
3251 "Graceful restart configuration changed, reset this peer to take effect\n");
3252
3253 return bgp_vty_return(vty, ret);
3254 }
3255
3256 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3257 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3258 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3259 NO_STR
3260 NEIGHBOR_STR
3261 NEIGHBOR_ADDR_STR2
3262 NO_GR_NEIGHBOR_HELPER_CMD
3263 )
3264 {
3265 int idx_peer = 2;
3266 int ret = BGP_GR_FAILURE;
3267 struct peer *peer;
3268
3269 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3270
3271 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3272 if (!peer)
3273 return CMD_WARNING_CONFIG_FAILED;
3274
3275 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3276 zlog_debug(
3277 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3278
3279 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3280
3281 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3282 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3283
3284 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3285 zlog_debug(
3286 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3287 vty_out(vty,
3288 "Graceful restart configuration changed, reset this peer to take effect\n");
3289
3290 return bgp_vty_return(vty, ret);
3291 }
3292
3293 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3294 bgp_neighbor_graceful_restart_disable_set_cmd,
3295 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3296 NEIGHBOR_STR
3297 NEIGHBOR_ADDR_STR2
3298 GR_NEIGHBOR_DISABLE_CMD
3299 )
3300 {
3301 int idx_peer = 1;
3302 struct peer *peer;
3303 int ret = BGP_GR_FAILURE;
3304
3305 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3306
3307 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3308 zlog_debug(
3309 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3310
3311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3312 if (!peer)
3313 return CMD_WARNING_CONFIG_FAILED;
3314
3315 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3316
3317 if (peer->bgp->t_startup)
3318 bgp_peer_gr_flags_update(peer);
3319
3320 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3321 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3322
3323 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3324 zlog_debug(
3325 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3326 vty_out(vty,
3327 "Graceful restart configuration changed, reset this peer to take effect\n");
3328
3329 return bgp_vty_return(vty, ret);
3330 }
3331
3332 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3333 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3334 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3335 NO_STR
3336 NEIGHBOR_STR
3337 NEIGHBOR_ADDR_STR2
3338 NO_GR_NEIGHBOR_DISABLE_CMD
3339 )
3340 {
3341 int idx_peer = 2;
3342 int ret = BGP_GR_FAILURE;
3343 struct peer *peer;
3344
3345 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3346
3347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3348 if (!peer)
3349 return CMD_WARNING_CONFIG_FAILED;
3350
3351 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3352 zlog_debug(
3353 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3354
3355 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3356
3357 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3358 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3359
3360 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3361 zlog_debug(
3362 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3363 vty_out(vty,
3364 "Graceful restart configuration changed, reset this peer to take effect\n");
3365
3366 return bgp_vty_return(vty, ret);
3367 }
3368
3369 DEFPY (neighbor_graceful_shutdown,
3370 neighbor_graceful_shutdown_cmd,
3371 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3372 NO_STR
3373 NEIGHBOR_STR
3374 NEIGHBOR_ADDR_STR2
3375 "Graceful shutdown\n")
3376 {
3377 afi_t afi;
3378 safi_t safi;
3379 struct peer *peer;
3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381 int ret;
3382
3383 peer = peer_and_group_lookup_vty(vty, neighbor);
3384 if (!peer)
3385 return CMD_WARNING_CONFIG_FAILED;
3386
3387 if (no)
3388 ret = peer_flag_unset_vty(vty, neighbor,
3389 PEER_FLAG_GRACEFUL_SHUTDOWN);
3390 else
3391 ret = peer_flag_set_vty(vty, neighbor,
3392 PEER_FLAG_GRACEFUL_SHUTDOWN);
3393
3394 FOREACH_AFI_SAFI (afi, safi) {
3395 if (!peer->afc[afi][safi])
3396 continue;
3397
3398 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3399 neighbor);
3400 }
3401
3402 return ret;
3403 }
3404
3405 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3406 bgp_graceful_restart_disable_eor_cmd,
3407 "bgp graceful-restart disable-eor",
3408 BGP_STR
3409 "Graceful restart configuration parameters\n"
3410 "Disable EOR Check\n")
3411 {
3412 VTY_DECLVAR_CONTEXT(bgp, bgp);
3413 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3414
3415 return CMD_SUCCESS;
3416 }
3417
3418 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3419 no_bgp_graceful_restart_disable_eor_cmd,
3420 "no bgp graceful-restart disable-eor",
3421 NO_STR
3422 BGP_STR
3423 "Graceful restart configuration parameters\n"
3424 "Disable EOR Check\n")
3425 {
3426 VTY_DECLVAR_CONTEXT(bgp, bgp);
3427 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3428
3429 return CMD_SUCCESS;
3430 }
3431
3432 DEFUN (bgp_graceful_restart_rib_stale_time,
3433 bgp_graceful_restart_rib_stale_time_cmd,
3434 "bgp graceful-restart rib-stale-time (1-3600)",
3435 BGP_STR
3436 "Graceful restart configuration parameters\n"
3437 "Specify the stale route removal timer in rib\n"
3438 "Delay value (seconds)\n")
3439 {
3440 VTY_DECLVAR_CONTEXT(bgp, bgp);
3441 int idx_number = 3;
3442 uint32_t stale_time;
3443
3444 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3445 bgp->rib_stale_time = stale_time;
3446 /* Send the stale timer update message to RIB */
3447 if (bgp_zebra_stale_timer_update(bgp))
3448 return CMD_WARNING;
3449
3450 return CMD_SUCCESS;
3451 }
3452
3453 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3454 no_bgp_graceful_restart_rib_stale_time_cmd,
3455 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3456 NO_STR
3457 BGP_STR
3458 "Graceful restart configuration parameters\n"
3459 "Specify the stale route removal timer in rib\n"
3460 "Delay value (seconds)\n")
3461 {
3462 VTY_DECLVAR_CONTEXT(bgp, bgp);
3463
3464 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3465 /* Send the stale timer update message to RIB */
3466 if (bgp_zebra_stale_timer_update(bgp))
3467 return CMD_WARNING;
3468
3469 return CMD_SUCCESS;
3470 }
3471
3472 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3473 "bgp long-lived-graceful-restart stale-time (1-16777215)",
3474 BGP_STR
3475 "Enable Long-lived Graceful Restart\n"
3476 "Specifies maximum time to wait before purging long-lived stale routes\n"
3477 "Stale time value (seconds)\n")
3478 {
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480
3481 uint32_t llgr_stale_time;
3482
3483 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3484 bgp->llgr_stale_time = llgr_stale_time;
3485
3486 return CMD_SUCCESS;
3487 }
3488
3489 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3490 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3491 NO_STR BGP_STR
3492 "Enable Long-lived Graceful Restart\n"
3493 "Specifies maximum time to wait before purging long-lived stale routes\n"
3494 "Stale time value (seconds)\n")
3495 {
3496 VTY_DECLVAR_CONTEXT(bgp, bgp);
3497
3498 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3499
3500 return CMD_SUCCESS;
3501 }
3502
3503 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3504 struct bgp *bgp)
3505 {
3506 bgp_static_redo_import_check(bgp);
3507 bgp_redistribute_redo(bgp);
3508 bgp_clear_star_soft_out(vty, bgp->name);
3509 bgp_clear_star_soft_in(vty, bgp->name);
3510 }
3511
3512 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3513 {
3514 struct listnode *node, *nnode;
3515 struct bgp *bgp;
3516 bool vrf_cfg = false;
3517
3518 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3519 return CMD_SUCCESS;
3520
3521 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3522 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3523 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3524 vty_out(vty,
3525 "%% graceful-shutdown configuration found in vrf %s\n",
3526 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3527 VRF_DEFAULT_NAME : bgp->name);
3528 vrf_cfg = true;
3529 }
3530 }
3531
3532 if (vrf_cfg) {
3533 vty_out(vty,
3534 "%%Failed: global graceful-shutdown not permitted\n");
3535 return CMD_WARNING;
3536 }
3537
3538 /* Set flag globally */
3539 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3540
3541 /* Initiate processing for all BGP instances. */
3542 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3543 bgp_initiate_graceful_shut_unshut(vty, bgp);
3544
3545 return CMD_SUCCESS;
3546 }
3547
3548 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3549 {
3550 struct listnode *node, *nnode;
3551 struct bgp *bgp;
3552
3553 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3554 return CMD_SUCCESS;
3555
3556 /* Unset flag globally */
3557 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3558
3559 /* Initiate processing for all BGP instances. */
3560 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3561 bgp_initiate_graceful_shut_unshut(vty, bgp);
3562
3563 return CMD_SUCCESS;
3564 }
3565
3566 /* "bgp graceful-shutdown" configuration */
3567 DEFUN (bgp_graceful_shutdown,
3568 bgp_graceful_shutdown_cmd,
3569 "bgp graceful-shutdown",
3570 BGP_STR
3571 "Graceful shutdown parameters\n")
3572 {
3573 if (vty->node == CONFIG_NODE)
3574 return bgp_global_graceful_shutdown_config_vty(vty);
3575
3576 VTY_DECLVAR_CONTEXT(bgp, bgp);
3577
3578 /* if configured globally, per-instance config is not allowed */
3579 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3580 vty_out(vty,
3581 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3582 return CMD_WARNING_CONFIG_FAILED;
3583 }
3584
3585 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3586 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3587 bgp_initiate_graceful_shut_unshut(vty, bgp);
3588 }
3589
3590 return CMD_SUCCESS;
3591 }
3592
3593 DEFUN (no_bgp_graceful_shutdown,
3594 no_bgp_graceful_shutdown_cmd,
3595 "no bgp graceful-shutdown",
3596 NO_STR
3597 BGP_STR
3598 "Graceful shutdown parameters\n")
3599 {
3600 if (vty->node == CONFIG_NODE)
3601 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3602
3603 VTY_DECLVAR_CONTEXT(bgp, bgp);
3604
3605 /* If configured globally, cannot remove from one bgp instance */
3606 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3607 vty_out(vty,
3608 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3609 return CMD_WARNING_CONFIG_FAILED;
3610 }
3611
3612 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3613 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3614 bgp_initiate_graceful_shut_unshut(vty, bgp);
3615 }
3616
3617 return CMD_SUCCESS;
3618 }
3619
3620 /* "bgp fast-external-failover" configuration. */
3621 DEFUN (bgp_fast_external_failover,
3622 bgp_fast_external_failover_cmd,
3623 "bgp fast-external-failover",
3624 BGP_STR
3625 "Immediately reset session if a link to a directly connected external peer goes down\n")
3626 {
3627 VTY_DECLVAR_CONTEXT(bgp, bgp);
3628 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3629 return CMD_SUCCESS;
3630 }
3631
3632 DEFUN (no_bgp_fast_external_failover,
3633 no_bgp_fast_external_failover_cmd,
3634 "no bgp fast-external-failover",
3635 NO_STR
3636 BGP_STR
3637 "Immediately reset session if a link to a directly connected external peer goes down\n")
3638 {
3639 VTY_DECLVAR_CONTEXT(bgp, bgp);
3640 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3641 return CMD_SUCCESS;
3642 }
3643
3644 DEFPY (bgp_bestpath_aigp,
3645 bgp_bestpath_aigp_cmd,
3646 "[no$no] bgp bestpath aigp",
3647 NO_STR
3648 BGP_STR
3649 "Change the default bestpath selection\n"
3650 "Evaluate the AIGP attribute during the best path selection process\n")
3651 {
3652 VTY_DECLVAR_CONTEXT(bgp, bgp);
3653
3654 if (no)
3655 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3656 else
3657 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3658
3659 bgp_recalculate_all_bestpaths(bgp);
3660
3661 return CMD_SUCCESS;
3662 }
3663
3664 /* "bgp bestpath compare-routerid" configuration. */
3665 DEFUN (bgp_bestpath_compare_router_id,
3666 bgp_bestpath_compare_router_id_cmd,
3667 "bgp bestpath compare-routerid",
3668 BGP_STR
3669 "Change the default bestpath selection\n"
3670 "Compare router-id for identical EBGP paths\n")
3671 {
3672 VTY_DECLVAR_CONTEXT(bgp, bgp);
3673 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3674 bgp_recalculate_all_bestpaths(bgp);
3675
3676 return CMD_SUCCESS;
3677 }
3678
3679 DEFUN (no_bgp_bestpath_compare_router_id,
3680 no_bgp_bestpath_compare_router_id_cmd,
3681 "no bgp bestpath compare-routerid",
3682 NO_STR
3683 BGP_STR
3684 "Change the default bestpath selection\n"
3685 "Compare router-id for identical EBGP paths\n")
3686 {
3687 VTY_DECLVAR_CONTEXT(bgp, bgp);
3688 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3689 bgp_recalculate_all_bestpaths(bgp);
3690
3691 return CMD_SUCCESS;
3692 }
3693
3694 /* "bgp bestpath as-path ignore" configuration. */
3695 DEFUN (bgp_bestpath_aspath_ignore,
3696 bgp_bestpath_aspath_ignore_cmd,
3697 "bgp bestpath as-path ignore",
3698 BGP_STR
3699 "Change the default bestpath selection\n"
3700 "AS-path attribute\n"
3701 "Ignore as-path length in selecting a route\n")
3702 {
3703 VTY_DECLVAR_CONTEXT(bgp, bgp);
3704 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3705 bgp_recalculate_all_bestpaths(bgp);
3706
3707 return CMD_SUCCESS;
3708 }
3709
3710 DEFUN (no_bgp_bestpath_aspath_ignore,
3711 no_bgp_bestpath_aspath_ignore_cmd,
3712 "no bgp bestpath as-path ignore",
3713 NO_STR
3714 BGP_STR
3715 "Change the default bestpath selection\n"
3716 "AS-path attribute\n"
3717 "Ignore as-path length in selecting a route\n")
3718 {
3719 VTY_DECLVAR_CONTEXT(bgp, bgp);
3720 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3721 bgp_recalculate_all_bestpaths(bgp);
3722
3723 return CMD_SUCCESS;
3724 }
3725
3726 /* "bgp bestpath as-path confed" configuration. */
3727 DEFUN (bgp_bestpath_aspath_confed,
3728 bgp_bestpath_aspath_confed_cmd,
3729 "bgp bestpath as-path confed",
3730 BGP_STR
3731 "Change the default bestpath selection\n"
3732 "AS-path attribute\n"
3733 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3734 {
3735 VTY_DECLVAR_CONTEXT(bgp, bgp);
3736 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3737 bgp_recalculate_all_bestpaths(bgp);
3738
3739 return CMD_SUCCESS;
3740 }
3741
3742 DEFUN (no_bgp_bestpath_aspath_confed,
3743 no_bgp_bestpath_aspath_confed_cmd,
3744 "no bgp bestpath as-path confed",
3745 NO_STR
3746 BGP_STR
3747 "Change the default bestpath selection\n"
3748 "AS-path attribute\n"
3749 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3750 {
3751 VTY_DECLVAR_CONTEXT(bgp, bgp);
3752 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3753 bgp_recalculate_all_bestpaths(bgp);
3754
3755 return CMD_SUCCESS;
3756 }
3757
3758 /* "bgp bestpath as-path multipath-relax" configuration. */
3759 DEFUN (bgp_bestpath_aspath_multipath_relax,
3760 bgp_bestpath_aspath_multipath_relax_cmd,
3761 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3762 BGP_STR
3763 "Change the default bestpath selection\n"
3764 "AS-path attribute\n"
3765 "Allow load sharing across routes that have different AS paths (but same length)\n"
3766 "Generate an AS_SET\n"
3767 "Do not generate an AS_SET\n")
3768 {
3769 VTY_DECLVAR_CONTEXT(bgp, bgp);
3770 int idx = 0;
3771 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3772
3773 /* no-as-set is now the default behavior so we can silently
3774 * ignore it */
3775 if (argv_find(argv, argc, "as-set", &idx))
3776 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3777 else
3778 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3779
3780 bgp_recalculate_all_bestpaths(bgp);
3781
3782 return CMD_SUCCESS;
3783 }
3784
3785 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3786 no_bgp_bestpath_aspath_multipath_relax_cmd,
3787 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3788 NO_STR
3789 BGP_STR
3790 "Change the default bestpath selection\n"
3791 "AS-path attribute\n"
3792 "Allow load sharing across routes that have different AS paths (but same length)\n"
3793 "Generate an AS_SET\n"
3794 "Do not generate an AS_SET\n")
3795 {
3796 VTY_DECLVAR_CONTEXT(bgp, bgp);
3797 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3798 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3799 bgp_recalculate_all_bestpaths(bgp);
3800
3801 return CMD_SUCCESS;
3802 }
3803
3804 /* "bgp bestpath peer-type multipath-relax" configuration. */
3805 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3806 bgp_bestpath_peer_type_multipath_relax_cmd,
3807 "bgp bestpath peer-type multipath-relax",
3808 BGP_STR
3809 "Change the default bestpath selection\n"
3810 "Peer type\n"
3811 "Allow load sharing across routes learned from different peer types\n")
3812 {
3813 VTY_DECLVAR_CONTEXT(bgp, bgp);
3814 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3815 bgp_recalculate_all_bestpaths(bgp);
3816
3817 return CMD_SUCCESS;
3818 }
3819
3820 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3821 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3822 "no bgp bestpath peer-type multipath-relax",
3823 NO_STR BGP_STR
3824 "Change the default bestpath selection\n"
3825 "Peer type\n"
3826 "Allow load sharing across routes learned from different peer types\n")
3827 {
3828 VTY_DECLVAR_CONTEXT(bgp, bgp);
3829 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3830 bgp_recalculate_all_bestpaths(bgp);
3831
3832 return CMD_SUCCESS;
3833 }
3834
3835 /* "bgp log-neighbor-changes" configuration. */
3836 DEFUN (bgp_log_neighbor_changes,
3837 bgp_log_neighbor_changes_cmd,
3838 "bgp log-neighbor-changes",
3839 BGP_STR
3840 "Log neighbor up/down and reset reason\n")
3841 {
3842 VTY_DECLVAR_CONTEXT(bgp, bgp);
3843 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3844 return CMD_SUCCESS;
3845 }
3846
3847 DEFUN (no_bgp_log_neighbor_changes,
3848 no_bgp_log_neighbor_changes_cmd,
3849 "no bgp log-neighbor-changes",
3850 NO_STR
3851 BGP_STR
3852 "Log neighbor up/down and reset reason\n")
3853 {
3854 VTY_DECLVAR_CONTEXT(bgp, bgp);
3855 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3856 return CMD_SUCCESS;
3857 }
3858
3859 /* "bgp bestpath med" configuration. */
3860 DEFUN (bgp_bestpath_med,
3861 bgp_bestpath_med_cmd,
3862 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3863 BGP_STR
3864 "Change the default bestpath selection\n"
3865 "MED attribute\n"
3866 "Compare MED among confederation paths\n"
3867 "Treat missing MED as the least preferred one\n"
3868 "Treat missing MED as the least preferred one\n"
3869 "Compare MED among confederation paths\n")
3870 {
3871 VTY_DECLVAR_CONTEXT(bgp, bgp);
3872
3873 int idx = 0;
3874 if (argv_find(argv, argc, "confed", &idx))
3875 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3876 idx = 0;
3877 if (argv_find(argv, argc, "missing-as-worst", &idx))
3878 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3879
3880 bgp_recalculate_all_bestpaths(bgp);
3881
3882 return CMD_SUCCESS;
3883 }
3884
3885 DEFUN (no_bgp_bestpath_med,
3886 no_bgp_bestpath_med_cmd,
3887 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3888 NO_STR
3889 BGP_STR
3890 "Change the default bestpath selection\n"
3891 "MED attribute\n"
3892 "Compare MED among confederation paths\n"
3893 "Treat missing MED as the least preferred one\n"
3894 "Treat missing MED as the least preferred one\n"
3895 "Compare MED among confederation paths\n")
3896 {
3897 VTY_DECLVAR_CONTEXT(bgp, bgp);
3898
3899 int idx = 0;
3900 if (argv_find(argv, argc, "confed", &idx))
3901 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3902 idx = 0;
3903 if (argv_find(argv, argc, "missing-as-worst", &idx))
3904 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3905
3906 bgp_recalculate_all_bestpaths(bgp);
3907
3908 return CMD_SUCCESS;
3909 }
3910
3911 /* "bgp bestpath bandwidth" configuration. */
3912 DEFPY (bgp_bestpath_bw,
3913 bgp_bestpath_bw_cmd,
3914 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3915 BGP_STR
3916 "Change the default bestpath selection\n"
3917 "Link Bandwidth attribute\n"
3918 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3919 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3920 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3921 {
3922 VTY_DECLVAR_CONTEXT(bgp, bgp);
3923 afi_t afi;
3924 safi_t safi;
3925
3926 if (!bw_cfg) {
3927 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3928 return CMD_ERR_INCOMPLETE;
3929 }
3930 if (!strcmp(bw_cfg, "ignore"))
3931 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3932 else if (!strcmp(bw_cfg, "skip-missing"))
3933 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3934 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3935 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3936 else
3937 return CMD_ERR_NO_MATCH;
3938
3939 /* This config is used in route install, so redo that. */
3940 FOREACH_AFI_SAFI (afi, safi) {
3941 if (!bgp_fibupd_safi(safi))
3942 continue;
3943 bgp_zebra_announce_table(bgp, afi, safi);
3944 }
3945
3946 return CMD_SUCCESS;
3947 }
3948
3949 DEFPY (no_bgp_bestpath_bw,
3950 no_bgp_bestpath_bw_cmd,
3951 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3952 NO_STR
3953 BGP_STR
3954 "Change the default bestpath selection\n"
3955 "Link Bandwidth attribute\n"
3956 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3957 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3958 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3959 {
3960 VTY_DECLVAR_CONTEXT(bgp, bgp);
3961 afi_t afi;
3962 safi_t safi;
3963
3964 bgp->lb_handling = BGP_LINK_BW_ECMP;
3965
3966 /* This config is used in route install, so redo that. */
3967 FOREACH_AFI_SAFI (afi, safi) {
3968 if (!bgp_fibupd_safi(safi))
3969 continue;
3970 bgp_zebra_announce_table(bgp, afi, safi);
3971 }
3972 return CMD_SUCCESS;
3973 }
3974
3975 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3976 "[no] bgp default <ipv4-unicast|"
3977 "ipv4-multicast|"
3978 "ipv4-vpn|"
3979 "ipv4-labeled-unicast|"
3980 "ipv4-flowspec|"
3981 "ipv6-unicast|"
3982 "ipv6-multicast|"
3983 "ipv6-vpn|"
3984 "ipv6-labeled-unicast|"
3985 "ipv6-flowspec|"
3986 "l2vpn-evpn>$afi_safi",
3987 NO_STR
3988 BGP_STR
3989 "Configure BGP defaults\n"
3990 "Activate ipv4-unicast for a peer by default\n"
3991 "Activate ipv4-multicast for a peer by default\n"
3992 "Activate ipv4-vpn for a peer by default\n"
3993 "Activate ipv4-labeled-unicast for a peer by default\n"
3994 "Activate ipv4-flowspec for a peer by default\n"
3995 "Activate ipv6-unicast for a peer by default\n"
3996 "Activate ipv6-multicast for a peer by default\n"
3997 "Activate ipv6-vpn for a peer by default\n"
3998 "Activate ipv6-labeled-unicast for a peer by default\n"
3999 "Activate ipv6-flowspec for a peer by default\n"
4000 "Activate l2vpn-evpn for a peer by default\n")
4001 {
4002 VTY_DECLVAR_CONTEXT(bgp, bgp);
4003 char afi_safi_str[strlen(afi_safi) + 1];
4004 char *afi_safi_str_tok;
4005
4006 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4007 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4008 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4009 afi_t afi = bgp_vty_afi_from_str(afi_str);
4010 safi_t safi;
4011
4012 /*
4013 * Impossible situation but making coverity happy
4014 */
4015 assert(afi != AFI_MAX);
4016
4017 if (strmatch(safi_str, "labeled"))
4018 safi = bgp_vty_safi_from_str("labeled-unicast");
4019 else
4020 safi = bgp_vty_safi_from_str(safi_str);
4021
4022 assert(safi != SAFI_MAX);
4023 if (no)
4024 bgp->default_af[afi][safi] = false;
4025 else {
4026 if ((safi == SAFI_LABELED_UNICAST
4027 && bgp->default_af[afi][SAFI_UNICAST])
4028 || (safi == SAFI_UNICAST
4029 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4030 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4031 else
4032 bgp->default_af[afi][safi] = true;
4033 }
4034
4035 return CMD_SUCCESS;
4036 }
4037
4038 /* Display hostname in certain command outputs */
4039 DEFUN (bgp_default_show_hostname,
4040 bgp_default_show_hostname_cmd,
4041 "bgp default show-hostname",
4042 BGP_STR
4043 "Configure BGP defaults\n"
4044 "Show hostname in certain command outputs\n")
4045 {
4046 VTY_DECLVAR_CONTEXT(bgp, bgp);
4047 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4048 return CMD_SUCCESS;
4049 }
4050
4051 DEFUN (no_bgp_default_show_hostname,
4052 no_bgp_default_show_hostname_cmd,
4053 "no bgp default show-hostname",
4054 NO_STR
4055 BGP_STR
4056 "Configure BGP defaults\n"
4057 "Show hostname in certain command outputs\n")
4058 {
4059 VTY_DECLVAR_CONTEXT(bgp, bgp);
4060 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4061 return CMD_SUCCESS;
4062 }
4063
4064 /* Display hostname in certain command outputs */
4065 DEFUN (bgp_default_show_nexthop_hostname,
4066 bgp_default_show_nexthop_hostname_cmd,
4067 "bgp default show-nexthop-hostname",
4068 BGP_STR
4069 "Configure BGP defaults\n"
4070 "Show hostname for nexthop in certain command outputs\n")
4071 {
4072 VTY_DECLVAR_CONTEXT(bgp, bgp);
4073 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4074 return CMD_SUCCESS;
4075 }
4076
4077 DEFUN (no_bgp_default_show_nexthop_hostname,
4078 no_bgp_default_show_nexthop_hostname_cmd,
4079 "no bgp default show-nexthop-hostname",
4080 NO_STR
4081 BGP_STR
4082 "Configure BGP defaults\n"
4083 "Show hostname for nexthop in certain command outputs\n")
4084 {
4085 VTY_DECLVAR_CONTEXT(bgp, bgp);
4086 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4087 return CMD_SUCCESS;
4088 }
4089
4090 /* "bgp network import-check" configuration. */
4091 DEFUN (bgp_network_import_check,
4092 bgp_network_import_check_cmd,
4093 "bgp network import-check",
4094 BGP_STR
4095 "BGP network command\n"
4096 "Check BGP network route exists in IGP\n")
4097 {
4098 VTY_DECLVAR_CONTEXT(bgp, bgp);
4099 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4100 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4101 bgp_static_redo_import_check(bgp);
4102 }
4103
4104 return CMD_SUCCESS;
4105 }
4106
4107 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4108 "bgp network import-check exact",
4109 BGP_STR
4110 "BGP network command\n"
4111 "Check BGP network route exists in IGP\n"
4112 "Match route precisely\n")
4113
4114 DEFUN (no_bgp_network_import_check,
4115 no_bgp_network_import_check_cmd,
4116 "no bgp network import-check",
4117 NO_STR
4118 BGP_STR
4119 "BGP network command\n"
4120 "Check BGP network route exists in IGP\n")
4121 {
4122 VTY_DECLVAR_CONTEXT(bgp, bgp);
4123 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4124 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4125 bgp_static_redo_import_check(bgp);
4126 }
4127
4128 return CMD_SUCCESS;
4129 }
4130
4131 DEFUN (bgp_default_local_preference,
4132 bgp_default_local_preference_cmd,
4133 "bgp default local-preference (0-4294967295)",
4134 BGP_STR
4135 "Configure BGP defaults\n"
4136 "local preference (higher=more preferred)\n"
4137 "Configure default local preference value\n")
4138 {
4139 VTY_DECLVAR_CONTEXT(bgp, bgp);
4140 int idx_number = 3;
4141 uint32_t local_pref;
4142
4143 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4144
4145 bgp_default_local_preference_set(bgp, local_pref);
4146 bgp_clear_star_soft_in(vty, bgp->name);
4147
4148 return CMD_SUCCESS;
4149 }
4150
4151 DEFUN (no_bgp_default_local_preference,
4152 no_bgp_default_local_preference_cmd,
4153 "no bgp default local-preference [(0-4294967295)]",
4154 NO_STR
4155 BGP_STR
4156 "Configure BGP defaults\n"
4157 "local preference (higher=more preferred)\n"
4158 "Configure default local preference value\n")
4159 {
4160 VTY_DECLVAR_CONTEXT(bgp, bgp);
4161 bgp_default_local_preference_unset(bgp);
4162 bgp_clear_star_soft_in(vty, bgp->name);
4163
4164 return CMD_SUCCESS;
4165 }
4166
4167
4168 DEFUN (bgp_default_subgroup_pkt_queue_max,
4169 bgp_default_subgroup_pkt_queue_max_cmd,
4170 "bgp default subgroup-pkt-queue-max (20-100)",
4171 BGP_STR
4172 "Configure BGP defaults\n"
4173 "subgroup-pkt-queue-max\n"
4174 "Configure subgroup packet queue max\n")
4175 {
4176 VTY_DECLVAR_CONTEXT(bgp, bgp);
4177 int idx_number = 3;
4178 uint32_t max_size;
4179
4180 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4181
4182 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4183
4184 return CMD_SUCCESS;
4185 }
4186
4187 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4188 no_bgp_default_subgroup_pkt_queue_max_cmd,
4189 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4190 NO_STR
4191 BGP_STR
4192 "Configure BGP defaults\n"
4193 "subgroup-pkt-queue-max\n"
4194 "Configure subgroup packet queue max\n")
4195 {
4196 VTY_DECLVAR_CONTEXT(bgp, bgp);
4197 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4198 return CMD_SUCCESS;
4199 }
4200
4201
4202 DEFUN (bgp_rr_allow_outbound_policy,
4203 bgp_rr_allow_outbound_policy_cmd,
4204 "bgp route-reflector allow-outbound-policy",
4205 BGP_STR
4206 "Allow modifications made by out route-map\n"
4207 "on ibgp neighbors\n")
4208 {
4209 VTY_DECLVAR_CONTEXT(bgp, bgp);
4210
4211 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4212 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4213 update_group_announce_rrclients(bgp);
4214 bgp_clear_star_soft_out(vty, bgp->name);
4215 }
4216
4217 return CMD_SUCCESS;
4218 }
4219
4220 DEFUN (no_bgp_rr_allow_outbound_policy,
4221 no_bgp_rr_allow_outbound_policy_cmd,
4222 "no bgp route-reflector allow-outbound-policy",
4223 NO_STR
4224 BGP_STR
4225 "Allow modifications made by out route-map\n"
4226 "on ibgp neighbors\n")
4227 {
4228 VTY_DECLVAR_CONTEXT(bgp, bgp);
4229
4230 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4231 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4232 update_group_announce_rrclients(bgp);
4233 bgp_clear_star_soft_out(vty, bgp->name);
4234 }
4235
4236 return CMD_SUCCESS;
4237 }
4238
4239 DEFUN (bgp_listen_limit,
4240 bgp_listen_limit_cmd,
4241 "bgp listen limit (1-65535)",
4242 BGP_STR
4243 "BGP Dynamic Neighbors listen commands\n"
4244 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4245 "Configure Dynamic Neighbors listen limit value\n")
4246 {
4247 VTY_DECLVAR_CONTEXT(bgp, bgp);
4248 int idx_number = 3;
4249 int listen_limit;
4250
4251 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4252
4253 bgp_listen_limit_set(bgp, listen_limit);
4254
4255 return CMD_SUCCESS;
4256 }
4257
4258 DEFUN (no_bgp_listen_limit,
4259 no_bgp_listen_limit_cmd,
4260 "no bgp listen limit [(1-65535)]",
4261 NO_STR
4262 BGP_STR
4263 "BGP Dynamic Neighbors listen commands\n"
4264 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4265 "Configure Dynamic Neighbors listen limit value\n")
4266 {
4267 VTY_DECLVAR_CONTEXT(bgp, bgp);
4268 bgp_listen_limit_unset(bgp);
4269 return CMD_SUCCESS;
4270 }
4271
4272
4273 /*
4274 * Check if this listen range is already configured. Check for exact
4275 * match or overlap based on input.
4276 */
4277 static struct peer_group *listen_range_exists(struct bgp *bgp,
4278 struct prefix *range, int exact)
4279 {
4280 struct listnode *node, *nnode;
4281 struct listnode *node1, *nnode1;
4282 struct peer_group *group;
4283 struct prefix *lr;
4284 afi_t afi;
4285 int match;
4286
4287 afi = family2afi(range->family);
4288 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4289 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4290 lr)) {
4291 if (exact)
4292 match = prefix_same(range, lr);
4293 else
4294 match = (prefix_match(range, lr)
4295 || prefix_match(lr, range));
4296 if (match)
4297 return group;
4298 }
4299 }
4300
4301 return NULL;
4302 }
4303
4304 DEFUN (bgp_listen_range,
4305 bgp_listen_range_cmd,
4306 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4307 BGP_STR
4308 "Configure BGP dynamic neighbors listen range\n"
4309 "Configure BGP dynamic neighbors listen range\n"
4310 NEIGHBOR_ADDR_STR
4311 "Member of the peer-group\n"
4312 "Peer-group name\n")
4313 {
4314 VTY_DECLVAR_CONTEXT(bgp, bgp);
4315 struct prefix range;
4316 struct peer_group *group, *existing_group;
4317 afi_t afi;
4318 int ret;
4319 int idx = 0;
4320
4321 argv_find(argv, argc, "A.B.C.D/M", &idx);
4322 argv_find(argv, argc, "X:X::X:X/M", &idx);
4323 char *prefix = argv[idx]->arg;
4324 argv_find(argv, argc, "PGNAME", &idx);
4325 char *peergroup = argv[idx]->arg;
4326
4327 /* Convert IP prefix string to struct prefix. */
4328 ret = str2prefix(prefix, &range);
4329 if (!ret) {
4330 vty_out(vty, "%% Malformed listen range\n");
4331 return CMD_WARNING_CONFIG_FAILED;
4332 }
4333
4334 afi = family2afi(range.family);
4335
4336 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4337 vty_out(vty,
4338 "%% Malformed listen range (link-local address)\n");
4339 return CMD_WARNING_CONFIG_FAILED;
4340 }
4341
4342 apply_mask(&range);
4343
4344 /* Check if same listen range is already configured. */
4345 existing_group = listen_range_exists(bgp, &range, 1);
4346 if (existing_group) {
4347 if (strcmp(existing_group->name, peergroup) == 0)
4348 return CMD_SUCCESS;
4349 else {
4350 vty_out(vty,
4351 "%% Same listen range is attached to peer-group %s\n",
4352 existing_group->name);
4353 return CMD_WARNING_CONFIG_FAILED;
4354 }
4355 }
4356
4357 /* Check if an overlapping listen range exists. */
4358 if (listen_range_exists(bgp, &range, 0)) {
4359 vty_out(vty,
4360 "%% Listen range overlaps with existing listen range\n");
4361 return CMD_WARNING_CONFIG_FAILED;
4362 }
4363
4364 group = peer_group_lookup(bgp, peergroup);
4365 if (!group) {
4366 vty_out(vty, "%% Configure the peer-group first\n");
4367 return CMD_WARNING_CONFIG_FAILED;
4368 }
4369
4370 ret = peer_group_listen_range_add(group, &range);
4371 return bgp_vty_return(vty, ret);
4372 }
4373
4374 DEFUN (no_bgp_listen_range,
4375 no_bgp_listen_range_cmd,
4376 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4377 NO_STR
4378 BGP_STR
4379 "Unconfigure BGP dynamic neighbors listen range\n"
4380 "Unconfigure BGP dynamic neighbors listen range\n"
4381 NEIGHBOR_ADDR_STR
4382 "Member of the peer-group\n"
4383 "Peer-group name\n")
4384 {
4385 VTY_DECLVAR_CONTEXT(bgp, bgp);
4386 struct prefix range;
4387 struct peer_group *group;
4388 afi_t afi;
4389 int ret;
4390 int idx = 0;
4391
4392 argv_find(argv, argc, "A.B.C.D/M", &idx);
4393 argv_find(argv, argc, "X:X::X:X/M", &idx);
4394 char *prefix = argv[idx]->arg;
4395 argv_find(argv, argc, "PGNAME", &idx);
4396 char *peergroup = argv[idx]->arg;
4397
4398 /* Convert IP prefix string to struct prefix. */
4399 ret = str2prefix(prefix, &range);
4400 if (!ret) {
4401 vty_out(vty, "%% Malformed listen range\n");
4402 return CMD_WARNING_CONFIG_FAILED;
4403 }
4404
4405 afi = family2afi(range.family);
4406
4407 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4408 vty_out(vty,
4409 "%% Malformed listen range (link-local address)\n");
4410 return CMD_WARNING_CONFIG_FAILED;
4411 }
4412
4413 apply_mask(&range);
4414
4415 group = peer_group_lookup(bgp, peergroup);
4416 if (!group) {
4417 vty_out(vty, "%% Peer-group does not exist\n");
4418 return CMD_WARNING_CONFIG_FAILED;
4419 }
4420
4421 ret = peer_group_listen_range_del(group, &range);
4422 return bgp_vty_return(vty, ret);
4423 }
4424
4425 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4426 {
4427 struct peer_group *group;
4428 struct listnode *node, *nnode, *rnode, *nrnode;
4429 struct prefix *range;
4430 afi_t afi;
4431
4432 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4433 vty_out(vty, " bgp listen limit %d\n",
4434 bgp->dynamic_neighbors_limit);
4435
4436 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4437 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4438 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4439 nrnode, range)) {
4440 vty_out(vty,
4441 " bgp listen range %pFX peer-group %s\n",
4442 range, group->name);
4443 }
4444 }
4445 }
4446 }
4447
4448
4449 DEFUN (bgp_disable_connected_route_check,
4450 bgp_disable_connected_route_check_cmd,
4451 "bgp disable-ebgp-connected-route-check",
4452 BGP_STR
4453 "Disable checking if nexthop is connected on ebgp sessions\n")
4454 {
4455 VTY_DECLVAR_CONTEXT(bgp, bgp);
4456 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4457 bgp_clear_star_soft_in(vty, bgp->name);
4458
4459 return CMD_SUCCESS;
4460 }
4461
4462 DEFUN (no_bgp_disable_connected_route_check,
4463 no_bgp_disable_connected_route_check_cmd,
4464 "no bgp disable-ebgp-connected-route-check",
4465 NO_STR
4466 BGP_STR
4467 "Disable checking if nexthop is connected on ebgp sessions\n")
4468 {
4469 VTY_DECLVAR_CONTEXT(bgp, bgp);
4470 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4471 bgp_clear_star_soft_in(vty, bgp->name);
4472
4473 return CMD_SUCCESS;
4474 }
4475
4476
4477 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4478 const char *as_str)
4479 {
4480 VTY_DECLVAR_CONTEXT(bgp, bgp);
4481 int ret;
4482 as_t as;
4483 int as_type = AS_SPECIFIED;
4484 union sockunion su;
4485
4486 if (as_str[0] == 'i') {
4487 as = 0;
4488 as_type = AS_INTERNAL;
4489 } else if (as_str[0] == 'e') {
4490 as = 0;
4491 as_type = AS_EXTERNAL;
4492 } else {
4493 /* Get AS number. */
4494 as = strtoul(as_str, NULL, 10);
4495 }
4496
4497 /* If peer is peer group or interface peer, call proper function. */
4498 ret = str2sockunion(peer_str, &su);
4499 if (ret < 0) {
4500 struct peer *peer;
4501
4502 /* Check if existing interface peer */
4503 peer = peer_lookup_by_conf_if(bgp, peer_str);
4504
4505 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4506
4507 /* if not interface peer, check peer-group settings */
4508 if (ret < 0 && !peer) {
4509 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4510 if (ret < 0) {
4511 vty_out(vty,
4512 "%% Create the peer-group or interface first\n");
4513 return CMD_WARNING_CONFIG_FAILED;
4514 }
4515 return CMD_SUCCESS;
4516 }
4517 } else {
4518 if (peer_address_self_check(bgp, &su)) {
4519 vty_out(vty,
4520 "%% Can not configure the local system as neighbor\n");
4521 return CMD_WARNING_CONFIG_FAILED;
4522 }
4523 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4524 }
4525
4526 return bgp_vty_return(vty, ret);
4527 }
4528
4529 DEFUN (bgp_default_shutdown,
4530 bgp_default_shutdown_cmd,
4531 "[no] bgp default shutdown",
4532 NO_STR
4533 BGP_STR
4534 "Configure BGP defaults\n"
4535 "Apply administrative shutdown to newly configured peers\n")
4536 {
4537 VTY_DECLVAR_CONTEXT(bgp, bgp);
4538 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4539 return CMD_SUCCESS;
4540 }
4541
4542 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4543 BGP_STR
4544 "Administrative shutdown of the BGP instance\n"
4545 "Add a shutdown message (RFC 8203)\n"
4546 "Shutdown message\n")
4547 {
4548 char *msgstr = NULL;
4549
4550 VTY_DECLVAR_CONTEXT(bgp, bgp);
4551
4552 if (argc > 3)
4553 msgstr = argv_concat(argv, argc, 3);
4554
4555 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4556 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4557 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4558 return CMD_WARNING_CONFIG_FAILED;
4559 }
4560
4561 bgp_shutdown_enable(bgp, msgstr);
4562 XFREE(MTYPE_TMP, msgstr);
4563
4564 return CMD_SUCCESS;
4565 }
4566
4567 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4568 BGP_STR "Administrative shutdown of the BGP instance\n")
4569 {
4570 VTY_DECLVAR_CONTEXT(bgp, bgp);
4571
4572 bgp_shutdown_enable(bgp, NULL);
4573
4574 return CMD_SUCCESS;
4575 }
4576
4577 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4578 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4579 {
4580 VTY_DECLVAR_CONTEXT(bgp, bgp);
4581
4582 bgp_shutdown_disable(bgp);
4583
4584 return CMD_SUCCESS;
4585 }
4586
4587 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4588 "no bgp shutdown message MSG...", NO_STR BGP_STR
4589 "Administrative shutdown of the BGP instance\n"
4590 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4591
4592 DEFUN (neighbor_remote_as,
4593 neighbor_remote_as_cmd,
4594 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4595 NEIGHBOR_STR
4596 NEIGHBOR_ADDR_STR2
4597 "Specify a BGP neighbor\n"
4598 AS_STR
4599 "Internal BGP peer\n"
4600 "External BGP peer\n")
4601 {
4602 int idx_peer = 1;
4603 int idx_remote_as = 3;
4604 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4605 argv[idx_remote_as]->arg);
4606 }
4607
4608 DEFPY (bgp_allow_martian,
4609 bgp_allow_martian_cmd,
4610 "[no]$no bgp allow-martian-nexthop",
4611 NO_STR
4612 BGP_STR
4613 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4614 {
4615 VTY_DECLVAR_CONTEXT(bgp, bgp);
4616
4617 if (no)
4618 bgp->allow_martian = false;
4619 else
4620 bgp->allow_martian = true;
4621
4622 return CMD_SUCCESS;
4623 }
4624
4625 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4626 * sessions do not wait for hold timer expiry to bring down the sessions
4627 * when nexthop becomes unreachable
4628 */
4629 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4630 BGP_STR "Fast convergence for bgp sessions\n")
4631 {
4632 VTY_DECLVAR_CONTEXT(bgp, bgp);
4633 bgp->fast_convergence = true;
4634
4635 return CMD_SUCCESS;
4636 }
4637
4638 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4639 "no bgp fast-convergence",
4640 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4641 {
4642 VTY_DECLVAR_CONTEXT(bgp, bgp);
4643 bgp->fast_convergence = false;
4644
4645 return CMD_SUCCESS;
4646 }
4647
4648 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4649 int v6only,
4650 const char *peer_group_name,
4651 const char *as_str)
4652 {
4653 VTY_DECLVAR_CONTEXT(bgp, bgp);
4654 as_t as = 0;
4655 int as_type = AS_UNSPECIFIED;
4656 struct peer *peer;
4657 struct peer_group *group;
4658 int ret = 0;
4659
4660 group = peer_group_lookup(bgp, conf_if);
4661
4662 if (group) {
4663 vty_out(vty, "%% Name conflict with peer-group \n");
4664 return CMD_WARNING_CONFIG_FAILED;
4665 }
4666
4667 if (as_str) {
4668 if (as_str[0] == 'i') {
4669 as_type = AS_INTERNAL;
4670 } else if (as_str[0] == 'e') {
4671 as_type = AS_EXTERNAL;
4672 } else {
4673 /* Get AS number. */
4674 as = strtoul(as_str, NULL, 10);
4675 as_type = AS_SPECIFIED;
4676 }
4677 }
4678
4679 peer = peer_lookup_by_conf_if(bgp, conf_if);
4680 if (peer) {
4681 if (as_str)
4682 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4683 } else {
4684 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4685 NULL, true);
4686
4687 if (!peer) {
4688 vty_out(vty, "%% BGP failed to create peer\n");
4689 return CMD_WARNING_CONFIG_FAILED;
4690 }
4691
4692 if (v6only)
4693 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4694
4695 /* Request zebra to initiate IPv6 RAs on this interface. We do
4696 * this
4697 * any unnumbered peer in order to not worry about run-time
4698 * transitions
4699 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4700 * address
4701 * gets deleted later etc.)
4702 */
4703 if (peer->ifp)
4704 bgp_zebra_initiate_radv(bgp, peer);
4705 }
4706
4707 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4708 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4709 if (v6only)
4710 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4711 else
4712 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4713
4714 /* v6only flag changed. Reset bgp seesion */
4715 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4716 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4717 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4718 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4719 } else
4720 bgp_session_reset(peer);
4721 }
4722
4723 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4724 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4725 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4726 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4727 }
4728
4729 if (peer_group_name) {
4730 group = peer_group_lookup(bgp, peer_group_name);
4731 if (!group) {
4732 vty_out(vty, "%% Configure the peer-group first\n");
4733 return CMD_WARNING_CONFIG_FAILED;
4734 }
4735
4736 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4737 }
4738
4739 return bgp_vty_return(vty, ret);
4740 }
4741
4742 DEFUN (neighbor_interface_config,
4743 neighbor_interface_config_cmd,
4744 "neighbor WORD interface [peer-group PGNAME]",
4745 NEIGHBOR_STR
4746 "Interface name or neighbor tag\n"
4747 "Enable BGP on interface\n"
4748 "Member of the peer-group\n"
4749 "Peer-group name\n")
4750 {
4751 int idx_word = 1;
4752 int idx_peer_group_word = 4;
4753
4754 if (argc > idx_peer_group_word)
4755 return peer_conf_interface_get(
4756 vty, argv[idx_word]->arg, 0,
4757 argv[idx_peer_group_word]->arg, NULL);
4758 else
4759 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4760 NULL, NULL);
4761 }
4762
4763 DEFUN (neighbor_interface_config_v6only,
4764 neighbor_interface_config_v6only_cmd,
4765 "neighbor WORD interface v6only [peer-group PGNAME]",
4766 NEIGHBOR_STR
4767 "Interface name or neighbor tag\n"
4768 "Enable BGP on interface\n"
4769 "Enable BGP with v6 link-local only\n"
4770 "Member of the peer-group\n"
4771 "Peer-group name\n")
4772 {
4773 int idx_word = 1;
4774 int idx_peer_group_word = 5;
4775
4776 if (argc > idx_peer_group_word)
4777 return peer_conf_interface_get(
4778 vty, argv[idx_word]->arg, 1,
4779 argv[idx_peer_group_word]->arg, NULL);
4780
4781 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4782 }
4783
4784
4785 DEFUN (neighbor_interface_config_remote_as,
4786 neighbor_interface_config_remote_as_cmd,
4787 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4788 NEIGHBOR_STR
4789 "Interface name or neighbor tag\n"
4790 "Enable BGP on interface\n"
4791 "Specify a BGP neighbor\n"
4792 AS_STR
4793 "Internal BGP peer\n"
4794 "External BGP peer\n")
4795 {
4796 int idx_word = 1;
4797 int idx_remote_as = 4;
4798 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4799 argv[idx_remote_as]->arg);
4800 }
4801
4802 DEFUN (neighbor_interface_v6only_config_remote_as,
4803 neighbor_interface_v6only_config_remote_as_cmd,
4804 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4805 NEIGHBOR_STR
4806 "Interface name or neighbor tag\n"
4807 "Enable BGP with v6 link-local only\n"
4808 "Enable BGP on interface\n"
4809 "Specify a BGP neighbor\n"
4810 AS_STR
4811 "Internal BGP peer\n"
4812 "External BGP peer\n")
4813 {
4814 int idx_word = 1;
4815 int idx_remote_as = 5;
4816 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4817 argv[idx_remote_as]->arg);
4818 }
4819
4820 DEFUN (neighbor_peer_group,
4821 neighbor_peer_group_cmd,
4822 "neighbor WORD peer-group",
4823 NEIGHBOR_STR
4824 "Interface name or neighbor tag\n"
4825 "Configure peer-group\n")
4826 {
4827 VTY_DECLVAR_CONTEXT(bgp, bgp);
4828 int idx_word = 1;
4829 struct peer *peer;
4830 struct peer_group *group;
4831
4832 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4833 if (peer) {
4834 vty_out(vty, "%% Name conflict with interface: \n");
4835 return CMD_WARNING_CONFIG_FAILED;
4836 }
4837
4838 group = peer_group_get(bgp, argv[idx_word]->arg);
4839 if (!group) {
4840 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4841 return CMD_WARNING_CONFIG_FAILED;
4842 }
4843
4844 return CMD_SUCCESS;
4845 }
4846
4847 DEFUN (no_neighbor,
4848 no_neighbor_cmd,
4849 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4850 NO_STR
4851 NEIGHBOR_STR
4852 NEIGHBOR_ADDR_STR2
4853 "Specify a BGP neighbor\n"
4854 AS_STR
4855 "Internal BGP peer\n"
4856 "External BGP peer\n")
4857 {
4858 VTY_DECLVAR_CONTEXT(bgp, bgp);
4859 int idx_peer = 2;
4860 int ret;
4861 union sockunion su;
4862 struct peer_group *group;
4863 struct peer *peer;
4864 struct peer *other;
4865
4866 ret = str2sockunion(argv[idx_peer]->arg, &su);
4867 if (ret < 0) {
4868 /* look up for neighbor by interface name config. */
4869 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4870 if (peer) {
4871 /* Request zebra to terminate IPv6 RAs on this
4872 * interface. */
4873 if (peer->ifp)
4874 bgp_zebra_terminate_radv(peer->bgp, peer);
4875 peer_notify_unconfig(peer);
4876 peer_delete(peer);
4877 return CMD_SUCCESS;
4878 }
4879
4880 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4881 if (group) {
4882 peer_group_notify_unconfig(group);
4883 peer_group_delete(group);
4884 } else {
4885 vty_out(vty, "%% Create the peer-group first\n");
4886 return CMD_WARNING_CONFIG_FAILED;
4887 }
4888 } else {
4889 peer = peer_lookup(bgp, &su);
4890 if (peer) {
4891 if (peer_dynamic_neighbor(peer)) {
4892 vty_out(vty,
4893 "%% Operation not allowed on a dynamic neighbor\n");
4894 return CMD_WARNING_CONFIG_FAILED;
4895 }
4896
4897 other = peer->doppelganger;
4898
4899 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4900 bgp_zebra_terminate_radv(peer->bgp, peer);
4901
4902 peer_notify_unconfig(peer);
4903 peer_delete(peer);
4904 if (other && other->status != Deleted) {
4905 peer_notify_unconfig(other);
4906 peer_delete(other);
4907 }
4908 }
4909 }
4910
4911 return CMD_SUCCESS;
4912 }
4913
4914 DEFUN (no_neighbor_interface_config,
4915 no_neighbor_interface_config_cmd,
4916 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4917 NO_STR
4918 NEIGHBOR_STR
4919 "Interface name\n"
4920 "Configure BGP on interface\n"
4921 "Enable BGP with v6 link-local only\n"
4922 "Member of the peer-group\n"
4923 "Peer-group name\n"
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_word = 2;
4931 struct peer *peer;
4932
4933 /* look up for neighbor by interface name config. */
4934 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4935 if (peer) {
4936 /* Request zebra to terminate IPv6 RAs on this interface. */
4937 if (peer->ifp)
4938 bgp_zebra_terminate_radv(peer->bgp, peer);
4939 peer_notify_unconfig(peer);
4940 peer_delete(peer);
4941 } else {
4942 vty_out(vty, "%% Create the bgp interface first\n");
4943 return CMD_WARNING_CONFIG_FAILED;
4944 }
4945 return CMD_SUCCESS;
4946 }
4947
4948 DEFUN (no_neighbor_peer_group,
4949 no_neighbor_peer_group_cmd,
4950 "no neighbor WORD peer-group",
4951 NO_STR
4952 NEIGHBOR_STR
4953 "Neighbor tag\n"
4954 "Configure peer-group\n")
4955 {
4956 VTY_DECLVAR_CONTEXT(bgp, bgp);
4957 int idx_word = 2;
4958 struct peer_group *group;
4959
4960 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4961 if (group) {
4962 peer_group_notify_unconfig(group);
4963 peer_group_delete(group);
4964 } else {
4965 vty_out(vty, "%% Create the peer-group first\n");
4966 return CMD_WARNING_CONFIG_FAILED;
4967 }
4968 return CMD_SUCCESS;
4969 }
4970
4971 DEFUN (no_neighbor_interface_peer_group_remote_as,
4972 no_neighbor_interface_peer_group_remote_as_cmd,
4973 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4974 NO_STR
4975 NEIGHBOR_STR
4976 "Interface name or neighbor tag\n"
4977 "Specify a BGP neighbor\n"
4978 AS_STR
4979 "Internal BGP peer\n"
4980 "External BGP peer\n")
4981 {
4982 VTY_DECLVAR_CONTEXT(bgp, bgp);
4983 int idx_word = 2;
4984 struct peer_group *group;
4985 struct peer *peer;
4986
4987 /* look up for neighbor by interface name config. */
4988 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4989 if (peer) {
4990 peer_as_change(peer, 0, AS_UNSPECIFIED);
4991 return CMD_SUCCESS;
4992 }
4993
4994 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4995 if (group)
4996 peer_group_remote_as_delete(group);
4997 else {
4998 vty_out(vty, "%% Create the peer-group or interface first\n");
4999 return CMD_WARNING_CONFIG_FAILED;
5000 }
5001 return CMD_SUCCESS;
5002 }
5003
5004 DEFUN (neighbor_local_as,
5005 neighbor_local_as_cmd,
5006 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR2
5009 "Specify a local-as number\n"
5010 "AS number used as local AS\n")
5011 {
5012 int idx_peer = 1;
5013 int idx_number = 3;
5014 struct peer *peer;
5015 int ret;
5016 as_t as;
5017
5018 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 as = strtoul(argv[idx_number]->arg, NULL, 10);
5023 ret = peer_local_as_set(peer, as, 0, 0);
5024 return bgp_vty_return(vty, ret);
5025 }
5026
5027 DEFUN (neighbor_local_as_no_prepend,
5028 neighbor_local_as_no_prepend_cmd,
5029 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
5030 NEIGHBOR_STR
5031 NEIGHBOR_ADDR_STR2
5032 "Specify a local-as number\n"
5033 "AS number used as local AS\n"
5034 "Do not prepend local-as to updates from ebgp peers\n")
5035 {
5036 int idx_peer = 1;
5037 int idx_number = 3;
5038 struct peer *peer;
5039 int ret;
5040 as_t as;
5041
5042 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5043 if (!peer)
5044 return CMD_WARNING_CONFIG_FAILED;
5045
5046 as = strtoul(argv[idx_number]->arg, NULL, 10);
5047 ret = peer_local_as_set(peer, as, 1, 0);
5048 return bgp_vty_return(vty, ret);
5049 }
5050
5051 DEFUN (neighbor_local_as_no_prepend_replace_as,
5052 neighbor_local_as_no_prepend_replace_as_cmd,
5053 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
5054 NEIGHBOR_STR
5055 NEIGHBOR_ADDR_STR2
5056 "Specify a local-as number\n"
5057 "AS number used as local AS\n"
5058 "Do not prepend local-as to updates from ebgp peers\n"
5059 "Do not prepend local-as to updates from ibgp peers\n")
5060 {
5061 int idx_peer = 1;
5062 int idx_number = 3;
5063 struct peer *peer;
5064 int ret;
5065 as_t as;
5066
5067 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5068 if (!peer)
5069 return CMD_WARNING_CONFIG_FAILED;
5070
5071 as = strtoul(argv[idx_number]->arg, NULL, 10);
5072 ret = peer_local_as_set(peer, as, 1, 1);
5073 return bgp_vty_return(vty, ret);
5074 }
5075
5076 DEFUN (no_neighbor_local_as,
5077 no_neighbor_local_as_cmd,
5078 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5079 NO_STR
5080 NEIGHBOR_STR
5081 NEIGHBOR_ADDR_STR2
5082 "Specify a local-as number\n"
5083 "AS number used as local AS\n"
5084 "Do not prepend local-as to updates from ebgp peers\n"
5085 "Do not prepend local-as to updates from ibgp peers\n")
5086 {
5087 int idx_peer = 2;
5088 struct peer *peer;
5089 int ret;
5090
5091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5092 if (!peer)
5093 return CMD_WARNING_CONFIG_FAILED;
5094
5095 ret = peer_local_as_unset(peer);
5096 return bgp_vty_return(vty, ret);
5097 }
5098
5099
5100 DEFUN (neighbor_solo,
5101 neighbor_solo_cmd,
5102 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5103 NEIGHBOR_STR
5104 NEIGHBOR_ADDR_STR2
5105 "Solo peer - part of its own update group\n")
5106 {
5107 int idx_peer = 1;
5108 struct peer *peer;
5109 int ret;
5110
5111 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5112 if (!peer)
5113 return CMD_WARNING_CONFIG_FAILED;
5114
5115 ret = update_group_adjust_soloness(peer, 1);
5116 return bgp_vty_return(vty, ret);
5117 }
5118
5119 DEFUN (no_neighbor_solo,
5120 no_neighbor_solo_cmd,
5121 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5122 NO_STR
5123 NEIGHBOR_STR
5124 NEIGHBOR_ADDR_STR2
5125 "Solo peer - part of its own update group\n")
5126 {
5127 int idx_peer = 2;
5128 struct peer *peer;
5129 int ret;
5130
5131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5132 if (!peer)
5133 return CMD_WARNING_CONFIG_FAILED;
5134
5135 ret = update_group_adjust_soloness(peer, 0);
5136 return bgp_vty_return(vty, ret);
5137 }
5138
5139 DEFUN (neighbor_password,
5140 neighbor_password_cmd,
5141 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5142 NEIGHBOR_STR
5143 NEIGHBOR_ADDR_STR2
5144 "Set a password\n"
5145 "The password\n")
5146 {
5147 int idx_peer = 1;
5148 int idx_line = 3;
5149 struct peer *peer;
5150 int ret;
5151
5152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5153 if (!peer)
5154 return CMD_WARNING_CONFIG_FAILED;
5155
5156 ret = peer_password_set(peer, argv[idx_line]->arg);
5157 return bgp_vty_return(vty, ret);
5158 }
5159
5160 DEFUN (no_neighbor_password,
5161 no_neighbor_password_cmd,
5162 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5163 NO_STR
5164 NEIGHBOR_STR
5165 NEIGHBOR_ADDR_STR2
5166 "Set a password\n"
5167 "The password\n")
5168 {
5169 int idx_peer = 2;
5170 struct peer *peer;
5171 int ret;
5172
5173 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5174 if (!peer)
5175 return CMD_WARNING_CONFIG_FAILED;
5176
5177 ret = peer_password_unset(peer);
5178 return bgp_vty_return(vty, ret);
5179 }
5180
5181 DEFUN (neighbor_activate,
5182 neighbor_activate_cmd,
5183 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5184 NEIGHBOR_STR
5185 NEIGHBOR_ADDR_STR2
5186 "Enable the Address Family for this Neighbor\n")
5187 {
5188 int idx_peer = 1;
5189 int ret;
5190 struct peer *peer;
5191
5192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5193 if (!peer)
5194 return CMD_WARNING_CONFIG_FAILED;
5195
5196 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5197 return bgp_vty_return(vty, ret);
5198 }
5199
5200 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5201 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5202 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5203 "Enable the Address Family for this Neighbor\n")
5204
5205 DEFUN (no_neighbor_activate,
5206 no_neighbor_activate_cmd,
5207 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5208 NO_STR
5209 NEIGHBOR_STR
5210 NEIGHBOR_ADDR_STR2
5211 "Enable the Address Family for this Neighbor\n")
5212 {
5213 int idx_peer = 2;
5214 int ret;
5215 struct peer *peer;
5216
5217 /* Lookup peer. */
5218 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5219 if (!peer)
5220 return CMD_WARNING_CONFIG_FAILED;
5221
5222 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5223 return bgp_vty_return(vty, ret);
5224 }
5225
5226 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5227 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5228 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5229 "Enable the Address Family for this Neighbor\n")
5230
5231 DEFUN (neighbor_set_peer_group,
5232 neighbor_set_peer_group_cmd,
5233 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5234 NEIGHBOR_STR
5235 NEIGHBOR_ADDR_STR2
5236 "Member of the peer-group\n"
5237 "Peer-group name\n")
5238 {
5239 VTY_DECLVAR_CONTEXT(bgp, bgp);
5240 int idx_peer = 1;
5241 int idx_word = 3;
5242 int ret;
5243 as_t as;
5244 union sockunion su;
5245 struct peer *peer;
5246 struct peer_group *group;
5247
5248 ret = str2sockunion(argv[idx_peer]->arg, &su);
5249 if (ret < 0) {
5250 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5251 if (!peer) {
5252 vty_out(vty, "%% Malformed address or name: %s\n",
5253 argv[idx_peer]->arg);
5254 return CMD_WARNING_CONFIG_FAILED;
5255 }
5256 } else {
5257 if (peer_address_self_check(bgp, &su)) {
5258 vty_out(vty,
5259 "%% Can not configure the local system as neighbor\n");
5260 return CMD_WARNING_CONFIG_FAILED;
5261 }
5262
5263 /* Disallow for dynamic neighbor. */
5264 peer = peer_lookup(bgp, &su);
5265 if (peer && peer_dynamic_neighbor(peer)) {
5266 vty_out(vty,
5267 "%% Operation not allowed on a dynamic neighbor\n");
5268 return CMD_WARNING_CONFIG_FAILED;
5269 }
5270 }
5271
5272 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5273 if (!group) {
5274 vty_out(vty, "%% Configure the peer-group first\n");
5275 return CMD_WARNING_CONFIG_FAILED;
5276 }
5277
5278 ret = peer_group_bind(bgp, &su, peer, group, &as);
5279
5280 return bgp_vty_return(vty, ret);
5281 }
5282
5283 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5284 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5285 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5286 "Member of the peer-group\n"
5287 "Peer-group name\n")
5288
5289 DEFUN (no_neighbor_set_peer_group,
5290 no_neighbor_set_peer_group_cmd,
5291 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5292 NO_STR
5293 NEIGHBOR_STR
5294 NEIGHBOR_ADDR_STR2
5295 "Member of the peer-group\n"
5296 "Peer-group name\n")
5297 {
5298 VTY_DECLVAR_CONTEXT(bgp, bgp);
5299 int idx_peer = 2;
5300 int idx_word = 4;
5301 int ret;
5302 struct peer *peer;
5303 struct peer_group *group;
5304
5305 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5306 if (!peer)
5307 return CMD_WARNING_CONFIG_FAILED;
5308
5309 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5310 if (!group) {
5311 vty_out(vty, "%% Configure the peer-group first\n");
5312 return CMD_WARNING_CONFIG_FAILED;
5313 }
5314
5315 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5316 bgp_zebra_terminate_radv(peer->bgp, peer);
5317
5318 peer_notify_unconfig(peer);
5319 ret = peer_delete(peer);
5320
5321 return bgp_vty_return(vty, ret);
5322 }
5323
5324 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5325 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5326 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5327 "Member of the peer-group\n"
5328 "Peer-group name\n")
5329
5330 /* neighbor passive. */
5331 DEFUN (neighbor_passive,
5332 neighbor_passive_cmd,
5333 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5334 NEIGHBOR_STR
5335 NEIGHBOR_ADDR_STR2
5336 "Don't send open messages to this neighbor\n")
5337 {
5338 int idx_peer = 1;
5339 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5340 }
5341
5342 DEFUN (no_neighbor_passive,
5343 no_neighbor_passive_cmd,
5344 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5345 NO_STR
5346 NEIGHBOR_STR
5347 NEIGHBOR_ADDR_STR2
5348 "Don't send open messages to this neighbor\n")
5349 {
5350 int idx_peer = 2;
5351 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5352 }
5353
5354 /* neighbor shutdown. */
5355 DEFUN (neighbor_shutdown_msg,
5356 neighbor_shutdown_msg_cmd,
5357 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5358 NEIGHBOR_STR
5359 NEIGHBOR_ADDR_STR2
5360 "Administratively shut down this neighbor\n"
5361 "Add a shutdown message (RFC 8203)\n"
5362 "Shutdown message\n")
5363 {
5364 int idx_peer = 1;
5365
5366 if (argc >= 5) {
5367 struct peer *peer =
5368 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5369 char *message;
5370
5371 if (!peer)
5372 return CMD_WARNING_CONFIG_FAILED;
5373 message = argv_concat(argv, argc, 4);
5374 peer_tx_shutdown_message_set(peer, message);
5375 XFREE(MTYPE_TMP, message);
5376 }
5377
5378 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5379 }
5380
5381 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5382 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5383 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5384 "Administratively shut down this neighbor\n")
5385
5386 DEFUN (no_neighbor_shutdown_msg,
5387 no_neighbor_shutdown_msg_cmd,
5388 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5389 NO_STR
5390 NEIGHBOR_STR
5391 NEIGHBOR_ADDR_STR2
5392 "Administratively shut down this neighbor\n"
5393 "Remove a shutdown message (RFC 8203)\n"
5394 "Shutdown message\n")
5395 {
5396 int idx_peer = 2;
5397
5398 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5399 PEER_FLAG_SHUTDOWN);
5400 }
5401
5402 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5403 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5404 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5405 "Administratively shut down this neighbor\n")
5406
5407 DEFUN(neighbor_shutdown_rtt,
5408 neighbor_shutdown_rtt_cmd,
5409 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5410 NEIGHBOR_STR
5411 NEIGHBOR_ADDR_STR2
5412 "Administratively shut down this neighbor\n"
5413 "Shutdown if round-trip-time is higher than expected\n"
5414 "Round-trip-time in milliseconds\n"
5415 "Specify the number of keepalives before shutdown\n"
5416 "The number of keepalives with higher RTT to shutdown\n")
5417 {
5418 int idx_peer = 1;
5419 int idx_rtt = 4;
5420 int idx_count = 0;
5421 struct peer *peer;
5422
5423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5424
5425 if (!peer)
5426 return CMD_WARNING_CONFIG_FAILED;
5427
5428 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5429
5430 if (argv_find(argv, argc, "count", &idx_count))
5431 peer->rtt_keepalive_conf =
5432 strtol(argv[idx_count + 1]->arg, NULL, 10);
5433
5434 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5435 PEER_FLAG_RTT_SHUTDOWN);
5436 }
5437
5438 DEFUN(no_neighbor_shutdown_rtt,
5439 no_neighbor_shutdown_rtt_cmd,
5440 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5441 NO_STR
5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Administratively shut down this neighbor\n"
5445 "Shutdown if round-trip-time is higher than expected\n"
5446 "Round-trip-time in milliseconds\n"
5447 "Specify the number of keepalives before shutdown\n"
5448 "The number of keepalives with higher RTT to shutdown\n")
5449 {
5450 int idx_peer = 2;
5451 struct peer *peer;
5452
5453 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5454
5455 if (!peer)
5456 return CMD_WARNING_CONFIG_FAILED;
5457
5458 peer->rtt_expected = 0;
5459 peer->rtt_keepalive_conf = 1;
5460
5461 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5462 PEER_FLAG_RTT_SHUTDOWN);
5463 }
5464
5465 /* neighbor capability dynamic. */
5466 DEFUN (neighbor_capability_dynamic,
5467 neighbor_capability_dynamic_cmd,
5468 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5469 NEIGHBOR_STR
5470 NEIGHBOR_ADDR_STR2
5471 "Advertise capability to the peer\n"
5472 "Advertise dynamic capability to this neighbor\n")
5473 {
5474 int idx_peer = 1;
5475 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5476 PEER_FLAG_DYNAMIC_CAPABILITY);
5477 }
5478
5479 DEFUN (no_neighbor_capability_dynamic,
5480 no_neighbor_capability_dynamic_cmd,
5481 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5482 NO_STR
5483 NEIGHBOR_STR
5484 NEIGHBOR_ADDR_STR2
5485 "Advertise capability to the peer\n"
5486 "Advertise dynamic capability to this neighbor\n")
5487 {
5488 int idx_peer = 2;
5489 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5490 PEER_FLAG_DYNAMIC_CAPABILITY);
5491 }
5492
5493 /* neighbor dont-capability-negotiate */
5494 DEFUN (neighbor_dont_capability_negotiate,
5495 neighbor_dont_capability_negotiate_cmd,
5496 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5497 NEIGHBOR_STR
5498 NEIGHBOR_ADDR_STR2
5499 "Do not perform capability negotiation\n")
5500 {
5501 int idx_peer = 1;
5502 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5503 PEER_FLAG_DONT_CAPABILITY);
5504 }
5505
5506 DEFUN (no_neighbor_dont_capability_negotiate,
5507 no_neighbor_dont_capability_negotiate_cmd,
5508 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5509 NO_STR
5510 NEIGHBOR_STR
5511 NEIGHBOR_ADDR_STR2
5512 "Do not perform capability negotiation\n")
5513 {
5514 int idx_peer = 2;
5515 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5516 PEER_FLAG_DONT_CAPABILITY);
5517 }
5518
5519 /* neighbor capability extended next hop encoding */
5520 DEFUN (neighbor_capability_enhe,
5521 neighbor_capability_enhe_cmd,
5522 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5523 NEIGHBOR_STR
5524 NEIGHBOR_ADDR_STR2
5525 "Advertise capability to the peer\n"
5526 "Advertise extended next-hop capability to the peer\n")
5527 {
5528 int idx_peer = 1;
5529 struct peer *peer;
5530
5531 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5532 if (peer && peer->conf_if)
5533 return CMD_SUCCESS;
5534
5535 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5536 PEER_FLAG_CAPABILITY_ENHE);
5537 }
5538
5539 DEFUN (no_neighbor_capability_enhe,
5540 no_neighbor_capability_enhe_cmd,
5541 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5542 NO_STR
5543 NEIGHBOR_STR
5544 NEIGHBOR_ADDR_STR2
5545 "Advertise capability to the peer\n"
5546 "Advertise extended next-hop capability to the peer\n")
5547 {
5548 int idx_peer = 2;
5549 struct peer *peer;
5550
5551 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5552 if (peer && peer->conf_if) {
5553 vty_out(vty,
5554 "Peer %s cannot have capability extended-nexthop turned off\n",
5555 argv[idx_peer]->arg);
5556 return CMD_WARNING_CONFIG_FAILED;
5557 }
5558
5559 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5560 PEER_FLAG_CAPABILITY_ENHE);
5561 }
5562
5563 /* neighbor capability software-version */
5564 DEFPY(neighbor_capability_software_version,
5565 neighbor_capability_software_version_cmd,
5566 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor capability software-version",
5567 NO_STR
5568 NEIGHBOR_STR
5569 NEIGHBOR_ADDR_STR2
5570 "Advertise capability to the peer\n"
5571 "Advertise Software Version capability to the peer\n")
5572 {
5573 struct peer *peer;
5574
5575 peer = peer_and_group_lookup_vty(vty, neighbor);
5576 if (peer && peer->conf_if)
5577 return CMD_SUCCESS;
5578
5579 if (no)
5580 return peer_flag_unset_vty(vty, neighbor,
5581 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5582 else
5583 return peer_flag_set_vty(vty, neighbor,
5584 PEER_FLAG_CAPABILITY_SOFT_VERSION);
5585 }
5586
5587 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5588 afi_t afi, safi_t safi, uint32_t flag,
5589 int set)
5590 {
5591 int ret;
5592 struct peer *peer;
5593
5594 peer = peer_and_group_lookup_vty(vty, peer_str);
5595 if (!peer)
5596 return CMD_WARNING_CONFIG_FAILED;
5597
5598 if (set)
5599 ret = peer_af_flag_set(peer, afi, safi, flag);
5600 else
5601 ret = peer_af_flag_unset(peer, afi, safi, flag);
5602
5603 return bgp_vty_return(vty, ret);
5604 }
5605
5606 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5607 afi_t afi, safi_t safi, uint32_t flag)
5608 {
5609 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5610 }
5611
5612 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5613 afi_t afi, safi_t safi, uint32_t flag)
5614 {
5615 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5616 }
5617
5618 /* neighbor capability orf prefix-list. */
5619 DEFUN (neighbor_capability_orf_prefix,
5620 neighbor_capability_orf_prefix_cmd,
5621 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5622 NEIGHBOR_STR
5623 NEIGHBOR_ADDR_STR2
5624 "Advertise capability to the peer\n"
5625 "Advertise ORF capability to the peer\n"
5626 "Advertise prefixlist ORF capability to this neighbor\n"
5627 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5628 "Capability to RECEIVE the ORF from this neighbor\n"
5629 "Capability to SEND the ORF to this neighbor\n")
5630 {
5631 int idx_send_recv = 5;
5632 char *peer_str = argv[1]->arg;
5633 struct peer *peer;
5634 afi_t afi = bgp_node_afi(vty);
5635 safi_t safi = bgp_node_safi(vty);
5636
5637 peer = peer_and_group_lookup_vty(vty, peer_str);
5638 if (!peer)
5639 return CMD_WARNING_CONFIG_FAILED;
5640
5641 if (strmatch(argv[idx_send_recv]->text, "send"))
5642 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5643 PEER_FLAG_ORF_PREFIX_SM);
5644
5645 if (strmatch(argv[idx_send_recv]->text, "receive"))
5646 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5647 PEER_FLAG_ORF_PREFIX_RM);
5648
5649 if (strmatch(argv[idx_send_recv]->text, "both"))
5650 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5651 PEER_FLAG_ORF_PREFIX_SM)
5652 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5653 PEER_FLAG_ORF_PREFIX_RM);
5654
5655 return CMD_WARNING_CONFIG_FAILED;
5656 }
5657
5658 ALIAS_HIDDEN(
5659 neighbor_capability_orf_prefix,
5660 neighbor_capability_orf_prefix_hidden_cmd,
5661 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5662 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5663 "Advertise capability to the peer\n"
5664 "Advertise ORF capability to the peer\n"
5665 "Advertise prefixlist ORF capability to this neighbor\n"
5666 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5667 "Capability to RECEIVE the ORF from this neighbor\n"
5668 "Capability to SEND the ORF to this neighbor\n")
5669
5670 DEFUN (no_neighbor_capability_orf_prefix,
5671 no_neighbor_capability_orf_prefix_cmd,
5672 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5673 NO_STR
5674 NEIGHBOR_STR
5675 NEIGHBOR_ADDR_STR2
5676 "Advertise capability to the peer\n"
5677 "Advertise ORF capability to the peer\n"
5678 "Advertise prefixlist ORF capability to this neighbor\n"
5679 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5680 "Capability to RECEIVE the ORF from this neighbor\n"
5681 "Capability to SEND the ORF to this neighbor\n")
5682 {
5683 int idx_send_recv = 6;
5684 char *peer_str = argv[2]->arg;
5685 struct peer *peer;
5686 afi_t afi = bgp_node_afi(vty);
5687 safi_t safi = bgp_node_safi(vty);
5688
5689 peer = peer_and_group_lookup_vty(vty, peer_str);
5690 if (!peer)
5691 return CMD_WARNING_CONFIG_FAILED;
5692
5693 if (strmatch(argv[idx_send_recv]->text, "send"))
5694 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5695 PEER_FLAG_ORF_PREFIX_SM);
5696
5697 if (strmatch(argv[idx_send_recv]->text, "receive"))
5698 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5699 PEER_FLAG_ORF_PREFIX_RM);
5700
5701 if (strmatch(argv[idx_send_recv]->text, "both"))
5702 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5703 PEER_FLAG_ORF_PREFIX_SM)
5704 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5705 PEER_FLAG_ORF_PREFIX_RM);
5706
5707 return CMD_WARNING_CONFIG_FAILED;
5708 }
5709
5710 ALIAS_HIDDEN(
5711 no_neighbor_capability_orf_prefix,
5712 no_neighbor_capability_orf_prefix_hidden_cmd,
5713 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5714 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Advertise capability to the peer\n"
5716 "Advertise ORF capability to the peer\n"
5717 "Advertise prefixlist ORF capability to this neighbor\n"
5718 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5719 "Capability to RECEIVE the ORF from this neighbor\n"
5720 "Capability to SEND the ORF to this neighbor\n")
5721
5722 /* neighbor next-hop-self. */
5723 DEFUN (neighbor_nexthop_self,
5724 neighbor_nexthop_self_cmd,
5725 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5726 NEIGHBOR_STR
5727 NEIGHBOR_ADDR_STR2
5728 "Disable the next hop calculation for this neighbor\n")
5729 {
5730 int idx_peer = 1;
5731 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5732 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5733 }
5734
5735 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5736 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Disable the next hop calculation for this neighbor\n")
5739
5740 /* neighbor next-hop-self. */
5741 DEFUN (neighbor_nexthop_self_force,
5742 neighbor_nexthop_self_force_cmd,
5743 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5744 NEIGHBOR_STR
5745 NEIGHBOR_ADDR_STR2
5746 "Disable the next hop calculation for this neighbor\n"
5747 "Set the next hop to self for reflected routes\n")
5748 {
5749 int idx_peer = 1;
5750 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5751 bgp_node_safi(vty),
5752 PEER_FLAG_FORCE_NEXTHOP_SELF);
5753 }
5754
5755 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5756 neighbor_nexthop_self_force_hidden_cmd,
5757 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5758 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5759 "Disable the next hop calculation for this neighbor\n"
5760 "Set the next hop to self for reflected routes\n")
5761
5762 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5763 neighbor_nexthop_self_all_hidden_cmd,
5764 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5766 "Disable the next hop calculation for this neighbor\n"
5767 "Set the next hop to self for reflected routes\n")
5768
5769 DEFUN (no_neighbor_nexthop_self,
5770 no_neighbor_nexthop_self_cmd,
5771 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5772 NO_STR
5773 NEIGHBOR_STR
5774 NEIGHBOR_ADDR_STR2
5775 "Disable the next hop calculation for this neighbor\n")
5776 {
5777 int idx_peer = 2;
5778 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5779 bgp_node_afi(vty), bgp_node_safi(vty),
5780 PEER_FLAG_NEXTHOP_SELF);
5781 }
5782
5783 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5784 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5785 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5786 "Disable the next hop calculation for this neighbor\n")
5787
5788 DEFUN (no_neighbor_nexthop_self_force,
5789 no_neighbor_nexthop_self_force_cmd,
5790 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5791 NO_STR
5792 NEIGHBOR_STR
5793 NEIGHBOR_ADDR_STR2
5794 "Disable the next hop calculation for this neighbor\n"
5795 "Set the next hop to self for reflected routes\n")
5796 {
5797 int idx_peer = 2;
5798 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5799 bgp_node_afi(vty), bgp_node_safi(vty),
5800 PEER_FLAG_FORCE_NEXTHOP_SELF);
5801 }
5802
5803 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5804 no_neighbor_nexthop_self_force_hidden_cmd,
5805 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5806 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5807 "Disable the next hop calculation for this neighbor\n"
5808 "Set the next hop to self for reflected routes\n")
5809
5810 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5811 no_neighbor_nexthop_self_all_hidden_cmd,
5812 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5813 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5814 "Disable the next hop calculation for this neighbor\n"
5815 "Set the next hop to self for reflected routes\n")
5816
5817 /* neighbor as-override */
5818 DEFUN (neighbor_as_override,
5819 neighbor_as_override_cmd,
5820 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5821 NEIGHBOR_STR
5822 NEIGHBOR_ADDR_STR2
5823 "Override ASNs in outbound updates if aspath equals remote-as\n")
5824 {
5825 int idx_peer = 1;
5826 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5827 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5828 }
5829
5830 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5831 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5832 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5833 "Override ASNs in outbound updates if aspath equals remote-as\n")
5834
5835 DEFUN (no_neighbor_as_override,
5836 no_neighbor_as_override_cmd,
5837 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5838 NO_STR
5839 NEIGHBOR_STR
5840 NEIGHBOR_ADDR_STR2
5841 "Override ASNs in outbound updates if aspath equals remote-as\n")
5842 {
5843 int idx_peer = 2;
5844 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5845 bgp_node_afi(vty), bgp_node_safi(vty),
5846 PEER_FLAG_AS_OVERRIDE);
5847 }
5848
5849 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5850 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5852 "Override ASNs in outbound updates if aspath equals remote-as\n")
5853
5854 /* neighbor remove-private-AS. */
5855 DEFUN (neighbor_remove_private_as,
5856 neighbor_remove_private_as_cmd,
5857 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5858 NEIGHBOR_STR
5859 NEIGHBOR_ADDR_STR2
5860 "Remove private ASNs in outbound updates\n")
5861 {
5862 int idx_peer = 1;
5863 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5864 bgp_node_safi(vty),
5865 PEER_FLAG_REMOVE_PRIVATE_AS);
5866 }
5867
5868 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5871 "Remove private ASNs in outbound updates\n")
5872
5873 DEFUN (neighbor_remove_private_as_all,
5874 neighbor_remove_private_as_all_cmd,
5875 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5876 NEIGHBOR_STR
5877 NEIGHBOR_ADDR_STR2
5878 "Remove private ASNs in outbound updates\n"
5879 "Apply to all AS numbers\n")
5880 {
5881 int idx_peer = 1;
5882 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5883 bgp_node_safi(vty),
5884 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5885 }
5886
5887 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5888 neighbor_remove_private_as_all_hidden_cmd,
5889 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5891 "Remove private ASNs in outbound updates\n"
5892 "Apply to all AS numbers\n")
5893
5894 DEFUN (neighbor_remove_private_as_replace_as,
5895 neighbor_remove_private_as_replace_as_cmd,
5896 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5897 NEIGHBOR_STR
5898 NEIGHBOR_ADDR_STR2
5899 "Remove private ASNs in outbound updates\n"
5900 "Replace private ASNs with our ASN in outbound updates\n")
5901 {
5902 int idx_peer = 1;
5903 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5904 bgp_node_safi(vty),
5905 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5906 }
5907
5908 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5909 neighbor_remove_private_as_replace_as_hidden_cmd,
5910 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5912 "Remove private ASNs in outbound updates\n"
5913 "Replace private ASNs with our ASN in outbound updates\n")
5914
5915 DEFUN (neighbor_remove_private_as_all_replace_as,
5916 neighbor_remove_private_as_all_replace_as_cmd,
5917 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5918 NEIGHBOR_STR
5919 NEIGHBOR_ADDR_STR2
5920 "Remove private ASNs in outbound updates\n"
5921 "Apply to all AS numbers\n"
5922 "Replace private ASNs with our ASN in outbound updates\n")
5923 {
5924 int idx_peer = 1;
5925 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5926 bgp_node_safi(vty),
5927 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5928 }
5929
5930 ALIAS_HIDDEN(
5931 neighbor_remove_private_as_all_replace_as,
5932 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5933 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5935 "Remove private ASNs in outbound updates\n"
5936 "Apply to all AS numbers\n"
5937 "Replace private ASNs with our ASN in outbound updates\n")
5938
5939 DEFUN (no_neighbor_remove_private_as,
5940 no_neighbor_remove_private_as_cmd,
5941 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5942 NO_STR
5943 NEIGHBOR_STR
5944 NEIGHBOR_ADDR_STR2
5945 "Remove private ASNs in outbound updates\n")
5946 {
5947 int idx_peer = 2;
5948 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5949 bgp_node_afi(vty), bgp_node_safi(vty),
5950 PEER_FLAG_REMOVE_PRIVATE_AS);
5951 }
5952
5953 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5954 no_neighbor_remove_private_as_hidden_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n")
5958
5959 DEFUN (no_neighbor_remove_private_as_all,
5960 no_neighbor_remove_private_as_all_cmd,
5961 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5962 NO_STR
5963 NEIGHBOR_STR
5964 NEIGHBOR_ADDR_STR2
5965 "Remove private ASNs in outbound updates\n"
5966 "Apply to all AS numbers\n")
5967 {
5968 int idx_peer = 2;
5969 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5970 bgp_node_afi(vty), bgp_node_safi(vty),
5971 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5972 }
5973
5974 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5975 no_neighbor_remove_private_as_all_hidden_cmd,
5976 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5977 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5978 "Remove private ASNs in outbound updates\n"
5979 "Apply to all AS numbers\n")
5980
5981 DEFUN (no_neighbor_remove_private_as_replace_as,
5982 no_neighbor_remove_private_as_replace_as_cmd,
5983 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5984 NO_STR
5985 NEIGHBOR_STR
5986 NEIGHBOR_ADDR_STR2
5987 "Remove private ASNs in outbound updates\n"
5988 "Replace private ASNs with our ASN in outbound updates\n")
5989 {
5990 int idx_peer = 2;
5991 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5992 bgp_node_afi(vty), bgp_node_safi(vty),
5993 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5994 }
5995
5996 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5997 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5998 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5999 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6000 "Remove private ASNs in outbound updates\n"
6001 "Replace private ASNs with our ASN in outbound updates\n")
6002
6003 DEFUN (no_neighbor_remove_private_as_all_replace_as,
6004 no_neighbor_remove_private_as_all_replace_as_cmd,
6005 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6006 NO_STR
6007 NEIGHBOR_STR
6008 NEIGHBOR_ADDR_STR2
6009 "Remove private ASNs in outbound updates\n"
6010 "Apply to all AS numbers\n"
6011 "Replace private ASNs with our ASN in outbound updates\n")
6012 {
6013 int idx_peer = 2;
6014 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6015 bgp_node_afi(vty), bgp_node_safi(vty),
6016 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
6017 }
6018
6019 ALIAS_HIDDEN(
6020 no_neighbor_remove_private_as_all_replace_as,
6021 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6022 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6023 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6024 "Remove private ASNs in outbound updates\n"
6025 "Apply to all AS numbers\n"
6026 "Replace private ASNs with our ASN in outbound updates\n")
6027
6028
6029 /* neighbor send-community. */
6030 DEFUN (neighbor_send_community,
6031 neighbor_send_community_cmd,
6032 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "Send Community attribute to this neighbor\n")
6036 {
6037 int idx_peer = 1;
6038
6039 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6040 bgp_node_safi(vty),
6041 PEER_FLAG_SEND_COMMUNITY);
6042 }
6043
6044 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6045 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6046 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6047 "Send Community attribute to this neighbor\n")
6048
6049 DEFUN (no_neighbor_send_community,
6050 no_neighbor_send_community_cmd,
6051 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6052 NO_STR
6053 NEIGHBOR_STR
6054 NEIGHBOR_ADDR_STR2
6055 "Send Community attribute to this neighbor\n")
6056 {
6057 int idx_peer = 2;
6058
6059 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6060 bgp_node_afi(vty), bgp_node_safi(vty),
6061 PEER_FLAG_SEND_COMMUNITY);
6062 }
6063
6064 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6065 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6066 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6067 "Send Community attribute to this neighbor\n")
6068
6069 /* neighbor send-community extended. */
6070 DEFUN (neighbor_send_community_type,
6071 neighbor_send_community_type_cmd,
6072 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6073 NEIGHBOR_STR
6074 NEIGHBOR_ADDR_STR2
6075 "Send Community attribute to this neighbor\n"
6076 "Send Standard and Extended Community attributes\n"
6077 "Send Standard, Large and Extended Community attributes\n"
6078 "Send Extended Community attributes\n"
6079 "Send Standard Community attributes\n"
6080 "Send Large Community attributes\n")
6081 {
6082 const char *type = argv[argc - 1]->text;
6083 char *peer_str = argv[1]->arg;
6084 struct peer *peer;
6085 afi_t afi = bgp_node_afi(vty);
6086 safi_t safi = bgp_node_safi(vty);
6087
6088 peer = peer_and_group_lookup_vty(vty, peer_str);
6089 if (!peer)
6090 return CMD_WARNING_CONFIG_FAILED;
6091
6092 if (strmatch(type, "standard"))
6093 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6094 PEER_FLAG_SEND_COMMUNITY);
6095
6096 if (strmatch(type, "extended"))
6097 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6098 PEER_FLAG_SEND_EXT_COMMUNITY);
6099
6100 if (strmatch(type, "large"))
6101 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6102 PEER_FLAG_SEND_LARGE_COMMUNITY);
6103
6104 if (strmatch(type, "both")) {
6105 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6106 PEER_FLAG_SEND_COMMUNITY)
6107 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6108 PEER_FLAG_SEND_EXT_COMMUNITY);
6109 }
6110 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6111 PEER_FLAG_SEND_COMMUNITY)
6112 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6113 PEER_FLAG_SEND_EXT_COMMUNITY)
6114 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6115 PEER_FLAG_SEND_LARGE_COMMUNITY);
6116 }
6117
6118 ALIAS_HIDDEN(
6119 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6120 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6121 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6122 "Send Community attribute to this neighbor\n"
6123 "Send Standard and Extended Community attributes\n"
6124 "Send Standard, Large and Extended Community attributes\n"
6125 "Send Extended Community attributes\n"
6126 "Send Standard Community attributes\n"
6127 "Send Large Community attributes\n")
6128
6129 DEFUN (no_neighbor_send_community_type,
6130 no_neighbor_send_community_type_cmd,
6131 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6132 NO_STR
6133 NEIGHBOR_STR
6134 NEIGHBOR_ADDR_STR2
6135 "Send Community attribute to this neighbor\n"
6136 "Send Standard and Extended Community attributes\n"
6137 "Send Standard, Large and Extended Community attributes\n"
6138 "Send Extended Community attributes\n"
6139 "Send Standard Community attributes\n"
6140 "Send Large Community attributes\n")
6141 {
6142 const char *type = argv[argc - 1]->text;
6143 char *peer_str = argv[2]->arg;
6144 struct peer *peer;
6145 afi_t afi = bgp_node_afi(vty);
6146 safi_t safi = bgp_node_safi(vty);
6147
6148 peer = peer_and_group_lookup_vty(vty, peer_str);
6149 if (!peer)
6150 return CMD_WARNING_CONFIG_FAILED;
6151
6152 if (strmatch(type, "standard"))
6153 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6154 PEER_FLAG_SEND_COMMUNITY);
6155
6156 if (strmatch(type, "extended"))
6157 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6158 PEER_FLAG_SEND_EXT_COMMUNITY);
6159
6160 if (strmatch(type, "large"))
6161 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6162 PEER_FLAG_SEND_LARGE_COMMUNITY);
6163
6164 if (strmatch(type, "both")) {
6165
6166 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6167 PEER_FLAG_SEND_COMMUNITY)
6168 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6169 PEER_FLAG_SEND_EXT_COMMUNITY);
6170 }
6171
6172 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6173 PEER_FLAG_SEND_COMMUNITY)
6174 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6175 PEER_FLAG_SEND_EXT_COMMUNITY)
6176 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6177 PEER_FLAG_SEND_LARGE_COMMUNITY);
6178 }
6179
6180 ALIAS_HIDDEN(
6181 no_neighbor_send_community_type,
6182 no_neighbor_send_community_type_hidden_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6185 "Send Community attribute to this neighbor\n"
6186 "Send Standard and Extended Community attributes\n"
6187 "Send Standard, Large and Extended Community attributes\n"
6188 "Send Extended Community attributes\n"
6189 "Send Standard Community attributes\n"
6190 "Send Large Community attributes\n")
6191
6192 /* neighbor soft-reconfig. */
6193 DEFUN (neighbor_soft_reconfiguration,
6194 neighbor_soft_reconfiguration_cmd,
6195 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6196 NEIGHBOR_STR
6197 NEIGHBOR_ADDR_STR2
6198 "Per neighbor soft reconfiguration\n"
6199 "Allow inbound soft reconfiguration for this neighbor\n")
6200 {
6201 int idx_peer = 1;
6202 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6203 bgp_node_safi(vty),
6204 PEER_FLAG_SOFT_RECONFIG);
6205 }
6206
6207 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6208 neighbor_soft_reconfiguration_hidden_cmd,
6209 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6210 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6211 "Per neighbor soft reconfiguration\n"
6212 "Allow inbound soft reconfiguration for this neighbor\n")
6213
6214 DEFUN (no_neighbor_soft_reconfiguration,
6215 no_neighbor_soft_reconfiguration_cmd,
6216 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6217 NO_STR
6218 NEIGHBOR_STR
6219 NEIGHBOR_ADDR_STR2
6220 "Per neighbor soft reconfiguration\n"
6221 "Allow inbound soft reconfiguration for this neighbor\n")
6222 {
6223 int idx_peer = 2;
6224 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6225 bgp_node_afi(vty), bgp_node_safi(vty),
6226 PEER_FLAG_SOFT_RECONFIG);
6227 }
6228
6229 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6230 no_neighbor_soft_reconfiguration_hidden_cmd,
6231 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6232 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6233 "Per neighbor soft reconfiguration\n"
6234 "Allow inbound soft reconfiguration for this neighbor\n")
6235
6236 DEFUN (neighbor_route_reflector_client,
6237 neighbor_route_reflector_client_cmd,
6238 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6239 NEIGHBOR_STR
6240 NEIGHBOR_ADDR_STR2
6241 "Configure a neighbor as Route Reflector client\n")
6242 {
6243 int idx_peer = 1;
6244 struct peer *peer;
6245
6246
6247 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6248 if (!peer)
6249 return CMD_WARNING_CONFIG_FAILED;
6250
6251 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6252 bgp_node_safi(vty),
6253 PEER_FLAG_REFLECTOR_CLIENT);
6254 }
6255
6256 ALIAS_HIDDEN(neighbor_route_reflector_client,
6257 neighbor_route_reflector_client_hidden_cmd,
6258 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6259 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6260 "Configure a neighbor as Route Reflector client\n")
6261
6262 DEFUN (no_neighbor_route_reflector_client,
6263 no_neighbor_route_reflector_client_cmd,
6264 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6265 NO_STR
6266 NEIGHBOR_STR
6267 NEIGHBOR_ADDR_STR2
6268 "Configure a neighbor as Route Reflector client\n")
6269 {
6270 int idx_peer = 2;
6271 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6272 bgp_node_afi(vty), bgp_node_safi(vty),
6273 PEER_FLAG_REFLECTOR_CLIENT);
6274 }
6275
6276 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6277 no_neighbor_route_reflector_client_hidden_cmd,
6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6279 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6280 "Configure a neighbor as Route Reflector client\n")
6281
6282 /* neighbor route-server-client. */
6283 DEFUN (neighbor_route_server_client,
6284 neighbor_route_server_client_cmd,
6285 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6286 NEIGHBOR_STR
6287 NEIGHBOR_ADDR_STR2
6288 "Configure a neighbor as Route Server client\n")
6289 {
6290 int idx_peer = 1;
6291 struct peer *peer;
6292
6293 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6294 if (!peer)
6295 return CMD_WARNING_CONFIG_FAILED;
6296 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6297 bgp_node_safi(vty),
6298 PEER_FLAG_RSERVER_CLIENT);
6299 }
6300
6301 ALIAS_HIDDEN(neighbor_route_server_client,
6302 neighbor_route_server_client_hidden_cmd,
6303 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6304 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6305 "Configure a neighbor as Route Server client\n")
6306
6307 DEFUN (no_neighbor_route_server_client,
6308 no_neighbor_route_server_client_cmd,
6309 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6310 NO_STR
6311 NEIGHBOR_STR
6312 NEIGHBOR_ADDR_STR2
6313 "Configure a neighbor as Route Server client\n")
6314 {
6315 int idx_peer = 2;
6316 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6317 bgp_node_afi(vty), bgp_node_safi(vty),
6318 PEER_FLAG_RSERVER_CLIENT);
6319 }
6320
6321 ALIAS_HIDDEN(no_neighbor_route_server_client,
6322 no_neighbor_route_server_client_hidden_cmd,
6323 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6324 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6325 "Configure a neighbor as Route Server client\n")
6326
6327 DEFUN (neighbor_nexthop_local_unchanged,
6328 neighbor_nexthop_local_unchanged_cmd,
6329 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6330 NEIGHBOR_STR
6331 NEIGHBOR_ADDR_STR2
6332 "Configure treatment of outgoing link-local nexthop attribute\n"
6333 "Leave link-local nexthop unchanged for this peer\n")
6334 {
6335 int idx_peer = 1;
6336 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6337 bgp_node_safi(vty),
6338 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6339 }
6340
6341 DEFUN (no_neighbor_nexthop_local_unchanged,
6342 no_neighbor_nexthop_local_unchanged_cmd,
6343 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6344 NO_STR
6345 NEIGHBOR_STR
6346 NEIGHBOR_ADDR_STR2
6347 "Configure treatment of outgoing link-local-nexthop attribute\n"
6348 "Leave link-local nexthop unchanged for this peer\n")
6349 {
6350 int idx_peer = 2;
6351 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6352 bgp_node_afi(vty), bgp_node_safi(vty),
6353 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6354 }
6355
6356 DEFUN (neighbor_attr_unchanged,
6357 neighbor_attr_unchanged_cmd,
6358 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6359 NEIGHBOR_STR
6360 NEIGHBOR_ADDR_STR2
6361 "BGP attribute is propagated unchanged to this neighbor\n"
6362 "As-path attribute\n"
6363 "Nexthop attribute\n"
6364 "Med attribute\n")
6365 {
6366 int idx = 0;
6367 char *peer_str = argv[1]->arg;
6368 struct peer *peer;
6369 bool aspath = false;
6370 bool nexthop = false;
6371 bool med = false;
6372 afi_t afi = bgp_node_afi(vty);
6373 safi_t safi = bgp_node_safi(vty);
6374 int ret = 0;
6375
6376 peer = peer_and_group_lookup_vty(vty, peer_str);
6377 if (!peer)
6378 return CMD_WARNING_CONFIG_FAILED;
6379
6380 if (argv_find(argv, argc, "as-path", &idx))
6381 aspath = true;
6382
6383 idx = 0;
6384 if (argv_find(argv, argc, "next-hop", &idx))
6385 nexthop = true;
6386
6387 idx = 0;
6388 if (argv_find(argv, argc, "med", &idx))
6389 med = true;
6390
6391 /* no flags means all of them! */
6392 if (!aspath && !nexthop && !med) {
6393 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6394 PEER_FLAG_AS_PATH_UNCHANGED);
6395 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6396 PEER_FLAG_NEXTHOP_UNCHANGED);
6397 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6398 PEER_FLAG_MED_UNCHANGED);
6399 } else {
6400 if (!aspath) {
6401 if (peer_af_flag_check(peer, afi, safi,
6402 PEER_FLAG_AS_PATH_UNCHANGED)) {
6403 ret |= peer_af_flag_unset_vty(
6404 vty, peer_str, afi, safi,
6405 PEER_FLAG_AS_PATH_UNCHANGED);
6406 }
6407 } else
6408 ret |= peer_af_flag_set_vty(
6409 vty, peer_str, afi, safi,
6410 PEER_FLAG_AS_PATH_UNCHANGED);
6411
6412 if (!nexthop) {
6413 if (peer_af_flag_check(peer, afi, safi,
6414 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6415 ret |= peer_af_flag_unset_vty(
6416 vty, peer_str, afi, safi,
6417 PEER_FLAG_NEXTHOP_UNCHANGED);
6418 }
6419 } else
6420 ret |= peer_af_flag_set_vty(
6421 vty, peer_str, afi, safi,
6422 PEER_FLAG_NEXTHOP_UNCHANGED);
6423
6424 if (!med) {
6425 if (peer_af_flag_check(peer, afi, safi,
6426 PEER_FLAG_MED_UNCHANGED)) {
6427 ret |= peer_af_flag_unset_vty(
6428 vty, peer_str, afi, safi,
6429 PEER_FLAG_MED_UNCHANGED);
6430 }
6431 } else
6432 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6433 PEER_FLAG_MED_UNCHANGED);
6434 }
6435
6436 return ret;
6437 }
6438
6439 ALIAS_HIDDEN(
6440 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6441 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6443 "BGP attribute is propagated unchanged to this neighbor\n"
6444 "As-path attribute\n"
6445 "Nexthop attribute\n"
6446 "Med attribute\n")
6447
6448 DEFUN (no_neighbor_attr_unchanged,
6449 no_neighbor_attr_unchanged_cmd,
6450 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6451 NO_STR
6452 NEIGHBOR_STR
6453 NEIGHBOR_ADDR_STR2
6454 "BGP attribute is propagated unchanged to this neighbor\n"
6455 "As-path attribute\n"
6456 "Nexthop attribute\n"
6457 "Med attribute\n")
6458 {
6459 int idx = 0;
6460 char *peer_str = argv[2]->arg;
6461 struct peer *peer;
6462 bool aspath = false;
6463 bool nexthop = false;
6464 bool med = false;
6465 afi_t afi = bgp_node_afi(vty);
6466 safi_t safi = bgp_node_safi(vty);
6467 int ret = 0;
6468
6469 peer = peer_and_group_lookup_vty(vty, peer_str);
6470 if (!peer)
6471 return CMD_WARNING_CONFIG_FAILED;
6472
6473 if (argv_find(argv, argc, "as-path", &idx))
6474 aspath = true;
6475
6476 idx = 0;
6477 if (argv_find(argv, argc, "next-hop", &idx))
6478 nexthop = true;
6479
6480 idx = 0;
6481 if (argv_find(argv, argc, "med", &idx))
6482 med = true;
6483
6484 if (!aspath && !nexthop && !med) // no flags means all of them!
6485 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6486 PEER_FLAG_AS_PATH_UNCHANGED)
6487 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6488 PEER_FLAG_NEXTHOP_UNCHANGED)
6489 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6490 PEER_FLAG_MED_UNCHANGED);
6491
6492 if (aspath)
6493 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6494 PEER_FLAG_AS_PATH_UNCHANGED);
6495
6496 if (nexthop)
6497 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6498 PEER_FLAG_NEXTHOP_UNCHANGED);
6499
6500 if (med)
6501 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6502 PEER_FLAG_MED_UNCHANGED);
6503
6504 return ret;
6505 }
6506
6507 ALIAS_HIDDEN(
6508 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6509 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6510 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6511 "BGP attribute is propagated unchanged to this neighbor\n"
6512 "As-path attribute\n"
6513 "Nexthop attribute\n"
6514 "Med attribute\n")
6515
6516 /* EBGP multihop configuration. */
6517 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6518 const char *ttl_str)
6519 {
6520 struct peer *peer;
6521 unsigned int ttl;
6522
6523 peer = peer_and_group_lookup_vty(vty, ip_str);
6524 if (!peer)
6525 return CMD_WARNING_CONFIG_FAILED;
6526
6527 if (peer->conf_if)
6528 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6529
6530 if (!ttl_str)
6531 ttl = MAXTTL;
6532 else
6533 ttl = strtoul(ttl_str, NULL, 10);
6534
6535 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6536 }
6537
6538 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6539 {
6540 struct peer *peer;
6541
6542 peer = peer_and_group_lookup_vty(vty, ip_str);
6543 if (!peer)
6544 return CMD_WARNING_CONFIG_FAILED;
6545
6546 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6547 }
6548
6549 /* neighbor ebgp-multihop. */
6550 DEFUN (neighbor_ebgp_multihop,
6551 neighbor_ebgp_multihop_cmd,
6552 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6553 NEIGHBOR_STR
6554 NEIGHBOR_ADDR_STR2
6555 "Allow EBGP neighbors not on directly connected networks\n")
6556 {
6557 int idx_peer = 1;
6558 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6559 }
6560
6561 DEFUN (neighbor_ebgp_multihop_ttl,
6562 neighbor_ebgp_multihop_ttl_cmd,
6563 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6564 NEIGHBOR_STR
6565 NEIGHBOR_ADDR_STR2
6566 "Allow EBGP neighbors not on directly connected networks\n"
6567 "maximum hop count\n")
6568 {
6569 int idx_peer = 1;
6570 int idx_number = 3;
6571 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6572 argv[idx_number]->arg);
6573 }
6574
6575 DEFUN (no_neighbor_ebgp_multihop,
6576 no_neighbor_ebgp_multihop_cmd,
6577 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6578 NO_STR
6579 NEIGHBOR_STR
6580 NEIGHBOR_ADDR_STR2
6581 "Allow EBGP neighbors not on directly connected networks\n"
6582 "maximum hop count\n")
6583 {
6584 int idx_peer = 2;
6585 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6586 }
6587
6588 DEFPY (neighbor_aigp,
6589 neighbor_aigp_cmd,
6590 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6591 NO_STR
6592 NEIGHBOR_STR
6593 NEIGHBOR_ADDR_STR2
6594 "Enable send and receive of the AIGP attribute per neighbor\n")
6595 {
6596 struct peer *peer;
6597
6598 peer = peer_and_group_lookup_vty(vty, neighbor);
6599 if (!peer)
6600 return CMD_WARNING_CONFIG_FAILED;
6601
6602 if (no)
6603 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6604 else
6605 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6606 }
6607
6608 static uint8_t get_role_by_name(const char *role_str)
6609 {
6610 if (strncmp(role_str, "peer", 2) == 0)
6611 return ROLE_PEER;
6612 if (strncmp(role_str, "provider", 2) == 0)
6613 return ROLE_PROVIDER;
6614 if (strncmp(role_str, "customer", 2) == 0)
6615 return ROLE_CUSTOMER;
6616 if (strncmp(role_str, "rs-server", 4) == 0)
6617 return ROLE_RS_SERVER;
6618 if (strncmp(role_str, "rs-client", 4) == 0)
6619 return ROLE_RS_CLIENT;
6620 return ROLE_UNDEFINED;
6621 }
6622
6623 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6624 const char *role_str, bool strict_mode)
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 uint8_t role = get_role_by_name(role_str);
6632
6633 if (role == ROLE_UNDEFINED)
6634 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6635 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6636 }
6637
6638 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6639 {
6640 struct peer *peer;
6641
6642 peer = peer_and_group_lookup_vty(vty, ip_str);
6643 if (!peer)
6644 return CMD_WARNING_CONFIG_FAILED;
6645 return bgp_vty_return(vty, peer_role_unset(peer));
6646 }
6647
6648 DEFPY(neighbor_role,
6649 neighbor_role_cmd,
6650 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6651 NEIGHBOR_STR
6652 NEIGHBOR_ADDR_STR2
6653 "Set session role\n"
6654 ROLE_STR)
6655 {
6656 int idx_peer = 1;
6657 int idx_role = 3;
6658
6659 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6660 false);
6661 }
6662
6663 DEFPY(neighbor_role_strict,
6664 neighbor_role_strict_cmd,
6665 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6666 NEIGHBOR_STR
6667 NEIGHBOR_ADDR_STR2
6668 "Set session role\n"
6669 ROLE_STR
6670 "Use additional restriction on peer\n")
6671 {
6672 int idx_peer = 1;
6673 int idx_role = 3;
6674
6675 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6676 true);
6677 }
6678
6679 DEFPY(no_neighbor_role,
6680 no_neighbor_role_cmd,
6681 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6682 NO_STR
6683 NEIGHBOR_STR
6684 NEIGHBOR_ADDR_STR2
6685 "Set session role\n"
6686 ROLE_STR
6687 "Use additional restriction on peer\n")
6688 {
6689 int idx_peer = 2;
6690
6691 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6692 }
6693
6694 /* disable-connected-check */
6695 DEFUN (neighbor_disable_connected_check,
6696 neighbor_disable_connected_check_cmd,
6697 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6698 NEIGHBOR_STR
6699 NEIGHBOR_ADDR_STR2
6700 "one-hop away EBGP peer using loopback address\n"
6701 "Enforce EBGP neighbors perform multihop\n")
6702 {
6703 int idx_peer = 1;
6704 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6705 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6706 }
6707
6708 DEFUN (no_neighbor_disable_connected_check,
6709 no_neighbor_disable_connected_check_cmd,
6710 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6711 NO_STR
6712 NEIGHBOR_STR
6713 NEIGHBOR_ADDR_STR2
6714 "one-hop away EBGP peer using loopback address\n"
6715 "Enforce EBGP neighbors perform multihop\n")
6716 {
6717 int idx_peer = 2;
6718 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6719 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6720 }
6721
6722 /* disable-link-bw-encoding-ieee */
6723 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6724 neighbor_disable_link_bw_encoding_ieee_cmd,
6725 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6726 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6727 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6728 {
6729 int idx_peer = 1;
6730
6731 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6732 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6733 }
6734
6735 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6736 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6737 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6738 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6739 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6740 {
6741 int idx_peer = 2;
6742
6743 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6744 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6745 }
6746
6747 /* extended-optional-parameters */
6748 DEFUN(neighbor_extended_optional_parameters,
6749 neighbor_extended_optional_parameters_cmd,
6750 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6751 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6752 "Force the extended optional parameters format for OPEN messages\n")
6753 {
6754 int idx_peer = 1;
6755
6756 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6757 PEER_FLAG_EXTENDED_OPT_PARAMS);
6758 }
6759
6760 DEFUN(no_neighbor_extended_optional_parameters,
6761 no_neighbor_extended_optional_parameters_cmd,
6762 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6763 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6764 "Force the extended optional parameters format for OPEN messages\n")
6765 {
6766 int idx_peer = 2;
6767
6768 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6769 PEER_FLAG_EXTENDED_OPT_PARAMS);
6770 }
6771
6772 /* enforce-first-as */
6773 DEFUN (neighbor_enforce_first_as,
6774 neighbor_enforce_first_as_cmd,
6775 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6776 NEIGHBOR_STR
6777 NEIGHBOR_ADDR_STR2
6778 "Enforce the first AS for EBGP routes\n")
6779 {
6780 int idx_peer = 1;
6781
6782 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6783 PEER_FLAG_ENFORCE_FIRST_AS);
6784 }
6785
6786 DEFUN (no_neighbor_enforce_first_as,
6787 no_neighbor_enforce_first_as_cmd,
6788 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6789 NO_STR
6790 NEIGHBOR_STR
6791 NEIGHBOR_ADDR_STR2
6792 "Enforce the first AS for EBGP routes\n")
6793 {
6794 int idx_peer = 2;
6795
6796 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6797 PEER_FLAG_ENFORCE_FIRST_AS);
6798 }
6799
6800
6801 DEFUN (neighbor_description,
6802 neighbor_description_cmd,
6803 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6804 NEIGHBOR_STR
6805 NEIGHBOR_ADDR_STR2
6806 "Neighbor specific description\n"
6807 "Up to 80 characters describing this neighbor\n")
6808 {
6809 int idx_peer = 1;
6810 int idx_line = 3;
6811 struct peer *peer;
6812 char *str;
6813
6814 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6815 if (!peer)
6816 return CMD_WARNING_CONFIG_FAILED;
6817
6818 str = argv_concat(argv, argc, idx_line);
6819
6820 peer_description_set(peer, str);
6821
6822 XFREE(MTYPE_TMP, str);
6823
6824 return CMD_SUCCESS;
6825 }
6826
6827 DEFUN (no_neighbor_description,
6828 no_neighbor_description_cmd,
6829 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6830 NO_STR
6831 NEIGHBOR_STR
6832 NEIGHBOR_ADDR_STR2
6833 "Neighbor specific description\n")
6834 {
6835 int idx_peer = 2;
6836 struct peer *peer;
6837
6838 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6839 if (!peer)
6840 return CMD_WARNING_CONFIG_FAILED;
6841
6842 peer_description_unset(peer);
6843
6844 return CMD_SUCCESS;
6845 }
6846
6847 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6848 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6849 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6850 "Neighbor specific description\n"
6851 "Up to 80 characters describing this neighbor\n")
6852
6853 /* Neighbor update-source. */
6854 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6855 const char *source_str)
6856 {
6857 struct peer *peer;
6858 struct prefix p;
6859 union sockunion su;
6860
6861 peer = peer_and_group_lookup_vty(vty, peer_str);
6862 if (!peer)
6863 return CMD_WARNING_CONFIG_FAILED;
6864
6865 if (peer->conf_if)
6866 return CMD_WARNING;
6867
6868 if (source_str) {
6869 if (str2sockunion(source_str, &su) == 0)
6870 peer_update_source_addr_set(peer, &su);
6871 else {
6872 if (str2prefix(source_str, &p)) {
6873 vty_out(vty,
6874 "%% Invalid update-source, remove prefix length \n");
6875 return CMD_WARNING_CONFIG_FAILED;
6876 } else
6877 peer_update_source_if_set(peer, source_str);
6878 }
6879 } else
6880 peer_update_source_unset(peer);
6881
6882 return CMD_SUCCESS;
6883 }
6884
6885 #define BGP_UPDATE_SOURCE_HELP_STR \
6886 "IPv4 address\n" \
6887 "IPv6 address\n" \
6888 "Interface name (requires zebra to be running)\n"
6889
6890 DEFUN (neighbor_update_source,
6891 neighbor_update_source_cmd,
6892 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6893 NEIGHBOR_STR
6894 NEIGHBOR_ADDR_STR2
6895 "Source of routing updates\n"
6896 BGP_UPDATE_SOURCE_HELP_STR)
6897 {
6898 int idx_peer = 1;
6899 int idx_peer_2 = 3;
6900 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6901 argv[idx_peer_2]->arg);
6902 }
6903
6904 DEFUN (no_neighbor_update_source,
6905 no_neighbor_update_source_cmd,
6906 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6907 NO_STR
6908 NEIGHBOR_STR
6909 NEIGHBOR_ADDR_STR2
6910 "Source of routing updates\n"
6911 BGP_UPDATE_SOURCE_HELP_STR)
6912 {
6913 int idx_peer = 2;
6914 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6915 }
6916
6917 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6918 afi_t afi, safi_t safi,
6919 const char *rmap, int set)
6920 {
6921 int ret;
6922 struct peer *peer;
6923 struct route_map *route_map = NULL;
6924
6925 peer = peer_and_group_lookup_vty(vty, peer_str);
6926 if (!peer)
6927 return CMD_WARNING_CONFIG_FAILED;
6928
6929 if (set) {
6930 if (rmap)
6931 route_map = route_map_lookup_warn_noexist(vty, rmap);
6932 ret = peer_default_originate_set(peer, afi, safi,
6933 rmap, route_map);
6934 } else
6935 ret = peer_default_originate_unset(peer, afi, safi);
6936
6937 return bgp_vty_return(vty, ret);
6938 }
6939
6940 /* neighbor default-originate. */
6941 DEFUN (neighbor_default_originate,
6942 neighbor_default_originate_cmd,
6943 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6944 NEIGHBOR_STR
6945 NEIGHBOR_ADDR_STR2
6946 "Originate default route to this neighbor\n")
6947 {
6948 int idx_peer = 1;
6949 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6950 bgp_node_afi(vty),
6951 bgp_node_safi(vty), NULL, 1);
6952 }
6953
6954 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6955 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6957 "Originate default route to this neighbor\n")
6958
6959 DEFUN (neighbor_default_originate_rmap,
6960 neighbor_default_originate_rmap_cmd,
6961 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6962 NEIGHBOR_STR
6963 NEIGHBOR_ADDR_STR2
6964 "Originate default route to this neighbor\n"
6965 "Route-map to specify criteria to originate default\n"
6966 "route-map name\n")
6967 {
6968 int idx_peer = 1;
6969 int idx_word = 4;
6970 return peer_default_originate_set_vty(
6971 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6972 argv[idx_word]->arg, 1);
6973 }
6974
6975 ALIAS_HIDDEN(
6976 neighbor_default_originate_rmap,
6977 neighbor_default_originate_rmap_hidden_cmd,
6978 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6979 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6980 "Originate default route to this neighbor\n"
6981 "Route-map to specify criteria to originate default\n"
6982 "route-map name\n")
6983
6984 DEFUN (no_neighbor_default_originate,
6985 no_neighbor_default_originate_cmd,
6986 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6987 NO_STR
6988 NEIGHBOR_STR
6989 NEIGHBOR_ADDR_STR2
6990 "Originate default route to this neighbor\n"
6991 "Route-map to specify criteria to originate default\n"
6992 "route-map name\n")
6993 {
6994 int idx_peer = 2;
6995 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6996 bgp_node_afi(vty),
6997 bgp_node_safi(vty), NULL, 0);
6998 }
6999
7000 ALIAS_HIDDEN(
7001 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7002 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
7003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7004 "Originate default route to this neighbor\n"
7005 "Route-map to specify criteria to originate default\n"
7006 "route-map name\n")
7007
7008
7009 /* Set neighbor's BGP port. */
7010 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7011 const char *port_str)
7012 {
7013 struct peer *peer;
7014 uint16_t port;
7015 struct servent *sp;
7016
7017 peer = peer_and_group_lookup_vty(vty, ip_str);
7018 if (!peer)
7019 return CMD_WARNING_CONFIG_FAILED;
7020
7021 if (!port_str) {
7022 sp = getservbyname("bgp", "tcp");
7023 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7024 } else {
7025 port = strtoul(port_str, NULL, 10);
7026 }
7027
7028 peer_port_set(peer, port);
7029
7030 return CMD_SUCCESS;
7031 }
7032
7033 /* Set specified peer's BGP port. */
7034 DEFUN (neighbor_port,
7035 neighbor_port_cmd,
7036 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7037 NEIGHBOR_STR
7038 NEIGHBOR_ADDR_STR2
7039 "Neighbor's BGP port\n"
7040 "TCP port number\n")
7041 {
7042 int idx_ip = 1;
7043 int idx_number = 3;
7044 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7045 argv[idx_number]->arg);
7046 }
7047
7048 DEFUN (no_neighbor_port,
7049 no_neighbor_port_cmd,
7050 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7051 NO_STR
7052 NEIGHBOR_STR
7053 NEIGHBOR_ADDR_STR2
7054 "Neighbor's BGP port\n"
7055 "TCP port number\n")
7056 {
7057 int idx_ip = 2;
7058 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7059 }
7060
7061
7062 /* neighbor weight. */
7063 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7064 safi_t safi, const char *weight_str)
7065 {
7066 int ret;
7067 struct peer *peer;
7068 unsigned long weight;
7069
7070 peer = peer_and_group_lookup_vty(vty, ip_str);
7071 if (!peer)
7072 return CMD_WARNING_CONFIG_FAILED;
7073
7074 weight = strtoul(weight_str, NULL, 10);
7075
7076 ret = peer_weight_set(peer, afi, safi, weight);
7077 return bgp_vty_return(vty, ret);
7078 }
7079
7080 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7081 safi_t safi)
7082 {
7083 int ret;
7084 struct peer *peer;
7085
7086 peer = peer_and_group_lookup_vty(vty, ip_str);
7087 if (!peer)
7088 return CMD_WARNING_CONFIG_FAILED;
7089
7090 ret = peer_weight_unset(peer, afi, safi);
7091 return bgp_vty_return(vty, ret);
7092 }
7093
7094 DEFUN (neighbor_weight,
7095 neighbor_weight_cmd,
7096 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7097 NEIGHBOR_STR
7098 NEIGHBOR_ADDR_STR2
7099 "Set default weight for routes from this neighbor\n"
7100 "default weight\n")
7101 {
7102 int idx_peer = 1;
7103 int idx_number = 3;
7104 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7105 bgp_node_safi(vty), argv[idx_number]->arg);
7106 }
7107
7108 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7109 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7110 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7111 "Set default weight for routes from this neighbor\n"
7112 "default weight\n")
7113
7114 DEFUN (no_neighbor_weight,
7115 no_neighbor_weight_cmd,
7116 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7117 NO_STR
7118 NEIGHBOR_STR
7119 NEIGHBOR_ADDR_STR2
7120 "Set default weight for routes from this neighbor\n"
7121 "default weight\n")
7122 {
7123 int idx_peer = 2;
7124 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7125 bgp_node_afi(vty), bgp_node_safi(vty));
7126 }
7127
7128 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7129 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7130 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7131 "Set default weight for routes from this neighbor\n"
7132 "default weight\n")
7133
7134
7135 /* Override capability negotiation. */
7136 DEFUN (neighbor_override_capability,
7137 neighbor_override_capability_cmd,
7138 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7139 NEIGHBOR_STR
7140 NEIGHBOR_ADDR_STR2
7141 "Override capability negotiation result\n")
7142 {
7143 int idx_peer = 1;
7144 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7145 PEER_FLAG_OVERRIDE_CAPABILITY);
7146 }
7147
7148 DEFUN (no_neighbor_override_capability,
7149 no_neighbor_override_capability_cmd,
7150 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7151 NO_STR
7152 NEIGHBOR_STR
7153 NEIGHBOR_ADDR_STR2
7154 "Override capability negotiation result\n")
7155 {
7156 int idx_peer = 2;
7157 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7158 PEER_FLAG_OVERRIDE_CAPABILITY);
7159 }
7160
7161 DEFUN (neighbor_strict_capability,
7162 neighbor_strict_capability_cmd,
7163 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7164 NEIGHBOR_STR
7165 NEIGHBOR_ADDR_STR2
7166 "Strict capability negotiation match\n")
7167 {
7168 int idx_peer = 1;
7169
7170 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7171 PEER_FLAG_STRICT_CAP_MATCH);
7172 }
7173
7174 DEFUN (no_neighbor_strict_capability,
7175 no_neighbor_strict_capability_cmd,
7176 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7177 NO_STR
7178 NEIGHBOR_STR
7179 NEIGHBOR_ADDR_STR2
7180 "Strict capability negotiation match\n")
7181 {
7182 int idx_peer = 2;
7183
7184 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7185 PEER_FLAG_STRICT_CAP_MATCH);
7186 }
7187
7188 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7189 const char *keep_str, const char *hold_str)
7190 {
7191 int ret;
7192 struct peer *peer;
7193 uint32_t keepalive;
7194 uint32_t holdtime;
7195
7196 peer = peer_and_group_lookup_vty(vty, ip_str);
7197 if (!peer)
7198 return CMD_WARNING_CONFIG_FAILED;
7199
7200 keepalive = strtoul(keep_str, NULL, 10);
7201 holdtime = strtoul(hold_str, NULL, 10);
7202
7203 ret = peer_timers_set(peer, keepalive, holdtime);
7204
7205 return bgp_vty_return(vty, ret);
7206 }
7207
7208 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7209 {
7210 int ret;
7211 struct peer *peer;
7212
7213 peer = peer_and_group_lookup_vty(vty, ip_str);
7214 if (!peer)
7215 return CMD_WARNING_CONFIG_FAILED;
7216
7217 ret = peer_timers_unset(peer);
7218
7219 return bgp_vty_return(vty, ret);
7220 }
7221
7222 DEFUN (neighbor_timers,
7223 neighbor_timers_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7225 NEIGHBOR_STR
7226 NEIGHBOR_ADDR_STR2
7227 "BGP per neighbor timers\n"
7228 "Keepalive interval\n"
7229 "Holdtime\n")
7230 {
7231 int idx_peer = 1;
7232 int idx_number = 3;
7233 int idx_number_2 = 4;
7234 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7235 argv[idx_number]->arg,
7236 argv[idx_number_2]->arg);
7237 }
7238
7239 DEFUN (no_neighbor_timers,
7240 no_neighbor_timers_cmd,
7241 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7242 NO_STR
7243 NEIGHBOR_STR
7244 NEIGHBOR_ADDR_STR2
7245 "BGP per neighbor timers\n"
7246 "Keepalive interval\n"
7247 "Holdtime\n")
7248 {
7249 int idx_peer = 2;
7250 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7251 }
7252
7253
7254 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7255 const char *time_str)
7256 {
7257 int ret;
7258 struct peer *peer;
7259 uint32_t connect;
7260
7261 peer = peer_and_group_lookup_vty(vty, ip_str);
7262 if (!peer)
7263 return CMD_WARNING_CONFIG_FAILED;
7264
7265 connect = strtoul(time_str, NULL, 10);
7266
7267 ret = peer_timers_connect_set(peer, connect);
7268
7269 return bgp_vty_return(vty, ret);
7270 }
7271
7272 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7273 {
7274 int ret;
7275 struct peer *peer;
7276
7277 peer = peer_and_group_lookup_vty(vty, ip_str);
7278 if (!peer)
7279 return CMD_WARNING_CONFIG_FAILED;
7280
7281 ret = peer_timers_connect_unset(peer);
7282
7283 return bgp_vty_return(vty, ret);
7284 }
7285
7286 DEFUN (neighbor_timers_connect,
7287 neighbor_timers_connect_cmd,
7288 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7289 NEIGHBOR_STR
7290 NEIGHBOR_ADDR_STR2
7291 "BGP per neighbor timers\n"
7292 "BGP connect timer\n"
7293 "Connect timer\n")
7294 {
7295 int idx_peer = 1;
7296 int idx_number = 4;
7297 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7298 argv[idx_number]->arg);
7299 }
7300
7301 DEFUN (no_neighbor_timers_connect,
7302 no_neighbor_timers_connect_cmd,
7303 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7304 NO_STR
7305 NEIGHBOR_STR
7306 NEIGHBOR_ADDR_STR2
7307 "BGP per neighbor timers\n"
7308 "BGP connect timer\n"
7309 "Connect timer\n")
7310 {
7311 int idx_peer = 2;
7312 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7313 }
7314
7315 DEFPY (neighbor_timers_delayopen,
7316 neighbor_timers_delayopen_cmd,
7317 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7318 NEIGHBOR_STR
7319 NEIGHBOR_ADDR_STR2
7320 "BGP per neighbor timers\n"
7321 "RFC 4271 DelayOpenTimer\n"
7322 "DelayOpenTime timer interval\n")
7323 {
7324 struct peer *peer;
7325
7326 peer = peer_and_group_lookup_vty(vty, neighbor);
7327 if (!peer)
7328 return CMD_WARNING_CONFIG_FAILED;
7329
7330 if (!interval) {
7331 if (peer_timers_delayopen_unset(peer))
7332 return CMD_WARNING_CONFIG_FAILED;
7333 } else {
7334 if (peer_timers_delayopen_set(peer, interval))
7335 return CMD_WARNING_CONFIG_FAILED;
7336 }
7337
7338 return CMD_SUCCESS;
7339 }
7340
7341 DEFPY (no_neighbor_timers_delayopen,
7342 no_neighbor_timers_delayopen_cmd,
7343 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7344 NO_STR
7345 NEIGHBOR_STR
7346 NEIGHBOR_ADDR_STR2
7347 "BGP per neighbor timers\n"
7348 "RFC 4271 DelayOpenTimer\n"
7349 "DelayOpenTime timer interval\n")
7350 {
7351 struct peer *peer;
7352
7353 peer = peer_and_group_lookup_vty(vty, neighbor);
7354 if (!peer)
7355 return CMD_WARNING_CONFIG_FAILED;
7356
7357 if (peer_timers_delayopen_unset(peer))
7358 return CMD_WARNING_CONFIG_FAILED;
7359
7360 return CMD_SUCCESS;
7361 }
7362
7363 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7364 const char *time_str, int set)
7365 {
7366 int ret;
7367 struct peer *peer;
7368 uint32_t routeadv = 0;
7369
7370 peer = peer_and_group_lookup_vty(vty, ip_str);
7371 if (!peer)
7372 return CMD_WARNING_CONFIG_FAILED;
7373
7374 if (time_str)
7375 routeadv = strtoul(time_str, NULL, 10);
7376
7377 if (set)
7378 ret = peer_advertise_interval_set(peer, routeadv);
7379 else
7380 ret = peer_advertise_interval_unset(peer);
7381
7382 return bgp_vty_return(vty, ret);
7383 }
7384
7385 DEFUN (neighbor_advertise_interval,
7386 neighbor_advertise_interval_cmd,
7387 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7388 NEIGHBOR_STR
7389 NEIGHBOR_ADDR_STR2
7390 "Minimum interval between sending BGP routing updates\n"
7391 "time in seconds\n")
7392 {
7393 int idx_peer = 1;
7394 int idx_number = 3;
7395 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7396 argv[idx_number]->arg, 1);
7397 }
7398
7399 DEFUN (no_neighbor_advertise_interval,
7400 no_neighbor_advertise_interval_cmd,
7401 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7402 NO_STR
7403 NEIGHBOR_STR
7404 NEIGHBOR_ADDR_STR2
7405 "Minimum interval between sending BGP routing updates\n"
7406 "time in seconds\n")
7407 {
7408 int idx_peer = 2;
7409 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7410 }
7411
7412
7413 /* Time to wait before processing route-map updates */
7414 DEFUN (bgp_set_route_map_delay_timer,
7415 bgp_set_route_map_delay_timer_cmd,
7416 "bgp route-map delay-timer (0-600)",
7417 SET_STR
7418 "BGP route-map delay timer\n"
7419 "Time in secs to wait before processing route-map changes\n"
7420 "0 disables the timer, no route updates happen when route-maps change\n")
7421 {
7422 int idx_number = 3;
7423 uint32_t rmap_delay_timer;
7424
7425 if (argv[idx_number]->arg) {
7426 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7427 bm->rmap_update_timer = rmap_delay_timer;
7428
7429 /* if the dynamic update handling is being disabled, and a timer
7430 * is
7431 * running, stop the timer and act as if the timer has already
7432 * fired.
7433 */
7434 if (!rmap_delay_timer && bm->t_rmap_update) {
7435 THREAD_OFF(bm->t_rmap_update);
7436 thread_execute(bm->master, bgp_route_map_update_timer,
7437 NULL, 0);
7438 }
7439 return CMD_SUCCESS;
7440 } else {
7441 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7442 return CMD_WARNING_CONFIG_FAILED;
7443 }
7444 }
7445
7446 DEFUN (no_bgp_set_route_map_delay_timer,
7447 no_bgp_set_route_map_delay_timer_cmd,
7448 "no bgp route-map delay-timer [(0-600)]",
7449 NO_STR
7450 BGP_STR
7451 "Default BGP route-map delay timer\n"
7452 "Reset to default time to wait for processing route-map changes\n"
7453 "0 disables the timer, no route updates happen when route-maps change\n")
7454 {
7455
7456 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7457
7458 return CMD_SUCCESS;
7459 }
7460
7461 /* neighbor interface */
7462 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7463 const char *str)
7464 {
7465 struct peer *peer;
7466
7467 peer = peer_lookup_vty(vty, ip_str);
7468 if (!peer || peer->conf_if) {
7469 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7470 return CMD_WARNING_CONFIG_FAILED;
7471 }
7472
7473 if (str)
7474 peer_interface_set(peer, str);
7475 else
7476 peer_interface_unset(peer);
7477
7478 return CMD_SUCCESS;
7479 }
7480
7481 DEFUN (neighbor_interface,
7482 neighbor_interface_cmd,
7483 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7484 NEIGHBOR_STR
7485 NEIGHBOR_ADDR_STR
7486 "Interface\n"
7487 "Interface name\n")
7488 {
7489 int idx_ip = 1;
7490 int idx_word = 3;
7491
7492 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7493 }
7494
7495 DEFUN (no_neighbor_interface,
7496 no_neighbor_interface_cmd,
7497 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7498 NO_STR
7499 NEIGHBOR_STR
7500 NEIGHBOR_ADDR_STR
7501 "Interface\n"
7502 "Interface name\n")
7503 {
7504 int idx_peer = 2;
7505
7506 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7507 }
7508
7509 DEFUN (neighbor_distribute_list,
7510 neighbor_distribute_list_cmd,
7511 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7512 NEIGHBOR_STR
7513 NEIGHBOR_ADDR_STR2
7514 "Filter updates to/from this neighbor\n"
7515 "IP Access-list name\n"
7516 "Filter incoming updates\n"
7517 "Filter outgoing updates\n")
7518 {
7519 int idx_peer = 1;
7520 int idx_acl = 3;
7521 int direct, ret;
7522 struct peer *peer;
7523
7524 const char *pstr = argv[idx_peer]->arg;
7525 const char *acl = argv[idx_acl]->arg;
7526 const char *inout = argv[argc - 1]->text;
7527
7528 peer = peer_and_group_lookup_vty(vty, pstr);
7529 if (!peer)
7530 return CMD_WARNING_CONFIG_FAILED;
7531
7532 /* Check filter direction. */
7533 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7534 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7535 direct, acl);
7536
7537 return bgp_vty_return(vty, ret);
7538 }
7539
7540 ALIAS_HIDDEN(
7541 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7542 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7543 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7544 "Filter updates to/from this neighbor\n"
7545 "IP Access-list name\n"
7546 "Filter incoming updates\n"
7547 "Filter outgoing updates\n")
7548
7549 DEFUN (no_neighbor_distribute_list,
7550 no_neighbor_distribute_list_cmd,
7551 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7552 NO_STR
7553 NEIGHBOR_STR
7554 NEIGHBOR_ADDR_STR2
7555 "Filter updates to/from this neighbor\n"
7556 "IP Access-list name\n"
7557 "Filter incoming updates\n"
7558 "Filter outgoing updates\n")
7559 {
7560 int idx_peer = 2;
7561 int direct, ret;
7562 struct peer *peer;
7563
7564 const char *pstr = argv[idx_peer]->arg;
7565 const char *inout = argv[argc - 1]->text;
7566
7567 peer = peer_and_group_lookup_vty(vty, pstr);
7568 if (!peer)
7569 return CMD_WARNING_CONFIG_FAILED;
7570
7571 /* Check filter direction. */
7572 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7573 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7574 direct);
7575
7576 return bgp_vty_return(vty, ret);
7577 }
7578
7579 ALIAS_HIDDEN(
7580 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7581 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7582 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7583 "Filter updates to/from this neighbor\n"
7584 "IP Access-list name\n"
7585 "Filter incoming updates\n"
7586 "Filter outgoing updates\n")
7587
7588 /* Set prefix list to the peer. */
7589 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7590 afi_t afi, safi_t safi,
7591 const char *name_str,
7592 const char *direct_str)
7593 {
7594 int ret;
7595 int direct = FILTER_IN;
7596 struct peer *peer;
7597
7598 peer = peer_and_group_lookup_vty(vty, ip_str);
7599 if (!peer)
7600 return CMD_WARNING_CONFIG_FAILED;
7601
7602 /* Check filter direction. */
7603 if (strncmp(direct_str, "i", 1) == 0)
7604 direct = FILTER_IN;
7605 else if (strncmp(direct_str, "o", 1) == 0)
7606 direct = FILTER_OUT;
7607
7608 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7609
7610 return bgp_vty_return(vty, ret);
7611 }
7612
7613 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7614 afi_t afi, safi_t safi,
7615 const char *direct_str)
7616 {
7617 int ret;
7618 struct peer *peer;
7619 int direct = FILTER_IN;
7620
7621 peer = peer_and_group_lookup_vty(vty, ip_str);
7622 if (!peer)
7623 return CMD_WARNING_CONFIG_FAILED;
7624
7625 /* Check filter direction. */
7626 if (strncmp(direct_str, "i", 1) == 0)
7627 direct = FILTER_IN;
7628 else if (strncmp(direct_str, "o", 1) == 0)
7629 direct = FILTER_OUT;
7630
7631 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7632
7633 return bgp_vty_return(vty, ret);
7634 }
7635
7636 DEFUN (neighbor_prefix_list,
7637 neighbor_prefix_list_cmd,
7638 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7639 NEIGHBOR_STR
7640 NEIGHBOR_ADDR_STR2
7641 "Filter updates to/from this neighbor\n"
7642 "Name of a prefix list\n"
7643 "Filter incoming updates\n"
7644 "Filter outgoing updates\n")
7645 {
7646 int idx_peer = 1;
7647 int idx_word = 3;
7648 int idx_in_out = 4;
7649 return peer_prefix_list_set_vty(
7650 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7651 argv[idx_word]->arg, argv[idx_in_out]->arg);
7652 }
7653
7654 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7655 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7656 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7657 "Filter updates to/from this neighbor\n"
7658 "Name of a prefix list\n"
7659 "Filter incoming updates\n"
7660 "Filter outgoing updates\n")
7661
7662 DEFUN (no_neighbor_prefix_list,
7663 no_neighbor_prefix_list_cmd,
7664 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7665 NO_STR
7666 NEIGHBOR_STR
7667 NEIGHBOR_ADDR_STR2
7668 "Filter updates to/from this neighbor\n"
7669 "Name of a prefix list\n"
7670 "Filter incoming updates\n"
7671 "Filter outgoing updates\n")
7672 {
7673 int idx_peer = 2;
7674 int idx_in_out = 5;
7675 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7676 bgp_node_afi(vty), bgp_node_safi(vty),
7677 argv[idx_in_out]->arg);
7678 }
7679
7680 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7681 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7682 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7683 "Filter updates to/from this neighbor\n"
7684 "Name of a prefix list\n"
7685 "Filter incoming updates\n"
7686 "Filter outgoing updates\n")
7687
7688 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7689 safi_t safi, const char *name_str,
7690 const char *direct_str)
7691 {
7692 int ret;
7693 struct peer *peer;
7694 int direct = FILTER_IN;
7695
7696 peer = peer_and_group_lookup_vty(vty, ip_str);
7697 if (!peer)
7698 return CMD_WARNING_CONFIG_FAILED;
7699
7700 /* Check filter direction. */
7701 if (strncmp(direct_str, "i", 1) == 0)
7702 direct = FILTER_IN;
7703 else if (strncmp(direct_str, "o", 1) == 0)
7704 direct = FILTER_OUT;
7705
7706 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7707
7708 return bgp_vty_return(vty, ret);
7709 }
7710
7711 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7712 safi_t safi, const char *direct_str)
7713 {
7714 int ret;
7715 struct peer *peer;
7716 int direct = FILTER_IN;
7717
7718 peer = peer_and_group_lookup_vty(vty, ip_str);
7719 if (!peer)
7720 return CMD_WARNING_CONFIG_FAILED;
7721
7722 /* Check filter direction. */
7723 if (strncmp(direct_str, "i", 1) == 0)
7724 direct = FILTER_IN;
7725 else if (strncmp(direct_str, "o", 1) == 0)
7726 direct = FILTER_OUT;
7727
7728 ret = peer_aslist_unset(peer, afi, safi, direct);
7729
7730 return bgp_vty_return(vty, ret);
7731 }
7732
7733 DEFUN (neighbor_filter_list,
7734 neighbor_filter_list_cmd,
7735 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7736 NEIGHBOR_STR
7737 NEIGHBOR_ADDR_STR2
7738 "Establish BGP filters\n"
7739 "AS path access-list name\n"
7740 "Filter incoming routes\n"
7741 "Filter outgoing routes\n")
7742 {
7743 int idx_peer = 1;
7744 int idx_word = 3;
7745 int idx_in_out = 4;
7746 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7747 bgp_node_safi(vty), argv[idx_word]->arg,
7748 argv[idx_in_out]->arg);
7749 }
7750
7751 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7752 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7753 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7754 "Establish BGP filters\n"
7755 "AS path access-list name\n"
7756 "Filter incoming routes\n"
7757 "Filter outgoing routes\n")
7758
7759 DEFUN (no_neighbor_filter_list,
7760 no_neighbor_filter_list_cmd,
7761 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7762 NO_STR
7763 NEIGHBOR_STR
7764 NEIGHBOR_ADDR_STR2
7765 "Establish BGP filters\n"
7766 "AS path access-list name\n"
7767 "Filter incoming routes\n"
7768 "Filter outgoing routes\n")
7769 {
7770 int idx_peer = 2;
7771 int idx_in_out = 5;
7772 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7773 bgp_node_afi(vty), bgp_node_safi(vty),
7774 argv[idx_in_out]->arg);
7775 }
7776
7777 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7778 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7779 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7780 "Establish BGP filters\n"
7781 "AS path access-list name\n"
7782 "Filter incoming routes\n"
7783 "Filter outgoing routes\n")
7784
7785 /* Set advertise-map to the peer. */
7786 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7787 afi_t afi, safi_t safi,
7788 const char *advertise_str,
7789 const char *condition_str, bool condition,
7790 bool set)
7791 {
7792 int ret = CMD_WARNING_CONFIG_FAILED;
7793 struct peer *peer;
7794 struct route_map *advertise_map;
7795 struct route_map *condition_map;
7796
7797 peer = peer_and_group_lookup_vty(vty, ip_str);
7798 if (!peer)
7799 return ret;
7800
7801 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7802 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7803
7804 if (set)
7805 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7806 advertise_map, condition_str,
7807 condition_map, condition);
7808 else
7809 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7810 advertise_map, condition_str,
7811 condition_map, condition);
7812
7813 return bgp_vty_return(vty, ret);
7814 }
7815
7816 DEFPY (bgp_condadv_period,
7817 bgp_condadv_period_cmd,
7818 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7819 NO_STR
7820 BGP_STR
7821 "Conditional advertisement settings\n"
7822 "Set period to rescan BGP table to check if condition is met\n"
7823 "Period between BGP table scans, in seconds; default 60\n")
7824 {
7825 VTY_DECLVAR_CONTEXT(bgp, bgp);
7826
7827 bgp->condition_check_period =
7828 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7829
7830 return CMD_SUCCESS;
7831 }
7832
7833 DEFPY (neighbor_advertise_map,
7834 neighbor_advertise_map_cmd,
7835 "[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",
7836 NO_STR
7837 NEIGHBOR_STR
7838 NEIGHBOR_ADDR_STR2
7839 "Route-map to conditionally advertise routes\n"
7840 "Name of advertise map\n"
7841 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7842 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7843 "Name of the exist or non exist map\n")
7844 {
7845 bool condition = CONDITION_EXIST;
7846
7847 if (!strcmp(exist, "non-exist-map"))
7848 condition = CONDITION_NON_EXIST;
7849
7850 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7851 bgp_node_safi(vty), advertise_str,
7852 condition_str, condition, !no);
7853 }
7854
7855 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7856 "[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",
7857 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7858 "Route-map to conditionally advertise routes\n"
7859 "Name of advertise map\n"
7860 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7861 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7862 "Name of the exist or non exist map\n")
7863
7864 /* Set route-map to the peer. */
7865 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7866 afi_t afi, safi_t safi, const char *name_str,
7867 const char *direct_str)
7868 {
7869 int ret;
7870 struct peer *peer;
7871 int direct = RMAP_IN;
7872 struct route_map *route_map;
7873
7874 peer = peer_and_group_lookup_vty(vty, ip_str);
7875 if (!peer)
7876 return CMD_WARNING_CONFIG_FAILED;
7877
7878 /* Check filter direction. */
7879 if (strncmp(direct_str, "in", 2) == 0)
7880 direct = RMAP_IN;
7881 else if (strncmp(direct_str, "o", 1) == 0)
7882 direct = RMAP_OUT;
7883
7884 route_map = route_map_lookup_warn_noexist(vty, name_str);
7885 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7886
7887 return bgp_vty_return(vty, ret);
7888 }
7889
7890 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7891 afi_t afi, safi_t safi,
7892 const char *direct_str)
7893 {
7894 int ret;
7895 struct peer *peer;
7896 int direct = RMAP_IN;
7897
7898 peer = peer_and_group_lookup_vty(vty, ip_str);
7899 if (!peer)
7900 return CMD_WARNING_CONFIG_FAILED;
7901
7902 /* Check filter direction. */
7903 if (strncmp(direct_str, "in", 2) == 0)
7904 direct = RMAP_IN;
7905 else if (strncmp(direct_str, "o", 1) == 0)
7906 direct = RMAP_OUT;
7907
7908 ret = peer_route_map_unset(peer, afi, safi, direct);
7909
7910 return bgp_vty_return(vty, ret);
7911 }
7912
7913 DEFUN (neighbor_route_map,
7914 neighbor_route_map_cmd,
7915 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7916 NEIGHBOR_STR
7917 NEIGHBOR_ADDR_STR2
7918 "Apply route map to neighbor\n"
7919 "Name of route map\n"
7920 "Apply map to incoming routes\n"
7921 "Apply map to outbound routes\n")
7922 {
7923 int idx_peer = 1;
7924 int idx_word = 3;
7925 int idx_in_out = 4;
7926 return peer_route_map_set_vty(
7927 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7928 argv[idx_word]->arg, argv[idx_in_out]->arg);
7929 }
7930
7931 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7932 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7934 "Apply route map to neighbor\n"
7935 "Name of route map\n"
7936 "Apply map to incoming routes\n"
7937 "Apply map to outbound routes\n")
7938
7939 DEFUN (no_neighbor_route_map,
7940 no_neighbor_route_map_cmd,
7941 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7942 NO_STR
7943 NEIGHBOR_STR
7944 NEIGHBOR_ADDR_STR2
7945 "Apply route map to neighbor\n"
7946 "Name of route map\n"
7947 "Apply map to incoming routes\n"
7948 "Apply map to outbound routes\n")
7949 {
7950 int idx_peer = 2;
7951 int idx_in_out = 5;
7952 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7953 bgp_node_afi(vty), bgp_node_safi(vty),
7954 argv[idx_in_out]->arg);
7955 }
7956
7957 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7958 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7959 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7960 "Apply route map to neighbor\n"
7961 "Name of route map\n"
7962 "Apply map to incoming routes\n"
7963 "Apply map to outbound routes\n")
7964
7965 /* Set unsuppress-map to the peer. */
7966 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7967 afi_t afi, safi_t safi,
7968 const char *name_str)
7969 {
7970 int ret;
7971 struct peer *peer;
7972 struct route_map *route_map;
7973
7974 peer = peer_and_group_lookup_vty(vty, ip_str);
7975 if (!peer)
7976 return CMD_WARNING_CONFIG_FAILED;
7977
7978 route_map = route_map_lookup_warn_noexist(vty, name_str);
7979 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7980
7981 return bgp_vty_return(vty, ret);
7982 }
7983
7984 /* Unset route-map from the peer. */
7985 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7986 afi_t afi, safi_t safi)
7987 {
7988 int ret;
7989 struct peer *peer;
7990
7991 peer = peer_and_group_lookup_vty(vty, ip_str);
7992 if (!peer)
7993 return CMD_WARNING_CONFIG_FAILED;
7994
7995 ret = peer_unsuppress_map_unset(peer, afi, safi);
7996
7997 return bgp_vty_return(vty, ret);
7998 }
7999
8000 DEFUN (neighbor_unsuppress_map,
8001 neighbor_unsuppress_map_cmd,
8002 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8003 NEIGHBOR_STR
8004 NEIGHBOR_ADDR_STR2
8005 "Route-map to selectively unsuppress suppressed routes\n"
8006 "Name of route map\n")
8007 {
8008 int idx_peer = 1;
8009 int idx_word = 3;
8010 return peer_unsuppress_map_set_vty(
8011 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8012 argv[idx_word]->arg);
8013 }
8014
8015 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8016 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8018 "Route-map to selectively unsuppress suppressed routes\n"
8019 "Name of route map\n")
8020
8021 DEFUN (no_neighbor_unsuppress_map,
8022 no_neighbor_unsuppress_map_cmd,
8023 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8024 NO_STR
8025 NEIGHBOR_STR
8026 NEIGHBOR_ADDR_STR2
8027 "Route-map to selectively unsuppress suppressed routes\n"
8028 "Name of route map\n")
8029 {
8030 int idx_peer = 2;
8031 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8032 bgp_node_afi(vty),
8033 bgp_node_safi(vty));
8034 }
8035
8036 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8037 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8038 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8039 "Route-map to selectively unsuppress suppressed routes\n"
8040 "Name of route map\n")
8041
8042 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8043 afi_t afi, safi_t safi,
8044 const char *num_str,
8045 const char *threshold_str, int warning,
8046 const char *restart_str,
8047 const char *force_str)
8048 {
8049 int ret;
8050 struct peer *peer;
8051 uint32_t max;
8052 uint8_t threshold;
8053 uint16_t restart;
8054
8055 peer = peer_and_group_lookup_vty(vty, ip_str);
8056 if (!peer)
8057 return CMD_WARNING_CONFIG_FAILED;
8058
8059 max = strtoul(num_str, NULL, 10);
8060 if (threshold_str)
8061 threshold = atoi(threshold_str);
8062 else
8063 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8064
8065 if (restart_str)
8066 restart = atoi(restart_str);
8067 else
8068 restart = 0;
8069
8070 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8071 restart, force_str ? true : false);
8072
8073 return bgp_vty_return(vty, ret);
8074 }
8075
8076 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8077 afi_t afi, safi_t safi)
8078 {
8079 int ret;
8080 struct peer *peer;
8081
8082 peer = peer_and_group_lookup_vty(vty, ip_str);
8083 if (!peer)
8084 return CMD_WARNING_CONFIG_FAILED;
8085
8086 ret = peer_maximum_prefix_unset(peer, afi, safi);
8087
8088 return bgp_vty_return(vty, ret);
8089 }
8090
8091 /* Maximum number of prefix to be sent to the neighbor. */
8092 DEFUN(neighbor_maximum_prefix_out,
8093 neighbor_maximum_prefix_out_cmd,
8094 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8095 NEIGHBOR_STR
8096 NEIGHBOR_ADDR_STR2
8097 "Maximum number of prefixes to be sent to this peer\n"
8098 "Maximum no. of prefix limit\n")
8099 {
8100 int ret;
8101 int idx_peer = 1;
8102 int idx_number = 3;
8103 struct peer *peer;
8104 uint32_t max;
8105 afi_t afi = bgp_node_afi(vty);
8106 safi_t safi = bgp_node_safi(vty);
8107
8108 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8109 if (!peer)
8110 return CMD_WARNING_CONFIG_FAILED;
8111
8112 max = strtoul(argv[idx_number]->arg, NULL, 10);
8113
8114 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8115
8116 return bgp_vty_return(vty, ret);
8117 }
8118
8119 DEFUN(no_neighbor_maximum_prefix_out,
8120 no_neighbor_maximum_prefix_out_cmd,
8121 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8122 NO_STR
8123 NEIGHBOR_STR
8124 NEIGHBOR_ADDR_STR2
8125 "Maximum number of prefixes to be sent to this peer\n"
8126 "Maximum no. of prefix limit\n")
8127 {
8128 int ret;
8129 int idx_peer = 2;
8130 struct peer *peer;
8131 afi_t afi = bgp_node_afi(vty);
8132 safi_t safi = bgp_node_safi(vty);
8133
8134 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8135 if (!peer)
8136 return CMD_WARNING_CONFIG_FAILED;
8137
8138 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8139
8140 return bgp_vty_return(vty, ret);
8141 }
8142
8143 /* Maximum number of prefix configuration. Prefix count is different
8144 for each peer configuration. So this configuration can be set for
8145 each peer configuration. */
8146 DEFUN (neighbor_maximum_prefix,
8147 neighbor_maximum_prefix_cmd,
8148 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8149 NEIGHBOR_STR
8150 NEIGHBOR_ADDR_STR2
8151 "Maximum number of prefix accept from this peer\n"
8152 "maximum no. of prefix limit\n"
8153 "Force checking all received routes not only accepted\n")
8154 {
8155 int idx_peer = 1;
8156 int idx_number = 3;
8157 int idx_force = 0;
8158 char *force = NULL;
8159
8160 if (argv_find(argv, argc, "force", &idx_force))
8161 force = argv[idx_force]->arg;
8162
8163 return peer_maximum_prefix_set_vty(
8164 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8165 argv[idx_number]->arg, NULL, 0, NULL, force);
8166 }
8167
8168 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8169 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8170 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8171 "Maximum number of prefix accept from this peer\n"
8172 "maximum no. of prefix limit\n"
8173 "Force checking all received routes not only accepted\n")
8174
8175 DEFUN (neighbor_maximum_prefix_threshold,
8176 neighbor_maximum_prefix_threshold_cmd,
8177 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8178 NEIGHBOR_STR
8179 NEIGHBOR_ADDR_STR2
8180 "Maximum number of prefix accept from this peer\n"
8181 "maximum no. of prefix limit\n"
8182 "Threshold value (%) at which to generate a warning msg\n"
8183 "Force checking all received routes not only accepted\n")
8184 {
8185 int idx_peer = 1;
8186 int idx_number = 3;
8187 int idx_number_2 = 4;
8188 int idx_force = 0;
8189 char *force = NULL;
8190
8191 if (argv_find(argv, argc, "force", &idx_force))
8192 force = argv[idx_force]->arg;
8193
8194 return peer_maximum_prefix_set_vty(
8195 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8196 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8197 }
8198
8199 ALIAS_HIDDEN(
8200 neighbor_maximum_prefix_threshold,
8201 neighbor_maximum_prefix_threshold_hidden_cmd,
8202 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8203 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8204 "Maximum number of prefix accept from this peer\n"
8205 "maximum no. of prefix limit\n"
8206 "Threshold value (%) at which to generate a warning msg\n"
8207 "Force checking all received routes not only accepted\n")
8208
8209 DEFUN (neighbor_maximum_prefix_warning,
8210 neighbor_maximum_prefix_warning_cmd,
8211 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8212 NEIGHBOR_STR
8213 NEIGHBOR_ADDR_STR2
8214 "Maximum number of prefix accept from this peer\n"
8215 "maximum no. of prefix limit\n"
8216 "Only give warning message when limit is exceeded\n"
8217 "Force checking all received routes not only accepted\n")
8218 {
8219 int idx_peer = 1;
8220 int idx_number = 3;
8221 int idx_force = 0;
8222 char *force = NULL;
8223
8224 if (argv_find(argv, argc, "force", &idx_force))
8225 force = argv[idx_force]->arg;
8226
8227 return peer_maximum_prefix_set_vty(
8228 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8229 argv[idx_number]->arg, NULL, 1, NULL, force);
8230 }
8231
8232 ALIAS_HIDDEN(
8233 neighbor_maximum_prefix_warning,
8234 neighbor_maximum_prefix_warning_hidden_cmd,
8235 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8236 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8237 "Maximum number of prefix accept from this peer\n"
8238 "maximum no. of prefix limit\n"
8239 "Only give warning message when limit is exceeded\n"
8240 "Force checking all received routes not only accepted\n")
8241
8242 DEFUN (neighbor_maximum_prefix_threshold_warning,
8243 neighbor_maximum_prefix_threshold_warning_cmd,
8244 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8245 NEIGHBOR_STR
8246 NEIGHBOR_ADDR_STR2
8247 "Maximum number of prefix accept from this peer\n"
8248 "maximum no. of prefix limit\n"
8249 "Threshold value (%) at which to generate a warning msg\n"
8250 "Only give warning message when limit is exceeded\n"
8251 "Force checking all received routes not only accepted\n")
8252 {
8253 int idx_peer = 1;
8254 int idx_number = 3;
8255 int idx_number_2 = 4;
8256 int idx_force = 0;
8257 char *force = NULL;
8258
8259 if (argv_find(argv, argc, "force", &idx_force))
8260 force = argv[idx_force]->arg;
8261
8262 return peer_maximum_prefix_set_vty(
8263 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8264 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8265 }
8266
8267 ALIAS_HIDDEN(
8268 neighbor_maximum_prefix_threshold_warning,
8269 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8270 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8271 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8272 "Maximum number of prefix accept from this peer\n"
8273 "maximum no. of prefix limit\n"
8274 "Threshold value (%) at which to generate a warning msg\n"
8275 "Only give warning message when limit is exceeded\n"
8276 "Force checking all received routes not only accepted\n")
8277
8278 DEFUN (neighbor_maximum_prefix_restart,
8279 neighbor_maximum_prefix_restart_cmd,
8280 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8281 NEIGHBOR_STR
8282 NEIGHBOR_ADDR_STR2
8283 "Maximum number of prefix accept from this peer\n"
8284 "maximum no. of prefix limit\n"
8285 "Restart bgp connection after limit is exceeded\n"
8286 "Restart interval in minutes\n"
8287 "Force checking all received routes not only accepted\n")
8288 {
8289 int idx_peer = 1;
8290 int idx_number = 3;
8291 int idx_number_2 = 5;
8292 int idx_force = 0;
8293 char *force = NULL;
8294
8295 if (argv_find(argv, argc, "force", &idx_force))
8296 force = argv[idx_force]->arg;
8297
8298 return peer_maximum_prefix_set_vty(
8299 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8300 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8301 }
8302
8303 ALIAS_HIDDEN(
8304 neighbor_maximum_prefix_restart,
8305 neighbor_maximum_prefix_restart_hidden_cmd,
8306 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8307 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8308 "Maximum number of prefix accept from this peer\n"
8309 "maximum no. of prefix limit\n"
8310 "Restart bgp connection after limit is exceeded\n"
8311 "Restart interval in minutes\n"
8312 "Force checking all received routes not only accepted\n")
8313
8314 DEFUN (neighbor_maximum_prefix_threshold_restart,
8315 neighbor_maximum_prefix_threshold_restart_cmd,
8316 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8317 NEIGHBOR_STR
8318 NEIGHBOR_ADDR_STR2
8319 "Maximum number of prefixes to accept from this peer\n"
8320 "maximum no. of prefix limit\n"
8321 "Threshold value (%) at which to generate a warning msg\n"
8322 "Restart bgp connection after limit is exceeded\n"
8323 "Restart interval in minutes\n"
8324 "Force checking all received routes not only accepted\n")
8325 {
8326 int idx_peer = 1;
8327 int idx_number = 3;
8328 int idx_number_2 = 4;
8329 int idx_number_3 = 6;
8330 int idx_force = 0;
8331 char *force = NULL;
8332
8333 if (argv_find(argv, argc, "force", &idx_force))
8334 force = argv[idx_force]->arg;
8335
8336 return peer_maximum_prefix_set_vty(
8337 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8338 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8339 argv[idx_number_3]->arg, force);
8340 }
8341
8342 ALIAS_HIDDEN(
8343 neighbor_maximum_prefix_threshold_restart,
8344 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8345 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8346 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8347 "Maximum number of prefixes to accept from this peer\n"
8348 "maximum no. of prefix limit\n"
8349 "Threshold value (%) at which to generate a warning msg\n"
8350 "Restart bgp connection after limit is exceeded\n"
8351 "Restart interval in minutes\n"
8352 "Force checking all received routes not only accepted\n")
8353
8354 DEFUN (no_neighbor_maximum_prefix,
8355 no_neighbor_maximum_prefix_cmd,
8356 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8357 NO_STR
8358 NEIGHBOR_STR
8359 NEIGHBOR_ADDR_STR2
8360 "Maximum number of prefixes to accept from this peer\n"
8361 "maximum no. of prefix limit\n"
8362 "Threshold value (%) at which to generate a warning msg\n"
8363 "Restart bgp connection after limit is exceeded\n"
8364 "Restart interval in minutes\n"
8365 "Only give warning message when limit is exceeded\n"
8366 "Force checking all received routes not only accepted\n")
8367 {
8368 int idx_peer = 2;
8369 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8370 bgp_node_afi(vty),
8371 bgp_node_safi(vty));
8372 }
8373
8374 ALIAS_HIDDEN(
8375 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8376 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8377 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8378 "Maximum number of prefixes to accept from this peer\n"
8379 "maximum no. of prefix limit\n"
8380 "Threshold value (%) at which to generate a warning msg\n"
8381 "Restart bgp connection after limit is exceeded\n"
8382 "Restart interval in minutes\n"
8383 "Only give warning message when limit is exceeded\n"
8384 "Force checking all received routes not only accepted\n")
8385
8386 /* "neighbor accept-own" */
8387 DEFPY (neighbor_accept_own,
8388 neighbor_accept_own_cmd,
8389 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8390 NO_STR
8391 NEIGHBOR_STR
8392 NEIGHBOR_ADDR_STR2
8393 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8394 {
8395 struct peer *peer;
8396 afi_t afi = bgp_node_afi(vty);
8397 safi_t safi = bgp_node_safi(vty);
8398 int ret;
8399
8400 peer = peer_and_group_lookup_vty(vty, neighbor);
8401 if (!peer)
8402 return CMD_WARNING_CONFIG_FAILED;
8403
8404 if (no)
8405 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8406 else
8407 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8408
8409 return bgp_vty_return(vty, ret);
8410 }
8411
8412 /* "neighbor soo" */
8413 DEFPY (neighbor_soo,
8414 neighbor_soo_cmd,
8415 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8416 NEIGHBOR_STR
8417 NEIGHBOR_ADDR_STR2
8418 "Set the Site-of-Origin (SoO) extended community\n"
8419 "VPN extended community\n")
8420 {
8421 struct peer *peer;
8422 afi_t afi = bgp_node_afi(vty);
8423 safi_t safi = bgp_node_safi(vty);
8424 struct ecommunity *ecomm_soo;
8425
8426 peer = peer_and_group_lookup_vty(vty, neighbor);
8427 if (!peer)
8428 return CMD_WARNING_CONFIG_FAILED;
8429
8430 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8431 if (!ecomm_soo) {
8432 vty_out(vty, "%% Malformed SoO extended community\n");
8433 return CMD_WARNING;
8434 }
8435 ecommunity_str(ecomm_soo);
8436
8437 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8438 ecommunity_free(&peer->soo[afi][safi]);
8439 peer->soo[afi][safi] = ecomm_soo;
8440 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8441 }
8442
8443 return bgp_vty_return(vty,
8444 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8445 }
8446
8447 DEFPY (no_neighbor_soo,
8448 no_neighbor_soo_cmd,
8449 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8450 NO_STR
8451 NEIGHBOR_STR
8452 NEIGHBOR_ADDR_STR2
8453 "Set the Site-of-Origin (SoO) extended community\n"
8454 "VPN extended community\n")
8455 {
8456 struct peer *peer;
8457 afi_t afi = bgp_node_afi(vty);
8458 safi_t safi = bgp_node_safi(vty);
8459
8460 peer = peer_and_group_lookup_vty(vty, neighbor);
8461 if (!peer)
8462 return CMD_WARNING_CONFIG_FAILED;
8463
8464 ecommunity_free(&peer->soo[afi][safi]);
8465
8466 return bgp_vty_return(
8467 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8468 }
8469
8470 /* "neighbor allowas-in" */
8471 DEFUN (neighbor_allowas_in,
8472 neighbor_allowas_in_cmd,
8473 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8474 NEIGHBOR_STR
8475 NEIGHBOR_ADDR_STR2
8476 "Accept as-path with my AS present in it\n"
8477 "Number of occurrences of AS number\n"
8478 "Only accept my AS in the as-path if the route was originated in my AS\n")
8479 {
8480 int idx_peer = 1;
8481 int idx_number_origin = 3;
8482 int ret;
8483 int origin = 0;
8484 struct peer *peer;
8485 int allow_num = 0;
8486
8487 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8488 if (!peer)
8489 return CMD_WARNING_CONFIG_FAILED;
8490
8491 if (argc <= idx_number_origin)
8492 allow_num = 3;
8493 else {
8494 if (argv[idx_number_origin]->type == WORD_TKN)
8495 origin = 1;
8496 else
8497 allow_num = atoi(argv[idx_number_origin]->arg);
8498 }
8499
8500 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8501 allow_num, origin);
8502
8503 return bgp_vty_return(vty, ret);
8504 }
8505
8506 ALIAS_HIDDEN(
8507 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8508 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8509 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8510 "Accept as-path with my AS present in it\n"
8511 "Number of occurrences of AS number\n"
8512 "Only accept my AS in the as-path if the route was originated in my AS\n")
8513
8514 DEFUN (no_neighbor_allowas_in,
8515 no_neighbor_allowas_in_cmd,
8516 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8517 NO_STR
8518 NEIGHBOR_STR
8519 NEIGHBOR_ADDR_STR2
8520 "allow local ASN appears in aspath attribute\n"
8521 "Number of occurrences of AS number\n"
8522 "Only accept my AS in the as-path if the route was originated in my AS\n")
8523 {
8524 int idx_peer = 2;
8525 int ret;
8526 struct peer *peer;
8527
8528 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8529 if (!peer)
8530 return CMD_WARNING_CONFIG_FAILED;
8531
8532 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8533 bgp_node_safi(vty));
8534
8535 return bgp_vty_return(vty, ret);
8536 }
8537
8538 ALIAS_HIDDEN(
8539 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8540 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8541 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8542 "allow local ASN appears in aspath attribute\n"
8543 "Number of occurrences of AS number\n"
8544 "Only accept my AS in the as-path if the route was originated in my AS\n")
8545
8546 DEFUN (neighbor_ttl_security,
8547 neighbor_ttl_security_cmd,
8548 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8549 NEIGHBOR_STR
8550 NEIGHBOR_ADDR_STR2
8551 "BGP ttl-security parameters\n"
8552 "Specify the maximum number of hops to the BGP peer\n"
8553 "Number of hops to BGP peer\n")
8554 {
8555 int idx_peer = 1;
8556 int idx_number = 4;
8557 struct peer *peer;
8558 int gtsm_hops;
8559
8560 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8561 if (!peer)
8562 return CMD_WARNING_CONFIG_FAILED;
8563
8564 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8565
8566 /*
8567 * If 'neighbor swpX', then this is for directly connected peers,
8568 * we should not accept a ttl-security hops value greater than 1.
8569 */
8570 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8571 vty_out(vty,
8572 "%s is directly connected peer, hops cannot exceed 1\n",
8573 argv[idx_peer]->arg);
8574 return CMD_WARNING_CONFIG_FAILED;
8575 }
8576
8577 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8578 }
8579
8580 DEFUN (no_neighbor_ttl_security,
8581 no_neighbor_ttl_security_cmd,
8582 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8583 NO_STR
8584 NEIGHBOR_STR
8585 NEIGHBOR_ADDR_STR2
8586 "BGP ttl-security parameters\n"
8587 "Specify the maximum number of hops to the BGP peer\n"
8588 "Number of hops to BGP peer\n")
8589 {
8590 int idx_peer = 2;
8591 struct peer *peer;
8592
8593 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8594 if (!peer)
8595 return CMD_WARNING_CONFIG_FAILED;
8596
8597 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8598 }
8599
8600 /* disable-addpath-rx */
8601 DEFUN(neighbor_disable_addpath_rx,
8602 neighbor_disable_addpath_rx_cmd,
8603 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8604 NEIGHBOR_STR
8605 NEIGHBOR_ADDR_STR2
8606 "Do not accept additional paths\n")
8607 {
8608 char *peer_str = argv[1]->arg;
8609 struct peer *peer;
8610 afi_t afi = bgp_node_afi(vty);
8611 safi_t safi = bgp_node_safi(vty);
8612
8613 peer = peer_and_group_lookup_vty(vty, peer_str);
8614 if (!peer)
8615 return CMD_WARNING_CONFIG_FAILED;
8616
8617 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8618 PEER_FLAG_DISABLE_ADDPATH_RX);
8619 }
8620
8621 DEFUN(no_neighbor_disable_addpath_rx,
8622 no_neighbor_disable_addpath_rx_cmd,
8623 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8624 NO_STR
8625 NEIGHBOR_STR
8626 NEIGHBOR_ADDR_STR2
8627 "Do not accept additional paths\n")
8628 {
8629 char *peer_str = argv[2]->arg;
8630 struct peer *peer;
8631 afi_t afi = bgp_node_afi(vty);
8632 safi_t safi = bgp_node_safi(vty);
8633
8634 peer = peer_and_group_lookup_vty(vty, peer_str);
8635 if (!peer)
8636 return CMD_WARNING_CONFIG_FAILED;
8637
8638 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8639 PEER_FLAG_DISABLE_ADDPATH_RX);
8640 }
8641
8642 DEFUN (neighbor_addpath_tx_all_paths,
8643 neighbor_addpath_tx_all_paths_cmd,
8644 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8645 NEIGHBOR_STR
8646 NEIGHBOR_ADDR_STR2
8647 "Use addpath to advertise all paths to a neighbor\n")
8648 {
8649 int idx_peer = 1;
8650 struct peer *peer;
8651
8652 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8653 if (!peer)
8654 return CMD_WARNING_CONFIG_FAILED;
8655
8656 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8657 BGP_ADDPATH_ALL);
8658 return CMD_SUCCESS;
8659 }
8660
8661 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8662 neighbor_addpath_tx_all_paths_hidden_cmd,
8663 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8664 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8665 "Use addpath to advertise all paths to a neighbor\n")
8666
8667 DEFUN (no_neighbor_addpath_tx_all_paths,
8668 no_neighbor_addpath_tx_all_paths_cmd,
8669 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8670 NO_STR
8671 NEIGHBOR_STR
8672 NEIGHBOR_ADDR_STR2
8673 "Use addpath to advertise all paths to a neighbor\n")
8674 {
8675 int idx_peer = 2;
8676 struct peer *peer;
8677
8678 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8679 if (!peer)
8680 return CMD_WARNING_CONFIG_FAILED;
8681
8682 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8683 != BGP_ADDPATH_ALL) {
8684 vty_out(vty,
8685 "%% Peer not currently configured to transmit all paths.");
8686 return CMD_WARNING_CONFIG_FAILED;
8687 }
8688
8689 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8690 BGP_ADDPATH_NONE);
8691
8692 return CMD_SUCCESS;
8693 }
8694
8695 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8696 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8697 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8698 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8699 "Use addpath to advertise all paths to a neighbor\n")
8700
8701 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8702 neighbor_addpath_tx_bestpath_per_as_cmd,
8703 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8704 NEIGHBOR_STR
8705 NEIGHBOR_ADDR_STR2
8706 "Use addpath to advertise the bestpath per each neighboring AS\n")
8707 {
8708 int idx_peer = 1;
8709 struct peer *peer;
8710
8711 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8712 if (!peer)
8713 return CMD_WARNING_CONFIG_FAILED;
8714
8715 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8716 BGP_ADDPATH_BEST_PER_AS);
8717
8718 return CMD_SUCCESS;
8719 }
8720
8721 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8722 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8723 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8724 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8725 "Use addpath to advertise the bestpath per each neighboring AS\n")
8726
8727 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8728 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8729 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8730 NO_STR
8731 NEIGHBOR_STR
8732 NEIGHBOR_ADDR_STR2
8733 "Use addpath to advertise the bestpath per each neighboring AS\n")
8734 {
8735 int idx_peer = 2;
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 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8743 != BGP_ADDPATH_BEST_PER_AS) {
8744 vty_out(vty,
8745 "%% Peer not currently configured to transmit all best path per as.");
8746 return CMD_WARNING_CONFIG_FAILED;
8747 }
8748
8749 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8750 BGP_ADDPATH_NONE);
8751
8752 return CMD_SUCCESS;
8753 }
8754
8755 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8756 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8757 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8758 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8759 "Use addpath to advertise the bestpath per each neighboring AS\n")
8760
8761 DEFPY(
8762 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8763 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8764 NEIGHBOR_STR
8765 NEIGHBOR_ADDR_STR2
8766 "Detect AS loops before sending to neighbor\n")
8767 {
8768 struct peer *peer;
8769
8770 peer = peer_and_group_lookup_vty(vty, neighbor);
8771 if (!peer)
8772 return CMD_WARNING_CONFIG_FAILED;
8773
8774 peer->as_path_loop_detection = true;
8775
8776 return CMD_SUCCESS;
8777 }
8778
8779 DEFPY(
8780 no_neighbor_aspath_loop_detection,
8781 no_neighbor_aspath_loop_detection_cmd,
8782 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8783 NO_STR
8784 NEIGHBOR_STR
8785 NEIGHBOR_ADDR_STR2
8786 "Detect AS loops before sending to neighbor\n")
8787 {
8788 struct peer *peer;
8789
8790 peer = peer_and_group_lookup_vty(vty, neighbor);
8791 if (!peer)
8792 return CMD_WARNING_CONFIG_FAILED;
8793
8794 peer->as_path_loop_detection = false;
8795
8796 return CMD_SUCCESS;
8797 }
8798
8799 DEFPY(neighbor_path_attribute_discard,
8800 neighbor_path_attribute_discard_cmd,
8801 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8802 NEIGHBOR_STR
8803 NEIGHBOR_ADDR_STR2
8804 "Manipulate path attributes from incoming UPDATE messages\n"
8805 "Drop specified attributes from incoming UPDATE messages\n"
8806 "Attribute number\n")
8807 {
8808 struct peer *peer;
8809 int idx = 0;
8810 const char *discard_attrs = NULL;
8811
8812 peer = peer_and_group_lookup_vty(vty, neighbor);
8813 if (!peer)
8814 return CMD_WARNING_CONFIG_FAILED;
8815
8816 argv_find(argv, argc, "(1-255)", &idx);
8817 if (idx)
8818 discard_attrs = argv_concat(argv, argc, idx);
8819
8820 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8821
8822 return CMD_SUCCESS;
8823 }
8824
8825 DEFPY(no_neighbor_path_attribute_discard,
8826 no_neighbor_path_attribute_discard_cmd,
8827 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8828 NO_STR
8829 NEIGHBOR_STR
8830 NEIGHBOR_ADDR_STR2
8831 "Manipulate path attributes from incoming UPDATE messages\n"
8832 "Drop specified attributes from incoming UPDATE messages\n"
8833 "Attribute number\n")
8834 {
8835 struct peer *peer;
8836 int idx = 0;
8837 const char *discard_attrs = NULL;
8838
8839 peer = peer_and_group_lookup_vty(vty, neighbor);
8840 if (!peer)
8841 return CMD_WARNING_CONFIG_FAILED;
8842
8843 argv_find(argv, argc, "(1-255)", &idx);
8844 if (idx)
8845 discard_attrs = argv[idx]->arg;
8846
8847 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
8848
8849 return CMD_SUCCESS;
8850 }
8851
8852 DEFPY(neighbor_path_attribute_treat_as_withdraw,
8853 neighbor_path_attribute_treat_as_withdraw_cmd,
8854 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8855 NEIGHBOR_STR
8856 NEIGHBOR_ADDR_STR2
8857 "Manipulate path attributes from incoming UPDATE messages\n"
8858 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8859 "Attribute number\n")
8860 {
8861 struct peer *peer;
8862 int idx = 0;
8863 const char *withdraw_attrs = NULL;
8864
8865 peer = peer_and_group_lookup_vty(vty, neighbor);
8866 if (!peer)
8867 return CMD_WARNING_CONFIG_FAILED;
8868
8869 argv_find(argv, argc, "(1-255)", &idx);
8870 if (idx)
8871 withdraw_attrs = argv_concat(argv, argc, idx);
8872
8873 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, true);
8874
8875 return CMD_SUCCESS;
8876 }
8877
8878 DEFPY(no_neighbor_path_attribute_treat_as_withdraw,
8879 no_neighbor_path_attribute_treat_as_withdraw_cmd,
8880 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute treat-as-withdraw (1-255)...",
8881 NO_STR
8882 NEIGHBOR_STR
8883 NEIGHBOR_ADDR_STR2
8884 "Manipulate path attributes from incoming UPDATE messages\n"
8885 "Treat-as-withdraw any incoming BGP UPDATE messages that contain the specified attribute\n"
8886 "Attribute number\n")
8887 {
8888 struct peer *peer;
8889 int idx = 0;
8890 const char *withdraw_attrs = NULL;
8891
8892 peer = peer_and_group_lookup_vty(vty, neighbor);
8893 if (!peer)
8894 return CMD_WARNING_CONFIG_FAILED;
8895
8896 argv_find(argv, argc, "(1-255)", &idx);
8897 if (idx)
8898 withdraw_attrs = argv_concat(argv, argc, idx);
8899
8900 bgp_path_attribute_withdraw_vty(vty, peer, withdraw_attrs, false);
8901
8902 return CMD_SUCCESS;
8903 }
8904
8905 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8906 struct ecommunity **list, bool is_rt6)
8907 {
8908 struct ecommunity *ecom = NULL;
8909 struct ecommunity *ecomadd;
8910
8911 for (; argc; --argc, ++argv) {
8912 if (is_rt6)
8913 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8914 ECOMMUNITY_ROUTE_TARGET,
8915 0);
8916 else
8917 ecomadd = ecommunity_str2com(argv[0]->arg,
8918 ECOMMUNITY_ROUTE_TARGET,
8919 0);
8920 if (!ecomadd) {
8921 vty_out(vty, "Malformed community-list value\n");
8922 if (ecom)
8923 ecommunity_free(&ecom);
8924 return CMD_WARNING_CONFIG_FAILED;
8925 }
8926
8927 if (ecom) {
8928 ecommunity_merge(ecom, ecomadd);
8929 ecommunity_free(&ecomadd);
8930 } else {
8931 ecom = ecomadd;
8932 }
8933 }
8934
8935 if (*list) {
8936 ecommunity_free(&*list);
8937 }
8938 *list = ecom;
8939
8940 return CMD_SUCCESS;
8941 }
8942
8943 /*
8944 * v2vimport is true if we are handling a `import vrf ...` command
8945 */
8946 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8947 {
8948 afi_t afi;
8949
8950 switch (vty->node) {
8951 case BGP_IPV4_NODE:
8952 afi = AFI_IP;
8953 break;
8954 case BGP_IPV6_NODE:
8955 afi = AFI_IP6;
8956 break;
8957 default:
8958 vty_out(vty,
8959 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8960 return AFI_MAX;
8961 }
8962
8963 if (!v2vimport) {
8964 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8965 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8966 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8967 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8968 vty_out(vty,
8969 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8970 return AFI_MAX;
8971 }
8972 } else {
8973 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8974 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8975 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8976 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8977 vty_out(vty,
8978 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8979 return AFI_MAX;
8980 }
8981 }
8982 return afi;
8983 }
8984
8985 DEFPY (af_rd_vpn_export,
8986 af_rd_vpn_export_cmd,
8987 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8988 NO_STR
8989 "Specify route distinguisher\n"
8990 "Between current address-family and vpn\n"
8991 "For routes leaked from current address-family to vpn\n"
8992 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8993 {
8994 VTY_DECLVAR_CONTEXT(bgp, bgp);
8995 struct prefix_rd prd;
8996 int ret;
8997 afi_t afi;
8998 int idx = 0;
8999 bool yes = true;
9000
9001 if (argv_find(argv, argc, "no", &idx))
9002 yes = false;
9003
9004 if (yes) {
9005 ret = str2prefix_rd(rd_str, &prd);
9006 if (!ret) {
9007 vty_out(vty, "%% Malformed rd\n");
9008 return CMD_WARNING_CONFIG_FAILED;
9009 }
9010 }
9011
9012 afi = vpn_policy_getafi(vty, bgp, false);
9013 if (afi == AFI_MAX)
9014 return CMD_WARNING_CONFIG_FAILED;
9015
9016 /*
9017 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9018 */
9019 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9020 bgp_get_default(), bgp);
9021
9022 if (yes) {
9023 bgp->vpn_policy[afi].tovpn_rd = prd;
9024 SET_FLAG(bgp->vpn_policy[afi].flags,
9025 BGP_VPN_POLICY_TOVPN_RD_SET);
9026 } else {
9027 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9028 BGP_VPN_POLICY_TOVPN_RD_SET);
9029 }
9030
9031 /* post-change: re-export vpn routes */
9032 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9033 bgp_get_default(), bgp);
9034
9035 return CMD_SUCCESS;
9036 }
9037
9038 ALIAS (af_rd_vpn_export,
9039 af_no_rd_vpn_export_cmd,
9040 "no rd vpn export",
9041 NO_STR
9042 "Specify route distinguisher\n"
9043 "Between current address-family and vpn\n"
9044 "For routes leaked from current address-family to vpn\n")
9045
9046 DEFPY (af_label_vpn_export,
9047 af_label_vpn_export_cmd,
9048 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9049 NO_STR
9050 "label value for VRF\n"
9051 "Between current address-family and vpn\n"
9052 "For routes leaked from current address-family to vpn\n"
9053 "Label Value <0-1048575>\n"
9054 "Automatically assign a label\n")
9055 {
9056 VTY_DECLVAR_CONTEXT(bgp, bgp);
9057 mpls_label_t label = MPLS_LABEL_NONE;
9058 afi_t afi;
9059 int idx = 0;
9060 bool yes = true;
9061
9062 if (argv_find(argv, argc, "no", &idx))
9063 yes = false;
9064
9065 /* If "no ...", squash trailing parameter */
9066 if (!yes)
9067 label_auto = NULL;
9068
9069 if (yes) {
9070 if (!label_auto)
9071 label = label_val; /* parser should force unsigned */
9072 }
9073
9074 afi = vpn_policy_getafi(vty, bgp, false);
9075 if (afi == AFI_MAX)
9076 return CMD_WARNING_CONFIG_FAILED;
9077
9078
9079 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9080 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9081 /* no change */
9082 return CMD_SUCCESS;
9083
9084 /*
9085 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9086 */
9087 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9088 bgp_get_default(), bgp);
9089
9090 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9091 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9092
9093 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9094
9095 /*
9096 * label has previously been automatically
9097 * assigned by labelpool: release it
9098 *
9099 * NB if tovpn_label == MPLS_LABEL_NONE it
9100 * means the automatic assignment is in flight
9101 * and therefore the labelpool callback must
9102 * detect that the auto label is not needed.
9103 */
9104
9105 bgp_lp_release(LP_TYPE_VRF,
9106 &bgp->vpn_policy[afi],
9107 bgp->vpn_policy[afi].tovpn_label);
9108 }
9109 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9110 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9111 }
9112
9113 bgp->vpn_policy[afi].tovpn_label = label;
9114 if (label_auto) {
9115 SET_FLAG(bgp->vpn_policy[afi].flags,
9116 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9117 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9118 vpn_leak_label_callback);
9119 }
9120
9121 /* post-change: re-export vpn routes */
9122 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9123 bgp_get_default(), bgp);
9124
9125 hook_call(bgp_snmp_update_last_changed, bgp);
9126 return CMD_SUCCESS;
9127 }
9128
9129 DEFPY (af_sid_vpn_export,
9130 af_sid_vpn_export_cmd,
9131 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9132 NO_STR
9133 "sid value for VRF\n"
9134 "Between current address-family and vpn\n"
9135 "For routes leaked from current address-family to vpn\n"
9136 "Sid allocation index\n"
9137 "Automatically assign a label\n")
9138 {
9139 VTY_DECLVAR_CONTEXT(bgp, bgp);
9140 afi_t afi;
9141 int debug = 0;
9142 int idx = 0;
9143 bool yes = true;
9144
9145 if (argv_find(argv, argc, "no", &idx))
9146 yes = false;
9147 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9148 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9149
9150 afi = vpn_policy_getafi(vty, bgp, false);
9151 if (afi == AFI_MAX)
9152 return CMD_WARNING_CONFIG_FAILED;
9153
9154 if (!yes) {
9155 /* implement me */
9156 vty_out(vty, "It's not implemented\n");
9157 return CMD_WARNING_CONFIG_FAILED;
9158 }
9159
9160 if (bgp->tovpn_sid_index != 0 ||
9161 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9162 vty_out(vty,
9163 "per-vrf sid and per-af sid are mutually exclusive\n"
9164 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9165 return CMD_WARNING_CONFIG_FAILED;
9166 }
9167
9168 /* skip when it's already configured */
9169 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9170 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9171 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9172 return CMD_SUCCESS;
9173
9174 /*
9175 * mode change between sid_idx and sid_auto isn't supported.
9176 * user must negate sid vpn export when they want to change the mode
9177 */
9178 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9179 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9180 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9181 vty_out(vty, "it's already configured as %s.\n",
9182 sid_auto ? "auto-mode" : "idx-mode");
9183 return CMD_WARNING_CONFIG_FAILED;
9184 }
9185
9186 /* pre-change */
9187 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9188 bgp_get_default(), bgp);
9189
9190 if (sid_auto) {
9191 /* SID allocation auto-mode */
9192 if (debug)
9193 zlog_debug("%s: auto sid alloc.", __func__);
9194 SET_FLAG(bgp->vpn_policy[afi].flags,
9195 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9196 } else {
9197 /* SID allocation index-mode */
9198 if (debug)
9199 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9200 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9201 }
9202
9203 /* post-change */
9204 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9205 bgp_get_default(), bgp);
9206 return CMD_SUCCESS;
9207 }
9208
9209 DEFPY (bgp_sid_vpn_export,
9210 bgp_sid_vpn_export_cmd,
9211 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9212 NO_STR
9213 "sid value for VRF\n"
9214 "Between current vrf and vpn\n"
9215 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9216 "For routes leaked from current vrf to vpn\n"
9217 "Sid allocation index\n"
9218 "Automatically assign a label\n")
9219 {
9220 VTY_DECLVAR_CONTEXT(bgp, bgp);
9221 int debug;
9222
9223 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9224 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9225
9226 if (no) {
9227 /* when per-VRF SID is not set, do nothing */
9228 if (bgp->tovpn_sid_index == 0 &&
9229 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9230 return CMD_SUCCESS;
9231
9232 sid_idx = 0;
9233 sid_auto = false;
9234 bgp->tovpn_sid_index = 0;
9235 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9236 }
9237
9238 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9239 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9240 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9241 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9242 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9243 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9244 vty_out(vty,
9245 "per-vrf sid and per-af sid are mutually exclusive\n"
9246 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9247 return CMD_WARNING_CONFIG_FAILED;
9248 }
9249
9250 /* skip when it's already configured */
9251 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9252 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9253 return CMD_SUCCESS;
9254
9255 /*
9256 * mode change between sid_idx and sid_auto isn't supported.
9257 * user must negate sid vpn export when they want to change the mode
9258 */
9259 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9260 (sid_idx != 0 &&
9261 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9262 vty_out(vty, "it's already configured as %s.\n",
9263 sid_auto ? "auto-mode" : "idx-mode");
9264 return CMD_WARNING_CONFIG_FAILED;
9265 }
9266
9267 /* pre-change */
9268 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9269 bgp);
9270 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9271 bgp);
9272
9273 if (sid_auto) {
9274 /* SID allocation auto-mode */
9275 if (debug)
9276 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9277 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9278 } else if (sid_idx != 0) {
9279 /* SID allocation index-mode */
9280 if (debug)
9281 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9282 sid_idx);
9283 bgp->tovpn_sid_index = sid_idx;
9284 }
9285
9286 /* post-change */
9287 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9288 bgp);
9289 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9290 bgp_get_default(), bgp);
9291
9292 return CMD_SUCCESS;
9293 }
9294
9295 ALIAS (af_label_vpn_export,
9296 af_no_label_vpn_export_cmd,
9297 "no label vpn export",
9298 NO_STR
9299 "label value for VRF\n"
9300 "Between current address-family and vpn\n"
9301 "For routes leaked from current address-family to vpn\n")
9302
9303 ALIAS (bgp_sid_vpn_export,
9304 no_bgp_sid_vpn_export_cmd,
9305 "no$no sid vpn per-vrf export",
9306 NO_STR
9307 "sid value for VRF\n"
9308 "Between current vrf and vpn\n"
9309 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9310 "For routes leaked from current vrf to vpn\n")
9311
9312 DEFPY (af_nexthop_vpn_export,
9313 af_nexthop_vpn_export_cmd,
9314 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9315 NO_STR
9316 "Specify next hop to use for VRF advertised prefixes\n"
9317 "Between current address-family and vpn\n"
9318 "For routes leaked from current address-family to vpn\n"
9319 "IPv4 prefix\n"
9320 "IPv6 prefix\n")
9321 {
9322 VTY_DECLVAR_CONTEXT(bgp, bgp);
9323 afi_t afi;
9324 struct prefix p;
9325
9326 if (!no) {
9327 if (!nexthop_su) {
9328 vty_out(vty, "%% Nexthop required\n");
9329 return CMD_WARNING_CONFIG_FAILED;
9330 }
9331 if (!sockunion2hostprefix(nexthop_su, &p))
9332 return CMD_WARNING_CONFIG_FAILED;
9333 }
9334
9335 afi = vpn_policy_getafi(vty, bgp, false);
9336 if (afi == AFI_MAX)
9337 return CMD_WARNING_CONFIG_FAILED;
9338
9339 /*
9340 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9341 */
9342 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9343 bgp_get_default(), bgp);
9344
9345 if (!no) {
9346 bgp->vpn_policy[afi].tovpn_nexthop = p;
9347 SET_FLAG(bgp->vpn_policy[afi].flags,
9348 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9349 } else {
9350 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9351 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9352 }
9353
9354 /* post-change: re-export vpn routes */
9355 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9356 bgp_get_default(), bgp);
9357
9358 return CMD_SUCCESS;
9359 }
9360
9361 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9362 {
9363 if (!strcmp(dstr, "import")) {
9364 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9365 } else if (!strcmp(dstr, "export")) {
9366 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9367 } else if (!strcmp(dstr, "both")) {
9368 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9369 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9370 } else {
9371 vty_out(vty, "%% direction parse error\n");
9372 return CMD_WARNING_CONFIG_FAILED;
9373 }
9374 return CMD_SUCCESS;
9375 }
9376
9377 DEFPY (af_rt_vpn_imexport,
9378 af_rt_vpn_imexport_cmd,
9379 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9380 NO_STR
9381 "Specify route target list\n"
9382 "Specify route target list\n"
9383 "Between current address-family and vpn\n"
9384 "For routes leaked from vpn to current address-family: match any\n"
9385 "For routes leaked from current address-family to vpn: set\n"
9386 "both import: match any and export: set\n"
9387 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9388 {
9389 VTY_DECLVAR_CONTEXT(bgp, bgp);
9390 int ret;
9391 struct ecommunity *ecom = NULL;
9392 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9393 enum vpn_policy_direction dir;
9394 afi_t afi;
9395 int idx = 0;
9396 bool yes = true;
9397
9398 if (argv_find(argv, argc, "no", &idx))
9399 yes = false;
9400
9401 afi = vpn_policy_getafi(vty, bgp, false);
9402 if (afi == AFI_MAX)
9403 return CMD_WARNING_CONFIG_FAILED;
9404
9405 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9406 if (ret != CMD_SUCCESS)
9407 return ret;
9408
9409 if (yes) {
9410 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9411 vty_out(vty, "%% Missing RTLIST\n");
9412 return CMD_WARNING_CONFIG_FAILED;
9413 }
9414 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9415 if (ret != CMD_SUCCESS) {
9416 return ret;
9417 }
9418 }
9419
9420 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9421 if (!dodir[dir])
9422 continue;
9423
9424 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9425
9426 if (yes) {
9427 if (bgp->vpn_policy[afi].rtlist[dir])
9428 ecommunity_free(
9429 &bgp->vpn_policy[afi].rtlist[dir]);
9430 bgp->vpn_policy[afi].rtlist[dir] =
9431 ecommunity_dup(ecom);
9432 } else {
9433 if (bgp->vpn_policy[afi].rtlist[dir])
9434 ecommunity_free(
9435 &bgp->vpn_policy[afi].rtlist[dir]);
9436 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9437 }
9438
9439 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9440 }
9441
9442 if (ecom)
9443 ecommunity_free(&ecom);
9444
9445 return CMD_SUCCESS;
9446 }
9447
9448 ALIAS (af_rt_vpn_imexport,
9449 af_no_rt_vpn_imexport_cmd,
9450 "no <rt|route-target> vpn <import|export|both>$direction_str",
9451 NO_STR
9452 "Specify route target list\n"
9453 "Specify route target list\n"
9454 "Between current address-family and vpn\n"
9455 "For routes leaked from vpn to current address-family\n"
9456 "For routes leaked from current address-family to vpn\n"
9457 "both import and export\n")
9458
9459 DEFPY (af_route_map_vpn_imexport,
9460 af_route_map_vpn_imexport_cmd,
9461 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9462 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9463 NO_STR
9464 "Specify route map\n"
9465 "Between current address-family and vpn\n"
9466 "For routes leaked from vpn to current address-family\n"
9467 "For routes leaked from current address-family to vpn\n"
9468 "name of route-map\n")
9469 {
9470 VTY_DECLVAR_CONTEXT(bgp, bgp);
9471 int ret;
9472 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9473 enum vpn_policy_direction dir;
9474 afi_t afi;
9475 int idx = 0;
9476 bool yes = true;
9477
9478 if (argv_find(argv, argc, "no", &idx))
9479 yes = false;
9480
9481 afi = vpn_policy_getafi(vty, bgp, false);
9482 if (afi == AFI_MAX)
9483 return CMD_WARNING_CONFIG_FAILED;
9484
9485 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9486 if (ret != CMD_SUCCESS)
9487 return ret;
9488
9489 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9490 if (!dodir[dir])
9491 continue;
9492
9493 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9494
9495 if (yes) {
9496 if (bgp->vpn_policy[afi].rmap_name[dir])
9497 XFREE(MTYPE_ROUTE_MAP_NAME,
9498 bgp->vpn_policy[afi].rmap_name[dir]);
9499 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9500 MTYPE_ROUTE_MAP_NAME, rmap_str);
9501 bgp->vpn_policy[afi].rmap[dir] =
9502 route_map_lookup_warn_noexist(vty, rmap_str);
9503 if (!bgp->vpn_policy[afi].rmap[dir])
9504 return CMD_SUCCESS;
9505 } else {
9506 if (bgp->vpn_policy[afi].rmap_name[dir])
9507 XFREE(MTYPE_ROUTE_MAP_NAME,
9508 bgp->vpn_policy[afi].rmap_name[dir]);
9509 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9510 bgp->vpn_policy[afi].rmap[dir] = NULL;
9511 }
9512
9513 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9514 }
9515
9516 return CMD_SUCCESS;
9517 }
9518
9519 ALIAS (af_route_map_vpn_imexport,
9520 af_no_route_map_vpn_imexport_cmd,
9521 "no route-map vpn <import|export>$direction_str",
9522 NO_STR
9523 "Specify route map\n"
9524 "Between current address-family and vpn\n"
9525 "For routes leaked from vpn to current address-family\n"
9526 "For routes leaked from current address-family to vpn\n")
9527
9528 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9529 "import vrf route-map RMAP$rmap_str",
9530 "Import routes from another VRF\n"
9531 "Vrf routes being filtered\n"
9532 "Specify route map\n"
9533 "name of route-map\n")
9534 {
9535 VTY_DECLVAR_CONTEXT(bgp, bgp);
9536 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9537 afi_t afi;
9538 struct bgp *bgp_default;
9539
9540 afi = vpn_policy_getafi(vty, bgp, true);
9541 if (afi == AFI_MAX)
9542 return CMD_WARNING_CONFIG_FAILED;
9543
9544 bgp_default = bgp_get_default();
9545 if (!bgp_default) {
9546 int32_t ret;
9547 as_t as = bgp->as;
9548
9549 /* Auto-create assuming the same AS */
9550 ret = bgp_get_vty(&bgp_default, &as, NULL,
9551 BGP_INSTANCE_TYPE_DEFAULT);
9552
9553 if (ret) {
9554 vty_out(vty,
9555 "VRF default is not configured as a bgp instance\n");
9556 return CMD_WARNING;
9557 }
9558 }
9559
9560 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9561
9562 if (bgp->vpn_policy[afi].rmap_name[dir])
9563 XFREE(MTYPE_ROUTE_MAP_NAME,
9564 bgp->vpn_policy[afi].rmap_name[dir]);
9565 bgp->vpn_policy[afi].rmap_name[dir] =
9566 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9567 bgp->vpn_policy[afi].rmap[dir] =
9568 route_map_lookup_warn_noexist(vty, rmap_str);
9569 if (!bgp->vpn_policy[afi].rmap[dir])
9570 return CMD_SUCCESS;
9571
9572 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9573 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9574
9575 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9576
9577 return CMD_SUCCESS;
9578 }
9579
9580 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9581 "no import vrf route-map [RMAP$rmap_str]",
9582 NO_STR
9583 "Import routes from another VRF\n"
9584 "Vrf routes being filtered\n"
9585 "Specify route map\n"
9586 "name of route-map\n")
9587 {
9588 VTY_DECLVAR_CONTEXT(bgp, bgp);
9589 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9590 afi_t afi;
9591
9592 afi = vpn_policy_getafi(vty, bgp, true);
9593 if (afi == AFI_MAX)
9594 return CMD_WARNING_CONFIG_FAILED;
9595
9596 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9597
9598 if (bgp->vpn_policy[afi].rmap_name[dir])
9599 XFREE(MTYPE_ROUTE_MAP_NAME,
9600 bgp->vpn_policy[afi].rmap_name[dir]);
9601 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9602 bgp->vpn_policy[afi].rmap[dir] = NULL;
9603
9604 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9605 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9606 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9607
9608 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9609
9610 return CMD_SUCCESS;
9611 }
9612
9613 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9614 "[no] import vrf VIEWVRFNAME$import_name",
9615 NO_STR
9616 "Import routes from another VRF\n"
9617 "VRF to import from\n"
9618 "The name of the VRF\n")
9619 {
9620 VTY_DECLVAR_CONTEXT(bgp, bgp);
9621 struct listnode *node;
9622 struct bgp *vrf_bgp, *bgp_default;
9623 int32_t ret = 0;
9624 as_t as = bgp->as;
9625 bool remove = false;
9626 int32_t idx = 0;
9627 char *vname;
9628 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9629 safi_t safi;
9630 afi_t afi;
9631
9632 if (import_name == NULL) {
9633 vty_out(vty, "%% Missing import name\n");
9634 return CMD_WARNING;
9635 }
9636
9637 if (strcmp(import_name, "route-map") == 0) {
9638 vty_out(vty, "%% Must include route-map name\n");
9639 return CMD_WARNING;
9640 }
9641
9642 if (argv_find(argv, argc, "no", &idx))
9643 remove = true;
9644
9645 afi = vpn_policy_getafi(vty, bgp, true);
9646 if (afi == AFI_MAX)
9647 return CMD_WARNING_CONFIG_FAILED;
9648
9649 safi = bgp_node_safi(vty);
9650
9651 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9652 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9653 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9654 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9655 remove ? "unimport" : "import", import_name);
9656 return CMD_WARNING;
9657 }
9658
9659 bgp_default = bgp_get_default();
9660 if (!bgp_default) {
9661 /* Auto-create assuming the same AS */
9662 ret = bgp_get_vty(&bgp_default, &as, NULL,
9663 BGP_INSTANCE_TYPE_DEFAULT);
9664
9665 if (ret) {
9666 vty_out(vty,
9667 "VRF default is not configured as a bgp instance\n");
9668 return CMD_WARNING;
9669 }
9670 }
9671
9672 vrf_bgp = bgp_lookup_by_name(import_name);
9673 if (!vrf_bgp) {
9674 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9675 vrf_bgp = bgp_default;
9676 else
9677 /* Auto-create assuming the same AS */
9678 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9679
9680 if (ret) {
9681 vty_out(vty,
9682 "VRF %s is not configured as a bgp instance\n",
9683 import_name);
9684 return CMD_WARNING;
9685 }
9686 }
9687
9688 if (remove) {
9689 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9690 } else {
9691 /* Already importing from "import_vrf"? */
9692 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9693 vname)) {
9694 if (strcmp(vname, import_name) == 0)
9695 return CMD_WARNING;
9696 }
9697
9698 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9699 }
9700
9701 return CMD_SUCCESS;
9702 }
9703
9704 /* This command is valid only in a bgp vrf instance or the default instance */
9705 DEFPY (bgp_imexport_vpn,
9706 bgp_imexport_vpn_cmd,
9707 "[no] <import|export>$direction_str vpn",
9708 NO_STR
9709 "Import routes to this address-family\n"
9710 "Export routes from this address-family\n"
9711 "to/from default instance VPN RIB\n")
9712 {
9713 VTY_DECLVAR_CONTEXT(bgp, bgp);
9714 int previous_state;
9715 afi_t afi;
9716 safi_t safi;
9717 int idx = 0;
9718 bool yes = true;
9719 int flag;
9720 enum vpn_policy_direction dir;
9721
9722 if (argv_find(argv, argc, "no", &idx))
9723 yes = false;
9724
9725 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9726 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9727
9728 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9729 return CMD_WARNING_CONFIG_FAILED;
9730 }
9731
9732 afi = bgp_node_afi(vty);
9733 safi = bgp_node_safi(vty);
9734 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9735 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9736 return CMD_WARNING_CONFIG_FAILED;
9737 }
9738
9739 if (!strcmp(direction_str, "import")) {
9740 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9741 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9742 } else if (!strcmp(direction_str, "export")) {
9743 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9744 dir = BGP_VPN_POLICY_DIR_TOVPN;
9745 } else {
9746 vty_out(vty, "%% unknown direction %s\n", direction_str);
9747 return CMD_WARNING_CONFIG_FAILED;
9748 }
9749
9750 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9751
9752 if (yes) {
9753 SET_FLAG(bgp->af_flags[afi][safi], flag);
9754 if (!previous_state) {
9755 /* trigger export current vrf */
9756 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9757 }
9758 } else {
9759 if (previous_state) {
9760 /* trigger un-export current vrf */
9761 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9762 }
9763 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9764 }
9765
9766 hook_call(bgp_snmp_init_stats, bgp);
9767
9768 return CMD_SUCCESS;
9769 }
9770
9771 DEFPY (af_routetarget_import,
9772 af_routetarget_import_cmd,
9773 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9774 NO_STR
9775 "Specify route target list\n"
9776 "Specify route target list\n"
9777 "Specify route target list\n"
9778 "Specify route target list\n"
9779 "Flow-spec redirect type route target\n"
9780 "Import routes to this address-family\n"
9781 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9782 {
9783 VTY_DECLVAR_CONTEXT(bgp, bgp);
9784 int ret;
9785 struct ecommunity *ecom = NULL;
9786 afi_t afi;
9787 int idx = 0, idx_unused = 0;
9788 bool yes = true;
9789 bool rt6 = false;
9790
9791 if (argv_find(argv, argc, "no", &idx))
9792 yes = false;
9793
9794 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9795 argv_find(argv, argc, "route-target6", &idx_unused))
9796 rt6 = true;
9797
9798 afi = vpn_policy_getafi(vty, bgp, false);
9799 if (afi == AFI_MAX)
9800 return CMD_WARNING_CONFIG_FAILED;
9801
9802 if (rt6 && afi != AFI_IP6)
9803 return CMD_WARNING_CONFIG_FAILED;
9804
9805 if (yes) {
9806 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9807 vty_out(vty, "%% Missing RTLIST\n");
9808 return CMD_WARNING_CONFIG_FAILED;
9809 }
9810 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9811 if (ret != CMD_SUCCESS)
9812 return ret;
9813 }
9814
9815 if (yes) {
9816 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9817 ecommunity_free(&bgp->vpn_policy[afi]
9818 .import_redirect_rtlist);
9819 bgp->vpn_policy[afi].import_redirect_rtlist =
9820 ecommunity_dup(ecom);
9821 } else {
9822 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9823 ecommunity_free(&bgp->vpn_policy[afi]
9824 .import_redirect_rtlist);
9825 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9826 }
9827
9828 if (ecom)
9829 ecommunity_free(&ecom);
9830
9831 return CMD_SUCCESS;
9832 }
9833
9834 DEFUN_NOSH (address_family_ipv4_safi,
9835 address_family_ipv4_safi_cmd,
9836 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9837 "Enter Address Family command mode\n"
9838 BGP_AF_STR
9839 BGP_SAFI_WITH_LABEL_HELP_STR)
9840 {
9841
9842 if (argc == 3) {
9843 VTY_DECLVAR_CONTEXT(bgp, bgp);
9844 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9845 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9846 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9847 && safi != SAFI_EVPN) {
9848 vty_out(vty,
9849 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9850 return CMD_WARNING_CONFIG_FAILED;
9851 }
9852 vty->node = bgp_node_type(AFI_IP, safi);
9853 } else
9854 vty->node = BGP_IPV4_NODE;
9855
9856 return CMD_SUCCESS;
9857 }
9858
9859 DEFUN_NOSH (address_family_ipv6_safi,
9860 address_family_ipv6_safi_cmd,
9861 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9862 "Enter Address Family command mode\n"
9863 BGP_AF_STR
9864 BGP_SAFI_WITH_LABEL_HELP_STR)
9865 {
9866 if (argc == 3) {
9867 VTY_DECLVAR_CONTEXT(bgp, bgp);
9868 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9869 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9870 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9871 && safi != SAFI_EVPN) {
9872 vty_out(vty,
9873 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9874 return CMD_WARNING_CONFIG_FAILED;
9875 }
9876 vty->node = bgp_node_type(AFI_IP6, safi);
9877 } else
9878 vty->node = BGP_IPV6_NODE;
9879
9880 return CMD_SUCCESS;
9881 }
9882
9883 #ifdef KEEP_OLD_VPN_COMMANDS
9884 DEFUN_NOSH (address_family_vpnv4,
9885 address_family_vpnv4_cmd,
9886 "address-family vpnv4 [unicast]",
9887 "Enter Address Family command mode\n"
9888 BGP_AF_STR
9889 BGP_AF_MODIFIER_STR)
9890 {
9891 vty->node = BGP_VPNV4_NODE;
9892 return CMD_SUCCESS;
9893 }
9894
9895 DEFUN_NOSH (address_family_vpnv6,
9896 address_family_vpnv6_cmd,
9897 "address-family vpnv6 [unicast]",
9898 "Enter Address Family command mode\n"
9899 BGP_AF_STR
9900 BGP_AF_MODIFIER_STR)
9901 {
9902 vty->node = BGP_VPNV6_NODE;
9903 return CMD_SUCCESS;
9904 }
9905 #endif /* KEEP_OLD_VPN_COMMANDS */
9906
9907 DEFUN_NOSH (address_family_evpn,
9908 address_family_evpn_cmd,
9909 "address-family l2vpn evpn",
9910 "Enter Address Family command mode\n"
9911 BGP_AF_STR
9912 BGP_AF_MODIFIER_STR)
9913 {
9914 VTY_DECLVAR_CONTEXT(bgp, bgp);
9915 vty->node = BGP_EVPN_NODE;
9916 return CMD_SUCCESS;
9917 }
9918
9919 DEFUN_NOSH (bgp_segment_routing_srv6,
9920 bgp_segment_routing_srv6_cmd,
9921 "segment-routing srv6",
9922 "Segment-Routing configuration\n"
9923 "Segment-Routing SRv6 configuration\n")
9924 {
9925 VTY_DECLVAR_CONTEXT(bgp, bgp);
9926 bgp->srv6_enabled = true;
9927 vty->node = BGP_SRV6_NODE;
9928 return CMD_SUCCESS;
9929 }
9930
9931 DEFUN (no_bgp_segment_routing_srv6,
9932 no_bgp_segment_routing_srv6_cmd,
9933 "no segment-routing srv6",
9934 NO_STR
9935 "Segment-Routing configuration\n"
9936 "Segment-Routing SRv6 configuration\n")
9937 {
9938 VTY_DECLVAR_CONTEXT(bgp, bgp);
9939
9940 if (strlen(bgp->srv6_locator_name) > 0)
9941 if (bgp_srv6_locator_unset(bgp) < 0)
9942 return CMD_WARNING_CONFIG_FAILED;
9943
9944 bgp->srv6_enabled = false;
9945 return CMD_SUCCESS;
9946 }
9947
9948 DEFPY (bgp_srv6_locator,
9949 bgp_srv6_locator_cmd,
9950 "locator NAME$name",
9951 "Specify SRv6 locator\n"
9952 "Specify SRv6 locator\n")
9953 {
9954 VTY_DECLVAR_CONTEXT(bgp, bgp);
9955 int ret;
9956
9957 if (strlen(bgp->srv6_locator_name) > 0
9958 && strcmp(name, bgp->srv6_locator_name) != 0) {
9959 vty_out(vty, "srv6 locator is already configured\n");
9960 return CMD_WARNING_CONFIG_FAILED;
9961 }
9962
9963 snprintf(bgp->srv6_locator_name,
9964 sizeof(bgp->srv6_locator_name), "%s", name);
9965
9966 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9967 if (ret < 0)
9968 return CMD_WARNING_CONFIG_FAILED;
9969
9970 return CMD_SUCCESS;
9971 }
9972
9973 DEFPY (no_bgp_srv6_locator,
9974 no_bgp_srv6_locator_cmd,
9975 "no locator NAME$name",
9976 NO_STR
9977 "Specify SRv6 locator\n"
9978 "Specify SRv6 locator\n")
9979 {
9980 VTY_DECLVAR_CONTEXT(bgp, bgp);
9981
9982 /* when locator isn't configured, do nothing */
9983 if (strlen(bgp->srv6_locator_name) < 1)
9984 return CMD_SUCCESS;
9985
9986 /* name validation */
9987 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9988 vty_out(vty, "%% No srv6 locator is configured\n");
9989 return CMD_WARNING_CONFIG_FAILED;
9990 }
9991
9992 /* unset locator */
9993 if (bgp_srv6_locator_unset(bgp) < 0)
9994 return CMD_WARNING_CONFIG_FAILED;
9995
9996 return CMD_SUCCESS;
9997 }
9998
9999 DEFPY (show_bgp_srv6,
10000 show_bgp_srv6_cmd,
10001 "show bgp segment-routing srv6",
10002 SHOW_STR
10003 BGP_STR
10004 "BGP Segment Routing\n"
10005 "BGP Segment Routing SRv6\n")
10006 {
10007 struct bgp *bgp;
10008 struct listnode *node;
10009 struct srv6_locator_chunk *chunk;
10010 struct bgp_srv6_function *func;
10011
10012 bgp = bgp_get_default();
10013 if (!bgp)
10014 return CMD_SUCCESS;
10015
10016 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10017 vty_out(vty, "locator_chunks:\n");
10018 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
10019 vty_out(vty, "- %pFX\n", &chunk->prefix);
10020 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10021 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10022 vty_out(vty, " func-length: %d\n",
10023 chunk->function_bits_length);
10024 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10025 }
10026
10027 vty_out(vty, "functions:\n");
10028 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
10029 vty_out(vty, "- sid: %pI6\n", &func->sid);
10030 vty_out(vty, " locator: %s\n", func->locator_name);
10031 }
10032
10033 vty_out(vty, "bgps:\n");
10034 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10035 vty_out(vty, "- name: %s\n",
10036 bgp->name ? bgp->name : "default");
10037
10038 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10039 bgp->vpn_policy[AFI_IP].tovpn_sid);
10040 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10041 bgp->vpn_policy[AFI_IP6].tovpn_sid);
10042 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
10043 }
10044
10045 return CMD_SUCCESS;
10046 }
10047
10048 DEFUN_NOSH (exit_address_family,
10049 exit_address_family_cmd,
10050 "exit-address-family",
10051 "Exit from Address Family configuration mode\n")
10052 {
10053 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10054 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10055 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10056 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
10057 || vty->node == BGP_EVPN_NODE
10058 || vty->node == BGP_FLOWSPECV4_NODE
10059 || vty->node == BGP_FLOWSPECV6_NODE)
10060 vty->node = BGP_NODE;
10061 return CMD_SUCCESS;
10062 }
10063
10064 /* Recalculate bestpath and re-advertise a prefix */
10065 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10066 const char *ip_str, afi_t afi, safi_t safi,
10067 struct prefix_rd *prd)
10068 {
10069 int ret;
10070 struct prefix match;
10071 struct bgp_dest *dest;
10072 struct bgp_dest *rm;
10073 struct bgp *bgp;
10074 struct bgp_table *table;
10075 struct bgp_table *rib;
10076
10077 /* BGP structure lookup. */
10078 if (view_name) {
10079 bgp = bgp_lookup_by_name(view_name);
10080 if (bgp == NULL) {
10081 vty_out(vty, "%% Can't find BGP instance %s\n",
10082 view_name);
10083 return CMD_WARNING;
10084 }
10085 } else {
10086 bgp = bgp_get_default();
10087 if (bgp == NULL) {
10088 vty_out(vty, "%% No BGP process is configured\n");
10089 return CMD_WARNING;
10090 }
10091 }
10092
10093 /* Check IP address argument. */
10094 ret = str2prefix(ip_str, &match);
10095 if (!ret) {
10096 vty_out(vty, "%% address is malformed\n");
10097 return CMD_WARNING;
10098 }
10099
10100 match.family = afi2family(afi);
10101 rib = bgp->rib[afi][safi];
10102
10103 if (safi == SAFI_MPLS_VPN) {
10104 for (dest = bgp_table_top(rib); dest;
10105 dest = bgp_route_next(dest)) {
10106 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10107
10108 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10109 continue;
10110
10111 table = bgp_dest_get_bgp_table_info(dest);
10112 if (table == NULL)
10113 continue;
10114
10115 rm = bgp_node_match(table, &match);
10116 if (rm != NULL) {
10117 const struct prefix *rm_p =
10118 bgp_dest_get_prefix(rm);
10119
10120 if (rm_p->prefixlen == match.prefixlen) {
10121 SET_FLAG(rm->flags,
10122 BGP_NODE_USER_CLEAR);
10123 bgp_process(bgp, rm, afi, safi);
10124 }
10125 bgp_dest_unlock_node(rm);
10126 }
10127 }
10128 } else {
10129 dest = bgp_node_match(rib, &match);
10130 if (dest != NULL) {
10131 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10132
10133 if (dest_p->prefixlen == match.prefixlen) {
10134 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10135 bgp_process(bgp, dest, afi, safi);
10136 }
10137 bgp_dest_unlock_node(dest);
10138 }
10139 }
10140
10141 return CMD_SUCCESS;
10142 }
10143
10144 /* one clear bgp command to rule them all */
10145 DEFUN (clear_ip_bgp_all,
10146 clear_ip_bgp_all_cmd,
10147 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
10148 CLEAR_STR
10149 IP_STR
10150 BGP_STR
10151 BGP_INSTANCE_HELP_STR
10152 BGP_AFI_HELP_STR
10153 BGP_AF_STR
10154 BGP_SAFI_WITH_LABEL_HELP_STR
10155 BGP_AF_MODIFIER_STR
10156 "Clear all peers\n"
10157 "BGP IPv4 neighbor to clear\n"
10158 "BGP IPv6 neighbor to clear\n"
10159 "BGP neighbor on interface to clear\n"
10160 "Clear peers with the AS number\n"
10161 "Clear all external peers\n"
10162 "Clear all members of peer-group\n"
10163 "BGP peer-group name\n"
10164 BGP_SOFT_STR
10165 BGP_SOFT_IN_STR
10166 BGP_SOFT_OUT_STR
10167 BGP_SOFT_IN_STR
10168 "Push out prefix-list ORF and do inbound soft reconfig\n"
10169 BGP_SOFT_OUT_STR
10170 "Reset message statistics\n")
10171 {
10172 char *vrf = NULL;
10173
10174 afi_t afi = AFI_UNSPEC;
10175 safi_t safi = SAFI_UNSPEC;
10176 enum clear_sort clr_sort = clear_peer;
10177 enum bgp_clear_type clr_type;
10178 char *clr_arg = NULL;
10179
10180 int idx = 0;
10181
10182 /* clear [ip] bgp */
10183 if (argv_find(argv, argc, "ip", &idx))
10184 afi = AFI_IP;
10185
10186 /* [<vrf> VIEWVRFNAME] */
10187 if (argv_find(argv, argc, "vrf", &idx)) {
10188 vrf = argv[idx + 1]->arg;
10189 idx += 2;
10190 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10191 vrf = NULL;
10192 } else if (argv_find(argv, argc, "view", &idx)) {
10193 /* [<view> VIEWVRFNAME] */
10194 vrf = argv[idx + 1]->arg;
10195 idx += 2;
10196 }
10197 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10198 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10199 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10200
10201 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10202 if (argv_find(argv, argc, "*", &idx)) {
10203 clr_sort = clear_all;
10204 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10205 clr_sort = clear_peer;
10206 clr_arg = argv[idx]->arg;
10207 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10208 clr_sort = clear_peer;
10209 clr_arg = argv[idx]->arg;
10210 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10211 clr_sort = clear_group;
10212 idx++;
10213 clr_arg = argv[idx]->arg;
10214 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10215 clr_sort = clear_peer;
10216 clr_arg = argv[idx]->arg;
10217 } else if (argv_find(argv, argc, "WORD", &idx)) {
10218 clr_sort = clear_peer;
10219 clr_arg = argv[idx]->arg;
10220 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10221 clr_sort = clear_as;
10222 clr_arg = argv[idx]->arg;
10223 } else if (argv_find(argv, argc, "external", &idx)) {
10224 clr_sort = clear_external;
10225 }
10226
10227 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10228 if (argv_find(argv, argc, "soft", &idx)) {
10229 if (argv_find(argv, argc, "in", &idx)
10230 || argv_find(argv, argc, "out", &idx))
10231 clr_type = strmatch(argv[idx]->text, "in")
10232 ? BGP_CLEAR_SOFT_IN
10233 : BGP_CLEAR_SOFT_OUT;
10234 else
10235 clr_type = BGP_CLEAR_SOFT_BOTH;
10236 } else if (argv_find(argv, argc, "in", &idx)) {
10237 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10238 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10239 : BGP_CLEAR_SOFT_IN;
10240 } else if (argv_find(argv, argc, "out", &idx)) {
10241 clr_type = BGP_CLEAR_SOFT_OUT;
10242 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10243 clr_type = BGP_CLEAR_MESSAGE_STATS;
10244 } else
10245 clr_type = BGP_CLEAR_SOFT_NONE;
10246
10247 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10248 }
10249
10250 DEFUN (clear_ip_bgp_prefix,
10251 clear_ip_bgp_prefix_cmd,
10252 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10253 CLEAR_STR
10254 IP_STR
10255 BGP_STR
10256 BGP_INSTANCE_HELP_STR
10257 "Clear bestpath and re-advertise\n"
10258 "IPv4 prefix\n")
10259 {
10260 char *vrf = NULL;
10261 char *prefix = NULL;
10262
10263 int idx = 0;
10264
10265 /* [<view|vrf> VIEWVRFNAME] */
10266 if (argv_find(argv, argc, "vrf", &idx)) {
10267 vrf = argv[idx + 1]->arg;
10268 idx += 2;
10269 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10270 vrf = NULL;
10271 } else if (argv_find(argv, argc, "view", &idx)) {
10272 /* [<view> VIEWVRFNAME] */
10273 vrf = argv[idx + 1]->arg;
10274 idx += 2;
10275 }
10276
10277 prefix = argv[argc - 1]->arg;
10278
10279 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10280 }
10281
10282 DEFUN (clear_bgp_ipv6_safi_prefix,
10283 clear_bgp_ipv6_safi_prefix_cmd,
10284 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10285 CLEAR_STR
10286 IP_STR
10287 BGP_STR
10288 BGP_AF_STR
10289 BGP_SAFI_HELP_STR
10290 "Clear bestpath and re-advertise\n"
10291 "IPv6 prefix\n")
10292 {
10293 int idx_safi = 0;
10294 int idx_ipv6_prefix = 0;
10295 safi_t safi = SAFI_UNICAST;
10296 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10297 argv[idx_ipv6_prefix]->arg : NULL;
10298
10299 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10300 return bgp_clear_prefix(
10301 vty, NULL, prefix, AFI_IP6,
10302 safi, NULL);
10303 }
10304
10305 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10306 clear_bgp_instance_ipv6_safi_prefix_cmd,
10307 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10308 CLEAR_STR
10309 IP_STR
10310 BGP_STR
10311 BGP_INSTANCE_HELP_STR
10312 BGP_AF_STR
10313 BGP_SAFI_HELP_STR
10314 "Clear bestpath and re-advertise\n"
10315 "IPv6 prefix\n")
10316 {
10317 int idx_safi = 0;
10318 int idx_vrfview = 0;
10319 int idx_ipv6_prefix = 0;
10320 safi_t safi = SAFI_UNICAST;
10321 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10322 argv[idx_ipv6_prefix]->arg : NULL;
10323 char *vrfview = NULL;
10324
10325 /* [<view|vrf> VIEWVRFNAME] */
10326 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10327 vrfview = argv[idx_vrfview + 1]->arg;
10328 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10329 vrfview = NULL;
10330 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10331 /* [<view> VIEWVRFNAME] */
10332 vrfview = argv[idx_vrfview + 1]->arg;
10333 }
10334 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10335
10336 return bgp_clear_prefix(
10337 vty, vrfview, prefix,
10338 AFI_IP6, safi, NULL);
10339 }
10340
10341 DEFUN (show_bgp_views,
10342 show_bgp_views_cmd,
10343 "show [ip] bgp views",
10344 SHOW_STR
10345 IP_STR
10346 BGP_STR
10347 "Show the defined BGP views\n")
10348 {
10349 struct list *inst = bm->bgp;
10350 struct listnode *node;
10351 struct bgp *bgp;
10352
10353 vty_out(vty, "Defined BGP views:\n");
10354 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10355 /* Skip VRFs. */
10356 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10357 continue;
10358 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10359 bgp->as);
10360 }
10361
10362 return CMD_SUCCESS;
10363 }
10364
10365 static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10366 int *peers_estbd)
10367 {
10368 struct peer *peer;
10369 struct listnode *node;
10370
10371 *peers_cfgd = *peers_estbd = 0;
10372 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10373 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10374 continue;
10375 (*peers_cfgd)++;
10376 if (peer_established(peer))
10377 (*peers_estbd)++;
10378 }
10379 }
10380
10381 static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10382 const char *type)
10383 {
10384 int peers_cfg, peers_estb;
10385
10386 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10387
10388 if (json) {
10389 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10390 ? -1
10391 : (int64_t)bgp->vrf_id;
10392 json_object_string_add(json, "type", type);
10393 json_object_int_add(json, "vrfId", vrf_id_ui);
10394 json_object_string_addf(json, "routerId", "%pI4",
10395 &bgp->router_id);
10396 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10397 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10398 json_object_int_add(json, "l3vni", bgp->l3vni);
10399 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10400 json_object_string_add(
10401 json, "interface",
10402 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10403 }
10404 }
10405
10406 static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10407 json_object *json, const char *name,
10408 const char *type, bool use_vrf)
10409 {
10410 int peers_cfg, peers_estb;
10411
10412 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10413
10414 if (use_vrf) {
10415 if (json) {
10416 print_bgp_vrfs(bgp, vty, json, type);
10417 } else {
10418 vty_out(vty, "BGP instance %s VRF id %d\n",
10419 bgp->name_pretty,
10420 bgp->vrf_id == VRF_UNKNOWN ? -1
10421 : (int)bgp->vrf_id);
10422 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10423 vty_out(vty,
10424 "Num Configured Peers %d, Established %d\n",
10425 peers_cfg, peers_estb);
10426 if (bgp->l3vni) {
10427 vty_out(vty,
10428 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10429 bgp->l3vni,
10430 ifindex2ifname(bgp->l3vni_svi_ifindex,
10431 bgp->vrf_id),
10432 &bgp->rmac);
10433 }
10434 }
10435 } else {
10436 if (json) {
10437 print_bgp_vrfs(bgp, vty, json, type);
10438 } else {
10439 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10440 type,
10441 bgp->vrf_id == VRF_UNKNOWN ? -1
10442 : (int)bgp->vrf_id,
10443 &bgp->router_id, peers_cfg, peers_estb, name);
10444 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10445 bgp->l3vni, &bgp->rmac,
10446 ifindex2ifname(bgp->l3vni_svi_ifindex,
10447 bgp->vrf_id));
10448 }
10449 }
10450
10451 return CMD_SUCCESS;
10452 }
10453
10454 DEFPY (show_bgp_vrfs,
10455 show_bgp_vrfs_cmd,
10456 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10457 SHOW_STR
10458 IP_STR
10459 BGP_STR
10460 "Show BGP VRFs\n"
10461 "Specific VRF name\n"
10462 JSON_STR)
10463 {
10464 struct list *inst = bm->bgp;
10465 struct listnode *node;
10466 struct bgp *bgp;
10467 bool uj = use_json(argc, argv);
10468 json_object *json = NULL;
10469 json_object *json_vrfs = NULL;
10470 json_object *json_vrf = NULL;
10471 int count = 0;
10472 const char *name = vrf_name;
10473 const char *type;
10474
10475 if (uj)
10476 json = json_object_new_object();
10477
10478 if (name) {
10479 if (strmatch(name, VRF_DEFAULT_NAME)) {
10480 bgp = bgp_get_default();
10481 type = "DFLT";
10482 } else {
10483 bgp = bgp_lookup_by_name(name);
10484 type = "VRF";
10485 }
10486 if (!bgp) {
10487 if (uj)
10488 vty_json(vty, json);
10489 else
10490 vty_out(vty,
10491 "%% Specified BGP instance not found\n");
10492
10493 return CMD_WARNING;
10494 }
10495 }
10496
10497 if (vrf_name) {
10498 if (uj)
10499 json_vrf = json_object_new_object();
10500
10501 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10502 true);
10503
10504 if (uj) {
10505 json_object_object_add(json, name, json_vrf);
10506 vty_json(vty, json);
10507 }
10508
10509 return CMD_SUCCESS;
10510 }
10511
10512 if (uj)
10513 json_vrfs = json_object_new_object();
10514
10515 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10516 const char *name;
10517
10518 /* Skip Views. */
10519 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10520 continue;
10521
10522 count++;
10523 if (!uj && count == 1) {
10524 vty_out(vty,
10525 "%4s %-5s %-16s %9s %10s %-37s\n",
10526 "Type", "Id", "routerId", "#PeersCfg",
10527 "#PeersEstb", "Name");
10528 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10529 "L3-VNI", "RouterMAC", "Interface");
10530 }
10531 if (uj)
10532 json_vrf = json_object_new_object();
10533
10534 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10535 name = VRF_DEFAULT_NAME;
10536 type = "DFLT";
10537 } else {
10538 name = bgp->name;
10539 type = "VRF";
10540 }
10541
10542 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10543 false);
10544
10545 if (uj)
10546 json_object_object_add(json_vrfs, name, json_vrf);
10547 }
10548
10549 if (uj) {
10550 json_object_object_add(json, "vrfs", json_vrfs);
10551 json_object_int_add(json, "totalVrfs", count);
10552 vty_json(vty, json);
10553 } else {
10554 if (count)
10555 vty_out(vty,
10556 "\nTotal number of VRFs (including default): %d\n",
10557 count);
10558 }
10559
10560 return CMD_SUCCESS;
10561 }
10562
10563 DEFUN (show_bgp_mac_hash,
10564 show_bgp_mac_hash_cmd,
10565 "show bgp mac hash",
10566 SHOW_STR
10567 BGP_STR
10568 "Mac Address\n"
10569 "Mac Address database\n")
10570 {
10571 bgp_mac_dump_table(vty);
10572
10573 return CMD_SUCCESS;
10574 }
10575
10576 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10577 {
10578 struct vty *vty = (struct vty *)args;
10579 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10580
10581 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10582 }
10583
10584 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10585 {
10586 vty_out(vty, "self nexthop database:\n");
10587 bgp_nexthop_show_address_hash(vty, bgp);
10588
10589 vty_out(vty, "Tunnel-ip database:\n");
10590 hash_iterate(bgp->tip_hash,
10591 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10592 vty);
10593 }
10594
10595 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10596 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10597 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10598 "martian next-hops\n"
10599 "martian next-hop database\n")
10600 {
10601 struct bgp *bgp = NULL;
10602 int idx = 0;
10603 char *name = NULL;
10604
10605 /* [<vrf> VIEWVRFNAME] */
10606 if (argv_find(argv, argc, "vrf", &idx)) {
10607 name = argv[idx + 1]->arg;
10608 if (name && strmatch(name, VRF_DEFAULT_NAME))
10609 name = NULL;
10610 } else if (argv_find(argv, argc, "view", &idx))
10611 /* [<view> VIEWVRFNAME] */
10612 name = argv[idx + 1]->arg;
10613 if (name)
10614 bgp = bgp_lookup_by_name(name);
10615 else
10616 bgp = bgp_get_default();
10617
10618 if (!bgp) {
10619 vty_out(vty, "%% No BGP process is configured\n");
10620 return CMD_WARNING;
10621 }
10622 bgp_show_martian_nexthops(vty, bgp);
10623
10624 return CMD_SUCCESS;
10625 }
10626
10627 DEFUN (show_bgp_memory,
10628 show_bgp_memory_cmd,
10629 "show [ip] bgp memory",
10630 SHOW_STR
10631 IP_STR
10632 BGP_STR
10633 "Global BGP memory statistics\n")
10634 {
10635 char memstrbuf[MTYPE_MEMSTR_LEN];
10636 unsigned long count;
10637
10638 /* RIB related usage stats */
10639 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10640 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10641 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10642 count * sizeof(struct bgp_dest)));
10643
10644 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10645 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10646 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10647 count * sizeof(struct bgp_path_info)));
10648 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10649 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10650 count,
10651 mtype_memstr(
10652 memstrbuf, sizeof(memstrbuf),
10653 count * sizeof(struct bgp_path_info_extra)));
10654
10655 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10656 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10658 count * sizeof(struct bgp_static)));
10659
10660 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10661 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10662 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10663 count * sizeof(struct bpacket)));
10664
10665 /* Adj-In/Out */
10666 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10667 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10668 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10669 count * sizeof(struct bgp_adj_in)));
10670 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10671 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10672 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10673 count * sizeof(struct bgp_adj_out)));
10674
10675 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10676 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10677 count,
10678 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10679 count * sizeof(struct bgp_nexthop_cache)));
10680
10681 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10682 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10683 count,
10684 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10685 count * sizeof(struct bgp_damp_info)));
10686
10687 /* Attributes */
10688 count = attr_count();
10689 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10690 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10691 count * sizeof(struct attr)));
10692
10693 if ((count = attr_unknown_count()))
10694 vty_out(vty, "%ld unknown attributes\n", count);
10695
10696 /* AS_PATH attributes */
10697 count = aspath_count();
10698 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10699 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10700 count * sizeof(struct aspath)));
10701
10702 count = mtype_stats_alloc(MTYPE_AS_SEG);
10703 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10704 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10705 count * sizeof(struct assegment)));
10706
10707 /* Other attributes */
10708 if ((count = community_count()))
10709 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10710 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10711 count * sizeof(struct community)));
10712 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10713 vty_out(vty,
10714 "%ld BGP ext-community entries, using %s of memory\n",
10715 count,
10716 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10717 count * sizeof(struct ecommunity)));
10718 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10719 vty_out(vty,
10720 "%ld BGP large-community entries, using %s of memory\n",
10721 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10722 count * sizeof(struct lcommunity)));
10723
10724 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10725 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10726 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10727 count * sizeof(struct cluster_list)));
10728
10729 /* Peer related usage */
10730 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10731 vty_out(vty, "%ld peers, using %s of memory\n", count,
10732 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10733 count * sizeof(struct peer)));
10734
10735 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10736 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10737 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10738 count * sizeof(struct peer_group)));
10739
10740 /* Other */
10741 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10742 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10743 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10744 count * sizeof(regex_t)));
10745 return CMD_SUCCESS;
10746 }
10747
10748 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10749 {
10750 json_object *bestpath = json_object_new_object();
10751
10752 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10753 json_object_string_add(bestpath, "asPath", "ignore");
10754
10755 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10756 json_object_string_add(bestpath, "asPath", "confed");
10757
10758 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10759 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10760 json_object_string_add(bestpath, "multiPathRelax",
10761 "as-set");
10762 else
10763 json_object_string_add(bestpath, "multiPathRelax",
10764 "true");
10765 } else
10766 json_object_string_add(bestpath, "multiPathRelax", "false");
10767
10768 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10769 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10770
10771 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10772 json_object_string_add(bestpath, "compareRouterId", "true");
10773 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10774 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10775 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10776 json_object_string_add(bestpath, "med", "confed");
10777 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10778 json_object_string_add(bestpath, "med",
10779 "missing-as-worst");
10780 else
10781 json_object_string_add(bestpath, "med", "true");
10782 }
10783
10784 json_object_object_add(json, "bestPath", bestpath);
10785 }
10786
10787 /* Print the error code/subcode for why the peer is down */
10788 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10789 json_object *json_peer, bool use_json)
10790 {
10791 const char *code_str;
10792 const char *subcode_str;
10793
10794 if (use_json) {
10795 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10796 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10797 char errorcodesubcode_hexstr[5];
10798 char errorcodesubcode_str[256];
10799
10800 code_str = bgp_notify_code_str(peer->notify.code);
10801 subcode_str = bgp_notify_subcode_str(
10802 peer->notify.code,
10803 peer->notify.subcode);
10804
10805 snprintf(errorcodesubcode_hexstr,
10806 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10807 peer->notify.code, peer->notify.subcode);
10808 json_object_string_add(json_peer,
10809 "lastErrorCodeSubcode",
10810 errorcodesubcode_hexstr);
10811 snprintf(errorcodesubcode_str, 255, "%s%s",
10812 code_str, subcode_str);
10813 json_object_string_add(json_peer,
10814 "lastNotificationReason",
10815 errorcodesubcode_str);
10816 json_object_boolean_add(json_peer,
10817 "lastNotificationHardReset",
10818 peer->notify.hard_reset);
10819 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10820 && peer->notify.code == BGP_NOTIFY_CEASE
10821 && (peer->notify.subcode
10822 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10823 || peer->notify.subcode
10824 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10825 && peer->notify.length) {
10826 char msgbuf[1024];
10827 const char *msg_str;
10828
10829 msg_str = bgp_notify_admin_message(
10830 msgbuf, sizeof(msgbuf),
10831 (uint8_t *)peer->notify.data,
10832 peer->notify.length);
10833 if (msg_str)
10834 json_object_string_add(
10835 json_peer,
10836 "lastShutdownDescription",
10837 msg_str);
10838 }
10839
10840 }
10841 json_object_string_add(json_peer, "lastResetDueTo",
10842 peer_down_str[(int)peer->last_reset]);
10843 json_object_int_add(json_peer, "lastResetCode",
10844 peer->last_reset);
10845 json_object_string_add(json_peer, "softwareVersion",
10846 peer->soft_version ? peer->soft_version
10847 : "n/a");
10848 } else {
10849 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10850 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10851 code_str = bgp_notify_code_str(peer->notify.code);
10852 subcode_str =
10853 bgp_notify_subcode_str(peer->notify.code,
10854 peer->notify.subcode);
10855 vty_out(vty, " Notification %s (%s%s%s)\n",
10856 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10857 ? "sent"
10858 : "received",
10859 code_str, subcode_str,
10860 peer->notify.hard_reset
10861 ? bgp_notify_subcode_str(
10862 BGP_NOTIFY_CEASE,
10863 BGP_NOTIFY_CEASE_HARD_RESET)
10864 : "");
10865 } else {
10866 vty_out(vty, " %s (%s)\n",
10867 peer_down_str[(int)peer->last_reset],
10868 peer->soft_version ? peer->soft_version
10869 : "n/a");
10870 }
10871 }
10872 }
10873
10874 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10875 safi_t safi)
10876 {
10877 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10878 }
10879
10880 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10881 struct peer *peer, json_object *json_peer,
10882 int max_neighbor_width, bool use_json)
10883 {
10884 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10885 int len;
10886
10887 if (use_json) {
10888 if (peer_dynamic_neighbor(peer))
10889 json_object_boolean_true_add(json_peer,
10890 "dynamicPeer");
10891 if (peer->hostname)
10892 json_object_string_add(json_peer, "hostname",
10893 peer->hostname);
10894
10895 if (peer->domainname)
10896 json_object_string_add(json_peer, "domainname",
10897 peer->domainname);
10898 json_object_int_add(json_peer, "connectionsEstablished",
10899 peer->established);
10900 json_object_int_add(json_peer, "connectionsDropped",
10901 peer->dropped);
10902 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10903 use_json, json_peer);
10904 if (peer_established(peer))
10905 json_object_string_add(json_peer, "lastResetDueTo",
10906 "AFI/SAFI Not Negotiated");
10907 else
10908 bgp_show_peer_reset(NULL, peer, json_peer, true);
10909 } else {
10910 dn_flag[1] = '\0';
10911 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10912 if (peer->hostname
10913 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10914 len = vty_out(vty, "%s%s(%s)", dn_flag,
10915 peer->hostname, peer->host);
10916 else
10917 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10918
10919 /* pad the neighbor column with spaces */
10920 if (len < max_neighbor_width)
10921 vty_out(vty, "%*s", max_neighbor_width - len,
10922 " ");
10923 vty_out(vty, "%7d %7d %9s", peer->established,
10924 peer->dropped,
10925 peer_uptime(peer->uptime, timebuf,
10926 BGP_UPTIME_LEN, 0, NULL));
10927 if (peer_established(peer))
10928 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10929 else
10930 bgp_show_peer_reset(vty, peer, NULL,
10931 false);
10932 }
10933 }
10934
10935 /* Strip peer's description to the given size. */
10936 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10937 {
10938 static char stripped[BUFSIZ];
10939 uint32_t i = 0;
10940 uint32_t last_space = 0;
10941
10942 while (i < size) {
10943 if (*(desc + i) == 0) {
10944 stripped[i] = '\0';
10945 return stripped;
10946 }
10947 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10948 last_space = i;
10949 stripped[i] = *(desc + i);
10950 i++;
10951 }
10952
10953 if (last_space > size)
10954 stripped[size + 1] = '\0';
10955 else
10956 stripped[last_space] = '\0';
10957
10958 return stripped;
10959 }
10960
10961 /* Determine whether var peer should be filtered out of the summary. */
10962 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10963 struct peer *fpeer, int as_type,
10964 as_t as)
10965 {
10966
10967 /* filter neighbor XXXX */
10968 if (fpeer && fpeer != peer)
10969 return true;
10970
10971 /* filter remote-as (internal|external) */
10972 if (as_type != AS_UNSPECIFIED) {
10973 if (peer->as_type == AS_SPECIFIED) {
10974 if (as_type == AS_INTERNAL) {
10975 if (peer->as != peer->local_as)
10976 return true;
10977 } else if (peer->as == peer->local_as)
10978 return true;
10979 } else if (as_type != peer->as_type)
10980 return true;
10981 } else if (as && as != peer->as) /* filter remote-as XXX */
10982 return true;
10983
10984 return false;
10985 }
10986
10987 /* Show BGP peer's summary information.
10988 *
10989 * Peer's description is stripped according to if `wide` option is given
10990 * or not.
10991 *
10992 * When adding new columns to `show bgp summary` output, please make
10993 * sure `Desc` is the lastest column to show because it can contain
10994 * whitespaces and the whole output will be tricky.
10995 */
10996 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10997 struct peer *fpeer, int as_type, as_t as,
10998 uint16_t show_flags)
10999 {
11000 struct peer *peer;
11001 struct listnode *node, *nnode;
11002 unsigned int count = 0, dn_count = 0;
11003 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11004 char neighbor_buf[VTY_BUFSIZ];
11005 int neighbor_col_default_width = 16;
11006 int len, failed_count = 0;
11007 unsigned int filtered_count = 0;
11008 int max_neighbor_width = 0;
11009 int pfx_rcd_safi;
11010 json_object *json = NULL;
11011 json_object *json_peer = NULL;
11012 json_object *json_peers = NULL;
11013 struct peer_af *paf;
11014 struct bgp_filter *filter;
11015 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11016 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11017 bool show_established =
11018 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11019 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11020 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11021
11022 /* labeled-unicast routes are installed in the unicast table so in order
11023 * to
11024 * display the correct PfxRcd value we must look at SAFI_UNICAST
11025 */
11026
11027 if (safi == SAFI_LABELED_UNICAST)
11028 pfx_rcd_safi = SAFI_UNICAST;
11029 else
11030 pfx_rcd_safi = safi;
11031
11032 if (use_json) {
11033 json = json_object_new_object();
11034 json_peers = json_object_new_object();
11035 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11036 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11037 as_type, as)) {
11038 filtered_count++;
11039 count++;
11040 continue;
11041 }
11042
11043 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11044 continue;
11045
11046 if (peer->afc[afi][safi]) {
11047 /* See if we have at least a single failed peer */
11048 if (bgp_has_peer_failed(peer, afi, safi))
11049 failed_count++;
11050 count++;
11051 }
11052 if (peer_dynamic_neighbor(peer))
11053 dn_count++;
11054 }
11055
11056 } else {
11057 /* Loop over all neighbors that will be displayed to determine
11058 * how many
11059 * characters are needed for the Neighbor column
11060 */
11061 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11062 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11063 as_type, as)) {
11064 filtered_count++;
11065 count++;
11066 continue;
11067 }
11068
11069 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11070 continue;
11071
11072 if (peer->afc[afi][safi]) {
11073 memset(dn_flag, '\0', sizeof(dn_flag));
11074 if (peer_dynamic_neighbor(peer))
11075 dn_flag[0] = '*';
11076
11077 if (peer->hostname
11078 && CHECK_FLAG(bgp->flags,
11079 BGP_FLAG_SHOW_HOSTNAME))
11080 snprintf(neighbor_buf,
11081 sizeof(neighbor_buf),
11082 "%s%s(%s) ", dn_flag,
11083 peer->hostname, peer->host);
11084 else
11085 snprintf(neighbor_buf,
11086 sizeof(neighbor_buf), "%s%s ",
11087 dn_flag, peer->host);
11088
11089 len = strlen(neighbor_buf);
11090
11091 if (len > max_neighbor_width)
11092 max_neighbor_width = len;
11093
11094 /* See if we have at least a single failed peer */
11095 if (bgp_has_peer_failed(peer, afi, safi))
11096 failed_count++;
11097 count++;
11098 }
11099 }
11100
11101 /* Originally we displayed the Neighbor column as 16
11102 * characters wide so make that the default
11103 */
11104 if (max_neighbor_width < neighbor_col_default_width)
11105 max_neighbor_width = neighbor_col_default_width;
11106 }
11107
11108 if (show_failed && !failed_count) {
11109 if (use_json) {
11110 json_object_int_add(json, "failedPeersCount", 0);
11111 json_object_int_add(json, "dynamicPeers", dn_count);
11112 json_object_int_add(json, "totalPeers", count);
11113
11114 vty_json(vty, json);
11115 } else {
11116 vty_out(vty, "%% No failed BGP neighbors found\n");
11117 }
11118 return CMD_SUCCESS;
11119 }
11120
11121 count = 0; /* Reset the value as its used again */
11122 filtered_count = 0;
11123 dn_count = 0;
11124 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11125 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11126 continue;
11127
11128 if (!peer->afc[afi][safi])
11129 continue;
11130
11131 if (!count) {
11132 unsigned long ents;
11133 char memstrbuf[MTYPE_MEMSTR_LEN];
11134 int64_t vrf_id_ui;
11135
11136 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11137 ? -1
11138 : (int64_t)bgp->vrf_id;
11139
11140 /* Usage summary and header */
11141 if (use_json) {
11142 json_object_string_addf(json, "routerId",
11143 "%pI4",
11144 &bgp->router_id);
11145 json_object_int_add(json, "as", bgp->as);
11146 json_object_int_add(json, "vrfId", vrf_id_ui);
11147 json_object_string_add(
11148 json, "vrfName",
11149 (bgp->inst_type
11150 == BGP_INSTANCE_TYPE_DEFAULT)
11151 ? VRF_DEFAULT_NAME
11152 : bgp->name);
11153 } else {
11154 vty_out(vty,
11155 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11156 &bgp->router_id, bgp->as,
11157 bgp->vrf_id == VRF_UNKNOWN
11158 ? -1
11159 : (int)bgp->vrf_id);
11160 vty_out(vty, "\n");
11161 }
11162
11163 if (bgp_update_delay_configured(bgp)) {
11164 if (use_json) {
11165 json_object_int_add(
11166 json, "updateDelayLimit",
11167 bgp->v_update_delay);
11168
11169 if (bgp->v_update_delay
11170 != bgp->v_establish_wait)
11171 json_object_int_add(
11172 json,
11173 "updateDelayEstablishWait",
11174 bgp->v_establish_wait);
11175
11176 if (bgp_update_delay_active(bgp)) {
11177 json_object_string_add(
11178 json,
11179 "updateDelayFirstNeighbor",
11180 bgp->update_delay_begin_time);
11181 json_object_boolean_true_add(
11182 json,
11183 "updateDelayInProgress");
11184 } else {
11185 if (bgp->update_delay_over) {
11186 json_object_string_add(
11187 json,
11188 "updateDelayFirstNeighbor",
11189 bgp->update_delay_begin_time);
11190 json_object_string_add(
11191 json,
11192 "updateDelayBestpathResumed",
11193 bgp->update_delay_end_time);
11194 json_object_string_add(
11195 json,
11196 "updateDelayZebraUpdateResume",
11197 bgp->update_delay_zebra_resume_time);
11198 json_object_string_add(
11199 json,
11200 "updateDelayPeerUpdateResume",
11201 bgp->update_delay_peers_resume_time);
11202 }
11203 }
11204 } else {
11205 vty_out(vty,
11206 "Read-only mode update-delay limit: %d seconds\n",
11207 bgp->v_update_delay);
11208 if (bgp->v_update_delay
11209 != bgp->v_establish_wait)
11210 vty_out(vty,
11211 " Establish wait: %d seconds\n",
11212 bgp->v_establish_wait);
11213
11214 if (bgp_update_delay_active(bgp)) {
11215 vty_out(vty,
11216 " First neighbor established: %s\n",
11217 bgp->update_delay_begin_time);
11218 vty_out(vty,
11219 " Delay in progress\n");
11220 } else {
11221 if (bgp->update_delay_over) {
11222 vty_out(vty,
11223 " First neighbor established: %s\n",
11224 bgp->update_delay_begin_time);
11225 vty_out(vty,
11226 " Best-paths resumed: %s\n",
11227 bgp->update_delay_end_time);
11228 vty_out(vty,
11229 " zebra update resumed: %s\n",
11230 bgp->update_delay_zebra_resume_time);
11231 vty_out(vty,
11232 " peers update resumed: %s\n",
11233 bgp->update_delay_peers_resume_time);
11234 }
11235 }
11236 }
11237 }
11238
11239 if (use_json) {
11240 if (bgp_maxmed_onstartup_configured(bgp)
11241 && bgp->maxmed_active)
11242 json_object_boolean_true_add(
11243 json, "maxMedOnStartup");
11244 if (bgp->v_maxmed_admin)
11245 json_object_boolean_true_add(
11246 json, "maxMedAdministrative");
11247
11248 json_object_int_add(
11249 json, "tableVersion",
11250 bgp_table_version(bgp->rib[afi][safi]));
11251
11252 ents = bgp_table_count(bgp->rib[afi][safi]);
11253 json_object_int_add(json, "ribCount", ents);
11254 json_object_int_add(
11255 json, "ribMemory",
11256 ents * sizeof(struct bgp_dest));
11257
11258 ents = bgp->af_peer_count[afi][safi];
11259 json_object_int_add(json, "peerCount", ents);
11260 json_object_int_add(json, "peerMemory",
11261 ents * sizeof(struct peer));
11262
11263 if ((ents = listcount(bgp->group))) {
11264 json_object_int_add(
11265 json, "peerGroupCount", ents);
11266 json_object_int_add(
11267 json, "peerGroupMemory",
11268 ents * sizeof(struct
11269 peer_group));
11270 }
11271
11272 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11273 BGP_CONFIG_DAMPENING))
11274 json_object_boolean_true_add(
11275 json, "dampeningEnabled");
11276 } else {
11277 if (!show_terse) {
11278 if (bgp_maxmed_onstartup_configured(bgp)
11279 && bgp->maxmed_active)
11280 vty_out(vty,
11281 "Max-med on-startup active\n");
11282 if (bgp->v_maxmed_admin)
11283 vty_out(vty,
11284 "Max-med administrative active\n");
11285
11286 vty_out(vty,
11287 "BGP table version %" PRIu64
11288 "\n",
11289 bgp_table_version(
11290 bgp->rib[afi][safi]));
11291
11292 ents = bgp_table_count(
11293 bgp->rib[afi][safi]);
11294 vty_out(vty,
11295 "RIB entries %ld, using %s of memory\n",
11296 ents,
11297 mtype_memstr(
11298 memstrbuf,
11299 sizeof(memstrbuf),
11300 ents
11301 * sizeof(
11302 struct
11303 bgp_dest)));
11304
11305 /* Peer related usage */
11306 ents = bgp->af_peer_count[afi][safi];
11307 vty_out(vty,
11308 "Peers %ld, using %s of memory\n",
11309 ents,
11310 mtype_memstr(
11311 memstrbuf,
11312 sizeof(memstrbuf),
11313 ents
11314 * sizeof(
11315 struct
11316 peer)));
11317
11318 if ((ents = listcount(bgp->group)))
11319 vty_out(vty,
11320 "Peer groups %ld, using %s of memory\n",
11321 ents,
11322 mtype_memstr(
11323 memstrbuf,
11324 sizeof(memstrbuf),
11325 ents
11326 * sizeof(
11327 struct
11328 peer_group)));
11329
11330 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11331 BGP_CONFIG_DAMPENING))
11332 vty_out(vty,
11333 "Dampening enabled.\n");
11334 }
11335 if (show_failed) {
11336 vty_out(vty, "\n");
11337
11338 /* Subtract 8 here because 'Neighbor' is
11339 * 8 characters */
11340 vty_out(vty, "Neighbor");
11341 vty_out(vty, "%*s",
11342 max_neighbor_width - 8, " ");
11343 vty_out(vty,
11344 BGP_SHOW_SUMMARY_HEADER_FAILED);
11345 }
11346 }
11347 }
11348
11349 paf = peer_af_find(peer, afi, safi);
11350 filter = &peer->filter[afi][safi];
11351
11352 count++;
11353 /* Works for both failed & successful cases */
11354 if (peer_dynamic_neighbor(peer))
11355 dn_count++;
11356
11357 if (use_json) {
11358 json_peer = NULL;
11359 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11360 as_type, as)) {
11361 filtered_count++;
11362 continue;
11363 }
11364 if (show_failed &&
11365 bgp_has_peer_failed(peer, afi, safi)) {
11366 json_peer = json_object_new_object();
11367 bgp_show_failed_summary(vty, bgp, peer,
11368 json_peer, 0, use_json);
11369 } else if (!show_failed) {
11370 if (show_established
11371 && bgp_has_peer_failed(peer, afi, safi)) {
11372 filtered_count++;
11373 continue;
11374 }
11375
11376 json_peer = json_object_new_object();
11377 if (peer_dynamic_neighbor(peer)) {
11378 json_object_boolean_true_add(json_peer,
11379 "dynamicPeer");
11380 }
11381
11382 if (peer->hostname)
11383 json_object_string_add(json_peer, "hostname",
11384 peer->hostname);
11385
11386 if (peer->domainname)
11387 json_object_string_add(json_peer, "domainname",
11388 peer->domainname);
11389
11390 json_object_int_add(json_peer, "remoteAs", peer->as);
11391 json_object_int_add(
11392 json_peer, "localAs",
11393 peer->change_local_as
11394 ? peer->change_local_as
11395 : peer->local_as);
11396 json_object_int_add(json_peer, "version", 4);
11397 json_object_int_add(json_peer, "msgRcvd",
11398 PEER_TOTAL_RX(peer));
11399 json_object_int_add(json_peer, "msgSent",
11400 PEER_TOTAL_TX(peer));
11401
11402 atomic_size_t outq_count, inq_count;
11403 outq_count = atomic_load_explicit(
11404 &peer->obuf->count,
11405 memory_order_relaxed);
11406 inq_count = atomic_load_explicit(
11407 &peer->ibuf->count,
11408 memory_order_relaxed);
11409
11410 json_object_int_add(json_peer, "tableVersion",
11411 peer->version[afi][safi]);
11412 json_object_int_add(json_peer, "outq",
11413 outq_count);
11414 json_object_int_add(json_peer, "inq",
11415 inq_count);
11416 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11417 use_json, json_peer);
11418
11419 json_object_int_add(json_peer, "pfxRcd",
11420 peer->pcount[afi][pfx_rcd_safi]);
11421
11422 if (paf && PAF_SUBGRP(paf))
11423 json_object_int_add(
11424 json_peer, "pfxSnt",
11425 (PAF_SUBGRP(paf))->scount);
11426 else
11427 json_object_int_add(json_peer, "pfxSnt",
11428 0);
11429
11430 /* BGP FSM state */
11431 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11432 || CHECK_FLAG(peer->bgp->flags,
11433 BGP_FLAG_SHUTDOWN))
11434 json_object_string_add(json_peer,
11435 "state",
11436 "Idle (Admin)");
11437 else if (peer->afc_recv[afi][safi])
11438 json_object_string_add(
11439 json_peer, "state",
11440 lookup_msg(bgp_status_msg,
11441 peer->status, NULL));
11442 else if (CHECK_FLAG(
11443 peer->sflags,
11444 PEER_STATUS_PREFIX_OVERFLOW))
11445 json_object_string_add(json_peer,
11446 "state",
11447 "Idle (PfxCt)");
11448 else
11449 json_object_string_add(
11450 json_peer, "state",
11451 lookup_msg(bgp_status_msg,
11452 peer->status, NULL));
11453
11454 /* BGP peer state */
11455 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11456 || CHECK_FLAG(peer->bgp->flags,
11457 BGP_FLAG_SHUTDOWN))
11458 json_object_string_add(json_peer,
11459 "peerState",
11460 "Admin");
11461 else if (CHECK_FLAG(
11462 peer->sflags,
11463 PEER_STATUS_PREFIX_OVERFLOW))
11464 json_object_string_add(json_peer,
11465 "peerState",
11466 "PfxCt");
11467 else if (CHECK_FLAG(peer->flags,
11468 PEER_FLAG_PASSIVE))
11469 json_object_string_add(json_peer,
11470 "peerState",
11471 "Passive");
11472 else if (CHECK_FLAG(peer->sflags,
11473 PEER_STATUS_NSF_WAIT))
11474 json_object_string_add(json_peer,
11475 "peerState",
11476 "NSF passive");
11477 else if (CHECK_FLAG(
11478 peer->bgp->flags,
11479 BGP_FLAG_EBGP_REQUIRES_POLICY)
11480 && (!bgp_inbound_policy_exists(peer,
11481 filter)
11482 || !bgp_outbound_policy_exists(
11483 peer, filter)))
11484 json_object_string_add(json_peer,
11485 "peerState",
11486 "Policy");
11487 else
11488 json_object_string_add(
11489 json_peer, "peerState", "OK");
11490
11491 json_object_int_add(json_peer, "connectionsEstablished",
11492 peer->established);
11493 json_object_int_add(json_peer, "connectionsDropped",
11494 peer->dropped);
11495 if (peer->desc)
11496 json_object_string_add(
11497 json_peer, "desc", peer->desc);
11498 }
11499 /* Avoid creating empty peer dicts in JSON */
11500 if (json_peer == NULL)
11501 continue;
11502
11503 if (peer->conf_if)
11504 json_object_string_add(json_peer, "idType",
11505 "interface");
11506 else if (peer->su.sa.sa_family == AF_INET)
11507 json_object_string_add(json_peer, "idType",
11508 "ipv4");
11509 else if (peer->su.sa.sa_family == AF_INET6)
11510 json_object_string_add(json_peer, "idType",
11511 "ipv6");
11512 json_object_object_add(json_peers, peer->host,
11513 json_peer);
11514 } else {
11515 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11516 as_type, as)) {
11517 filtered_count++;
11518 continue;
11519 }
11520 if (show_failed &&
11521 bgp_has_peer_failed(peer, afi, safi)) {
11522 bgp_show_failed_summary(vty, bgp, peer, NULL,
11523 max_neighbor_width,
11524 use_json);
11525 } else if (!show_failed) {
11526 if (show_established
11527 && bgp_has_peer_failed(peer, afi, safi)) {
11528 filtered_count++;
11529 continue;
11530 }
11531
11532 if ((count - filtered_count) == 1) {
11533 /* display headline before the first
11534 * neighbor line */
11535 vty_out(vty, "\n");
11536
11537 /* Subtract 8 here because 'Neighbor' is
11538 * 8 characters */
11539 vty_out(vty, "Neighbor");
11540 vty_out(vty, "%*s",
11541 max_neighbor_width - 8, " ");
11542 vty_out(vty,
11543 show_wide
11544 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11545 : BGP_SHOW_SUMMARY_HEADER_ALL);
11546 }
11547
11548 memset(dn_flag, '\0', sizeof(dn_flag));
11549 if (peer_dynamic_neighbor(peer)) {
11550 dn_flag[0] = '*';
11551 }
11552
11553 if (peer->hostname
11554 && CHECK_FLAG(bgp->flags,
11555 BGP_FLAG_SHOW_HOSTNAME))
11556 len = vty_out(vty, "%s%s(%s)", dn_flag,
11557 peer->hostname,
11558 peer->host);
11559 else
11560 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11561
11562 /* pad the neighbor column with spaces */
11563 if (len < max_neighbor_width)
11564 vty_out(vty, "%*s", max_neighbor_width - len,
11565 " ");
11566
11567 atomic_size_t outq_count, inq_count;
11568 outq_count = atomic_load_explicit(
11569 &peer->obuf->count,
11570 memory_order_relaxed);
11571 inq_count = atomic_load_explicit(
11572 &peer->ibuf->count,
11573 memory_order_relaxed);
11574
11575 if (show_wide)
11576 vty_out(vty,
11577 "4 %10u %10u %9u %9u %8" PRIu64
11578 " %4zu %4zu %8s",
11579 peer->as,
11580 peer->change_local_as
11581 ? peer->change_local_as
11582 : peer->local_as,
11583 PEER_TOTAL_RX(peer),
11584 PEER_TOTAL_TX(peer),
11585 peer->version[afi][safi],
11586 inq_count, outq_count,
11587 peer_uptime(peer->uptime,
11588 timebuf,
11589 BGP_UPTIME_LEN, 0,
11590 NULL));
11591 else
11592 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11593 " %4zu %4zu %8s",
11594 peer->as, PEER_TOTAL_RX(peer),
11595 PEER_TOTAL_TX(peer),
11596 peer->version[afi][safi],
11597 inq_count, outq_count,
11598 peer_uptime(peer->uptime,
11599 timebuf,
11600 BGP_UPTIME_LEN, 0,
11601 NULL));
11602
11603 if (peer_established(peer)) {
11604 if (peer->afc_recv[afi][safi]) {
11605 if (CHECK_FLAG(
11606 bgp->flags,
11607 BGP_FLAG_EBGP_REQUIRES_POLICY)
11608 && !bgp_inbound_policy_exists(
11609 peer, filter))
11610 vty_out(vty, " %12s",
11611 "(Policy)");
11612 else
11613 vty_out(vty,
11614 " %12u",
11615 peer->pcount
11616 [afi]
11617 [pfx_rcd_safi]);
11618 } else {
11619 vty_out(vty, " NoNeg");
11620 }
11621
11622 if (paf && PAF_SUBGRP(paf)) {
11623 if (CHECK_FLAG(
11624 bgp->flags,
11625 BGP_FLAG_EBGP_REQUIRES_POLICY)
11626 && !bgp_outbound_policy_exists(
11627 peer, filter))
11628 vty_out(vty, " %8s",
11629 "(Policy)");
11630 else
11631 vty_out(vty,
11632 " %8u",
11633 (PAF_SUBGRP(
11634 paf))
11635 ->scount);
11636 } else {
11637 vty_out(vty, " NoNeg");
11638 }
11639 } else {
11640 if (CHECK_FLAG(peer->flags,
11641 PEER_FLAG_SHUTDOWN)
11642 || CHECK_FLAG(peer->bgp->flags,
11643 BGP_FLAG_SHUTDOWN))
11644 vty_out(vty, " Idle (Admin)");
11645 else if (CHECK_FLAG(
11646 peer->sflags,
11647 PEER_STATUS_PREFIX_OVERFLOW))
11648 vty_out(vty, " Idle (PfxCt)");
11649 else
11650 vty_out(vty, " %12s",
11651 lookup_msg(bgp_status_msg,
11652 peer->status, NULL));
11653
11654 vty_out(vty, " %8u", 0);
11655 }
11656 /* Make sure `Desc` column is the lastest in
11657 * the output.
11658 */
11659 if (peer->desc)
11660 vty_out(vty, " %s",
11661 bgp_peer_description_stripped(
11662 peer->desc,
11663 show_wide ? 64 : 20));
11664 else
11665 vty_out(vty, " N/A");
11666 vty_out(vty, "\n");
11667 }
11668
11669 }
11670 }
11671
11672 if (use_json) {
11673 json_object_object_add(json, "peers", json_peers);
11674 json_object_int_add(json, "failedPeers", failed_count);
11675 json_object_int_add(json, "displayedPeers",
11676 count - filtered_count);
11677 json_object_int_add(json, "totalPeers", count);
11678 json_object_int_add(json, "dynamicPeers", dn_count);
11679
11680 if (!show_failed)
11681 bgp_show_bestpath_json(bgp, json);
11682
11683 vty_json(vty, json);
11684 } else {
11685 if (count) {
11686 if (filtered_count == count)
11687 vty_out(vty, "\n%% No matching neighbor\n");
11688 else {
11689 if (show_failed)
11690 vty_out(vty, "\nDisplayed neighbors %d",
11691 failed_count);
11692 else if (as_type != AS_UNSPECIFIED || as
11693 || fpeer || show_established)
11694 vty_out(vty, "\nDisplayed neighbors %d",
11695 count - filtered_count);
11696
11697 vty_out(vty, "\nTotal number of neighbors %d\n",
11698 count);
11699 }
11700 } else {
11701 vty_out(vty, "No %s neighbor is configured\n",
11702 get_afi_safi_str(afi, safi, false));
11703 }
11704
11705 if (dn_count) {
11706 vty_out(vty, "* - dynamic neighbor\n");
11707 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11708 dn_count, bgp->dynamic_neighbors_limit);
11709 }
11710 }
11711
11712 return CMD_SUCCESS;
11713 }
11714
11715 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11716 int safi, struct peer *fpeer, int as_type,
11717 as_t as, uint16_t show_flags)
11718 {
11719 int is_first = 1;
11720 int afi_wildcard = (afi == AFI_MAX);
11721 int safi_wildcard = (safi == SAFI_MAX);
11722 int is_wildcard = (afi_wildcard || safi_wildcard);
11723 bool nbr_output = false;
11724 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11725
11726 if (use_json && is_wildcard)
11727 vty_out(vty, "{\n");
11728 if (afi_wildcard)
11729 afi = 1; /* AFI_IP */
11730 while (afi < AFI_MAX) {
11731 if (safi_wildcard)
11732 safi = 1; /* SAFI_UNICAST */
11733 while (safi < SAFI_MAX) {
11734 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11735 nbr_output = true;
11736
11737 if (is_wildcard) {
11738 /*
11739 * So limit output to those afi/safi
11740 * pairs that
11741 * actualy have something interesting in
11742 * them
11743 */
11744 if (use_json) {
11745 if (!is_first)
11746 vty_out(vty, ",\n");
11747 else
11748 is_first = 0;
11749
11750 vty_out(vty, "\"%s\":",
11751 get_afi_safi_str(afi,
11752 safi,
11753 true));
11754 } else {
11755 vty_out(vty,
11756 "\n%s Summary (%s):\n",
11757 get_afi_safi_str(afi,
11758 safi,
11759 false),
11760 bgp->name_pretty);
11761 }
11762 }
11763 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11764 as_type, as, show_flags);
11765 }
11766 safi++;
11767 if (!safi_wildcard)
11768 safi = SAFI_MAX;
11769 }
11770 afi++;
11771 if (!afi_wildcard)
11772 afi = AFI_MAX;
11773 }
11774
11775 if (use_json && is_wildcard)
11776 vty_out(vty, "}\n");
11777 else if (!nbr_output) {
11778 if (use_json)
11779 vty_out(vty, "{}\n");
11780 else
11781 vty_out(vty, "%% No BGP neighbors found in %s\n",
11782 bgp->name_pretty);
11783 }
11784 }
11785
11786 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11787 safi_t safi,
11788 const char *neighbor,
11789 int as_type, as_t as,
11790 uint16_t show_flags)
11791 {
11792 struct listnode *node, *nnode;
11793 struct bgp *bgp;
11794 struct peer *fpeer = NULL;
11795 int is_first = 1;
11796 bool nbr_output = false;
11797 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11798
11799 if (use_json)
11800 vty_out(vty, "{\n");
11801
11802 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11803 nbr_output = true;
11804 if (use_json) {
11805 if (!is_first)
11806 vty_out(vty, ",\n");
11807 else
11808 is_first = 0;
11809
11810 vty_out(vty, "\"%s\":",
11811 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11812 ? VRF_DEFAULT_NAME
11813 : bgp->name);
11814 }
11815 if (neighbor) {
11816 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11817 use_json);
11818 if (!fpeer)
11819 continue;
11820 }
11821 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11822 as, show_flags);
11823 }
11824
11825 if (use_json)
11826 vty_out(vty, "}\n");
11827 else if (!nbr_output)
11828 vty_out(vty, "%% BGP instance not found\n");
11829 }
11830
11831 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11832 safi_t safi, const char *neighbor, int as_type,
11833 as_t as, uint16_t show_flags)
11834 {
11835 struct bgp *bgp;
11836 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11837 struct peer *fpeer = NULL;
11838
11839 if (name) {
11840 if (strmatch(name, "all")) {
11841 bgp_show_all_instances_summary_vty(vty, afi, safi,
11842 neighbor, as_type,
11843 as, show_flags);
11844 return CMD_SUCCESS;
11845 } else {
11846 bgp = bgp_lookup_by_name(name);
11847
11848 if (!bgp) {
11849 if (use_json)
11850 vty_out(vty, "{}\n");
11851 else
11852 vty_out(vty,
11853 "%% BGP instance not found\n");
11854 return CMD_WARNING;
11855 }
11856
11857 if (neighbor) {
11858 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11859 use_json);
11860 if (!fpeer)
11861 return CMD_WARNING;
11862 }
11863 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11864 as_type, as, show_flags);
11865 return CMD_SUCCESS;
11866 }
11867 }
11868
11869 bgp = bgp_get_default();
11870
11871 if (bgp) {
11872 if (neighbor) {
11873 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11874 use_json);
11875 if (!fpeer)
11876 return CMD_WARNING;
11877 }
11878 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11879 as, show_flags);
11880 } else {
11881 if (use_json)
11882 vty_out(vty, "{}\n");
11883 else
11884 vty_out(vty, "%% BGP instance not found\n");
11885 return CMD_WARNING;
11886 }
11887
11888 return CMD_SUCCESS;
11889 }
11890
11891 /* `show [ip] bgp summary' commands. */
11892 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11893 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11894 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11895 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
11896 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11897 BGP_SAFI_WITH_LABEL_HELP_STR
11898 "Display the entries for all address families\n"
11899 "Summary of BGP neighbor status\n"
11900 "Show only sessions in Established state\n"
11901 "Show only sessions not in Established state\n"
11902 "Show only the specified neighbor session\n"
11903 "Neighbor to display information about\n"
11904 "Neighbor to display information about\n"
11905 "Neighbor on BGP configured interface\n"
11906 "Show only the specified remote AS sessions\n"
11907 "AS number\n"
11908 "Internal (iBGP) AS sessions\n"
11909 "External (eBGP) AS sessions\n"
11910 "Shorten the information on BGP instances\n"
11911 "Increase table width for longer output\n" JSON_STR)
11912 {
11913 char *vrf = NULL;
11914 afi_t afi = AFI_MAX;
11915 safi_t safi = SAFI_MAX;
11916 as_t as = 0; /* 0 means AS filter not set */
11917 int as_type = AS_UNSPECIFIED;
11918 uint16_t show_flags = 0;
11919
11920 int idx = 0;
11921
11922 /* show [ip] bgp */
11923 if (!all && argv_find(argv, argc, "ip", &idx))
11924 afi = AFI_IP;
11925 /* [<vrf> VIEWVRFNAME] */
11926 if (argv_find(argv, argc, "vrf", &idx)) {
11927 vrf = argv[idx + 1]->arg;
11928 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11929 vrf = NULL;
11930 } else if (argv_find(argv, argc, "view", &idx))
11931 /* [<view> VIEWVRFNAME] */
11932 vrf = argv[idx + 1]->arg;
11933 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11934 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11935 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11936 }
11937
11938 if (argv_find(argv, argc, "failed", &idx))
11939 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11940
11941 if (argv_find(argv, argc, "established", &idx))
11942 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11943
11944 if (argv_find(argv, argc, "remote-as", &idx)) {
11945 if (argv[idx + 1]->arg[0] == 'i')
11946 as_type = AS_INTERNAL;
11947 else if (argv[idx + 1]->arg[0] == 'e')
11948 as_type = AS_EXTERNAL;
11949 else
11950 as = (as_t)atoi(argv[idx + 1]->arg);
11951 }
11952
11953 if (argv_find(argv, argc, "terse", &idx))
11954 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11955
11956 if (argv_find(argv, argc, "wide", &idx))
11957 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11958
11959 if (argv_find(argv, argc, "json", &idx))
11960 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11961
11962 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11963 show_flags);
11964 }
11965
11966 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11967 {
11968 if (for_json)
11969 return get_afi_safi_json_str(afi, safi);
11970 else
11971 return get_afi_safi_vty_str(afi, safi);
11972 }
11973
11974
11975 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11976 afi_t afi, safi_t safi,
11977 uint16_t adv_smcap, uint16_t adv_rmcap,
11978 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11979 bool use_json, json_object *json_pref)
11980 {
11981 /* Send-Mode */
11982 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11983 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11984 if (use_json) {
11985 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11986 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11987 json_object_string_add(json_pref, "sendMode",
11988 "advertisedAndReceived");
11989 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11990 json_object_string_add(json_pref, "sendMode",
11991 "advertised");
11992 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11993 json_object_string_add(json_pref, "sendMode",
11994 "received");
11995 } else {
11996 vty_out(vty, " Send-mode: ");
11997 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11998 vty_out(vty, "advertised");
11999 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12000 vty_out(vty, "%sreceived",
12001 CHECK_FLAG(p->af_cap[afi][safi],
12002 adv_smcap)
12003 ? ", "
12004 : "");
12005 vty_out(vty, "\n");
12006 }
12007 }
12008
12009 /* Receive-Mode */
12010 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12011 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
12012 if (use_json) {
12013 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12014 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12015 json_object_string_add(json_pref, "recvMode",
12016 "advertisedAndReceived");
12017 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12018 json_object_string_add(json_pref, "recvMode",
12019 "advertised");
12020 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12021 json_object_string_add(json_pref, "recvMode",
12022 "received");
12023 } else {
12024 vty_out(vty, " Receive-mode: ");
12025 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12026 vty_out(vty, "advertised");
12027 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12028 vty_out(vty, "%sreceived",
12029 CHECK_FLAG(p->af_cap[afi][safi],
12030 adv_rmcap)
12031 ? ", "
12032 : "");
12033 vty_out(vty, "\n");
12034 }
12035 }
12036 }
12037
12038 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12039 struct peer *p,
12040 json_object *json)
12041 {
12042 bool rbit = false;
12043 bool nbit = false;
12044
12045 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12046 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
12047 && (peer_established(p))) {
12048 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12049 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
12050 }
12051
12052 if (json) {
12053 json_object_boolean_add(json, "rBit", rbit);
12054 json_object_boolean_add(json, "nBit", nbit);
12055 } else {
12056 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12057 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
12058 }
12059 }
12060
12061 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12062 struct peer *peer,
12063 json_object *json)
12064 {
12065 const char *mode = "NotApplicable";
12066
12067 if (!json)
12068 vty_out(vty, "\n Remote GR Mode: ");
12069
12070 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12071 && (peer_established(peer))) {
12072
12073 if ((peer->nsf_af_count == 0)
12074 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12075
12076 mode = "Disable";
12077
12078 } else if (peer->nsf_af_count == 0
12079 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12080
12081 mode = "Helper";
12082
12083 } else if (peer->nsf_af_count != 0
12084 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12085
12086 mode = "Restart";
12087 }
12088 }
12089
12090 if (json)
12091 json_object_string_add(json, "remoteGrMode", mode);
12092 else
12093 vty_out(vty, "%s\n", mode);
12094 }
12095
12096 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12097 struct peer *p,
12098 json_object *json)
12099 {
12100 const char *mode = "Invalid";
12101
12102 if (!json)
12103 vty_out(vty, " Local GR Mode: ");
12104
12105 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12106 mode = "Helper";
12107 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12108 mode = "Restart";
12109 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12110 mode = "Disable";
12111 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12112 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12113 mode = "Helper*";
12114 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12115 mode = "Restart*";
12116 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12117 mode = "Disable*";
12118 else
12119 mode = "Invalid*";
12120 }
12121
12122 if (json)
12123 json_object_string_add(json, "localGrMode", mode);
12124 else
12125 vty_out(vty, "%s\n", mode);
12126 }
12127
12128 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12129 struct vty *vty, struct peer *peer, json_object *json)
12130 {
12131 afi_t afi;
12132 safi_t safi;
12133 json_object *json_afi_safi = NULL;
12134 json_object *json_timer = NULL;
12135 json_object *json_endofrib_status = NULL;
12136 bool eor_flag = false;
12137
12138 FOREACH_AFI_SAFI_NSF (afi, safi) {
12139 if (!peer->afc[afi][safi])
12140 continue;
12141
12142 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12143 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12144 continue;
12145
12146 if (json) {
12147 json_afi_safi = json_object_new_object();
12148 json_endofrib_status = json_object_new_object();
12149 json_timer = json_object_new_object();
12150 }
12151
12152 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12153 eor_flag = true;
12154 else
12155 eor_flag = false;
12156
12157 if (!json) {
12158 vty_out(vty, " %s:\n",
12159 get_afi_safi_str(afi, safi, false));
12160
12161 vty_out(vty, " F bit: ");
12162 }
12163
12164 if (peer->nsf[afi][safi] &&
12165 CHECK_FLAG(peer->af_cap[afi][safi],
12166 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12167
12168 if (json) {
12169 json_object_boolean_true_add(json_afi_safi,
12170 "fBit");
12171 } else
12172 vty_out(vty, "True\n");
12173 } else {
12174 if (json)
12175 json_object_boolean_false_add(json_afi_safi,
12176 "fBit");
12177 else
12178 vty_out(vty, "False\n");
12179 }
12180
12181 if (!json)
12182 vty_out(vty, " End-of-RIB sent: ");
12183
12184 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12185 PEER_STATUS_EOR_SEND)) {
12186 if (json) {
12187 json_object_boolean_true_add(
12188 json_endofrib_status, "endOfRibSend");
12189
12190 PRINT_EOR_JSON(eor_flag);
12191 } else {
12192 vty_out(vty, "Yes\n");
12193 vty_out(vty,
12194 " End-of-RIB sent after update: ");
12195
12196 PRINT_EOR(eor_flag);
12197 }
12198 } else {
12199 if (json) {
12200 json_object_boolean_false_add(
12201 json_endofrib_status, "endOfRibSend");
12202 json_object_boolean_false_add(
12203 json_endofrib_status,
12204 "endOfRibSentAfterUpdate");
12205 } else {
12206 vty_out(vty, "No\n");
12207 vty_out(vty,
12208 " End-of-RIB sent after update: ");
12209 vty_out(vty, "No\n");
12210 }
12211 }
12212
12213 if (!json)
12214 vty_out(vty, " End-of-RIB received: ");
12215
12216 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12217 PEER_STATUS_EOR_RECEIVED)) {
12218 if (json)
12219 json_object_boolean_true_add(
12220 json_endofrib_status, "endOfRibRecv");
12221 else
12222 vty_out(vty, "Yes\n");
12223 } else {
12224 if (json)
12225 json_object_boolean_false_add(
12226 json_endofrib_status, "endOfRibRecv");
12227 else
12228 vty_out(vty, "No\n");
12229 }
12230
12231 if (json) {
12232 json_object_int_add(json_timer, "stalePathTimer",
12233 peer->bgp->stalepath_time);
12234
12235 if (peer->t_gr_stale != NULL) {
12236 json_object_int_add(json_timer,
12237 "stalePathTimerRemaining",
12238 thread_timer_remain_second(
12239 peer->t_gr_stale));
12240 }
12241
12242 /* Display Configured Selection
12243 * Deferral only when when
12244 * Gr mode is enabled.
12245 */
12246 if (CHECK_FLAG(peer->flags,
12247 PEER_FLAG_GRACEFUL_RESTART)) {
12248 json_object_int_add(json_timer,
12249 "selectionDeferralTimer",
12250 peer->bgp->stalepath_time);
12251 }
12252
12253 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12254 NULL) {
12255
12256 json_object_int_add(
12257 json_timer,
12258 "selectionDeferralTimerRemaining",
12259 thread_timer_remain_second(
12260 peer->bgp->gr_info[afi][safi]
12261 .t_select_deferral));
12262 }
12263 } else {
12264 vty_out(vty, " Timers:\n");
12265 vty_out(vty,
12266 " Configured Stale Path Time(sec): %u\n",
12267 peer->bgp->stalepath_time);
12268
12269 if (peer->t_gr_stale != NULL)
12270 vty_out(vty,
12271 " Stale Path Remaining(sec): %ld\n",
12272 thread_timer_remain_second(
12273 peer->t_gr_stale));
12274 /* Display Configured Selection
12275 * Deferral only when when
12276 * Gr mode is enabled.
12277 */
12278 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12279 vty_out(vty,
12280 " Configured Selection Deferral Time(sec): %u\n",
12281 peer->bgp->select_defer_time);
12282
12283 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12284 NULL)
12285 vty_out(vty,
12286 " Selection Deferral Time Remaining(sec): %ld\n",
12287 thread_timer_remain_second(
12288 peer->bgp->gr_info[afi][safi]
12289 .t_select_deferral));
12290 }
12291 if (json) {
12292 json_object_object_add(json_afi_safi, "endOfRibStatus",
12293 json_endofrib_status);
12294 json_object_object_add(json_afi_safi, "timers",
12295 json_timer);
12296 json_object_object_add(
12297 json, get_afi_safi_str(afi, safi, true),
12298 json_afi_safi);
12299 }
12300 }
12301 }
12302
12303 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12304 struct peer *p,
12305 json_object *json)
12306 {
12307 if (json) {
12308 json_object *json_timer = NULL;
12309
12310 json_timer = json_object_new_object();
12311
12312 json_object_int_add(json_timer, "configuredRestartTimer",
12313 p->bgp->restart_time);
12314
12315 json_object_int_add(json_timer, "receivedRestartTimer",
12316 p->v_gr_restart);
12317
12318 if (p->t_gr_restart != NULL)
12319 json_object_int_add(
12320 json_timer, "restartTimerRemaining",
12321 thread_timer_remain_second(p->t_gr_restart));
12322
12323 json_object_object_add(json, "timers", json_timer);
12324 } else {
12325
12326 vty_out(vty, " Timers:\n");
12327 vty_out(vty, " Configured Restart Time(sec): %u\n",
12328 p->bgp->restart_time);
12329
12330 vty_out(vty, " Received Restart Time(sec): %u\n",
12331 p->v_gr_restart);
12332 if (p->t_gr_restart != NULL)
12333 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12334 thread_timer_remain_second(p->t_gr_restart));
12335 if (p->t_gr_restart != NULL) {
12336 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12337 thread_timer_remain_second(p->t_gr_restart));
12338 }
12339 }
12340 }
12341
12342 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12343 json_object *json)
12344 {
12345 char dn_flag[2] = {0};
12346 /* '*' + v6 address of neighbor */
12347 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12348
12349 if (!p->conf_if && peer_dynamic_neighbor(p))
12350 dn_flag[0] = '*';
12351
12352 if (p->conf_if) {
12353 if (json)
12354 json_object_string_addf(json, "neighborAddr", "%pSU",
12355 &p->su);
12356 else
12357 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12358 &p->su);
12359 } else {
12360 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12361 p->host);
12362
12363 if (json)
12364 json_object_string_add(json, "neighborAddr",
12365 neighborAddr);
12366 else
12367 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12368 }
12369
12370 /* more gr info in new format */
12371 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12372 }
12373
12374 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12375 safi_t safi, bool use_json,
12376 json_object *json_neigh)
12377 {
12378 struct bgp_filter *filter;
12379 struct peer_af *paf;
12380 char orf_pfx_name[BUFSIZ];
12381 int orf_pfx_count;
12382 json_object *json_af = NULL;
12383 json_object *json_prefA = NULL;
12384 json_object *json_prefB = NULL;
12385 json_object *json_addr = NULL;
12386 json_object *json_advmap = NULL;
12387
12388 if (use_json) {
12389 json_addr = json_object_new_object();
12390 json_af = json_object_new_object();
12391 filter = &p->filter[afi][safi];
12392
12393 if (peer_group_active(p))
12394 json_object_string_add(json_addr, "peerGroupMember",
12395 p->group->name);
12396
12397 paf = peer_af_find(p, afi, safi);
12398 if (paf && PAF_SUBGRP(paf)) {
12399 json_object_int_add(json_addr, "updateGroupId",
12400 PAF_UPDGRP(paf)->id);
12401 json_object_int_add(json_addr, "subGroupId",
12402 PAF_SUBGRP(paf)->id);
12403 json_object_int_add(json_addr, "packetQueueLength",
12404 bpacket_queue_virtual_length(paf));
12405 }
12406
12407 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12408 || CHECK_FLAG(p->af_cap[afi][safi],
12409 PEER_CAP_ORF_PREFIX_SM_RCV)
12410 || CHECK_FLAG(p->af_cap[afi][safi],
12411 PEER_CAP_ORF_PREFIX_RM_ADV)
12412 || CHECK_FLAG(p->af_cap[afi][safi],
12413 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12414 json_object_int_add(json_af, "orfType",
12415 ORF_TYPE_PREFIX);
12416 json_prefA = json_object_new_object();
12417 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12418 PEER_CAP_ORF_PREFIX_SM_ADV,
12419 PEER_CAP_ORF_PREFIX_RM_ADV,
12420 PEER_CAP_ORF_PREFIX_SM_RCV,
12421 PEER_CAP_ORF_PREFIX_RM_RCV,
12422 use_json, json_prefA);
12423 json_object_object_add(json_af, "orfPrefixList",
12424 json_prefA);
12425 }
12426
12427 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12428 || CHECK_FLAG(p->af_cap[afi][safi],
12429 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12430 || CHECK_FLAG(p->af_cap[afi][safi],
12431 PEER_CAP_ORF_PREFIX_RM_ADV)
12432 || CHECK_FLAG(p->af_cap[afi][safi],
12433 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12434 json_object_int_add(json_af, "orfOldType",
12435 ORF_TYPE_PREFIX_OLD);
12436 json_prefB = json_object_new_object();
12437 bgp_show_peer_afi_orf_cap(
12438 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12439 PEER_CAP_ORF_PREFIX_RM_ADV,
12440 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12441 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12442 json_prefB);
12443 json_object_object_add(json_af, "orfOldPrefixList",
12444 json_prefB);
12445 }
12446
12447 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12448 || CHECK_FLAG(p->af_cap[afi][safi],
12449 PEER_CAP_ORF_PREFIX_SM_RCV)
12450 || CHECK_FLAG(p->af_cap[afi][safi],
12451 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12452 || CHECK_FLAG(p->af_cap[afi][safi],
12453 PEER_CAP_ORF_PREFIX_RM_ADV)
12454 || CHECK_FLAG(p->af_cap[afi][safi],
12455 PEER_CAP_ORF_PREFIX_RM_RCV)
12456 || CHECK_FLAG(p->af_cap[afi][safi],
12457 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12458 json_object_object_add(json_addr, "afDependentCap",
12459 json_af);
12460 else
12461 json_object_free(json_af);
12462
12463 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12464 p->host, afi, safi);
12465 orf_pfx_count = prefix_bgp_show_prefix_list(
12466 NULL, afi, orf_pfx_name, use_json);
12467
12468 if (CHECK_FLAG(p->af_sflags[afi][safi],
12469 PEER_STATUS_ORF_PREFIX_SEND)
12470 || orf_pfx_count) {
12471 if (CHECK_FLAG(p->af_sflags[afi][safi],
12472 PEER_STATUS_ORF_PREFIX_SEND))
12473 json_object_boolean_true_add(json_neigh,
12474 "orfSent");
12475 if (orf_pfx_count)
12476 json_object_int_add(json_addr, "orfRecvCounter",
12477 orf_pfx_count);
12478 }
12479 if (CHECK_FLAG(p->af_sflags[afi][safi],
12480 PEER_STATUS_ORF_WAIT_REFRESH))
12481 json_object_string_add(
12482 json_addr, "orfFirstUpdate",
12483 "deferredUntilORFOrRouteRefreshRecvd");
12484
12485 if (CHECK_FLAG(p->af_flags[afi][safi],
12486 PEER_FLAG_REFLECTOR_CLIENT))
12487 json_object_boolean_true_add(json_addr,
12488 "routeReflectorClient");
12489 if (CHECK_FLAG(p->af_flags[afi][safi],
12490 PEER_FLAG_RSERVER_CLIENT))
12491 json_object_boolean_true_add(json_addr,
12492 "routeServerClient");
12493 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12494 json_object_boolean_true_add(json_addr,
12495 "inboundSoftConfigPermit");
12496
12497 if (CHECK_FLAG(p->af_flags[afi][safi],
12498 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12499 json_object_boolean_true_add(
12500 json_addr,
12501 "privateAsNumsAllReplacedInUpdatesToNbr");
12502 else if (CHECK_FLAG(p->af_flags[afi][safi],
12503 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12504 json_object_boolean_true_add(
12505 json_addr,
12506 "privateAsNumsReplacedInUpdatesToNbr");
12507 else if (CHECK_FLAG(p->af_flags[afi][safi],
12508 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12509 json_object_boolean_true_add(
12510 json_addr,
12511 "privateAsNumsAllRemovedInUpdatesToNbr");
12512 else if (CHECK_FLAG(p->af_flags[afi][safi],
12513 PEER_FLAG_REMOVE_PRIVATE_AS))
12514 json_object_boolean_true_add(
12515 json_addr,
12516 "privateAsNumsRemovedInUpdatesToNbr");
12517
12518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12519 if (CHECK_FLAG(p->af_flags[afi][safi],
12520 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12521 json_object_boolean_true_add(json_addr,
12522 "allowAsInOrigin");
12523 else
12524 json_object_int_add(json_addr, "allowAsInCount",
12525 p->allowas_in[afi][safi]);
12526 }
12527
12528 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12529 json_object_boolean_true_add(
12530 json_addr,
12531 bgp_addpath_names(p->addpath_type[afi][safi])
12532 ->type_json_name);
12533
12534 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12535 json_object_string_add(json_addr,
12536 "overrideASNsInOutboundUpdates",
12537 "ifAspathEqualRemoteAs");
12538
12539 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12540 || CHECK_FLAG(p->af_flags[afi][safi],
12541 PEER_FLAG_FORCE_NEXTHOP_SELF))
12542 json_object_boolean_true_add(json_addr,
12543 "routerAlwaysNextHop");
12544 if (CHECK_FLAG(p->af_flags[afi][safi],
12545 PEER_FLAG_AS_PATH_UNCHANGED))
12546 json_object_boolean_true_add(
12547 json_addr, "unchangedAsPathPropogatedToNbr");
12548 if (CHECK_FLAG(p->af_flags[afi][safi],
12549 PEER_FLAG_NEXTHOP_UNCHANGED))
12550 json_object_boolean_true_add(
12551 json_addr, "unchangedNextHopPropogatedToNbr");
12552 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12553 json_object_boolean_true_add(
12554 json_addr, "unchangedMedPropogatedToNbr");
12555 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12556 || CHECK_FLAG(p->af_flags[afi][safi],
12557 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12558 if (CHECK_FLAG(p->af_flags[afi][safi],
12559 PEER_FLAG_SEND_COMMUNITY)
12560 && CHECK_FLAG(p->af_flags[afi][safi],
12561 PEER_FLAG_SEND_EXT_COMMUNITY))
12562 json_object_string_add(json_addr,
12563 "commAttriSentToNbr",
12564 "extendedAndStandard");
12565 else if (CHECK_FLAG(p->af_flags[afi][safi],
12566 PEER_FLAG_SEND_EXT_COMMUNITY))
12567 json_object_string_add(json_addr,
12568 "commAttriSentToNbr",
12569 "extended");
12570 else
12571 json_object_string_add(json_addr,
12572 "commAttriSentToNbr",
12573 "standard");
12574 }
12575 if (CHECK_FLAG(p->af_flags[afi][safi],
12576 PEER_FLAG_DEFAULT_ORIGINATE)) {
12577 if (p->default_rmap[afi][safi].name)
12578 json_object_string_add(
12579 json_addr, "defaultRouteMap",
12580 p->default_rmap[afi][safi].name);
12581
12582 if (paf && PAF_SUBGRP(paf)
12583 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12584 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12585 json_object_boolean_true_add(json_addr,
12586 "defaultSent");
12587 else
12588 json_object_boolean_true_add(json_addr,
12589 "defaultNotSent");
12590 }
12591
12592 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12593 if (is_evpn_enabled())
12594 json_object_boolean_true_add(
12595 json_addr, "advertiseAllVnis");
12596 }
12597
12598 if (filter->plist[FILTER_IN].name
12599 || filter->dlist[FILTER_IN].name
12600 || filter->aslist[FILTER_IN].name
12601 || filter->map[RMAP_IN].name)
12602 json_object_boolean_true_add(json_addr,
12603 "inboundPathPolicyConfig");
12604 if (filter->plist[FILTER_OUT].name
12605 || filter->dlist[FILTER_OUT].name
12606 || filter->aslist[FILTER_OUT].name
12607 || filter->map[RMAP_OUT].name || filter->usmap.name)
12608 json_object_boolean_true_add(
12609 json_addr, "outboundPathPolicyConfig");
12610
12611 /* prefix-list */
12612 if (filter->plist[FILTER_IN].name)
12613 json_object_string_add(json_addr,
12614 "incomingUpdatePrefixFilterList",
12615 filter->plist[FILTER_IN].name);
12616 if (filter->plist[FILTER_OUT].name)
12617 json_object_string_add(json_addr,
12618 "outgoingUpdatePrefixFilterList",
12619 filter->plist[FILTER_OUT].name);
12620
12621 /* distribute-list */
12622 if (filter->dlist[FILTER_IN].name)
12623 json_object_string_add(
12624 json_addr, "incomingUpdateNetworkFilterList",
12625 filter->dlist[FILTER_IN].name);
12626 if (filter->dlist[FILTER_OUT].name)
12627 json_object_string_add(
12628 json_addr, "outgoingUpdateNetworkFilterList",
12629 filter->dlist[FILTER_OUT].name);
12630
12631 /* filter-list. */
12632 if (filter->aslist[FILTER_IN].name)
12633 json_object_string_add(json_addr,
12634 "incomingUpdateAsPathFilterList",
12635 filter->aslist[FILTER_IN].name);
12636 if (filter->aslist[FILTER_OUT].name)
12637 json_object_string_add(json_addr,
12638 "outgoingUpdateAsPathFilterList",
12639 filter->aslist[FILTER_OUT].name);
12640
12641 /* route-map. */
12642 if (filter->map[RMAP_IN].name)
12643 json_object_string_add(
12644 json_addr, "routeMapForIncomingAdvertisements",
12645 filter->map[RMAP_IN].name);
12646 if (filter->map[RMAP_OUT].name)
12647 json_object_string_add(
12648 json_addr, "routeMapForOutgoingAdvertisements",
12649 filter->map[RMAP_OUT].name);
12650
12651 /* ebgp-requires-policy (inbound) */
12652 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12653 && !bgp_inbound_policy_exists(p, filter))
12654 json_object_string_add(
12655 json_addr, "inboundEbgpRequiresPolicy",
12656 "Inbound updates discarded due to missing policy");
12657
12658 /* ebgp-requires-policy (outbound) */
12659 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12660 && (!bgp_outbound_policy_exists(p, filter)))
12661 json_object_string_add(
12662 json_addr, "outboundEbgpRequiresPolicy",
12663 "Outbound updates discarded due to missing policy");
12664
12665 /* unsuppress-map */
12666 if (filter->usmap.name)
12667 json_object_string_add(json_addr,
12668 "selectiveUnsuppressRouteMap",
12669 filter->usmap.name);
12670
12671 /* advertise-map */
12672 if (filter->advmap.aname) {
12673 json_advmap = json_object_new_object();
12674 json_object_string_add(json_advmap, "condition",
12675 filter->advmap.condition
12676 ? "EXIST"
12677 : "NON_EXIST");
12678 json_object_string_add(json_advmap, "conditionMap",
12679 filter->advmap.cname);
12680 json_object_string_add(json_advmap, "advertiseMap",
12681 filter->advmap.aname);
12682 json_object_string_add(
12683 json_advmap, "advertiseStatus",
12684 filter->advmap.update_type ==
12685 UPDATE_TYPE_ADVERTISE
12686 ? "Advertise"
12687 : "Withdraw");
12688 json_object_object_add(json_addr, "advertiseMap",
12689 json_advmap);
12690 }
12691
12692 /* Receive prefix count */
12693 json_object_int_add(json_addr, "acceptedPrefixCounter",
12694 p->pcount[afi][safi]);
12695 if (paf && PAF_SUBGRP(paf))
12696 json_object_int_add(json_addr, "sentPrefixCounter",
12697 (PAF_SUBGRP(paf))->scount);
12698
12699 /* Maximum prefix */
12700 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12701 json_object_int_add(json_addr, "prefixOutAllowedMax",
12702 p->pmax_out[afi][safi]);
12703
12704 /* Maximum prefix */
12705 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12706 json_object_int_add(json_addr, "prefixAllowedMax",
12707 p->pmax[afi][safi]);
12708 if (CHECK_FLAG(p->af_flags[afi][safi],
12709 PEER_FLAG_MAX_PREFIX_WARNING))
12710 json_object_boolean_true_add(
12711 json_addr, "prefixAllowedMaxWarning");
12712 json_object_int_add(json_addr,
12713 "prefixAllowedWarningThresh",
12714 p->pmax_threshold[afi][safi]);
12715 if (p->pmax_restart[afi][safi])
12716 json_object_int_add(
12717 json_addr,
12718 "prefixAllowedRestartIntervalMsecs",
12719 p->pmax_restart[afi][safi] * 60000);
12720 }
12721 json_object_object_add(json_neigh,
12722 get_afi_safi_str(afi, safi, true),
12723 json_addr);
12724
12725 } else {
12726 filter = &p->filter[afi][safi];
12727
12728 vty_out(vty, " For address family: %s\n",
12729 get_afi_safi_str(afi, safi, false));
12730
12731 if (peer_group_active(p))
12732 vty_out(vty, " %s peer-group member\n",
12733 p->group->name);
12734
12735 paf = peer_af_find(p, afi, safi);
12736 if (paf && PAF_SUBGRP(paf)) {
12737 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12738 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12739 vty_out(vty, " Packet Queue length %d\n",
12740 bpacket_queue_virtual_length(paf));
12741 } else {
12742 vty_out(vty, " Not part of any update group\n");
12743 }
12744 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12745 || CHECK_FLAG(p->af_cap[afi][safi],
12746 PEER_CAP_ORF_PREFIX_SM_RCV)
12747 || CHECK_FLAG(p->af_cap[afi][safi],
12748 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12749 || CHECK_FLAG(p->af_cap[afi][safi],
12750 PEER_CAP_ORF_PREFIX_RM_ADV)
12751 || CHECK_FLAG(p->af_cap[afi][safi],
12752 PEER_CAP_ORF_PREFIX_RM_RCV)
12753 || CHECK_FLAG(p->af_cap[afi][safi],
12754 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12755 vty_out(vty, " AF-dependant capabilities:\n");
12756
12757 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12758 || CHECK_FLAG(p->af_cap[afi][safi],
12759 PEER_CAP_ORF_PREFIX_SM_RCV)
12760 || CHECK_FLAG(p->af_cap[afi][safi],
12761 PEER_CAP_ORF_PREFIX_RM_ADV)
12762 || CHECK_FLAG(p->af_cap[afi][safi],
12763 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12764 vty_out(vty,
12765 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12766 ORF_TYPE_PREFIX);
12767 bgp_show_peer_afi_orf_cap(
12768 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12769 PEER_CAP_ORF_PREFIX_RM_ADV,
12770 PEER_CAP_ORF_PREFIX_SM_RCV,
12771 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12772 }
12773 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12774 || CHECK_FLAG(p->af_cap[afi][safi],
12775 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12776 || CHECK_FLAG(p->af_cap[afi][safi],
12777 PEER_CAP_ORF_PREFIX_RM_ADV)
12778 || CHECK_FLAG(p->af_cap[afi][safi],
12779 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12780 vty_out(vty,
12781 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12782 ORF_TYPE_PREFIX_OLD);
12783 bgp_show_peer_afi_orf_cap(
12784 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12785 PEER_CAP_ORF_PREFIX_RM_ADV,
12786 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12787 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12788 }
12789
12790 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12791 p->host, afi, safi);
12792 orf_pfx_count = prefix_bgp_show_prefix_list(
12793 NULL, afi, orf_pfx_name, use_json);
12794
12795 if (CHECK_FLAG(p->af_sflags[afi][safi],
12796 PEER_STATUS_ORF_PREFIX_SEND)
12797 || orf_pfx_count) {
12798 vty_out(vty, " Outbound Route Filter (ORF):");
12799 if (CHECK_FLAG(p->af_sflags[afi][safi],
12800 PEER_STATUS_ORF_PREFIX_SEND))
12801 vty_out(vty, " sent;");
12802 if (orf_pfx_count)
12803 vty_out(vty, " received (%d entries)",
12804 orf_pfx_count);
12805 vty_out(vty, "\n");
12806 }
12807 if (CHECK_FLAG(p->af_sflags[afi][safi],
12808 PEER_STATUS_ORF_WAIT_REFRESH))
12809 vty_out(vty,
12810 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12811
12812 if (CHECK_FLAG(p->af_flags[afi][safi],
12813 PEER_FLAG_REFLECTOR_CLIENT))
12814 vty_out(vty, " Route-Reflector Client\n");
12815 if (CHECK_FLAG(p->af_flags[afi][safi],
12816 PEER_FLAG_RSERVER_CLIENT))
12817 vty_out(vty, " Route-Server Client\n");
12818 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12819 vty_out(vty,
12820 " Inbound soft reconfiguration allowed\n");
12821
12822 if (CHECK_FLAG(p->af_flags[afi][safi],
12823 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12824 vty_out(vty,
12825 " Private AS numbers (all) replaced in updates to this neighbor\n");
12826 else if (CHECK_FLAG(p->af_flags[afi][safi],
12827 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12828 vty_out(vty,
12829 " Private AS numbers replaced in updates to this neighbor\n");
12830 else if (CHECK_FLAG(p->af_flags[afi][safi],
12831 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12832 vty_out(vty,
12833 " Private AS numbers (all) removed in updates to this neighbor\n");
12834 else if (CHECK_FLAG(p->af_flags[afi][safi],
12835 PEER_FLAG_REMOVE_PRIVATE_AS))
12836 vty_out(vty,
12837 " Private AS numbers removed in updates to this neighbor\n");
12838
12839 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12840 if (CHECK_FLAG(p->af_flags[afi][safi],
12841 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12842 vty_out(vty,
12843 " Local AS allowed as path origin\n");
12844 else
12845 vty_out(vty,
12846 " Local AS allowed in path, %d occurrences\n",
12847 p->allowas_in[afi][safi]);
12848 }
12849
12850 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12851 vty_out(vty, " %s\n",
12852 bgp_addpath_names(p->addpath_type[afi][safi])
12853 ->human_description);
12854
12855 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12856 vty_out(vty,
12857 " Override ASNs in outbound updates if aspath equals remote-as\n");
12858
12859 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12860 || CHECK_FLAG(p->af_flags[afi][safi],
12861 PEER_FLAG_FORCE_NEXTHOP_SELF))
12862 vty_out(vty, " NEXT_HOP is always this router\n");
12863 if (CHECK_FLAG(p->af_flags[afi][safi],
12864 PEER_FLAG_AS_PATH_UNCHANGED))
12865 vty_out(vty,
12866 " AS_PATH is propagated unchanged to this neighbor\n");
12867 if (CHECK_FLAG(p->af_flags[afi][safi],
12868 PEER_FLAG_NEXTHOP_UNCHANGED))
12869 vty_out(vty,
12870 " NEXT_HOP is propagated unchanged to this neighbor\n");
12871 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12872 vty_out(vty,
12873 " MED is propagated unchanged to this neighbor\n");
12874 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12875 || CHECK_FLAG(p->af_flags[afi][safi],
12876 PEER_FLAG_SEND_EXT_COMMUNITY)
12877 || CHECK_FLAG(p->af_flags[afi][safi],
12878 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12879 vty_out(vty,
12880 " Community attribute sent to this neighbor");
12881 if (CHECK_FLAG(p->af_flags[afi][safi],
12882 PEER_FLAG_SEND_COMMUNITY)
12883 && CHECK_FLAG(p->af_flags[afi][safi],
12884 PEER_FLAG_SEND_EXT_COMMUNITY)
12885 && CHECK_FLAG(p->af_flags[afi][safi],
12886 PEER_FLAG_SEND_LARGE_COMMUNITY))
12887 vty_out(vty, "(all)\n");
12888 else if (CHECK_FLAG(p->af_flags[afi][safi],
12889 PEER_FLAG_SEND_LARGE_COMMUNITY))
12890 vty_out(vty, "(large)\n");
12891 else if (CHECK_FLAG(p->af_flags[afi][safi],
12892 PEER_FLAG_SEND_EXT_COMMUNITY))
12893 vty_out(vty, "(extended)\n");
12894 else
12895 vty_out(vty, "(standard)\n");
12896 }
12897 if (CHECK_FLAG(p->af_flags[afi][safi],
12898 PEER_FLAG_DEFAULT_ORIGINATE)) {
12899 vty_out(vty, " Default information originate,");
12900
12901 if (p->default_rmap[afi][safi].name)
12902 vty_out(vty, " default route-map %s%s,",
12903 p->default_rmap[afi][safi].map ? "*"
12904 : "",
12905 p->default_rmap[afi][safi].name);
12906 if (paf && PAF_SUBGRP(paf)
12907 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12908 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12909 vty_out(vty, " default sent\n");
12910 else
12911 vty_out(vty, " default not sent\n");
12912 }
12913
12914 /* advertise-vni-all */
12915 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12916 if (is_evpn_enabled())
12917 vty_out(vty, " advertise-all-vni\n");
12918 }
12919
12920 if (filter->plist[FILTER_IN].name
12921 || filter->dlist[FILTER_IN].name
12922 || filter->aslist[FILTER_IN].name
12923 || filter->map[RMAP_IN].name)
12924 vty_out(vty, " Inbound path policy configured\n");
12925 if (filter->plist[FILTER_OUT].name
12926 || filter->dlist[FILTER_OUT].name
12927 || filter->aslist[FILTER_OUT].name
12928 || filter->map[RMAP_OUT].name || filter->usmap.name)
12929 vty_out(vty, " Outbound path policy configured\n");
12930
12931 /* prefix-list */
12932 if (filter->plist[FILTER_IN].name)
12933 vty_out(vty,
12934 " Incoming update prefix filter list is %s%s\n",
12935 filter->plist[FILTER_IN].plist ? "*" : "",
12936 filter->plist[FILTER_IN].name);
12937 if (filter->plist[FILTER_OUT].name)
12938 vty_out(vty,
12939 " Outgoing update prefix filter list is %s%s\n",
12940 filter->plist[FILTER_OUT].plist ? "*" : "",
12941 filter->plist[FILTER_OUT].name);
12942
12943 /* distribute-list */
12944 if (filter->dlist[FILTER_IN].name)
12945 vty_out(vty,
12946 " Incoming update network filter list is %s%s\n",
12947 filter->dlist[FILTER_IN].alist ? "*" : "",
12948 filter->dlist[FILTER_IN].name);
12949 if (filter->dlist[FILTER_OUT].name)
12950 vty_out(vty,
12951 " Outgoing update network filter list is %s%s\n",
12952 filter->dlist[FILTER_OUT].alist ? "*" : "",
12953 filter->dlist[FILTER_OUT].name);
12954
12955 /* filter-list. */
12956 if (filter->aslist[FILTER_IN].name)
12957 vty_out(vty,
12958 " Incoming update AS path filter list is %s%s\n",
12959 filter->aslist[FILTER_IN].aslist ? "*" : "",
12960 filter->aslist[FILTER_IN].name);
12961 if (filter->aslist[FILTER_OUT].name)
12962 vty_out(vty,
12963 " Outgoing update AS path filter list is %s%s\n",
12964 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12965 filter->aslist[FILTER_OUT].name);
12966
12967 /* route-map. */
12968 if (filter->map[RMAP_IN].name)
12969 vty_out(vty,
12970 " Route map for incoming advertisements is %s%s\n",
12971 filter->map[RMAP_IN].map ? "*" : "",
12972 filter->map[RMAP_IN].name);
12973 if (filter->map[RMAP_OUT].name)
12974 vty_out(vty,
12975 " Route map for outgoing advertisements is %s%s\n",
12976 filter->map[RMAP_OUT].map ? "*" : "",
12977 filter->map[RMAP_OUT].name);
12978
12979 /* ebgp-requires-policy (inbound) */
12980 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12981 && !bgp_inbound_policy_exists(p, filter))
12982 vty_out(vty,
12983 " Inbound updates discarded due to missing policy\n");
12984
12985 /* ebgp-requires-policy (outbound) */
12986 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12987 && !bgp_outbound_policy_exists(p, filter))
12988 vty_out(vty,
12989 " Outbound updates discarded due to missing policy\n");
12990
12991 /* unsuppress-map */
12992 if (filter->usmap.name)
12993 vty_out(vty,
12994 " Route map for selective unsuppress is %s%s\n",
12995 filter->usmap.map ? "*" : "",
12996 filter->usmap.name);
12997
12998 /* advertise-map */
12999 if (filter->advmap.aname && filter->advmap.cname)
13000 vty_out(vty,
13001 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13002 filter->advmap.condition ? "EXIST"
13003 : "NON_EXIST",
13004 filter->advmap.cmap ? "*" : "",
13005 filter->advmap.cname,
13006 filter->advmap.amap ? "*" : "",
13007 filter->advmap.aname,
13008 filter->advmap.update_type ==
13009 UPDATE_TYPE_ADVERTISE
13010 ? "Advertise"
13011 : "Withdraw");
13012
13013 /* Receive prefix count */
13014 vty_out(vty, " %u accepted prefixes\n",
13015 p->pcount[afi][safi]);
13016
13017 /* maximum-prefix-out */
13018 if (CHECK_FLAG(p->af_flags[afi][safi],
13019 PEER_FLAG_MAX_PREFIX_OUT))
13020 vty_out(vty,
13021 " Maximum allowed prefixes sent %u\n",
13022 p->pmax_out[afi][safi]);
13023
13024 /* Maximum prefix */
13025 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
13026 vty_out(vty,
13027 " Maximum prefixes allowed %u%s\n",
13028 p->pmax[afi][safi],
13029 CHECK_FLAG(p->af_flags[afi][safi],
13030 PEER_FLAG_MAX_PREFIX_WARNING)
13031 ? " (warning-only)"
13032 : "");
13033 vty_out(vty, " Threshold for warning message %d%%",
13034 p->pmax_threshold[afi][safi]);
13035 if (p->pmax_restart[afi][safi])
13036 vty_out(vty, ", restart interval %d min",
13037 p->pmax_restart[afi][safi]);
13038 vty_out(vty, "\n");
13039 }
13040
13041 vty_out(vty, "\n");
13042 }
13043 }
13044
13045 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
13046 json_object *json)
13047 {
13048 struct bgp *bgp;
13049 char timebuf[BGP_UPTIME_LEN];
13050 char dn_flag[2];
13051 afi_t afi;
13052 safi_t safi;
13053 uint16_t i;
13054 uint8_t *msg;
13055 json_object *json_neigh = NULL;
13056 time_t epoch_tbuf;
13057 uint32_t sync_tcp_mss;
13058
13059 bgp = p->bgp;
13060
13061 if (use_json)
13062 json_neigh = json_object_new_object();
13063
13064 memset(dn_flag, '\0', sizeof(dn_flag));
13065 if (!p->conf_if && peer_dynamic_neighbor(p))
13066 dn_flag[0] = '*';
13067
13068 if (!use_json) {
13069 if (p->conf_if) /* Configured interface name. */
13070 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13071 &p->su);
13072 else /* Configured IP address. */
13073 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13074 p->host);
13075 }
13076
13077 if (use_json) {
13078 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13079 json_object_string_add(json_neigh, "bgpNeighborAddr",
13080 "none");
13081 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13082 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13083 "%pSU", &p->su);
13084
13085 json_object_int_add(json_neigh, "remoteAs", p->as);
13086
13087 if (p->change_local_as)
13088 json_object_int_add(json_neigh, "localAs",
13089 p->change_local_as);
13090 else
13091 json_object_int_add(json_neigh, "localAs", p->local_as);
13092
13093 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13094 json_object_boolean_true_add(json_neigh,
13095 "localAsNoPrepend");
13096
13097 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13098 json_object_boolean_true_add(json_neigh,
13099 "localAsReplaceAs");
13100 } else {
13101 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13102 || (p->as_type == AS_INTERNAL))
13103 vty_out(vty, "remote AS %u, ", p->as);
13104 else
13105 vty_out(vty, "remote AS Unspecified, ");
13106 vty_out(vty, "local AS %u%s%s, ",
13107 p->change_local_as ? p->change_local_as : p->local_as,
13108 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13109 ? " no-prepend"
13110 : "",
13111 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13112 ? " replace-as"
13113 : "");
13114 }
13115 /* peer type internal or confed-internal */
13116 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13117 if (use_json) {
13118 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13119 json_object_boolean_true_add(
13120 json_neigh, "nbrConfedInternalLink");
13121 else
13122 json_object_boolean_true_add(json_neigh,
13123 "nbrInternalLink");
13124 } else {
13125 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13126 vty_out(vty, "confed-internal link\n");
13127 else
13128 vty_out(vty, "internal link\n");
13129 }
13130 /* peer type external or confed-external */
13131 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13132 if (use_json) {
13133 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13134 json_object_boolean_true_add(
13135 json_neigh, "nbrConfedExternalLink");
13136 else
13137 json_object_boolean_true_add(json_neigh,
13138 "nbrExternalLink");
13139 } else {
13140 if (bgp_confederation_peers_check(bgp, p->as))
13141 vty_out(vty, "confed-external link\n");
13142 else
13143 vty_out(vty, "external link\n");
13144 }
13145 } else {
13146 if (use_json)
13147 json_object_boolean_true_add(json_neigh,
13148 "nbrUnspecifiedLink");
13149 else
13150 vty_out(vty, "unspecified link\n");
13151 }
13152
13153 /* Roles */
13154 if (use_json) {
13155 json_object_string_add(json_neigh, "localRole",
13156 bgp_get_name_by_role(p->local_role));
13157 json_object_string_add(json_neigh, "remoteRole",
13158 bgp_get_name_by_role(p->remote_role));
13159 } else {
13160 vty_out(vty, " Local Role: %s\n",
13161 bgp_get_name_by_role(p->local_role));
13162 vty_out(vty, " Remote Role: %s\n",
13163 bgp_get_name_by_role(p->remote_role));
13164 }
13165
13166
13167 /* Description. */
13168 if (p->desc) {
13169 if (use_json)
13170 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13171 else
13172 vty_out(vty, " Description: %s\n", p->desc);
13173 }
13174
13175 if (p->hostname) {
13176 if (use_json) {
13177 json_object_string_add(json_neigh, "hostname",
13178 p->hostname);
13179
13180 if (p->domainname)
13181 json_object_string_add(json_neigh, "domainname",
13182 p->domainname);
13183 } else {
13184 if (p->domainname && (p->domainname[0] != '\0'))
13185 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13186 p->domainname);
13187 else
13188 vty_out(vty, "Hostname: %s\n", p->hostname);
13189 }
13190 } else {
13191 if (use_json)
13192 json_object_string_add(json_neigh, "hostname",
13193 "Unknown");
13194 }
13195
13196 /* Peer-group */
13197 if (p->group) {
13198 if (use_json) {
13199 json_object_string_add(json_neigh, "peerGroup",
13200 p->group->name);
13201
13202 if (dn_flag[0]) {
13203 struct prefix prefix, *range = NULL;
13204
13205 if (sockunion2hostprefix(&(p->su), &prefix))
13206 range = peer_group_lookup_dynamic_neighbor_range(
13207 p->group, &prefix);
13208
13209 if (range) {
13210 json_object_string_addf(
13211 json_neigh,
13212 "peerSubnetRangeGroup", "%pFX",
13213 range);
13214 }
13215 }
13216 } else {
13217 vty_out(vty,
13218 " Member of peer-group %s for session parameters\n",
13219 p->group->name);
13220
13221 if (dn_flag[0]) {
13222 struct prefix prefix, *range = NULL;
13223
13224 if (sockunion2hostprefix(&(p->su), &prefix))
13225 range = peer_group_lookup_dynamic_neighbor_range(
13226 p->group, &prefix);
13227
13228 if (range) {
13229 vty_out(vty,
13230 " Belongs to the subnet range group: %pFX\n",
13231 range);
13232 }
13233 }
13234 }
13235 }
13236
13237 if (use_json) {
13238 /* Administrative shutdown. */
13239 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13240 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13241 json_object_boolean_true_add(json_neigh,
13242 "adminShutDown");
13243
13244 /* BGP Version. */
13245 json_object_int_add(json_neigh, "bgpVersion", 4);
13246 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13247 &p->remote_id);
13248 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13249 &bgp->router_id);
13250
13251 /* Confederation */
13252 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13253 && bgp_confederation_peers_check(bgp, p->as))
13254 json_object_boolean_true_add(json_neigh,
13255 "nbrCommonAdmin");
13256
13257 /* Status. */
13258 json_object_string_add(
13259 json_neigh, "bgpState",
13260 lookup_msg(bgp_status_msg, p->status, NULL));
13261
13262 if (peer_established(p)) {
13263 time_t uptime;
13264
13265 uptime = monotime(NULL);
13266 uptime -= p->uptime;
13267 epoch_tbuf = time(NULL) - uptime;
13268
13269 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13270 uptime * 1000);
13271 json_object_string_add(json_neigh, "bgpTimerUpString",
13272 peer_uptime(p->uptime, timebuf,
13273 BGP_UPTIME_LEN, 0,
13274 NULL));
13275 json_object_int_add(json_neigh,
13276 "bgpTimerUpEstablishedEpoch",
13277 epoch_tbuf);
13278 }
13279
13280 else if (p->status == Active) {
13281 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13282 json_object_string_add(json_neigh, "bgpStateIs",
13283 "passive");
13284 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13285 json_object_string_add(json_neigh, "bgpStateIs",
13286 "passiveNSF");
13287 }
13288
13289 /* read timer */
13290 time_t uptime;
13291 struct tm tm;
13292
13293 uptime = monotime(NULL);
13294 uptime -= p->readtime;
13295 gmtime_r(&uptime, &tm);
13296
13297 json_object_int_add(json_neigh, "bgpTimerLastRead",
13298 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13299 + (tm.tm_hour * 3600000));
13300
13301 uptime = monotime(NULL);
13302 uptime -= p->last_write;
13303 gmtime_r(&uptime, &tm);
13304
13305 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13306 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13307 + (tm.tm_hour * 3600000));
13308
13309 uptime = monotime(NULL);
13310 uptime -= p->update_time;
13311 gmtime_r(&uptime, &tm);
13312
13313 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13314 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13315 + (tm.tm_hour * 3600000));
13316
13317 /* Configured timer values. */
13318 json_object_int_add(json_neigh,
13319 "bgpTimerConfiguredHoldTimeMsecs",
13320 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13321 ? p->holdtime * 1000
13322 : bgp->default_holdtime * 1000);
13323 json_object_int_add(json_neigh,
13324 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13325 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13326 ? p->keepalive * 1000
13327 : bgp->default_keepalive * 1000);
13328 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13329 p->v_holdtime * 1000);
13330 json_object_int_add(json_neigh,
13331 "bgpTimerKeepAliveIntervalMsecs",
13332 p->v_keepalive * 1000);
13333 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13334 json_object_int_add(json_neigh,
13335 "bgpTimerDelayOpenTimeMsecs",
13336 p->v_delayopen * 1000);
13337 }
13338
13339 /* Configured and Synced tcp-mss value for peer */
13340 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13341 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13342 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13343 p->tcp_mss);
13344 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13345 sync_tcp_mss);
13346 }
13347
13348 /* Extended Optional Parameters Length for BGP OPEN Message */
13349 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13350 json_object_boolean_true_add(
13351 json_neigh, "extendedOptionalParametersLength");
13352 else
13353 json_object_boolean_false_add(
13354 json_neigh, "extendedOptionalParametersLength");
13355
13356 /* Conditional advertisements */
13357 json_object_int_add(
13358 json_neigh,
13359 "bgpTimerConfiguredConditionalAdvertisementsSec",
13360 bgp->condition_check_period);
13361 if (thread_is_scheduled(bgp->t_condition_check))
13362 json_object_int_add(
13363 json_neigh,
13364 "bgpTimerUntilConditionalAdvertisementsSec",
13365 thread_timer_remain_second(
13366 bgp->t_condition_check));
13367 } else {
13368 /* Administrative shutdown. */
13369 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13370 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13371 vty_out(vty, " Administratively shut down\n");
13372
13373 /* BGP Version. */
13374 vty_out(vty, " BGP version 4");
13375 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13376 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13377
13378 /* Confederation */
13379 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13380 && bgp_confederation_peers_check(bgp, p->as))
13381 vty_out(vty,
13382 " Neighbor under common administration\n");
13383
13384 /* Status. */
13385 vty_out(vty, " BGP state = %s",
13386 lookup_msg(bgp_status_msg, p->status, NULL));
13387
13388 if (peer_established(p))
13389 vty_out(vty, ", up for %8s",
13390 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13391 0, NULL));
13392
13393 else if (p->status == Active) {
13394 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13395 vty_out(vty, " (passive)");
13396 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13397 vty_out(vty, " (NSF passive)");
13398 }
13399 vty_out(vty, "\n");
13400
13401 /* read timer */
13402 vty_out(vty, " Last read %s",
13403 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13404 NULL));
13405 vty_out(vty, ", Last write %s\n",
13406 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13407 NULL));
13408
13409 /* Configured timer values. */
13410 vty_out(vty,
13411 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13412 p->v_holdtime, p->v_keepalive);
13413 vty_out(vty, " Configured hold time is %d seconds",
13414 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13415 ? p->holdtime
13416 : bgp->default_holdtime);
13417 vty_out(vty, ", keepalive interval is %d seconds\n",
13418 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13419 ? p->keepalive
13420 : bgp->default_keepalive);
13421 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13422 vty_out(vty,
13423 " Configured DelayOpenTime is %d seconds\n",
13424 p->delayopen);
13425
13426 /* Configured and synced tcp-mss value for peer */
13427 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13428 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13429 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13430 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13431 }
13432
13433 /* Extended Optional Parameters Length for BGP OPEN Message */
13434 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13435 vty_out(vty,
13436 " Extended Optional Parameters Length is enabled\n");
13437
13438 /* Conditional advertisements */
13439 vty_out(vty,
13440 " Configured conditional advertisements interval is %d seconds\n",
13441 bgp->condition_check_period);
13442 if (thread_is_scheduled(bgp->t_condition_check))
13443 vty_out(vty,
13444 " Time until conditional advertisements begin is %lu seconds\n",
13445 thread_timer_remain_second(
13446 bgp->t_condition_check));
13447 }
13448 /* Capability. */
13449 if (peer_established(p) &&
13450 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13451 if (use_json) {
13452 json_object *json_cap = NULL;
13453
13454 json_cap = json_object_new_object();
13455
13456 /* AS4 */
13457 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13458 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13459 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13460 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13461 json_object_string_add(
13462 json_cap, "4byteAs",
13463 "advertisedAndReceived");
13464 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13465 json_object_string_add(json_cap,
13466 "4byteAs",
13467 "advertised");
13468 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13469 json_object_string_add(json_cap,
13470 "4byteAs",
13471 "received");
13472 }
13473
13474 /* Extended Message Support */
13475 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13476 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13477 json_object_string_add(json_cap,
13478 "extendedMessage",
13479 "advertisedAndReceived");
13480 else if (CHECK_FLAG(p->cap,
13481 PEER_CAP_EXTENDED_MESSAGE_ADV))
13482 json_object_string_add(json_cap,
13483 "extendedMessage",
13484 "advertised");
13485 else if (CHECK_FLAG(p->cap,
13486 PEER_CAP_EXTENDED_MESSAGE_RCV))
13487 json_object_string_add(json_cap,
13488 "extendedMessage",
13489 "received");
13490
13491 /* AddPath */
13492 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13493 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13494 json_object *json_add = NULL;
13495 const char *print_store;
13496
13497 json_add = json_object_new_object();
13498
13499 FOREACH_AFI_SAFI (afi, safi) {
13500 json_object *json_sub = NULL;
13501 json_sub = json_object_new_object();
13502 print_store = get_afi_safi_str(
13503 afi, safi, true);
13504
13505 if (CHECK_FLAG(
13506 p->af_cap[afi][safi],
13507 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13508 CHECK_FLAG(
13509 p->af_cap[afi][safi],
13510 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13511 if (CHECK_FLAG(
13512 p->af_cap[afi]
13513 [safi],
13514 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13515 CHECK_FLAG(
13516 p->af_cap[afi]
13517 [safi],
13518 PEER_CAP_ADDPATH_AF_TX_RCV))
13519 json_object_boolean_true_add(
13520 json_sub,
13521 "txAdvertisedAndReceived");
13522 else if (
13523 CHECK_FLAG(
13524 p->af_cap[afi]
13525 [safi],
13526 PEER_CAP_ADDPATH_AF_TX_ADV))
13527 json_object_boolean_true_add(
13528 json_sub,
13529 "txAdvertised");
13530 else if (
13531 CHECK_FLAG(
13532 p->af_cap[afi]
13533 [safi],
13534 PEER_CAP_ADDPATH_AF_TX_RCV))
13535 json_object_boolean_true_add(
13536 json_sub,
13537 "txReceived");
13538 }
13539
13540 if (CHECK_FLAG(
13541 p->af_cap[afi][safi],
13542 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13543 CHECK_FLAG(
13544 p->af_cap[afi][safi],
13545 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13546 if (CHECK_FLAG(
13547 p->af_cap[afi]
13548 [safi],
13549 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13550 CHECK_FLAG(
13551 p->af_cap[afi]
13552 [safi],
13553 PEER_CAP_ADDPATH_AF_RX_RCV))
13554 json_object_boolean_true_add(
13555 json_sub,
13556 "rxAdvertisedAndReceived");
13557 else if (
13558 CHECK_FLAG(
13559 p->af_cap[afi]
13560 [safi],
13561 PEER_CAP_ADDPATH_AF_RX_ADV))
13562 json_object_boolean_true_add(
13563 json_sub,
13564 "rxAdvertised");
13565 else if (
13566 CHECK_FLAG(
13567 p->af_cap[afi]
13568 [safi],
13569 PEER_CAP_ADDPATH_AF_RX_RCV))
13570 json_object_boolean_true_add(
13571 json_sub,
13572 "rxReceived");
13573 }
13574
13575 if (CHECK_FLAG(
13576 p->af_cap[afi][safi],
13577 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13578 CHECK_FLAG(
13579 p->af_cap[afi][safi],
13580 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13581 CHECK_FLAG(
13582 p->af_cap[afi][safi],
13583 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13584 CHECK_FLAG(
13585 p->af_cap[afi][safi],
13586 PEER_CAP_ADDPATH_AF_RX_RCV))
13587 json_object_object_add(
13588 json_add, print_store,
13589 json_sub);
13590 else
13591 json_object_free(json_sub);
13592 }
13593
13594 json_object_object_add(json_cap, "addPath",
13595 json_add);
13596 }
13597
13598 /* Dynamic */
13599 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13600 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13601 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13602 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13603 json_object_string_add(
13604 json_cap, "dynamic",
13605 "advertisedAndReceived");
13606 else if (CHECK_FLAG(p->cap,
13607 PEER_CAP_DYNAMIC_ADV))
13608 json_object_string_add(json_cap,
13609 "dynamic",
13610 "advertised");
13611 else if (CHECK_FLAG(p->cap,
13612 PEER_CAP_DYNAMIC_RCV))
13613 json_object_string_add(json_cap,
13614 "dynamic",
13615 "received");
13616 }
13617
13618 /* Role */
13619 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13620 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13621 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13622 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13623 json_object_string_add(
13624 json_cap, "role",
13625 "advertisedAndReceived");
13626 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13627 json_object_string_add(json_cap, "role",
13628 "advertised");
13629 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13630 json_object_string_add(json_cap, "role",
13631 "received");
13632 }
13633
13634 /* Extended nexthop */
13635 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13636 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13637 json_object *json_nxt = NULL;
13638 const char *print_store;
13639
13640
13641 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13642 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13643 json_object_string_add(
13644 json_cap, "extendedNexthop",
13645 "advertisedAndReceived");
13646 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13647 json_object_string_add(
13648 json_cap, "extendedNexthop",
13649 "advertised");
13650 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13651 json_object_string_add(
13652 json_cap, "extendedNexthop",
13653 "received");
13654
13655 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13656 json_nxt = json_object_new_object();
13657
13658 for (safi = SAFI_UNICAST;
13659 safi < SAFI_MAX; safi++) {
13660 if (CHECK_FLAG(
13661 p->af_cap[AFI_IP]
13662 [safi],
13663 PEER_CAP_ENHE_AF_RCV)) {
13664 print_store =
13665 get_afi_safi_str(
13666 AFI_IP,
13667 safi,
13668 true);
13669 json_object_string_add(
13670 json_nxt,
13671 print_store,
13672 "recieved"); /* misspelled for compatibility */
13673 }
13674 }
13675 json_object_object_add(
13676 json_cap,
13677 "extendedNexthopFamililesByPeer",
13678 json_nxt);
13679 }
13680 }
13681
13682 /* Long-lived Graceful Restart */
13683 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13684 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13685 json_object *json_llgr = NULL;
13686 const char *afi_safi_str;
13687
13688 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13689 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13690 json_object_string_add(
13691 json_cap,
13692 "longLivedGracefulRestart",
13693 "advertisedAndReceived");
13694 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13695 json_object_string_add(
13696 json_cap,
13697 "longLivedGracefulRestart",
13698 "advertised");
13699 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13700 json_object_string_add(
13701 json_cap,
13702 "longLivedGracefulRestart",
13703 "received");
13704
13705 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13706 json_llgr = json_object_new_object();
13707
13708 FOREACH_AFI_SAFI (afi, safi) {
13709 if (CHECK_FLAG(
13710 p->af_cap[afi]
13711 [safi],
13712 PEER_CAP_ENHE_AF_RCV)) {
13713 afi_safi_str =
13714 get_afi_safi_str(
13715 afi,
13716 safi,
13717 true);
13718 json_object_string_add(
13719 json_llgr,
13720 afi_safi_str,
13721 "received");
13722 }
13723 }
13724 json_object_object_add(
13725 json_cap,
13726 "longLivedGracefulRestartByPeer",
13727 json_llgr);
13728 }
13729 }
13730
13731 /* Route Refresh */
13732 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13733 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13734 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13735 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13736 (CHECK_FLAG(p->cap,
13737 PEER_CAP_REFRESH_NEW_RCV) ||
13738 CHECK_FLAG(p->cap,
13739 PEER_CAP_REFRESH_OLD_RCV))) {
13740 if (CHECK_FLAG(
13741 p->cap,
13742 PEER_CAP_REFRESH_OLD_RCV) &&
13743 CHECK_FLAG(
13744 p->cap,
13745 PEER_CAP_REFRESH_NEW_RCV))
13746 json_object_string_add(
13747 json_cap,
13748 "routeRefresh",
13749 "advertisedAndReceivedOldNew");
13750 else {
13751 if (CHECK_FLAG(
13752 p->cap,
13753 PEER_CAP_REFRESH_OLD_RCV))
13754 json_object_string_add(
13755 json_cap,
13756 "routeRefresh",
13757 "advertisedAndReceivedOld");
13758 else
13759 json_object_string_add(
13760 json_cap,
13761 "routeRefresh",
13762 "advertisedAndReceivedNew");
13763 }
13764 } else if (CHECK_FLAG(p->cap,
13765 PEER_CAP_REFRESH_ADV))
13766 json_object_string_add(json_cap,
13767 "routeRefresh",
13768 "advertised");
13769 else if (CHECK_FLAG(p->cap,
13770 PEER_CAP_REFRESH_NEW_RCV) ||
13771 CHECK_FLAG(p->cap,
13772 PEER_CAP_REFRESH_OLD_RCV))
13773 json_object_string_add(json_cap,
13774 "routeRefresh",
13775 "received");
13776 }
13777
13778 /* Enhanced Route Refresh */
13779 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13780 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13781 if (CHECK_FLAG(p->cap,
13782 PEER_CAP_ENHANCED_RR_ADV) &&
13783 CHECK_FLAG(p->cap,
13784 PEER_CAP_ENHANCED_RR_RCV))
13785 json_object_string_add(
13786 json_cap,
13787 "enhancedRouteRefresh",
13788 "advertisedAndReceived");
13789 else if (CHECK_FLAG(p->cap,
13790 PEER_CAP_ENHANCED_RR_ADV))
13791 json_object_string_add(
13792 json_cap,
13793 "enhancedRouteRefresh",
13794 "advertised");
13795 else if (CHECK_FLAG(p->cap,
13796 PEER_CAP_ENHANCED_RR_RCV))
13797 json_object_string_add(
13798 json_cap,
13799 "enhancedRouteRefresh",
13800 "received");
13801 }
13802
13803 /* Multiprotocol Extensions */
13804 json_object *json_multi = NULL;
13805
13806 json_multi = json_object_new_object();
13807
13808 FOREACH_AFI_SAFI (afi, safi) {
13809 if (p->afc_adv[afi][safi] ||
13810 p->afc_recv[afi][safi]) {
13811 json_object *json_exten = NULL;
13812 json_exten = json_object_new_object();
13813
13814 if (p->afc_adv[afi][safi] &&
13815 p->afc_recv[afi][safi])
13816 json_object_boolean_true_add(
13817 json_exten,
13818 "advertisedAndReceived");
13819 else if (p->afc_adv[afi][safi])
13820 json_object_boolean_true_add(
13821 json_exten,
13822 "advertised");
13823 else if (p->afc_recv[afi][safi])
13824 json_object_boolean_true_add(
13825 json_exten, "received");
13826
13827 json_object_object_add(
13828 json_multi,
13829 get_afi_safi_str(afi, safi,
13830 true),
13831 json_exten);
13832 }
13833 }
13834 json_object_object_add(json_cap,
13835 "multiprotocolExtensions",
13836 json_multi);
13837
13838 /* Hostname capabilities */
13839 json_object *json_hname = NULL;
13840
13841 json_hname = json_object_new_object();
13842
13843 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13844 json_object_string_add(
13845 json_hname, "advHostName",
13846 bgp->peer_self->hostname
13847 ? bgp->peer_self->hostname
13848 : "n/a");
13849 json_object_string_add(
13850 json_hname, "advDomainName",
13851 bgp->peer_self->domainname
13852 ? bgp->peer_self->domainname
13853 : "n/a");
13854 }
13855
13856
13857 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13858 json_object_string_add(
13859 json_hname, "rcvHostName",
13860 p->hostname ? p->hostname : "n/a");
13861 json_object_string_add(
13862 json_hname, "rcvDomainName",
13863 p->domainname ? p->domainname : "n/a");
13864 }
13865
13866 json_object_object_add(json_cap, "hostName",
13867 json_hname);
13868
13869 /* Software Version capability */
13870 json_object *json_soft_version = NULL;
13871
13872 json_soft_version = json_object_new_object();
13873
13874 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV))
13875 json_object_string_add(
13876 json_soft_version,
13877 "advertisedSoftwareVersion",
13878 cmd_software_version_get());
13879
13880 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV))
13881 json_object_string_add(
13882 json_soft_version,
13883 "receivedSoftwareVersion",
13884 p->soft_version ? p->soft_version
13885 : "n/a");
13886
13887 json_object_object_add(json_cap, "softwareVersion",
13888 json_soft_version);
13889
13890 /* Graceful Restart */
13891 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13892 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13893 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13894 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13895 json_object_string_add(
13896 json_cap, "gracefulRestart",
13897 "advertisedAndReceived");
13898 else if (CHECK_FLAG(p->cap,
13899 PEER_CAP_RESTART_ADV))
13900 json_object_string_add(
13901 json_cap,
13902 "gracefulRestartCapability",
13903 "advertised");
13904 else if (CHECK_FLAG(p->cap,
13905 PEER_CAP_RESTART_RCV))
13906 json_object_string_add(
13907 json_cap,
13908 "gracefulRestartCapability",
13909 "received");
13910
13911 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13912 int restart_af_count = 0;
13913 json_object *json_restart = NULL;
13914 json_restart = json_object_new_object();
13915
13916 json_object_int_add(
13917 json_cap,
13918 "gracefulRestartRemoteTimerMsecs",
13919 p->v_gr_restart * 1000);
13920
13921 FOREACH_AFI_SAFI (afi, safi) {
13922 if (CHECK_FLAG(
13923 p->af_cap[afi]
13924 [safi],
13925 PEER_CAP_RESTART_AF_RCV)) {
13926 json_object *json_sub =
13927 NULL;
13928 json_sub =
13929 json_object_new_object();
13930
13931 if (CHECK_FLAG(
13932 p->af_cap
13933 [afi]
13934 [safi],
13935 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13936 json_object_boolean_true_add(
13937 json_sub,
13938 "preserved");
13939 restart_af_count++;
13940 json_object_object_add(
13941 json_restart,
13942 get_afi_safi_str(
13943 afi,
13944 safi,
13945 true),
13946 json_sub);
13947 }
13948 }
13949 if (!restart_af_count) {
13950 json_object_string_add(
13951 json_cap,
13952 "addressFamiliesByPeer",
13953 "none");
13954 json_object_free(json_restart);
13955 } else
13956 json_object_object_add(
13957 json_cap,
13958 "addressFamiliesByPeer",
13959 json_restart);
13960 }
13961 }
13962 json_object_object_add(
13963 json_neigh, "neighborCapabilities", json_cap);
13964 } else {
13965 vty_out(vty, " Neighbor capabilities:\n");
13966
13967 /* AS4 */
13968 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13969 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13970 vty_out(vty, " 4 Byte AS:");
13971 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13972 vty_out(vty, " advertised");
13973 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13974 vty_out(vty, " %sreceived",
13975 CHECK_FLAG(p->cap,
13976 PEER_CAP_AS4_ADV)
13977 ? "and "
13978 : "");
13979 vty_out(vty, "\n");
13980 }
13981
13982 /* Extended Message Support */
13983 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13984 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13985 vty_out(vty, " Extended Message:");
13986 if (CHECK_FLAG(p->cap,
13987 PEER_CAP_EXTENDED_MESSAGE_ADV))
13988 vty_out(vty, " advertised");
13989 if (CHECK_FLAG(p->cap,
13990 PEER_CAP_EXTENDED_MESSAGE_RCV))
13991 vty_out(vty, " %sreceived",
13992 CHECK_FLAG(
13993 p->cap,
13994 PEER_CAP_EXTENDED_MESSAGE_ADV)
13995 ? "and "
13996 : "");
13997 vty_out(vty, "\n");
13998 }
13999
14000 /* AddPath */
14001 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
14002 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
14003 vty_out(vty, " AddPath:\n");
14004
14005 FOREACH_AFI_SAFI (afi, safi) {
14006 if (CHECK_FLAG(
14007 p->af_cap[afi][safi],
14008 PEER_CAP_ADDPATH_AF_TX_ADV) ||
14009 CHECK_FLAG(
14010 p->af_cap[afi][safi],
14011 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14012 vty_out(vty, " %s: TX ",
14013 get_afi_safi_str(
14014 afi, safi,
14015 false));
14016
14017 if (CHECK_FLAG(
14018 p->af_cap[afi]
14019 [safi],
14020 PEER_CAP_ADDPATH_AF_TX_ADV))
14021 vty_out(vty,
14022 "advertised");
14023
14024 if (CHECK_FLAG(
14025 p->af_cap[afi]
14026 [safi],
14027 PEER_CAP_ADDPATH_AF_TX_RCV))
14028 vty_out(vty,
14029 "%sreceived",
14030 CHECK_FLAG(
14031 p->af_cap
14032 [afi]
14033 [safi],
14034 PEER_CAP_ADDPATH_AF_TX_ADV)
14035 ? " and "
14036 : "");
14037
14038 vty_out(vty, "\n");
14039 }
14040
14041 if (CHECK_FLAG(
14042 p->af_cap[afi][safi],
14043 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14044 CHECK_FLAG(
14045 p->af_cap[afi][safi],
14046 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14047 vty_out(vty, " %s: RX ",
14048 get_afi_safi_str(
14049 afi, safi,
14050 false));
14051
14052 if (CHECK_FLAG(
14053 p->af_cap[afi]
14054 [safi],
14055 PEER_CAP_ADDPATH_AF_RX_ADV))
14056 vty_out(vty,
14057 "advertised");
14058
14059 if (CHECK_FLAG(
14060 p->af_cap[afi]
14061 [safi],
14062 PEER_CAP_ADDPATH_AF_RX_RCV))
14063 vty_out(vty,
14064 "%sreceived",
14065 CHECK_FLAG(
14066 p->af_cap
14067 [afi]
14068 [safi],
14069 PEER_CAP_ADDPATH_AF_RX_ADV)
14070 ? " and "
14071 : "");
14072
14073 vty_out(vty, "\n");
14074 }
14075 }
14076 }
14077
14078 /* Dynamic */
14079 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14080 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14081 vty_out(vty, " Dynamic:");
14082 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14083 vty_out(vty, " advertised");
14084 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14085 vty_out(vty, " %sreceived",
14086 CHECK_FLAG(p->cap,
14087 PEER_CAP_DYNAMIC_ADV)
14088 ? "and "
14089 : "");
14090 vty_out(vty, "\n");
14091 }
14092
14093 /* Role */
14094 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14095 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14096 vty_out(vty, " Role:");
14097 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14098 vty_out(vty, " advertised");
14099 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14100 vty_out(vty, " %sreceived",
14101 CHECK_FLAG(p->cap,
14102 PEER_CAP_ROLE_ADV)
14103 ? "and "
14104 : "");
14105 vty_out(vty, "\n");
14106 }
14107
14108 /* Extended nexthop */
14109 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14110 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14111 vty_out(vty, " Extended nexthop:");
14112 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14113 vty_out(vty, " advertised");
14114 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14115 vty_out(vty, " %sreceived",
14116 CHECK_FLAG(p->cap,
14117 PEER_CAP_ENHE_ADV)
14118 ? "and "
14119 : "");
14120 vty_out(vty, "\n");
14121
14122 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
14123 vty_out(vty,
14124 " Address families by peer:\n ");
14125 for (safi = SAFI_UNICAST;
14126 safi < SAFI_MAX; safi++)
14127 if (CHECK_FLAG(
14128 p->af_cap[AFI_IP]
14129 [safi],
14130 PEER_CAP_ENHE_AF_RCV))
14131 vty_out(vty,
14132 " %s\n",
14133 get_afi_safi_str(
14134 AFI_IP,
14135 safi,
14136 false));
14137 }
14138 }
14139
14140 /* Long-lived Graceful Restart */
14141 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14142 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14143 vty_out(vty,
14144 " Long-lived Graceful Restart:");
14145 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14146 vty_out(vty, " advertised");
14147 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14148 vty_out(vty, " %sreceived",
14149 CHECK_FLAG(p->cap,
14150 PEER_CAP_LLGR_ADV)
14151 ? "and "
14152 : "");
14153 vty_out(vty, "\n");
14154
14155 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14156 vty_out(vty,
14157 " Address families by peer:\n");
14158 FOREACH_AFI_SAFI (afi, safi)
14159 if (CHECK_FLAG(
14160 p->af_cap[afi]
14161 [safi],
14162 PEER_CAP_LLGR_AF_RCV))
14163 vty_out(vty,
14164 " %s\n",
14165 get_afi_safi_str(
14166 afi,
14167 safi,
14168 false));
14169 }
14170 }
14171
14172 /* Route Refresh */
14173 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14174 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14175 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14176 vty_out(vty, " Route refresh:");
14177 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14178 vty_out(vty, " advertised");
14179 if (CHECK_FLAG(p->cap,
14180 PEER_CAP_REFRESH_NEW_RCV) ||
14181 CHECK_FLAG(p->cap,
14182 PEER_CAP_REFRESH_OLD_RCV))
14183 vty_out(vty, " %sreceived(%s)",
14184 CHECK_FLAG(p->cap,
14185 PEER_CAP_REFRESH_ADV)
14186 ? "and "
14187 : "",
14188 (CHECK_FLAG(
14189 p->cap,
14190 PEER_CAP_REFRESH_OLD_RCV) &&
14191 CHECK_FLAG(
14192 p->cap,
14193 PEER_CAP_REFRESH_NEW_RCV))
14194 ? "old & new"
14195 : CHECK_FLAG(
14196 p->cap,
14197 PEER_CAP_REFRESH_OLD_RCV)
14198 ? "old"
14199 : "new");
14200
14201 vty_out(vty, "\n");
14202 }
14203
14204 /* Enhanced Route Refresh */
14205 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14206 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14207 vty_out(vty, " Enhanced Route Refresh:");
14208 if (CHECK_FLAG(p->cap,
14209 PEER_CAP_ENHANCED_RR_ADV))
14210 vty_out(vty, " advertised");
14211 if (CHECK_FLAG(p->cap,
14212 PEER_CAP_ENHANCED_RR_RCV))
14213 vty_out(vty, " %sreceived",
14214 CHECK_FLAG(p->cap,
14215 PEER_CAP_REFRESH_ADV)
14216 ? "and "
14217 : "");
14218 vty_out(vty, "\n");
14219 }
14220
14221 /* Multiprotocol Extensions */
14222 FOREACH_AFI_SAFI (afi, safi)
14223 if (p->afc_adv[afi][safi] ||
14224 p->afc_recv[afi][safi]) {
14225 vty_out(vty, " Address Family %s:",
14226 get_afi_safi_str(afi, safi,
14227 false));
14228 if (p->afc_adv[afi][safi])
14229 vty_out(vty, " advertised");
14230 if (p->afc_recv[afi][safi])
14231 vty_out(vty, " %sreceived",
14232 p->afc_adv[afi][safi]
14233 ? "and "
14234 : "");
14235 vty_out(vty, "\n");
14236 }
14237
14238 /* Hostname capability */
14239 vty_out(vty, " Hostname Capability:");
14240
14241 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14242 vty_out(vty,
14243 " advertised (name: %s,domain name: %s)",
14244 bgp->peer_self->hostname
14245 ? bgp->peer_self->hostname
14246 : "n/a",
14247 bgp->peer_self->domainname
14248 ? bgp->peer_self->domainname
14249 : "n/a");
14250 } else {
14251 vty_out(vty, " not advertised");
14252 }
14253
14254 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14255 vty_out(vty,
14256 " received (name: %s,domain name: %s)",
14257 p->hostname ? p->hostname : "n/a",
14258 p->domainname ? p->domainname : "n/a");
14259 } else {
14260 vty_out(vty, " not received");
14261 }
14262
14263 vty_out(vty, "\n");
14264
14265 /* Software Version capability */
14266 vty_out(vty, " Version Capability:");
14267
14268 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_ADV)) {
14269 vty_out(vty,
14270 " advertised software version (%s)",
14271 cmd_software_version_get());
14272 } else
14273 vty_out(vty, " not advertised");
14274
14275 if (CHECK_FLAG(p->cap, PEER_CAP_SOFT_VERSION_RCV)) {
14276 vty_out(vty, " received software version (%s)",
14277 p->soft_version ? p->soft_version
14278 : "n/a");
14279 } else
14280 vty_out(vty, " not received");
14281
14282 vty_out(vty, "\n");
14283
14284 /* Graceful Restart */
14285 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14286 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14287 vty_out(vty,
14288 " Graceful Restart Capability:");
14289 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14290 vty_out(vty, " advertised");
14291 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14292 vty_out(vty, " %sreceived",
14293 CHECK_FLAG(p->cap,
14294 PEER_CAP_RESTART_ADV)
14295 ? "and "
14296 : "");
14297 vty_out(vty, "\n");
14298
14299 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14300 int restart_af_count = 0;
14301
14302 vty_out(vty,
14303 " Remote Restart timer is %d seconds\n",
14304 p->v_gr_restart);
14305 vty_out(vty,
14306 " Address families by peer:\n ");
14307
14308 FOREACH_AFI_SAFI (afi, safi)
14309 if (CHECK_FLAG(
14310 p->af_cap[afi]
14311 [safi],
14312 PEER_CAP_RESTART_AF_RCV)) {
14313 vty_out(vty, "%s%s(%s)",
14314 restart_af_count
14315 ? ", "
14316 : "",
14317 get_afi_safi_str(
14318 afi,
14319 safi,
14320 false),
14321 CHECK_FLAG(
14322 p->af_cap
14323 [afi]
14324 [safi],
14325 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14326 ? "preserved"
14327 : "not preserved");
14328 restart_af_count++;
14329 }
14330 if (!restart_af_count)
14331 vty_out(vty, "none");
14332 vty_out(vty, "\n");
14333 }
14334 } /* Graceful Restart */
14335 }
14336 }
14337
14338 /* graceful restart information */
14339 json_object *json_grace = NULL;
14340 json_object *json_grace_send = NULL;
14341 json_object *json_grace_recv = NULL;
14342 int eor_send_af_count = 0;
14343 int eor_receive_af_count = 0;
14344
14345 if (use_json) {
14346 json_grace = json_object_new_object();
14347 json_grace_send = json_object_new_object();
14348 json_grace_recv = json_object_new_object();
14349
14350 if ((peer_established(p)) &&
14351 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14352 FOREACH_AFI_SAFI (afi, safi) {
14353 if (CHECK_FLAG(p->af_sflags[afi][safi],
14354 PEER_STATUS_EOR_SEND)) {
14355 json_object_boolean_true_add(
14356 json_grace_send,
14357 get_afi_safi_str(afi, safi,
14358 true));
14359 eor_send_af_count++;
14360 }
14361 }
14362 FOREACH_AFI_SAFI (afi, safi) {
14363 if (CHECK_FLAG(p->af_sflags[afi][safi],
14364 PEER_STATUS_EOR_RECEIVED)) {
14365 json_object_boolean_true_add(
14366 json_grace_recv,
14367 get_afi_safi_str(afi, safi,
14368 true));
14369 eor_receive_af_count++;
14370 }
14371 }
14372 }
14373 json_object_object_add(json_grace, "endOfRibSend",
14374 json_grace_send);
14375 json_object_object_add(json_grace, "endOfRibRecv",
14376 json_grace_recv);
14377
14378
14379 if (p->t_gr_restart)
14380 json_object_int_add(
14381 json_grace, "gracefulRestartTimerMsecs",
14382 thread_timer_remain_second(p->t_gr_restart) *
14383 1000);
14384
14385 if (p->t_gr_stale)
14386 json_object_int_add(
14387 json_grace, "gracefulStalepathTimerMsecs",
14388 thread_timer_remain_second(p->t_gr_stale) *
14389 1000);
14390 /* more gr info in new format */
14391 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14392 json_object_object_add(json_neigh, "gracefulRestartInfo",
14393 json_grace);
14394 } else {
14395 vty_out(vty, " Graceful restart information:\n");
14396 if ((peer_established(p)) &&
14397 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14398
14399 vty_out(vty, " End-of-RIB send: ");
14400 FOREACH_AFI_SAFI (afi, safi) {
14401 if (CHECK_FLAG(p->af_sflags[afi][safi],
14402 PEER_STATUS_EOR_SEND)) {
14403 vty_out(vty, "%s%s",
14404 eor_send_af_count ? ", " : "",
14405 get_afi_safi_str(afi, safi,
14406 false));
14407 eor_send_af_count++;
14408 }
14409 }
14410 vty_out(vty, "\n");
14411 vty_out(vty, " End-of-RIB received: ");
14412 FOREACH_AFI_SAFI (afi, safi) {
14413 if (CHECK_FLAG(p->af_sflags[afi][safi],
14414 PEER_STATUS_EOR_RECEIVED)) {
14415 vty_out(vty, "%s%s",
14416 eor_receive_af_count ? ", "
14417 : "",
14418 get_afi_safi_str(afi, safi,
14419 false));
14420 eor_receive_af_count++;
14421 }
14422 }
14423 vty_out(vty, "\n");
14424 }
14425
14426 if (p->t_gr_restart)
14427 vty_out(vty,
14428 " The remaining time of restart timer is %ld\n",
14429 thread_timer_remain_second(p->t_gr_restart));
14430
14431 if (p->t_gr_stale)
14432 vty_out(vty,
14433 " The remaining time of stalepath timer is %ld\n",
14434 thread_timer_remain_second(p->t_gr_stale));
14435
14436 /* more gr info in new format */
14437 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14438 }
14439
14440 if (use_json) {
14441 json_object *json_stat = NULL;
14442 json_stat = json_object_new_object();
14443 /* Packet counts. */
14444
14445 atomic_size_t outq_count, inq_count;
14446 outq_count = atomic_load_explicit(&p->obuf->count,
14447 memory_order_relaxed);
14448 inq_count = atomic_load_explicit(&p->ibuf->count,
14449 memory_order_relaxed);
14450
14451 json_object_int_add(json_stat, "depthInq",
14452 (unsigned long)inq_count);
14453 json_object_int_add(json_stat, "depthOutq",
14454 (unsigned long)outq_count);
14455 json_object_int_add(json_stat, "opensSent",
14456 atomic_load_explicit(&p->open_out,
14457 memory_order_relaxed));
14458 json_object_int_add(json_stat, "opensRecv",
14459 atomic_load_explicit(&p->open_in,
14460 memory_order_relaxed));
14461 json_object_int_add(json_stat, "notificationsSent",
14462 atomic_load_explicit(&p->notify_out,
14463 memory_order_relaxed));
14464 json_object_int_add(json_stat, "notificationsRecv",
14465 atomic_load_explicit(&p->notify_in,
14466 memory_order_relaxed));
14467 json_object_int_add(json_stat, "updatesSent",
14468 atomic_load_explicit(&p->update_out,
14469 memory_order_relaxed));
14470 json_object_int_add(json_stat, "updatesRecv",
14471 atomic_load_explicit(&p->update_in,
14472 memory_order_relaxed));
14473 json_object_int_add(json_stat, "keepalivesSent",
14474 atomic_load_explicit(&p->keepalive_out,
14475 memory_order_relaxed));
14476 json_object_int_add(json_stat, "keepalivesRecv",
14477 atomic_load_explicit(&p->keepalive_in,
14478 memory_order_relaxed));
14479 json_object_int_add(json_stat, "routeRefreshSent",
14480 atomic_load_explicit(&p->refresh_out,
14481 memory_order_relaxed));
14482 json_object_int_add(json_stat, "routeRefreshRecv",
14483 atomic_load_explicit(&p->refresh_in,
14484 memory_order_relaxed));
14485 json_object_int_add(json_stat, "capabilitySent",
14486 atomic_load_explicit(&p->dynamic_cap_out,
14487 memory_order_relaxed));
14488 json_object_int_add(json_stat, "capabilityRecv",
14489 atomic_load_explicit(&p->dynamic_cap_in,
14490 memory_order_relaxed));
14491 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14492 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14493 json_object_object_add(json_neigh, "messageStats", json_stat);
14494 } else {
14495 atomic_size_t outq_count, inq_count, open_out, open_in,
14496 notify_out, notify_in, update_out, update_in,
14497 keepalive_out, keepalive_in, refresh_out, refresh_in,
14498 dynamic_cap_out, dynamic_cap_in;
14499 outq_count = atomic_load_explicit(&p->obuf->count,
14500 memory_order_relaxed);
14501 inq_count = atomic_load_explicit(&p->ibuf->count,
14502 memory_order_relaxed);
14503 open_out = atomic_load_explicit(&p->open_out,
14504 memory_order_relaxed);
14505 open_in =
14506 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14507 notify_out = atomic_load_explicit(&p->notify_out,
14508 memory_order_relaxed);
14509 notify_in = atomic_load_explicit(&p->notify_in,
14510 memory_order_relaxed);
14511 update_out = atomic_load_explicit(&p->update_out,
14512 memory_order_relaxed);
14513 update_in = atomic_load_explicit(&p->update_in,
14514 memory_order_relaxed);
14515 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14516 memory_order_relaxed);
14517 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14518 memory_order_relaxed);
14519 refresh_out = atomic_load_explicit(&p->refresh_out,
14520 memory_order_relaxed);
14521 refresh_in = atomic_load_explicit(&p->refresh_in,
14522 memory_order_relaxed);
14523 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14524 memory_order_relaxed);
14525 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14526 memory_order_relaxed);
14527
14528 /* Packet counts. */
14529 vty_out(vty, " Message statistics:\n");
14530 vty_out(vty, " Inq depth is %zu\n", inq_count);
14531 vty_out(vty, " Outq depth is %zu\n", outq_count);
14532 vty_out(vty, " Sent Rcvd\n");
14533 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14534 open_in);
14535 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14536 notify_in);
14537 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14538 update_in);
14539 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14540 keepalive_in);
14541 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14542 refresh_in);
14543 vty_out(vty, " Capability: %10zu %10zu\n",
14544 dynamic_cap_out, dynamic_cap_in);
14545 vty_out(vty, " Total: %10u %10u\n",
14546 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14547 }
14548
14549 if (use_json) {
14550 /* advertisement-interval */
14551 json_object_int_add(json_neigh,
14552 "minBtwnAdvertisementRunsTimerMsecs",
14553 p->v_routeadv * 1000);
14554
14555 /* Update-source. */
14556 if (p->update_if || p->update_source) {
14557 if (p->update_if)
14558 json_object_string_add(json_neigh,
14559 "updateSource",
14560 p->update_if);
14561 else if (p->update_source)
14562 json_object_string_addf(json_neigh,
14563 "updateSource", "%pSU",
14564 p->update_source);
14565 }
14566 } else {
14567 /* advertisement-interval */
14568 vty_out(vty,
14569 " Minimum time between advertisement runs is %d seconds\n",
14570 p->v_routeadv);
14571
14572 /* Update-source. */
14573 if (p->update_if || p->update_source) {
14574 vty_out(vty, " Update source is ");
14575 if (p->update_if)
14576 vty_out(vty, "%s", p->update_if);
14577 else if (p->update_source)
14578 vty_out(vty, "%pSU", p->update_source);
14579 vty_out(vty, "\n");
14580 }
14581
14582 vty_out(vty, "\n");
14583 }
14584
14585 /* Address Family Information */
14586 json_object *json_hold = NULL;
14587
14588 if (use_json)
14589 json_hold = json_object_new_object();
14590
14591 FOREACH_AFI_SAFI (afi, safi)
14592 if (p->afc[afi][safi])
14593 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14594 json_hold);
14595
14596 if (use_json) {
14597 json_object_object_add(json_neigh, "addressFamilyInfo",
14598 json_hold);
14599 json_object_int_add(json_neigh, "connectionsEstablished",
14600 p->established);
14601 json_object_int_add(json_neigh, "connectionsDropped",
14602 p->dropped);
14603 } else
14604 vty_out(vty, " Connections established %d; dropped %d\n",
14605 p->established, p->dropped);
14606
14607 if (!p->last_reset) {
14608 if (use_json)
14609 json_object_string_add(json_neigh, "lastReset",
14610 "never");
14611 else
14612 vty_out(vty, " Last reset never\n");
14613 } else {
14614 if (use_json) {
14615 time_t uptime;
14616 struct tm tm;
14617
14618 uptime = monotime(NULL);
14619 uptime -= p->resettime;
14620 gmtime_r(&uptime, &tm);
14621
14622 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14623 (tm.tm_sec * 1000)
14624 + (tm.tm_min * 60000)
14625 + (tm.tm_hour * 3600000));
14626 bgp_show_peer_reset(NULL, p, json_neigh, true);
14627 } else {
14628 vty_out(vty, " Last reset %s, ",
14629 peer_uptime(p->resettime, timebuf,
14630 BGP_UPTIME_LEN, 0, NULL));
14631
14632 bgp_show_peer_reset(vty, p, NULL, false);
14633 if (p->last_reset_cause_size) {
14634 msg = p->last_reset_cause;
14635 vty_out(vty,
14636 " Message received that caused BGP to send a NOTIFICATION:\n ");
14637 for (i = 1; i <= p->last_reset_cause_size;
14638 i++) {
14639 vty_out(vty, "%02X", *msg++);
14640
14641 if (i != p->last_reset_cause_size) {
14642 if (i % 16 == 0) {
14643 vty_out(vty, "\n ");
14644 } else if (i % 4 == 0) {
14645 vty_out(vty, " ");
14646 }
14647 }
14648 }
14649 vty_out(vty, "\n");
14650 }
14651 }
14652 }
14653
14654 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14655 if (use_json)
14656 json_object_boolean_true_add(json_neigh,
14657 "prefixesConfigExceedMax");
14658 else
14659 vty_out(vty,
14660 " Peer had exceeded the max. no. of prefixes configured.\n");
14661
14662 if (p->t_pmax_restart) {
14663 if (use_json) {
14664 json_object_boolean_true_add(
14665 json_neigh, "reducePrefixNumFrom");
14666 json_object_int_add(json_neigh,
14667 "restartInTimerMsec",
14668 thread_timer_remain_second(
14669 p->t_pmax_restart)
14670 * 1000);
14671 } else
14672 vty_out(vty,
14673 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14674 p->host, thread_timer_remain_second(
14675 p->t_pmax_restart));
14676 } else {
14677 if (use_json)
14678 json_object_boolean_true_add(
14679 json_neigh,
14680 "reducePrefixNumAndClearIpBgp");
14681 else
14682 vty_out(vty,
14683 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14684 p->host);
14685 }
14686 }
14687
14688 /* EBGP Multihop and GTSM */
14689 if (p->sort != BGP_PEER_IBGP) {
14690 if (use_json) {
14691 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14692 json_object_int_add(json_neigh,
14693 "externalBgpNbrMaxHopsAway",
14694 p->gtsm_hops);
14695 else
14696 json_object_int_add(json_neigh,
14697 "externalBgpNbrMaxHopsAway",
14698 p->ttl);
14699 } else {
14700 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14701 vty_out(vty,
14702 " External BGP neighbor may be up to %d hops away.\n",
14703 p->gtsm_hops);
14704 else
14705 vty_out(vty,
14706 " External BGP neighbor may be up to %d hops away.\n",
14707 p->ttl);
14708 }
14709 } else {
14710 if (use_json) {
14711 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14712 json_object_int_add(json_neigh,
14713 "internalBgpNbrMaxHopsAway",
14714 p->gtsm_hops);
14715 else
14716 json_object_int_add(json_neigh,
14717 "internalBgpNbrMaxHopsAway",
14718 p->ttl);
14719 } else {
14720 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14721 vty_out(vty,
14722 " Internal BGP neighbor may be up to %d hops away.\n",
14723 p->gtsm_hops);
14724 else
14725 vty_out(vty,
14726 " Internal BGP neighbor may be up to %d hops away.\n",
14727 p->ttl);
14728 }
14729 }
14730
14731 /* Local address. */
14732 if (p->su_local) {
14733 if (use_json) {
14734 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14735 p->su_local);
14736 json_object_int_add(json_neigh, "portLocal",
14737 ntohs(p->su_local->sin.sin_port));
14738 } else
14739 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14740 p->su_local, ntohs(p->su_local->sin.sin_port));
14741 } else {
14742 if (use_json) {
14743 json_object_string_add(json_neigh, "hostLocal",
14744 "Unknown");
14745 json_object_int_add(json_neigh, "portLocal", -1);
14746 }
14747 }
14748
14749 /* Remote address. */
14750 if (p->su_remote) {
14751 if (use_json) {
14752 json_object_string_addf(json_neigh, "hostForeign",
14753 "%pSU", p->su_remote);
14754 json_object_int_add(json_neigh, "portForeign",
14755 ntohs(p->su_remote->sin.sin_port));
14756 } else
14757 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14758 p->su_remote,
14759 ntohs(p->su_remote->sin.sin_port));
14760 } else {
14761 if (use_json) {
14762 json_object_string_add(json_neigh, "hostForeign",
14763 "Unknown");
14764 json_object_int_add(json_neigh, "portForeign", -1);
14765 }
14766 }
14767
14768 /* Nexthop display. */
14769 if (p->su_local) {
14770 if (use_json) {
14771 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14772 &p->nexthop.v4);
14773 json_object_string_addf(json_neigh, "nexthopGlobal",
14774 "%pI6", &p->nexthop.v6_global);
14775 json_object_string_addf(json_neigh, "nexthopLocal",
14776 "%pI6", &p->nexthop.v6_local);
14777 if (p->shared_network)
14778 json_object_string_add(json_neigh,
14779 "bgpConnection",
14780 "sharedNetwork");
14781 else
14782 json_object_string_add(json_neigh,
14783 "bgpConnection",
14784 "nonSharedNetwork");
14785 } else {
14786 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14787 vty_out(vty, "Nexthop global: %pI6\n",
14788 &p->nexthop.v6_global);
14789 vty_out(vty, "Nexthop local: %pI6\n",
14790 &p->nexthop.v6_local);
14791 vty_out(vty, "BGP connection: %s\n",
14792 p->shared_network ? "shared network"
14793 : "non shared network");
14794 }
14795 } else {
14796 if (use_json) {
14797 json_object_string_add(json_neigh, "nexthop",
14798 "Unknown");
14799 json_object_string_add(json_neigh, "nexthopGlobal",
14800 "Unknown");
14801 json_object_string_add(json_neigh, "nexthopLocal",
14802 "Unknown");
14803 json_object_string_add(json_neigh, "bgpConnection",
14804 "Unknown");
14805 }
14806 }
14807
14808 /* Timer information. */
14809 if (use_json) {
14810 json_object_int_add(json_neigh, "connectRetryTimer",
14811 p->v_connect);
14812 if (peer_established(p)) {
14813 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14814 p->rtt);
14815 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14816 json_object_int_add(json_neigh,
14817 "shutdownRttInMsecs",
14818 p->rtt_expected);
14819 json_object_int_add(json_neigh,
14820 "shutdownRttAfterCount",
14821 p->rtt_keepalive_rcv);
14822 }
14823 }
14824 if (p->t_start)
14825 json_object_int_add(
14826 json_neigh, "nextStartTimerDueInMsecs",
14827 thread_timer_remain_second(p->t_start) * 1000);
14828 if (p->t_connect)
14829 json_object_int_add(
14830 json_neigh, "nextConnectTimerDueInMsecs",
14831 thread_timer_remain_second(p->t_connect)
14832 * 1000);
14833 if (p->t_routeadv) {
14834 json_object_int_add(json_neigh, "mraiInterval",
14835 p->v_routeadv);
14836 json_object_int_add(
14837 json_neigh, "mraiTimerExpireInMsecs",
14838 thread_timer_remain_second(p->t_routeadv)
14839 * 1000);
14840 }
14841 if (p->password)
14842 json_object_int_add(json_neigh, "authenticationEnabled",
14843 1);
14844
14845 if (p->t_read)
14846 json_object_string_add(json_neigh, "readThread", "on");
14847 else
14848 json_object_string_add(json_neigh, "readThread", "off");
14849
14850 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14851 json_object_string_add(json_neigh, "writeThread", "on");
14852 else
14853 json_object_string_add(json_neigh, "writeThread",
14854 "off");
14855 } else {
14856 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14857 p->v_connect);
14858 if (peer_established(p)) {
14859 vty_out(vty, "Estimated round trip time: %d ms\n",
14860 p->rtt);
14861 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14862 vty_out(vty,
14863 "Shutdown when RTT > %dms, count > %u\n",
14864 p->rtt_expected, p->rtt_keepalive_rcv);
14865 }
14866 if (p->t_start)
14867 vty_out(vty, "Next start timer due in %ld seconds\n",
14868 thread_timer_remain_second(p->t_start));
14869 if (p->t_connect)
14870 vty_out(vty, "Next connect timer due in %ld seconds\n",
14871 thread_timer_remain_second(p->t_connect));
14872 if (p->t_routeadv)
14873 vty_out(vty,
14874 "MRAI (interval %u) timer expires in %ld seconds\n",
14875 p->v_routeadv,
14876 thread_timer_remain_second(p->t_routeadv));
14877 if (p->password)
14878 vty_out(vty, "Peer Authentication Enabled\n");
14879
14880 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14881 p->t_read ? "on" : "off",
14882 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14883 ? "on"
14884 : "off", p->fd);
14885 }
14886
14887 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14888 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14889 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14890
14891 if (!use_json)
14892 vty_out(vty, "\n");
14893
14894 /* BFD information. */
14895 if (p->bfd_config)
14896 bgp_bfd_show_info(vty, p, json_neigh);
14897
14898 if (use_json) {
14899 if (p->conf_if) /* Configured interface name. */
14900 json_object_object_add(json, p->conf_if, json_neigh);
14901 else /* Configured IP address. */
14902 json_object_object_add(json, p->host, json_neigh);
14903 }
14904 }
14905
14906 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14907 enum show_type type,
14908 union sockunion *su,
14909 const char *conf_if, afi_t afi,
14910 json_object *json)
14911 {
14912 struct listnode *node, *nnode;
14913 struct peer *peer;
14914 bool found = false;
14915 safi_t safi = SAFI_UNICAST;
14916 json_object *json_neighbor = NULL;
14917
14918 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14919
14920 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14921 continue;
14922
14923 if ((peer->afc[afi][safi]) == 0)
14924 continue;
14925
14926 if (json)
14927 json_neighbor = json_object_new_object();
14928
14929 if (type == show_all) {
14930 bgp_show_peer_gr_status(vty, peer, json_neighbor);
14931
14932 if (json)
14933 json_object_object_add(json, peer->host,
14934 json_neighbor);
14935
14936 } else if (type == show_peer) {
14937 if (conf_if) {
14938 if ((peer->conf_if
14939 && !strcmp(peer->conf_if, conf_if))
14940 || (peer->hostname
14941 && !strcmp(peer->hostname, conf_if))) {
14942 found = true;
14943 bgp_show_peer_gr_status(vty, peer,
14944 json_neighbor);
14945 }
14946 } else {
14947 if (sockunion_same(&peer->su, su)) {
14948 found = true;
14949 bgp_show_peer_gr_status(vty, peer,
14950 json_neighbor);
14951 }
14952 }
14953 if (json) {
14954 if (found)
14955 json_object_object_add(json, peer->host,
14956 json_neighbor);
14957 else
14958 json_object_free(json_neighbor);
14959 }
14960 }
14961
14962 if (found)
14963 break;
14964 }
14965
14966 if (type == show_peer && !found) {
14967 if (json)
14968 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14969 else
14970 vty_out(vty, "%% No such neighbor\n");
14971 }
14972
14973 if (!json)
14974 vty_out(vty, "\n");
14975
14976 return CMD_SUCCESS;
14977 }
14978
14979 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14980 enum show_type type, union sockunion *su,
14981 const char *conf_if, bool use_json,
14982 json_object *json)
14983 {
14984 struct listnode *node, *nnode;
14985 struct peer *peer;
14986 int find = 0;
14987 bool nbr_output = false;
14988 afi_t afi = AFI_MAX;
14989 safi_t safi = SAFI_MAX;
14990
14991 if (type == show_ipv4_peer || type == show_ipv4_all) {
14992 afi = AFI_IP;
14993 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14994 afi = AFI_IP6;
14995 }
14996
14997 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14998 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14999 continue;
15000
15001 switch (type) {
15002 case show_all:
15003 bgp_show_peer(vty, peer, use_json, json);
15004 nbr_output = true;
15005 break;
15006 case show_peer:
15007 if (conf_if) {
15008 if ((peer->conf_if
15009 && !strcmp(peer->conf_if, conf_if))
15010 || (peer->hostname
15011 && !strcmp(peer->hostname, conf_if))) {
15012 find = 1;
15013 bgp_show_peer(vty, peer, use_json,
15014 json);
15015 }
15016 } else {
15017 if (sockunion_same(&peer->su, su)) {
15018 find = 1;
15019 bgp_show_peer(vty, peer, use_json,
15020 json);
15021 }
15022 }
15023 break;
15024 case show_ipv4_peer:
15025 case show_ipv6_peer:
15026 FOREACH_SAFI (safi) {
15027 if (peer->afc[afi][safi]) {
15028 if (conf_if) {
15029 if ((peer->conf_if
15030 && !strcmp(peer->conf_if, conf_if))
15031 || (peer->hostname
15032 && !strcmp(peer->hostname, conf_if))) {
15033 find = 1;
15034 bgp_show_peer(vty, peer, use_json,
15035 json);
15036 break;
15037 }
15038 } else {
15039 if (sockunion_same(&peer->su, su)) {
15040 find = 1;
15041 bgp_show_peer(vty, peer, use_json,
15042 json);
15043 break;
15044 }
15045 }
15046 }
15047 }
15048 break;
15049 case show_ipv4_all:
15050 case show_ipv6_all:
15051 FOREACH_SAFI (safi) {
15052 if (peer->afc[afi][safi]) {
15053 bgp_show_peer(vty, peer, use_json, json);
15054 nbr_output = true;
15055 break;
15056 }
15057 }
15058 break;
15059 }
15060 }
15061
15062 if ((type == show_peer || type == show_ipv4_peer ||
15063 type == show_ipv6_peer) && !find) {
15064 if (use_json)
15065 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15066 else
15067 vty_out(vty, "%% No such neighbor in this view/vrf\n");
15068 }
15069
15070 if (type != show_peer && type != show_ipv4_peer &&
15071 type != show_ipv6_peer && !nbr_output && !use_json)
15072 vty_out(vty, "%% No BGP neighbors found\n");
15073
15074 if (use_json) {
15075 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15076 json, JSON_C_TO_STRING_PRETTY));
15077 } else {
15078 vty_out(vty, "\n");
15079 }
15080
15081 return CMD_SUCCESS;
15082 }
15083
15084 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15085 enum show_type type,
15086 const char *ip_str,
15087 afi_t afi, json_object *json)
15088 {
15089
15090 int ret;
15091 struct bgp *bgp;
15092 union sockunion su;
15093
15094 bgp = bgp_get_default();
15095
15096 if (!bgp)
15097 return;
15098
15099 if (!json)
15100 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
15101
15102 if (ip_str) {
15103 ret = str2sockunion(ip_str, &su);
15104 if (ret < 0)
15105 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15106 ip_str, afi, json);
15107 else
15108 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15109 NULL, afi, json);
15110 } else
15111 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15112 afi, json);
15113 }
15114
15115 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15116 enum show_type type,
15117 const char *ip_str,
15118 bool use_json)
15119 {
15120 struct listnode *node, *nnode;
15121 struct bgp *bgp;
15122 union sockunion su;
15123 json_object *json = NULL;
15124 int ret, is_first = 1;
15125 bool nbr_output = false;
15126
15127 if (use_json)
15128 vty_out(vty, "{\n");
15129
15130 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15131 nbr_output = true;
15132 if (use_json) {
15133 if (!(json = json_object_new_object())) {
15134 flog_err(
15135 EC_BGP_JSON_MEM_ERROR,
15136 "Unable to allocate memory for JSON object");
15137 vty_out(vty,
15138 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15139 return;
15140 }
15141
15142 json_object_int_add(json, "vrfId",
15143 (bgp->vrf_id == VRF_UNKNOWN)
15144 ? -1
15145 : (int64_t)bgp->vrf_id);
15146 json_object_string_add(
15147 json, "vrfName",
15148 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15149 ? VRF_DEFAULT_NAME
15150 : bgp->name);
15151
15152 if (!is_first)
15153 vty_out(vty, ",\n");
15154 else
15155 is_first = 0;
15156
15157 vty_out(vty, "\"%s\":",
15158 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15159 ? VRF_DEFAULT_NAME
15160 : bgp->name);
15161 } else {
15162 vty_out(vty, "\nInstance %s:\n",
15163 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15164 ? VRF_DEFAULT_NAME
15165 : bgp->name);
15166 }
15167
15168 if (type == show_peer || type == show_ipv4_peer ||
15169 type == show_ipv6_peer) {
15170 ret = str2sockunion(ip_str, &su);
15171 if (ret < 0)
15172 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15173 use_json, json);
15174 else
15175 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15176 use_json, json);
15177 } else {
15178 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15179 use_json, json);
15180 }
15181 json_object_free(json);
15182 json = NULL;
15183 }
15184
15185 if (use_json)
15186 vty_out(vty, "}\n");
15187 else if (!nbr_output)
15188 vty_out(vty, "%% BGP instance not found\n");
15189 }
15190
15191 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15192 enum show_type type, const char *ip_str,
15193 bool use_json)
15194 {
15195 int ret;
15196 struct bgp *bgp;
15197 union sockunion su;
15198 json_object *json = NULL;
15199
15200 if (name) {
15201 if (strmatch(name, "all")) {
15202 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15203 use_json);
15204 return CMD_SUCCESS;
15205 } else {
15206 bgp = bgp_lookup_by_name(name);
15207 if (!bgp) {
15208 if (use_json) {
15209 json = json_object_new_object();
15210 vty_json(vty, json);
15211 } else
15212 vty_out(vty,
15213 "%% BGP instance not found\n");
15214
15215 return CMD_WARNING;
15216 }
15217 }
15218 } else {
15219 bgp = bgp_get_default();
15220 }
15221
15222 if (bgp) {
15223 json = json_object_new_object();
15224 if (ip_str) {
15225 ret = str2sockunion(ip_str, &su);
15226 if (ret < 0)
15227 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15228 use_json, json);
15229 else
15230 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15231 use_json, json);
15232 } else {
15233 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15234 json);
15235 }
15236 json_object_free(json);
15237 } else {
15238 if (use_json)
15239 vty_out(vty, "{}\n");
15240 else
15241 vty_out(vty, "%% BGP instance not found\n");
15242 }
15243
15244 return CMD_SUCCESS;
15245 }
15246
15247
15248
15249 /* "show [ip] bgp neighbors graceful-restart" commands. */
15250 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15251 show_ip_bgp_neighbors_graceful_restart_cmd,
15252 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15253 SHOW_STR
15254 BGP_STR
15255 IP_STR
15256 IPV6_STR
15257 NEIGHBOR_STR
15258 "Neighbor to display information about\n"
15259 "Neighbor to display information about\n"
15260 "Neighbor on BGP configured interface\n"
15261 GR_SHOW
15262 JSON_STR)
15263 {
15264 char *sh_arg = NULL;
15265 enum show_type sh_type;
15266 int idx = 0;
15267 afi_t afi = AFI_MAX;
15268 bool uj = use_json(argc, argv);
15269
15270 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15271 afi = AFI_MAX;
15272
15273 idx++;
15274
15275 if (argv_find(argv, argc, "A.B.C.D", &idx)
15276 || argv_find(argv, argc, "X:X::X:X", &idx)
15277 || argv_find(argv, argc, "WORD", &idx)) {
15278 sh_type = show_peer;
15279 sh_arg = argv[idx]->arg;
15280 } else
15281 sh_type = show_all;
15282
15283 if (!argv_find(argv, argc, "graceful-restart", &idx))
15284 return CMD_SUCCESS;
15285
15286
15287 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15288 afi, uj);
15289 }
15290
15291 /* "show [ip] bgp neighbors" commands. */
15292 DEFUN (show_ip_bgp_neighbors,
15293 show_ip_bgp_neighbors_cmd,
15294 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15295 SHOW_STR
15296 IP_STR
15297 BGP_STR
15298 BGP_INSTANCE_HELP_STR
15299 BGP_AF_STR
15300 BGP_AF_STR
15301 "Detailed information on TCP and BGP neighbor connections\n"
15302 "Neighbor to display information about\n"
15303 "Neighbor to display information about\n"
15304 "Neighbor on BGP configured interface\n"
15305 JSON_STR)
15306 {
15307 char *vrf = NULL;
15308 char *sh_arg = NULL;
15309 enum show_type sh_type;
15310 afi_t afi = AFI_MAX;
15311
15312 bool uj = use_json(argc, argv);
15313
15314 int idx = 0;
15315
15316 /* [<vrf> VIEWVRFNAME] */
15317 if (argv_find(argv, argc, "vrf", &idx)) {
15318 vrf = argv[idx + 1]->arg;
15319 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15320 vrf = NULL;
15321 } else if (argv_find(argv, argc, "view", &idx))
15322 /* [<view> VIEWVRFNAME] */
15323 vrf = argv[idx + 1]->arg;
15324
15325 idx++;
15326
15327 if (argv_find(argv, argc, "ipv4", &idx)) {
15328 sh_type = show_ipv4_all;
15329 afi = AFI_IP;
15330 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15331 sh_type = show_ipv6_all;
15332 afi = AFI_IP6;
15333 } else {
15334 sh_type = show_all;
15335 }
15336
15337 if (argv_find(argv, argc, "A.B.C.D", &idx)
15338 || argv_find(argv, argc, "X:X::X:X", &idx)
15339 || argv_find(argv, argc, "WORD", &idx)) {
15340 sh_type = show_peer;
15341 sh_arg = argv[idx]->arg;
15342 }
15343
15344 if (sh_type == show_peer && afi == AFI_IP) {
15345 sh_type = show_ipv4_peer;
15346 } else if (sh_type == show_peer && afi == AFI_IP6) {
15347 sh_type = show_ipv6_peer;
15348 }
15349
15350 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15351 }
15352
15353 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15354 paths' and `show ip mbgp paths'. Those functions results are the
15355 same.*/
15356 DEFUN (show_ip_bgp_paths,
15357 show_ip_bgp_paths_cmd,
15358 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15359 SHOW_STR
15360 IP_STR
15361 BGP_STR
15362 BGP_SAFI_HELP_STR
15363 "Path information\n")
15364 {
15365 vty_out(vty, "Address Refcnt Path\n");
15366 aspath_print_all_vty(vty);
15367 return CMD_SUCCESS;
15368 }
15369
15370 #include "hash.h"
15371
15372 static void community_show_all_iterator(struct hash_bucket *bucket,
15373 struct vty *vty)
15374 {
15375 struct community *com;
15376
15377 com = (struct community *)bucket->data;
15378 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15379 community_str(com, false, false));
15380 }
15381
15382 /* Show BGP's community internal data. */
15383 DEFUN (show_ip_bgp_community_info,
15384 show_ip_bgp_community_info_cmd,
15385 "show [ip] bgp community-info",
15386 SHOW_STR
15387 IP_STR
15388 BGP_STR
15389 "List all bgp community information\n")
15390 {
15391 vty_out(vty, "Address Refcnt Community\n");
15392
15393 hash_iterate(community_hash(),
15394 (void (*)(struct hash_bucket *,
15395 void *))community_show_all_iterator,
15396 vty);
15397
15398 return CMD_SUCCESS;
15399 }
15400
15401 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15402 struct vty *vty)
15403 {
15404 struct lcommunity *lcom;
15405
15406 lcom = (struct lcommunity *)bucket->data;
15407 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15408 lcommunity_str(lcom, false, false));
15409 }
15410
15411 /* Show BGP's community internal data. */
15412 DEFUN (show_ip_bgp_lcommunity_info,
15413 show_ip_bgp_lcommunity_info_cmd,
15414 "show ip bgp large-community-info",
15415 SHOW_STR
15416 IP_STR
15417 BGP_STR
15418 "List all bgp large-community information\n")
15419 {
15420 vty_out(vty, "Address Refcnt Large-community\n");
15421
15422 hash_iterate(lcommunity_hash(),
15423 (void (*)(struct hash_bucket *,
15424 void *))lcommunity_show_all_iterator,
15425 vty);
15426
15427 return CMD_SUCCESS;
15428 }
15429 /* Graceful Restart */
15430
15431 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15432 struct bgp *bgp)
15433 {
15434
15435
15436 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15437
15438 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15439
15440 switch (bgp_global_gr_mode) {
15441
15442 case GLOBAL_HELPER:
15443 vty_out(vty, "Global BGP GR Mode : Helper\n");
15444 break;
15445
15446 case GLOBAL_GR:
15447 vty_out(vty, "Global BGP GR Mode : Restart\n");
15448 break;
15449
15450 case GLOBAL_DISABLE:
15451 vty_out(vty, "Global BGP GR Mode : Disable\n");
15452 break;
15453
15454 case GLOBAL_INVALID:
15455 vty_out(vty,
15456 "Global BGP GR Mode Invalid\n");
15457 break;
15458 }
15459 vty_out(vty, "\n");
15460 }
15461
15462 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15463 enum show_type type,
15464 const char *ip_str,
15465 afi_t afi, bool use_json)
15466 {
15467 json_object *json = NULL;
15468
15469 if (use_json)
15470 json = json_object_new_object();
15471
15472 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15473 afi = AFI_IP;
15474
15475 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15476
15477 bgp_show_neighbor_graceful_restart_vty(
15478 vty, type, ip_str, afi, json);
15479 afi++;
15480 }
15481 } else if (afi != AFI_MAX) {
15482 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15483 json);
15484 } else {
15485 if (json)
15486 json_object_free(json);
15487 return CMD_ERR_INCOMPLETE;
15488 }
15489
15490 if (json)
15491 vty_json(vty, json);
15492
15493 return CMD_SUCCESS;
15494 }
15495 /* Graceful Restart */
15496
15497 DEFUN (show_ip_bgp_attr_info,
15498 show_ip_bgp_attr_info_cmd,
15499 "show [ip] bgp attribute-info",
15500 SHOW_STR
15501 IP_STR
15502 BGP_STR
15503 "List all bgp attribute information\n")
15504 {
15505 attr_show_all(vty);
15506 return CMD_SUCCESS;
15507 }
15508
15509 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15510 afi_t afi, safi_t safi,
15511 bool use_json, json_object *json)
15512 {
15513 struct bgp *bgp;
15514 struct listnode *node;
15515 char *vname;
15516 char *ecom_str;
15517 enum vpn_policy_direction dir;
15518
15519 if (json) {
15520 json_object *json_import_vrfs = NULL;
15521 json_object *json_export_vrfs = NULL;
15522
15523 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15524
15525 if (!bgp) {
15526 vty_json(vty, json);
15527
15528 return CMD_WARNING;
15529 }
15530
15531 /* Provide context for the block */
15532 json_object_string_add(json, "vrf", name ? name : "default");
15533 json_object_string_add(json, "afiSafi",
15534 get_afi_safi_str(afi, safi, true));
15535
15536 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15537 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15538 json_object_string_add(json, "importFromVrfs", "none");
15539 json_object_string_add(json, "importRts", "none");
15540 } else {
15541 json_import_vrfs = json_object_new_array();
15542
15543 for (ALL_LIST_ELEMENTS_RO(
15544 bgp->vpn_policy[afi].import_vrf,
15545 node, vname))
15546 json_object_array_add(json_import_vrfs,
15547 json_object_new_string(vname));
15548
15549 json_object_object_add(json, "importFromVrfs",
15550 json_import_vrfs);
15551 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15552 if (bgp->vpn_policy[afi].rtlist[dir]) {
15553 ecom_str = ecommunity_ecom2str(
15554 bgp->vpn_policy[afi].rtlist[dir],
15555 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15556 json_object_string_add(json, "importRts",
15557 ecom_str);
15558 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15559 } else
15560 json_object_string_add(json, "importRts",
15561 "none");
15562 }
15563
15564 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15565 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15566 json_object_string_add(json, "exportToVrfs", "none");
15567 json_object_string_add(json, "routeDistinguisher",
15568 "none");
15569 json_object_string_add(json, "exportRts", "none");
15570 } else {
15571 json_export_vrfs = json_object_new_array();
15572
15573 for (ALL_LIST_ELEMENTS_RO(
15574 bgp->vpn_policy[afi].export_vrf,
15575 node, vname))
15576 json_object_array_add(json_export_vrfs,
15577 json_object_new_string(vname));
15578 json_object_object_add(json, "exportToVrfs",
15579 json_export_vrfs);
15580 json_object_string_addf(json, "routeDistinguisher",
15581 "%pRD",
15582 &bgp->vpn_policy[afi].tovpn_rd);
15583
15584 dir = BGP_VPN_POLICY_DIR_TOVPN;
15585 if (bgp->vpn_policy[afi].rtlist[dir]) {
15586 ecom_str = ecommunity_ecom2str(
15587 bgp->vpn_policy[afi].rtlist[dir],
15588 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15589 json_object_string_add(json, "exportRts",
15590 ecom_str);
15591 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15592 } else
15593 json_object_string_add(json, "exportRts",
15594 "none");
15595 }
15596
15597 if (use_json) {
15598 vty_json(vty, json);
15599 }
15600 } else {
15601 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15602
15603 if (!bgp) {
15604 vty_out(vty, "%% No such BGP instance exist\n");
15605 return CMD_WARNING;
15606 }
15607
15608 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15609 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15610 vty_out(vty,
15611 "This VRF is not importing %s routes from any other VRF\n",
15612 get_afi_safi_str(afi, safi, false));
15613 else {
15614 vty_out(vty,
15615 "This VRF is importing %s routes from the following VRFs:\n",
15616 get_afi_safi_str(afi, safi, false));
15617
15618 for (ALL_LIST_ELEMENTS_RO(
15619 bgp->vpn_policy[afi].import_vrf,
15620 node, vname))
15621 vty_out(vty, " %s\n", vname);
15622
15623 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15624 ecom_str = NULL;
15625 if (bgp->vpn_policy[afi].rtlist[dir]) {
15626 ecom_str = ecommunity_ecom2str(
15627 bgp->vpn_policy[afi].rtlist[dir],
15628 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15629 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15630
15631 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15632 } else
15633 vty_out(vty, "Import RT(s):\n");
15634 }
15635
15636 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15637 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15638 vty_out(vty,
15639 "This VRF is not exporting %s routes to any other VRF\n",
15640 get_afi_safi_str(afi, safi, false));
15641 else {
15642 vty_out(vty,
15643 "This VRF is exporting %s routes to the following VRFs:\n",
15644 get_afi_safi_str(afi, safi, false));
15645
15646 for (ALL_LIST_ELEMENTS_RO(
15647 bgp->vpn_policy[afi].export_vrf,
15648 node, vname))
15649 vty_out(vty, " %s\n", vname);
15650
15651 vty_out(vty, "RD: %pRD\n",
15652 &bgp->vpn_policy[afi].tovpn_rd);
15653
15654 dir = BGP_VPN_POLICY_DIR_TOVPN;
15655 if (bgp->vpn_policy[afi].rtlist[dir]) {
15656 ecom_str = ecommunity_ecom2str(
15657 bgp->vpn_policy[afi].rtlist[dir],
15658 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15659 vty_out(vty, "Export RT: %s\n", ecom_str);
15660 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15661 } else
15662 vty_out(vty, "Import RT(s):\n");
15663 }
15664 }
15665
15666 return CMD_SUCCESS;
15667 }
15668
15669 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15670 safi_t safi, bool use_json)
15671 {
15672 struct listnode *node, *nnode;
15673 struct bgp *bgp;
15674 char *vrf_name = NULL;
15675 json_object *json = NULL;
15676 json_object *json_vrf = NULL;
15677 json_object *json_vrfs = NULL;
15678
15679 if (use_json) {
15680 json = json_object_new_object();
15681 json_vrfs = json_object_new_object();
15682 }
15683
15684 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15685
15686 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15687 vrf_name = bgp->name;
15688
15689 if (use_json) {
15690 json_vrf = json_object_new_object();
15691 } else {
15692 vty_out(vty, "\nInstance %s:\n",
15693 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15694 ? VRF_DEFAULT_NAME : bgp->name);
15695 }
15696 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15697 if (use_json) {
15698 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15699 json_object_object_add(json_vrfs,
15700 VRF_DEFAULT_NAME, json_vrf);
15701 else
15702 json_object_object_add(json_vrfs, vrf_name,
15703 json_vrf);
15704 }
15705 }
15706
15707 if (use_json) {
15708 json_object_object_add(json, "vrfs", json_vrfs);
15709 vty_json(vty, json);
15710 }
15711
15712 return CMD_SUCCESS;
15713 }
15714
15715 /* "show [ip] bgp route-leak" command. */
15716 DEFUN (show_ip_bgp_route_leak,
15717 show_ip_bgp_route_leak_cmd,
15718 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15719 SHOW_STR
15720 IP_STR
15721 BGP_STR
15722 BGP_INSTANCE_HELP_STR
15723 BGP_AFI_HELP_STR
15724 BGP_SAFI_HELP_STR
15725 "Route leaking information\n"
15726 JSON_STR)
15727 {
15728 char *vrf = NULL;
15729 afi_t afi = AFI_MAX;
15730 safi_t safi = SAFI_MAX;
15731
15732 bool uj = use_json(argc, argv);
15733 int idx = 0;
15734 json_object *json = NULL;
15735
15736 /* show [ip] bgp */
15737 if (argv_find(argv, argc, "ip", &idx)) {
15738 afi = AFI_IP;
15739 safi = SAFI_UNICAST;
15740 }
15741 /* [vrf VIEWVRFNAME] */
15742 if (argv_find(argv, argc, "view", &idx)) {
15743 vty_out(vty,
15744 "%% This command is not applicable to BGP views\n");
15745 return CMD_WARNING;
15746 }
15747
15748 if (argv_find(argv, argc, "vrf", &idx)) {
15749 vrf = argv[idx + 1]->arg;
15750 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15751 vrf = NULL;
15752 }
15753 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15754 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15755 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15756
15757 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15758 vty_out(vty,
15759 "%% This command is applicable only for unicast ipv4|ipv6\n");
15760 return CMD_WARNING;
15761 }
15762
15763 if (vrf && strmatch(vrf, "all"))
15764 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15765
15766 if (uj)
15767 json = json_object_new_object();
15768
15769 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15770 }
15771
15772 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15773 safi_t safi, bool uj)
15774 {
15775 struct listnode *node, *nnode;
15776 struct bgp *bgp;
15777
15778 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15779 if (!uj)
15780 vty_out(vty, "\nInstance %s:\n",
15781 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15782 ? VRF_DEFAULT_NAME
15783 : bgp->name);
15784
15785 update_group_show(bgp, afi, safi, vty, 0, uj);
15786 }
15787 }
15788
15789 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15790 int safi, uint64_t subgrp_id, bool uj)
15791 {
15792 struct bgp *bgp;
15793
15794 if (name) {
15795 if (strmatch(name, "all")) {
15796 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15797 return CMD_SUCCESS;
15798 } else {
15799 bgp = bgp_lookup_by_name(name);
15800 }
15801 } else {
15802 bgp = bgp_get_default();
15803 }
15804
15805 if (bgp)
15806 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15807 return CMD_SUCCESS;
15808 }
15809
15810 DEFUN (show_ip_bgp_updgrps,
15811 show_ip_bgp_updgrps_cmd,
15812 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15813 SHOW_STR
15814 IP_STR
15815 BGP_STR
15816 BGP_INSTANCE_HELP_STR
15817 BGP_AFI_HELP_STR
15818 BGP_SAFI_WITH_LABEL_HELP_STR
15819 "Detailed info about dynamic update groups\n"
15820 "Specific subgroup to display detailed info for\n"
15821 JSON_STR)
15822 {
15823 char *vrf = NULL;
15824 afi_t afi = AFI_IP6;
15825 safi_t safi = SAFI_UNICAST;
15826 uint64_t subgrp_id = 0;
15827
15828 int idx = 0;
15829
15830 bool uj = use_json(argc, argv);
15831
15832 /* show [ip] bgp */
15833 if (argv_find(argv, argc, "ip", &idx))
15834 afi = AFI_IP;
15835 /* [<vrf> VIEWVRFNAME] */
15836 if (argv_find(argv, argc, "vrf", &idx)) {
15837 vrf = argv[idx + 1]->arg;
15838 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15839 vrf = NULL;
15840 } else if (argv_find(argv, argc, "view", &idx))
15841 /* [<view> VIEWVRFNAME] */
15842 vrf = argv[idx + 1]->arg;
15843 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15844 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15845 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15846 }
15847
15848 /* get subgroup id, if provided */
15849 idx = argc - 1;
15850 if (argv[idx]->type == VARIABLE_TKN)
15851 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15852
15853 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15854 }
15855
15856 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15857 show_bgp_instance_all_ipv6_updgrps_cmd,
15858 "show [ip] bgp <view|vrf> all update-groups [json]",
15859 SHOW_STR
15860 IP_STR
15861 BGP_STR
15862 BGP_INSTANCE_ALL_HELP_STR
15863 "Detailed info about dynamic update groups\n"
15864 JSON_STR)
15865 {
15866 bool uj = use_json(argc, argv);
15867
15868 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15869 return CMD_SUCCESS;
15870 }
15871
15872 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15873 show_bgp_l2vpn_evpn_updgrps_cmd,
15874 "show [ip] bgp l2vpn evpn update-groups",
15875 SHOW_STR
15876 IP_STR
15877 BGP_STR
15878 "l2vpn address family\n"
15879 "evpn sub-address family\n"
15880 "Detailed info about dynamic update groups\n")
15881 {
15882 char *vrf = NULL;
15883 uint64_t subgrp_id = 0;
15884
15885 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15886 return CMD_SUCCESS;
15887 }
15888
15889 DEFUN (show_bgp_updgrps_stats,
15890 show_bgp_updgrps_stats_cmd,
15891 "show [ip] bgp update-groups statistics",
15892 SHOW_STR
15893 IP_STR
15894 BGP_STR
15895 "Detailed info about dynamic update groups\n"
15896 "Statistics\n")
15897 {
15898 struct bgp *bgp;
15899
15900 bgp = bgp_get_default();
15901 if (bgp)
15902 update_group_show_stats(bgp, vty);
15903
15904 return CMD_SUCCESS;
15905 }
15906
15907 DEFUN (show_bgp_instance_updgrps_stats,
15908 show_bgp_instance_updgrps_stats_cmd,
15909 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15910 SHOW_STR
15911 IP_STR
15912 BGP_STR
15913 BGP_INSTANCE_HELP_STR
15914 "Detailed info about dynamic update groups\n"
15915 "Statistics\n")
15916 {
15917 int idx_word = 3;
15918 struct bgp *bgp;
15919
15920 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15921 if (bgp)
15922 update_group_show_stats(bgp, vty);
15923
15924 return CMD_SUCCESS;
15925 }
15926
15927 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15928 afi_t afi, safi_t safi,
15929 const char *what, uint64_t subgrp_id)
15930 {
15931 struct bgp *bgp;
15932
15933 if (name)
15934 bgp = bgp_lookup_by_name(name);
15935 else
15936 bgp = bgp_get_default();
15937
15938 if (bgp) {
15939 if (!strcmp(what, "advertise-queue"))
15940 update_group_show_adj_queue(bgp, afi, safi, vty,
15941 subgrp_id);
15942 else if (!strcmp(what, "advertised-routes"))
15943 update_group_show_advertised(bgp, afi, safi, vty,
15944 subgrp_id);
15945 else if (!strcmp(what, "packet-queue"))
15946 update_group_show_packet_queue(bgp, afi, safi, vty,
15947 subgrp_id);
15948 }
15949 }
15950
15951 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15952 show_ip_bgp_instance_updgrps_adj_s_cmd,
15953 "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",
15954 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15955 BGP_SAFI_HELP_STR
15956 "Detailed info about dynamic update groups\n"
15957 "Specific subgroup to display info for\n"
15958 "Advertisement queue\n"
15959 "Announced routes\n"
15960 "Packet queue\n")
15961 {
15962 uint64_t subgrp_id = 0;
15963 afi_t afiz;
15964 safi_t safiz;
15965 if (sgid)
15966 subgrp_id = strtoull(sgid, NULL, 10);
15967
15968 if (!ip && !afi)
15969 afiz = AFI_IP6;
15970 if (!ip && afi)
15971 afiz = bgp_vty_afi_from_str(afi);
15972 if (ip && !afi)
15973 afiz = AFI_IP;
15974 if (ip && afi) {
15975 afiz = bgp_vty_afi_from_str(afi);
15976 if (afiz != AFI_IP)
15977 vty_out(vty,
15978 "%% Cannot specify both 'ip' and 'ipv6'\n");
15979 return CMD_WARNING;
15980 }
15981
15982 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15983
15984 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15985 return CMD_SUCCESS;
15986 }
15987
15988 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15989 json_object *json)
15990 {
15991 struct listnode *node, *nnode;
15992 struct prefix *range;
15993 struct peer *conf;
15994 struct peer *peer;
15995 afi_t afi;
15996 safi_t safi;
15997 const char *peer_status;
15998 int lr_count;
15999 int dynamic;
16000 bool af_cfgd;
16001 json_object *json_peer_group = NULL;
16002 json_object *json_peer_group_afc = NULL;
16003 json_object *json_peer_group_members = NULL;
16004 json_object *json_peer_group_dynamic = NULL;
16005 json_object *json_peer_group_dynamic_af = NULL;
16006 json_object *json_peer_group_ranges = NULL;
16007
16008 conf = group->conf;
16009
16010 if (json) {
16011 json_peer_group = json_object_new_object();
16012 json_peer_group_afc = json_object_new_array();
16013 }
16014
16015 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
16016 if (json)
16017 json_object_int_add(json_peer_group, "remoteAs",
16018 conf->as);
16019 else
16020 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
16021 group->name, conf->as);
16022 } else if (conf->as_type == AS_INTERNAL) {
16023 if (json)
16024 json_object_int_add(json_peer_group, "remoteAs",
16025 group->bgp->as);
16026 else
16027 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
16028 group->name, group->bgp->as);
16029 } else {
16030 if (!json)
16031 vty_out(vty, "\nBGP peer-group %s\n", group->name);
16032 }
16033
16034 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16035 if (json)
16036 json_object_string_add(json_peer_group, "type",
16037 "internal");
16038 else
16039 vty_out(vty, " Peer-group type is internal\n");
16040 } else {
16041 if (json)
16042 json_object_string_add(json_peer_group, "type",
16043 "external");
16044 else
16045 vty_out(vty, " Peer-group type is external\n");
16046 }
16047
16048 /* Display AFs configured. */
16049 if (!json)
16050 vty_out(vty, " Configured address-families:");
16051
16052 FOREACH_AFI_SAFI (afi, safi) {
16053 if (conf->afc[afi][safi]) {
16054 af_cfgd = true;
16055 if (json)
16056 json_object_array_add(
16057 json_peer_group_afc,
16058 json_object_new_string(get_afi_safi_str(
16059 afi, safi, false)));
16060 else
16061 vty_out(vty, " %s;",
16062 get_afi_safi_str(afi, safi, false));
16063 }
16064 }
16065
16066 if (json) {
16067 json_object_object_add(json_peer_group,
16068 "addressFamiliesConfigured",
16069 json_peer_group_afc);
16070 } else {
16071 if (!af_cfgd)
16072 vty_out(vty, " none\n");
16073 else
16074 vty_out(vty, "\n");
16075 }
16076
16077 /* Display listen ranges (for dynamic neighbors), if any */
16078 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
16079 lr_count = listcount(group->listen_range[afi]);
16080 if (lr_count) {
16081 if (json) {
16082 if (!json_peer_group_dynamic)
16083 json_peer_group_dynamic =
16084 json_object_new_object();
16085
16086 json_peer_group_dynamic_af =
16087 json_object_new_object();
16088 json_peer_group_ranges =
16089 json_object_new_array();
16090 json_object_int_add(json_peer_group_dynamic_af,
16091 "count", lr_count);
16092 } else {
16093 vty_out(vty, " %d %s listen range(s)\n",
16094 lr_count, afi2str(afi));
16095 }
16096
16097 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
16098 nnode, range)) {
16099 if (json) {
16100 char buf[BUFSIZ];
16101
16102 snprintfrr(buf, sizeof(buf), "%pFX",
16103 range);
16104
16105 json_object_array_add(
16106 json_peer_group_ranges,
16107 json_object_new_string(buf));
16108 } else {
16109 vty_out(vty, " %pFX\n", range);
16110 }
16111 }
16112
16113 if (json) {
16114 json_object_object_add(
16115 json_peer_group_dynamic_af, "ranges",
16116 json_peer_group_ranges);
16117
16118 json_object_object_add(
16119 json_peer_group_dynamic, afi2str(afi),
16120 json_peer_group_dynamic_af);
16121 }
16122 }
16123 }
16124
16125 if (json_peer_group_dynamic)
16126 json_object_object_add(json_peer_group, "dynamicRanges",
16127 json_peer_group_dynamic);
16128
16129 /* Display group members and their status */
16130 if (listcount(group->peer)) {
16131 if (json)
16132 json_peer_group_members = json_object_new_object();
16133 else
16134 vty_out(vty, " Peer-group members:\n");
16135 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16136 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16137 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16138 peer_status = "Idle (Admin)";
16139 else if (CHECK_FLAG(peer->sflags,
16140 PEER_STATUS_PREFIX_OVERFLOW))
16141 peer_status = "Idle (PfxCt)";
16142 else
16143 peer_status = lookup_msg(bgp_status_msg,
16144 peer->status, NULL);
16145
16146 dynamic = peer_dynamic_neighbor(peer);
16147
16148 if (json) {
16149 json_object *json_peer_group_member =
16150 json_object_new_object();
16151
16152 json_object_string_add(json_peer_group_member,
16153 "status", peer_status);
16154
16155 if (dynamic)
16156 json_object_boolean_true_add(
16157 json_peer_group_member,
16158 "dynamic");
16159
16160 json_object_object_add(json_peer_group_members,
16161 peer->host,
16162 json_peer_group_member);
16163 } else {
16164 vty_out(vty, " %s %s %s \n", peer->host,
16165 dynamic ? "(dynamic)" : "",
16166 peer_status);
16167 }
16168 }
16169 if (json)
16170 json_object_object_add(json_peer_group, "members",
16171 json_peer_group_members);
16172 }
16173
16174 if (json)
16175 json_object_object_add(json, group->name, json_peer_group);
16176
16177 return CMD_SUCCESS;
16178 }
16179
16180 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16181 const char *group_name, bool uj)
16182 {
16183 struct bgp *bgp;
16184 struct listnode *node, *nnode;
16185 struct peer_group *group;
16186 bool found = false;
16187 json_object *json = NULL;
16188
16189 if (uj)
16190 json = json_object_new_object();
16191
16192 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16193
16194 if (!bgp) {
16195 if (uj)
16196 vty_json(vty, json);
16197 else
16198 vty_out(vty, "%% BGP instance not found\n");
16199
16200 return CMD_WARNING;
16201 }
16202
16203 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16204 if (group_name) {
16205 if (strmatch(group->name, group_name)) {
16206 bgp_show_one_peer_group(vty, group, json);
16207 found = true;
16208 break;
16209 }
16210 } else {
16211 bgp_show_one_peer_group(vty, group, json);
16212 }
16213 }
16214
16215 if (group_name && !found && !uj)
16216 vty_out(vty, "%% No such peer-group\n");
16217
16218 if (uj)
16219 vty_json(vty, json);
16220
16221 return CMD_SUCCESS;
16222 }
16223
16224 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16225 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16226 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16227 "Detailed information on BGP peer groups\n"
16228 "Peer group name\n" JSON_STR)
16229 {
16230 char *vrf, *pg;
16231 int idx = 0;
16232 bool uj = use_json(argc, argv);
16233
16234 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16235 : NULL;
16236 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16237
16238 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16239 }
16240
16241
16242 /* Redistribute VTY commands. */
16243
16244 DEFUN (bgp_redistribute_ipv4,
16245 bgp_redistribute_ipv4_cmd,
16246 "redistribute " FRR_IP_REDIST_STR_BGPD,
16247 "Redistribute information from another routing protocol\n"
16248 FRR_IP_REDIST_HELP_STR_BGPD)
16249 {
16250 VTY_DECLVAR_CONTEXT(bgp, bgp);
16251 int idx_protocol = 1;
16252 int type;
16253
16254 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16255 if (type < 0) {
16256 vty_out(vty, "%% Invalid route type\n");
16257 return CMD_WARNING_CONFIG_FAILED;
16258 }
16259
16260 bgp_redist_add(bgp, AFI_IP, type, 0);
16261 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16262 }
16263
16264 ALIAS_HIDDEN(
16265 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16266 "redistribute " FRR_IP_REDIST_STR_BGPD,
16267 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16268
16269 DEFUN (bgp_redistribute_ipv4_rmap,
16270 bgp_redistribute_ipv4_rmap_cmd,
16271 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16272 "Redistribute information from another routing protocol\n"
16273 FRR_IP_REDIST_HELP_STR_BGPD
16274 "Route map reference\n"
16275 "Pointer to route-map entries\n")
16276 {
16277 VTY_DECLVAR_CONTEXT(bgp, bgp);
16278 int idx_protocol = 1;
16279 int idx_word = 3;
16280 int type;
16281 struct bgp_redist *red;
16282 bool changed;
16283 struct route_map *route_map = route_map_lookup_warn_noexist(
16284 vty, argv[idx_word]->arg);
16285
16286 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16287 if (type < 0) {
16288 vty_out(vty, "%% Invalid route type\n");
16289 return CMD_WARNING_CONFIG_FAILED;
16290 }
16291
16292 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16293 changed =
16294 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16295 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16296 }
16297
16298 ALIAS_HIDDEN(
16299 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16300 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16301 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16302 "Route map reference\n"
16303 "Pointer to route-map entries\n")
16304
16305 DEFUN (bgp_redistribute_ipv4_metric,
16306 bgp_redistribute_ipv4_metric_cmd,
16307 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16308 "Redistribute information from another routing protocol\n"
16309 FRR_IP_REDIST_HELP_STR_BGPD
16310 "Metric for redistributed routes\n"
16311 "Default metric\n")
16312 {
16313 VTY_DECLVAR_CONTEXT(bgp, bgp);
16314 int idx_protocol = 1;
16315 int idx_number = 3;
16316 int type;
16317 uint32_t metric;
16318 struct bgp_redist *red;
16319 bool changed;
16320
16321 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16322 if (type < 0) {
16323 vty_out(vty, "%% Invalid route type\n");
16324 return CMD_WARNING_CONFIG_FAILED;
16325 }
16326 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16327
16328 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16329 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16330 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16331 }
16332
16333 ALIAS_HIDDEN(
16334 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16335 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16336 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16337 "Metric for redistributed routes\n"
16338 "Default metric\n")
16339
16340 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16341 bgp_redistribute_ipv4_rmap_metric_cmd,
16342 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16343 "Redistribute information from another routing protocol\n"
16344 FRR_IP_REDIST_HELP_STR_BGPD
16345 "Route map reference\n"
16346 "Pointer to route-map entries\n"
16347 "Metric for redistributed routes\n"
16348 "Default metric\n")
16349 {
16350 VTY_DECLVAR_CONTEXT(bgp, bgp);
16351 int idx_protocol = 1;
16352 int idx_word = 3;
16353 int idx_number = 5;
16354 int type;
16355 uint32_t metric;
16356 struct bgp_redist *red;
16357 bool changed;
16358 struct route_map *route_map =
16359 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16360
16361 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16362 if (type < 0) {
16363 vty_out(vty, "%% Invalid route type\n");
16364 return CMD_WARNING_CONFIG_FAILED;
16365 }
16366 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16367
16368 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16369 changed =
16370 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16371 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16372 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16373 }
16374
16375 ALIAS_HIDDEN(
16376 bgp_redistribute_ipv4_rmap_metric,
16377 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16378 "redistribute " FRR_IP_REDIST_STR_BGPD
16379 " route-map RMAP_NAME metric (0-4294967295)",
16380 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16381 "Route map reference\n"
16382 "Pointer to route-map entries\n"
16383 "Metric for redistributed routes\n"
16384 "Default metric\n")
16385
16386 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16387 bgp_redistribute_ipv4_metric_rmap_cmd,
16388 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16389 "Redistribute information from another routing protocol\n"
16390 FRR_IP_REDIST_HELP_STR_BGPD
16391 "Metric for redistributed routes\n"
16392 "Default metric\n"
16393 "Route map reference\n"
16394 "Pointer to route-map entries\n")
16395 {
16396 VTY_DECLVAR_CONTEXT(bgp, bgp);
16397 int idx_protocol = 1;
16398 int idx_number = 3;
16399 int idx_word = 5;
16400 int type;
16401 uint32_t metric;
16402 struct bgp_redist *red;
16403 bool changed;
16404 struct route_map *route_map =
16405 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16406
16407 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16408 if (type < 0) {
16409 vty_out(vty, "%% Invalid route type\n");
16410 return CMD_WARNING_CONFIG_FAILED;
16411 }
16412 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16413
16414 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16415 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16416 changed |=
16417 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16418 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16419 }
16420
16421 ALIAS_HIDDEN(
16422 bgp_redistribute_ipv4_metric_rmap,
16423 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16424 "redistribute " FRR_IP_REDIST_STR_BGPD
16425 " metric (0-4294967295) route-map RMAP_NAME",
16426 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16427 "Metric for redistributed routes\n"
16428 "Default metric\n"
16429 "Route map reference\n"
16430 "Pointer to route-map entries\n")
16431
16432 DEFUN (bgp_redistribute_ipv4_ospf,
16433 bgp_redistribute_ipv4_ospf_cmd,
16434 "redistribute <ospf|table> (1-65535)",
16435 "Redistribute information from another routing protocol\n"
16436 "Open Shortest Path First (OSPFv2)\n"
16437 "Non-main Kernel Routing Table\n"
16438 "Instance ID/Table ID\n")
16439 {
16440 VTY_DECLVAR_CONTEXT(bgp, bgp);
16441 int idx_ospf_table = 1;
16442 int idx_number = 2;
16443 unsigned short instance;
16444 unsigned short protocol;
16445
16446 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16447
16448 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16449 protocol = ZEBRA_ROUTE_OSPF;
16450 else
16451 protocol = ZEBRA_ROUTE_TABLE;
16452
16453 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16454 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16455 }
16456
16457 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16458 "redistribute <ospf|table> (1-65535)",
16459 "Redistribute information from another routing protocol\n"
16460 "Open Shortest Path First (OSPFv2)\n"
16461 "Non-main Kernel Routing Table\n"
16462 "Instance ID/Table ID\n")
16463
16464 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16465 bgp_redistribute_ipv4_ospf_rmap_cmd,
16466 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16467 "Redistribute information from another routing protocol\n"
16468 "Open Shortest Path First (OSPFv2)\n"
16469 "Non-main Kernel Routing Table\n"
16470 "Instance ID/Table ID\n"
16471 "Route map reference\n"
16472 "Pointer to route-map entries\n")
16473 {
16474 VTY_DECLVAR_CONTEXT(bgp, bgp);
16475 int idx_ospf_table = 1;
16476 int idx_number = 2;
16477 int idx_word = 4;
16478 struct bgp_redist *red;
16479 unsigned short instance;
16480 int protocol;
16481 bool changed;
16482 struct route_map *route_map =
16483 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16484
16485 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16486 protocol = ZEBRA_ROUTE_OSPF;
16487 else
16488 protocol = ZEBRA_ROUTE_TABLE;
16489
16490 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16491 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16492 changed =
16493 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16494 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16495 }
16496
16497 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16498 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16499 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16500 "Redistribute information from another routing protocol\n"
16501 "Open Shortest Path First (OSPFv2)\n"
16502 "Non-main Kernel Routing Table\n"
16503 "Instance ID/Table ID\n"
16504 "Route map reference\n"
16505 "Pointer to route-map entries\n")
16506
16507 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16508 bgp_redistribute_ipv4_ospf_metric_cmd,
16509 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16510 "Redistribute information from another routing protocol\n"
16511 "Open Shortest Path First (OSPFv2)\n"
16512 "Non-main Kernel Routing Table\n"
16513 "Instance ID/Table ID\n"
16514 "Metric for redistributed routes\n"
16515 "Default metric\n")
16516 {
16517 VTY_DECLVAR_CONTEXT(bgp, bgp);
16518 int idx_ospf_table = 1;
16519 int idx_number = 2;
16520 int idx_number_2 = 4;
16521 uint32_t metric;
16522 struct bgp_redist *red;
16523 unsigned short instance;
16524 int protocol;
16525 bool changed;
16526
16527 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16528 protocol = ZEBRA_ROUTE_OSPF;
16529 else
16530 protocol = ZEBRA_ROUTE_TABLE;
16531
16532 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16533 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16534
16535 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16536 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16537 metric);
16538 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16539 }
16540
16541 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16542 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16543 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16544 "Redistribute information from another routing protocol\n"
16545 "Open Shortest Path First (OSPFv2)\n"
16546 "Non-main Kernel Routing Table\n"
16547 "Instance ID/Table ID\n"
16548 "Metric for redistributed routes\n"
16549 "Default metric\n")
16550
16551 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16552 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16553 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16554 "Redistribute information from another routing protocol\n"
16555 "Open Shortest Path First (OSPFv2)\n"
16556 "Non-main Kernel Routing Table\n"
16557 "Instance ID/Table ID\n"
16558 "Route map reference\n"
16559 "Pointer to route-map entries\n"
16560 "Metric for redistributed routes\n"
16561 "Default metric\n")
16562 {
16563 VTY_DECLVAR_CONTEXT(bgp, bgp);
16564 int idx_ospf_table = 1;
16565 int idx_number = 2;
16566 int idx_word = 4;
16567 int idx_number_2 = 6;
16568 uint32_t metric;
16569 struct bgp_redist *red;
16570 unsigned short instance;
16571 int protocol;
16572 bool changed;
16573 struct route_map *route_map =
16574 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16575
16576 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16577 protocol = ZEBRA_ROUTE_OSPF;
16578 else
16579 protocol = ZEBRA_ROUTE_TABLE;
16580
16581 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16582 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16583
16584 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16585 changed =
16586 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16587 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16588 metric);
16589 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16590 }
16591
16592 ALIAS_HIDDEN(
16593 bgp_redistribute_ipv4_ospf_rmap_metric,
16594 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16595 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16596 "Redistribute information from another routing protocol\n"
16597 "Open Shortest Path First (OSPFv2)\n"
16598 "Non-main Kernel Routing Table\n"
16599 "Instance ID/Table ID\n"
16600 "Route map reference\n"
16601 "Pointer to route-map entries\n"
16602 "Metric for redistributed routes\n"
16603 "Default metric\n")
16604
16605 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16606 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16607 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16608 "Redistribute information from another routing protocol\n"
16609 "Open Shortest Path First (OSPFv2)\n"
16610 "Non-main Kernel Routing Table\n"
16611 "Instance ID/Table ID\n"
16612 "Metric for redistributed routes\n"
16613 "Default metric\n"
16614 "Route map reference\n"
16615 "Pointer to route-map entries\n")
16616 {
16617 VTY_DECLVAR_CONTEXT(bgp, bgp);
16618 int idx_ospf_table = 1;
16619 int idx_number = 2;
16620 int idx_number_2 = 4;
16621 int idx_word = 6;
16622 uint32_t metric;
16623 struct bgp_redist *red;
16624 unsigned short instance;
16625 int protocol;
16626 bool changed;
16627 struct route_map *route_map =
16628 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16629
16630 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16631 protocol = ZEBRA_ROUTE_OSPF;
16632 else
16633 protocol = ZEBRA_ROUTE_TABLE;
16634
16635 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16636 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16637
16638 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16639 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16640 metric);
16641 changed |=
16642 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16643 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16644 }
16645
16646 ALIAS_HIDDEN(
16647 bgp_redistribute_ipv4_ospf_metric_rmap,
16648 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16649 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16650 "Redistribute information from another routing protocol\n"
16651 "Open Shortest Path First (OSPFv2)\n"
16652 "Non-main Kernel Routing Table\n"
16653 "Instance ID/Table ID\n"
16654 "Metric for redistributed routes\n"
16655 "Default metric\n"
16656 "Route map reference\n"
16657 "Pointer to route-map entries\n")
16658
16659 DEFUN (no_bgp_redistribute_ipv4_ospf,
16660 no_bgp_redistribute_ipv4_ospf_cmd,
16661 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16662 NO_STR
16663 "Redistribute information from another routing protocol\n"
16664 "Open Shortest Path First (OSPFv2)\n"
16665 "Non-main Kernel Routing Table\n"
16666 "Instance ID/Table ID\n"
16667 "Metric for redistributed routes\n"
16668 "Default metric\n"
16669 "Route map reference\n"
16670 "Pointer to route-map entries\n")
16671 {
16672 VTY_DECLVAR_CONTEXT(bgp, bgp);
16673 int idx_ospf_table = 2;
16674 int idx_number = 3;
16675 unsigned short instance;
16676 int protocol;
16677
16678 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16679 protocol = ZEBRA_ROUTE_OSPF;
16680 else
16681 protocol = ZEBRA_ROUTE_TABLE;
16682
16683 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16684 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16685 }
16686
16687 ALIAS_HIDDEN(
16688 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16689 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16690 NO_STR
16691 "Redistribute information from another routing protocol\n"
16692 "Open Shortest Path First (OSPFv2)\n"
16693 "Non-main Kernel Routing Table\n"
16694 "Instance ID/Table ID\n"
16695 "Metric for redistributed routes\n"
16696 "Default metric\n"
16697 "Route map reference\n"
16698 "Pointer to route-map entries\n")
16699
16700 DEFUN (no_bgp_redistribute_ipv4,
16701 no_bgp_redistribute_ipv4_cmd,
16702 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16703 NO_STR
16704 "Redistribute information from another routing protocol\n"
16705 FRR_IP_REDIST_HELP_STR_BGPD
16706 "Metric for redistributed routes\n"
16707 "Default metric\n"
16708 "Route map reference\n"
16709 "Pointer to route-map entries\n")
16710 {
16711 VTY_DECLVAR_CONTEXT(bgp, bgp);
16712 int idx_protocol = 2;
16713 int type;
16714
16715 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16716 if (type < 0) {
16717 vty_out(vty, "%% Invalid route type\n");
16718 return CMD_WARNING_CONFIG_FAILED;
16719 }
16720 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16721 }
16722
16723 ALIAS_HIDDEN(
16724 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16725 "no redistribute " FRR_IP_REDIST_STR_BGPD
16726 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16727 NO_STR
16728 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16729 "Metric for redistributed routes\n"
16730 "Default metric\n"
16731 "Route map reference\n"
16732 "Pointer to route-map entries\n")
16733
16734 DEFUN (bgp_redistribute_ipv6,
16735 bgp_redistribute_ipv6_cmd,
16736 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16737 "Redistribute information from another routing protocol\n"
16738 FRR_IP6_REDIST_HELP_STR_BGPD)
16739 {
16740 VTY_DECLVAR_CONTEXT(bgp, bgp);
16741 int idx_protocol = 1;
16742 int type;
16743
16744 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16745 if (type < 0) {
16746 vty_out(vty, "%% Invalid route type\n");
16747 return CMD_WARNING_CONFIG_FAILED;
16748 }
16749
16750 bgp_redist_add(bgp, AFI_IP6, type, 0);
16751 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16752 }
16753
16754 DEFUN (bgp_redistribute_ipv6_rmap,
16755 bgp_redistribute_ipv6_rmap_cmd,
16756 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16757 "Redistribute information from another routing protocol\n"
16758 FRR_IP6_REDIST_HELP_STR_BGPD
16759 "Route map reference\n"
16760 "Pointer to route-map entries\n")
16761 {
16762 VTY_DECLVAR_CONTEXT(bgp, bgp);
16763 int idx_protocol = 1;
16764 int idx_word = 3;
16765 int type;
16766 struct bgp_redist *red;
16767 bool changed;
16768 struct route_map *route_map =
16769 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16770
16771 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16772 if (type < 0) {
16773 vty_out(vty, "%% Invalid route type\n");
16774 return CMD_WARNING_CONFIG_FAILED;
16775 }
16776
16777 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16778 changed =
16779 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16780 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16781 }
16782
16783 DEFUN (bgp_redistribute_ipv6_metric,
16784 bgp_redistribute_ipv6_metric_cmd,
16785 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16786 "Redistribute information from another routing protocol\n"
16787 FRR_IP6_REDIST_HELP_STR_BGPD
16788 "Metric for redistributed routes\n"
16789 "Default metric\n")
16790 {
16791 VTY_DECLVAR_CONTEXT(bgp, bgp);
16792 int idx_protocol = 1;
16793 int idx_number = 3;
16794 int type;
16795 uint32_t metric;
16796 struct bgp_redist *red;
16797 bool changed;
16798
16799 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16800 if (type < 0) {
16801 vty_out(vty, "%% Invalid route type\n");
16802 return CMD_WARNING_CONFIG_FAILED;
16803 }
16804 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16805
16806 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16807 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16808 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16809 }
16810
16811 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16812 bgp_redistribute_ipv6_rmap_metric_cmd,
16813 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16814 "Redistribute information from another routing protocol\n"
16815 FRR_IP6_REDIST_HELP_STR_BGPD
16816 "Route map reference\n"
16817 "Pointer to route-map entries\n"
16818 "Metric for redistributed routes\n"
16819 "Default metric\n")
16820 {
16821 VTY_DECLVAR_CONTEXT(bgp, bgp);
16822 int idx_protocol = 1;
16823 int idx_word = 3;
16824 int idx_number = 5;
16825 int type;
16826 uint32_t metric;
16827 struct bgp_redist *red;
16828 bool changed;
16829 struct route_map *route_map =
16830 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16831
16832 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16833 if (type < 0) {
16834 vty_out(vty, "%% Invalid route type\n");
16835 return CMD_WARNING_CONFIG_FAILED;
16836 }
16837 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16838
16839 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16840 changed =
16841 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16842 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16843 metric);
16844 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16845 }
16846
16847 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16848 bgp_redistribute_ipv6_metric_rmap_cmd,
16849 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16850 "Redistribute information from another routing protocol\n"
16851 FRR_IP6_REDIST_HELP_STR_BGPD
16852 "Metric for redistributed routes\n"
16853 "Default metric\n"
16854 "Route map reference\n"
16855 "Pointer to route-map entries\n")
16856 {
16857 VTY_DECLVAR_CONTEXT(bgp, bgp);
16858 int idx_protocol = 1;
16859 int idx_number = 3;
16860 int idx_word = 5;
16861 int type;
16862 uint32_t metric;
16863 struct bgp_redist *red;
16864 bool changed;
16865 struct route_map *route_map =
16866 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16867
16868 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16869 if (type < 0) {
16870 vty_out(vty, "%% Invalid route type\n");
16871 return CMD_WARNING_CONFIG_FAILED;
16872 }
16873 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16874
16875 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16876 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16877 metric);
16878 changed |=
16879 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16880 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16881 }
16882
16883 DEFUN (no_bgp_redistribute_ipv6,
16884 no_bgp_redistribute_ipv6_cmd,
16885 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16886 NO_STR
16887 "Redistribute information from another routing protocol\n"
16888 FRR_IP6_REDIST_HELP_STR_BGPD
16889 "Metric for redistributed routes\n"
16890 "Default metric\n"
16891 "Route map reference\n"
16892 "Pointer to route-map entries\n")
16893 {
16894 VTY_DECLVAR_CONTEXT(bgp, bgp);
16895 int idx_protocol = 2;
16896 int type;
16897
16898 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16899 if (type < 0) {
16900 vty_out(vty, "%% Invalid route type\n");
16901 return CMD_WARNING_CONFIG_FAILED;
16902 }
16903
16904 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16905 }
16906
16907 /* Neighbor update tcp-mss. */
16908 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16909 const char *tcp_mss_str)
16910 {
16911 struct peer *peer;
16912 uint32_t tcp_mss_val = 0;
16913
16914 peer = peer_and_group_lookup_vty(vty, peer_str);
16915 if (!peer)
16916 return CMD_WARNING_CONFIG_FAILED;
16917
16918 if (tcp_mss_str) {
16919 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16920 peer_tcp_mss_set(peer, tcp_mss_val);
16921 } else {
16922 peer_tcp_mss_unset(peer);
16923 }
16924
16925 return CMD_SUCCESS;
16926 }
16927
16928 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16929 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16931 "TCP max segment size\n"
16932 "TCP MSS value\n")
16933 {
16934 int peer_index = 1;
16935 int mss_index = 3;
16936
16937 vty_out(vty,
16938 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16939 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16940 argv[mss_index]->arg);
16941 }
16942
16943 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16944 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16946 "TCP max segment size\n"
16947 "TCP MSS value\n")
16948 {
16949 int peer_index = 2;
16950
16951 vty_out(vty,
16952 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16953 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16954 }
16955
16956 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16957 "[no$no] bgp retain route-target all",
16958 NO_STR BGP_STR
16959 "Retain BGP updates\n"
16960 "Retain BGP updates based on route-target values\n"
16961 "Retain all BGP updates\n")
16962 {
16963 bool check;
16964 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16965
16966 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16967 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16968 if (check != !no) {
16969 if (!no)
16970 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16971 [bgp_node_safi(vty)],
16972 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16973 else
16974 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16975 [bgp_node_safi(vty)],
16976 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16977 /* trigger a flush to re-sync with ADJ-RIB-in */
16978 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16979 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16980 }
16981 return CMD_SUCCESS;
16982 }
16983
16984 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16985 afi_t afi, safi_t safi)
16986 {
16987 int i;
16988
16989 /* Unicast redistribution only. */
16990 if (safi != SAFI_UNICAST)
16991 return;
16992
16993 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16994 /* Redistribute BGP does not make sense. */
16995 if (i != ZEBRA_ROUTE_BGP) {
16996 struct list *red_list;
16997 struct listnode *node;
16998 struct bgp_redist *red;
16999
17000 red_list = bgp->redist[afi][i];
17001 if (!red_list)
17002 continue;
17003
17004 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
17005 /* "redistribute" configuration. */
17006 vty_out(vty, " redistribute %s",
17007 zebra_route_string(i));
17008 if (red->instance)
17009 vty_out(vty, " %d", red->instance);
17010 if (red->redist_metric_flag)
17011 vty_out(vty, " metric %u",
17012 red->redist_metric);
17013 if (red->rmap.name)
17014 vty_out(vty, " route-map %s",
17015 red->rmap.name);
17016 vty_out(vty, "\n");
17017 }
17018 }
17019 }
17020 }
17021
17022 /* peer-group helpers for config-write */
17023
17024 bool peergroup_flag_check(struct peer *peer, uint64_t flag)
17025 {
17026 if (!peer_group_active(peer)) {
17027 if (CHECK_FLAG(peer->flags_invert, flag))
17028 return !CHECK_FLAG(peer->flags, flag);
17029 else
17030 return !!CHECK_FLAG(peer->flags, flag);
17031 }
17032
17033 return !!CHECK_FLAG(peer->flags_override, flag);
17034 }
17035
17036 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
17037 uint64_t flag)
17038 {
17039 if (!peer_group_active(peer)) {
17040 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
17041 return !peer_af_flag_check(peer, afi, safi, flag);
17042 else
17043 return !!peer_af_flag_check(peer, afi, safi, flag);
17044 }
17045
17046 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
17047 }
17048
17049 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
17050 uint8_t type, int direct)
17051 {
17052 struct bgp_filter *filter;
17053
17054 if (peer_group_active(peer))
17055 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
17056 type);
17057
17058 filter = &peer->filter[afi][safi];
17059 switch (type) {
17060 case PEER_FT_DISTRIBUTE_LIST:
17061 return !!(filter->dlist[direct].name);
17062 case PEER_FT_FILTER_LIST:
17063 return !!(filter->aslist[direct].name);
17064 case PEER_FT_PREFIX_LIST:
17065 return !!(filter->plist[direct].name);
17066 case PEER_FT_ROUTE_MAP:
17067 return !!(filter->map[direct].name);
17068 case PEER_FT_UNSUPPRESS_MAP:
17069 return !!(filter->usmap.name);
17070 case PEER_FT_ADVERTISE_MAP:
17071 return !!(filter->advmap.aname
17072 && ((filter->advmap.condition == direct)
17073 && filter->advmap.cname));
17074 default:
17075 return false;
17076 }
17077 }
17078
17079 /* Return true if the addpath type is set for peer and different from
17080 * peer-group.
17081 */
17082 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17083 safi_t safi)
17084 {
17085 enum bgp_addpath_strat type, g_type;
17086
17087 type = peer->addpath_type[afi][safi];
17088
17089 if (type != BGP_ADDPATH_NONE) {
17090 if (peer_group_active(peer)) {
17091 g_type = peer->group->conf->addpath_type[afi][safi];
17092
17093 if (type != g_type)
17094 return true;
17095 else
17096 return false;
17097 }
17098
17099 return true;
17100 }
17101
17102 return false;
17103 }
17104
17105 /* This is part of the address-family block (unicast only) */
17106 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17107 afi_t afi)
17108 {
17109 int indent = 2;
17110 uint32_t tovpn_sid_index = 0;
17111
17112 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17113 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17114 BGP_CONFIG_VRF_TO_VRF_IMPORT))
17115 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17116 bgp->vpn_policy[afi]
17117 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17118 else
17119 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17120 bgp->vpn_policy[afi]
17121 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17122 }
17123 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17124 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17125 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17126 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17127 return;
17128
17129 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17130 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17131
17132 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17133
17134 } else {
17135 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17136 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17137 bgp->vpn_policy[afi].tovpn_label);
17138 }
17139 }
17140
17141 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17142 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17143 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17144 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17145 } else if (tovpn_sid_index != 0) {
17146 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17147 tovpn_sid_index);
17148 }
17149
17150 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17151 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17152 &bgp->vpn_policy[afi].tovpn_rd);
17153
17154 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17155 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17156
17157 char buf[PREFIX_STRLEN];
17158 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17159 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17160 sizeof(buf))) {
17161
17162 vty_out(vty, "%*snexthop vpn export %s\n",
17163 indent, "", buf);
17164 }
17165 }
17166 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17167 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17168 && ecommunity_cmp(
17169 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17170 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17171
17172 char *b = ecommunity_ecom2str(
17173 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17174 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17175 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17176 XFREE(MTYPE_ECOMMUNITY_STR, b);
17177 } else {
17178 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17179 char *b = ecommunity_ecom2str(
17180 bgp->vpn_policy[afi]
17181 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17182 ECOMMUNITY_FORMAT_ROUTE_MAP,
17183 ECOMMUNITY_ROUTE_TARGET);
17184 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17185 XFREE(MTYPE_ECOMMUNITY_STR, b);
17186 }
17187 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17188 char *b = ecommunity_ecom2str(
17189 bgp->vpn_policy[afi]
17190 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17191 ECOMMUNITY_FORMAT_ROUTE_MAP,
17192 ECOMMUNITY_ROUTE_TARGET);
17193 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17194 XFREE(MTYPE_ECOMMUNITY_STR, b);
17195 }
17196 }
17197
17198 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17199 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17200 bgp->vpn_policy[afi]
17201 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17202
17203 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17204 char *b = ecommunity_ecom2str(
17205 bgp->vpn_policy[afi]
17206 .import_redirect_rtlist,
17207 ECOMMUNITY_FORMAT_ROUTE_MAP,
17208 ECOMMUNITY_ROUTE_TARGET);
17209
17210 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17211 != ECOMMUNITY_SIZE)
17212 vty_out(vty, "%*srt6 redirect import %s\n",
17213 indent, "", b);
17214 else
17215 vty_out(vty, "%*srt redirect import %s\n",
17216 indent, "", b);
17217 XFREE(MTYPE_ECOMMUNITY_STR, b);
17218 }
17219 }
17220
17221 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17222 afi_t afi, safi_t safi)
17223 {
17224 struct bgp_filter *filter;
17225 char *addr;
17226
17227 addr = peer->host;
17228 filter = &peer->filter[afi][safi];
17229
17230 /* distribute-list. */
17231 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17232 FILTER_IN))
17233 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17234 filter->dlist[FILTER_IN].name);
17235
17236 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17237 FILTER_OUT))
17238 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17239 filter->dlist[FILTER_OUT].name);
17240
17241 /* prefix-list. */
17242 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17243 FILTER_IN))
17244 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17245 filter->plist[FILTER_IN].name);
17246
17247 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17248 FILTER_OUT))
17249 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17250 filter->plist[FILTER_OUT].name);
17251
17252 /* route-map. */
17253 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17254 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17255 filter->map[RMAP_IN].name);
17256
17257 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17258 RMAP_OUT))
17259 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17260 filter->map[RMAP_OUT].name);
17261
17262 /* unsuppress-map */
17263 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17264 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17265 filter->usmap.name);
17266
17267 /* advertise-map : always applied in OUT direction*/
17268 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17269 CONDITION_NON_EXIST))
17270 vty_out(vty,
17271 " neighbor %s advertise-map %s non-exist-map %s\n",
17272 addr, filter->advmap.aname, filter->advmap.cname);
17273
17274 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17275 CONDITION_EXIST))
17276 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17277 addr, filter->advmap.aname, filter->advmap.cname);
17278
17279 /* filter-list. */
17280 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17281 FILTER_IN))
17282 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17283 filter->aslist[FILTER_IN].name);
17284
17285 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17286 FILTER_OUT))
17287 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17288 filter->aslist[FILTER_OUT].name);
17289 }
17290
17291 /* BGP peer configuration display function. */
17292 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17293 struct peer *peer)
17294 {
17295 struct peer *g_peer = NULL;
17296 char *addr;
17297 int if_pg_printed = false;
17298 int if_ras_printed = false;
17299
17300 /* Skip dynamic neighbors. */
17301 if (peer_dynamic_neighbor(peer))
17302 return;
17303
17304 if (peer->conf_if)
17305 addr = peer->conf_if;
17306 else
17307 addr = peer->host;
17308
17309 /************************************
17310 ****** Global to the neighbor ******
17311 ************************************/
17312 if (peer->conf_if) {
17313 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17314 vty_out(vty, " neighbor %s interface v6only", addr);
17315 else
17316 vty_out(vty, " neighbor %s interface", addr);
17317
17318 if (peer_group_active(peer)) {
17319 vty_out(vty, " peer-group %s", peer->group->name);
17320 if_pg_printed = true;
17321 } else if (peer->as_type == AS_SPECIFIED) {
17322 vty_out(vty, " remote-as %u", peer->as);
17323 if_ras_printed = true;
17324 } else if (peer->as_type == AS_INTERNAL) {
17325 vty_out(vty, " remote-as internal");
17326 if_ras_printed = true;
17327 } else if (peer->as_type == AS_EXTERNAL) {
17328 vty_out(vty, " remote-as external");
17329 if_ras_printed = true;
17330 }
17331
17332 vty_out(vty, "\n");
17333 }
17334
17335 /* remote-as and peer-group */
17336 /* peer is a member of a peer-group */
17337 if (peer_group_active(peer)) {
17338 g_peer = peer->group->conf;
17339
17340 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17341 if (peer->as_type == AS_SPECIFIED) {
17342 vty_out(vty, " neighbor %s remote-as %u\n",
17343 addr, peer->as);
17344 } else if (peer->as_type == AS_INTERNAL) {
17345 vty_out(vty,
17346 " neighbor %s remote-as internal\n",
17347 addr);
17348 } else if (peer->as_type == AS_EXTERNAL) {
17349 vty_out(vty,
17350 " neighbor %s remote-as external\n",
17351 addr);
17352 }
17353 }
17354
17355 /* For swpX peers we displayed the peer-group
17356 * via 'neighbor swpX interface peer-group PGNAME' */
17357 if (!if_pg_printed)
17358 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17359 peer->group->name);
17360 }
17361
17362 /* peer is NOT a member of a peer-group */
17363 else {
17364 /* peer is a peer-group, declare the peer-group */
17365 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17366 vty_out(vty, " neighbor %s peer-group\n", addr);
17367 }
17368
17369 if (!if_ras_printed) {
17370 if (peer->as_type == AS_SPECIFIED) {
17371 vty_out(vty, " neighbor %s remote-as %u\n",
17372 addr, peer->as);
17373 } else if (peer->as_type == AS_INTERNAL) {
17374 vty_out(vty,
17375 " neighbor %s remote-as internal\n",
17376 addr);
17377 } else if (peer->as_type == AS_EXTERNAL) {
17378 vty_out(vty,
17379 " neighbor %s remote-as external\n",
17380 addr);
17381 }
17382 }
17383 }
17384
17385 /* local-as */
17386 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17387 vty_out(vty, " neighbor %s local-as %u", addr,
17388 peer->change_local_as);
17389 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17390 vty_out(vty, " no-prepend");
17391 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17392 vty_out(vty, " replace-as");
17393 vty_out(vty, "\n");
17394 }
17395
17396 /* description */
17397 if (peer->desc) {
17398 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17399 }
17400
17401 /* shutdown */
17402 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17403 if (peer->tx_shutdown_message)
17404 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17405 peer->tx_shutdown_message);
17406 else
17407 vty_out(vty, " neighbor %s shutdown\n", addr);
17408 }
17409
17410 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17411 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17412 peer->rtt_expected, peer->rtt_keepalive_conf);
17413
17414 /* bfd */
17415 if (peer->bfd_config)
17416 bgp_bfd_peer_config_write(vty, peer, addr);
17417
17418 /* password */
17419 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17420 vty_out(vty, " neighbor %s password %s\n", addr,
17421 peer->password);
17422
17423 /* neighbor solo */
17424 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17425 if (!peer_group_active(peer)) {
17426 vty_out(vty, " neighbor %s solo\n", addr);
17427 }
17428 }
17429
17430 /* BGP port */
17431 if (peer->port != BGP_PORT_DEFAULT) {
17432 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17433 }
17434
17435 /* Local interface name */
17436 if (peer->ifname) {
17437 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17438 }
17439
17440 /* TCP max segment size */
17441 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17442 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17443
17444 /* passive */
17445 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17446 vty_out(vty, " neighbor %s passive\n", addr);
17447
17448 /* ebgp-multihop */
17449 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17450 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17451 && peer->ttl == MAXTTL)) {
17452 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17453 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17454 peer->ttl);
17455 }
17456 }
17457
17458 /* aigp */
17459 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17460 vty_out(vty, " neighbor %s aigp\n", addr);
17461
17462 /* graceful-shutdown */
17463 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17464 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17465
17466 /* role */
17467 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17468 peer->local_role != ROLE_UNDEFINED)
17469 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17470 bgp_get_name_by_role(peer->local_role),
17471 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17472 ? " strict-mode"
17473 : "");
17474
17475 /* ttl-security hops */
17476 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17477 if (!peer_group_active(peer)
17478 || g_peer->gtsm_hops != peer->gtsm_hops) {
17479 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17480 addr, peer->gtsm_hops);
17481 }
17482 }
17483
17484 /* disable-connected-check */
17485 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17486 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17487
17488 /* link-bw-encoding-ieee */
17489 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17490 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17491 addr);
17492
17493 /* extended-optional-parameters */
17494 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17495 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17496 addr);
17497
17498 /* enforce-first-as */
17499 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17500 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17501
17502 /* update-source */
17503 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17504 if (peer->update_source)
17505 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17506 peer->update_source);
17507 else if (peer->update_if)
17508 vty_out(vty, " neighbor %s update-source %s\n", addr,
17509 peer->update_if);
17510 }
17511
17512 /* advertisement-interval */
17513 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17514 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17515 peer->routeadv);
17516
17517 /* timers */
17518 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17519 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17520 peer->keepalive, peer->holdtime);
17521
17522 /* timers connect */
17523 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17524 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17525 peer->connect);
17526 /* need special-case handling for changed default values due to
17527 * config profile / version (because there is no "timers bgp connect"
17528 * command, we need to save this per-peer :/)
17529 */
17530 else if (!peer_group_active(peer) && !peer->connect &&
17531 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17532 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17533 peer->bgp->default_connect_retry);
17534
17535 /* timers delayopen */
17536 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17537 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17538 peer->delayopen);
17539 /* Save config even though flag is not set if default values have been
17540 * changed
17541 */
17542 else if (!peer_group_active(peer) && !peer->delayopen
17543 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17544 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17545 peer->bgp->default_delayopen);
17546
17547 /* capability dynamic */
17548 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17549 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17550
17551 /* capability extended-nexthop */
17552 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17553 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17554 !peer->conf_if)
17555 vty_out(vty,
17556 " no neighbor %s capability extended-nexthop\n",
17557 addr);
17558 else if (!peer->conf_if)
17559 vty_out(vty,
17560 " neighbor %s capability extended-nexthop\n",
17561 addr);
17562 }
17563
17564 /* capability software-version */
17565 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION))
17566 vty_out(vty, " neighbor %s capability software-version\n",
17567 addr);
17568
17569 /* dont-capability-negotiation */
17570 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17571 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17572
17573 /* override-capability */
17574 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17575 vty_out(vty, " neighbor %s override-capability\n", addr);
17576
17577 /* strict-capability-match */
17578 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17579 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17580
17581 /* Sender side AS path loop detection. */
17582 if (peer->as_path_loop_detection)
17583 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17584 addr);
17585
17586 /* path-attribute discard */
17587 char discard_attrs_str[BUFSIZ] = {0};
17588 bool discard_attrs = bgp_path_attribute_discard(
17589 peer, discard_attrs_str, sizeof(discard_attrs_str));
17590
17591 if (discard_attrs)
17592 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17593 discard_attrs_str);
17594
17595 /* path-attribute treat-as-withdraw */
17596 char withdraw_attrs_str[BUFSIZ] = {0};
17597 bool withdraw_attrs = bgp_path_attribute_treat_as_withdraw(
17598 peer, withdraw_attrs_str, sizeof(withdraw_attrs_str));
17599
17600 if (withdraw_attrs)
17601 vty_out(vty,
17602 " neighbor %s path-attribute treat-as-withdraw %s\n",
17603 addr, withdraw_attrs_str);
17604
17605 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17606 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17607
17608 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17609 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17610 vty_out(vty,
17611 " neighbor %s graceful-restart-helper\n", addr);
17612 } else if (CHECK_FLAG(
17613 peer->peer_gr_new_status_flag,
17614 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17615 vty_out(vty,
17616 " neighbor %s graceful-restart\n", addr);
17617 } else if (
17618 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17619 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17620 && !(CHECK_FLAG(
17621 peer->peer_gr_new_status_flag,
17622 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17623 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17624 addr);
17625 }
17626 }
17627 }
17628
17629 /* BGP peer configuration display function. */
17630 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17631 struct peer *peer, afi_t afi, safi_t safi)
17632 {
17633 struct peer *g_peer = NULL;
17634 char *addr;
17635 bool flag_scomm, flag_secomm, flag_slcomm;
17636
17637 /* Skip dynamic neighbors. */
17638 if (peer_dynamic_neighbor(peer))
17639 return;
17640
17641 if (peer->conf_if)
17642 addr = peer->conf_if;
17643 else
17644 addr = peer->host;
17645
17646 /************************************
17647 ****** Per AF to the neighbor ******
17648 ************************************/
17649 if (peer_group_active(peer)) {
17650 g_peer = peer->group->conf;
17651
17652 /* If the peer-group is active but peer is not, print a 'no
17653 * activate' */
17654 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17655 vty_out(vty, " no neighbor %s activate\n", addr);
17656 }
17657
17658 /* If the peer-group is not active but peer is, print an
17659 'activate' */
17660 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17661 vty_out(vty, " neighbor %s activate\n", addr);
17662 }
17663 } else {
17664 if (peer->afc[afi][safi]) {
17665 if (safi == SAFI_ENCAP)
17666 vty_out(vty, " neighbor %s activate\n", addr);
17667 else if (!bgp->default_af[afi][safi])
17668 vty_out(vty, " neighbor %s activate\n", addr);
17669 } else {
17670 if (bgp->default_af[afi][safi])
17671 vty_out(vty, " no neighbor %s activate\n",
17672 addr);
17673 }
17674 }
17675
17676 /* addpath TX knobs */
17677 if (peergroup_af_addpath_check(peer, afi, safi)) {
17678 switch (peer->addpath_type[afi][safi]) {
17679 case BGP_ADDPATH_ALL:
17680 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17681 addr);
17682 break;
17683 case BGP_ADDPATH_BEST_PER_AS:
17684 vty_out(vty,
17685 " neighbor %s addpath-tx-bestpath-per-AS\n",
17686 addr);
17687 break;
17688 case BGP_ADDPATH_MAX:
17689 case BGP_ADDPATH_NONE:
17690 break;
17691 }
17692 }
17693
17694 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17695 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17696
17697 /* ORF capability. */
17698 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17699 || peergroup_af_flag_check(peer, afi, safi,
17700 PEER_FLAG_ORF_PREFIX_RM)) {
17701 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17702
17703 if (peergroup_af_flag_check(peer, afi, safi,
17704 PEER_FLAG_ORF_PREFIX_SM)
17705 && peergroup_af_flag_check(peer, afi, safi,
17706 PEER_FLAG_ORF_PREFIX_RM))
17707 vty_out(vty, " both");
17708 else if (peergroup_af_flag_check(peer, afi, safi,
17709 PEER_FLAG_ORF_PREFIX_SM))
17710 vty_out(vty, " send");
17711 else
17712 vty_out(vty, " receive");
17713 vty_out(vty, "\n");
17714 }
17715
17716 /* Route reflector client. */
17717 if (peergroup_af_flag_check(peer, afi, safi,
17718 PEER_FLAG_REFLECTOR_CLIENT)) {
17719 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17720 }
17721
17722 /* next-hop-self force */
17723 if (peergroup_af_flag_check(peer, afi, safi,
17724 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17725 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17726 }
17727
17728 /* next-hop-self */
17729 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17730 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17731 }
17732
17733 /* remove-private-AS */
17734 if (peergroup_af_flag_check(peer, afi, safi,
17735 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17736 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17737 addr);
17738 }
17739
17740 else if (peergroup_af_flag_check(peer, afi, safi,
17741 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17742 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17743 addr);
17744 }
17745
17746 else if (peergroup_af_flag_check(peer, afi, safi,
17747 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17748 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17749 }
17750
17751 else if (peergroup_af_flag_check(peer, afi, safi,
17752 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17753 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17754 }
17755
17756 /* as-override */
17757 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17758 vty_out(vty, " neighbor %s as-override\n", addr);
17759 }
17760
17761 /* send-community print. */
17762 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17763 PEER_FLAG_SEND_COMMUNITY);
17764 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17765 PEER_FLAG_SEND_EXT_COMMUNITY);
17766 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17767 PEER_FLAG_SEND_LARGE_COMMUNITY);
17768
17769 if (flag_scomm && flag_secomm && flag_slcomm) {
17770 vty_out(vty, " no neighbor %s send-community all\n", addr);
17771 } else {
17772 if (flag_scomm)
17773 vty_out(vty, " no neighbor %s send-community\n", addr);
17774 if (flag_secomm)
17775 vty_out(vty,
17776 " no neighbor %s send-community extended\n",
17777 addr);
17778
17779 if (flag_slcomm)
17780 vty_out(vty, " no neighbor %s send-community large\n",
17781 addr);
17782 }
17783
17784 /* Default information */
17785 if (peergroup_af_flag_check(peer, afi, safi,
17786 PEER_FLAG_DEFAULT_ORIGINATE)) {
17787 vty_out(vty, " neighbor %s default-originate", addr);
17788
17789 if (peer->default_rmap[afi][safi].name)
17790 vty_out(vty, " route-map %s",
17791 peer->default_rmap[afi][safi].name);
17792
17793 vty_out(vty, "\n");
17794 }
17795
17796 /* Soft reconfiguration inbound. */
17797 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17798 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17799 addr);
17800 }
17801
17802 /* maximum-prefix. */
17803 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17804 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17805 peer->pmax[afi][safi]);
17806
17807 if (peer->pmax_threshold[afi][safi]
17808 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17809 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17810 if (peer_af_flag_check(peer, afi, safi,
17811 PEER_FLAG_MAX_PREFIX_WARNING))
17812 vty_out(vty, " warning-only");
17813 if (peer->pmax_restart[afi][safi])
17814 vty_out(vty, " restart %u",
17815 peer->pmax_restart[afi][safi]);
17816 if (peer_af_flag_check(peer, afi, safi,
17817 PEER_FLAG_MAX_PREFIX_FORCE))
17818 vty_out(vty, " force");
17819
17820 vty_out(vty, "\n");
17821 }
17822
17823 /* maximum-prefix-out */
17824 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17825 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17826 addr, peer->pmax_out[afi][safi]);
17827
17828 /* Route server client. */
17829 if (peergroup_af_flag_check(peer, afi, safi,
17830 PEER_FLAG_RSERVER_CLIENT)) {
17831 vty_out(vty, " neighbor %s route-server-client\n", addr);
17832 }
17833
17834 /* Nexthop-local unchanged. */
17835 if (peergroup_af_flag_check(peer, afi, safi,
17836 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17837 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17838 }
17839
17840 /* allowas-in <1-10> */
17841 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17842 if (peer_af_flag_check(peer, afi, safi,
17843 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17844 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17845 } else if (peer->allowas_in[afi][safi] == 3) {
17846 vty_out(vty, " neighbor %s allowas-in\n", addr);
17847 } else {
17848 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17849 peer->allowas_in[afi][safi]);
17850 }
17851 }
17852
17853 /* accept-own */
17854 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17855 vty_out(vty, " neighbor %s accept-own\n", addr);
17856
17857 /* soo */
17858 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17859 char *soo_str = ecommunity_ecom2str(
17860 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17861
17862 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17863 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17864 }
17865
17866 /* weight */
17867 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17868 vty_out(vty, " neighbor %s weight %lu\n", addr,
17869 peer->weight[afi][safi]);
17870
17871 /* Filter. */
17872 bgp_config_write_filter(vty, peer, afi, safi);
17873
17874 /* atribute-unchanged. */
17875 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17876 || (safi != SAFI_EVPN
17877 && peer_af_flag_check(peer, afi, safi,
17878 PEER_FLAG_NEXTHOP_UNCHANGED))
17879 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17880
17881 if (!peer_group_active(peer)
17882 || peergroup_af_flag_check(peer, afi, safi,
17883 PEER_FLAG_AS_PATH_UNCHANGED)
17884 || peergroup_af_flag_check(peer, afi, safi,
17885 PEER_FLAG_NEXTHOP_UNCHANGED)
17886 || peergroup_af_flag_check(peer, afi, safi,
17887 PEER_FLAG_MED_UNCHANGED)) {
17888
17889 vty_out(vty,
17890 " neighbor %s attribute-unchanged%s%s%s\n",
17891 addr,
17892 peer_af_flag_check(peer, afi, safi,
17893 PEER_FLAG_AS_PATH_UNCHANGED)
17894 ? " as-path"
17895 : "",
17896 peer_af_flag_check(peer, afi, safi,
17897 PEER_FLAG_NEXTHOP_UNCHANGED)
17898 ? " next-hop"
17899 : "",
17900 peer_af_flag_check(peer, afi, safi,
17901 PEER_FLAG_MED_UNCHANGED)
17902 ? " med"
17903 : "");
17904 }
17905 }
17906 }
17907
17908 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17909 safi_t safi)
17910 {
17911 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17912 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17913 vty_out(vty, " no bgp retain route-target all\n");
17914 }
17915
17916 /* Address family based peer configuration display. */
17917 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17918 safi_t safi)
17919 {
17920 struct peer *peer;
17921 struct peer_group *group;
17922 struct listnode *node, *nnode;
17923
17924
17925 vty_frame(vty, " !\n address-family ");
17926 if (afi == AFI_IP) {
17927 if (safi == SAFI_UNICAST)
17928 vty_frame(vty, "ipv4 unicast");
17929 else if (safi == SAFI_LABELED_UNICAST)
17930 vty_frame(vty, "ipv4 labeled-unicast");
17931 else if (safi == SAFI_MULTICAST)
17932 vty_frame(vty, "ipv4 multicast");
17933 else if (safi == SAFI_MPLS_VPN)
17934 vty_frame(vty, "ipv4 vpn");
17935 else if (safi == SAFI_ENCAP)
17936 vty_frame(vty, "ipv4 encap");
17937 else if (safi == SAFI_FLOWSPEC)
17938 vty_frame(vty, "ipv4 flowspec");
17939 } else if (afi == AFI_IP6) {
17940 if (safi == SAFI_UNICAST)
17941 vty_frame(vty, "ipv6 unicast");
17942 else if (safi == SAFI_LABELED_UNICAST)
17943 vty_frame(vty, "ipv6 labeled-unicast");
17944 else if (safi == SAFI_MULTICAST)
17945 vty_frame(vty, "ipv6 multicast");
17946 else if (safi == SAFI_MPLS_VPN)
17947 vty_frame(vty, "ipv6 vpn");
17948 else if (safi == SAFI_ENCAP)
17949 vty_frame(vty, "ipv6 encap");
17950 else if (safi == SAFI_FLOWSPEC)
17951 vty_frame(vty, "ipv6 flowspec");
17952 } else if (afi == AFI_L2VPN) {
17953 if (safi == SAFI_EVPN)
17954 vty_frame(vty, "l2vpn evpn");
17955 }
17956 vty_frame(vty, "\n");
17957
17958 bgp_config_write_distance(vty, bgp, afi, safi);
17959
17960 bgp_config_write_network(vty, bgp, afi, safi);
17961
17962 bgp_config_write_redistribute(vty, bgp, afi, safi);
17963
17964 /* BGP flag dampening. */
17965 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17966 bgp_config_write_damp(vty, afi, safi);
17967
17968 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17969 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17970
17971 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17972 /* Do not display doppelganger peers */
17973 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17974 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17975 }
17976
17977 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17978 bgp_config_write_table_map(vty, bgp, afi, safi);
17979
17980 if (safi == SAFI_EVPN)
17981 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17982
17983 if (safi == SAFI_FLOWSPEC)
17984 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17985
17986 if (safi == SAFI_MPLS_VPN)
17987 bgp_vpn_config_write(vty, bgp, afi, safi);
17988
17989 if (safi == SAFI_UNICAST) {
17990 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17991 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17992 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17993
17994 vty_out(vty, " export vpn\n");
17995 }
17996 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17997 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17998
17999 vty_out(vty, " import vpn\n");
18000 }
18001 if (CHECK_FLAG(bgp->af_flags[afi][safi],
18002 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
18003 char *name;
18004
18005 for (ALL_LIST_ELEMENTS_RO(
18006 bgp->vpn_policy[afi].import_vrf, node,
18007 name))
18008 vty_out(vty, " import vrf %s\n", name);
18009 }
18010 }
18011
18012 vty_endframe(vty, " exit-address-family\n");
18013 }
18014
18015 int bgp_config_write(struct vty *vty)
18016 {
18017 struct bgp *bgp;
18018 struct peer_group *group;
18019 struct peer *peer;
18020 struct listnode *node, *nnode;
18021 struct listnode *mnode, *mnnode;
18022 afi_t afi;
18023 safi_t safi;
18024 uint32_t tovpn_sid_index = 0;
18025
18026 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
18027 vty_out(vty, "bgp route-map delay-timer %u\n",
18028 bm->rmap_update_timer);
18029
18030 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
18031 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
18032 if (bm->v_update_delay != bm->v_establish_wait)
18033 vty_out(vty, " %d", bm->v_establish_wait);
18034 vty_out(vty, "\n");
18035 }
18036
18037 if (bm->wait_for_fib)
18038 vty_out(vty, "bgp suppress-fib-pending\n");
18039
18040 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18041 vty_out(vty, "bgp graceful-shutdown\n");
18042
18043 /* No-RIB (Zebra) option flag configuration */
18044 if (bgp_option_check(BGP_OPT_NO_FIB))
18045 vty_out(vty, "bgp no-rib\n");
18046
18047 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
18048 vty_out(vty, "bgp send-extra-data zebra\n");
18049
18050 /* BGP session DSCP value */
18051 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
18052 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
18053
18054 /* BGP InQ limit */
18055 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
18056 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
18057
18058 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
18059 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
18060
18061 /* BGP configuration. */
18062 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
18063
18064 /* skip all auto created vrf as they dont have user config */
18065 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
18066 continue;
18067
18068 /* Router bgp ASN */
18069 vty_out(vty, "router bgp %u", bgp->as);
18070
18071 if (bgp->name)
18072 vty_out(vty, " %s %s",
18073 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
18074 ? "view" : "vrf", bgp->name);
18075 vty_out(vty, "\n");
18076
18077 /* BGP fast-external-failover. */
18078 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18079 vty_out(vty, " no bgp fast-external-failover\n");
18080
18081 /* BGP router ID. */
18082 if (bgp->router_id_static.s_addr != INADDR_ANY)
18083 vty_out(vty, " bgp router-id %pI4\n",
18084 &bgp->router_id_static);
18085
18086 /* Suppress fib pending */
18087 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18088 vty_out(vty, " bgp suppress-fib-pending\n");
18089
18090 /* BGP log-neighbor-changes. */
18091 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18092 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
18093 vty_out(vty, " %sbgp log-neighbor-changes\n",
18094 CHECK_FLAG(bgp->flags,
18095 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18096 ? ""
18097 : "no ");
18098
18099 /* BGP configuration. */
18100 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
18101 vty_out(vty, " bgp always-compare-med\n");
18102
18103 /* RFC8212 default eBGP policy. */
18104 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18105 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18106 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18107 CHECK_FLAG(bgp->flags,
18108 BGP_FLAG_EBGP_REQUIRES_POLICY)
18109 ? ""
18110 : "no ");
18111
18112 /* draft-ietf-idr-deprecate-as-set-confed-set */
18113 if (bgp->reject_as_sets)
18114 vty_out(vty, " bgp reject-as-sets\n");
18115
18116 /* Suppress duplicate updates if the route actually not changed
18117 */
18118 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18119 != SAVE_BGP_SUPPRESS_DUPLICATES)
18120 vty_out(vty, " %sbgp suppress-duplicates\n",
18121 CHECK_FLAG(bgp->flags,
18122 BGP_FLAG_SUPPRESS_DUPLICATES)
18123 ? ""
18124 : "no ");
18125
18126 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18127 */
18128 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18129 SAVE_BGP_HARD_ADMIN_RESET)
18130 vty_out(vty, " %sbgp hard-administrative-reset\n",
18131 CHECK_FLAG(bgp->flags,
18132 BGP_FLAG_HARD_ADMIN_RESET)
18133 ? ""
18134 : "no ");
18135
18136 /* BGP default <afi>-<safi> */
18137 FOREACH_AFI_SAFI (afi, safi) {
18138 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18139 if (!bgp->default_af[afi][safi])
18140 vty_out(vty, " no bgp default %s\n",
18141 get_bgp_default_af_flag(afi,
18142 safi));
18143 } else if (bgp->default_af[afi][safi])
18144 vty_out(vty, " bgp default %s\n",
18145 get_bgp_default_af_flag(afi, safi));
18146 }
18147
18148 /* BGP default local-preference. */
18149 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18150 vty_out(vty, " bgp default local-preference %u\n",
18151 bgp->default_local_pref);
18152
18153 /* BGP default show-hostname */
18154 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18155 != SAVE_BGP_SHOW_HOSTNAME)
18156 vty_out(vty, " %sbgp default show-hostname\n",
18157 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18158 ? ""
18159 : "no ");
18160
18161 /* BGP default show-nexthop-hostname */
18162 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18163 != SAVE_BGP_SHOW_HOSTNAME)
18164 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18165 CHECK_FLAG(bgp->flags,
18166 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18167 ? ""
18168 : "no ");
18169
18170 /* BGP default subgroup-pkt-queue-max. */
18171 if (bgp->default_subgroup_pkt_queue_max
18172 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18173 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18174 bgp->default_subgroup_pkt_queue_max);
18175
18176 /* BGP client-to-client reflection. */
18177 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18178 vty_out(vty, " no bgp client-to-client reflection\n");
18179
18180 /* BGP cluster ID. */
18181 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18182 vty_out(vty, " bgp cluster-id %pI4\n",
18183 &bgp->cluster_id);
18184
18185 /* Disable ebgp connected nexthop check */
18186 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18187 vty_out(vty,
18188 " bgp disable-ebgp-connected-route-check\n");
18189
18190 /* Confederation identifier*/
18191 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18192 vty_out(vty, " bgp confederation identifier %u\n",
18193 bgp->confed_id);
18194
18195 /* Confederation peer */
18196 if (bgp->confed_peers_cnt > 0) {
18197 int i;
18198
18199 vty_out(vty, " bgp confederation peers");
18200
18201 for (i = 0; i < bgp->confed_peers_cnt; i++)
18202 vty_out(vty, " %u", bgp->confed_peers[i]);
18203
18204 vty_out(vty, "\n");
18205 }
18206
18207 /* BGP deterministic-med. */
18208 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18209 != SAVE_BGP_DETERMINISTIC_MED)
18210 vty_out(vty, " %sbgp deterministic-med\n",
18211 CHECK_FLAG(bgp->flags,
18212 BGP_FLAG_DETERMINISTIC_MED)
18213 ? ""
18214 : "no ");
18215
18216 /* BGP update-delay. */
18217 bgp_config_write_update_delay(vty, bgp);
18218
18219 if (bgp->v_maxmed_onstartup
18220 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18221 vty_out(vty, " bgp max-med on-startup %u",
18222 bgp->v_maxmed_onstartup);
18223 if (bgp->maxmed_onstartup_value
18224 != BGP_MAXMED_VALUE_DEFAULT)
18225 vty_out(vty, " %u",
18226 bgp->maxmed_onstartup_value);
18227 vty_out(vty, "\n");
18228 }
18229 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18230 vty_out(vty, " bgp max-med administrative");
18231 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18232 vty_out(vty, " %u", bgp->maxmed_admin_value);
18233 vty_out(vty, "\n");
18234 }
18235
18236 /* write quanta */
18237 bgp_config_write_wpkt_quanta(vty, bgp);
18238 /* read quanta */
18239 bgp_config_write_rpkt_quanta(vty, bgp);
18240
18241 /* coalesce time */
18242 bgp_config_write_coalesce_time(vty, bgp);
18243
18244 /* BGP per-instance graceful-shutdown */
18245 /* BGP-wide settings and per-instance settings are mutually
18246 * exclusive.
18247 */
18248 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18249 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18250 vty_out(vty, " bgp graceful-shutdown\n");
18251
18252 /* Long-lived Graceful Restart */
18253 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18254 vty_out(vty,
18255 " bgp long-lived-graceful-restart stale-time %u\n",
18256 bgp->llgr_stale_time);
18257
18258 /* BGP graceful-restart. */
18259 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18260 vty_out(vty,
18261 " bgp graceful-restart stalepath-time %u\n",
18262 bgp->stalepath_time);
18263
18264 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18265 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18266 bgp->restart_time);
18267
18268 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18269 SAVE_BGP_GRACEFUL_NOTIFICATION)
18270 vty_out(vty, " %sbgp graceful-restart notification\n",
18271 CHECK_FLAG(bgp->flags,
18272 BGP_FLAG_GRACEFUL_NOTIFICATION)
18273 ? ""
18274 : "no ");
18275
18276 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18277 vty_out(vty,
18278 " bgp graceful-restart select-defer-time %u\n",
18279 bgp->select_defer_time);
18280
18281 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18282 vty_out(vty, " bgp graceful-restart\n");
18283
18284 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18285 vty_out(vty, " bgp graceful-restart-disable\n");
18286
18287 /* BGP graceful-restart Preserve State F bit. */
18288 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18289 vty_out(vty,
18290 " bgp graceful-restart preserve-fw-state\n");
18291
18292 /* BGP TCP keepalive */
18293 bgp_config_tcp_keepalive(vty, bgp);
18294
18295 /* Stale timer for RIB */
18296 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18297 vty_out(vty,
18298 " bgp graceful-restart rib-stale-time %u\n",
18299 bgp->rib_stale_time);
18300
18301 /* BGP bestpath method. */
18302 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18303 vty_out(vty, " bgp bestpath as-path ignore\n");
18304 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18305 vty_out(vty, " bgp bestpath as-path confed\n");
18306
18307 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18308 if (CHECK_FLAG(bgp->flags,
18309 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18310 vty_out(vty,
18311 " bgp bestpath as-path multipath-relax as-set\n");
18312 } else {
18313 vty_out(vty,
18314 " bgp bestpath as-path multipath-relax\n");
18315 }
18316 }
18317
18318 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18319 vty_out(vty,
18320 " bgp route-reflector allow-outbound-policy\n");
18321 }
18322 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18323 vty_out(vty, " bgp bestpath compare-routerid\n");
18324 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18325 vty_out(vty, " bgp bestpath aigp\n");
18326 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18327 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18328 vty_out(vty, " bgp bestpath med");
18329 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18330 vty_out(vty, " confed");
18331 if (CHECK_FLAG(bgp->flags,
18332 BGP_FLAG_MED_MISSING_AS_WORST))
18333 vty_out(vty, " missing-as-worst");
18334 vty_out(vty, "\n");
18335 }
18336
18337 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18338 vty_out(vty,
18339 " bgp bestpath peer-type multipath-relax\n");
18340
18341 /* Link bandwidth handling. */
18342 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18343 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18344 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18345 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18346 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18347 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18348
18349 /* BGP network import check. */
18350 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18351 != SAVE_BGP_IMPORT_CHECK)
18352 vty_out(vty, " %sbgp network import-check\n",
18353 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18354 ? ""
18355 : "no ");
18356
18357 /* BGP timers configuration. */
18358 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18359 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18360 vty_out(vty, " timers bgp %u %u\n",
18361 bgp->default_keepalive, bgp->default_holdtime);
18362
18363 /* BGP minimum holdtime configuration. */
18364 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18365 && bgp->default_min_holdtime != 0)
18366 vty_out(vty, " bgp minimum-holdtime %u\n",
18367 bgp->default_min_holdtime);
18368
18369 /* Conditional advertisement timer configuration */
18370 if (bgp->condition_check_period
18371 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18372 vty_out(vty,
18373 " bgp conditional-advertisement timer %u\n",
18374 bgp->condition_check_period);
18375
18376 /* peer-group */
18377 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18378 bgp_config_write_peer_global(vty, bgp, group->conf);
18379 }
18380
18381 /* Normal neighbor configuration. */
18382 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18383 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18384 bgp_config_write_peer_global(vty, bgp, peer);
18385 }
18386
18387 /* listen range and limit for dynamic BGP neighbors */
18388 bgp_config_write_listen(vty, bgp);
18389
18390 /*
18391 * BGP default autoshutdown neighbors
18392 *
18393 * This must be placed after any peer and peer-group
18394 * configuration, to avoid setting all peers to shutdown after
18395 * a daemon restart, which is undesired behavior. (see #2286)
18396 */
18397 if (bgp->autoshutdown)
18398 vty_out(vty, " bgp default shutdown\n");
18399
18400 /* BGP instance administrative shutdown */
18401 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18402 vty_out(vty, " bgp shutdown\n");
18403
18404 if (bgp->allow_martian)
18405 vty_out(vty, " bgp allow-martian-nexthop\n");
18406
18407 if (bgp->fast_convergence)
18408 vty_out(vty, " bgp fast-convergence\n");
18409
18410 if (bgp->srv6_enabled) {
18411 vty_frame(vty, " !\n segment-routing srv6\n");
18412 if (strlen(bgp->srv6_locator_name))
18413 vty_out(vty, " locator %s\n",
18414 bgp->srv6_locator_name);
18415 vty_endframe(vty, " exit\n");
18416 }
18417
18418 tovpn_sid_index = bgp->tovpn_sid_index;
18419 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18420 vty_out(vty, " sid vpn per-vrf export auto\n");
18421 } else if (tovpn_sid_index != 0) {
18422 vty_out(vty, " sid vpn per-vrf export %d\n",
18423 tovpn_sid_index);
18424 }
18425
18426 /* IPv4 unicast configuration. */
18427 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18428
18429 /* IPv4 multicast configuration. */
18430 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18431
18432 /* IPv4 labeled-unicast configuration. */
18433 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18434
18435 /* IPv4 VPN configuration. */
18436 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18437
18438 /* ENCAPv4 configuration. */
18439 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18440
18441 /* FLOWSPEC v4 configuration. */
18442 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18443
18444 /* IPv6 unicast configuration. */
18445 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18446
18447 /* IPv6 multicast configuration. */
18448 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18449
18450 /* IPv6 labeled-unicast configuration. */
18451 bgp_config_write_family(vty, bgp, AFI_IP6,
18452 SAFI_LABELED_UNICAST);
18453
18454 /* IPv6 VPN configuration. */
18455 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18456
18457 /* ENCAPv6 configuration. */
18458 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18459
18460 /* FLOWSPEC v6 configuration. */
18461 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18462
18463 /* EVPN configuration. */
18464 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18465
18466 hook_call(bgp_inst_config_write, bgp, vty);
18467
18468 #ifdef ENABLE_BGP_VNC
18469 bgp_rfapi_cfg_write(vty, bgp);
18470 #endif
18471
18472 vty_out(vty, "exit\n");
18473 vty_out(vty, "!\n");
18474 }
18475 return 0;
18476 }
18477
18478
18479 /* BGP node structure. */
18480 static struct cmd_node bgp_node = {
18481 .name = "bgp",
18482 .node = BGP_NODE,
18483 .parent_node = CONFIG_NODE,
18484 .prompt = "%s(config-router)# ",
18485 .config_write = bgp_config_write,
18486 };
18487
18488 static struct cmd_node bgp_ipv4_unicast_node = {
18489 .name = "bgp ipv4 unicast",
18490 .node = BGP_IPV4_NODE,
18491 .parent_node = BGP_NODE,
18492 .prompt = "%s(config-router-af)# ",
18493 .no_xpath = true,
18494 };
18495
18496 static struct cmd_node bgp_ipv4_multicast_node = {
18497 .name = "bgp ipv4 multicast",
18498 .node = BGP_IPV4M_NODE,
18499 .parent_node = BGP_NODE,
18500 .prompt = "%s(config-router-af)# ",
18501 .no_xpath = true,
18502 };
18503
18504 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18505 .name = "bgp ipv4 labeled unicast",
18506 .node = BGP_IPV4L_NODE,
18507 .parent_node = BGP_NODE,
18508 .prompt = "%s(config-router-af)# ",
18509 .no_xpath = true,
18510 };
18511
18512 static struct cmd_node bgp_ipv6_unicast_node = {
18513 .name = "bgp ipv6 unicast",
18514 .node = BGP_IPV6_NODE,
18515 .parent_node = BGP_NODE,
18516 .prompt = "%s(config-router-af)# ",
18517 .no_xpath = true,
18518 };
18519
18520 static struct cmd_node bgp_ipv6_multicast_node = {
18521 .name = "bgp ipv6 multicast",
18522 .node = BGP_IPV6M_NODE,
18523 .parent_node = BGP_NODE,
18524 .prompt = "%s(config-router-af)# ",
18525 .no_xpath = true,
18526 };
18527
18528 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18529 .name = "bgp ipv6 labeled unicast",
18530 .node = BGP_IPV6L_NODE,
18531 .parent_node = BGP_NODE,
18532 .prompt = "%s(config-router-af)# ",
18533 .no_xpath = true,
18534 };
18535
18536 static struct cmd_node bgp_vpnv4_node = {
18537 .name = "bgp vpnv4",
18538 .node = BGP_VPNV4_NODE,
18539 .parent_node = BGP_NODE,
18540 .prompt = "%s(config-router-af)# ",
18541 .no_xpath = true,
18542 };
18543
18544 static struct cmd_node bgp_vpnv6_node = {
18545 .name = "bgp vpnv6",
18546 .node = BGP_VPNV6_NODE,
18547 .parent_node = BGP_NODE,
18548 .prompt = "%s(config-router-af-vpnv6)# ",
18549 .no_xpath = true,
18550 };
18551
18552 static struct cmd_node bgp_evpn_node = {
18553 .name = "bgp evpn",
18554 .node = BGP_EVPN_NODE,
18555 .parent_node = BGP_NODE,
18556 .prompt = "%s(config-router-evpn)# ",
18557 .no_xpath = true,
18558 };
18559
18560 static struct cmd_node bgp_evpn_vni_node = {
18561 .name = "bgp evpn vni",
18562 .node = BGP_EVPN_VNI_NODE,
18563 .parent_node = BGP_EVPN_NODE,
18564 .prompt = "%s(config-router-af-vni)# ",
18565 };
18566
18567 static struct cmd_node bgp_flowspecv4_node = {
18568 .name = "bgp ipv4 flowspec",
18569 .node = BGP_FLOWSPECV4_NODE,
18570 .parent_node = BGP_NODE,
18571 .prompt = "%s(config-router-af)# ",
18572 .no_xpath = true,
18573 };
18574
18575 static struct cmd_node bgp_flowspecv6_node = {
18576 .name = "bgp ipv6 flowspec",
18577 .node = BGP_FLOWSPECV6_NODE,
18578 .parent_node = BGP_NODE,
18579 .prompt = "%s(config-router-af-vpnv6)# ",
18580 .no_xpath = true,
18581 };
18582
18583 static struct cmd_node bgp_srv6_node = {
18584 .name = "bgp srv6",
18585 .node = BGP_SRV6_NODE,
18586 .parent_node = BGP_NODE,
18587 .prompt = "%s(config-router-srv6)# ",
18588 };
18589
18590 static void community_list_vty(void);
18591
18592 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18593 {
18594 struct bgp *bgp;
18595 struct peer_group *group;
18596 struct listnode *lnbgp, *lnpeer;
18597
18598 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18599 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18600 vector_set(comps,
18601 XSTRDUP(MTYPE_COMPLETION, group->name));
18602 }
18603 }
18604
18605 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18606 {
18607 struct bgp *bgp;
18608 struct peer *peer;
18609 struct listnode *lnbgp, *lnpeer;
18610
18611 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18612 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18613 /* only provide suggestions on the appropriate input
18614 * token type,
18615 * they'll otherwise show up multiple times */
18616 enum cmd_token_type match_type;
18617 char *name = peer->host;
18618
18619 if (peer->conf_if) {
18620 match_type = VARIABLE_TKN;
18621 name = peer->conf_if;
18622 } else if (strchr(peer->host, ':'))
18623 match_type = IPV6_TKN;
18624 else
18625 match_type = IPV4_TKN;
18626
18627 if (token->type != match_type)
18628 continue;
18629
18630 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18631 }
18632 }
18633 }
18634
18635 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18636 {
18637 bgp_ac_peer(comps, token);
18638
18639 if (token->type == VARIABLE_TKN)
18640 bgp_ac_peergroup(comps, token);
18641 }
18642
18643 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18644 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18645 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18646 {.varname = "peer", .completions = bgp_ac_neighbor},
18647 {.completions = NULL}};
18648
18649 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18650 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18651 {.completions = NULL} };
18652
18653 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18654
18655 static struct thread *t_bgp_cfg;
18656
18657 bool bgp_config_inprocess(void)
18658 {
18659 return thread_is_scheduled(t_bgp_cfg);
18660 }
18661
18662 static void bgp_config_finish(struct thread *t)
18663 {
18664 struct listnode *node;
18665 struct bgp *bgp;
18666
18667 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18668 hook_call(bgp_config_end, bgp);
18669 }
18670
18671 static void bgp_config_start(void)
18672 {
18673 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18674 THREAD_OFF(t_bgp_cfg);
18675 thread_add_timer(bm->master, bgp_config_finish, NULL,
18676 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18677 }
18678
18679 /* When we receive a hook the configuration is read,
18680 * we start a timer to make sure we postpone sending
18681 * EoR before route-maps are processed.
18682 * This is especially valid if using `bgp route-map delay-timer`.
18683 */
18684 static void bgp_config_end(void)
18685 {
18686 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18687 uint32_t bgp_post_config_delay =
18688 thread_is_scheduled(bm->t_rmap_update)
18689 ? thread_timer_remain_second(bm->t_rmap_update)
18690 : BGP_POST_CONFIG_DELAY_SECONDS;
18691
18692 /* If BGP config processing thread isn't running, then
18693 * we can return and rely it's properly handled.
18694 */
18695 if (!bgp_config_inprocess())
18696 return;
18697
18698 THREAD_OFF(t_bgp_cfg);
18699
18700 /* Start a new timer to make sure we don't send EoR
18701 * before route-maps are processed.
18702 */
18703 thread_add_timer(bm->master, bgp_config_finish, NULL,
18704 bgp_post_config_delay, &t_bgp_cfg);
18705 }
18706
18707 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18708 {
18709 int write = 0;
18710 struct interface *ifp;
18711 struct bgp_interface *iifp;
18712
18713 FOR_ALL_INTERFACES (vrf, ifp) {
18714 iifp = ifp->info;
18715 if (!iifp)
18716 continue;
18717
18718 if_vty_config_start(vty, ifp);
18719
18720 if (CHECK_FLAG(iifp->flags,
18721 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18722 vty_out(vty, " mpls bgp forwarding\n");
18723 write++;
18724 }
18725
18726 if_vty_config_end(vty);
18727 }
18728
18729 return write;
18730 }
18731
18732 /* Configuration write function for bgpd. */
18733 static int config_write_interface(struct vty *vty)
18734 {
18735 int write = 0;
18736 struct vrf *vrf = NULL;
18737
18738 /* Display all VRF aware OSPF interface configuration */
18739 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18740 write += config_write_interface_one(vty, vrf);
18741 }
18742
18743 return write;
18744 }
18745
18746 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18747 "[no$no] mpls bgp forwarding",
18748 NO_STR MPLS_STR BGP_STR
18749 "Enable MPLS forwarding for eBGP directly connected peers\n")
18750 {
18751 bool check;
18752 struct bgp_interface *iifp;
18753
18754 VTY_DECLVAR_CONTEXT(interface, ifp);
18755 iifp = ifp->info;
18756 if (!iifp) {
18757 vty_out(vty, "Interface %s not available\n", ifp->name);
18758 return CMD_WARNING_CONFIG_FAILED;
18759 }
18760 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18761 if (check != !no) {
18762 if (no)
18763 UNSET_FLAG(iifp->flags,
18764 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18765 else
18766 SET_FLAG(iifp->flags,
18767 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18768 /* trigger a nht update on eBGP sessions */
18769 if (if_is_operative(ifp))
18770 bgp_nht_ifp_up(ifp);
18771 }
18772 return CMD_SUCCESS;
18773 }
18774
18775 DEFPY (bgp_inq_limit,
18776 bgp_inq_limit_cmd,
18777 "bgp input-queue-limit (1-4294967295)$limit",
18778 BGP_STR
18779 "Set the BGP Input Queue limit for all peers when message parsing\n"
18780 "Input-Queue limit\n")
18781 {
18782 bm->inq_limit = limit;
18783
18784 return CMD_SUCCESS;
18785 }
18786
18787 DEFPY (no_bgp_inq_limit,
18788 no_bgp_inq_limit_cmd,
18789 "no bgp input-queue-limit [(1-4294967295)$limit]",
18790 NO_STR
18791 BGP_STR
18792 "Set the BGP Input Queue limit for all peers when message parsing\n"
18793 "Input-Queue limit\n")
18794 {
18795 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18796
18797 return CMD_SUCCESS;
18798 }
18799
18800 DEFPY (bgp_outq_limit,
18801 bgp_outq_limit_cmd,
18802 "bgp output-queue-limit (1-4294967295)$limit",
18803 BGP_STR
18804 "Set the BGP Output Queue limit for all peers when message parsing\n"
18805 "Output-Queue limit\n")
18806 {
18807 bm->outq_limit = limit;
18808
18809 return CMD_SUCCESS;
18810 }
18811
18812 DEFPY (no_bgp_outq_limit,
18813 no_bgp_outq_limit_cmd,
18814 "no bgp output-queue-limit [(1-4294967295)$limit]",
18815 NO_STR
18816 BGP_STR
18817 "Set the BGP Output Queue limit for all peers when message parsing\n"
18818 "Output-Queue limit\n")
18819 {
18820 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18821
18822 return CMD_SUCCESS;
18823 }
18824
18825
18826 /* Initialization of BGP interface. */
18827 static void bgp_vty_if_init(void)
18828 {
18829 /* Install interface node. */
18830 if_cmd_init(config_write_interface);
18831
18832 /* "mpls bgp forwarding" commands. */
18833 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18834 }
18835
18836 void bgp_vty_init(void)
18837 {
18838 cmd_variable_handler_register(bgp_var_neighbor);
18839 cmd_variable_handler_register(bgp_var_peergroup);
18840
18841 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18842
18843 /* Install bgp top node. */
18844 install_node(&bgp_node);
18845 install_node(&bgp_ipv4_unicast_node);
18846 install_node(&bgp_ipv4_multicast_node);
18847 install_node(&bgp_ipv4_labeled_unicast_node);
18848 install_node(&bgp_ipv6_unicast_node);
18849 install_node(&bgp_ipv6_multicast_node);
18850 install_node(&bgp_ipv6_labeled_unicast_node);
18851 install_node(&bgp_vpnv4_node);
18852 install_node(&bgp_vpnv6_node);
18853 install_node(&bgp_evpn_node);
18854 install_node(&bgp_evpn_vni_node);
18855 install_node(&bgp_flowspecv4_node);
18856 install_node(&bgp_flowspecv6_node);
18857 install_node(&bgp_srv6_node);
18858
18859 /* Install default VTY commands to new nodes. */
18860 install_default(BGP_NODE);
18861 install_default(BGP_IPV4_NODE);
18862 install_default(BGP_IPV4M_NODE);
18863 install_default(BGP_IPV4L_NODE);
18864 install_default(BGP_IPV6_NODE);
18865 install_default(BGP_IPV6M_NODE);
18866 install_default(BGP_IPV6L_NODE);
18867 install_default(BGP_VPNV4_NODE);
18868 install_default(BGP_VPNV6_NODE);
18869 install_default(BGP_FLOWSPECV4_NODE);
18870 install_default(BGP_FLOWSPECV6_NODE);
18871 install_default(BGP_EVPN_NODE);
18872 install_default(BGP_EVPN_VNI_NODE);
18873 install_default(BGP_SRV6_NODE);
18874
18875 /* "global bgp inq-limit command */
18876 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18877 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18878 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18879 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
18880
18881 /* "bgp local-mac" hidden commands. */
18882 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18883 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18884
18885 /* "bgp suppress-fib-pending" global */
18886 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18887
18888 /* bgp route-map delay-timer commands. */
18889 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18890 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18891
18892 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18893
18894 /* bgp fast-convergence command */
18895 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18896 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18897
18898 /* global bgp update-delay command */
18899 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18900 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18901
18902 /* global bgp graceful-shutdown command */
18903 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18904 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18905
18906 /* Dummy commands (Currently not supported) */
18907 install_element(BGP_NODE, &no_synchronization_cmd);
18908 install_element(BGP_NODE, &no_auto_summary_cmd);
18909
18910 /* "router bgp" commands. */
18911 install_element(CONFIG_NODE, &router_bgp_cmd);
18912
18913 /* "no router bgp" commands. */
18914 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18915
18916 /* "bgp session-dscp command */
18917 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18918 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18919
18920 /* "bgp router-id" commands. */
18921 install_element(BGP_NODE, &bgp_router_id_cmd);
18922 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18923
18924 /* "bgp suppress-fib-pending" command */
18925 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18926
18927 /* "bgp cluster-id" commands. */
18928 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18929 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18930
18931 /* "bgp no-rib" commands. */
18932 install_element(CONFIG_NODE, &bgp_norib_cmd);
18933 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18934
18935 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18936
18937 /* "bgp confederation" commands. */
18938 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18939 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18940
18941 /* "bgp confederation peers" commands. */
18942 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18943 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18944
18945 /* bgp max-med command */
18946 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18947 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18948 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18949 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18950 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18951
18952 /* "neighbor role" commands. */
18953 install_element(BGP_NODE, &neighbor_role_cmd);
18954 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18955 install_element(BGP_NODE, &no_neighbor_role_cmd);
18956
18957 /* "neighbor aigp" commands. */
18958 install_element(BGP_NODE, &neighbor_aigp_cmd);
18959
18960 /* "neighbor graceful-shutdown" command */
18961 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18962
18963 /* bgp disable-ebgp-connected-nh-check */
18964 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18965 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18966
18967 /* bgp update-delay command */
18968 install_element(BGP_NODE, &bgp_update_delay_cmd);
18969 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18970
18971 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18972 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18973
18974 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18975 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18976
18977 /* "maximum-paths" commands. */
18978 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18979 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18980 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18981 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18982 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18983 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18984 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18985 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18986 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18987 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18988 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18989 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18990 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18991 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18992 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18993
18994 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18995 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18996 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18997 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18998 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18999 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
19000 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
19001 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
19002 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
19003 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
19004
19005 /* "timers bgp" commands. */
19006 install_element(BGP_NODE, &bgp_timers_cmd);
19007 install_element(BGP_NODE, &no_bgp_timers_cmd);
19008
19009 /* "minimum-holdtime" commands. */
19010 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
19011 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
19012
19013 /* route-map delay-timer commands - per instance for backwards compat.
19014 */
19015 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
19016 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19017
19018 /* "bgp client-to-client reflection" commands */
19019 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
19020 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
19021
19022 /* "bgp always-compare-med" commands */
19023 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
19024 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
19025
19026 /* bgp ebgp-requires-policy */
19027 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
19028 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
19029
19030 /* bgp suppress-duplicates */
19031 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
19032 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
19033
19034 /* bgp reject-as-sets */
19035 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
19036 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
19037
19038 /* "bgp deterministic-med" commands */
19039 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
19040 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
19041
19042 /* "bgp graceful-restart" command */
19043 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
19044 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
19045
19046 /* "bgp graceful-restart-disable" command */
19047 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
19048 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
19049
19050 /* "neighbor a:b:c:d graceful-restart" command */
19051 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
19052 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
19053
19054 /* "neighbor a:b:c:d graceful-restart-disable" command */
19055 install_element(BGP_NODE,
19056 &bgp_neighbor_graceful_restart_disable_set_cmd);
19057 install_element(BGP_NODE,
19058 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
19059
19060 /* "neighbor a:b:c:d graceful-restart-helper" command */
19061 install_element(BGP_NODE,
19062 &bgp_neighbor_graceful_restart_helper_set_cmd);
19063 install_element(BGP_NODE,
19064 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
19065
19066 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
19067 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
19068 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
19069 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
19070 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
19071 install_element(BGP_NODE,
19072 &no_bgp_graceful_restart_select_defer_time_cmd);
19073 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
19074 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
19075 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
19076
19077 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19078 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
19079 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19080 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
19081
19082 /* "bgp graceful-shutdown" commands */
19083 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19084 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19085
19086 /* "bgp hard-administrative-reset" commands */
19087 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19088
19089 /* "bgp long-lived-graceful-restart" commands */
19090 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19091 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19092
19093 /* "bgp fast-external-failover" commands */
19094 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19095 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19096
19097 /* "bgp bestpath aigp" commands */
19098 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19099
19100 /* "bgp bestpath compare-routerid" commands */
19101 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19102 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19103
19104 /* "bgp bestpath as-path ignore" commands */
19105 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19106 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19107
19108 /* "bgp bestpath as-path confed" commands */
19109 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19110 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19111
19112 /* "bgp bestpath as-path multipath-relax" commands */
19113 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19114 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19115
19116 /* "bgp bestpath peer-type multipath-relax" commands */
19117 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19118 install_element(BGP_NODE,
19119 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19120
19121 /* "bgp log-neighbor-changes" commands */
19122 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19123 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19124
19125 /* "bgp bestpath med" commands */
19126 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19127 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19128
19129 /* "bgp bestpath bandwidth" commands */
19130 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
19131 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
19132
19133 /* "no bgp default <afi>-<safi>" commands. */
19134 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
19135
19136 /* "bgp network import-check" commands. */
19137 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19138 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19139 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19140
19141 /* "bgp default local-preference" commands. */
19142 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19143 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19144
19145 /* bgp default show-hostname */
19146 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19147 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19148
19149 /* bgp default show-nexthop-hostname */
19150 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19151 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19152
19153 /* "bgp default subgroup-pkt-queue-max" commands. */
19154 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19155 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19156
19157 /* bgp ibgp-allow-policy-mods command */
19158 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19159 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19160
19161 /* "bgp listen limit" commands. */
19162 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19163 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19164
19165 /* "bgp listen range" commands. */
19166 install_element(BGP_NODE, &bgp_listen_range_cmd);
19167 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19168
19169 /* "bgp default shutdown" command */
19170 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19171
19172 /* "bgp shutdown" commands */
19173 install_element(BGP_NODE, &bgp_shutdown_cmd);
19174 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19175 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19176 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19177
19178 /* "neighbor remote-as" commands. */
19179 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19180 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19181 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19182 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19183 install_element(BGP_NODE,
19184 &neighbor_interface_v6only_config_remote_as_cmd);
19185 install_element(BGP_NODE, &no_neighbor_cmd);
19186 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19187
19188 /* "neighbor peer-group" commands. */
19189 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19190 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19191 install_element(BGP_NODE,
19192 &no_neighbor_interface_peer_group_remote_as_cmd);
19193
19194 /* "neighbor local-as" commands. */
19195 install_element(BGP_NODE, &neighbor_local_as_cmd);
19196 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19197 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19198 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19199
19200 /* "neighbor solo" commands. */
19201 install_element(BGP_NODE, &neighbor_solo_cmd);
19202 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19203
19204 /* "neighbor password" commands. */
19205 install_element(BGP_NODE, &neighbor_password_cmd);
19206 install_element(BGP_NODE, &no_neighbor_password_cmd);
19207
19208 /* "neighbor activate" commands. */
19209 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19210 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19211 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19212 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19213 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19214 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19215 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19216 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19217 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19218 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19219 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19220 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19221
19222 /* "no neighbor activate" commands. */
19223 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19224 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19225 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19226 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19227 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19228 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19229 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19230 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19231 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19232 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19233 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19234 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19235
19236 /* "neighbor peer-group" set commands. */
19237 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19238 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19239 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19240 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19241 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19242 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19243 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19244 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19245 install_element(BGP_FLOWSPECV4_NODE,
19246 &neighbor_set_peer_group_hidden_cmd);
19247 install_element(BGP_FLOWSPECV6_NODE,
19248 &neighbor_set_peer_group_hidden_cmd);
19249
19250 /* "no neighbor peer-group unset" commands. */
19251 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19252 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19253 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19254 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19255 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19256 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19257 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19258 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19259 install_element(BGP_FLOWSPECV4_NODE,
19260 &no_neighbor_set_peer_group_hidden_cmd);
19261 install_element(BGP_FLOWSPECV6_NODE,
19262 &no_neighbor_set_peer_group_hidden_cmd);
19263
19264 /* "neighbor softreconfiguration inbound" commands.*/
19265 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19266 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19267 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19268 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19269 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19270 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19271 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19272 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19273 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19274 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19275 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19276 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19277 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19278 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19279 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19280 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19281 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19282 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19283 install_element(BGP_FLOWSPECV4_NODE,
19284 &neighbor_soft_reconfiguration_cmd);
19285 install_element(BGP_FLOWSPECV4_NODE,
19286 &no_neighbor_soft_reconfiguration_cmd);
19287 install_element(BGP_FLOWSPECV6_NODE,
19288 &neighbor_soft_reconfiguration_cmd);
19289 install_element(BGP_FLOWSPECV6_NODE,
19290 &no_neighbor_soft_reconfiguration_cmd);
19291 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19292 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19293
19294 /* "neighbor attribute-unchanged" commands. */
19295 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19296 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19297 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19298 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19299 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19300 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19301 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19302 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19303 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19304 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19305 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19306 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19307 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19308 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19309 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19310 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19311 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19312 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19313
19314 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19315 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19316
19317 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19318 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19319 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19320 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19321
19322 /* "nexthop-local unchanged" commands */
19323 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19324 install_element(BGP_IPV6_NODE,
19325 &no_neighbor_nexthop_local_unchanged_cmd);
19326
19327 /* "neighbor next-hop-self" commands. */
19328 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19329 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19330 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19331 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19332 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19333 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19334 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19335 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19336 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19337 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19338 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19339 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19340 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19341 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19342 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19343 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19344 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19345 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19346 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19347 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19348
19349 /* "neighbor next-hop-self force" commands. */
19350 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19351 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19352 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19353 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19354 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19355 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19356 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19357 install_element(BGP_IPV4_NODE,
19358 &no_neighbor_nexthop_self_all_hidden_cmd);
19359 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19360 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19361 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19362 install_element(BGP_IPV4M_NODE,
19363 &no_neighbor_nexthop_self_all_hidden_cmd);
19364 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19365 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19366 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19367 install_element(BGP_IPV4L_NODE,
19368 &no_neighbor_nexthop_self_all_hidden_cmd);
19369 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19370 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19371 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19372 install_element(BGP_IPV6_NODE,
19373 &no_neighbor_nexthop_self_all_hidden_cmd);
19374 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19375 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19376 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19377 install_element(BGP_IPV6M_NODE,
19378 &no_neighbor_nexthop_self_all_hidden_cmd);
19379 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19380 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19381 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19382 install_element(BGP_IPV6L_NODE,
19383 &no_neighbor_nexthop_self_all_hidden_cmd);
19384 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19385 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19386 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19387 install_element(BGP_VPNV4_NODE,
19388 &no_neighbor_nexthop_self_all_hidden_cmd);
19389 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19390 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19391 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19392 install_element(BGP_VPNV6_NODE,
19393 &no_neighbor_nexthop_self_all_hidden_cmd);
19394 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19395 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19396
19397 /* "neighbor as-override" commands. */
19398 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19399 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19400 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19401 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19402 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19403 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19404 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19405 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19406 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19407 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19408 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19409 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19410 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19411 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19412 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19413 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19414 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19415 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19416
19417 /* "neighbor remove-private-AS" commands. */
19418 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19419 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19420 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19421 install_element(BGP_NODE,
19422 &no_neighbor_remove_private_as_all_hidden_cmd);
19423 install_element(BGP_NODE,
19424 &neighbor_remove_private_as_replace_as_hidden_cmd);
19425 install_element(BGP_NODE,
19426 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19427 install_element(BGP_NODE,
19428 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19429 install_element(
19430 BGP_NODE,
19431 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19432 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19433 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19434 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19435 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19436 install_element(BGP_IPV4_NODE,
19437 &neighbor_remove_private_as_replace_as_cmd);
19438 install_element(BGP_IPV4_NODE,
19439 &no_neighbor_remove_private_as_replace_as_cmd);
19440 install_element(BGP_IPV4_NODE,
19441 &neighbor_remove_private_as_all_replace_as_cmd);
19442 install_element(BGP_IPV4_NODE,
19443 &no_neighbor_remove_private_as_all_replace_as_cmd);
19444 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19445 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19446 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19447 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19448 install_element(BGP_IPV4M_NODE,
19449 &neighbor_remove_private_as_replace_as_cmd);
19450 install_element(BGP_IPV4M_NODE,
19451 &no_neighbor_remove_private_as_replace_as_cmd);
19452 install_element(BGP_IPV4M_NODE,
19453 &neighbor_remove_private_as_all_replace_as_cmd);
19454 install_element(BGP_IPV4M_NODE,
19455 &no_neighbor_remove_private_as_all_replace_as_cmd);
19456 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19457 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19458 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19459 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19460 install_element(BGP_IPV4L_NODE,
19461 &neighbor_remove_private_as_replace_as_cmd);
19462 install_element(BGP_IPV4L_NODE,
19463 &no_neighbor_remove_private_as_replace_as_cmd);
19464 install_element(BGP_IPV4L_NODE,
19465 &neighbor_remove_private_as_all_replace_as_cmd);
19466 install_element(BGP_IPV4L_NODE,
19467 &no_neighbor_remove_private_as_all_replace_as_cmd);
19468 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19469 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19470 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19471 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19472 install_element(BGP_IPV6_NODE,
19473 &neighbor_remove_private_as_replace_as_cmd);
19474 install_element(BGP_IPV6_NODE,
19475 &no_neighbor_remove_private_as_replace_as_cmd);
19476 install_element(BGP_IPV6_NODE,
19477 &neighbor_remove_private_as_all_replace_as_cmd);
19478 install_element(BGP_IPV6_NODE,
19479 &no_neighbor_remove_private_as_all_replace_as_cmd);
19480 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19481 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19482 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19483 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19484 install_element(BGP_IPV6M_NODE,
19485 &neighbor_remove_private_as_replace_as_cmd);
19486 install_element(BGP_IPV6M_NODE,
19487 &no_neighbor_remove_private_as_replace_as_cmd);
19488 install_element(BGP_IPV6M_NODE,
19489 &neighbor_remove_private_as_all_replace_as_cmd);
19490 install_element(BGP_IPV6M_NODE,
19491 &no_neighbor_remove_private_as_all_replace_as_cmd);
19492 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19493 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19494 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19495 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19496 install_element(BGP_IPV6L_NODE,
19497 &neighbor_remove_private_as_replace_as_cmd);
19498 install_element(BGP_IPV6L_NODE,
19499 &no_neighbor_remove_private_as_replace_as_cmd);
19500 install_element(BGP_IPV6L_NODE,
19501 &neighbor_remove_private_as_all_replace_as_cmd);
19502 install_element(BGP_IPV6L_NODE,
19503 &no_neighbor_remove_private_as_all_replace_as_cmd);
19504 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19505 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19506 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19507 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19508 install_element(BGP_VPNV4_NODE,
19509 &neighbor_remove_private_as_replace_as_cmd);
19510 install_element(BGP_VPNV4_NODE,
19511 &no_neighbor_remove_private_as_replace_as_cmd);
19512 install_element(BGP_VPNV4_NODE,
19513 &neighbor_remove_private_as_all_replace_as_cmd);
19514 install_element(BGP_VPNV4_NODE,
19515 &no_neighbor_remove_private_as_all_replace_as_cmd);
19516 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19517 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19518 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19519 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19520 install_element(BGP_VPNV6_NODE,
19521 &neighbor_remove_private_as_replace_as_cmd);
19522 install_element(BGP_VPNV6_NODE,
19523 &no_neighbor_remove_private_as_replace_as_cmd);
19524 install_element(BGP_VPNV6_NODE,
19525 &neighbor_remove_private_as_all_replace_as_cmd);
19526 install_element(BGP_VPNV6_NODE,
19527 &no_neighbor_remove_private_as_all_replace_as_cmd);
19528
19529 /* "neighbor send-community" commands.*/
19530 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19531 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19532 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19533 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19534 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19535 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19536 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19537 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19538 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19539 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19540 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19541 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19542 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19543 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19544 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19545 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19546 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19547 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19548 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19549 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19550 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19551 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19552 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19553 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19554 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19555 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19556 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19557 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19558 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19559 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19560 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19561 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19562 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19563 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19564 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19565 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19566
19567 /* "neighbor route-reflector" commands.*/
19568 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19569 install_element(BGP_NODE,
19570 &no_neighbor_route_reflector_client_hidden_cmd);
19571 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19572 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19573 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19574 install_element(BGP_IPV4M_NODE,
19575 &no_neighbor_route_reflector_client_cmd);
19576 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19577 install_element(BGP_IPV4L_NODE,
19578 &no_neighbor_route_reflector_client_cmd);
19579 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19580 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19581 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19582 install_element(BGP_IPV6M_NODE,
19583 &no_neighbor_route_reflector_client_cmd);
19584 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19585 install_element(BGP_IPV6L_NODE,
19586 &no_neighbor_route_reflector_client_cmd);
19587 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19588 install_element(BGP_VPNV4_NODE,
19589 &no_neighbor_route_reflector_client_cmd);
19590 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19591 install_element(BGP_VPNV6_NODE,
19592 &no_neighbor_route_reflector_client_cmd);
19593 install_element(BGP_FLOWSPECV4_NODE,
19594 &neighbor_route_reflector_client_cmd);
19595 install_element(BGP_FLOWSPECV4_NODE,
19596 &no_neighbor_route_reflector_client_cmd);
19597 install_element(BGP_FLOWSPECV6_NODE,
19598 &neighbor_route_reflector_client_cmd);
19599 install_element(BGP_FLOWSPECV6_NODE,
19600 &no_neighbor_route_reflector_client_cmd);
19601 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19602 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19603
19604 /* "neighbor route-server" commands.*/
19605 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19606 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19607 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19608 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19609 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19610 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19611 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19612 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19613 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19614 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19615 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19616 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19617 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19618 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19619 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19620 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19621 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19622 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19623 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19624 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19625 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19626 install_element(BGP_FLOWSPECV4_NODE,
19627 &no_neighbor_route_server_client_cmd);
19628 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19629 install_element(BGP_FLOWSPECV6_NODE,
19630 &no_neighbor_route_server_client_cmd);
19631
19632 /* "neighbor disable-addpath-rx" commands. */
19633 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19634 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19635 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19636 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19637 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19638 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19639 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19640 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19641 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19642 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19643 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19644 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19645 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19646 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19647 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19648 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19649
19650 /* "neighbor addpath-tx-all-paths" commands.*/
19651 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19652 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19653 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19654 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19655 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19656 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19657 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19658 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19659 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19660 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19661 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19662 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19663 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19664 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19665 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19666 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19667 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19668 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19669
19670 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19671 install_element(BGP_NODE,
19672 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19673 install_element(BGP_NODE,
19674 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19675 install_element(BGP_IPV4_NODE,
19676 &neighbor_addpath_tx_bestpath_per_as_cmd);
19677 install_element(BGP_IPV4_NODE,
19678 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19679 install_element(BGP_IPV4M_NODE,
19680 &neighbor_addpath_tx_bestpath_per_as_cmd);
19681 install_element(BGP_IPV4M_NODE,
19682 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19683 install_element(BGP_IPV4L_NODE,
19684 &neighbor_addpath_tx_bestpath_per_as_cmd);
19685 install_element(BGP_IPV4L_NODE,
19686 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19687 install_element(BGP_IPV6_NODE,
19688 &neighbor_addpath_tx_bestpath_per_as_cmd);
19689 install_element(BGP_IPV6_NODE,
19690 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19691 install_element(BGP_IPV6M_NODE,
19692 &neighbor_addpath_tx_bestpath_per_as_cmd);
19693 install_element(BGP_IPV6M_NODE,
19694 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19695 install_element(BGP_IPV6L_NODE,
19696 &neighbor_addpath_tx_bestpath_per_as_cmd);
19697 install_element(BGP_IPV6L_NODE,
19698 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19699 install_element(BGP_VPNV4_NODE,
19700 &neighbor_addpath_tx_bestpath_per_as_cmd);
19701 install_element(BGP_VPNV4_NODE,
19702 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19703 install_element(BGP_VPNV6_NODE,
19704 &neighbor_addpath_tx_bestpath_per_as_cmd);
19705 install_element(BGP_VPNV6_NODE,
19706 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19707
19708 /* "neighbor sender-as-path-loop-detection" commands. */
19709 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19710 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19711
19712 /* "neighbor path-attribute discard" commands. */
19713 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19714 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
19715
19716 /* "neighbor path-attribute treat-as-withdraw" commands. */
19717 install_element(BGP_NODE,
19718 &neighbor_path_attribute_treat_as_withdraw_cmd);
19719 install_element(BGP_NODE,
19720 &no_neighbor_path_attribute_treat_as_withdraw_cmd);
19721
19722 /* "neighbor passive" commands. */
19723 install_element(BGP_NODE, &neighbor_passive_cmd);
19724 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19725
19726
19727 /* "neighbor shutdown" commands. */
19728 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19729 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19730 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19731 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19732 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19733 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19734
19735 /* "neighbor capability extended-nexthop" commands.*/
19736 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19737 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19738
19739 /* "neighbor capability software-version" commands.*/
19740 install_element(BGP_NODE, &neighbor_capability_software_version_cmd);
19741
19742 /* "neighbor capability orf prefix-list" commands.*/
19743 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19744 install_element(BGP_NODE,
19745 &no_neighbor_capability_orf_prefix_hidden_cmd);
19746 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19747 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19748 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19749 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19750 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19751 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19752 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19753 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19754 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19755 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19756 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19757 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19758
19759 /* "neighbor capability dynamic" commands.*/
19760 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19761 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19762
19763 /* "neighbor dont-capability-negotiate" commands. */
19764 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19765 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19766
19767 /* "neighbor ebgp-multihop" commands. */
19768 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19769 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19770 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19771
19772 /* "neighbor disable-connected-check" commands. */
19773 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19774 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19775
19776 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19777 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19778 install_element(BGP_NODE,
19779 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19780
19781 /* "neighbor extended-optional-parameters" commands. */
19782 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19783 install_element(BGP_NODE,
19784 &no_neighbor_extended_optional_parameters_cmd);
19785
19786 /* "neighbor enforce-first-as" commands. */
19787 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19788 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19789
19790 /* "neighbor description" commands. */
19791 install_element(BGP_NODE, &neighbor_description_cmd);
19792 install_element(BGP_NODE, &no_neighbor_description_cmd);
19793 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19794
19795 /* "neighbor update-source" commands. "*/
19796 install_element(BGP_NODE, &neighbor_update_source_cmd);
19797 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19798
19799 /* "neighbor default-originate" commands. */
19800 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19801 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19802 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19803 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19804 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19805 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19806 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19807 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19808 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19809 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19810 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19811 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19812 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19813 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19814 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19815 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19816 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19817 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19818 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19819 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19820 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19821
19822 /* "neighbor port" commands. */
19823 install_element(BGP_NODE, &neighbor_port_cmd);
19824 install_element(BGP_NODE, &no_neighbor_port_cmd);
19825
19826 /* "neighbor weight" commands. */
19827 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19828 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19829
19830 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19831 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19832 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19833 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19834 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19835 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19836 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19837 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19838 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19839 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19840 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19841 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19842 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19843 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19844 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19845 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19846
19847 /* "neighbor override-capability" commands. */
19848 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19849 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19850
19851 /* "neighbor strict-capability-match" commands. */
19852 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19853 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19854
19855 /* "neighbor timers" commands. */
19856 install_element(BGP_NODE, &neighbor_timers_cmd);
19857 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19858
19859 /* "neighbor timers connect" commands. */
19860 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19861 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19862
19863 /* "neighbor timers delayopen" commands. */
19864 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19865 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19866
19867 /* "neighbor advertisement-interval" commands. */
19868 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19869 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19870
19871 /* "neighbor interface" commands. */
19872 install_element(BGP_NODE, &neighbor_interface_cmd);
19873 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19874
19875 /* "neighbor distribute" commands. */
19876 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19877 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19878 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19879 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19880 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19881 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19882 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19883 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19884 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19885 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19886 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19887 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19888 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19889 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19890 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19891 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19892 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19893 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19894
19895 /* "neighbor prefix-list" commands. */
19896 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19897 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19898 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19899 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19900 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19901 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19902 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19903 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19904 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19905 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19906 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19907 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19908 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19909 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19910 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19911 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19912 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19913 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19914 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19915 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19916 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19917 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19918
19919 /* "neighbor filter-list" commands. */
19920 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19921 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19922 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19923 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19924 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19925 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19926 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19927 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19928 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19929 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19930 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19931 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19932 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19933 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19934 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19935 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19936 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19937 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19938 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19939 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19940 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19941 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19942
19943 /* "neighbor route-map" commands. */
19944 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19945 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19946 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19947 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19948 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19949 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19950 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19951 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19952 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19953 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19954 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19955 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19956 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19957 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19958 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19959 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19960 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19961 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19962 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19963 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19964 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19965 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19966 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19967 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19968
19969 /* "neighbor unsuppress-map" commands. */
19970 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19971 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19972 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19973 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19974 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19975 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19976 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19977 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19978 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19979 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19980 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19981 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19982 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19983 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19984 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19985 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19986 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19987 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19988
19989 /* "neighbor advertise-map" commands. */
19990 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19991 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19992 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19993 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19994 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19995 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19996 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19997 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19998 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19999 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
20000
20001 /* neighbor maximum-prefix-out commands. */
20002 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
20003 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
20004 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
20005 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20006 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
20007 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20008 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
20009 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20010 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
20011 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20012 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
20013 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
20014 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
20015 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20016 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
20017 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20018 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
20019 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20020
20021 /* "neighbor maximum-prefix" commands. */
20022 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
20023 install_element(BGP_NODE,
20024 &neighbor_maximum_prefix_threshold_hidden_cmd);
20025 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
20026 install_element(BGP_NODE,
20027 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
20028 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
20029 install_element(BGP_NODE,
20030 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
20031 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
20032 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
20033 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20034 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20035 install_element(BGP_IPV4_NODE,
20036 &neighbor_maximum_prefix_threshold_warning_cmd);
20037 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20038 install_element(BGP_IPV4_NODE,
20039 &neighbor_maximum_prefix_threshold_restart_cmd);
20040 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
20041 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
20042 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20043 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
20044 install_element(BGP_IPV4M_NODE,
20045 &neighbor_maximum_prefix_threshold_warning_cmd);
20046 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
20047 install_element(BGP_IPV4M_NODE,
20048 &neighbor_maximum_prefix_threshold_restart_cmd);
20049 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
20050 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
20051 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20052 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
20053 install_element(BGP_IPV4L_NODE,
20054 &neighbor_maximum_prefix_threshold_warning_cmd);
20055 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
20056 install_element(BGP_IPV4L_NODE,
20057 &neighbor_maximum_prefix_threshold_restart_cmd);
20058 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
20059 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
20060 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20061 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20062 install_element(BGP_IPV6_NODE,
20063 &neighbor_maximum_prefix_threshold_warning_cmd);
20064 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20065 install_element(BGP_IPV6_NODE,
20066 &neighbor_maximum_prefix_threshold_restart_cmd);
20067 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
20068 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
20069 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20070 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
20071 install_element(BGP_IPV6M_NODE,
20072 &neighbor_maximum_prefix_threshold_warning_cmd);
20073 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
20074 install_element(BGP_IPV6M_NODE,
20075 &neighbor_maximum_prefix_threshold_restart_cmd);
20076 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
20077 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
20078 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20079 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
20080 install_element(BGP_IPV6L_NODE,
20081 &neighbor_maximum_prefix_threshold_warning_cmd);
20082 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
20083 install_element(BGP_IPV6L_NODE,
20084 &neighbor_maximum_prefix_threshold_restart_cmd);
20085 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20086 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20087 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20088 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20089 install_element(BGP_VPNV4_NODE,
20090 &neighbor_maximum_prefix_threshold_warning_cmd);
20091 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20092 install_element(BGP_VPNV4_NODE,
20093 &neighbor_maximum_prefix_threshold_restart_cmd);
20094 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20095 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20096 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20097 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20098 install_element(BGP_VPNV6_NODE,
20099 &neighbor_maximum_prefix_threshold_warning_cmd);
20100 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20101 install_element(BGP_VPNV6_NODE,
20102 &neighbor_maximum_prefix_threshold_restart_cmd);
20103 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20104
20105 /* "neighbor allowas-in" */
20106 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20107 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20108 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20109 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20110 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20111 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20112 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20113 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20114 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20115 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20116 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20117 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20118 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20119 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20120 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20121 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20122 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20123 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20124 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20125 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20126
20127 /* neighbor accept-own */
20128 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20129 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20130
20131 /* "neighbor soo" */
20132 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20133 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20134 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20135 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20136 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20137 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20138 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20139 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20140 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20141 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20142 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20143 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20144 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20145 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20146 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20147 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20148 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20149 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20150
20151 /* address-family commands. */
20152 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20153 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
20154 #ifdef KEEP_OLD_VPN_COMMANDS
20155 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20156 install_element(BGP_NODE, &address_family_vpnv6_cmd);
20157 #endif /* KEEP_OLD_VPN_COMMANDS */
20158
20159 install_element(BGP_NODE, &address_family_evpn_cmd);
20160
20161 /* "exit-address-family" command. */
20162 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20163 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20164 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20165 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20166 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20167 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20168 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20169 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
20170 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20171 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
20172 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20173
20174 /* BGP retain all route-target */
20175 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20176 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20177
20178 /* "clear ip bgp commands" */
20179 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20180
20181 /* clear ip bgp prefix */
20182 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20183 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20184 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20185
20186 /* "show [ip] bgp summary" commands. */
20187 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20188 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20189 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20190 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20191 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20192 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20193 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20194
20195 /* "show [ip] bgp neighbors" commands. */
20196 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20197
20198 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20199
20200 /* "show [ip] bgp peer-group" commands. */
20201 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20202
20203 /* "show [ip] bgp paths" commands. */
20204 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20205
20206 /* "show [ip] bgp community" commands. */
20207 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20208
20209 /* "show ip bgp large-community" commands. */
20210 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20211 /* "show [ip] bgp attribute-info" commands. */
20212 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20213 /* "show [ip] bgp route-leak" command */
20214 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20215
20216 /* "redistribute" commands. */
20217 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20218 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20219 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20220 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20221 install_element(BGP_NODE,
20222 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20223 install_element(BGP_NODE,
20224 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20225 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20226 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20227 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20228 install_element(BGP_NODE,
20229 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20230 install_element(BGP_NODE,
20231 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20232 install_element(BGP_NODE,
20233 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20234 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20235 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20236 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20237 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20238 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20239 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20240 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20241 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20242 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20243 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20244 install_element(BGP_IPV4_NODE,
20245 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20246 install_element(BGP_IPV4_NODE,
20247 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20248 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20249 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20250 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20251 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20252 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20253 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20254
20255 /* import|export vpn [route-map RMAP_NAME] */
20256 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20257 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20258
20259 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20260 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20261
20262 /* ttl_security commands */
20263 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20264 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20265
20266 /* "bgp tcp-keepalive" commands */
20267 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20268 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20269
20270 /* "show [ip] bgp memory" commands. */
20271 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20272
20273 /* "show bgp martian next-hop" */
20274 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20275
20276 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20277
20278 /* "show [ip] bgp views" commands. */
20279 install_element(VIEW_NODE, &show_bgp_views_cmd);
20280
20281 /* "show [ip] bgp vrfs" commands. */
20282 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20283
20284 /* Community-list. */
20285 community_list_vty();
20286
20287 community_alias_vty();
20288
20289 /* vpn-policy commands */
20290 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20291 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20292 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20293 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20294 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20295 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20296 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20297 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20298 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20299 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20300 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20301 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20302
20303 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20304 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20305
20306 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20307 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20308 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20309 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20310 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20311 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20312 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20313 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20314 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20315 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20316
20317 /* tcp-mss command */
20318 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20319 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20320
20321 /* srv6 commands */
20322 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20323 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20324 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20325 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20326 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20327 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20328 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20329 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20330 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20331
20332 bgp_vty_if_init();
20333 }
20334
20335 #include "memory.h"
20336 #include "bgp_regex.h"
20337 #include "bgp_clist.h"
20338 #include "bgp_ecommunity.h"
20339
20340 /* VTY functions. */
20341
20342 /* Direction value to string conversion. */
20343 static const char *community_direct_str(int direct)
20344 {
20345 switch (direct) {
20346 case COMMUNITY_DENY:
20347 return "deny";
20348 case COMMUNITY_PERMIT:
20349 return "permit";
20350 default:
20351 return "unknown";
20352 }
20353 }
20354
20355 /* Display error string. */
20356 static void community_list_perror(struct vty *vty, int ret)
20357 {
20358 switch (ret) {
20359 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20360 vty_out(vty, "%% Can't find community-list\n");
20361 break;
20362 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20363 vty_out(vty, "%% Malformed community-list value\n");
20364 break;
20365 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20366 vty_out(vty,
20367 "%% Community name conflict, previously defined as standard community\n");
20368 break;
20369 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20370 vty_out(vty,
20371 "%% Community name conflict, previously defined as expanded community\n");
20372 break;
20373 }
20374 }
20375
20376 /* "community-list" keyword help string. */
20377 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20378
20379 /*community-list standard */
20380 DEFUN (community_list_standard,
20381 bgp_community_list_standard_cmd,
20382 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20383 BGP_STR
20384 COMMUNITY_LIST_STR
20385 "Community list number (standard)\n"
20386 "Add an standard community-list entry\n"
20387 "Community list name\n"
20388 "Sequence number of an entry\n"
20389 "Sequence number\n"
20390 "Specify community to reject\n"
20391 "Specify community to accept\n"
20392 COMMUNITY_VAL_STR)
20393 {
20394 char *cl_name_or_number = NULL;
20395 char *seq = NULL;
20396 int direct = 0;
20397 int style = COMMUNITY_LIST_STANDARD;
20398 int idx = 0;
20399
20400 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20401 seq = argv[idx]->arg;
20402
20403 idx = 0;
20404 argv_find(argv, argc, "(1-99)", &idx);
20405 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20406 cl_name_or_number = argv[idx]->arg;
20407 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20408 : COMMUNITY_DENY;
20409 argv_find(argv, argc, "AA:NN", &idx);
20410 char *str = argv_concat(argv, argc, idx);
20411
20412 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20413 direct, style);
20414
20415 XFREE(MTYPE_TMP, str);
20416
20417 if (ret < 0) {
20418 /* Display error string. */
20419 community_list_perror(vty, ret);
20420 return CMD_WARNING_CONFIG_FAILED;
20421 }
20422
20423 return CMD_SUCCESS;
20424 }
20425
20426 DEFUN (no_community_list_standard_all,
20427 no_bgp_community_list_standard_all_cmd,
20428 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20429 NO_STR
20430 BGP_STR
20431 COMMUNITY_LIST_STR
20432 "Community list number (standard)\n"
20433 "Add an standard community-list entry\n"
20434 "Community list name\n"
20435 "Sequence number of an entry\n"
20436 "Sequence number\n"
20437 "Specify community to reject\n"
20438 "Specify community to accept\n"
20439 COMMUNITY_VAL_STR)
20440 {
20441 char *cl_name_or_number = NULL;
20442 char *str = NULL;
20443 int direct = 0;
20444 int style = COMMUNITY_LIST_STANDARD;
20445 char *seq = NULL;
20446 int idx = 0;
20447
20448 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20449 seq = argv[idx]->arg;
20450
20451 idx = 0;
20452 argv_find(argv, argc, "permit", &idx);
20453 argv_find(argv, argc, "deny", &idx);
20454
20455 if (idx) {
20456 direct = argv_find(argv, argc, "permit", &idx)
20457 ? COMMUNITY_PERMIT
20458 : COMMUNITY_DENY;
20459
20460 idx = 0;
20461 argv_find(argv, argc, "AA:NN", &idx);
20462 str = argv_concat(argv, argc, idx);
20463 }
20464
20465 idx = 0;
20466 argv_find(argv, argc, "(1-99)", &idx);
20467 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20468 cl_name_or_number = argv[idx]->arg;
20469
20470 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20471 direct, style);
20472
20473 XFREE(MTYPE_TMP, str);
20474
20475 if (ret < 0) {
20476 community_list_perror(vty, ret);
20477 return CMD_WARNING_CONFIG_FAILED;
20478 }
20479
20480 return CMD_SUCCESS;
20481 }
20482
20483 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20484 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20485 NO_STR BGP_STR COMMUNITY_LIST_STR
20486 "Community list number (standard)\n"
20487 "Add an standard community-list entry\n"
20488 "Community list name\n")
20489
20490 /*community-list expanded */
20491 DEFUN (community_list_expanded_all,
20492 bgp_community_list_expanded_all_cmd,
20493 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20494 BGP_STR
20495 COMMUNITY_LIST_STR
20496 "Community list number (expanded)\n"
20497 "Add an expanded community-list entry\n"
20498 "Community list name\n"
20499 "Sequence number of an entry\n"
20500 "Sequence number\n"
20501 "Specify community to reject\n"
20502 "Specify community to accept\n"
20503 COMMUNITY_VAL_STR)
20504 {
20505 char *cl_name_or_number = NULL;
20506 char *seq = NULL;
20507 int direct = 0;
20508 int style = COMMUNITY_LIST_EXPANDED;
20509 int idx = 0;
20510
20511 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20512 seq = argv[idx]->arg;
20513
20514 idx = 0;
20515
20516 argv_find(argv, argc, "(100-500)", &idx);
20517 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20518 cl_name_or_number = argv[idx]->arg;
20519 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20520 : COMMUNITY_DENY;
20521 argv_find(argv, argc, "AA:NN", &idx);
20522 char *str = argv_concat(argv, argc, idx);
20523
20524 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20525 direct, style);
20526
20527 XFREE(MTYPE_TMP, str);
20528
20529 if (ret < 0) {
20530 /* Display error string. */
20531 community_list_perror(vty, ret);
20532 return CMD_WARNING_CONFIG_FAILED;
20533 }
20534
20535 return CMD_SUCCESS;
20536 }
20537
20538 DEFUN (no_community_list_expanded_all,
20539 no_bgp_community_list_expanded_all_cmd,
20540 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20541 NO_STR
20542 BGP_STR
20543 COMMUNITY_LIST_STR
20544 "Community list number (expanded)\n"
20545 "Add an expanded community-list entry\n"
20546 "Community list name\n"
20547 "Sequence number of an entry\n"
20548 "Sequence number\n"
20549 "Specify community to reject\n"
20550 "Specify community to accept\n"
20551 COMMUNITY_VAL_STR)
20552 {
20553 char *cl_name_or_number = NULL;
20554 char *seq = NULL;
20555 char *str = NULL;
20556 int direct = 0;
20557 int style = COMMUNITY_LIST_EXPANDED;
20558 int idx = 0;
20559
20560 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20561 seq = argv[idx]->arg;
20562
20563 idx = 0;
20564 argv_find(argv, argc, "permit", &idx);
20565 argv_find(argv, argc, "deny", &idx);
20566
20567 if (idx) {
20568 direct = argv_find(argv, argc, "permit", &idx)
20569 ? COMMUNITY_PERMIT
20570 : COMMUNITY_DENY;
20571
20572 idx = 0;
20573 argv_find(argv, argc, "AA:NN", &idx);
20574 str = argv_concat(argv, argc, idx);
20575 }
20576
20577 idx = 0;
20578 argv_find(argv, argc, "(100-500)", &idx);
20579 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20580 cl_name_or_number = argv[idx]->arg;
20581
20582 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20583 direct, style);
20584
20585 XFREE(MTYPE_TMP, str);
20586
20587 if (ret < 0) {
20588 community_list_perror(vty, ret);
20589 return CMD_WARNING_CONFIG_FAILED;
20590 }
20591
20592 return CMD_SUCCESS;
20593 }
20594
20595 ALIAS(no_community_list_expanded_all,
20596 no_bgp_community_list_expanded_all_list_cmd,
20597 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20598 NO_STR BGP_STR COMMUNITY_LIST_STR
20599 "Community list number (expanded)\n"
20600 "Add an expanded community-list entry\n"
20601 "Community list name\n")
20602
20603 /* Return configuration string of community-list entry. */
20604 static const char *community_list_config_str(struct community_entry *entry)
20605 {
20606 const char *str;
20607
20608 if (entry->any)
20609 str = "";
20610 else {
20611 if (entry->style == COMMUNITY_LIST_STANDARD)
20612 str = community_str(entry->u.com, false, false);
20613 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20614 str = lcommunity_str(entry->u.lcom, false, false);
20615 else
20616 str = entry->config;
20617 }
20618 return str;
20619 }
20620
20621 static void community_list_show(struct vty *vty, struct community_list *list)
20622 {
20623 struct community_entry *entry;
20624
20625 for (entry = list->head; entry; entry = entry->next) {
20626 if (entry == list->head) {
20627 if (all_digit(list->name))
20628 vty_out(vty, "Community %s list %s\n",
20629 entry->style == COMMUNITY_LIST_STANDARD
20630 ? "standard"
20631 : "(expanded) access",
20632 list->name);
20633 else
20634 vty_out(vty, "Named Community %s list %s\n",
20635 entry->style == COMMUNITY_LIST_STANDARD
20636 ? "standard"
20637 : "expanded",
20638 list->name);
20639 }
20640 if (entry->any)
20641 vty_out(vty, " %s\n",
20642 community_direct_str(entry->direct));
20643 else
20644 vty_out(vty, " %s %s\n",
20645 community_direct_str(entry->direct),
20646 community_list_config_str(entry));
20647 }
20648 }
20649
20650 DEFUN (show_community_list,
20651 show_bgp_community_list_cmd,
20652 "show bgp community-list",
20653 SHOW_STR
20654 BGP_STR
20655 "List community-list\n")
20656 {
20657 struct community_list *list;
20658 struct community_list_master *cm;
20659
20660 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20661 if (!cm)
20662 return CMD_SUCCESS;
20663
20664 for (list = cm->num.head; list; list = list->next)
20665 community_list_show(vty, list);
20666
20667 for (list = cm->str.head; list; list = list->next)
20668 community_list_show(vty, list);
20669
20670 return CMD_SUCCESS;
20671 }
20672
20673 DEFUN (show_community_list_arg,
20674 show_bgp_community_list_arg_cmd,
20675 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20676 SHOW_STR
20677 BGP_STR
20678 "List community-list\n"
20679 "Community-list number\n"
20680 "Community-list name\n"
20681 "Detailed information on community-list\n")
20682 {
20683 int idx_comm_list = 3;
20684 struct community_list *list;
20685
20686 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20687 COMMUNITY_LIST_MASTER);
20688 if (!list) {
20689 vty_out(vty, "%% Can't find community-list\n");
20690 return CMD_WARNING;
20691 }
20692
20693 community_list_show(vty, list);
20694
20695 return CMD_SUCCESS;
20696 }
20697
20698 /*
20699 * Large Community code.
20700 */
20701 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20702 struct cmd_token **argv, int style,
20703 int reject_all_digit_name)
20704 {
20705 int ret;
20706 int direct;
20707 char *str;
20708 int idx = 0;
20709 char *cl_name;
20710 char *seq = NULL;
20711
20712 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20713 seq = argv[idx]->arg;
20714
20715 idx = 0;
20716 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20717 : COMMUNITY_DENY;
20718
20719 /* All digit name check. */
20720 idx = 0;
20721 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20722 argv_find(argv, argc, "(1-99)", &idx);
20723 argv_find(argv, argc, "(100-500)", &idx);
20724 cl_name = argv[idx]->arg;
20725 if (reject_all_digit_name && all_digit(cl_name)) {
20726 vty_out(vty, "%% Community name cannot have all digits\n");
20727 return CMD_WARNING_CONFIG_FAILED;
20728 }
20729
20730 idx = 0;
20731 argv_find(argv, argc, "AA:BB:CC", &idx);
20732 argv_find(argv, argc, "LINE", &idx);
20733 /* Concat community string argument. */
20734 if (idx)
20735 str = argv_concat(argv, argc, idx);
20736 else
20737 str = NULL;
20738
20739 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20740
20741 /* Free temporary community list string allocated by
20742 argv_concat(). */
20743 XFREE(MTYPE_TMP, str);
20744
20745 if (ret < 0) {
20746 community_list_perror(vty, ret);
20747 return CMD_WARNING_CONFIG_FAILED;
20748 }
20749 return CMD_SUCCESS;
20750 }
20751
20752 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20753 struct cmd_token **argv, int style)
20754 {
20755 int ret;
20756 int direct = 0;
20757 char *str = NULL;
20758 int idx = 0;
20759 char *seq = NULL;
20760
20761 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20762 seq = argv[idx]->arg;
20763
20764 idx = 0;
20765 argv_find(argv, argc, "permit", &idx);
20766 argv_find(argv, argc, "deny", &idx);
20767
20768 if (idx) {
20769 /* Check the list direct. */
20770 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20771 direct = COMMUNITY_PERMIT;
20772 else
20773 direct = COMMUNITY_DENY;
20774
20775 idx = 0;
20776 argv_find(argv, argc, "LINE", &idx);
20777 argv_find(argv, argc, "AA:AA:NN", &idx);
20778 /* Concat community string argument. */
20779 str = argv_concat(argv, argc, idx);
20780 }
20781
20782 idx = 0;
20783 argv_find(argv, argc, "(1-99)", &idx);
20784 argv_find(argv, argc, "(100-500)", &idx);
20785 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20786
20787 /* Unset community list. */
20788 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20789 style);
20790
20791 /* Free temporary community list string allocated by
20792 argv_concat(). */
20793 XFREE(MTYPE_TMP, str);
20794
20795 if (ret < 0) {
20796 community_list_perror(vty, ret);
20797 return CMD_WARNING_CONFIG_FAILED;
20798 }
20799
20800 return CMD_SUCCESS;
20801 }
20802
20803 /* "large-community-list" keyword help string. */
20804 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20805 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20806
20807 DEFUN (lcommunity_list_standard,
20808 bgp_lcommunity_list_standard_cmd,
20809 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20810 BGP_STR
20811 LCOMMUNITY_LIST_STR
20812 "Large Community list number (standard)\n"
20813 "Sequence number of an entry\n"
20814 "Sequence number\n"
20815 "Specify large community to reject\n"
20816 "Specify large community to accept\n"
20817 LCOMMUNITY_VAL_STR)
20818 {
20819 return lcommunity_list_set_vty(vty, argc, argv,
20820 LARGE_COMMUNITY_LIST_STANDARD, 0);
20821 }
20822
20823 DEFUN (lcommunity_list_expanded,
20824 bgp_lcommunity_list_expanded_cmd,
20825 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20826 BGP_STR
20827 LCOMMUNITY_LIST_STR
20828 "Large Community list number (expanded)\n"
20829 "Sequence number of an entry\n"
20830 "Sequence number\n"
20831 "Specify large community to reject\n"
20832 "Specify large community to accept\n"
20833 "An ordered list as a regular-expression\n")
20834 {
20835 return lcommunity_list_set_vty(vty, argc, argv,
20836 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20837 }
20838
20839 DEFUN (lcommunity_list_name_standard,
20840 bgp_lcommunity_list_name_standard_cmd,
20841 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20842 BGP_STR
20843 LCOMMUNITY_LIST_STR
20844 "Specify standard large-community-list\n"
20845 "Large Community list name\n"
20846 "Sequence number of an entry\n"
20847 "Sequence number\n"
20848 "Specify large community to reject\n"
20849 "Specify large community to accept\n"
20850 LCOMMUNITY_VAL_STR)
20851 {
20852 return lcommunity_list_set_vty(vty, argc, argv,
20853 LARGE_COMMUNITY_LIST_STANDARD, 1);
20854 }
20855
20856 DEFUN (lcommunity_list_name_expanded,
20857 bgp_lcommunity_list_name_expanded_cmd,
20858 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20859 BGP_STR
20860 LCOMMUNITY_LIST_STR
20861 "Specify expanded large-community-list\n"
20862 "Large Community list name\n"
20863 "Sequence number of an entry\n"
20864 "Sequence number\n"
20865 "Specify large community to reject\n"
20866 "Specify large community to accept\n"
20867 "An ordered list as a regular-expression\n")
20868 {
20869 return lcommunity_list_set_vty(vty, argc, argv,
20870 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20871 }
20872
20873 DEFUN (no_lcommunity_list_all,
20874 no_bgp_lcommunity_list_all_cmd,
20875 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20876 NO_STR
20877 BGP_STR
20878 LCOMMUNITY_LIST_STR
20879 "Large Community list number (standard)\n"
20880 "Large Community list number (expanded)\n"
20881 "Large Community list name\n")
20882 {
20883 return lcommunity_list_unset_vty(vty, argc, argv,
20884 LARGE_COMMUNITY_LIST_STANDARD);
20885 }
20886
20887 DEFUN (no_lcommunity_list_name_standard_all,
20888 no_bgp_lcommunity_list_name_standard_all_cmd,
20889 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20890 NO_STR
20891 BGP_STR
20892 LCOMMUNITY_LIST_STR
20893 "Specify standard large-community-list\n"
20894 "Large Community list name\n")
20895 {
20896 return lcommunity_list_unset_vty(vty, argc, argv,
20897 LARGE_COMMUNITY_LIST_STANDARD);
20898 }
20899
20900 DEFUN (no_lcommunity_list_name_expanded_all,
20901 no_bgp_lcommunity_list_name_expanded_all_cmd,
20902 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20903 NO_STR
20904 BGP_STR
20905 LCOMMUNITY_LIST_STR
20906 "Specify expanded large-community-list\n"
20907 "Large Community list name\n")
20908 {
20909 return lcommunity_list_unset_vty(vty, argc, argv,
20910 LARGE_COMMUNITY_LIST_EXPANDED);
20911 }
20912
20913 DEFUN (no_lcommunity_list_standard,
20914 no_bgp_lcommunity_list_standard_cmd,
20915 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20916 NO_STR
20917 BGP_STR
20918 LCOMMUNITY_LIST_STR
20919 "Large Community list number (standard)\n"
20920 "Sequence number of an entry\n"
20921 "Sequence number\n"
20922 "Specify large community to reject\n"
20923 "Specify large community to accept\n"
20924 LCOMMUNITY_VAL_STR)
20925 {
20926 return lcommunity_list_unset_vty(vty, argc, argv,
20927 LARGE_COMMUNITY_LIST_STANDARD);
20928 }
20929
20930 DEFUN (no_lcommunity_list_expanded,
20931 no_bgp_lcommunity_list_expanded_cmd,
20932 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20933 NO_STR
20934 BGP_STR
20935 LCOMMUNITY_LIST_STR
20936 "Large Community list number (expanded)\n"
20937 "Sequence number of an entry\n"
20938 "Sequence number\n"
20939 "Specify large community to reject\n"
20940 "Specify large community to accept\n"
20941 "An ordered list as a regular-expression\n")
20942 {
20943 return lcommunity_list_unset_vty(vty, argc, argv,
20944 LARGE_COMMUNITY_LIST_EXPANDED);
20945 }
20946
20947 DEFUN (no_lcommunity_list_name_standard,
20948 no_bgp_lcommunity_list_name_standard_cmd,
20949 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20950 NO_STR
20951 BGP_STR
20952 LCOMMUNITY_LIST_STR
20953 "Specify standard large-community-list\n"
20954 "Large Community list name\n"
20955 "Sequence number of an entry\n"
20956 "Sequence number\n"
20957 "Specify large community to reject\n"
20958 "Specify large community to accept\n"
20959 LCOMMUNITY_VAL_STR)
20960 {
20961 return lcommunity_list_unset_vty(vty, argc, argv,
20962 LARGE_COMMUNITY_LIST_STANDARD);
20963 }
20964
20965 DEFUN (no_lcommunity_list_name_expanded,
20966 no_bgp_lcommunity_list_name_expanded_cmd,
20967 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20968 NO_STR
20969 BGP_STR
20970 LCOMMUNITY_LIST_STR
20971 "Specify expanded 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 "An ordered list as a regular-expression\n")
20978 {
20979 return lcommunity_list_unset_vty(vty, argc, argv,
20980 LARGE_COMMUNITY_LIST_EXPANDED);
20981 }
20982
20983 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20984 {
20985 struct community_entry *entry;
20986
20987 for (entry = list->head; entry; entry = entry->next) {
20988 if (entry == list->head) {
20989 if (all_digit(list->name))
20990 vty_out(vty, "Large community %s list %s\n",
20991 entry->style ==
20992 LARGE_COMMUNITY_LIST_STANDARD
20993 ? "standard"
20994 : "(expanded) access",
20995 list->name);
20996 else
20997 vty_out(vty,
20998 "Named large community %s list %s\n",
20999 entry->style ==
21000 LARGE_COMMUNITY_LIST_STANDARD
21001 ? "standard"
21002 : "expanded",
21003 list->name);
21004 }
21005 if (entry->any)
21006 vty_out(vty, " %s\n",
21007 community_direct_str(entry->direct));
21008 else
21009 vty_out(vty, " %s %s\n",
21010 community_direct_str(entry->direct),
21011 community_list_config_str(entry));
21012 }
21013 }
21014
21015 DEFUN (show_lcommunity_list,
21016 show_bgp_lcommunity_list_cmd,
21017 "show bgp large-community-list",
21018 SHOW_STR
21019 BGP_STR
21020 "List large-community list\n")
21021 {
21022 struct community_list *list;
21023 struct community_list_master *cm;
21024
21025 cm = community_list_master_lookup(bgp_clist,
21026 LARGE_COMMUNITY_LIST_MASTER);
21027 if (!cm)
21028 return CMD_SUCCESS;
21029
21030 for (list = cm->num.head; list; list = list->next)
21031 lcommunity_list_show(vty, list);
21032
21033 for (list = cm->str.head; list; list = list->next)
21034 lcommunity_list_show(vty, list);
21035
21036 return CMD_SUCCESS;
21037 }
21038
21039 DEFUN (show_lcommunity_list_arg,
21040 show_bgp_lcommunity_list_arg_cmd,
21041 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
21042 SHOW_STR
21043 BGP_STR
21044 "List large-community list\n"
21045 "Large-community-list number\n"
21046 "Large-community-list name\n"
21047 "Detailed information on large-community-list\n")
21048 {
21049 struct community_list *list;
21050
21051 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
21052 LARGE_COMMUNITY_LIST_MASTER);
21053 if (!list) {
21054 vty_out(vty, "%% Can't find large-community-list\n");
21055 return CMD_WARNING;
21056 }
21057
21058 lcommunity_list_show(vty, list);
21059
21060 return CMD_SUCCESS;
21061 }
21062
21063 /* "extcommunity-list" keyword help string. */
21064 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
21065 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
21066
21067 DEFUN (extcommunity_list_standard,
21068 bgp_extcommunity_list_standard_cmd,
21069 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21070 BGP_STR
21071 EXTCOMMUNITY_LIST_STR
21072 "Extended Community list number (standard)\n"
21073 "Specify standard extcommunity-list\n"
21074 "Community list name\n"
21075 "Sequence number of an entry\n"
21076 "Sequence number\n"
21077 "Specify community to reject\n"
21078 "Specify community to accept\n"
21079 EXTCOMMUNITY_VAL_STR)
21080 {
21081 int style = EXTCOMMUNITY_LIST_STANDARD;
21082 int direct = 0;
21083 char *cl_number_or_name = NULL;
21084 char *seq = NULL;
21085
21086 int idx = 0;
21087
21088 argv_find(argv, argc, "(1-99)", &idx);
21089 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21090 cl_number_or_name = argv[idx]->arg;
21091
21092 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21093 seq = argv[idx]->arg;
21094
21095 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21096 : COMMUNITY_DENY;
21097 argv_find(argv, argc, "AA:NN", &idx);
21098 char *str = argv_concat(argv, argc, idx);
21099
21100 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21101 direct, style);
21102
21103 XFREE(MTYPE_TMP, str);
21104
21105 if (ret < 0) {
21106 community_list_perror(vty, ret);
21107 return CMD_WARNING_CONFIG_FAILED;
21108 }
21109
21110 return CMD_SUCCESS;
21111 }
21112
21113 DEFUN (extcommunity_list_name_expanded,
21114 bgp_extcommunity_list_name_expanded_cmd,
21115 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21116 BGP_STR
21117 EXTCOMMUNITY_LIST_STR
21118 "Extended Community list number (expanded)\n"
21119 "Specify expanded extcommunity-list\n"
21120 "Extended Community list name\n"
21121 "Sequence number of an entry\n"
21122 "Sequence number\n"
21123 "Specify community to reject\n"
21124 "Specify community to accept\n"
21125 "An ordered list as a regular-expression\n")
21126 {
21127 int style = EXTCOMMUNITY_LIST_EXPANDED;
21128 int direct = 0;
21129 char *cl_number_or_name = NULL;
21130 char *seq = NULL;
21131 int idx = 0;
21132
21133 argv_find(argv, argc, "(100-500)", &idx);
21134 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21135 cl_number_or_name = argv[idx]->arg;
21136
21137 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21138 seq = argv[idx]->arg;
21139
21140 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21141 : COMMUNITY_DENY;
21142 argv_find(argv, argc, "LINE", &idx);
21143 char *str = argv_concat(argv, argc, idx);
21144
21145 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21146 direct, style);
21147
21148 XFREE(MTYPE_TMP, str);
21149
21150 if (ret < 0) {
21151 community_list_perror(vty, ret);
21152 return CMD_WARNING_CONFIG_FAILED;
21153 }
21154
21155 return CMD_SUCCESS;
21156 }
21157
21158 DEFUN (no_extcommunity_list_standard_all,
21159 no_bgp_extcommunity_list_standard_all_cmd,
21160 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21161 NO_STR
21162 BGP_STR
21163 EXTCOMMUNITY_LIST_STR
21164 "Extended Community list number (standard)\n"
21165 "Specify standard extcommunity-list\n"
21166 "Community list name\n"
21167 "Sequence number of an entry\n"
21168 "Sequence number\n"
21169 "Specify community to reject\n"
21170 "Specify community to accept\n"
21171 EXTCOMMUNITY_VAL_STR)
21172 {
21173 int style = EXTCOMMUNITY_LIST_STANDARD;
21174 int direct = 0;
21175 char *cl_number_or_name = NULL;
21176 char *str = NULL;
21177 char *seq = NULL;
21178 int idx = 0;
21179
21180 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21181 seq = argv[idx]->arg;
21182
21183 idx = 0;
21184 argv_find(argv, argc, "permit", &idx);
21185 argv_find(argv, argc, "deny", &idx);
21186 if (idx) {
21187 direct = argv_find(argv, argc, "permit", &idx)
21188 ? COMMUNITY_PERMIT
21189 : COMMUNITY_DENY;
21190
21191 idx = 0;
21192 argv_find(argv, argc, "AA:NN", &idx);
21193 str = argv_concat(argv, argc, idx);
21194 }
21195
21196 idx = 0;
21197 argv_find(argv, argc, "(1-99)", &idx);
21198 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21199 cl_number_or_name = argv[idx]->arg;
21200
21201 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21202 seq, direct, style);
21203
21204 XFREE(MTYPE_TMP, str);
21205
21206 if (ret < 0) {
21207 community_list_perror(vty, ret);
21208 return CMD_WARNING_CONFIG_FAILED;
21209 }
21210
21211 return CMD_SUCCESS;
21212 }
21213
21214 ALIAS(no_extcommunity_list_standard_all,
21215 no_bgp_extcommunity_list_standard_all_list_cmd,
21216 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21217 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21218 "Extended Community list number (standard)\n"
21219 "Specify standard extcommunity-list\n"
21220 "Community list name\n")
21221
21222 DEFUN (no_extcommunity_list_expanded_all,
21223 no_bgp_extcommunity_list_expanded_all_cmd,
21224 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21225 NO_STR
21226 BGP_STR
21227 EXTCOMMUNITY_LIST_STR
21228 "Extended Community list number (expanded)\n"
21229 "Specify expanded extcommunity-list\n"
21230 "Extended Community list name\n"
21231 "Sequence number of an entry\n"
21232 "Sequence number\n"
21233 "Specify community to reject\n"
21234 "Specify community to accept\n"
21235 "An ordered list as a regular-expression\n")
21236 {
21237 int style = EXTCOMMUNITY_LIST_EXPANDED;
21238 int direct = 0;
21239 char *cl_number_or_name = NULL;
21240 char *str = NULL;
21241 char *seq = NULL;
21242 int idx = 0;
21243
21244 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21245 seq = argv[idx]->arg;
21246
21247 idx = 0;
21248 argv_find(argv, argc, "permit", &idx);
21249 argv_find(argv, argc, "deny", &idx);
21250
21251 if (idx) {
21252 direct = argv_find(argv, argc, "permit", &idx)
21253 ? COMMUNITY_PERMIT
21254 : COMMUNITY_DENY;
21255
21256 idx = 0;
21257 argv_find(argv, argc, "LINE", &idx);
21258 str = argv_concat(argv, argc, idx);
21259 }
21260
21261 idx = 0;
21262 argv_find(argv, argc, "(100-500)", &idx);
21263 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21264 cl_number_or_name = argv[idx]->arg;
21265
21266 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21267 seq, direct, style);
21268
21269 XFREE(MTYPE_TMP, str);
21270
21271 if (ret < 0) {
21272 community_list_perror(vty, ret);
21273 return CMD_WARNING_CONFIG_FAILED;
21274 }
21275
21276 return CMD_SUCCESS;
21277 }
21278
21279 ALIAS(no_extcommunity_list_expanded_all,
21280 no_bgp_extcommunity_list_expanded_all_list_cmd,
21281 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21282 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21283 "Extended Community list number (expanded)\n"
21284 "Specify expanded extcommunity-list\n"
21285 "Extended Community list name\n")
21286
21287 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21288 {
21289 struct community_entry *entry;
21290
21291 for (entry = list->head; entry; entry = entry->next) {
21292 if (entry == list->head) {
21293 if (all_digit(list->name))
21294 vty_out(vty, "Extended community %s list %s\n",
21295 entry->style == EXTCOMMUNITY_LIST_STANDARD
21296 ? "standard"
21297 : "(expanded) access",
21298 list->name);
21299 else
21300 vty_out(vty,
21301 "Named extended community %s list %s\n",
21302 entry->style == EXTCOMMUNITY_LIST_STANDARD
21303 ? "standard"
21304 : "expanded",
21305 list->name);
21306 }
21307 if (entry->any)
21308 vty_out(vty, " %s\n",
21309 community_direct_str(entry->direct));
21310 else
21311 vty_out(vty, " %s %s\n",
21312 community_direct_str(entry->direct),
21313 community_list_config_str(entry));
21314 }
21315 }
21316
21317 DEFUN (show_extcommunity_list,
21318 show_bgp_extcommunity_list_cmd,
21319 "show bgp extcommunity-list",
21320 SHOW_STR
21321 BGP_STR
21322 "List extended-community list\n")
21323 {
21324 struct community_list *list;
21325 struct community_list_master *cm;
21326
21327 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21328 if (!cm)
21329 return CMD_SUCCESS;
21330
21331 for (list = cm->num.head; list; list = list->next)
21332 extcommunity_list_show(vty, list);
21333
21334 for (list = cm->str.head; list; list = list->next)
21335 extcommunity_list_show(vty, list);
21336
21337 return CMD_SUCCESS;
21338 }
21339
21340 DEFUN (show_extcommunity_list_arg,
21341 show_bgp_extcommunity_list_arg_cmd,
21342 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21343 SHOW_STR
21344 BGP_STR
21345 "List extended-community list\n"
21346 "Extcommunity-list number\n"
21347 "Extcommunity-list name\n"
21348 "Detailed information on extcommunity-list\n")
21349 {
21350 int idx_comm_list = 3;
21351 struct community_list *list;
21352
21353 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21354 EXTCOMMUNITY_LIST_MASTER);
21355 if (!list) {
21356 vty_out(vty, "%% Can't find extcommunity-list\n");
21357 return CMD_WARNING;
21358 }
21359
21360 extcommunity_list_show(vty, list);
21361
21362 return CMD_SUCCESS;
21363 }
21364
21365 /* Display community-list and extcommunity-list configuration. */
21366 static int community_list_config_write(struct vty *vty)
21367 {
21368 struct community_list *list;
21369 struct community_entry *entry;
21370 struct community_list_master *cm;
21371 int write = 0;
21372
21373 /* Community-list. */
21374 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21375
21376 for (list = cm->num.head; list; list = list->next)
21377 for (entry = list->head; entry; entry = entry->next) {
21378 vty_out(vty,
21379 "bgp community-list %s seq %" PRId64 " %s %s\n",
21380 list->name, entry->seq,
21381 community_direct_str(entry->direct),
21382 community_list_config_str(entry));
21383 write++;
21384 }
21385 for (list = cm->str.head; list; list = list->next)
21386 for (entry = list->head; entry; entry = entry->next) {
21387 vty_out(vty,
21388 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21389 entry->style == COMMUNITY_LIST_STANDARD
21390 ? "standard"
21391 : "expanded",
21392 list->name, entry->seq,
21393 community_direct_str(entry->direct),
21394 community_list_config_str(entry));
21395 write++;
21396 }
21397
21398 /* Extcommunity-list. */
21399 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21400
21401 for (list = cm->num.head; list; list = list->next)
21402 for (entry = list->head; entry; entry = entry->next) {
21403 vty_out(vty,
21404 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21405 list->name, entry->seq,
21406 community_direct_str(entry->direct),
21407 community_list_config_str(entry));
21408 write++;
21409 }
21410 for (list = cm->str.head; list; list = list->next)
21411 for (entry = list->head; entry; entry = entry->next) {
21412 vty_out(vty,
21413 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21414 entry->style == EXTCOMMUNITY_LIST_STANDARD
21415 ? "standard"
21416 : "expanded",
21417 list->name, entry->seq,
21418 community_direct_str(entry->direct),
21419 community_list_config_str(entry));
21420 write++;
21421 }
21422
21423
21424 /* lcommunity-list. */
21425 cm = community_list_master_lookup(bgp_clist,
21426 LARGE_COMMUNITY_LIST_MASTER);
21427
21428 for (list = cm->num.head; list; list = list->next)
21429 for (entry = list->head; entry; entry = entry->next) {
21430 vty_out(vty,
21431 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21432 list->name, entry->seq,
21433 community_direct_str(entry->direct),
21434 community_list_config_str(entry));
21435 write++;
21436 }
21437 for (list = cm->str.head; list; list = list->next)
21438 for (entry = list->head; entry; entry = entry->next) {
21439 vty_out(vty,
21440 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21441
21442 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21443 ? "standard"
21444 : "expanded",
21445 list->name, entry->seq, community_direct_str(entry->direct),
21446 community_list_config_str(entry));
21447 write++;
21448 }
21449
21450 return write;
21451 }
21452
21453 static int community_list_config_write(struct vty *vty);
21454 static struct cmd_node community_list_node = {
21455 .name = "community list",
21456 .node = COMMUNITY_LIST_NODE,
21457 .prompt = "",
21458 .config_write = community_list_config_write,
21459 };
21460
21461 static void community_list_vty(void)
21462 {
21463 install_node(&community_list_node);
21464
21465 /* Community-list. */
21466 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21467 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21468 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21469 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21470 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21471 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21472 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21473 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21474
21475 /* Extcommunity-list. */
21476 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21477 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21478 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21479 install_element(CONFIG_NODE,
21480 &no_bgp_extcommunity_list_standard_all_list_cmd);
21481 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21482 install_element(CONFIG_NODE,
21483 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21484 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21485 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21486
21487 /* Large Community List */
21488 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21489 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21490 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21491 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21492 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21493 install_element(CONFIG_NODE,
21494 &no_bgp_lcommunity_list_name_standard_all_cmd);
21495 install_element(CONFIG_NODE,
21496 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21497 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21498 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21499 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21500 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21501 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21502 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21503
21504 bgp_community_list_command_completion_setup();
21505 }
21506
21507 static struct cmd_node community_alias_node = {
21508 .name = "community alias",
21509 .node = COMMUNITY_ALIAS_NODE,
21510 .prompt = "",
21511 .config_write = bgp_community_alias_write,
21512 };
21513
21514 void community_alias_vty(void)
21515 {
21516 install_node(&community_alias_node);
21517
21518 /* Community-list. */
21519 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21520
21521 bgp_community_alias_command_completion_setup();
21522 }