]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
lib, bgp: add initial support for asdot format
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42 #include "asn.h"
43
44 #include "bgpd/bgpd.h"
45 #include "bgpd/bgp_attr_evpn.h"
46 #include "bgpd/bgp_advertise.h"
47 #include "bgpd/bgp_attr.h"
48 #include "bgpd/bgp_aspath.h"
49 #include "bgpd/bgp_community.h"
50 #include "bgpd/bgp_community_alias.h"
51 #include "bgpd/bgp_ecommunity.h"
52 #include "bgpd/bgp_lcommunity.h"
53 #include "bgpd/bgp_damp.h"
54 #include "bgpd/bgp_debug.h"
55 #include "bgpd/bgp_errors.h"
56 #include "bgpd/bgp_fsm.h"
57 #include "bgpd/bgp_nht.h"
58 #include "bgpd/bgp_nexthop.h"
59 #include "bgpd/bgp_network.h"
60 #include "bgpd/bgp_open.h"
61 #include "bgpd/bgp_regex.h"
62 #include "bgpd/bgp_route.h"
63 #include "bgpd/bgp_mplsvpn.h"
64 #include "bgpd/bgp_zebra.h"
65 #include "bgpd/bgp_table.h"
66 #include "bgpd/bgp_vty.h"
67 #include "bgpd/bgp_mpath.h"
68 #include "bgpd/bgp_packet.h"
69 #include "bgpd/bgp_updgrp.h"
70 #include "bgpd/bgp_bfd.h"
71 #include "bgpd/bgp_io.h"
72 #include "bgpd/bgp_evpn.h"
73 #include "bgpd/bgp_evpn_vty.h"
74 #include "bgpd/bgp_evpn_mh.h"
75 #include "bgpd/bgp_addpath.h"
76 #include "bgpd/bgp_mac.h"
77 #include "bgpd/bgp_flowspec.h"
78 #include "bgpd/bgp_conditional_adv.h"
79 #ifdef ENABLE_BGP_VNC
80 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
81 #endif
82
83 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
84 {
85 .val_bool = false,
86 .match_profile = "traditional",
87 .match_version = "< 7.4",
88 },
89 { .val_bool = true },
90 );
91 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
92 { .val_bool = true, .match_profile = "datacenter", },
93 { .val_bool = false },
94 );
95 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
96 { .val_bool = true, .match_profile = "datacenter", },
97 { .val_bool = false },
98 );
99 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
100 { .val_bool = true, .match_profile = "datacenter", },
101 { .val_bool = false },
102 );
103 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
104 { .val_bool = true, .match_profile = "datacenter", },
105 { .val_bool = false },
106 );
107 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
108 { .val_ulong = 10, .match_profile = "datacenter", },
109 { .val_ulong = 120 },
110 );
111 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
112 { .val_ulong = 9, .match_profile = "datacenter", },
113 { .val_ulong = 180 },
114 );
115 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
116 { .val_ulong = 3, .match_profile = "datacenter", },
117 { .val_ulong = 60 },
118 );
119 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
120 { .val_bool = false, .match_profile = "datacenter", },
121 { .val_bool = false, .match_version = "< 7.4", },
122 { .val_bool = true },
123 );
124 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
125 { .val_bool = false, .match_version = "< 7.6", },
126 { .val_bool = true },
127 );
128 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
129 { .val_bool = false, .match_version = "< 8.3", },
130 { .val_bool = true },
131 );
132 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
133 { .val_bool = false, .match_version = "< 8.3", },
134 { .val_bool = true },
135 );
136
137 DEFINE_HOOK(bgp_inst_config_write,
138 (struct bgp *bgp, struct vty *vty),
139 (bgp, vty));
140 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
141 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
142
143 static struct peer_group *listen_range_exists(struct bgp *bgp,
144 struct prefix *range, int exact);
145
146 /* Show BGP peer's information. */
147 enum show_type {
148 show_all,
149 show_peer,
150 show_ipv4_all,
151 show_ipv6_all,
152 show_ipv4_peer,
153 show_ipv6_peer
154 };
155
156 static struct peer_group *listen_range_exists(struct bgp *bgp,
157 struct prefix *range, int exact);
158
159 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
160 struct bgp *bgp);
161
162 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
163 enum show_type type,
164 const char *ip_str,
165 afi_t afi, bool use_json);
166
167 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
168 {
169 switch (afi) {
170 case AFI_IP:
171 switch (safi) {
172 case SAFI_UNICAST:
173 return BGP_IPV4_NODE;
174 case SAFI_MULTICAST:
175 return BGP_IPV4M_NODE;
176 case SAFI_LABELED_UNICAST:
177 return BGP_IPV4L_NODE;
178 case SAFI_MPLS_VPN:
179 return BGP_VPNV4_NODE;
180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV4_NODE;
182 case SAFI_UNSPEC:
183 case SAFI_ENCAP:
184 case SAFI_EVPN:
185 case SAFI_MAX:
186 /* not expected */
187 return BGP_IPV4_NODE;
188 }
189 break;
190 case AFI_IP6:
191 switch (safi) {
192 case SAFI_UNICAST:
193 return BGP_IPV6_NODE;
194 case SAFI_MULTICAST:
195 return BGP_IPV6M_NODE;
196 case SAFI_LABELED_UNICAST:
197 return BGP_IPV6L_NODE;
198 case SAFI_MPLS_VPN:
199 return BGP_VPNV6_NODE;
200 case SAFI_FLOWSPEC:
201 return BGP_FLOWSPECV6_NODE;
202 case SAFI_UNSPEC:
203 case SAFI_ENCAP:
204 case SAFI_EVPN:
205 case SAFI_MAX:
206 /* not expected and the return value seems wrong */
207 return BGP_IPV4_NODE;
208 }
209 break;
210 case AFI_L2VPN:
211 return BGP_EVPN_NODE;
212 case AFI_UNSPEC:
213 case AFI_MAX:
214 // We should never be here but to clarify the switch statement..
215 return BGP_IPV4_NODE;
216 }
217
218 // Impossible to happen
219 return BGP_IPV4_NODE;
220 }
221
222 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
223 {
224 if (afi == AFI_IP) {
225 if (safi == SAFI_UNICAST)
226 return "IPv4 Unicast";
227 if (safi == SAFI_MULTICAST)
228 return "IPv4 Multicast";
229 if (safi == SAFI_LABELED_UNICAST)
230 return "IPv4 Labeled Unicast";
231 if (safi == SAFI_MPLS_VPN)
232 return "IPv4 VPN";
233 if (safi == SAFI_ENCAP)
234 return "IPv4 Encap";
235 if (safi == SAFI_FLOWSPEC)
236 return "IPv4 Flowspec";
237 } else if (afi == AFI_IP6) {
238 if (safi == SAFI_UNICAST)
239 return "IPv6 Unicast";
240 if (safi == SAFI_MULTICAST)
241 return "IPv6 Multicast";
242 if (safi == SAFI_LABELED_UNICAST)
243 return "IPv6 Labeled Unicast";
244 if (safi == SAFI_MPLS_VPN)
245 return "IPv6 VPN";
246 if (safi == SAFI_ENCAP)
247 return "IPv6 Encap";
248 if (safi == SAFI_FLOWSPEC)
249 return "IPv6 Flowspec";
250 } else if (afi == AFI_L2VPN) {
251 if (safi == SAFI_EVPN)
252 return "L2VPN EVPN";
253 }
254
255 return "Unknown";
256 }
257
258 /*
259 * Please note that we have intentionally camelCased
260 * the return strings here. So if you want
261 * to use this function, please ensure you
262 * are doing this within json output
263 */
264 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
265 {
266 if (afi == AFI_IP) {
267 if (safi == SAFI_UNICAST)
268 return "ipv4Unicast";
269 if (safi == SAFI_MULTICAST)
270 return "ipv4Multicast";
271 if (safi == SAFI_LABELED_UNICAST)
272 return "ipv4LabeledUnicast";
273 if (safi == SAFI_MPLS_VPN)
274 return "ipv4Vpn";
275 if (safi == SAFI_ENCAP)
276 return "ipv4Encap";
277 if (safi == SAFI_FLOWSPEC)
278 return "ipv4Flowspec";
279 } else if (afi == AFI_IP6) {
280 if (safi == SAFI_UNICAST)
281 return "ipv6Unicast";
282 if (safi == SAFI_MULTICAST)
283 return "ipv6Multicast";
284 if (safi == SAFI_LABELED_UNICAST)
285 return "ipv6LabeledUnicast";
286 if (safi == SAFI_MPLS_VPN)
287 return "ipv6Vpn";
288 if (safi == SAFI_ENCAP)
289 return "ipv6Encap";
290 if (safi == SAFI_FLOWSPEC)
291 return "ipv6Flowspec";
292 } else if (afi == AFI_L2VPN) {
293 if (safi == SAFI_EVPN)
294 return "l2VpnEvpn";
295 }
296
297 return "Unknown";
298 }
299
300 /* unset srv6 locator */
301 static int bgp_srv6_locator_unset(struct bgp *bgp)
302 {
303 int ret;
304 struct listnode *node, *nnode;
305 struct srv6_locator_chunk *chunk;
306 struct bgp_srv6_function *func;
307 struct bgp *bgp_vrf;
308
309 /* release chunk notification via ZAPI */
310 ret = bgp_zebra_srv6_manager_release_locator_chunk(
311 bgp->srv6_locator_name);
312 if (ret < 0)
313 return -1;
314
315 /* refresh chunks */
316 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
317 listnode_delete(bgp->srv6_locator_chunks, chunk);
318 srv6_locator_chunk_free(&chunk);
319 }
320
321 /* refresh functions */
322 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
323 listnode_delete(bgp->srv6_functions, func);
324 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
325 }
326
327 /* refresh tovpn_sid */
328 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
329 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
330 continue;
331
332 /* refresh vpnv4 tovpn_sid */
333 XFREE(MTYPE_BGP_SRV6_SID,
334 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
335
336 /* refresh vpnv6 tovpn_sid */
337 XFREE(MTYPE_BGP_SRV6_SID,
338 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
339
340 /* refresh per-vrf tovpn_sid */
341 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
342 }
343
344 /* update vpn bgp processes */
345 vpn_leak_postchange_all();
346
347 /* refresh tovpn_sid_locator */
348 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
349 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
350 continue;
351
352 /* refresh vpnv4 tovpn_sid_locator */
353 srv6_locator_chunk_free(
354 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
355
356 /* refresh vpnv6 tovpn_sid_locator */
357 srv6_locator_chunk_free(
358 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
359
360 /* refresh per-vrf tovpn_sid_locator */
361 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
362 }
363
364 /* clear locator name */
365 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
366
367 return 0;
368 }
369
370 /* Utility function to get address family from current node. */
371 afi_t bgp_node_afi(struct vty *vty)
372 {
373 afi_t afi;
374 switch (vty->node) {
375 case BGP_IPV6_NODE:
376 case BGP_IPV6M_NODE:
377 case BGP_IPV6L_NODE:
378 case BGP_VPNV6_NODE:
379 case BGP_FLOWSPECV6_NODE:
380 afi = AFI_IP6;
381 break;
382 case BGP_EVPN_NODE:
383 afi = AFI_L2VPN;
384 break;
385 default:
386 afi = AFI_IP;
387 break;
388 }
389 return afi;
390 }
391
392 /* Utility function to get subsequent address family from current
393 node. */
394 safi_t bgp_node_safi(struct vty *vty)
395 {
396 safi_t safi;
397 switch (vty->node) {
398 case BGP_VPNV4_NODE:
399 case BGP_VPNV6_NODE:
400 safi = SAFI_MPLS_VPN;
401 break;
402 case BGP_IPV4M_NODE:
403 case BGP_IPV6M_NODE:
404 safi = SAFI_MULTICAST;
405 break;
406 case BGP_EVPN_NODE:
407 safi = SAFI_EVPN;
408 break;
409 case BGP_IPV4L_NODE:
410 case BGP_IPV6L_NODE:
411 safi = SAFI_LABELED_UNICAST;
412 break;
413 case BGP_FLOWSPECV4_NODE:
414 case BGP_FLOWSPECV6_NODE:
415 safi = SAFI_FLOWSPEC;
416 break;
417 default:
418 safi = SAFI_UNICAST;
419 break;
420 }
421 return safi;
422 }
423
424 /**
425 * Converts an AFI in string form to afi_t
426 *
427 * @param afi string, one of
428 * - "ipv4"
429 * - "ipv6"
430 * - "l2vpn"
431 * @return the corresponding afi_t
432 */
433 afi_t bgp_vty_afi_from_str(const char *afi_str)
434 {
435 afi_t afi = AFI_MAX; /* unknown */
436 if (strmatch(afi_str, "ipv4"))
437 afi = AFI_IP;
438 else if (strmatch(afi_str, "ipv6"))
439 afi = AFI_IP6;
440 else if (strmatch(afi_str, "l2vpn"))
441 afi = AFI_L2VPN;
442 return afi;
443 }
444
445 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
446 afi_t *afi)
447 {
448 int ret = 0;
449 if (argv_find(argv, argc, "ipv4", index)) {
450 ret = 1;
451 if (afi)
452 *afi = AFI_IP;
453 } else if (argv_find(argv, argc, "ipv6", index)) {
454 ret = 1;
455 if (afi)
456 *afi = AFI_IP6;
457 } else if (argv_find(argv, argc, "l2vpn", index)) {
458 ret = 1;
459 if (afi)
460 *afi = AFI_L2VPN;
461 }
462 return ret;
463 }
464
465 /* supports <unicast|multicast|vpn|labeled-unicast> */
466 safi_t bgp_vty_safi_from_str(const char *safi_str)
467 {
468 safi_t safi = SAFI_MAX; /* unknown */
469 if (strmatch(safi_str, "multicast"))
470 safi = SAFI_MULTICAST;
471 else if (strmatch(safi_str, "unicast"))
472 safi = SAFI_UNICAST;
473 else if (strmatch(safi_str, "vpn"))
474 safi = SAFI_MPLS_VPN;
475 else if (strmatch(safi_str, "evpn"))
476 safi = SAFI_EVPN;
477 else if (strmatch(safi_str, "labeled-unicast"))
478 safi = SAFI_LABELED_UNICAST;
479 else if (strmatch(safi_str, "flowspec"))
480 safi = SAFI_FLOWSPEC;
481 return safi;
482 }
483
484 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
485 safi_t *safi)
486 {
487 int ret = 0;
488 if (argv_find(argv, argc, "unicast", index)) {
489 ret = 1;
490 if (safi)
491 *safi = SAFI_UNICAST;
492 } else if (argv_find(argv, argc, "multicast", index)) {
493 ret = 1;
494 if (safi)
495 *safi = SAFI_MULTICAST;
496 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
497 ret = 1;
498 if (safi)
499 *safi = SAFI_LABELED_UNICAST;
500 } else if (argv_find(argv, argc, "vpn", index)) {
501 ret = 1;
502 if (safi)
503 *safi = SAFI_MPLS_VPN;
504 } else if (argv_find(argv, argc, "evpn", index)) {
505 ret = 1;
506 if (safi)
507 *safi = SAFI_EVPN;
508 } else if (argv_find(argv, argc, "flowspec", index)) {
509 ret = 1;
510 if (safi)
511 *safi = SAFI_FLOWSPEC;
512 }
513 return ret;
514 }
515
516 /*
517 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
518 *
519 * afi
520 * address-family identifier
521 *
522 * safi
523 * subsequent address-family identifier
524 *
525 * Returns:
526 * default_af string corresponding to the supplied afi/safi pair.
527 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
528 * return -1.
529 */
530 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
531 {
532 switch (afi) {
533 case AFI_IP:
534 switch (safi) {
535 case SAFI_UNICAST:
536 return "ipv4-unicast";
537 case SAFI_MULTICAST:
538 return "ipv4-multicast";
539 case SAFI_MPLS_VPN:
540 return "ipv4-vpn";
541 case SAFI_ENCAP:
542 return "ipv4-encap";
543 case SAFI_LABELED_UNICAST:
544 return "ipv4-labeled-unicast";
545 case SAFI_FLOWSPEC:
546 return "ipv4-flowspec";
547 case SAFI_UNSPEC:
548 case SAFI_EVPN:
549 case SAFI_MAX:
550 return "unknown-afi/safi";
551 }
552 break;
553 case AFI_IP6:
554 switch (safi) {
555 case SAFI_UNICAST:
556 return "ipv6-unicast";
557 case SAFI_MULTICAST:
558 return "ipv6-multicast";
559 case SAFI_MPLS_VPN:
560 return "ipv6-vpn";
561 case SAFI_ENCAP:
562 return "ipv6-encap";
563 case SAFI_LABELED_UNICAST:
564 return "ipv6-labeled-unicast";
565 case SAFI_FLOWSPEC:
566 return "ipv6-flowspec";
567 case SAFI_UNSPEC:
568 case SAFI_EVPN:
569 case SAFI_MAX:
570 return "unknown-afi/safi";
571 }
572 break;
573 case AFI_L2VPN:
574 switch (safi) {
575 case SAFI_EVPN:
576 return "l2vpn-evpn";
577 case SAFI_UNICAST:
578 case SAFI_MULTICAST:
579 case SAFI_MPLS_VPN:
580 case SAFI_ENCAP:
581 case SAFI_LABELED_UNICAST:
582 case SAFI_FLOWSPEC:
583 case SAFI_UNSPEC:
584 case SAFI_MAX:
585 return "unknown-afi/safi";
586 }
587 break;
588 case AFI_UNSPEC:
589 case AFI_MAX:
590 return "unknown-afi/safi";
591 }
592 /* all AFIs are accounted for above, so this shouldn't happen */
593
594 assert(!"Reached end of function where we did not expect to");
595 }
596
597 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
598 enum bgp_instance_type inst_type, const char *as_pretty)
599 {
600 int ret = bgp_get(bgp, as, name, inst_type, as_pretty);
601
602 if (ret == BGP_CREATED) {
603 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
604 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
605
606 if (DFLT_BGP_IMPORT_CHECK)
607 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
608 if (DFLT_BGP_SHOW_HOSTNAME)
609 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
610 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
611 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
612 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
613 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
614 if (DFLT_BGP_DETERMINISTIC_MED)
615 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
616 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
617 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
618 if (DFLT_BGP_SUPPRESS_DUPLICATES)
619 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
620 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
621 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
622 if (DFLT_BGP_HARD_ADMIN_RESET)
623 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
624
625 ret = BGP_SUCCESS;
626 }
627 return ret;
628 }
629
630 /*
631 * bgp_vty_find_and_parse_afi_safi_bgp
632 *
633 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
634 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
635 * to appropriate values for the calling function. This is to allow the
636 * calling function to make decisions appropriate for the show command
637 * that is being parsed.
638 *
639 * The show commands are generally of the form:
640 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
641 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
642 *
643 * Since we use argv_find if the show command in particular doesn't have:
644 * [ip]
645 * [<view|vrf> VIEWVRFNAME]
646 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
647 * The command parsing should still be ok.
648 *
649 * vty -> The vty for the command so we can output some useful data in
650 * the event of a parse error in the vrf.
651 * argv -> The command tokens
652 * argc -> How many command tokens we have
653 * idx -> The current place in the command, generally should be 0 for this
654 * function
655 * afi -> The parsed afi if it was included in the show command, returned here
656 * safi -> The parsed safi if it was included in the show command, returned here
657 * bgp -> Pointer to the bgp data structure we need to fill in.
658 * use_json -> json is configured or not
659 *
660 * The function returns the correct location in the parse tree for the
661 * last token found.
662 *
663 * Returns 0 for failure to parse correctly, else the idx position of where
664 * it found the last token.
665 */
666 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
667 struct cmd_token **argv, int argc,
668 int *idx, afi_t *afi, safi_t *safi,
669 struct bgp **bgp, bool use_json)
670 {
671 char *vrf_name = NULL;
672
673 assert(afi);
674 assert(safi);
675 assert(bgp);
676
677 if (argv_find(argv, argc, "ip", idx))
678 *afi = AFI_IP;
679
680 if (argv_find(argv, argc, "view", idx))
681 vrf_name = argv[*idx + 1]->arg;
682 else if (argv_find(argv, argc, "vrf", idx)) {
683 vrf_name = argv[*idx + 1]->arg;
684 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
685 vrf_name = NULL;
686 }
687 if (vrf_name) {
688 if (strmatch(vrf_name, "all"))
689 *bgp = NULL;
690 else {
691 *bgp = bgp_lookup_by_name(vrf_name);
692 if (!*bgp) {
693 if (use_json) {
694 json_object *json = NULL;
695 json = json_object_new_object();
696 json_object_string_add(
697 json, "warning",
698 "View/Vrf is unknown");
699 vty_json(vty, json);
700 }
701 else
702 vty_out(vty, "View/Vrf %s is unknown\n",
703 vrf_name);
704 *idx = 0;
705 return 0;
706 }
707 }
708 } else {
709 *bgp = bgp_get_default();
710 if (!*bgp) {
711 if (use_json) {
712 json_object *json = NULL;
713 json = json_object_new_object();
714 json_object_string_add(
715 json, "warning",
716 "Default BGP instance not found");
717 vty_json(vty, json);
718 }
719 else
720 vty_out(vty,
721 "Default BGP instance not found\n");
722 *idx = 0;
723 return 0;
724 }
725 }
726
727 if (argv_find_and_parse_afi(argv, argc, idx, afi))
728 argv_find_and_parse_safi(argv, argc, idx, safi);
729
730 *idx += 1;
731 return *idx;
732 }
733
734 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
735 {
736 struct interface *ifp = NULL;
737 struct listnode *node;
738 struct bgp_listener *listener;
739 union sockunion all_su;
740
741 if (su->sa.sa_family == AF_INET) {
742 (void)str2sockunion("0.0.0.0", &all_su);
743 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
744 } else if (su->sa.sa_family == AF_INET6) {
745 (void)str2sockunion("::", &all_su);
746 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
747 su->sin6.sin6_scope_id,
748 bgp->vrf_id);
749 }
750
751 if (ifp) {
752 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
753 if (sockunion_family(su) !=
754 sockunion_family(&listener->su))
755 continue;
756
757 /* If 0.0.0.0/:: is a listener, then treat as self and
758 * reject.
759 */
760 if (!sockunion_cmp(&listener->su, su) ||
761 !sockunion_cmp(&listener->su, &all_su))
762 return true;
763 }
764 }
765
766 return false;
767 }
768
769 /* Utility function for looking up peer from VTY. */
770 /* This is used only for configuration, so disallow if attempted on
771 * a dynamic neighbor.
772 */
773 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
774 {
775 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
776 int ret;
777 union sockunion su;
778 struct peer *peer;
779
780 if (!bgp) {
781 return NULL;
782 }
783
784 ret = str2sockunion(ip_str, &su);
785 if (ret < 0) {
786 peer = peer_lookup_by_conf_if(bgp, ip_str);
787 if (!peer) {
788 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
789 == NULL) {
790 vty_out(vty,
791 "%% Malformed address or name: %s\n",
792 ip_str);
793 return NULL;
794 }
795 }
796 } else {
797 peer = peer_lookup(bgp, &su);
798 if (!peer) {
799 vty_out(vty,
800 "%% Specify remote-as or peer-group commands first\n");
801 return NULL;
802 }
803 if (peer_dynamic_neighbor(peer)) {
804 vty_out(vty,
805 "%% Operation not allowed on a dynamic neighbor\n");
806 return NULL;
807 }
808 }
809 return peer;
810 }
811
812 /* Utility function for looking up peer or peer group. */
813 /* This is used only for configuration, so disallow if attempted on
814 * a dynamic neighbor.
815 */
816 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
817 {
818 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
819 int ret;
820 union sockunion su;
821 struct peer *peer = NULL;
822 struct peer_group *group = NULL;
823
824 if (!bgp) {
825 return NULL;
826 }
827
828 ret = str2sockunion(peer_str, &su);
829 if (ret == 0) {
830 /* IP address, locate peer. */
831 peer = peer_lookup(bgp, &su);
832 } else {
833 /* Not IP, could match either peer configured on interface or a
834 * group. */
835 peer = peer_lookup_by_conf_if(bgp, peer_str);
836 if (!peer)
837 group = peer_group_lookup(bgp, peer_str);
838 }
839
840 if (peer) {
841 if (peer_dynamic_neighbor(peer)) {
842 zlog_warn(
843 "%pBP: Operation not allowed on a dynamic neighbor",
844 peer);
845 vty_out(vty,
846 "%% Operation not allowed on a dynamic neighbor\n");
847 return NULL;
848 }
849
850 return peer;
851 }
852
853 if (group)
854 return group->conf;
855
856 zlog_warn("Specify remote-as or peer-group commands first before: %s",
857 vty->buf);
858 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
859
860 return NULL;
861 }
862
863 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
864 {
865 const char *str = NULL;
866
867 switch (ret) {
868 case BGP_SUCCESS:
869 case BGP_CREATED:
870 case BGP_GR_NO_OPERATION:
871 break;
872 case BGP_ERR_INVALID_VALUE:
873 str = "Invalid value";
874 break;
875 case BGP_ERR_INVALID_FLAG:
876 str = "Invalid flag";
877 break;
878 case BGP_ERR_PEER_GROUP_SHUTDOWN:
879 str = "Peer-group has been shutdown. Activate the peer-group first";
880 break;
881 case BGP_ERR_PEER_FLAG_CONFLICT:
882 str = "Can't set override-capability and strict-capability-match at the same time";
883 break;
884 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
885 str = "Specify remote-as or peer-group remote AS first";
886 break;
887 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
888 str = "Cannot change the peer-group. Deconfigure first";
889 break;
890 case BGP_ERR_PEER_GROUP_MISMATCH:
891 str = "Peer is not a member of this peer-group";
892 break;
893 case BGP_ERR_PEER_FILTER_CONFLICT:
894 str = "Prefix/distribute list can not co-exist";
895 break;
896 case BGP_ERR_NOT_INTERNAL_PEER:
897 str = "Invalid command. Not an internal neighbor";
898 break;
899 case BGP_ERR_REMOVE_PRIVATE_AS:
900 str = "remove-private-AS cannot be configured for IBGP peers";
901 break;
902 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
903 str = "Cannot have local-as same as BGP AS number";
904 break;
905 case BGP_ERR_TCPSIG_FAILED:
906 str = "Error while applying TCP-Sig to session(s)";
907 break;
908 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
909 str = "ebgp-multihop and ttl-security cannot be configured together";
910 break;
911 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
912 str = "ttl-security only allowed for EBGP peers";
913 break;
914 case BGP_ERR_AS_OVERRIDE:
915 str = "as-override cannot be configured for IBGP peers";
916 break;
917 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
918 str = "Invalid limit for number of dynamic neighbors";
919 break;
920 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
921 str = "Dynamic neighbor listen range already exists";
922 break;
923 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
924 str = "Operation not allowed on a dynamic neighbor";
925 break;
926 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
927 str = "Operation not allowed on a directly connected neighbor";
928 break;
929 case BGP_ERR_PEER_SAFI_CONFLICT:
930 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
931 break;
932 case BGP_ERR_GR_INVALID_CMD:
933 str = "The Graceful Restart command used is not valid at this moment.";
934 break;
935 case BGP_ERR_GR_OPERATION_FAILED:
936 str = "The Graceful Restart Operation failed due to an err.";
937 break;
938 case BGP_ERR_PEER_GROUP_MEMBER:
939 str = "Peer-group member cannot override remote-as of peer-group.";
940 break;
941 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
942 str = "Peer-group members must be all internal or all external.";
943 break;
944 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
945 str = "Range specified cannot be deleted because it is not part of current config.";
946 break;
947 case BGP_ERR_INSTANCE_MISMATCH:
948 str = "Instance specified does not match the current instance.";
949 break;
950 case BGP_ERR_NO_INTERFACE_CONFIG:
951 str = "Interface specified is not being used for interface based peer.";
952 break;
953 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
954 str = "No configuration already specified for soft reconfiguration.";
955 break;
956 case BGP_ERR_AS_MISMATCH:
957 str = "BGP is already running.";
958 break;
959 case BGP_ERR_AF_UNCONFIGURED:
960 str = "AFI/SAFI specified is not currently configured.";
961 break;
962 case BGP_ERR_INVALID_AS:
963 str = "Confederation AS specified is the same AS as our AS.";
964 break;
965 case BGP_ERR_INVALID_ROLE_NAME:
966 str = "Invalid role name";
967 break;
968 case BGP_ERR_INVALID_INTERNAL_ROLE:
969 str = "External roles can be set only on eBGP session";
970 break;
971 }
972 if (str) {
973 vty_out(vty, "%% %s\n", str);
974 return CMD_WARNING_CONFIG_FAILED;
975 }
976 return CMD_SUCCESS;
977 }
978
979 /* BGP clear sort. */
980 enum clear_sort {
981 clear_all,
982 clear_peer,
983 clear_group,
984 clear_external,
985 clear_as
986 };
987
988 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
989 safi_t safi, int error)
990 {
991 switch (error) {
992 case BGP_ERR_AF_UNCONFIGURED:
993 if (vty)
994 vty_out(vty,
995 "%% BGP: Enable %s address family for the neighbor %s\n",
996 get_afi_safi_str(afi, safi, false), peer->host);
997 else
998 zlog_warn(
999 "%% BGP: Enable %s address family for the neighbor %s",
1000 get_afi_safi_str(afi, safi, false), peer->host);
1001 break;
1002 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1003 if (vty)
1004 vty_out(vty,
1005 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
1006 peer->host);
1007 else
1008 zlog_warn(
1009 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
1010 peer->host);
1011 break;
1012 default:
1013 break;
1014 }
1015 }
1016
1017 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
1018 struct listnode **nnode, enum bgp_clear_type stype)
1019 {
1020 int ret = 0;
1021 struct peer_af *paf;
1022
1023 /* if afi/.safi not specified, spin thru all of them */
1024 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1025 afi_t tmp_afi;
1026 safi_t tmp_safi;
1027 enum bgp_af_index index;
1028
1029 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1030 paf = peer->peer_af_array[index];
1031 if (!paf)
1032 continue;
1033
1034 if (paf && paf->subgroup)
1035 SET_FLAG(paf->subgroup->sflags,
1036 SUBGRP_STATUS_FORCE_UPDATES);
1037
1038 tmp_afi = paf->afi;
1039 tmp_safi = paf->safi;
1040 if (!peer->afc[tmp_afi][tmp_safi])
1041 continue;
1042
1043 if (stype == BGP_CLEAR_SOFT_NONE)
1044 ret = peer_clear(peer, nnode);
1045 else
1046 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1047 stype);
1048 }
1049 /* if afi specified and safi not, spin thru safis on this afi */
1050 } else if (safi == SAFI_UNSPEC) {
1051 safi_t tmp_safi;
1052
1053 for (tmp_safi = SAFI_UNICAST;
1054 tmp_safi < SAFI_MAX; tmp_safi++) {
1055 if (!peer->afc[afi][tmp_safi])
1056 continue;
1057
1058 paf = peer_af_find(peer, afi, tmp_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,
1067 tmp_safi, stype);
1068 }
1069 /* both afi/safi specified, let the caller know if not defined */
1070 } else {
1071 if (!peer->afc[afi][safi])
1072 return 1;
1073
1074 paf = peer_af_find(peer, afi, safi);
1075 if (paf && paf->subgroup)
1076 SET_FLAG(paf->subgroup->sflags,
1077 SUBGRP_STATUS_FORCE_UPDATES);
1078
1079 if (stype == BGP_CLEAR_SOFT_NONE)
1080 ret = peer_clear(peer, nnode);
1081 else
1082 ret = peer_clear_soft(peer, afi, safi, stype);
1083 }
1084
1085 return ret;
1086 }
1087
1088 /* `clear ip bgp' functions. */
1089 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1090 enum clear_sort sort, enum bgp_clear_type stype,
1091 const char *arg)
1092 {
1093 int ret = 0;
1094 bool found = false;
1095 struct peer *peer;
1096
1097 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1098
1099 /* Clear all neighbors. */
1100 /*
1101 * Pass along pointer to next node to peer_clear() when walking all
1102 * nodes on the BGP instance as that may get freed if it is a
1103 * doppelganger
1104 */
1105 if (sort == clear_all) {
1106 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1107
1108 bgp_peer_gr_flags_update(peer);
1109
1110 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1111 gr_router_detected = true;
1112
1113 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1114 stype);
1115
1116 if (ret < 0)
1117 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1118 }
1119
1120 if (gr_router_detected
1121 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1122 bgp_zebra_send_capabilities(bgp, false);
1123 } else if (!gr_router_detected
1124 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1125 bgp_zebra_send_capabilities(bgp, true);
1126 }
1127
1128 /* This is to apply read-only mode on this clear. */
1129 if (stype == BGP_CLEAR_SOFT_NONE)
1130 bgp->update_delay_over = 0;
1131
1132 return CMD_SUCCESS;
1133 }
1134
1135 /* Clear specified neighbor. */
1136 if (sort == clear_peer) {
1137 union sockunion su;
1138
1139 /* Make sockunion for lookup. */
1140 ret = str2sockunion(arg, &su);
1141 if (ret < 0) {
1142 peer = peer_lookup_by_conf_if(bgp, arg);
1143 if (!peer) {
1144 peer = peer_lookup_by_hostname(bgp, arg);
1145 if (!peer) {
1146 vty_out(vty,
1147 "Malformed address or name: %s\n",
1148 arg);
1149 return CMD_WARNING;
1150 }
1151 }
1152 } else {
1153 peer = peer_lookup(bgp, &su);
1154 if (!peer) {
1155 vty_out(vty,
1156 "%% BGP: Unknown neighbor - \"%s\"\n",
1157 arg);
1158 return CMD_WARNING;
1159 }
1160 }
1161
1162 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1163 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1164
1165 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1166
1167 /* if afi/safi not defined for this peer, let caller know */
1168 if (ret == 1)
1169 ret = BGP_ERR_AF_UNCONFIGURED;
1170
1171 if (ret < 0)
1172 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1173
1174 return CMD_SUCCESS;
1175 }
1176
1177 /* Clear all neighbors belonging to a specific peer-group. */
1178 if (sort == clear_group) {
1179 struct peer_group *group;
1180
1181 group = peer_group_lookup(bgp, arg);
1182 if (!group) {
1183 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1184 return CMD_WARNING;
1185 }
1186
1187 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1188 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1189
1190 if (ret < 0)
1191 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1192 else
1193 found = true;
1194 }
1195
1196 if (!found)
1197 vty_out(vty,
1198 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1199 get_afi_safi_str(afi, safi, false), arg);
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 /* Clear all external (eBGP) neighbors. */
1205 if (sort == clear_external) {
1206 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1207 if (peer->sort == BGP_PEER_IBGP)
1208 continue;
1209
1210 bgp_peer_gr_flags_update(peer);
1211
1212 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1213 gr_router_detected = true;
1214
1215 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1216
1217 if (ret < 0)
1218 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1219 else
1220 found = true;
1221 }
1222
1223 if (gr_router_detected
1224 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1225 bgp_zebra_send_capabilities(bgp, false);
1226 } else if (!gr_router_detected
1227 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1228 bgp_zebra_send_capabilities(bgp, true);
1229 }
1230
1231 if (!found)
1232 vty_out(vty,
1233 "%% BGP: No external %s peer is configured\n",
1234 get_afi_safi_str(afi, safi, false));
1235
1236 return CMD_SUCCESS;
1237 }
1238
1239 /* Clear all neighbors belonging to a specific AS. */
1240 if (sort == clear_as) {
1241 as_t as;
1242
1243 if (!asn_str2asn(arg, &as)) {
1244 vty_out(vty, "%% BGP: No such AS %s\n", arg);
1245 return CMD_WARNING;
1246 }
1247
1248 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1249 if (peer->as != as)
1250 continue;
1251
1252 bgp_peer_gr_flags_update(peer);
1253
1254 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1255 gr_router_detected = true;
1256
1257 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1258
1259 if (ret < 0)
1260 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1261 else
1262 found = true;
1263 }
1264
1265 if (gr_router_detected
1266 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1267 bgp_zebra_send_capabilities(bgp, false);
1268 } else if (!gr_router_detected
1269 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1270 bgp_zebra_send_capabilities(bgp, true);
1271 }
1272
1273 if (!found)
1274 vty_out(vty,
1275 "%% BGP: No %s peer is configured with AS %s\n",
1276 get_afi_safi_str(afi, safi, false), arg);
1277
1278 return CMD_SUCCESS;
1279 }
1280
1281 return CMD_SUCCESS;
1282 }
1283
1284 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1285 safi_t safi, enum clear_sort sort,
1286 enum bgp_clear_type stype, const char *arg)
1287 {
1288 struct bgp *bgp;
1289
1290 /* BGP structure lookup. */
1291 if (name) {
1292 bgp = bgp_lookup_by_name(name);
1293 if (bgp == NULL) {
1294 vty_out(vty, "Can't find BGP instance %s\n", name);
1295 return CMD_WARNING;
1296 }
1297 } else {
1298 bgp = bgp_get_default();
1299 if (bgp == NULL) {
1300 vty_out(vty, "No BGP process is configured\n");
1301 return CMD_WARNING;
1302 }
1303 }
1304
1305 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1306 }
1307
1308 /* clear soft inbound */
1309 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1310 {
1311 afi_t afi;
1312 safi_t safi;
1313
1314 FOREACH_AFI_SAFI (afi, safi)
1315 bgp_clear_vty(vty, name, afi, safi, clear_all,
1316 BGP_CLEAR_SOFT_IN, NULL);
1317 }
1318
1319 /* clear soft outbound */
1320 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1321 {
1322 afi_t afi;
1323 safi_t safi;
1324
1325 FOREACH_AFI_SAFI (afi, safi)
1326 bgp_clear_vty(vty, name, afi, safi, clear_all,
1327 BGP_CLEAR_SOFT_OUT, NULL);
1328 }
1329
1330
1331 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1332 {
1333 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1334 }
1335
1336 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1337 uint64_t flag, int set)
1338 {
1339 int ret;
1340 struct peer *peer;
1341
1342 peer = peer_and_group_lookup_vty(vty, ip_str);
1343 if (!peer)
1344 return CMD_WARNING_CONFIG_FAILED;
1345
1346 /*
1347 * If 'neighbor <interface>', then this is for directly connected peers,
1348 * we should not accept disable-connected-check.
1349 */
1350 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1351 vty_out(vty,
1352 "%s is directly connected peer, cannot accept disable-connected-check\n",
1353 ip_str);
1354 return CMD_WARNING_CONFIG_FAILED;
1355 }
1356
1357 if (!set && flag == PEER_FLAG_SHUTDOWN)
1358 peer_tx_shutdown_message_unset(peer);
1359
1360 if (set)
1361 ret = peer_flag_set(peer, flag);
1362 else
1363 ret = peer_flag_unset(peer, flag);
1364
1365 return bgp_vty_return(vty, ret);
1366 }
1367
1368 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1369 {
1370 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1371 }
1372
1373 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1374 uint64_t flag)
1375 {
1376 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1377 }
1378
1379 #include "bgpd/bgp_vty_clippy.c"
1380
1381 DEFUN_HIDDEN (bgp_local_mac,
1382 bgp_local_mac_cmd,
1383 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1384 BGP_STR
1385 "Local MAC config\n"
1386 "VxLAN Network Identifier\n"
1387 "VNI number\n"
1388 "local mac\n"
1389 "mac address\n"
1390 "mac-mobility sequence\n"
1391 "seq number\n")
1392 {
1393 int rv;
1394 vni_t vni;
1395 struct ethaddr mac;
1396 struct ipaddr ip;
1397 uint32_t seq;
1398 struct bgp *bgp;
1399
1400 vni = strtoul(argv[3]->arg, NULL, 10);
1401 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1402 vty_out(vty, "%% Malformed MAC address\n");
1403 return CMD_WARNING;
1404 }
1405 memset(&ip, 0, sizeof(ip));
1406 seq = strtoul(argv[7]->arg, NULL, 10);
1407
1408 bgp = bgp_get_default();
1409 if (!bgp) {
1410 vty_out(vty, "Default BGP instance is not there\n");
1411 return CMD_WARNING;
1412 }
1413
1414 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1415 zero_esi);
1416 if (rv < 0) {
1417 vty_out(vty, "Internal error\n");
1418 return CMD_WARNING;
1419 }
1420
1421 return CMD_SUCCESS;
1422 }
1423
1424 DEFUN_HIDDEN (no_bgp_local_mac,
1425 no_bgp_local_mac_cmd,
1426 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1427 NO_STR
1428 BGP_STR
1429 "Local MAC config\n"
1430 "VxLAN Network Identifier\n"
1431 "VNI number\n"
1432 "local mac\n"
1433 "mac address\n")
1434 {
1435 int rv;
1436 vni_t vni;
1437 struct ethaddr mac;
1438 struct ipaddr ip;
1439 struct bgp *bgp;
1440
1441 vni = strtoul(argv[4]->arg, NULL, 10);
1442 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1443 vty_out(vty, "%% Malformed MAC address\n");
1444 return CMD_WARNING;
1445 }
1446 memset(&ip, 0, sizeof(ip));
1447
1448 bgp = bgp_get_default();
1449 if (!bgp) {
1450 vty_out(vty, "Default BGP instance is not there\n");
1451 return CMD_WARNING;
1452 }
1453
1454 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1455 if (rv < 0) {
1456 vty_out(vty, "Internal error\n");
1457 return CMD_WARNING;
1458 }
1459
1460 return CMD_SUCCESS;
1461 }
1462
1463 DEFUN (no_synchronization,
1464 no_synchronization_cmd,
1465 "no synchronization",
1466 NO_STR
1467 "Perform IGP synchronization\n")
1468 {
1469 return CMD_SUCCESS;
1470 }
1471
1472 DEFUN (no_auto_summary,
1473 no_auto_summary_cmd,
1474 "no auto-summary",
1475 NO_STR
1476 "Enable automatic network number summarization\n")
1477 {
1478 return CMD_SUCCESS;
1479 }
1480
1481 /* "router bgp" commands. */
1482 DEFUN_NOSH (router_bgp,
1483 router_bgp_cmd,
1484 "router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME]]",
1485 ROUTER_STR
1486 BGP_STR
1487 AS_STR
1488 BGP_INSTANCE_HELP_STR)
1489 {
1490 int idx_asn = 2;
1491 int idx_view_vrf = 3;
1492 int idx_vrf = 4;
1493 int is_new_bgp = 0;
1494 int ret;
1495 as_t as;
1496 struct bgp *bgp;
1497 const char *name = NULL;
1498 enum bgp_instance_type inst_type;
1499
1500 // "router bgp" without an ASN
1501 if (argc == 2) {
1502 // Pending: Make VRF option available for ASN less config
1503 bgp = bgp_get_default();
1504
1505 if (bgp == NULL) {
1506 vty_out(vty, "%% No BGP process is configured\n");
1507 return CMD_WARNING_CONFIG_FAILED;
1508 }
1509
1510 if (listcount(bm->bgp) > 1) {
1511 vty_out(vty, "%% Please specify ASN and VRF\n");
1512 return CMD_WARNING_CONFIG_FAILED;
1513 }
1514 }
1515
1516 // "router bgp X"
1517 else {
1518 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1519 vty_out(vty, "%% BGP: No such AS %s\n",
1520 argv[idx_asn]->arg);
1521 return CMD_WARNING_CONFIG_FAILED;
1522 }
1523
1524 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1525 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1526 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1527
1528 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1529 if (argc > 3) {
1530 name = argv[idx_vrf]->arg;
1531
1532 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1533 if (strmatch(name, VRF_DEFAULT_NAME))
1534 name = NULL;
1535 else
1536 inst_type = BGP_INSTANCE_TYPE_VRF;
1537 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1538 inst_type = BGP_INSTANCE_TYPE_VIEW;
1539 }
1540
1541 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1542 is_new_bgp = (bgp_lookup(as, name) == NULL);
1543
1544 ret = bgp_get_vty(&bgp, &as, name, inst_type,
1545 argv[idx_asn]->arg);
1546 switch (ret) {
1547 case BGP_ERR_AS_MISMATCH:
1548 vty_out(vty, "BGP is already running; AS is %s\n",
1549 bgp->as_pretty);
1550 return CMD_WARNING_CONFIG_FAILED;
1551 case BGP_ERR_INSTANCE_MISMATCH:
1552 vty_out(vty,
1553 "BGP instance name and AS number mismatch\n");
1554 vty_out(vty,
1555 "BGP instance is already running; AS is %s\n",
1556 bgp->as_pretty);
1557 return CMD_WARNING_CONFIG_FAILED;
1558 }
1559
1560 /*
1561 * If we just instantiated the default instance, complete
1562 * any pending VRF-VPN leaking that was configured via
1563 * earlier "router bgp X vrf FOO" blocks.
1564 */
1565 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1566 vpn_leak_postchange_all();
1567
1568 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1569 bgp_vpn_leak_export(bgp);
1570 /* Pending: handle when user tries to change a view to vrf n vv.
1571 */
1572 }
1573
1574 /* unset the auto created flag as the user config is now present */
1575 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1576 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1577
1578 return CMD_SUCCESS;
1579 }
1580
1581 /* "no router bgp" commands. */
1582 DEFUN (no_router_bgp,
1583 no_router_bgp_cmd,
1584 "no router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME]]",
1585 NO_STR
1586 ROUTER_STR
1587 BGP_STR
1588 AS_STR
1589 BGP_INSTANCE_HELP_STR)
1590 {
1591 int idx_asn = 3;
1592 int idx_vrf = 5;
1593 as_t as;
1594 struct bgp *bgp;
1595 const char *name = NULL;
1596
1597 // "no router bgp" without an ASN
1598 if (argc == 3) {
1599 // Pending: Make VRF option available for ASN less config
1600 bgp = bgp_get_default();
1601
1602 if (bgp == NULL) {
1603 vty_out(vty, "%% No BGP process is configured\n");
1604 return CMD_WARNING_CONFIG_FAILED;
1605 }
1606
1607 if (listcount(bm->bgp) > 1) {
1608 vty_out(vty, "%% Please specify ASN and VRF\n");
1609 return CMD_WARNING_CONFIG_FAILED;
1610 }
1611
1612 if (bgp->l3vni) {
1613 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1614 bgp->l3vni);
1615 return CMD_WARNING_CONFIG_FAILED;
1616 }
1617 } else {
1618 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1619 vty_out(vty, "%% BGP: No such AS %s\n",
1620 argv[idx_asn]->arg);
1621 return CMD_WARNING_CONFIG_FAILED;
1622 }
1623 if (argc > 4) {
1624 name = argv[idx_vrf]->arg;
1625 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1626 && strmatch(name, VRF_DEFAULT_NAME))
1627 name = NULL;
1628 }
1629
1630 /* Lookup bgp structure. */
1631 bgp = bgp_lookup(as, name);
1632 if (!bgp) {
1633 vty_out(vty, "%% Can't find BGP instance\n");
1634 return CMD_WARNING_CONFIG_FAILED;
1635 }
1636
1637 if (bgp->l3vni) {
1638 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1639 bgp->l3vni);
1640 return CMD_WARNING_CONFIG_FAILED;
1641 }
1642
1643 /* Cannot delete default instance if vrf instances exist */
1644 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1645 struct listnode *node;
1646 struct bgp *tmp_bgp;
1647
1648 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1649 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1650 continue;
1651 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1652 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1653 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1654 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1655 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1656 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1657 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1658 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1659 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1660 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1661 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1662 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1663 (bgp == bgp_get_evpn() &&
1664 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1665 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1666 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1667 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1668 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1669 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1670 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1671 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1672 (hashcount(tmp_bgp->vnihash))) {
1673 vty_out(vty,
1674 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1675 return CMD_WARNING_CONFIG_FAILED;
1676 }
1677 }
1678 }
1679 }
1680
1681 bgp_delete(bgp);
1682
1683 return CMD_SUCCESS;
1684 }
1685
1686 /* bgp session-dscp */
1687
1688 DEFPY (bgp_session_dscp,
1689 bgp_session_dscp_cmd,
1690 "bgp session-dscp (0-63)$dscp",
1691 BGP_STR
1692 "Override default (C6) bgp TCP session DSCP value\n"
1693 "Manually configured dscp parameter\n")
1694 {
1695 bm->tcp_dscp = dscp << 2;
1696
1697 return CMD_SUCCESS;
1698 }
1699
1700 DEFPY (no_bgp_session_dscp,
1701 no_bgp_session_dscp_cmd,
1702 "no bgp session-dscp [(0-63)]",
1703 NO_STR
1704 BGP_STR
1705 "Override default (C6) bgp TCP session DSCP value\n"
1706 "Manually configured dscp parameter\n")
1707 {
1708 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1709
1710 return CMD_SUCCESS;
1711 }
1712
1713 /* BGP router-id. */
1714
1715 DEFPY (bgp_router_id,
1716 bgp_router_id_cmd,
1717 "bgp router-id A.B.C.D",
1718 BGP_STR
1719 "Override configured router identifier\n"
1720 "Manually configured router identifier\n")
1721 {
1722 VTY_DECLVAR_CONTEXT(bgp, bgp);
1723 bgp_router_id_static_set(bgp, router_id);
1724 return CMD_SUCCESS;
1725 }
1726
1727 DEFPY (no_bgp_router_id,
1728 no_bgp_router_id_cmd,
1729 "no bgp router-id [A.B.C.D]",
1730 NO_STR
1731 BGP_STR
1732 "Override configured router identifier\n"
1733 "Manually configured router identifier\n")
1734 {
1735 VTY_DECLVAR_CONTEXT(bgp, bgp);
1736
1737 if (router_id_str) {
1738 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1739 vty_out(vty, "%% BGP router-id doesn't match\n");
1740 return CMD_WARNING_CONFIG_FAILED;
1741 }
1742 }
1743
1744 router_id.s_addr = 0;
1745 bgp_router_id_static_set(bgp, router_id);
1746
1747 return CMD_SUCCESS;
1748 }
1749
1750 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1751 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1752 NO_STR BGP_STR
1753 "Add community specific parameters\n"
1754 "Create an alias for a community\n"
1755 "Community (AA:BB or AA:BB:CC)\n"
1756 "Alias name\n")
1757 {
1758 struct community_alias ca = {};
1759 struct community_alias *lookup_community;
1760 struct community_alias *lookup_alias;
1761 struct community *comm;
1762 struct lcommunity *lcomm;
1763 uint8_t invalid = 0;
1764
1765 comm = community_str2com(community);
1766 if (!comm)
1767 invalid++;
1768 community_free(&comm);
1769
1770 lcomm = lcommunity_str2com(community);
1771 if (!lcomm)
1772 invalid++;
1773 lcommunity_free(&lcomm);
1774
1775 if (invalid > 1) {
1776 vty_out(vty, "Invalid community format\n");
1777 return CMD_WARNING;
1778 }
1779
1780 strlcpy(ca.community, community, sizeof(ca.community));
1781 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1782
1783 lookup_community = bgp_ca_community_lookup(&ca);
1784 lookup_alias = bgp_ca_alias_lookup(&ca);
1785
1786 if (no) {
1787 bgp_ca_alias_delete(&ca);
1788 bgp_ca_community_delete(&ca);
1789 } else {
1790 if (lookup_alias) {
1791 /* Lookup if community hash table has an item
1792 * with the same alias name.
1793 */
1794 strlcpy(ca.community, lookup_alias->community,
1795 sizeof(ca.community));
1796 if (bgp_ca_community_lookup(&ca)) {
1797 vty_out(vty,
1798 "community (%s) already has this alias (%s)\n",
1799 lookup_alias->community,
1800 lookup_alias->alias);
1801 return CMD_WARNING;
1802 }
1803 bgp_ca_alias_delete(&ca);
1804 }
1805
1806 if (lookup_community) {
1807 /* Lookup if alias hash table has an item
1808 * with the same community.
1809 */
1810 strlcpy(ca.alias, lookup_community->alias,
1811 sizeof(ca.alias));
1812 if (bgp_ca_alias_lookup(&ca)) {
1813 vty_out(vty,
1814 "alias (%s) already has this community (%s)\n",
1815 lookup_community->alias,
1816 lookup_community->community);
1817 return CMD_WARNING;
1818 }
1819 bgp_ca_community_delete(&ca);
1820 }
1821
1822 bgp_ca_alias_insert(&ca);
1823 bgp_ca_community_insert(&ca);
1824 }
1825
1826 return CMD_SUCCESS;
1827 }
1828
1829 DEFPY (bgp_global_suppress_fib_pending,
1830 bgp_global_suppress_fib_pending_cmd,
1831 "[no] bgp suppress-fib-pending",
1832 NO_STR
1833 BGP_STR
1834 "Advertise only routes that are programmed in kernel to peers globally\n")
1835 {
1836 bm_wait_for_fib_set(!no);
1837
1838 return CMD_SUCCESS;
1839 }
1840
1841 DEFPY (bgp_suppress_fib_pending,
1842 bgp_suppress_fib_pending_cmd,
1843 "[no] bgp suppress-fib-pending",
1844 NO_STR
1845 BGP_STR
1846 "Advertise only routes that are programmed in kernel to peers\n")
1847 {
1848 VTY_DECLVAR_CONTEXT(bgp, bgp);
1849
1850 bgp_suppress_fib_pending_set(bgp, !no);
1851 return CMD_SUCCESS;
1852 }
1853
1854
1855 /* BGP Cluster ID. */
1856 DEFUN (bgp_cluster_id,
1857 bgp_cluster_id_cmd,
1858 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1859 BGP_STR
1860 "Configure Route-Reflector Cluster-id\n"
1861 "Route-Reflector Cluster-id in IP address format\n"
1862 "Route-Reflector Cluster-id as 32 bit quantity\n")
1863 {
1864 VTY_DECLVAR_CONTEXT(bgp, bgp);
1865 int idx_ipv4 = 2;
1866 int ret;
1867 struct in_addr cluster;
1868
1869 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1870 if (!ret) {
1871 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1872 return CMD_WARNING_CONFIG_FAILED;
1873 }
1874
1875 bgp_cluster_id_set(bgp, &cluster);
1876 bgp_clear_star_soft_out(vty, bgp->name);
1877
1878 return CMD_SUCCESS;
1879 }
1880
1881 DEFUN (no_bgp_cluster_id,
1882 no_bgp_cluster_id_cmd,
1883 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1884 NO_STR
1885 BGP_STR
1886 "Configure Route-Reflector Cluster-id\n"
1887 "Route-Reflector Cluster-id in IP address format\n"
1888 "Route-Reflector Cluster-id as 32 bit quantity\n")
1889 {
1890 VTY_DECLVAR_CONTEXT(bgp, bgp);
1891 bgp_cluster_id_unset(bgp);
1892 bgp_clear_star_soft_out(vty, bgp->name);
1893
1894 return CMD_SUCCESS;
1895 }
1896
1897 DEFPY (bgp_norib,
1898 bgp_norib_cmd,
1899 "bgp no-rib",
1900 BGP_STR
1901 "Disable BGP route installation to RIB (Zebra)\n")
1902 {
1903 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1904 vty_out(vty,
1905 "%% No-RIB option is already set, nothing to do here.\n");
1906 return CMD_SUCCESS;
1907 }
1908
1909 bgp_option_norib_set_runtime();
1910
1911 return CMD_SUCCESS;
1912 }
1913
1914 DEFPY (no_bgp_norib,
1915 no_bgp_norib_cmd,
1916 "no bgp no-rib",
1917 NO_STR
1918 BGP_STR
1919 "Disable BGP route installation to RIB (Zebra)\n")
1920 {
1921 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1922 vty_out(vty,
1923 "%% No-RIB option is not set, nothing to do here.\n");
1924 return CMD_SUCCESS;
1925 }
1926
1927 bgp_option_norib_unset_runtime();
1928
1929 return CMD_SUCCESS;
1930 }
1931
1932 DEFPY (no_bgp_send_extra_data,
1933 no_bgp_send_extra_data_cmd,
1934 "[no] bgp send-extra-data zebra",
1935 NO_STR
1936 BGP_STR
1937 "Extra data to Zebra for display/use\n"
1938 "To zebra\n")
1939 {
1940 if (no)
1941 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1942 else
1943 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1944
1945 return CMD_SUCCESS;
1946 }
1947
1948 DEFUN (bgp_confederation_identifier,
1949 bgp_confederation_identifier_cmd,
1950 "bgp confederation identifier ASNUM",
1951 BGP_STR
1952 "AS confederation parameters\n"
1953 AS_STR
1954 "Set routing domain confederation AS\n")
1955 {
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957 int idx_number = 3;
1958 as_t as;
1959
1960 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
1961 vty_out(vty, "%% BGP: No such AS %s\n", argv[idx_number]->arg);
1962 return CMD_WARNING_CONFIG_FAILED;
1963 }
1964
1965 bgp_confederation_id_set(bgp, as);
1966
1967 return CMD_SUCCESS;
1968 }
1969
1970 DEFUN (no_bgp_confederation_identifier,
1971 no_bgp_confederation_identifier_cmd,
1972 "no bgp confederation identifier [ASNUM]",
1973 NO_STR
1974 BGP_STR
1975 "AS confederation parameters\n"
1976 AS_STR
1977 "Set routing domain confederation AS\n")
1978 {
1979 VTY_DECLVAR_CONTEXT(bgp, bgp);
1980 bgp_confederation_id_unset(bgp);
1981
1982 return CMD_SUCCESS;
1983 }
1984
1985 DEFUN (bgp_confederation_peers,
1986 bgp_confederation_peers_cmd,
1987 "bgp confederation peers ASNUM...",
1988 BGP_STR
1989 "AS confederation parameters\n"
1990 "Peer ASs in BGP confederation\n"
1991 AS_STR)
1992 {
1993 VTY_DECLVAR_CONTEXT(bgp, bgp);
1994 int idx_asn = 3;
1995 as_t as;
1996 int i;
1997
1998 for (i = idx_asn; i < argc; i++) {
1999 if (!asn_str2asn(argv[i]->arg, &as)) {
2000 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2001 argv[i]->arg);
2002 continue;
2003 }
2004
2005 bgp_confederation_peers_add(bgp, as);
2006 }
2007 return CMD_SUCCESS;
2008 }
2009
2010 DEFUN (no_bgp_confederation_peers,
2011 no_bgp_confederation_peers_cmd,
2012 "no bgp confederation peers ASNUM...",
2013 NO_STR
2014 BGP_STR
2015 "AS confederation parameters\n"
2016 "Peer ASs in BGP confederation\n"
2017 AS_STR)
2018 {
2019 VTY_DECLVAR_CONTEXT(bgp, bgp);
2020 int idx_asn = 4;
2021 as_t as;
2022 int i;
2023
2024 for (i = idx_asn; i < argc; i++) {
2025 if (!asn_str2asn(argv[i]->arg, &as)) {
2026 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2027 argv[i]->arg);
2028 continue;
2029 }
2030 bgp_confederation_peers_remove(bgp, as);
2031 }
2032 return CMD_SUCCESS;
2033 }
2034
2035 /**
2036 * Central routine for maximum-paths configuration.
2037 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
2038 * @set: 1 for setting values, 0 for removing the max-paths config.
2039 */
2040 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2041 const char *mpaths, uint16_t options,
2042 int set)
2043 {
2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 uint16_t maxpaths = 0;
2046 int ret;
2047 afi_t afi;
2048 safi_t safi;
2049
2050 afi = bgp_node_afi(vty);
2051 safi = bgp_node_safi(vty);
2052
2053 if (set) {
2054 maxpaths = strtol(mpaths, NULL, 10);
2055 if (maxpaths > multipath_num) {
2056 vty_out(vty,
2057 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2058 maxpaths, multipath_num);
2059 return CMD_WARNING_CONFIG_FAILED;
2060 }
2061 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2062 options);
2063 } else
2064 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2065
2066 if (ret < 0) {
2067 vty_out(vty,
2068 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2069 (set == 1) ? "" : "un",
2070 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2071 maxpaths, afi, safi);
2072 return CMD_WARNING_CONFIG_FAILED;
2073 }
2074
2075 bgp_recalculate_all_bestpaths(bgp);
2076
2077 return CMD_SUCCESS;
2078 }
2079
2080 DEFUN (bgp_maxmed_admin,
2081 bgp_maxmed_admin_cmd,
2082 "bgp max-med administrative ",
2083 BGP_STR
2084 "Advertise routes with max-med\n"
2085 "Administratively applied, for an indefinite period\n")
2086 {
2087 VTY_DECLVAR_CONTEXT(bgp, bgp);
2088
2089 bgp->v_maxmed_admin = 1;
2090 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2091
2092 bgp_maxmed_update(bgp);
2093
2094 return CMD_SUCCESS;
2095 }
2096
2097 DEFUN (bgp_maxmed_admin_medv,
2098 bgp_maxmed_admin_medv_cmd,
2099 "bgp max-med administrative (0-4294967295)",
2100 BGP_STR
2101 "Advertise routes with max-med\n"
2102 "Administratively applied, for an indefinite period\n"
2103 "Max MED value to be used\n")
2104 {
2105 VTY_DECLVAR_CONTEXT(bgp, bgp);
2106 int idx_number = 3;
2107
2108 bgp->v_maxmed_admin = 1;
2109 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2110
2111 bgp_maxmed_update(bgp);
2112
2113 return CMD_SUCCESS;
2114 }
2115
2116 DEFUN (no_bgp_maxmed_admin,
2117 no_bgp_maxmed_admin_cmd,
2118 "no bgp max-med administrative [(0-4294967295)]",
2119 NO_STR
2120 BGP_STR
2121 "Advertise routes with max-med\n"
2122 "Administratively applied, for an indefinite period\n"
2123 "Max MED value to be used\n")
2124 {
2125 VTY_DECLVAR_CONTEXT(bgp, bgp);
2126 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2127 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2128 bgp_maxmed_update(bgp);
2129
2130 return CMD_SUCCESS;
2131 }
2132
2133 DEFUN (bgp_maxmed_onstartup,
2134 bgp_maxmed_onstartup_cmd,
2135 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2136 BGP_STR
2137 "Advertise routes with max-med\n"
2138 "Effective on a startup\n"
2139 "Time (seconds) period for max-med\n"
2140 "Max MED value to be used\n")
2141 {
2142 VTY_DECLVAR_CONTEXT(bgp, bgp);
2143 int idx = 0;
2144
2145 if (argv_find(argv, argc, "(5-86400)", &idx))
2146 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2147 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2148 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2149 else
2150 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2151
2152 bgp_maxmed_update(bgp);
2153
2154 return CMD_SUCCESS;
2155 }
2156
2157 DEFUN (no_bgp_maxmed_onstartup,
2158 no_bgp_maxmed_onstartup_cmd,
2159 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2160 NO_STR
2161 BGP_STR
2162 "Advertise routes with max-med\n"
2163 "Effective on a startup\n"
2164 "Time (seconds) period for max-med\n"
2165 "Max MED value to be used\n")
2166 {
2167 VTY_DECLVAR_CONTEXT(bgp, bgp);
2168
2169 /* Cancel max-med onstartup if its on */
2170 if (bgp->t_maxmed_onstartup) {
2171 THREAD_OFF(bgp->t_maxmed_onstartup);
2172 bgp->maxmed_onstartup_over = 1;
2173 }
2174
2175 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2176 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2177
2178 bgp_maxmed_update(bgp);
2179
2180 return CMD_SUCCESS;
2181 }
2182
2183 static int bgp_global_update_delay_config_vty(struct vty *vty,
2184 uint16_t update_delay,
2185 uint16_t establish_wait)
2186 {
2187 struct listnode *node, *nnode;
2188 struct bgp *bgp;
2189 bool vrf_cfg = false;
2190
2191 /*
2192 * See if update-delay is set per-vrf and warn user to delete it
2193 * Note that we only need to check this if this is the first time
2194 * setting the global config.
2195 */
2196 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2197 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2198 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2199 vty_out(vty,
2200 "%% update-delay configuration found in vrf %s\n",
2201 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2202 ? VRF_DEFAULT_NAME
2203 : bgp->name);
2204 vrf_cfg = true;
2205 }
2206 }
2207 }
2208
2209 if (vrf_cfg) {
2210 vty_out(vty,
2211 "%%Failed: global update-delay config not permitted\n");
2212 return CMD_WARNING;
2213 }
2214
2215 if (!establish_wait) { /* update-delay <delay> */
2216 bm->v_update_delay = update_delay;
2217 bm->v_establish_wait = bm->v_update_delay;
2218 } else {
2219 /* update-delay <delay> <establish-wait> */
2220 if (update_delay < establish_wait) {
2221 vty_out(vty,
2222 "%%Failed: update-delay less than the establish-wait!\n");
2223 return CMD_WARNING_CONFIG_FAILED;
2224 }
2225
2226 bm->v_update_delay = update_delay;
2227 bm->v_establish_wait = establish_wait;
2228 }
2229
2230 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2231 bgp->v_update_delay = bm->v_update_delay;
2232 bgp->v_establish_wait = bm->v_establish_wait;
2233 }
2234
2235 return CMD_SUCCESS;
2236 }
2237
2238 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2239 {
2240 struct listnode *node, *nnode;
2241 struct bgp *bgp;
2242
2243 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2244 bm->v_establish_wait = bm->v_update_delay;
2245
2246 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2247 bgp->v_update_delay = bm->v_update_delay;
2248 bgp->v_establish_wait = bm->v_establish_wait;
2249 }
2250
2251 return CMD_SUCCESS;
2252 }
2253
2254 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2255 uint16_t establish_wait)
2256 {
2257 VTY_DECLVAR_CONTEXT(bgp, bgp);
2258
2259 /* if configured globally, per-instance config is not allowed */
2260 if (bm->v_update_delay) {
2261 vty_out(vty,
2262 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2263 return CMD_WARNING_CONFIG_FAILED;
2264 }
2265
2266
2267 if (!establish_wait) /* update-delay <delay> */
2268 {
2269 bgp->v_update_delay = update_delay;
2270 bgp->v_establish_wait = bgp->v_update_delay;
2271 return CMD_SUCCESS;
2272 }
2273
2274 /* update-delay <delay> <establish-wait> */
2275 if (update_delay < establish_wait) {
2276 vty_out(vty,
2277 "%%Failed: update-delay less than the establish-wait!\n");
2278 return CMD_WARNING_CONFIG_FAILED;
2279 }
2280
2281 bgp->v_update_delay = update_delay;
2282 bgp->v_establish_wait = establish_wait;
2283
2284 return CMD_SUCCESS;
2285 }
2286
2287 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2288 {
2289 VTY_DECLVAR_CONTEXT(bgp, bgp);
2290
2291 /* If configured globally, cannot remove from one bgp instance */
2292 if (bm->v_update_delay) {
2293 vty_out(vty,
2294 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2295 return CMD_WARNING_CONFIG_FAILED;
2296 }
2297 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2298 bgp->v_establish_wait = bgp->v_update_delay;
2299
2300 return CMD_SUCCESS;
2301 }
2302
2303 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2304 {
2305 /* If configured globally, no need to display per-instance value */
2306 if (bgp->v_update_delay != bm->v_update_delay) {
2307 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2308 if (bgp->v_update_delay != bgp->v_establish_wait)
2309 vty_out(vty, " %d", bgp->v_establish_wait);
2310 vty_out(vty, "\n");
2311 }
2312 }
2313
2314 /* Global update-delay configuration */
2315 DEFPY (bgp_global_update_delay,
2316 bgp_global_update_delay_cmd,
2317 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2318 BGP_STR
2319 "Force initial delay for best-path and updates for all bgp instances\n"
2320 "Max delay in seconds\n"
2321 "Establish wait in seconds\n")
2322 {
2323 return bgp_global_update_delay_config_vty(vty, delay, wait);
2324 }
2325
2326 /* Global update-delay deconfiguration */
2327 DEFPY (no_bgp_global_update_delay,
2328 no_bgp_global_update_delay_cmd,
2329 "no bgp update-delay [(0-3600) [(1-3600)]]",
2330 NO_STR
2331 BGP_STR
2332 "Force initial delay for best-path and updates\n"
2333 "Max delay in seconds\n"
2334 "Establish wait in seconds\n")
2335 {
2336 return bgp_global_update_delay_deconfig_vty(vty);
2337 }
2338
2339 /* Update-delay configuration */
2340
2341 DEFPY (bgp_update_delay,
2342 bgp_update_delay_cmd,
2343 "update-delay (0-3600)$delay [(1-3600)$wait]",
2344 "Force initial delay for best-path and updates\n"
2345 "Max delay in seconds\n"
2346 "Establish wait in seconds\n")
2347 {
2348 return bgp_update_delay_config_vty(vty, delay, wait);
2349 }
2350
2351 /* Update-delay deconfiguration */
2352 DEFPY (no_bgp_update_delay,
2353 no_bgp_update_delay_cmd,
2354 "no update-delay [(0-3600) [(1-3600)]]",
2355 NO_STR
2356 "Force initial delay for best-path and updates\n"
2357 "Max delay in seconds\n"
2358 "Establish wait in seconds\n")
2359 {
2360 return bgp_update_delay_deconfig_vty(vty);
2361 }
2362
2363
2364 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2365 bool set)
2366 {
2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368
2369 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2370 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2371
2372 return CMD_SUCCESS;
2373 }
2374
2375 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2376 bool set)
2377 {
2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379
2380 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2381 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2382
2383 return CMD_SUCCESS;
2384 }
2385
2386 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2387 {
2388 uint32_t quanta =
2389 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2390 if (quanta != BGP_WRITE_PACKET_MAX)
2391 vty_out(vty, " write-quanta %d\n", quanta);
2392 }
2393
2394 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2395 {
2396 uint32_t quanta =
2397 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2398 if (quanta != BGP_READ_PACKET_MAX)
2399 vty_out(vty, " read-quanta %d\n", quanta);
2400 }
2401
2402 /* Packet quanta configuration
2403 *
2404 * XXX: The value set here controls the size of a stack buffer in the IO
2405 * thread. When changing these limits be careful to prevent stack overflow.
2406 *
2407 * Furthermore, the maximums used here should correspond to
2408 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2409 */
2410 DEFPY (bgp_wpkt_quanta,
2411 bgp_wpkt_quanta_cmd,
2412 "[no] write-quanta (1-64)$quanta",
2413 NO_STR
2414 "How many packets to write to peer socket per run\n"
2415 "Number of packets\n")
2416 {
2417 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2418 }
2419
2420 DEFPY (bgp_rpkt_quanta,
2421 bgp_rpkt_quanta_cmd,
2422 "[no] read-quanta (1-10)$quanta",
2423 NO_STR
2424 "How many packets to read from peer socket per I/O cycle\n"
2425 "Number of packets\n")
2426 {
2427 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2428 }
2429
2430 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2431 {
2432 if (!bgp->heuristic_coalesce)
2433 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2434 }
2435
2436 /* BGP TCP keepalive */
2437 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2438 {
2439 if (bgp->tcp_keepalive_idle) {
2440 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2441 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2442 bgp->tcp_keepalive_probes);
2443 }
2444 }
2445
2446 DEFUN (bgp_coalesce_time,
2447 bgp_coalesce_time_cmd,
2448 "coalesce-time (0-4294967295)",
2449 "Subgroup coalesce timer\n"
2450 "Subgroup coalesce timer value (in ms)\n")
2451 {
2452 VTY_DECLVAR_CONTEXT(bgp, bgp);
2453
2454 int idx = 0;
2455
2456 bgp->heuristic_coalesce = false;
2457
2458 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2459 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2460
2461 return CMD_SUCCESS;
2462 }
2463
2464 DEFUN (no_bgp_coalesce_time,
2465 no_bgp_coalesce_time_cmd,
2466 "no coalesce-time (0-4294967295)",
2467 NO_STR
2468 "Subgroup coalesce timer\n"
2469 "Subgroup coalesce timer value (in ms)\n")
2470 {
2471 VTY_DECLVAR_CONTEXT(bgp, bgp);
2472
2473 bgp->heuristic_coalesce = true;
2474 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2475 return CMD_SUCCESS;
2476 }
2477
2478 /* Maximum-paths configuration */
2479 DEFUN (bgp_maxpaths,
2480 bgp_maxpaths_cmd,
2481 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2482 "Forward packets over multiple paths\n"
2483 "Number of paths\n")
2484 {
2485 int idx_number = 1;
2486 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2487 argv[idx_number]->arg, 0, 1);
2488 }
2489
2490 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2491 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2492 "Forward packets over multiple paths\n"
2493 "Number of paths\n")
2494
2495 DEFUN (bgp_maxpaths_ibgp,
2496 bgp_maxpaths_ibgp_cmd,
2497 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2498 "Forward packets over multiple paths\n"
2499 "iBGP-multipath\n"
2500 "Number of paths\n")
2501 {
2502 int idx_number = 2;
2503 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2504 argv[idx_number]->arg, 0, 1);
2505 }
2506
2507 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2508 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2509 "Forward packets over multiple paths\n"
2510 "iBGP-multipath\n"
2511 "Number of paths\n")
2512
2513 DEFUN (bgp_maxpaths_ibgp_cluster,
2514 bgp_maxpaths_ibgp_cluster_cmd,
2515 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2516 "Forward packets over multiple paths\n"
2517 "iBGP-multipath\n"
2518 "Number of paths\n"
2519 "Match the cluster length\n")
2520 {
2521 int idx_number = 2;
2522 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2523 argv[idx_number]->arg, true, 1);
2524 }
2525
2526 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2527 "maximum-paths ibgp " CMD_RANGE_STR(
2528 1, MULTIPATH_NUM) " equal-cluster-length",
2529 "Forward packets over multiple paths\n"
2530 "iBGP-multipath\n"
2531 "Number of paths\n"
2532 "Match the cluster length\n")
2533
2534 DEFUN (no_bgp_maxpaths,
2535 no_bgp_maxpaths_cmd,
2536 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2537 NO_STR
2538 "Forward packets over multiple paths\n"
2539 "Number of paths\n")
2540 {
2541 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2542 }
2543
2544 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2545 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2546 "Forward packets over multiple paths\n"
2547 "Number of paths\n")
2548
2549 DEFUN (no_bgp_maxpaths_ibgp,
2550 no_bgp_maxpaths_ibgp_cmd,
2551 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2552 NO_STR
2553 "Forward packets over multiple paths\n"
2554 "iBGP-multipath\n"
2555 "Number of paths\n"
2556 "Match the cluster length\n")
2557 {
2558 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2559 }
2560
2561 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2562 "no maximum-paths ibgp [" CMD_RANGE_STR(
2563 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2564 NO_STR
2565 "Forward packets over multiple paths\n"
2566 "iBGP-multipath\n"
2567 "Number of paths\n"
2568 "Match the cluster length\n")
2569
2570 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2571 afi_t afi, safi_t safi)
2572 {
2573 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2574 vty_out(vty, " maximum-paths %d\n",
2575 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2576 }
2577
2578 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2579 vty_out(vty, " maximum-paths ibgp %d",
2580 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2581 if (bgp->maxpaths[afi][safi].same_clusterlen)
2582 vty_out(vty, " equal-cluster-length");
2583 vty_out(vty, "\n");
2584 }
2585 }
2586
2587 /* BGP timers. */
2588
2589 DEFUN (bgp_timers,
2590 bgp_timers_cmd,
2591 "timers bgp (0-65535) (0-65535)",
2592 "Adjust routing timers\n"
2593 "BGP timers\n"
2594 "Keepalive interval\n"
2595 "Holdtime\n")
2596 {
2597 VTY_DECLVAR_CONTEXT(bgp, bgp);
2598 int idx_number = 2;
2599 int idx_number_2 = 3;
2600 unsigned long keepalive = 0;
2601 unsigned long holdtime = 0;
2602
2603 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2604 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2605
2606 /* Holdtime value check. */
2607 if (holdtime < 3 && holdtime != 0) {
2608 vty_out(vty,
2609 "%% hold time value must be either 0 or greater than 3\n");
2610 return CMD_WARNING_CONFIG_FAILED;
2611 }
2612
2613 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2614 BGP_DEFAULT_DELAYOPEN);
2615
2616 return CMD_SUCCESS;
2617 }
2618
2619 DEFUN (no_bgp_timers,
2620 no_bgp_timers_cmd,
2621 "no timers bgp [(0-65535) (0-65535)]",
2622 NO_STR
2623 "Adjust routing timers\n"
2624 "BGP timers\n"
2625 "Keepalive interval\n"
2626 "Holdtime\n")
2627 {
2628 VTY_DECLVAR_CONTEXT(bgp, bgp);
2629 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2630 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2631
2632 return CMD_SUCCESS;
2633 }
2634
2635 /* BGP minimum holdtime. */
2636
2637 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2638 "bgp minimum-holdtime (1-65535)",
2639 "BGP specific commands\n"
2640 "BGP minimum holdtime\n"
2641 "Seconds\n")
2642 {
2643 VTY_DECLVAR_CONTEXT(bgp, bgp);
2644 int idx_number = 2;
2645 unsigned long min_holdtime;
2646
2647 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2648
2649 bgp->default_min_holdtime = min_holdtime;
2650
2651 return CMD_SUCCESS;
2652 }
2653
2654 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2655 "no bgp minimum-holdtime [(1-65535)]",
2656 NO_STR
2657 "BGP specific commands\n"
2658 "BGP minimum holdtime\n"
2659 "Seconds\n")
2660 {
2661 VTY_DECLVAR_CONTEXT(bgp, bgp);
2662
2663 bgp->default_min_holdtime = 0;
2664
2665 return CMD_SUCCESS;
2666 }
2667
2668 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2669 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2670 BGP_STR
2671 "TCP keepalive parameters\n"
2672 "TCP keepalive idle time (seconds)\n"
2673 "TCP keepalive interval (seconds)\n"
2674 "TCP keepalive maximum probes\n")
2675 {
2676 VTY_DECLVAR_CONTEXT(bgp, bgp);
2677
2678 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2679 (uint16_t)probes);
2680
2681 return CMD_SUCCESS;
2682 }
2683
2684 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2685 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2686 NO_STR
2687 BGP_STR
2688 "TCP keepalive parameters\n"
2689 "TCP keepalive idle time (seconds)\n"
2690 "TCP keepalive interval (seconds)\n"
2691 "TCP keepalive maximum probes\n")
2692 {
2693 VTY_DECLVAR_CONTEXT(bgp, bgp);
2694
2695 bgp_tcp_keepalive_unset(bgp);
2696
2697 return CMD_SUCCESS;
2698 }
2699
2700 DEFUN (bgp_client_to_client_reflection,
2701 bgp_client_to_client_reflection_cmd,
2702 "bgp client-to-client reflection",
2703 BGP_STR
2704 "Configure client to client route reflection\n"
2705 "reflection of routes allowed\n")
2706 {
2707 VTY_DECLVAR_CONTEXT(bgp, bgp);
2708 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2709 bgp_clear_star_soft_out(vty, bgp->name);
2710
2711 return CMD_SUCCESS;
2712 }
2713
2714 DEFUN (no_bgp_client_to_client_reflection,
2715 no_bgp_client_to_client_reflection_cmd,
2716 "no bgp client-to-client reflection",
2717 NO_STR
2718 BGP_STR
2719 "Configure client to client route reflection\n"
2720 "reflection of routes allowed\n")
2721 {
2722 VTY_DECLVAR_CONTEXT(bgp, bgp);
2723 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2724 bgp_clear_star_soft_out(vty, bgp->name);
2725
2726 return CMD_SUCCESS;
2727 }
2728
2729 /* "bgp always-compare-med" configuration. */
2730 DEFUN (bgp_always_compare_med,
2731 bgp_always_compare_med_cmd,
2732 "bgp always-compare-med",
2733 BGP_STR
2734 "Allow comparing MED from different neighbors\n")
2735 {
2736 VTY_DECLVAR_CONTEXT(bgp, bgp);
2737 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2738 bgp_recalculate_all_bestpaths(bgp);
2739
2740 return CMD_SUCCESS;
2741 }
2742
2743 DEFUN (no_bgp_always_compare_med,
2744 no_bgp_always_compare_med_cmd,
2745 "no bgp always-compare-med",
2746 NO_STR
2747 BGP_STR
2748 "Allow comparing MED from different neighbors\n")
2749 {
2750 VTY_DECLVAR_CONTEXT(bgp, bgp);
2751 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2752 bgp_recalculate_all_bestpaths(bgp);
2753
2754 return CMD_SUCCESS;
2755 }
2756
2757
2758 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2759 "bgp ebgp-requires-policy",
2760 BGP_STR
2761 "Require in and out policy for eBGP peers (RFC8212)\n")
2762 {
2763 VTY_DECLVAR_CONTEXT(bgp, bgp);
2764 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2765 return CMD_SUCCESS;
2766 }
2767
2768 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2769 "no bgp ebgp-requires-policy",
2770 NO_STR
2771 BGP_STR
2772 "Require in and out policy for eBGP peers (RFC8212)\n")
2773 {
2774 VTY_DECLVAR_CONTEXT(bgp, bgp);
2775 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2776 return CMD_SUCCESS;
2777 }
2778
2779 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2780 "bgp suppress-duplicates",
2781 BGP_STR
2782 "Suppress duplicate updates if the route actually not changed\n")
2783 {
2784 VTY_DECLVAR_CONTEXT(bgp, bgp);
2785 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2786 return CMD_SUCCESS;
2787 }
2788
2789 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2790 "no bgp suppress-duplicates",
2791 NO_STR
2792 BGP_STR
2793 "Suppress duplicate updates if the route actually not changed\n")
2794 {
2795 VTY_DECLVAR_CONTEXT(bgp, bgp);
2796 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2797 return CMD_SUCCESS;
2798 }
2799
2800 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2801 "bgp reject-as-sets",
2802 BGP_STR
2803 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2804 {
2805 VTY_DECLVAR_CONTEXT(bgp, bgp);
2806 struct listnode *node, *nnode;
2807 struct peer *peer;
2808
2809 bgp->reject_as_sets = true;
2810
2811 /* Reset existing BGP sessions to reject routes
2812 * with aspath containing AS_SET or AS_CONFED_SET.
2813 */
2814 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2815 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2816 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2817 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2818 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2819 }
2820 }
2821
2822 return CMD_SUCCESS;
2823 }
2824
2825 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2826 "no bgp reject-as-sets",
2827 NO_STR
2828 BGP_STR
2829 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2830 {
2831 VTY_DECLVAR_CONTEXT(bgp, bgp);
2832 struct listnode *node, *nnode;
2833 struct peer *peer;
2834
2835 bgp->reject_as_sets = false;
2836
2837 /* Reset existing BGP sessions to reject routes
2838 * with aspath containing AS_SET or AS_CONFED_SET.
2839 */
2840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2841 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2842 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2843 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2844 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2845 }
2846 }
2847
2848 return CMD_SUCCESS;
2849 }
2850
2851 /* "bgp deterministic-med" configuration. */
2852 DEFUN (bgp_deterministic_med,
2853 bgp_deterministic_med_cmd,
2854 "bgp deterministic-med",
2855 BGP_STR
2856 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2857 {
2858 VTY_DECLVAR_CONTEXT(bgp, bgp);
2859
2860 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2861 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2862 bgp_recalculate_all_bestpaths(bgp);
2863 }
2864
2865 return CMD_SUCCESS;
2866 }
2867
2868 DEFUN (no_bgp_deterministic_med,
2869 no_bgp_deterministic_med_cmd,
2870 "no bgp deterministic-med",
2871 NO_STR
2872 BGP_STR
2873 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2874 {
2875 VTY_DECLVAR_CONTEXT(bgp, bgp);
2876 int bestpath_per_as_used;
2877 afi_t afi;
2878 safi_t safi;
2879 struct peer *peer;
2880 struct listnode *node, *nnode;
2881
2882 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2883 bestpath_per_as_used = 0;
2884
2885 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2886 FOREACH_AFI_SAFI (afi, safi)
2887 if (bgp_addpath_dmed_required(
2888 peer->addpath_type[afi][safi])) {
2889 bestpath_per_as_used = 1;
2890 break;
2891 }
2892
2893 if (bestpath_per_as_used)
2894 break;
2895 }
2896
2897 if (bestpath_per_as_used) {
2898 vty_out(vty,
2899 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2900 return CMD_WARNING_CONFIG_FAILED;
2901 } else {
2902 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2903 bgp_recalculate_all_bestpaths(bgp);
2904 }
2905 }
2906
2907 return CMD_SUCCESS;
2908 }
2909
2910 /* "bgp graceful-restart mode" configuration. */
2911 DEFUN (bgp_graceful_restart,
2912 bgp_graceful_restart_cmd,
2913 "bgp graceful-restart",
2914 BGP_STR
2915 GR_CMD
2916 )
2917 {
2918 int ret = BGP_GR_FAILURE;
2919
2920 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2921 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2922
2923 VTY_DECLVAR_CONTEXT(bgp, bgp);
2924
2925 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2926
2927 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2928 ret);
2929
2930 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2931 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2932 vty_out(vty,
2933 "Graceful restart configuration changed, reset all peers to take effect\n");
2934 return bgp_vty_return(vty, ret);
2935 }
2936
2937 DEFUN (no_bgp_graceful_restart,
2938 no_bgp_graceful_restart_cmd,
2939 "no bgp graceful-restart",
2940 NO_STR
2941 BGP_STR
2942 NO_GR_CMD
2943 )
2944 {
2945 VTY_DECLVAR_CONTEXT(bgp, bgp);
2946
2947 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2948 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2949
2950 int ret = BGP_GR_FAILURE;
2951
2952 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2953
2954 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2955 ret);
2956
2957 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2958 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2959 vty_out(vty,
2960 "Graceful restart configuration changed, reset all peers to take effect\n");
2961
2962 return bgp_vty_return(vty, ret);
2963 }
2964
2965 DEFUN (bgp_graceful_restart_stalepath_time,
2966 bgp_graceful_restart_stalepath_time_cmd,
2967 "bgp graceful-restart stalepath-time (1-4095)",
2968 BGP_STR
2969 "Graceful restart capability parameters\n"
2970 "Set the max time to hold onto restarting peer's stale paths\n"
2971 "Delay value (seconds)\n")
2972 {
2973 VTY_DECLVAR_CONTEXT(bgp, bgp);
2974 int idx_number = 3;
2975 uint32_t stalepath;
2976
2977 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2978 bgp->stalepath_time = stalepath;
2979 return CMD_SUCCESS;
2980 }
2981
2982 DEFUN (bgp_graceful_restart_restart_time,
2983 bgp_graceful_restart_restart_time_cmd,
2984 "bgp graceful-restart restart-time (0-4095)",
2985 BGP_STR
2986 "Graceful restart capability parameters\n"
2987 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2988 "Delay value (seconds)\n")
2989 {
2990 VTY_DECLVAR_CONTEXT(bgp, bgp);
2991 int idx_number = 3;
2992 uint32_t restart;
2993
2994 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2995 bgp->restart_time = restart;
2996 return CMD_SUCCESS;
2997 }
2998
2999 DEFUN (bgp_graceful_restart_select_defer_time,
3000 bgp_graceful_restart_select_defer_time_cmd,
3001 "bgp graceful-restart select-defer-time (0-3600)",
3002 BGP_STR
3003 "Graceful restart capability parameters\n"
3004 "Set the time to defer the BGP route selection after restart\n"
3005 "Delay value (seconds, 0 - disable)\n")
3006 {
3007 VTY_DECLVAR_CONTEXT(bgp, bgp);
3008 int idx_number = 3;
3009 uint32_t defer_time;
3010
3011 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
3012 bgp->select_defer_time = defer_time;
3013 if (defer_time == 0)
3014 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3015 else
3016 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3017
3018 return CMD_SUCCESS;
3019 }
3020
3021 DEFUN (no_bgp_graceful_restart_stalepath_time,
3022 no_bgp_graceful_restart_stalepath_time_cmd,
3023 "no bgp graceful-restart stalepath-time [(1-4095)]",
3024 NO_STR
3025 BGP_STR
3026 "Graceful restart capability parameters\n"
3027 "Set the max time to hold onto restarting peer's stale paths\n"
3028 "Delay value (seconds)\n")
3029 {
3030 VTY_DECLVAR_CONTEXT(bgp, bgp);
3031
3032 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
3033 return CMD_SUCCESS;
3034 }
3035
3036 DEFUN (no_bgp_graceful_restart_restart_time,
3037 no_bgp_graceful_restart_restart_time_cmd,
3038 "no bgp graceful-restart restart-time [(0-4095)]",
3039 NO_STR
3040 BGP_STR
3041 "Graceful restart capability parameters\n"
3042 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3043 "Delay value (seconds)\n")
3044 {
3045 VTY_DECLVAR_CONTEXT(bgp, bgp);
3046
3047 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3048 return CMD_SUCCESS;
3049 }
3050
3051 DEFUN (no_bgp_graceful_restart_select_defer_time,
3052 no_bgp_graceful_restart_select_defer_time_cmd,
3053 "no bgp graceful-restart select-defer-time [(0-3600)]",
3054 NO_STR
3055 BGP_STR
3056 "Graceful restart capability parameters\n"
3057 "Set the time to defer the BGP route selection after restart\n"
3058 "Delay value (seconds)\n")
3059 {
3060 VTY_DECLVAR_CONTEXT(bgp, bgp);
3061
3062 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3063 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3064
3065 return CMD_SUCCESS;
3066 }
3067
3068 DEFUN (bgp_graceful_restart_preserve_fw,
3069 bgp_graceful_restart_preserve_fw_cmd,
3070 "bgp graceful-restart preserve-fw-state",
3071 BGP_STR
3072 "Graceful restart capability parameters\n"
3073 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3074 {
3075 VTY_DECLVAR_CONTEXT(bgp, bgp);
3076 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3077 return CMD_SUCCESS;
3078 }
3079
3080 DEFUN (no_bgp_graceful_restart_preserve_fw,
3081 no_bgp_graceful_restart_preserve_fw_cmd,
3082 "no bgp graceful-restart preserve-fw-state",
3083 NO_STR
3084 BGP_STR
3085 "Graceful restart capability parameters\n"
3086 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3087 {
3088 VTY_DECLVAR_CONTEXT(bgp, bgp);
3089 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3090 return CMD_SUCCESS;
3091 }
3092
3093 DEFPY (bgp_graceful_restart_notification,
3094 bgp_graceful_restart_notification_cmd,
3095 "[no$no] bgp graceful-restart notification",
3096 NO_STR
3097 BGP_STR
3098 "Graceful restart capability parameters\n"
3099 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3100 {
3101 VTY_DECLVAR_CONTEXT(bgp, bgp);
3102
3103 if (no)
3104 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3105 else
3106 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3107
3108 return CMD_SUCCESS;
3109 }
3110
3111 DEFPY (bgp_administrative_reset,
3112 bgp_administrative_reset_cmd,
3113 "[no$no] bgp hard-administrative-reset",
3114 NO_STR
3115 BGP_STR
3116 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3117 {
3118 VTY_DECLVAR_CONTEXT(bgp, bgp);
3119
3120 if (no)
3121 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3122 else
3123 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3124
3125 return CMD_SUCCESS;
3126 }
3127
3128 DEFUN (bgp_graceful_restart_disable,
3129 bgp_graceful_restart_disable_cmd,
3130 "bgp graceful-restart-disable",
3131 BGP_STR
3132 GR_DISABLE)
3133 {
3134 int ret = BGP_GR_FAILURE;
3135
3136 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3137 zlog_debug(
3138 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3139
3140 VTY_DECLVAR_CONTEXT(bgp, bgp);
3141
3142 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3143
3144 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3145 bgp->peer, ret);
3146
3147 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3148 zlog_debug(
3149 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3150 vty_out(vty,
3151 "Graceful restart configuration changed, reset all peers to take effect\n");
3152
3153 return bgp_vty_return(vty, ret);
3154 }
3155
3156 DEFUN (no_bgp_graceful_restart_disable,
3157 no_bgp_graceful_restart_disable_cmd,
3158 "no bgp graceful-restart-disable",
3159 NO_STR
3160 BGP_STR
3161 NO_GR_DISABLE
3162 )
3163 {
3164 VTY_DECLVAR_CONTEXT(bgp, bgp);
3165
3166 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3167 zlog_debug(
3168 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3169
3170 int ret = BGP_GR_FAILURE;
3171
3172 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3173
3174 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3175 ret);
3176
3177 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3178 zlog_debug(
3179 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3180 vty_out(vty,
3181 "Graceful restart configuration changed, reset all peers to take effect\n");
3182
3183 return bgp_vty_return(vty, ret);
3184 }
3185
3186 DEFUN (bgp_neighbor_graceful_restart_set,
3187 bgp_neighbor_graceful_restart_set_cmd,
3188 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3189 NEIGHBOR_STR
3190 NEIGHBOR_ADDR_STR2
3191 GR_NEIGHBOR_CMD
3192 )
3193 {
3194 int idx_peer = 1;
3195 struct peer *peer;
3196 int ret = BGP_GR_FAILURE;
3197
3198 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3199
3200 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3201 zlog_debug(
3202 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3203
3204 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3205 if (!peer)
3206 return CMD_WARNING_CONFIG_FAILED;
3207
3208 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3209
3210 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3211 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3212
3213 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3214 zlog_debug(
3215 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3216 vty_out(vty,
3217 "Graceful restart configuration changed, reset this peer to take effect\n");
3218
3219 return bgp_vty_return(vty, ret);
3220 }
3221
3222 DEFUN (no_bgp_neighbor_graceful_restart,
3223 no_bgp_neighbor_graceful_restart_set_cmd,
3224 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3225 NO_STR
3226 NEIGHBOR_STR
3227 NEIGHBOR_ADDR_STR2
3228 NO_GR_NEIGHBOR_CMD
3229 )
3230 {
3231 int idx_peer = 2;
3232 int ret = BGP_GR_FAILURE;
3233 struct peer *peer;
3234
3235 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3236
3237 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3238 if (!peer)
3239 return CMD_WARNING_CONFIG_FAILED;
3240
3241 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3242 zlog_debug(
3243 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3244
3245 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3246
3247 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3248 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3249
3250 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3251 zlog_debug(
3252 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3253 vty_out(vty,
3254 "Graceful restart configuration changed, reset this peer to take effect\n");
3255
3256 return bgp_vty_return(vty, ret);
3257 }
3258
3259 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3260 bgp_neighbor_graceful_restart_helper_set_cmd,
3261 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3262 NEIGHBOR_STR
3263 NEIGHBOR_ADDR_STR2
3264 GR_NEIGHBOR_HELPER_CMD
3265 )
3266 {
3267 int idx_peer = 1;
3268 struct peer *peer;
3269 int ret = BGP_GR_FAILURE;
3270
3271 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3272
3273 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3274 zlog_debug(
3275 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3276
3277 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3278
3279 if (!peer)
3280 return CMD_WARNING_CONFIG_FAILED;
3281
3282
3283 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3284
3285 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3286 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3287
3288 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3289 zlog_debug(
3290 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3291 vty_out(vty,
3292 "Graceful restart configuration changed, reset this peer to take effect\n");
3293
3294 return bgp_vty_return(vty, ret);
3295 }
3296
3297 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3298 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3299 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3300 NO_STR
3301 NEIGHBOR_STR
3302 NEIGHBOR_ADDR_STR2
3303 NO_GR_NEIGHBOR_HELPER_CMD
3304 )
3305 {
3306 int idx_peer = 2;
3307 int ret = BGP_GR_FAILURE;
3308 struct peer *peer;
3309
3310 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3311
3312 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3313 if (!peer)
3314 return CMD_WARNING_CONFIG_FAILED;
3315
3316 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3317 zlog_debug(
3318 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3319
3320 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3321
3322 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3323 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3324
3325 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3326 zlog_debug(
3327 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3328 vty_out(vty,
3329 "Graceful restart configuration changed, reset this peer to take effect\n");
3330
3331 return bgp_vty_return(vty, ret);
3332 }
3333
3334 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3335 bgp_neighbor_graceful_restart_disable_set_cmd,
3336 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3337 NEIGHBOR_STR
3338 NEIGHBOR_ADDR_STR2
3339 GR_NEIGHBOR_DISABLE_CMD
3340 )
3341 {
3342 int idx_peer = 1;
3343 struct peer *peer;
3344 int ret = BGP_GR_FAILURE;
3345
3346 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3347
3348 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3349 zlog_debug(
3350 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3351
3352 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3353 if (!peer)
3354 return CMD_WARNING_CONFIG_FAILED;
3355
3356 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3357
3358 if (peer->bgp->t_startup)
3359 bgp_peer_gr_flags_update(peer);
3360
3361 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3362 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3363
3364 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3365 zlog_debug(
3366 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3367 vty_out(vty,
3368 "Graceful restart configuration changed, reset this peer to take effect\n");
3369
3370 return bgp_vty_return(vty, ret);
3371 }
3372
3373 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3374 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3375 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3376 NO_STR
3377 NEIGHBOR_STR
3378 NEIGHBOR_ADDR_STR2
3379 NO_GR_NEIGHBOR_DISABLE_CMD
3380 )
3381 {
3382 int idx_peer = 2;
3383 int ret = BGP_GR_FAILURE;
3384 struct peer *peer;
3385
3386 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3387
3388 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3389 if (!peer)
3390 return CMD_WARNING_CONFIG_FAILED;
3391
3392 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3393 zlog_debug(
3394 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3395
3396 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3397
3398 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3399 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3400
3401 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3402 zlog_debug(
3403 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3404 vty_out(vty,
3405 "Graceful restart configuration changed, reset this peer to take effect\n");
3406
3407 return bgp_vty_return(vty, ret);
3408 }
3409
3410 DEFPY (neighbor_graceful_shutdown,
3411 neighbor_graceful_shutdown_cmd,
3412 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3413 NO_STR
3414 NEIGHBOR_STR
3415 NEIGHBOR_ADDR_STR2
3416 "Graceful shutdown\n")
3417 {
3418 afi_t afi;
3419 safi_t safi;
3420 struct peer *peer;
3421 VTY_DECLVAR_CONTEXT(bgp, bgp);
3422 int ret;
3423
3424 peer = peer_and_group_lookup_vty(vty, neighbor);
3425 if (!peer)
3426 return CMD_WARNING_CONFIG_FAILED;
3427
3428 if (no)
3429 ret = peer_flag_unset_vty(vty, neighbor,
3430 PEER_FLAG_GRACEFUL_SHUTDOWN);
3431 else
3432 ret = peer_flag_set_vty(vty, neighbor,
3433 PEER_FLAG_GRACEFUL_SHUTDOWN);
3434
3435 FOREACH_AFI_SAFI (afi, safi) {
3436 if (!peer->afc[afi][safi])
3437 continue;
3438
3439 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3440 neighbor);
3441 }
3442
3443 return ret;
3444 }
3445
3446 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3447 bgp_graceful_restart_disable_eor_cmd,
3448 "bgp graceful-restart disable-eor",
3449 BGP_STR
3450 "Graceful restart configuration parameters\n"
3451 "Disable EOR Check\n")
3452 {
3453 VTY_DECLVAR_CONTEXT(bgp, bgp);
3454 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3455
3456 return CMD_SUCCESS;
3457 }
3458
3459 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3460 no_bgp_graceful_restart_disable_eor_cmd,
3461 "no bgp graceful-restart disable-eor",
3462 NO_STR
3463 BGP_STR
3464 "Graceful restart configuration parameters\n"
3465 "Disable EOR Check\n")
3466 {
3467 VTY_DECLVAR_CONTEXT(bgp, bgp);
3468 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3469
3470 return CMD_SUCCESS;
3471 }
3472
3473 DEFUN (bgp_graceful_restart_rib_stale_time,
3474 bgp_graceful_restart_rib_stale_time_cmd,
3475 "bgp graceful-restart rib-stale-time (1-3600)",
3476 BGP_STR
3477 "Graceful restart configuration parameters\n"
3478 "Specify the stale route removal timer in rib\n"
3479 "Delay value (seconds)\n")
3480 {
3481 VTY_DECLVAR_CONTEXT(bgp, bgp);
3482 int idx_number = 3;
3483 uint32_t stale_time;
3484
3485 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3486 bgp->rib_stale_time = stale_time;
3487 /* Send the stale timer update message to RIB */
3488 if (bgp_zebra_stale_timer_update(bgp))
3489 return CMD_WARNING;
3490
3491 return CMD_SUCCESS;
3492 }
3493
3494 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3495 no_bgp_graceful_restart_rib_stale_time_cmd,
3496 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3497 NO_STR
3498 BGP_STR
3499 "Graceful restart configuration parameters\n"
3500 "Specify the stale route removal timer in rib\n"
3501 "Delay value (seconds)\n")
3502 {
3503 VTY_DECLVAR_CONTEXT(bgp, bgp);
3504
3505 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3506 /* Send the stale timer update message to RIB */
3507 if (bgp_zebra_stale_timer_update(bgp))
3508 return CMD_WARNING;
3509
3510 return CMD_SUCCESS;
3511 }
3512
3513 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3514 "bgp long-lived-graceful-restart stale-time (1-16777215)",
3515 BGP_STR
3516 "Enable Long-lived Graceful Restart\n"
3517 "Specifies maximum time to wait before purging long-lived stale routes\n"
3518 "Stale time value (seconds)\n")
3519 {
3520 VTY_DECLVAR_CONTEXT(bgp, bgp);
3521
3522 uint32_t llgr_stale_time;
3523
3524 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3525 bgp->llgr_stale_time = llgr_stale_time;
3526
3527 return CMD_SUCCESS;
3528 }
3529
3530 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3531 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3532 NO_STR BGP_STR
3533 "Enable Long-lived Graceful Restart\n"
3534 "Specifies maximum time to wait before purging long-lived stale routes\n"
3535 "Stale time value (seconds)\n")
3536 {
3537 VTY_DECLVAR_CONTEXT(bgp, bgp);
3538
3539 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3540
3541 return CMD_SUCCESS;
3542 }
3543
3544 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3545 struct bgp *bgp)
3546 {
3547 bgp_static_redo_import_check(bgp);
3548 bgp_redistribute_redo(bgp);
3549 bgp_clear_star_soft_out(vty, bgp->name);
3550 bgp_clear_star_soft_in(vty, bgp->name);
3551 }
3552
3553 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3554 {
3555 struct listnode *node, *nnode;
3556 struct bgp *bgp;
3557 bool vrf_cfg = false;
3558
3559 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3560 return CMD_SUCCESS;
3561
3562 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3563 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3564 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3565 vty_out(vty,
3566 "%% graceful-shutdown configuration found in vrf %s\n",
3567 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3568 VRF_DEFAULT_NAME : bgp->name);
3569 vrf_cfg = true;
3570 }
3571 }
3572
3573 if (vrf_cfg) {
3574 vty_out(vty,
3575 "%%Failed: global graceful-shutdown not permitted\n");
3576 return CMD_WARNING;
3577 }
3578
3579 /* Set flag globally */
3580 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3581
3582 /* Initiate processing for all BGP instances. */
3583 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3584 bgp_initiate_graceful_shut_unshut(vty, bgp);
3585
3586 return CMD_SUCCESS;
3587 }
3588
3589 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3590 {
3591 struct listnode *node, *nnode;
3592 struct bgp *bgp;
3593
3594 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3595 return CMD_SUCCESS;
3596
3597 /* Unset flag globally */
3598 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3599
3600 /* Initiate processing for all BGP instances. */
3601 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3602 bgp_initiate_graceful_shut_unshut(vty, bgp);
3603
3604 return CMD_SUCCESS;
3605 }
3606
3607 /* "bgp graceful-shutdown" configuration */
3608 DEFUN (bgp_graceful_shutdown,
3609 bgp_graceful_shutdown_cmd,
3610 "bgp graceful-shutdown",
3611 BGP_STR
3612 "Graceful shutdown parameters\n")
3613 {
3614 if (vty->node == CONFIG_NODE)
3615 return bgp_global_graceful_shutdown_config_vty(vty);
3616
3617 VTY_DECLVAR_CONTEXT(bgp, bgp);
3618
3619 /* if configured globally, per-instance config is not allowed */
3620 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3621 vty_out(vty,
3622 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3623 return CMD_WARNING_CONFIG_FAILED;
3624 }
3625
3626 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3627 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3628 bgp_initiate_graceful_shut_unshut(vty, bgp);
3629 }
3630
3631 return CMD_SUCCESS;
3632 }
3633
3634 DEFUN (no_bgp_graceful_shutdown,
3635 no_bgp_graceful_shutdown_cmd,
3636 "no bgp graceful-shutdown",
3637 NO_STR
3638 BGP_STR
3639 "Graceful shutdown parameters\n")
3640 {
3641 if (vty->node == CONFIG_NODE)
3642 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3643
3644 VTY_DECLVAR_CONTEXT(bgp, bgp);
3645
3646 /* If configured globally, cannot remove from one bgp instance */
3647 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3648 vty_out(vty,
3649 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3650 return CMD_WARNING_CONFIG_FAILED;
3651 }
3652
3653 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3654 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3655 bgp_initiate_graceful_shut_unshut(vty, bgp);
3656 }
3657
3658 return CMD_SUCCESS;
3659 }
3660
3661 /* "bgp fast-external-failover" configuration. */
3662 DEFUN (bgp_fast_external_failover,
3663 bgp_fast_external_failover_cmd,
3664 "bgp fast-external-failover",
3665 BGP_STR
3666 "Immediately reset session if a link to a directly connected external peer goes down\n")
3667 {
3668 VTY_DECLVAR_CONTEXT(bgp, bgp);
3669 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3670 return CMD_SUCCESS;
3671 }
3672
3673 DEFUN (no_bgp_fast_external_failover,
3674 no_bgp_fast_external_failover_cmd,
3675 "no bgp fast-external-failover",
3676 NO_STR
3677 BGP_STR
3678 "Immediately reset session if a link to a directly connected external peer goes down\n")
3679 {
3680 VTY_DECLVAR_CONTEXT(bgp, bgp);
3681 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3682 return CMD_SUCCESS;
3683 }
3684
3685 DEFPY (bgp_bestpath_aigp,
3686 bgp_bestpath_aigp_cmd,
3687 "[no$no] bgp bestpath aigp",
3688 NO_STR
3689 BGP_STR
3690 "Change the default bestpath selection\n"
3691 "Evaluate the AIGP attribute during the best path selection process\n")
3692 {
3693 VTY_DECLVAR_CONTEXT(bgp, bgp);
3694
3695 if (no)
3696 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3697 else
3698 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3699
3700 bgp_recalculate_all_bestpaths(bgp);
3701
3702 return CMD_SUCCESS;
3703 }
3704
3705 /* "bgp bestpath compare-routerid" configuration. */
3706 DEFUN (bgp_bestpath_compare_router_id,
3707 bgp_bestpath_compare_router_id_cmd,
3708 "bgp bestpath compare-routerid",
3709 BGP_STR
3710 "Change the default bestpath selection\n"
3711 "Compare router-id for identical EBGP paths\n")
3712 {
3713 VTY_DECLVAR_CONTEXT(bgp, bgp);
3714 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3715 bgp_recalculate_all_bestpaths(bgp);
3716
3717 return CMD_SUCCESS;
3718 }
3719
3720 DEFUN (no_bgp_bestpath_compare_router_id,
3721 no_bgp_bestpath_compare_router_id_cmd,
3722 "no bgp bestpath compare-routerid",
3723 NO_STR
3724 BGP_STR
3725 "Change the default bestpath selection\n"
3726 "Compare router-id for identical EBGP paths\n")
3727 {
3728 VTY_DECLVAR_CONTEXT(bgp, bgp);
3729 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3730 bgp_recalculate_all_bestpaths(bgp);
3731
3732 return CMD_SUCCESS;
3733 }
3734
3735 /* "bgp bestpath as-path ignore" configuration. */
3736 DEFUN (bgp_bestpath_aspath_ignore,
3737 bgp_bestpath_aspath_ignore_cmd,
3738 "bgp bestpath as-path ignore",
3739 BGP_STR
3740 "Change the default bestpath selection\n"
3741 "AS-path attribute\n"
3742 "Ignore as-path length in selecting a route\n")
3743 {
3744 VTY_DECLVAR_CONTEXT(bgp, bgp);
3745 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3746 bgp_recalculate_all_bestpaths(bgp);
3747
3748 return CMD_SUCCESS;
3749 }
3750
3751 DEFUN (no_bgp_bestpath_aspath_ignore,
3752 no_bgp_bestpath_aspath_ignore_cmd,
3753 "no bgp bestpath as-path ignore",
3754 NO_STR
3755 BGP_STR
3756 "Change the default bestpath selection\n"
3757 "AS-path attribute\n"
3758 "Ignore as-path length in selecting a route\n")
3759 {
3760 VTY_DECLVAR_CONTEXT(bgp, bgp);
3761 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3762 bgp_recalculate_all_bestpaths(bgp);
3763
3764 return CMD_SUCCESS;
3765 }
3766
3767 /* "bgp bestpath as-path confed" configuration. */
3768 DEFUN (bgp_bestpath_aspath_confed,
3769 bgp_bestpath_aspath_confed_cmd,
3770 "bgp bestpath as-path confed",
3771 BGP_STR
3772 "Change the default bestpath selection\n"
3773 "AS-path attribute\n"
3774 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3775 {
3776 VTY_DECLVAR_CONTEXT(bgp, bgp);
3777 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3778 bgp_recalculate_all_bestpaths(bgp);
3779
3780 return CMD_SUCCESS;
3781 }
3782
3783 DEFUN (no_bgp_bestpath_aspath_confed,
3784 no_bgp_bestpath_aspath_confed_cmd,
3785 "no bgp bestpath as-path confed",
3786 NO_STR
3787 BGP_STR
3788 "Change the default bestpath selection\n"
3789 "AS-path attribute\n"
3790 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3791 {
3792 VTY_DECLVAR_CONTEXT(bgp, bgp);
3793 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3794 bgp_recalculate_all_bestpaths(bgp);
3795
3796 return CMD_SUCCESS;
3797 }
3798
3799 /* "bgp bestpath as-path multipath-relax" configuration. */
3800 DEFUN (bgp_bestpath_aspath_multipath_relax,
3801 bgp_bestpath_aspath_multipath_relax_cmd,
3802 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3803 BGP_STR
3804 "Change the default bestpath selection\n"
3805 "AS-path attribute\n"
3806 "Allow load sharing across routes that have different AS paths (but same length)\n"
3807 "Generate an AS_SET\n"
3808 "Do not generate an AS_SET\n")
3809 {
3810 VTY_DECLVAR_CONTEXT(bgp, bgp);
3811 int idx = 0;
3812 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3813
3814 /* no-as-set is now the default behavior so we can silently
3815 * ignore it */
3816 if (argv_find(argv, argc, "as-set", &idx))
3817 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3818 else
3819 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3820
3821 bgp_recalculate_all_bestpaths(bgp);
3822
3823 return CMD_SUCCESS;
3824 }
3825
3826 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3827 no_bgp_bestpath_aspath_multipath_relax_cmd,
3828 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3829 NO_STR
3830 BGP_STR
3831 "Change the default bestpath selection\n"
3832 "AS-path attribute\n"
3833 "Allow load sharing across routes that have different AS paths (but same length)\n"
3834 "Generate an AS_SET\n"
3835 "Do not generate an AS_SET\n")
3836 {
3837 VTY_DECLVAR_CONTEXT(bgp, bgp);
3838 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3839 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3840 bgp_recalculate_all_bestpaths(bgp);
3841
3842 return CMD_SUCCESS;
3843 }
3844
3845 /* "bgp bestpath peer-type multipath-relax" configuration. */
3846 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3847 bgp_bestpath_peer_type_multipath_relax_cmd,
3848 "bgp bestpath peer-type multipath-relax",
3849 BGP_STR
3850 "Change the default bestpath selection\n"
3851 "Peer type\n"
3852 "Allow load sharing across routes learned from different peer types\n")
3853 {
3854 VTY_DECLVAR_CONTEXT(bgp, bgp);
3855 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3856 bgp_recalculate_all_bestpaths(bgp);
3857
3858 return CMD_SUCCESS;
3859 }
3860
3861 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3862 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3863 "no bgp bestpath peer-type multipath-relax",
3864 NO_STR BGP_STR
3865 "Change the default bestpath selection\n"
3866 "Peer type\n"
3867 "Allow load sharing across routes learned from different peer types\n")
3868 {
3869 VTY_DECLVAR_CONTEXT(bgp, bgp);
3870 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3871 bgp_recalculate_all_bestpaths(bgp);
3872
3873 return CMD_SUCCESS;
3874 }
3875
3876 /* "bgp log-neighbor-changes" configuration. */
3877 DEFUN (bgp_log_neighbor_changes,
3878 bgp_log_neighbor_changes_cmd,
3879 "bgp log-neighbor-changes",
3880 BGP_STR
3881 "Log neighbor up/down and reset reason\n")
3882 {
3883 VTY_DECLVAR_CONTEXT(bgp, bgp);
3884 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3885 return CMD_SUCCESS;
3886 }
3887
3888 DEFUN (no_bgp_log_neighbor_changes,
3889 no_bgp_log_neighbor_changes_cmd,
3890 "no bgp log-neighbor-changes",
3891 NO_STR
3892 BGP_STR
3893 "Log neighbor up/down and reset reason\n")
3894 {
3895 VTY_DECLVAR_CONTEXT(bgp, bgp);
3896 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3897 return CMD_SUCCESS;
3898 }
3899
3900 /* "bgp bestpath med" configuration. */
3901 DEFUN (bgp_bestpath_med,
3902 bgp_bestpath_med_cmd,
3903 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3904 BGP_STR
3905 "Change the default bestpath selection\n"
3906 "MED attribute\n"
3907 "Compare MED among confederation paths\n"
3908 "Treat missing MED as the least preferred one\n"
3909 "Treat missing MED as the least preferred one\n"
3910 "Compare MED among confederation paths\n")
3911 {
3912 VTY_DECLVAR_CONTEXT(bgp, bgp);
3913
3914 int idx = 0;
3915 if (argv_find(argv, argc, "confed", &idx))
3916 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3917 idx = 0;
3918 if (argv_find(argv, argc, "missing-as-worst", &idx))
3919 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3920
3921 bgp_recalculate_all_bestpaths(bgp);
3922
3923 return CMD_SUCCESS;
3924 }
3925
3926 DEFUN (no_bgp_bestpath_med,
3927 no_bgp_bestpath_med_cmd,
3928 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3929 NO_STR
3930 BGP_STR
3931 "Change the default bestpath selection\n"
3932 "MED attribute\n"
3933 "Compare MED among confederation paths\n"
3934 "Treat missing MED as the least preferred one\n"
3935 "Treat missing MED as the least preferred one\n"
3936 "Compare MED among confederation paths\n")
3937 {
3938 VTY_DECLVAR_CONTEXT(bgp, bgp);
3939
3940 int idx = 0;
3941 if (argv_find(argv, argc, "confed", &idx))
3942 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3943 idx = 0;
3944 if (argv_find(argv, argc, "missing-as-worst", &idx))
3945 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3946
3947 bgp_recalculate_all_bestpaths(bgp);
3948
3949 return CMD_SUCCESS;
3950 }
3951
3952 /* "bgp bestpath bandwidth" configuration. */
3953 DEFPY (bgp_bestpath_bw,
3954 bgp_bestpath_bw_cmd,
3955 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3956 BGP_STR
3957 "Change the default bestpath selection\n"
3958 "Link Bandwidth attribute\n"
3959 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3960 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3961 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3962 {
3963 VTY_DECLVAR_CONTEXT(bgp, bgp);
3964 afi_t afi;
3965 safi_t safi;
3966
3967 if (!bw_cfg) {
3968 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3969 return CMD_ERR_INCOMPLETE;
3970 }
3971 if (!strcmp(bw_cfg, "ignore"))
3972 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3973 else if (!strcmp(bw_cfg, "skip-missing"))
3974 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3975 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3976 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3977 else
3978 return CMD_ERR_NO_MATCH;
3979
3980 /* This config is used in route install, so redo that. */
3981 FOREACH_AFI_SAFI (afi, safi) {
3982 if (!bgp_fibupd_safi(safi))
3983 continue;
3984 bgp_zebra_announce_table(bgp, afi, safi);
3985 }
3986
3987 return CMD_SUCCESS;
3988 }
3989
3990 DEFPY (no_bgp_bestpath_bw,
3991 no_bgp_bestpath_bw_cmd,
3992 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3993 NO_STR
3994 BGP_STR
3995 "Change the default bestpath selection\n"
3996 "Link Bandwidth attribute\n"
3997 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3998 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3999 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
4000 {
4001 VTY_DECLVAR_CONTEXT(bgp, bgp);
4002 afi_t afi;
4003 safi_t safi;
4004
4005 bgp->lb_handling = BGP_LINK_BW_ECMP;
4006
4007 /* This config is used in route install, so redo that. */
4008 FOREACH_AFI_SAFI (afi, safi) {
4009 if (!bgp_fibupd_safi(safi))
4010 continue;
4011 bgp_zebra_announce_table(bgp, afi, safi);
4012 }
4013 return CMD_SUCCESS;
4014 }
4015
4016 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
4017 "[no] bgp default <ipv4-unicast|"
4018 "ipv4-multicast|"
4019 "ipv4-vpn|"
4020 "ipv4-labeled-unicast|"
4021 "ipv4-flowspec|"
4022 "ipv6-unicast|"
4023 "ipv6-multicast|"
4024 "ipv6-vpn|"
4025 "ipv6-labeled-unicast|"
4026 "ipv6-flowspec|"
4027 "l2vpn-evpn>$afi_safi",
4028 NO_STR
4029 BGP_STR
4030 "Configure BGP defaults\n"
4031 "Activate ipv4-unicast for a peer by default\n"
4032 "Activate ipv4-multicast for a peer by default\n"
4033 "Activate ipv4-vpn for a peer by default\n"
4034 "Activate ipv4-labeled-unicast for a peer by default\n"
4035 "Activate ipv4-flowspec for a peer by default\n"
4036 "Activate ipv6-unicast for a peer by default\n"
4037 "Activate ipv6-multicast for a peer by default\n"
4038 "Activate ipv6-vpn for a peer by default\n"
4039 "Activate ipv6-labeled-unicast for a peer by default\n"
4040 "Activate ipv6-flowspec for a peer by default\n"
4041 "Activate l2vpn-evpn for a peer by default\n")
4042 {
4043 VTY_DECLVAR_CONTEXT(bgp, bgp);
4044 char afi_safi_str[strlen(afi_safi) + 1];
4045 char *afi_safi_str_tok;
4046
4047 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4048 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4049 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4050 afi_t afi = bgp_vty_afi_from_str(afi_str);
4051 safi_t safi;
4052
4053 /*
4054 * Impossible situation but making coverity happy
4055 */
4056 assert(afi != AFI_MAX);
4057
4058 if (strmatch(safi_str, "labeled"))
4059 safi = bgp_vty_safi_from_str("labeled-unicast");
4060 else
4061 safi = bgp_vty_safi_from_str(safi_str);
4062
4063 assert(safi != SAFI_MAX);
4064 if (no)
4065 bgp->default_af[afi][safi] = false;
4066 else {
4067 if ((safi == SAFI_LABELED_UNICAST
4068 && bgp->default_af[afi][SAFI_UNICAST])
4069 || (safi == SAFI_UNICAST
4070 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4071 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4072 else
4073 bgp->default_af[afi][safi] = true;
4074 }
4075
4076 return CMD_SUCCESS;
4077 }
4078
4079 /* Display hostname in certain command outputs */
4080 DEFUN (bgp_default_show_hostname,
4081 bgp_default_show_hostname_cmd,
4082 "bgp default show-hostname",
4083 BGP_STR
4084 "Configure BGP defaults\n"
4085 "Show hostname in certain command outputs\n")
4086 {
4087 VTY_DECLVAR_CONTEXT(bgp, bgp);
4088 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4089 return CMD_SUCCESS;
4090 }
4091
4092 DEFUN (no_bgp_default_show_hostname,
4093 no_bgp_default_show_hostname_cmd,
4094 "no bgp default show-hostname",
4095 NO_STR
4096 BGP_STR
4097 "Configure BGP defaults\n"
4098 "Show hostname in certain command outputs\n")
4099 {
4100 VTY_DECLVAR_CONTEXT(bgp, bgp);
4101 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4102 return CMD_SUCCESS;
4103 }
4104
4105 /* Display hostname in certain command outputs */
4106 DEFUN (bgp_default_show_nexthop_hostname,
4107 bgp_default_show_nexthop_hostname_cmd,
4108 "bgp default show-nexthop-hostname",
4109 BGP_STR
4110 "Configure BGP defaults\n"
4111 "Show hostname for nexthop in certain command outputs\n")
4112 {
4113 VTY_DECLVAR_CONTEXT(bgp, bgp);
4114 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4115 return CMD_SUCCESS;
4116 }
4117
4118 DEFUN (no_bgp_default_show_nexthop_hostname,
4119 no_bgp_default_show_nexthop_hostname_cmd,
4120 "no bgp default show-nexthop-hostname",
4121 NO_STR
4122 BGP_STR
4123 "Configure BGP defaults\n"
4124 "Show hostname for nexthop in certain command outputs\n")
4125 {
4126 VTY_DECLVAR_CONTEXT(bgp, bgp);
4127 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4128 return CMD_SUCCESS;
4129 }
4130
4131 /* "bgp network import-check" configuration. */
4132 DEFUN (bgp_network_import_check,
4133 bgp_network_import_check_cmd,
4134 "bgp network import-check",
4135 BGP_STR
4136 "BGP network command\n"
4137 "Check BGP network route exists in IGP\n")
4138 {
4139 VTY_DECLVAR_CONTEXT(bgp, bgp);
4140 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4141 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4142 bgp_static_redo_import_check(bgp);
4143 }
4144
4145 return CMD_SUCCESS;
4146 }
4147
4148 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4149 "bgp network import-check exact",
4150 BGP_STR
4151 "BGP network command\n"
4152 "Check BGP network route exists in IGP\n"
4153 "Match route precisely\n")
4154
4155 DEFUN (no_bgp_network_import_check,
4156 no_bgp_network_import_check_cmd,
4157 "no bgp network import-check",
4158 NO_STR
4159 BGP_STR
4160 "BGP network command\n"
4161 "Check BGP network route exists in IGP\n")
4162 {
4163 VTY_DECLVAR_CONTEXT(bgp, bgp);
4164 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4165 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4166 bgp_static_redo_import_check(bgp);
4167 }
4168
4169 return CMD_SUCCESS;
4170 }
4171
4172 DEFUN (bgp_default_local_preference,
4173 bgp_default_local_preference_cmd,
4174 "bgp default local-preference (0-4294967295)",
4175 BGP_STR
4176 "Configure BGP defaults\n"
4177 "local preference (higher=more preferred)\n"
4178 "Configure default local preference value\n")
4179 {
4180 VTY_DECLVAR_CONTEXT(bgp, bgp);
4181 int idx_number = 3;
4182 uint32_t local_pref;
4183
4184 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4185
4186 bgp_default_local_preference_set(bgp, local_pref);
4187 bgp_clear_star_soft_in(vty, bgp->name);
4188
4189 return CMD_SUCCESS;
4190 }
4191
4192 DEFUN (no_bgp_default_local_preference,
4193 no_bgp_default_local_preference_cmd,
4194 "no bgp default local-preference [(0-4294967295)]",
4195 NO_STR
4196 BGP_STR
4197 "Configure BGP defaults\n"
4198 "local preference (higher=more preferred)\n"
4199 "Configure default local preference value\n")
4200 {
4201 VTY_DECLVAR_CONTEXT(bgp, bgp);
4202 bgp_default_local_preference_unset(bgp);
4203 bgp_clear_star_soft_in(vty, bgp->name);
4204
4205 return CMD_SUCCESS;
4206 }
4207
4208
4209 DEFUN (bgp_default_subgroup_pkt_queue_max,
4210 bgp_default_subgroup_pkt_queue_max_cmd,
4211 "bgp default subgroup-pkt-queue-max (20-100)",
4212 BGP_STR
4213 "Configure BGP defaults\n"
4214 "subgroup-pkt-queue-max\n"
4215 "Configure subgroup packet queue max\n")
4216 {
4217 VTY_DECLVAR_CONTEXT(bgp, bgp);
4218 int idx_number = 3;
4219 uint32_t max_size;
4220
4221 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4222
4223 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4224
4225 return CMD_SUCCESS;
4226 }
4227
4228 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4229 no_bgp_default_subgroup_pkt_queue_max_cmd,
4230 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4231 NO_STR
4232 BGP_STR
4233 "Configure BGP defaults\n"
4234 "subgroup-pkt-queue-max\n"
4235 "Configure subgroup packet queue max\n")
4236 {
4237 VTY_DECLVAR_CONTEXT(bgp, bgp);
4238 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4239 return CMD_SUCCESS;
4240 }
4241
4242
4243 DEFUN (bgp_rr_allow_outbound_policy,
4244 bgp_rr_allow_outbound_policy_cmd,
4245 "bgp route-reflector allow-outbound-policy",
4246 BGP_STR
4247 "Allow modifications made by out route-map\n"
4248 "on ibgp neighbors\n")
4249 {
4250 VTY_DECLVAR_CONTEXT(bgp, bgp);
4251
4252 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4253 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4254 update_group_announce_rrclients(bgp);
4255 bgp_clear_star_soft_out(vty, bgp->name);
4256 }
4257
4258 return CMD_SUCCESS;
4259 }
4260
4261 DEFUN (no_bgp_rr_allow_outbound_policy,
4262 no_bgp_rr_allow_outbound_policy_cmd,
4263 "no bgp route-reflector allow-outbound-policy",
4264 NO_STR
4265 BGP_STR
4266 "Allow modifications made by out route-map\n"
4267 "on ibgp neighbors\n")
4268 {
4269 VTY_DECLVAR_CONTEXT(bgp, bgp);
4270
4271 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4272 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4273 update_group_announce_rrclients(bgp);
4274 bgp_clear_star_soft_out(vty, bgp->name);
4275 }
4276
4277 return CMD_SUCCESS;
4278 }
4279
4280 DEFUN (bgp_listen_limit,
4281 bgp_listen_limit_cmd,
4282 "bgp listen limit (1-65535)",
4283 BGP_STR
4284 "BGP Dynamic Neighbors listen commands\n"
4285 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4286 "Configure Dynamic Neighbors listen limit value\n")
4287 {
4288 VTY_DECLVAR_CONTEXT(bgp, bgp);
4289 int idx_number = 3;
4290 int listen_limit;
4291
4292 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4293
4294 bgp_listen_limit_set(bgp, listen_limit);
4295
4296 return CMD_SUCCESS;
4297 }
4298
4299 DEFUN (no_bgp_listen_limit,
4300 no_bgp_listen_limit_cmd,
4301 "no bgp listen limit [(1-65535)]",
4302 NO_STR
4303 BGP_STR
4304 "BGP Dynamic Neighbors listen commands\n"
4305 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4306 "Configure Dynamic Neighbors listen limit value\n")
4307 {
4308 VTY_DECLVAR_CONTEXT(bgp, bgp);
4309 bgp_listen_limit_unset(bgp);
4310 return CMD_SUCCESS;
4311 }
4312
4313
4314 /*
4315 * Check if this listen range is already configured. Check for exact
4316 * match or overlap based on input.
4317 */
4318 static struct peer_group *listen_range_exists(struct bgp *bgp,
4319 struct prefix *range, int exact)
4320 {
4321 struct listnode *node, *nnode;
4322 struct listnode *node1, *nnode1;
4323 struct peer_group *group;
4324 struct prefix *lr;
4325 afi_t afi;
4326 int match;
4327
4328 afi = family2afi(range->family);
4329 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4330 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4331 lr)) {
4332 if (exact)
4333 match = prefix_same(range, lr);
4334 else
4335 match = (prefix_match(range, lr)
4336 || prefix_match(lr, range));
4337 if (match)
4338 return group;
4339 }
4340 }
4341
4342 return NULL;
4343 }
4344
4345 DEFUN (bgp_listen_range,
4346 bgp_listen_range_cmd,
4347 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4348 BGP_STR
4349 "Configure BGP dynamic neighbors listen range\n"
4350 "Configure BGP dynamic neighbors listen range\n"
4351 NEIGHBOR_ADDR_STR
4352 "Member of the peer-group\n"
4353 "Peer-group name\n")
4354 {
4355 VTY_DECLVAR_CONTEXT(bgp, bgp);
4356 struct prefix range;
4357 struct peer_group *group, *existing_group;
4358 afi_t afi;
4359 int ret;
4360 int idx = 0;
4361
4362 argv_find(argv, argc, "A.B.C.D/M", &idx);
4363 argv_find(argv, argc, "X:X::X:X/M", &idx);
4364 char *prefix = argv[idx]->arg;
4365 argv_find(argv, argc, "PGNAME", &idx);
4366 char *peergroup = argv[idx]->arg;
4367
4368 /* Convert IP prefix string to struct prefix. */
4369 ret = str2prefix(prefix, &range);
4370 if (!ret) {
4371 vty_out(vty, "%% Malformed listen range\n");
4372 return CMD_WARNING_CONFIG_FAILED;
4373 }
4374
4375 afi = family2afi(range.family);
4376
4377 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4378 vty_out(vty,
4379 "%% Malformed listen range (link-local address)\n");
4380 return CMD_WARNING_CONFIG_FAILED;
4381 }
4382
4383 apply_mask(&range);
4384
4385 /* Check if same listen range is already configured. */
4386 existing_group = listen_range_exists(bgp, &range, 1);
4387 if (existing_group) {
4388 if (strcmp(existing_group->name, peergroup) == 0)
4389 return CMD_SUCCESS;
4390 else {
4391 vty_out(vty,
4392 "%% Same listen range is attached to peer-group %s\n",
4393 existing_group->name);
4394 return CMD_WARNING_CONFIG_FAILED;
4395 }
4396 }
4397
4398 /* Check if an overlapping listen range exists. */
4399 if (listen_range_exists(bgp, &range, 0)) {
4400 vty_out(vty,
4401 "%% Listen range overlaps with existing listen range\n");
4402 return CMD_WARNING_CONFIG_FAILED;
4403 }
4404
4405 group = peer_group_lookup(bgp, peergroup);
4406 if (!group) {
4407 vty_out(vty, "%% Configure the peer-group first\n");
4408 return CMD_WARNING_CONFIG_FAILED;
4409 }
4410
4411 ret = peer_group_listen_range_add(group, &range);
4412 return bgp_vty_return(vty, ret);
4413 }
4414
4415 DEFUN (no_bgp_listen_range,
4416 no_bgp_listen_range_cmd,
4417 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4418 NO_STR
4419 BGP_STR
4420 "Unconfigure BGP dynamic neighbors listen range\n"
4421 "Unconfigure BGP dynamic neighbors listen range\n"
4422 NEIGHBOR_ADDR_STR
4423 "Member of the peer-group\n"
4424 "Peer-group name\n")
4425 {
4426 VTY_DECLVAR_CONTEXT(bgp, bgp);
4427 struct prefix range;
4428 struct peer_group *group;
4429 afi_t afi;
4430 int ret;
4431 int idx = 0;
4432
4433 argv_find(argv, argc, "A.B.C.D/M", &idx);
4434 argv_find(argv, argc, "X:X::X:X/M", &idx);
4435 char *prefix = argv[idx]->arg;
4436 argv_find(argv, argc, "PGNAME", &idx);
4437 char *peergroup = argv[idx]->arg;
4438
4439 /* Convert IP prefix string to struct prefix. */
4440 ret = str2prefix(prefix, &range);
4441 if (!ret) {
4442 vty_out(vty, "%% Malformed listen range\n");
4443 return CMD_WARNING_CONFIG_FAILED;
4444 }
4445
4446 afi = family2afi(range.family);
4447
4448 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4449 vty_out(vty,
4450 "%% Malformed listen range (link-local address)\n");
4451 return CMD_WARNING_CONFIG_FAILED;
4452 }
4453
4454 apply_mask(&range);
4455
4456 group = peer_group_lookup(bgp, peergroup);
4457 if (!group) {
4458 vty_out(vty, "%% Peer-group does not exist\n");
4459 return CMD_WARNING_CONFIG_FAILED;
4460 }
4461
4462 ret = peer_group_listen_range_del(group, &range);
4463 return bgp_vty_return(vty, ret);
4464 }
4465
4466 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4467 {
4468 struct peer_group *group;
4469 struct listnode *node, *nnode, *rnode, *nrnode;
4470 struct prefix *range;
4471 afi_t afi;
4472
4473 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4474 vty_out(vty, " bgp listen limit %d\n",
4475 bgp->dynamic_neighbors_limit);
4476
4477 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4478 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4479 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4480 nrnode, range)) {
4481 vty_out(vty,
4482 " bgp listen range %pFX peer-group %s\n",
4483 range, group->name);
4484 }
4485 }
4486 }
4487 }
4488
4489
4490 DEFUN (bgp_disable_connected_route_check,
4491 bgp_disable_connected_route_check_cmd,
4492 "bgp disable-ebgp-connected-route-check",
4493 BGP_STR
4494 "Disable checking if nexthop is connected on ebgp sessions\n")
4495 {
4496 VTY_DECLVAR_CONTEXT(bgp, bgp);
4497 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4498 bgp_clear_star_soft_in(vty, bgp->name);
4499
4500 return CMD_SUCCESS;
4501 }
4502
4503 DEFUN (no_bgp_disable_connected_route_check,
4504 no_bgp_disable_connected_route_check_cmd,
4505 "no bgp disable-ebgp-connected-route-check",
4506 NO_STR
4507 BGP_STR
4508 "Disable checking if nexthop is connected on ebgp sessions\n")
4509 {
4510 VTY_DECLVAR_CONTEXT(bgp, bgp);
4511 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4512 bgp_clear_star_soft_in(vty, bgp->name);
4513
4514 return CMD_SUCCESS;
4515 }
4516
4517
4518 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4519 const char *as_str)
4520 {
4521 VTY_DECLVAR_CONTEXT(bgp, bgp);
4522 int ret;
4523 as_t as;
4524 int as_type = AS_SPECIFIED;
4525 union sockunion su;
4526
4527 if (as_str[0] == 'i') {
4528 as = 0;
4529 as_type = AS_INTERNAL;
4530 } else if (as_str[0] == 'e') {
4531 as = 0;
4532 as_type = AS_EXTERNAL;
4533 } else if (!asn_str2asn(as_str, &as))
4534 as_type = AS_UNSPECIFIED;
4535
4536 if (as_type == AS_UNSPECIFIED) {
4537 vty_out(vty, "%% Invalid peer AS: %s\n", as_str);
4538 return CMD_WARNING_CONFIG_FAILED;
4539 }
4540 /* If peer is peer group or interface peer, call proper function. */
4541 ret = str2sockunion(peer_str, &su);
4542 if (ret < 0) {
4543 struct peer *peer;
4544
4545 /* Check if existing interface peer */
4546 peer = peer_lookup_by_conf_if(bgp, peer_str);
4547
4548 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4549
4550 /* if not interface peer, check peer-group settings */
4551 if (ret < 0 && !peer) {
4552 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4553 if (ret < 0) {
4554 vty_out(vty,
4555 "%% Create the peer-group or interface first\n");
4556 return CMD_WARNING_CONFIG_FAILED;
4557 }
4558 return CMD_SUCCESS;
4559 }
4560 } else {
4561 if (peer_address_self_check(bgp, &su)) {
4562 vty_out(vty,
4563 "%% Can not configure the local system as neighbor\n");
4564 return CMD_WARNING_CONFIG_FAILED;
4565 }
4566 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4567 }
4568
4569 return bgp_vty_return(vty, ret);
4570 }
4571
4572 DEFUN (bgp_default_shutdown,
4573 bgp_default_shutdown_cmd,
4574 "[no] bgp default shutdown",
4575 NO_STR
4576 BGP_STR
4577 "Configure BGP defaults\n"
4578 "Apply administrative shutdown to newly configured peers\n")
4579 {
4580 VTY_DECLVAR_CONTEXT(bgp, bgp);
4581 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4582 return CMD_SUCCESS;
4583 }
4584
4585 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4586 BGP_STR
4587 "Administrative shutdown of the BGP instance\n"
4588 "Add a shutdown message (RFC 8203)\n"
4589 "Shutdown message\n")
4590 {
4591 char *msgstr = NULL;
4592
4593 VTY_DECLVAR_CONTEXT(bgp, bgp);
4594
4595 if (argc > 3)
4596 msgstr = argv_concat(argv, argc, 3);
4597
4598 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4599 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4600 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4601 return CMD_WARNING_CONFIG_FAILED;
4602 }
4603
4604 bgp_shutdown_enable(bgp, msgstr);
4605 XFREE(MTYPE_TMP, msgstr);
4606
4607 return CMD_SUCCESS;
4608 }
4609
4610 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4611 BGP_STR "Administrative shutdown of the BGP instance\n")
4612 {
4613 VTY_DECLVAR_CONTEXT(bgp, bgp);
4614
4615 bgp_shutdown_enable(bgp, NULL);
4616
4617 return CMD_SUCCESS;
4618 }
4619
4620 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4621 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4622 {
4623 VTY_DECLVAR_CONTEXT(bgp, bgp);
4624
4625 bgp_shutdown_disable(bgp);
4626
4627 return CMD_SUCCESS;
4628 }
4629
4630 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4631 "no bgp shutdown message MSG...", NO_STR BGP_STR
4632 "Administrative shutdown of the BGP instance\n"
4633 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4634
4635 DEFUN (neighbor_remote_as,
4636 neighbor_remote_as_cmd,
4637 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <ASNUM|internal|external>",
4638 NEIGHBOR_STR
4639 NEIGHBOR_ADDR_STR2
4640 "Specify a BGP neighbor\n"
4641 AS_STR
4642 "Internal BGP peer\n"
4643 "External BGP peer\n")
4644 {
4645 int idx_peer = 1;
4646 int idx_remote_as = 3;
4647 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4648 argv[idx_remote_as]->arg);
4649 }
4650
4651 DEFPY (bgp_allow_martian,
4652 bgp_allow_martian_cmd,
4653 "[no]$no bgp allow-martian-nexthop",
4654 NO_STR
4655 BGP_STR
4656 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4657 {
4658 VTY_DECLVAR_CONTEXT(bgp, bgp);
4659
4660 if (no)
4661 bgp->allow_martian = false;
4662 else
4663 bgp->allow_martian = true;
4664
4665 return CMD_SUCCESS;
4666 }
4667
4668 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4669 * sessions do not wait for hold timer expiry to bring down the sessions
4670 * when nexthop becomes unreachable
4671 */
4672 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4673 BGP_STR "Fast convergence for bgp sessions\n")
4674 {
4675 VTY_DECLVAR_CONTEXT(bgp, bgp);
4676 bgp->fast_convergence = true;
4677
4678 return CMD_SUCCESS;
4679 }
4680
4681 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4682 "no bgp fast-convergence",
4683 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4684 {
4685 VTY_DECLVAR_CONTEXT(bgp, bgp);
4686 bgp->fast_convergence = false;
4687
4688 return CMD_SUCCESS;
4689 }
4690
4691 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4692 int v6only,
4693 const char *peer_group_name,
4694 const char *as_str)
4695 {
4696 VTY_DECLVAR_CONTEXT(bgp, bgp);
4697 as_t as = 0;
4698 int as_type = AS_UNSPECIFIED;
4699 struct peer *peer;
4700 struct peer_group *group;
4701 int ret = 0;
4702
4703 group = peer_group_lookup(bgp, conf_if);
4704
4705 if (group) {
4706 vty_out(vty, "%% Name conflict with peer-group \n");
4707 return CMD_WARNING_CONFIG_FAILED;
4708 }
4709
4710 if (as_str) {
4711 if (as_str[0] == 'i') {
4712 as_type = AS_INTERNAL;
4713 } else if (as_str[0] == 'e') {
4714 as_type = AS_EXTERNAL;
4715 } else {
4716 /* Get AS number. */
4717 if (asn_str2asn(as_str, &as))
4718 as_type = AS_SPECIFIED;
4719 }
4720 }
4721
4722 peer = peer_lookup_by_conf_if(bgp, conf_if);
4723 if (peer) {
4724 if (as_str)
4725 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4726 } else {
4727 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4728 NULL, true);
4729
4730 if (!peer) {
4731 vty_out(vty, "%% BGP failed to create peer\n");
4732 return CMD_WARNING_CONFIG_FAILED;
4733 }
4734
4735 if (v6only)
4736 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4737
4738 /* Request zebra to initiate IPv6 RAs on this interface. We do
4739 * this
4740 * any unnumbered peer in order to not worry about run-time
4741 * transitions
4742 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4743 * address
4744 * gets deleted later etc.)
4745 */
4746 if (peer->ifp)
4747 bgp_zebra_initiate_radv(bgp, peer);
4748 }
4749
4750 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4751 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4752 if (v6only)
4753 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4754 else
4755 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4756
4757 /* v6only flag changed. Reset bgp seesion */
4758 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4759 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4760 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4761 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4762 } else
4763 bgp_session_reset(peer);
4764 }
4765
4766 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4767 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4768 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4769 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4770 }
4771
4772 if (peer_group_name) {
4773 group = peer_group_lookup(bgp, peer_group_name);
4774 if (!group) {
4775 vty_out(vty, "%% Configure the peer-group first\n");
4776 return CMD_WARNING_CONFIG_FAILED;
4777 }
4778
4779 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4780 }
4781
4782 return bgp_vty_return(vty, ret);
4783 }
4784
4785 DEFUN (neighbor_interface_config,
4786 neighbor_interface_config_cmd,
4787 "neighbor WORD interface [peer-group PGNAME]",
4788 NEIGHBOR_STR
4789 "Interface name or neighbor tag\n"
4790 "Enable BGP on interface\n"
4791 "Member of the peer-group\n"
4792 "Peer-group name\n")
4793 {
4794 int idx_word = 1;
4795 int idx_peer_group_word = 4;
4796
4797 if (argc > idx_peer_group_word)
4798 return peer_conf_interface_get(
4799 vty, argv[idx_word]->arg, 0,
4800 argv[idx_peer_group_word]->arg, NULL);
4801 else
4802 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4803 NULL, NULL);
4804 }
4805
4806 DEFUN (neighbor_interface_config_v6only,
4807 neighbor_interface_config_v6only_cmd,
4808 "neighbor WORD interface v6only [peer-group PGNAME]",
4809 NEIGHBOR_STR
4810 "Interface name or neighbor tag\n"
4811 "Enable BGP on interface\n"
4812 "Enable BGP with v6 link-local only\n"
4813 "Member of the peer-group\n"
4814 "Peer-group name\n")
4815 {
4816 int idx_word = 1;
4817 int idx_peer_group_word = 5;
4818
4819 if (argc > idx_peer_group_word)
4820 return peer_conf_interface_get(
4821 vty, argv[idx_word]->arg, 1,
4822 argv[idx_peer_group_word]->arg, NULL);
4823
4824 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4825 }
4826
4827
4828 DEFUN (neighbor_interface_config_remote_as,
4829 neighbor_interface_config_remote_as_cmd,
4830 "neighbor WORD interface remote-as <ASNUM|internal|external>",
4831 NEIGHBOR_STR
4832 "Interface name or neighbor tag\n"
4833 "Enable BGP on interface\n"
4834 "Specify a BGP neighbor\n"
4835 AS_STR
4836 "Internal BGP peer\n"
4837 "External BGP peer\n")
4838 {
4839 int idx_word = 1;
4840 int idx_remote_as = 4;
4841 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4842 argv[idx_remote_as]->arg);
4843 }
4844
4845 DEFUN (neighbor_interface_v6only_config_remote_as,
4846 neighbor_interface_v6only_config_remote_as_cmd,
4847 "neighbor WORD interface v6only remote-as <ASNUM|internal|external>",
4848 NEIGHBOR_STR
4849 "Interface name or neighbor tag\n"
4850 "Enable BGP with v6 link-local only\n"
4851 "Enable BGP on interface\n"
4852 "Specify a BGP neighbor\n"
4853 AS_STR
4854 "Internal BGP peer\n"
4855 "External BGP peer\n")
4856 {
4857 int idx_word = 1;
4858 int idx_remote_as = 5;
4859 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4860 argv[idx_remote_as]->arg);
4861 }
4862
4863 DEFUN (neighbor_peer_group,
4864 neighbor_peer_group_cmd,
4865 "neighbor WORD peer-group",
4866 NEIGHBOR_STR
4867 "Interface name or neighbor tag\n"
4868 "Configure peer-group\n")
4869 {
4870 VTY_DECLVAR_CONTEXT(bgp, bgp);
4871 int idx_word = 1;
4872 struct peer *peer;
4873 struct peer_group *group;
4874
4875 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4876 if (peer) {
4877 vty_out(vty, "%% Name conflict with interface: \n");
4878 return CMD_WARNING_CONFIG_FAILED;
4879 }
4880
4881 group = peer_group_get(bgp, argv[idx_word]->arg);
4882 if (!group) {
4883 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4884 return CMD_WARNING_CONFIG_FAILED;
4885 }
4886
4887 return CMD_SUCCESS;
4888 }
4889
4890 DEFUN (no_neighbor,
4891 no_neighbor_cmd,
4892 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4893 NO_STR
4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Specify a BGP neighbor\n"
4897 AS_STR
4898 "Internal BGP peer\n"
4899 "External BGP peer\n")
4900 {
4901 VTY_DECLVAR_CONTEXT(bgp, bgp);
4902 int idx_peer = 2;
4903 int ret;
4904 union sockunion su;
4905 struct peer_group *group;
4906 struct peer *peer;
4907 struct peer *other;
4908
4909 ret = str2sockunion(argv[idx_peer]->arg, &su);
4910 if (ret < 0) {
4911 /* look up for neighbor by interface name config. */
4912 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4913 if (peer) {
4914 /* Request zebra to terminate IPv6 RAs on this
4915 * interface. */
4916 if (peer->ifp)
4917 bgp_zebra_terminate_radv(peer->bgp, peer);
4918 peer_notify_unconfig(peer);
4919 peer_delete(peer);
4920 return CMD_SUCCESS;
4921 }
4922
4923 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4924 if (group) {
4925 peer_group_notify_unconfig(group);
4926 peer_group_delete(group);
4927 } else {
4928 vty_out(vty, "%% Create the peer-group first\n");
4929 return CMD_WARNING_CONFIG_FAILED;
4930 }
4931 } else {
4932 peer = peer_lookup(bgp, &su);
4933 if (peer) {
4934 if (peer_dynamic_neighbor(peer)) {
4935 vty_out(vty,
4936 "%% Operation not allowed on a dynamic neighbor\n");
4937 return CMD_WARNING_CONFIG_FAILED;
4938 }
4939
4940 other = peer->doppelganger;
4941
4942 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4943 bgp_zebra_terminate_radv(peer->bgp, peer);
4944
4945 peer_notify_unconfig(peer);
4946 peer_delete(peer);
4947 if (other && other->status != Deleted) {
4948 peer_notify_unconfig(other);
4949 peer_delete(other);
4950 }
4951 }
4952 }
4953
4954 return CMD_SUCCESS;
4955 }
4956
4957 DEFUN (no_neighbor_interface_config,
4958 no_neighbor_interface_config_cmd,
4959 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4960 NO_STR
4961 NEIGHBOR_STR
4962 "Interface name\n"
4963 "Configure BGP on interface\n"
4964 "Enable BGP with v6 link-local only\n"
4965 "Member of the peer-group\n"
4966 "Peer-group name\n"
4967 "Specify a BGP neighbor\n"
4968 AS_STR
4969 "Internal BGP peer\n"
4970 "External BGP peer\n")
4971 {
4972 VTY_DECLVAR_CONTEXT(bgp, bgp);
4973 int idx_word = 2;
4974 struct peer *peer;
4975
4976 /* look up for neighbor by interface name config. */
4977 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4978 if (peer) {
4979 /* Request zebra to terminate IPv6 RAs on this interface. */
4980 if (peer->ifp)
4981 bgp_zebra_terminate_radv(peer->bgp, peer);
4982 peer_notify_unconfig(peer);
4983 peer_delete(peer);
4984 } else {
4985 vty_out(vty, "%% Create the bgp interface first\n");
4986 return CMD_WARNING_CONFIG_FAILED;
4987 }
4988 return CMD_SUCCESS;
4989 }
4990
4991 DEFUN (no_neighbor_peer_group,
4992 no_neighbor_peer_group_cmd,
4993 "no neighbor WORD peer-group",
4994 NO_STR
4995 NEIGHBOR_STR
4996 "Neighbor tag\n"
4997 "Configure peer-group\n")
4998 {
4999 VTY_DECLVAR_CONTEXT(bgp, bgp);
5000 int idx_word = 2;
5001 struct peer_group *group;
5002
5003 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5004 if (group) {
5005 peer_group_notify_unconfig(group);
5006 peer_group_delete(group);
5007 } else {
5008 vty_out(vty, "%% Create the peer-group first\n");
5009 return CMD_WARNING_CONFIG_FAILED;
5010 }
5011 return CMD_SUCCESS;
5012 }
5013
5014 DEFUN (no_neighbor_interface_peer_group_remote_as,
5015 no_neighbor_interface_peer_group_remote_as_cmd,
5016 "no neighbor WORD remote-as <ASNUM|internal|external>",
5017 NO_STR
5018 NEIGHBOR_STR
5019 "Interface name or neighbor tag\n"
5020 "Specify a BGP neighbor\n"
5021 AS_STR
5022 "Internal BGP peer\n"
5023 "External BGP peer\n")
5024 {
5025 VTY_DECLVAR_CONTEXT(bgp, bgp);
5026 int idx_word = 2;
5027 struct peer_group *group;
5028 struct peer *peer;
5029
5030 /* look up for neighbor by interface name config. */
5031 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5032 if (peer) {
5033 peer_as_change(peer, 0, AS_UNSPECIFIED);
5034 return CMD_SUCCESS;
5035 }
5036
5037 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5038 if (group)
5039 peer_group_remote_as_delete(group);
5040 else {
5041 vty_out(vty, "%% Create the peer-group or interface first\n");
5042 return CMD_WARNING_CONFIG_FAILED;
5043 }
5044 return CMD_SUCCESS;
5045 }
5046
5047 DEFUN (neighbor_local_as,
5048 neighbor_local_as_cmd,
5049 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM",
5050 NEIGHBOR_STR
5051 NEIGHBOR_ADDR_STR2
5052 "Specify a local-as number\n"
5053 "AS number expressed in dotted or plain format used as local AS\n")
5054 {
5055 int idx_peer = 1;
5056 int idx_number = 3;
5057 struct peer *peer;
5058 int ret;
5059 as_t as;
5060
5061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5062 if (!peer)
5063 return CMD_WARNING_CONFIG_FAILED;
5064
5065 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5066 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5067 argv[idx_number]->arg);
5068 return CMD_WARNING_CONFIG_FAILED;
5069 }
5070
5071 ret = peer_local_as_set(peer, as, 0, 0);
5072 return bgp_vty_return(vty, ret);
5073 }
5074
5075 DEFUN (neighbor_local_as_no_prepend,
5076 neighbor_local_as_no_prepend_cmd,
5077 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend",
5078 NEIGHBOR_STR
5079 NEIGHBOR_ADDR_STR2
5080 "Specify a local-as number\n"
5081 "AS number expressed in dotted or plain format used as local AS\n"
5082 "Do not prepend local-as to updates from ebgp peers\n")
5083 {
5084 int idx_peer = 1;
5085 int idx_number = 3;
5086 struct peer *peer;
5087 int ret;
5088 as_t as;
5089
5090 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5091 if (!peer)
5092 return CMD_WARNING_CONFIG_FAILED;
5093
5094 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5095 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5096 argv[idx_number]->arg);
5097 return CMD_WARNING_CONFIG_FAILED;
5098 }
5099
5100 ret = peer_local_as_set(peer, as, 1, 0);
5101 return bgp_vty_return(vty, ret);
5102 }
5103
5104 DEFUN (neighbor_local_as_no_prepend_replace_as,
5105 neighbor_local_as_no_prepend_replace_as_cmd,
5106 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as",
5107 NEIGHBOR_STR
5108 NEIGHBOR_ADDR_STR2
5109 "Specify a local-as number\n"
5110 "AS number expressed in dotted or plain format used as local AS\n"
5111 "Do not prepend local-as to updates from ebgp peers\n"
5112 "Do not prepend local-as to updates from ibgp peers\n")
5113 {
5114 int idx_peer = 1;
5115 int idx_number = 3;
5116 struct peer *peer;
5117 int ret;
5118 as_t as;
5119
5120 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5121 if (!peer)
5122 return CMD_WARNING_CONFIG_FAILED;
5123
5124 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5125 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5126 argv[idx_number]->arg);
5127 return CMD_WARNING_CONFIG_FAILED;
5128 }
5129
5130 ret = peer_local_as_set(peer, as, 1, 1);
5131 return bgp_vty_return(vty, ret);
5132 }
5133
5134 DEFUN (no_neighbor_local_as,
5135 no_neighbor_local_as_cmd,
5136 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as]]]",
5137 NO_STR
5138 NEIGHBOR_STR
5139 NEIGHBOR_ADDR_STR2
5140 "Specify a local-as number\n"
5141 "AS number expressed in dotted or plain format used as local AS\n"
5142 "Do not prepend local-as to updates from ebgp peers\n"
5143 "Do not prepend local-as to updates from ibgp peers\n")
5144 {
5145 int idx_peer = 2;
5146 struct peer *peer;
5147 int ret;
5148
5149 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5150 if (!peer)
5151 return CMD_WARNING_CONFIG_FAILED;
5152
5153 ret = peer_local_as_unset(peer);
5154 return bgp_vty_return(vty, ret);
5155 }
5156
5157
5158 DEFUN (neighbor_solo,
5159 neighbor_solo_cmd,
5160 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5161 NEIGHBOR_STR
5162 NEIGHBOR_ADDR_STR2
5163 "Solo peer - part of its own update group\n")
5164 {
5165 int idx_peer = 1;
5166 struct peer *peer;
5167 int ret;
5168
5169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5170 if (!peer)
5171 return CMD_WARNING_CONFIG_FAILED;
5172
5173 ret = update_group_adjust_soloness(peer, 1);
5174 return bgp_vty_return(vty, ret);
5175 }
5176
5177 DEFUN (no_neighbor_solo,
5178 no_neighbor_solo_cmd,
5179 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5180 NO_STR
5181 NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "Solo peer - part of its own update group\n")
5184 {
5185 int idx_peer = 2;
5186 struct peer *peer;
5187 int ret;
5188
5189 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5190 if (!peer)
5191 return CMD_WARNING_CONFIG_FAILED;
5192
5193 ret = update_group_adjust_soloness(peer, 0);
5194 return bgp_vty_return(vty, ret);
5195 }
5196
5197 DEFUN (neighbor_password,
5198 neighbor_password_cmd,
5199 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Set a password\n"
5203 "The password\n")
5204 {
5205 int idx_peer = 1;
5206 int idx_line = 3;
5207 struct peer *peer;
5208 int ret;
5209
5210 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5211 if (!peer)
5212 return CMD_WARNING_CONFIG_FAILED;
5213
5214 ret = peer_password_set(peer, argv[idx_line]->arg);
5215 return bgp_vty_return(vty, ret);
5216 }
5217
5218 DEFUN (no_neighbor_password,
5219 no_neighbor_password_cmd,
5220 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5221 NO_STR
5222 NEIGHBOR_STR
5223 NEIGHBOR_ADDR_STR2
5224 "Set a password\n"
5225 "The password\n")
5226 {
5227 int idx_peer = 2;
5228 struct peer *peer;
5229 int ret;
5230
5231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5232 if (!peer)
5233 return CMD_WARNING_CONFIG_FAILED;
5234
5235 ret = peer_password_unset(peer);
5236 return bgp_vty_return(vty, ret);
5237 }
5238
5239 DEFUN (neighbor_activate,
5240 neighbor_activate_cmd,
5241 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5242 NEIGHBOR_STR
5243 NEIGHBOR_ADDR_STR2
5244 "Enable the Address Family for this Neighbor\n")
5245 {
5246 int idx_peer = 1;
5247 int ret;
5248 struct peer *peer;
5249
5250 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5251 if (!peer)
5252 return CMD_WARNING_CONFIG_FAILED;
5253
5254 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5255 return bgp_vty_return(vty, ret);
5256 }
5257
5258 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5259 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5260 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5261 "Enable the Address Family for this Neighbor\n")
5262
5263 DEFUN (no_neighbor_activate,
5264 no_neighbor_activate_cmd,
5265 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5266 NO_STR
5267 NEIGHBOR_STR
5268 NEIGHBOR_ADDR_STR2
5269 "Enable the Address Family for this Neighbor\n")
5270 {
5271 int idx_peer = 2;
5272 int ret;
5273 struct peer *peer;
5274
5275 /* Lookup peer. */
5276 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5277 if (!peer)
5278 return CMD_WARNING_CONFIG_FAILED;
5279
5280 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5281 return bgp_vty_return(vty, ret);
5282 }
5283
5284 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5285 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5286 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5287 "Enable the Address Family for this Neighbor\n")
5288
5289 DEFUN (neighbor_set_peer_group,
5290 neighbor_set_peer_group_cmd,
5291 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5292 NEIGHBOR_STR
5293 NEIGHBOR_ADDR_STR2
5294 "Member of the peer-group\n"
5295 "Peer-group name\n")
5296 {
5297 VTY_DECLVAR_CONTEXT(bgp, bgp);
5298 int idx_peer = 1;
5299 int idx_word = 3;
5300 int ret;
5301 as_t as;
5302 union sockunion su;
5303 struct peer *peer;
5304 struct peer_group *group;
5305
5306 ret = str2sockunion(argv[idx_peer]->arg, &su);
5307 if (ret < 0) {
5308 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5309 if (!peer) {
5310 vty_out(vty, "%% Malformed address or name: %s\n",
5311 argv[idx_peer]->arg);
5312 return CMD_WARNING_CONFIG_FAILED;
5313 }
5314 } else {
5315 if (peer_address_self_check(bgp, &su)) {
5316 vty_out(vty,
5317 "%% Can not configure the local system as neighbor\n");
5318 return CMD_WARNING_CONFIG_FAILED;
5319 }
5320
5321 /* Disallow for dynamic neighbor. */
5322 peer = peer_lookup(bgp, &su);
5323 if (peer && peer_dynamic_neighbor(peer)) {
5324 vty_out(vty,
5325 "%% Operation not allowed on a dynamic neighbor\n");
5326 return CMD_WARNING_CONFIG_FAILED;
5327 }
5328 }
5329
5330 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5331 if (!group) {
5332 vty_out(vty, "%% Configure the peer-group first\n");
5333 return CMD_WARNING_CONFIG_FAILED;
5334 }
5335
5336 ret = peer_group_bind(bgp, &su, peer, group, &as);
5337
5338 return bgp_vty_return(vty, ret);
5339 }
5340
5341 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5342 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5344 "Member of the peer-group\n"
5345 "Peer-group name\n")
5346
5347 DEFUN (no_neighbor_set_peer_group,
5348 no_neighbor_set_peer_group_cmd,
5349 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5350 NO_STR
5351 NEIGHBOR_STR
5352 NEIGHBOR_ADDR_STR2
5353 "Member of the peer-group\n"
5354 "Peer-group name\n")
5355 {
5356 VTY_DECLVAR_CONTEXT(bgp, bgp);
5357 int idx_peer = 2;
5358 int idx_word = 4;
5359 int ret;
5360 struct peer *peer;
5361 struct peer_group *group;
5362
5363 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5364 if (!peer)
5365 return CMD_WARNING_CONFIG_FAILED;
5366
5367 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5368 if (!group) {
5369 vty_out(vty, "%% Configure the peer-group first\n");
5370 return CMD_WARNING_CONFIG_FAILED;
5371 }
5372
5373 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5374 bgp_zebra_terminate_radv(peer->bgp, peer);
5375
5376 peer_notify_unconfig(peer);
5377 ret = peer_delete(peer);
5378
5379 return bgp_vty_return(vty, ret);
5380 }
5381
5382 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5383 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5384 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5385 "Member of the peer-group\n"
5386 "Peer-group name\n")
5387
5388 /* neighbor passive. */
5389 DEFUN (neighbor_passive,
5390 neighbor_passive_cmd,
5391 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5392 NEIGHBOR_STR
5393 NEIGHBOR_ADDR_STR2
5394 "Don't send open messages to this neighbor\n")
5395 {
5396 int idx_peer = 1;
5397 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5398 }
5399
5400 DEFUN (no_neighbor_passive,
5401 no_neighbor_passive_cmd,
5402 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5403 NO_STR
5404 NEIGHBOR_STR
5405 NEIGHBOR_ADDR_STR2
5406 "Don't send open messages to this neighbor\n")
5407 {
5408 int idx_peer = 2;
5409 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5410 }
5411
5412 /* neighbor shutdown. */
5413 DEFUN (neighbor_shutdown_msg,
5414 neighbor_shutdown_msg_cmd,
5415 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5416 NEIGHBOR_STR
5417 NEIGHBOR_ADDR_STR2
5418 "Administratively shut down this neighbor\n"
5419 "Add a shutdown message (RFC 8203)\n"
5420 "Shutdown message\n")
5421 {
5422 int idx_peer = 1;
5423
5424 if (argc >= 5) {
5425 struct peer *peer =
5426 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5427 char *message;
5428
5429 if (!peer)
5430 return CMD_WARNING_CONFIG_FAILED;
5431 message = argv_concat(argv, argc, 4);
5432 peer_tx_shutdown_message_set(peer, message);
5433 XFREE(MTYPE_TMP, message);
5434 }
5435
5436 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5437 }
5438
5439 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5440 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5441 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5442 "Administratively shut down this neighbor\n")
5443
5444 DEFUN (no_neighbor_shutdown_msg,
5445 no_neighbor_shutdown_msg_cmd,
5446 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5447 NO_STR
5448 NEIGHBOR_STR
5449 NEIGHBOR_ADDR_STR2
5450 "Administratively shut down this neighbor\n"
5451 "Remove a shutdown message (RFC 8203)\n"
5452 "Shutdown message\n")
5453 {
5454 int idx_peer = 2;
5455
5456 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5457 PEER_FLAG_SHUTDOWN);
5458 }
5459
5460 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5461 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5462 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5463 "Administratively shut down this neighbor\n")
5464
5465 DEFUN(neighbor_shutdown_rtt,
5466 neighbor_shutdown_rtt_cmd,
5467 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5468 NEIGHBOR_STR
5469 NEIGHBOR_ADDR_STR2
5470 "Administratively shut down this neighbor\n"
5471 "Shutdown if round-trip-time is higher than expected\n"
5472 "Round-trip-time in milliseconds\n"
5473 "Specify the number of keepalives before shutdown\n"
5474 "The number of keepalives with higher RTT to shutdown\n")
5475 {
5476 int idx_peer = 1;
5477 int idx_rtt = 4;
5478 int idx_count = 0;
5479 struct peer *peer;
5480
5481 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5482
5483 if (!peer)
5484 return CMD_WARNING_CONFIG_FAILED;
5485
5486 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5487
5488 if (argv_find(argv, argc, "count", &idx_count))
5489 peer->rtt_keepalive_conf =
5490 strtol(argv[idx_count + 1]->arg, NULL, 10);
5491
5492 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5493 PEER_FLAG_RTT_SHUTDOWN);
5494 }
5495
5496 DEFUN(no_neighbor_shutdown_rtt,
5497 no_neighbor_shutdown_rtt_cmd,
5498 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5499 NO_STR
5500 NEIGHBOR_STR
5501 NEIGHBOR_ADDR_STR2
5502 "Administratively shut down this neighbor\n"
5503 "Shutdown if round-trip-time is higher than expected\n"
5504 "Round-trip-time in milliseconds\n"
5505 "Specify the number of keepalives before shutdown\n"
5506 "The number of keepalives with higher RTT to shutdown\n")
5507 {
5508 int idx_peer = 2;
5509 struct peer *peer;
5510
5511 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5512
5513 if (!peer)
5514 return CMD_WARNING_CONFIG_FAILED;
5515
5516 peer->rtt_expected = 0;
5517 peer->rtt_keepalive_conf = 1;
5518
5519 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5520 PEER_FLAG_RTT_SHUTDOWN);
5521 }
5522
5523 /* neighbor capability dynamic. */
5524 DEFUN (neighbor_capability_dynamic,
5525 neighbor_capability_dynamic_cmd,
5526 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5527 NEIGHBOR_STR
5528 NEIGHBOR_ADDR_STR2
5529 "Advertise capability to the peer\n"
5530 "Advertise dynamic capability to this neighbor\n")
5531 {
5532 int idx_peer = 1;
5533 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5534 PEER_FLAG_DYNAMIC_CAPABILITY);
5535 }
5536
5537 DEFUN (no_neighbor_capability_dynamic,
5538 no_neighbor_capability_dynamic_cmd,
5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5540 NO_STR
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Advertise capability to the peer\n"
5544 "Advertise dynamic capability to this neighbor\n")
5545 {
5546 int idx_peer = 2;
5547 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5548 PEER_FLAG_DYNAMIC_CAPABILITY);
5549 }
5550
5551 /* neighbor dont-capability-negotiate */
5552 DEFUN (neighbor_dont_capability_negotiate,
5553 neighbor_dont_capability_negotiate_cmd,
5554 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Do not perform capability negotiation\n")
5558 {
5559 int idx_peer = 1;
5560 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5561 PEER_FLAG_DONT_CAPABILITY);
5562 }
5563
5564 DEFUN (no_neighbor_dont_capability_negotiate,
5565 no_neighbor_dont_capability_negotiate_cmd,
5566 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5567 NO_STR
5568 NEIGHBOR_STR
5569 NEIGHBOR_ADDR_STR2
5570 "Do not perform capability negotiation\n")
5571 {
5572 int idx_peer = 2;
5573 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5574 PEER_FLAG_DONT_CAPABILITY);
5575 }
5576
5577 /* neighbor capability extended next hop encoding */
5578 DEFUN (neighbor_capability_enhe,
5579 neighbor_capability_enhe_cmd,
5580 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5581 NEIGHBOR_STR
5582 NEIGHBOR_ADDR_STR2
5583 "Advertise capability to the peer\n"
5584 "Advertise extended next-hop capability to the peer\n")
5585 {
5586 int idx_peer = 1;
5587 struct peer *peer;
5588
5589 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5590 if (peer && peer->conf_if)
5591 return CMD_SUCCESS;
5592
5593 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5594 PEER_FLAG_CAPABILITY_ENHE);
5595 }
5596
5597 DEFUN (no_neighbor_capability_enhe,
5598 no_neighbor_capability_enhe_cmd,
5599 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5600 NO_STR
5601 NEIGHBOR_STR
5602 NEIGHBOR_ADDR_STR2
5603 "Advertise capability to the peer\n"
5604 "Advertise extended next-hop capability to the peer\n")
5605 {
5606 int idx_peer = 2;
5607 struct peer *peer;
5608
5609 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5610 if (peer && peer->conf_if) {
5611 vty_out(vty,
5612 "Peer %s cannot have capability extended-nexthop turned off\n",
5613 argv[idx_peer]->arg);
5614 return CMD_WARNING_CONFIG_FAILED;
5615 }
5616
5617 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5618 PEER_FLAG_CAPABILITY_ENHE);
5619 }
5620
5621 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5622 afi_t afi, safi_t safi, uint32_t flag,
5623 int set)
5624 {
5625 int ret;
5626 struct peer *peer;
5627
5628 peer = peer_and_group_lookup_vty(vty, peer_str);
5629 if (!peer)
5630 return CMD_WARNING_CONFIG_FAILED;
5631
5632 if (set)
5633 ret = peer_af_flag_set(peer, afi, safi, flag);
5634 else
5635 ret = peer_af_flag_unset(peer, afi, safi, flag);
5636
5637 return bgp_vty_return(vty, ret);
5638 }
5639
5640 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5641 afi_t afi, safi_t safi, uint32_t flag)
5642 {
5643 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5644 }
5645
5646 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5647 afi_t afi, safi_t safi, uint32_t flag)
5648 {
5649 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5650 }
5651
5652 /* neighbor capability orf prefix-list. */
5653 DEFUN (neighbor_capability_orf_prefix,
5654 neighbor_capability_orf_prefix_cmd,
5655 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5656 NEIGHBOR_STR
5657 NEIGHBOR_ADDR_STR2
5658 "Advertise capability to the peer\n"
5659 "Advertise ORF capability to the peer\n"
5660 "Advertise prefixlist ORF capability to this neighbor\n"
5661 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5662 "Capability to RECEIVE the ORF from this neighbor\n"
5663 "Capability to SEND the ORF to this neighbor\n")
5664 {
5665 int idx_send_recv = 5;
5666 char *peer_str = argv[1]->arg;
5667 struct peer *peer;
5668 afi_t afi = bgp_node_afi(vty);
5669 safi_t safi = bgp_node_safi(vty);
5670
5671 peer = peer_and_group_lookup_vty(vty, peer_str);
5672 if (!peer)
5673 return CMD_WARNING_CONFIG_FAILED;
5674
5675 if (strmatch(argv[idx_send_recv]->text, "send"))
5676 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5677 PEER_FLAG_ORF_PREFIX_SM);
5678
5679 if (strmatch(argv[idx_send_recv]->text, "receive"))
5680 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5681 PEER_FLAG_ORF_PREFIX_RM);
5682
5683 if (strmatch(argv[idx_send_recv]->text, "both"))
5684 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5685 PEER_FLAG_ORF_PREFIX_SM)
5686 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5687 PEER_FLAG_ORF_PREFIX_RM);
5688
5689 return CMD_WARNING_CONFIG_FAILED;
5690 }
5691
5692 ALIAS_HIDDEN(
5693 neighbor_capability_orf_prefix,
5694 neighbor_capability_orf_prefix_hidden_cmd,
5695 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5696 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5697 "Advertise capability to the peer\n"
5698 "Advertise ORF capability to the peer\n"
5699 "Advertise prefixlist ORF capability to this neighbor\n"
5700 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5701 "Capability to RECEIVE the ORF from this neighbor\n"
5702 "Capability to SEND the ORF to this neighbor\n")
5703
5704 DEFUN (no_neighbor_capability_orf_prefix,
5705 no_neighbor_capability_orf_prefix_cmd,
5706 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5707 NO_STR
5708 NEIGHBOR_STR
5709 NEIGHBOR_ADDR_STR2
5710 "Advertise capability to the peer\n"
5711 "Advertise ORF capability to the peer\n"
5712 "Advertise prefixlist ORF capability to this neighbor\n"
5713 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5714 "Capability to RECEIVE the ORF from this neighbor\n"
5715 "Capability to SEND the ORF to this neighbor\n")
5716 {
5717 int idx_send_recv = 6;
5718 char *peer_str = argv[2]->arg;
5719 struct peer *peer;
5720 afi_t afi = bgp_node_afi(vty);
5721 safi_t safi = bgp_node_safi(vty);
5722
5723 peer = peer_and_group_lookup_vty(vty, peer_str);
5724 if (!peer)
5725 return CMD_WARNING_CONFIG_FAILED;
5726
5727 if (strmatch(argv[idx_send_recv]->text, "send"))
5728 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5729 PEER_FLAG_ORF_PREFIX_SM);
5730
5731 if (strmatch(argv[idx_send_recv]->text, "receive"))
5732 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5733 PEER_FLAG_ORF_PREFIX_RM);
5734
5735 if (strmatch(argv[idx_send_recv]->text, "both"))
5736 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5737 PEER_FLAG_ORF_PREFIX_SM)
5738 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5739 PEER_FLAG_ORF_PREFIX_RM);
5740
5741 return CMD_WARNING_CONFIG_FAILED;
5742 }
5743
5744 ALIAS_HIDDEN(
5745 no_neighbor_capability_orf_prefix,
5746 no_neighbor_capability_orf_prefix_hidden_cmd,
5747 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5748 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5749 "Advertise capability to the peer\n"
5750 "Advertise ORF capability to the peer\n"
5751 "Advertise prefixlist ORF capability to this neighbor\n"
5752 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5753 "Capability to RECEIVE the ORF from this neighbor\n"
5754 "Capability to SEND the ORF to this neighbor\n")
5755
5756 /* neighbor next-hop-self. */
5757 DEFUN (neighbor_nexthop_self,
5758 neighbor_nexthop_self_cmd,
5759 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5760 NEIGHBOR_STR
5761 NEIGHBOR_ADDR_STR2
5762 "Disable the next hop calculation for this neighbor\n")
5763 {
5764 int idx_peer = 1;
5765 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5766 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5767 }
5768
5769 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5770 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5772 "Disable the next hop calculation for this neighbor\n")
5773
5774 /* neighbor next-hop-self. */
5775 DEFUN (neighbor_nexthop_self_force,
5776 neighbor_nexthop_self_force_cmd,
5777 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5778 NEIGHBOR_STR
5779 NEIGHBOR_ADDR_STR2
5780 "Disable the next hop calculation for this neighbor\n"
5781 "Set the next hop to self for reflected routes\n")
5782 {
5783 int idx_peer = 1;
5784 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5785 bgp_node_safi(vty),
5786 PEER_FLAG_FORCE_NEXTHOP_SELF);
5787 }
5788
5789 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5790 neighbor_nexthop_self_force_hidden_cmd,
5791 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5792 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5793 "Disable the next hop calculation for this neighbor\n"
5794 "Set the next hop to self for reflected routes\n")
5795
5796 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5797 neighbor_nexthop_self_all_hidden_cmd,
5798 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5800 "Disable the next hop calculation for this neighbor\n"
5801 "Set the next hop to self for reflected routes\n")
5802
5803 DEFUN (no_neighbor_nexthop_self,
5804 no_neighbor_nexthop_self_cmd,
5805 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5806 NO_STR
5807 NEIGHBOR_STR
5808 NEIGHBOR_ADDR_STR2
5809 "Disable the next hop calculation for this neighbor\n")
5810 {
5811 int idx_peer = 2;
5812 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5813 bgp_node_afi(vty), bgp_node_safi(vty),
5814 PEER_FLAG_NEXTHOP_SELF);
5815 }
5816
5817 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5818 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5819 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5820 "Disable the next hop calculation for this neighbor\n")
5821
5822 DEFUN (no_neighbor_nexthop_self_force,
5823 no_neighbor_nexthop_self_force_cmd,
5824 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5825 NO_STR
5826 NEIGHBOR_STR
5827 NEIGHBOR_ADDR_STR2
5828 "Disable the next hop calculation for this neighbor\n"
5829 "Set the next hop to self for reflected routes\n")
5830 {
5831 int idx_peer = 2;
5832 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5833 bgp_node_afi(vty), bgp_node_safi(vty),
5834 PEER_FLAG_FORCE_NEXTHOP_SELF);
5835 }
5836
5837 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5838 no_neighbor_nexthop_self_force_hidden_cmd,
5839 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5840 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5841 "Disable the next hop calculation for this neighbor\n"
5842 "Set the next hop to self for reflected routes\n")
5843
5844 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5845 no_neighbor_nexthop_self_all_hidden_cmd,
5846 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Disable the next hop calculation for this neighbor\n"
5849 "Set the next hop to self for reflected routes\n")
5850
5851 /* neighbor as-override */
5852 DEFUN (neighbor_as_override,
5853 neighbor_as_override_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5855 NEIGHBOR_STR
5856 NEIGHBOR_ADDR_STR2
5857 "Override ASNs in outbound updates if aspath equals remote-as\n")
5858 {
5859 int idx_peer = 1;
5860 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5861 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5862 }
5863
5864 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5865 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5867 "Override ASNs in outbound updates if aspath equals remote-as\n")
5868
5869 DEFUN (no_neighbor_as_override,
5870 no_neighbor_as_override_cmd,
5871 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5872 NO_STR
5873 NEIGHBOR_STR
5874 NEIGHBOR_ADDR_STR2
5875 "Override ASNs in outbound updates if aspath equals remote-as\n")
5876 {
5877 int idx_peer = 2;
5878 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5879 bgp_node_afi(vty), bgp_node_safi(vty),
5880 PEER_FLAG_AS_OVERRIDE);
5881 }
5882
5883 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5884 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5885 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5886 "Override ASNs in outbound updates if aspath equals remote-as\n")
5887
5888 /* neighbor remove-private-AS. */
5889 DEFUN (neighbor_remove_private_as,
5890 neighbor_remove_private_as_cmd,
5891 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5892 NEIGHBOR_STR
5893 NEIGHBOR_ADDR_STR2
5894 "Remove private ASNs in outbound updates\n")
5895 {
5896 int idx_peer = 1;
5897 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5898 bgp_node_safi(vty),
5899 PEER_FLAG_REMOVE_PRIVATE_AS);
5900 }
5901
5902 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5903 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5904 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5905 "Remove private ASNs in outbound updates\n")
5906
5907 DEFUN (neighbor_remove_private_as_all,
5908 neighbor_remove_private_as_all_cmd,
5909 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5910 NEIGHBOR_STR
5911 NEIGHBOR_ADDR_STR2
5912 "Remove private ASNs in outbound updates\n"
5913 "Apply to all AS numbers\n")
5914 {
5915 int idx_peer = 1;
5916 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5917 bgp_node_safi(vty),
5918 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5919 }
5920
5921 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5922 neighbor_remove_private_as_all_hidden_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5925 "Remove private ASNs in outbound updates\n"
5926 "Apply to all AS numbers\n")
5927
5928 DEFUN (neighbor_remove_private_as_replace_as,
5929 neighbor_remove_private_as_replace_as_cmd,
5930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5931 NEIGHBOR_STR
5932 NEIGHBOR_ADDR_STR2
5933 "Remove private ASNs in outbound updates\n"
5934 "Replace private ASNs with our ASN in outbound updates\n")
5935 {
5936 int idx_peer = 1;
5937 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5938 bgp_node_safi(vty),
5939 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5940 }
5941
5942 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5943 neighbor_remove_private_as_replace_as_hidden_cmd,
5944 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5945 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5946 "Remove private ASNs in outbound updates\n"
5947 "Replace private ASNs with our ASN in outbound updates\n")
5948
5949 DEFUN (neighbor_remove_private_as_all_replace_as,
5950 neighbor_remove_private_as_all_replace_as_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Remove private ASNs in outbound updates\n"
5955 "Apply to all AS numbers\n"
5956 "Replace private ASNs with our ASN in outbound updates\n")
5957 {
5958 int idx_peer = 1;
5959 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5960 bgp_node_safi(vty),
5961 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5962 }
5963
5964 ALIAS_HIDDEN(
5965 neighbor_remove_private_as_all_replace_as,
5966 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5967 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "Remove private ASNs in outbound updates\n"
5970 "Apply to all AS numbers\n"
5971 "Replace private ASNs with our ASN in outbound updates\n")
5972
5973 DEFUN (no_neighbor_remove_private_as,
5974 no_neighbor_remove_private_as_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5976 NO_STR
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Remove private ASNs in outbound updates\n")
5980 {
5981 int idx_peer = 2;
5982 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5983 bgp_node_afi(vty), bgp_node_safi(vty),
5984 PEER_FLAG_REMOVE_PRIVATE_AS);
5985 }
5986
5987 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5988 no_neighbor_remove_private_as_hidden_cmd,
5989 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5990 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5991 "Remove private ASNs in outbound updates\n")
5992
5993 DEFUN (no_neighbor_remove_private_as_all,
5994 no_neighbor_remove_private_as_all_cmd,
5995 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5996 NO_STR
5997 NEIGHBOR_STR
5998 NEIGHBOR_ADDR_STR2
5999 "Remove private ASNs in outbound updates\n"
6000 "Apply to all AS numbers\n")
6001 {
6002 int idx_peer = 2;
6003 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6004 bgp_node_afi(vty), bgp_node_safi(vty),
6005 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
6006 }
6007
6008 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6009 no_neighbor_remove_private_as_all_hidden_cmd,
6010 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6012 "Remove private ASNs in outbound updates\n"
6013 "Apply to all AS numbers\n")
6014
6015 DEFUN (no_neighbor_remove_private_as_replace_as,
6016 no_neighbor_remove_private_as_replace_as_cmd,
6017 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6018 NO_STR
6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "Remove private ASNs in outbound updates\n"
6022 "Replace private ASNs with our ASN in outbound updates\n")
6023 {
6024 int idx_peer = 2;
6025 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6026 bgp_node_afi(vty), bgp_node_safi(vty),
6027 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
6028 }
6029
6030 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6031 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6032 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6033 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6034 "Remove private ASNs in outbound updates\n"
6035 "Replace private ASNs with our ASN in outbound updates\n")
6036
6037 DEFUN (no_neighbor_remove_private_as_all_replace_as,
6038 no_neighbor_remove_private_as_all_replace_as_cmd,
6039 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6040 NO_STR
6041 NEIGHBOR_STR
6042 NEIGHBOR_ADDR_STR2
6043 "Remove private ASNs in outbound updates\n"
6044 "Apply to all AS numbers\n"
6045 "Replace private ASNs with our ASN in outbound updates\n")
6046 {
6047 int idx_peer = 2;
6048 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6049 bgp_node_afi(vty), bgp_node_safi(vty),
6050 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
6051 }
6052
6053 ALIAS_HIDDEN(
6054 no_neighbor_remove_private_as_all_replace_as,
6055 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6056 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6057 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6058 "Remove private ASNs in outbound updates\n"
6059 "Apply to all AS numbers\n"
6060 "Replace private ASNs with our ASN in outbound updates\n")
6061
6062
6063 /* neighbor send-community. */
6064 DEFUN (neighbor_send_community,
6065 neighbor_send_community_cmd,
6066 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6067 NEIGHBOR_STR
6068 NEIGHBOR_ADDR_STR2
6069 "Send Community attribute to this neighbor\n")
6070 {
6071 int idx_peer = 1;
6072
6073 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6074 bgp_node_safi(vty),
6075 PEER_FLAG_SEND_COMMUNITY);
6076 }
6077
6078 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6079 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6080 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6081 "Send Community attribute to this neighbor\n")
6082
6083 DEFUN (no_neighbor_send_community,
6084 no_neighbor_send_community_cmd,
6085 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6086 NO_STR
6087 NEIGHBOR_STR
6088 NEIGHBOR_ADDR_STR2
6089 "Send Community attribute to this neighbor\n")
6090 {
6091 int idx_peer = 2;
6092
6093 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6094 bgp_node_afi(vty), bgp_node_safi(vty),
6095 PEER_FLAG_SEND_COMMUNITY);
6096 }
6097
6098 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6099 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6100 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6101 "Send Community attribute to this neighbor\n")
6102
6103 /* neighbor send-community extended. */
6104 DEFUN (neighbor_send_community_type,
6105 neighbor_send_community_type_cmd,
6106 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6107 NEIGHBOR_STR
6108 NEIGHBOR_ADDR_STR2
6109 "Send Community attribute to this neighbor\n"
6110 "Send Standard and Extended Community attributes\n"
6111 "Send Standard, Large and Extended Community attributes\n"
6112 "Send Extended Community attributes\n"
6113 "Send Standard Community attributes\n"
6114 "Send Large Community attributes\n")
6115 {
6116 const char *type = argv[argc - 1]->text;
6117 char *peer_str = argv[1]->arg;
6118 struct peer *peer;
6119 afi_t afi = bgp_node_afi(vty);
6120 safi_t safi = bgp_node_safi(vty);
6121
6122 peer = peer_and_group_lookup_vty(vty, peer_str);
6123 if (!peer)
6124 return CMD_WARNING_CONFIG_FAILED;
6125
6126 if (strmatch(type, "standard"))
6127 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6128 PEER_FLAG_SEND_COMMUNITY);
6129
6130 if (strmatch(type, "extended"))
6131 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6132 PEER_FLAG_SEND_EXT_COMMUNITY);
6133
6134 if (strmatch(type, "large"))
6135 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6136 PEER_FLAG_SEND_LARGE_COMMUNITY);
6137
6138 if (strmatch(type, "both")) {
6139 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6140 PEER_FLAG_SEND_COMMUNITY)
6141 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6142 PEER_FLAG_SEND_EXT_COMMUNITY);
6143 }
6144 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6145 PEER_FLAG_SEND_COMMUNITY)
6146 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6147 PEER_FLAG_SEND_EXT_COMMUNITY)
6148 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6149 PEER_FLAG_SEND_LARGE_COMMUNITY);
6150 }
6151
6152 ALIAS_HIDDEN(
6153 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6154 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6155 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6156 "Send Community attribute to this neighbor\n"
6157 "Send Standard and Extended Community attributes\n"
6158 "Send Standard, Large and Extended Community attributes\n"
6159 "Send Extended Community attributes\n"
6160 "Send Standard Community attributes\n"
6161 "Send Large Community attributes\n")
6162
6163 DEFUN (no_neighbor_send_community_type,
6164 no_neighbor_send_community_type_cmd,
6165 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6166 NO_STR
6167 NEIGHBOR_STR
6168 NEIGHBOR_ADDR_STR2
6169 "Send Community attribute to this neighbor\n"
6170 "Send Standard and Extended Community attributes\n"
6171 "Send Standard, Large and Extended Community attributes\n"
6172 "Send Extended Community attributes\n"
6173 "Send Standard Community attributes\n"
6174 "Send Large Community attributes\n")
6175 {
6176 const char *type = argv[argc - 1]->text;
6177 char *peer_str = argv[2]->arg;
6178 struct peer *peer;
6179 afi_t afi = bgp_node_afi(vty);
6180 safi_t safi = bgp_node_safi(vty);
6181
6182 peer = peer_and_group_lookup_vty(vty, peer_str);
6183 if (!peer)
6184 return CMD_WARNING_CONFIG_FAILED;
6185
6186 if (strmatch(type, "standard"))
6187 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6188 PEER_FLAG_SEND_COMMUNITY);
6189
6190 if (strmatch(type, "extended"))
6191 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6192 PEER_FLAG_SEND_EXT_COMMUNITY);
6193
6194 if (strmatch(type, "large"))
6195 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6196 PEER_FLAG_SEND_LARGE_COMMUNITY);
6197
6198 if (strmatch(type, "both")) {
6199
6200 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6201 PEER_FLAG_SEND_COMMUNITY)
6202 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6203 PEER_FLAG_SEND_EXT_COMMUNITY);
6204 }
6205
6206 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6207 PEER_FLAG_SEND_COMMUNITY)
6208 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6209 PEER_FLAG_SEND_EXT_COMMUNITY)
6210 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6211 PEER_FLAG_SEND_LARGE_COMMUNITY);
6212 }
6213
6214 ALIAS_HIDDEN(
6215 no_neighbor_send_community_type,
6216 no_neighbor_send_community_type_hidden_cmd,
6217 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6218 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6219 "Send Community attribute to this neighbor\n"
6220 "Send Standard and Extended Community attributes\n"
6221 "Send Standard, Large and Extended Community attributes\n"
6222 "Send Extended Community attributes\n"
6223 "Send Standard Community attributes\n"
6224 "Send Large Community attributes\n")
6225
6226 /* neighbor soft-reconfig. */
6227 DEFUN (neighbor_soft_reconfiguration,
6228 neighbor_soft_reconfiguration_cmd,
6229 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Per neighbor soft reconfiguration\n"
6233 "Allow inbound soft reconfiguration for this neighbor\n")
6234 {
6235 int idx_peer = 1;
6236 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6237 bgp_node_safi(vty),
6238 PEER_FLAG_SOFT_RECONFIG);
6239 }
6240
6241 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6242 neighbor_soft_reconfiguration_hidden_cmd,
6243 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6244 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6245 "Per neighbor soft reconfiguration\n"
6246 "Allow inbound soft reconfiguration for this neighbor\n")
6247
6248 DEFUN (no_neighbor_soft_reconfiguration,
6249 no_neighbor_soft_reconfiguration_cmd,
6250 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6251 NO_STR
6252 NEIGHBOR_STR
6253 NEIGHBOR_ADDR_STR2
6254 "Per neighbor soft reconfiguration\n"
6255 "Allow inbound soft reconfiguration for this neighbor\n")
6256 {
6257 int idx_peer = 2;
6258 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6259 bgp_node_afi(vty), bgp_node_safi(vty),
6260 PEER_FLAG_SOFT_RECONFIG);
6261 }
6262
6263 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6264 no_neighbor_soft_reconfiguration_hidden_cmd,
6265 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6266 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6267 "Per neighbor soft reconfiguration\n"
6268 "Allow inbound soft reconfiguration for this neighbor\n")
6269
6270 DEFUN (neighbor_route_reflector_client,
6271 neighbor_route_reflector_client_cmd,
6272 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6273 NEIGHBOR_STR
6274 NEIGHBOR_ADDR_STR2
6275 "Configure a neighbor as Route Reflector client\n")
6276 {
6277 int idx_peer = 1;
6278 struct peer *peer;
6279
6280
6281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6282 if (!peer)
6283 return CMD_WARNING_CONFIG_FAILED;
6284
6285 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6286 bgp_node_safi(vty),
6287 PEER_FLAG_REFLECTOR_CLIENT);
6288 }
6289
6290 ALIAS_HIDDEN(neighbor_route_reflector_client,
6291 neighbor_route_reflector_client_hidden_cmd,
6292 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6294 "Configure a neighbor as Route Reflector client\n")
6295
6296 DEFUN (no_neighbor_route_reflector_client,
6297 no_neighbor_route_reflector_client_cmd,
6298 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6299 NO_STR
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "Configure a neighbor as Route Reflector client\n")
6303 {
6304 int idx_peer = 2;
6305 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6306 bgp_node_afi(vty), bgp_node_safi(vty),
6307 PEER_FLAG_REFLECTOR_CLIENT);
6308 }
6309
6310 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6311 no_neighbor_route_reflector_client_hidden_cmd,
6312 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6314 "Configure a neighbor as Route Reflector client\n")
6315
6316 /* neighbor route-server-client. */
6317 DEFUN (neighbor_route_server_client,
6318 neighbor_route_server_client_cmd,
6319 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6320 NEIGHBOR_STR
6321 NEIGHBOR_ADDR_STR2
6322 "Configure a neighbor as Route Server client\n")
6323 {
6324 int idx_peer = 1;
6325 struct peer *peer;
6326
6327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6328 if (!peer)
6329 return CMD_WARNING_CONFIG_FAILED;
6330 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6331 bgp_node_safi(vty),
6332 PEER_FLAG_RSERVER_CLIENT);
6333 }
6334
6335 ALIAS_HIDDEN(neighbor_route_server_client,
6336 neighbor_route_server_client_hidden_cmd,
6337 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6339 "Configure a neighbor as Route Server client\n")
6340
6341 DEFUN (no_neighbor_route_server_client,
6342 no_neighbor_route_server_client_cmd,
6343 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6344 NO_STR
6345 NEIGHBOR_STR
6346 NEIGHBOR_ADDR_STR2
6347 "Configure a neighbor as Route Server client\n")
6348 {
6349 int idx_peer = 2;
6350 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6351 bgp_node_afi(vty), bgp_node_safi(vty),
6352 PEER_FLAG_RSERVER_CLIENT);
6353 }
6354
6355 ALIAS_HIDDEN(no_neighbor_route_server_client,
6356 no_neighbor_route_server_client_hidden_cmd,
6357 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6358 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6359 "Configure a neighbor as Route Server client\n")
6360
6361 DEFUN (neighbor_nexthop_local_unchanged,
6362 neighbor_nexthop_local_unchanged_cmd,
6363 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6364 NEIGHBOR_STR
6365 NEIGHBOR_ADDR_STR2
6366 "Configure treatment of outgoing link-local nexthop attribute\n"
6367 "Leave link-local nexthop unchanged for this peer\n")
6368 {
6369 int idx_peer = 1;
6370 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6371 bgp_node_safi(vty),
6372 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6373 }
6374
6375 DEFUN (no_neighbor_nexthop_local_unchanged,
6376 no_neighbor_nexthop_local_unchanged_cmd,
6377 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6378 NO_STR
6379 NEIGHBOR_STR
6380 NEIGHBOR_ADDR_STR2
6381 "Configure treatment of outgoing link-local-nexthop attribute\n"
6382 "Leave link-local nexthop unchanged for this peer\n")
6383 {
6384 int idx_peer = 2;
6385 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6386 bgp_node_afi(vty), bgp_node_safi(vty),
6387 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6388 }
6389
6390 DEFUN (neighbor_attr_unchanged,
6391 neighbor_attr_unchanged_cmd,
6392 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6393 NEIGHBOR_STR
6394 NEIGHBOR_ADDR_STR2
6395 "BGP attribute is propagated unchanged to this neighbor\n"
6396 "As-path attribute\n"
6397 "Nexthop attribute\n"
6398 "Med attribute\n")
6399 {
6400 int idx = 0;
6401 char *peer_str = argv[1]->arg;
6402 struct peer *peer;
6403 bool aspath = false;
6404 bool nexthop = false;
6405 bool med = false;
6406 afi_t afi = bgp_node_afi(vty);
6407 safi_t safi = bgp_node_safi(vty);
6408 int ret = 0;
6409
6410 peer = peer_and_group_lookup_vty(vty, peer_str);
6411 if (!peer)
6412 return CMD_WARNING_CONFIG_FAILED;
6413
6414 if (argv_find(argv, argc, "as-path", &idx))
6415 aspath = true;
6416
6417 idx = 0;
6418 if (argv_find(argv, argc, "next-hop", &idx))
6419 nexthop = true;
6420
6421 idx = 0;
6422 if (argv_find(argv, argc, "med", &idx))
6423 med = true;
6424
6425 /* no flags means all of them! */
6426 if (!aspath && !nexthop && !med) {
6427 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6428 PEER_FLAG_AS_PATH_UNCHANGED);
6429 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6430 PEER_FLAG_NEXTHOP_UNCHANGED);
6431 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6432 PEER_FLAG_MED_UNCHANGED);
6433 } else {
6434 if (!aspath) {
6435 if (peer_af_flag_check(peer, afi, safi,
6436 PEER_FLAG_AS_PATH_UNCHANGED)) {
6437 ret |= peer_af_flag_unset_vty(
6438 vty, peer_str, afi, safi,
6439 PEER_FLAG_AS_PATH_UNCHANGED);
6440 }
6441 } else
6442 ret |= peer_af_flag_set_vty(
6443 vty, peer_str, afi, safi,
6444 PEER_FLAG_AS_PATH_UNCHANGED);
6445
6446 if (!nexthop) {
6447 if (peer_af_flag_check(peer, afi, safi,
6448 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6449 ret |= peer_af_flag_unset_vty(
6450 vty, peer_str, afi, safi,
6451 PEER_FLAG_NEXTHOP_UNCHANGED);
6452 }
6453 } else
6454 ret |= peer_af_flag_set_vty(
6455 vty, peer_str, afi, safi,
6456 PEER_FLAG_NEXTHOP_UNCHANGED);
6457
6458 if (!med) {
6459 if (peer_af_flag_check(peer, afi, safi,
6460 PEER_FLAG_MED_UNCHANGED)) {
6461 ret |= peer_af_flag_unset_vty(
6462 vty, peer_str, afi, safi,
6463 PEER_FLAG_MED_UNCHANGED);
6464 }
6465 } else
6466 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6467 PEER_FLAG_MED_UNCHANGED);
6468 }
6469
6470 return ret;
6471 }
6472
6473 ALIAS_HIDDEN(
6474 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6475 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6476 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6477 "BGP attribute is propagated unchanged to this neighbor\n"
6478 "As-path attribute\n"
6479 "Nexthop attribute\n"
6480 "Med attribute\n")
6481
6482 DEFUN (no_neighbor_attr_unchanged,
6483 no_neighbor_attr_unchanged_cmd,
6484 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6485 NO_STR
6486 NEIGHBOR_STR
6487 NEIGHBOR_ADDR_STR2
6488 "BGP attribute is propagated unchanged to this neighbor\n"
6489 "As-path attribute\n"
6490 "Nexthop attribute\n"
6491 "Med attribute\n")
6492 {
6493 int idx = 0;
6494 char *peer_str = argv[2]->arg;
6495 struct peer *peer;
6496 bool aspath = false;
6497 bool nexthop = false;
6498 bool med = false;
6499 afi_t afi = bgp_node_afi(vty);
6500 safi_t safi = bgp_node_safi(vty);
6501 int ret = 0;
6502
6503 peer = peer_and_group_lookup_vty(vty, peer_str);
6504 if (!peer)
6505 return CMD_WARNING_CONFIG_FAILED;
6506
6507 if (argv_find(argv, argc, "as-path", &idx))
6508 aspath = true;
6509
6510 idx = 0;
6511 if (argv_find(argv, argc, "next-hop", &idx))
6512 nexthop = true;
6513
6514 idx = 0;
6515 if (argv_find(argv, argc, "med", &idx))
6516 med = true;
6517
6518 if (!aspath && !nexthop && !med) // no flags means all of them!
6519 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6520 PEER_FLAG_AS_PATH_UNCHANGED)
6521 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6522 PEER_FLAG_NEXTHOP_UNCHANGED)
6523 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6524 PEER_FLAG_MED_UNCHANGED);
6525
6526 if (aspath)
6527 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6528 PEER_FLAG_AS_PATH_UNCHANGED);
6529
6530 if (nexthop)
6531 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6532 PEER_FLAG_NEXTHOP_UNCHANGED);
6533
6534 if (med)
6535 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6536 PEER_FLAG_MED_UNCHANGED);
6537
6538 return ret;
6539 }
6540
6541 ALIAS_HIDDEN(
6542 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6543 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6544 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6545 "BGP attribute is propagated unchanged to this neighbor\n"
6546 "As-path attribute\n"
6547 "Nexthop attribute\n"
6548 "Med attribute\n")
6549
6550 /* EBGP multihop configuration. */
6551 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6552 const char *ttl_str)
6553 {
6554 struct peer *peer;
6555 unsigned int ttl;
6556
6557 peer = peer_and_group_lookup_vty(vty, ip_str);
6558 if (!peer)
6559 return CMD_WARNING_CONFIG_FAILED;
6560
6561 if (peer->conf_if)
6562 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6563
6564 if (!ttl_str)
6565 ttl = MAXTTL;
6566 else
6567 ttl = strtoul(ttl_str, NULL, 10);
6568
6569 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6570 }
6571
6572 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6573 {
6574 struct peer *peer;
6575
6576 peer = peer_and_group_lookup_vty(vty, ip_str);
6577 if (!peer)
6578 return CMD_WARNING_CONFIG_FAILED;
6579
6580 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6581 }
6582
6583 /* neighbor ebgp-multihop. */
6584 DEFUN (neighbor_ebgp_multihop,
6585 neighbor_ebgp_multihop_cmd,
6586 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6587 NEIGHBOR_STR
6588 NEIGHBOR_ADDR_STR2
6589 "Allow EBGP neighbors not on directly connected networks\n")
6590 {
6591 int idx_peer = 1;
6592 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6593 }
6594
6595 DEFUN (neighbor_ebgp_multihop_ttl,
6596 neighbor_ebgp_multihop_ttl_cmd,
6597 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6598 NEIGHBOR_STR
6599 NEIGHBOR_ADDR_STR2
6600 "Allow EBGP neighbors not on directly connected networks\n"
6601 "maximum hop count\n")
6602 {
6603 int idx_peer = 1;
6604 int idx_number = 3;
6605 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6606 argv[idx_number]->arg);
6607 }
6608
6609 DEFUN (no_neighbor_ebgp_multihop,
6610 no_neighbor_ebgp_multihop_cmd,
6611 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6612 NO_STR
6613 NEIGHBOR_STR
6614 NEIGHBOR_ADDR_STR2
6615 "Allow EBGP neighbors not on directly connected networks\n"
6616 "maximum hop count\n")
6617 {
6618 int idx_peer = 2;
6619 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6620 }
6621
6622 DEFPY (neighbor_aigp,
6623 neighbor_aigp_cmd,
6624 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6625 NO_STR
6626 NEIGHBOR_STR
6627 NEIGHBOR_ADDR_STR2
6628 "Enable send and receive of the AIGP attribute per neighbor\n")
6629 {
6630 struct peer *peer;
6631
6632 peer = peer_and_group_lookup_vty(vty, neighbor);
6633 if (!peer)
6634 return CMD_WARNING_CONFIG_FAILED;
6635
6636 if (no)
6637 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6638 else
6639 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6640 }
6641
6642 static uint8_t get_role_by_name(const char *role_str)
6643 {
6644 if (strncmp(role_str, "peer", 2) == 0)
6645 return ROLE_PEER;
6646 if (strncmp(role_str, "provider", 2) == 0)
6647 return ROLE_PROVIDER;
6648 if (strncmp(role_str, "customer", 2) == 0)
6649 return ROLE_CUSTOMER;
6650 if (strncmp(role_str, "rs-server", 4) == 0)
6651 return ROLE_RS_SERVER;
6652 if (strncmp(role_str, "rs-client", 4) == 0)
6653 return ROLE_RS_CLIENT;
6654 return ROLE_UNDEFINED;
6655 }
6656
6657 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6658 const char *role_str, bool strict_mode)
6659 {
6660 struct peer *peer;
6661
6662 peer = peer_and_group_lookup_vty(vty, ip_str);
6663 if (!peer)
6664 return CMD_WARNING_CONFIG_FAILED;
6665 uint8_t role = get_role_by_name(role_str);
6666
6667 if (role == ROLE_UNDEFINED)
6668 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6669 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6670 }
6671
6672 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6673 {
6674 struct peer *peer;
6675
6676 peer = peer_and_group_lookup_vty(vty, ip_str);
6677 if (!peer)
6678 return CMD_WARNING_CONFIG_FAILED;
6679 return bgp_vty_return(vty, peer_role_unset(peer));
6680 }
6681
6682 DEFPY(neighbor_role,
6683 neighbor_role_cmd,
6684 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6685 NEIGHBOR_STR
6686 NEIGHBOR_ADDR_STR2
6687 "Set session role\n"
6688 ROLE_STR)
6689 {
6690 int idx_peer = 1;
6691 int idx_role = 3;
6692
6693 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6694 false);
6695 }
6696
6697 DEFPY(neighbor_role_strict,
6698 neighbor_role_strict_cmd,
6699 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6700 NEIGHBOR_STR
6701 NEIGHBOR_ADDR_STR2
6702 "Set session role\n"
6703 ROLE_STR
6704 "Use additional restriction on peer\n")
6705 {
6706 int idx_peer = 1;
6707 int idx_role = 3;
6708
6709 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6710 true);
6711 }
6712
6713 DEFPY(no_neighbor_role,
6714 no_neighbor_role_cmd,
6715 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6716 NO_STR
6717 NEIGHBOR_STR
6718 NEIGHBOR_ADDR_STR2
6719 "Set session role\n"
6720 ROLE_STR
6721 "Use additional restriction on peer\n")
6722 {
6723 int idx_peer = 2;
6724
6725 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6726 }
6727
6728 /* disable-connected-check */
6729 DEFUN (neighbor_disable_connected_check,
6730 neighbor_disable_connected_check_cmd,
6731 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6732 NEIGHBOR_STR
6733 NEIGHBOR_ADDR_STR2
6734 "one-hop away EBGP peer using loopback address\n"
6735 "Enforce EBGP neighbors perform multihop\n")
6736 {
6737 int idx_peer = 1;
6738 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6739 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6740 }
6741
6742 DEFUN (no_neighbor_disable_connected_check,
6743 no_neighbor_disable_connected_check_cmd,
6744 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6745 NO_STR
6746 NEIGHBOR_STR
6747 NEIGHBOR_ADDR_STR2
6748 "one-hop away EBGP peer using loopback address\n"
6749 "Enforce EBGP neighbors perform multihop\n")
6750 {
6751 int idx_peer = 2;
6752 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6753 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6754 }
6755
6756 /* disable-link-bw-encoding-ieee */
6757 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6758 neighbor_disable_link_bw_encoding_ieee_cmd,
6759 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6761 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6762 {
6763 int idx_peer = 1;
6764
6765 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6766 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6767 }
6768
6769 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6770 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6771 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6773 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6774 {
6775 int idx_peer = 2;
6776
6777 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6778 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6779 }
6780
6781 /* extended-optional-parameters */
6782 DEFUN(neighbor_extended_optional_parameters,
6783 neighbor_extended_optional_parameters_cmd,
6784 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6785 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6786 "Force the extended optional parameters format for OPEN messages\n")
6787 {
6788 int idx_peer = 1;
6789
6790 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6791 PEER_FLAG_EXTENDED_OPT_PARAMS);
6792 }
6793
6794 DEFUN(no_neighbor_extended_optional_parameters,
6795 no_neighbor_extended_optional_parameters_cmd,
6796 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6797 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6798 "Force the extended optional parameters format for OPEN messages\n")
6799 {
6800 int idx_peer = 2;
6801
6802 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6803 PEER_FLAG_EXTENDED_OPT_PARAMS);
6804 }
6805
6806 /* enforce-first-as */
6807 DEFUN (neighbor_enforce_first_as,
6808 neighbor_enforce_first_as_cmd,
6809 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6810 NEIGHBOR_STR
6811 NEIGHBOR_ADDR_STR2
6812 "Enforce the first AS for EBGP routes\n")
6813 {
6814 int idx_peer = 1;
6815
6816 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6817 PEER_FLAG_ENFORCE_FIRST_AS);
6818 }
6819
6820 DEFUN (no_neighbor_enforce_first_as,
6821 no_neighbor_enforce_first_as_cmd,
6822 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6823 NO_STR
6824 NEIGHBOR_STR
6825 NEIGHBOR_ADDR_STR2
6826 "Enforce the first AS for EBGP routes\n")
6827 {
6828 int idx_peer = 2;
6829
6830 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6831 PEER_FLAG_ENFORCE_FIRST_AS);
6832 }
6833
6834
6835 DEFUN (neighbor_description,
6836 neighbor_description_cmd,
6837 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6838 NEIGHBOR_STR
6839 NEIGHBOR_ADDR_STR2
6840 "Neighbor specific description\n"
6841 "Up to 80 characters describing this neighbor\n")
6842 {
6843 int idx_peer = 1;
6844 int idx_line = 3;
6845 struct peer *peer;
6846 char *str;
6847
6848 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6849 if (!peer)
6850 return CMD_WARNING_CONFIG_FAILED;
6851
6852 str = argv_concat(argv, argc, idx_line);
6853
6854 peer_description_set(peer, str);
6855
6856 XFREE(MTYPE_TMP, str);
6857
6858 return CMD_SUCCESS;
6859 }
6860
6861 DEFUN (no_neighbor_description,
6862 no_neighbor_description_cmd,
6863 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6864 NO_STR
6865 NEIGHBOR_STR
6866 NEIGHBOR_ADDR_STR2
6867 "Neighbor specific description\n")
6868 {
6869 int idx_peer = 2;
6870 struct peer *peer;
6871
6872 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6873 if (!peer)
6874 return CMD_WARNING_CONFIG_FAILED;
6875
6876 peer_description_unset(peer);
6877
6878 return CMD_SUCCESS;
6879 }
6880
6881 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6882 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6883 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6884 "Neighbor specific description\n"
6885 "Up to 80 characters describing this neighbor\n")
6886
6887 /* Neighbor update-source. */
6888 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6889 const char *source_str)
6890 {
6891 struct peer *peer;
6892 struct prefix p;
6893 union sockunion su;
6894
6895 peer = peer_and_group_lookup_vty(vty, peer_str);
6896 if (!peer)
6897 return CMD_WARNING_CONFIG_FAILED;
6898
6899 if (peer->conf_if)
6900 return CMD_WARNING;
6901
6902 if (source_str) {
6903 if (str2sockunion(source_str, &su) == 0)
6904 peer_update_source_addr_set(peer, &su);
6905 else {
6906 if (str2prefix(source_str, &p)) {
6907 vty_out(vty,
6908 "%% Invalid update-source, remove prefix length \n");
6909 return CMD_WARNING_CONFIG_FAILED;
6910 } else
6911 peer_update_source_if_set(peer, source_str);
6912 }
6913 } else
6914 peer_update_source_unset(peer);
6915
6916 return CMD_SUCCESS;
6917 }
6918
6919 #define BGP_UPDATE_SOURCE_HELP_STR \
6920 "IPv4 address\n" \
6921 "IPv6 address\n" \
6922 "Interface name (requires zebra to be running)\n"
6923
6924 DEFUN (neighbor_update_source,
6925 neighbor_update_source_cmd,
6926 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6927 NEIGHBOR_STR
6928 NEIGHBOR_ADDR_STR2
6929 "Source of routing updates\n"
6930 BGP_UPDATE_SOURCE_HELP_STR)
6931 {
6932 int idx_peer = 1;
6933 int idx_peer_2 = 3;
6934 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6935 argv[idx_peer_2]->arg);
6936 }
6937
6938 DEFUN (no_neighbor_update_source,
6939 no_neighbor_update_source_cmd,
6940 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6941 NO_STR
6942 NEIGHBOR_STR
6943 NEIGHBOR_ADDR_STR2
6944 "Source of routing updates\n"
6945 BGP_UPDATE_SOURCE_HELP_STR)
6946 {
6947 int idx_peer = 2;
6948 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6949 }
6950
6951 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6952 afi_t afi, safi_t safi,
6953 const char *rmap, int set)
6954 {
6955 int ret;
6956 struct peer *peer;
6957 struct route_map *route_map = NULL;
6958
6959 peer = peer_and_group_lookup_vty(vty, peer_str);
6960 if (!peer)
6961 return CMD_WARNING_CONFIG_FAILED;
6962
6963 if (set) {
6964 if (rmap)
6965 route_map = route_map_lookup_warn_noexist(vty, rmap);
6966 ret = peer_default_originate_set(peer, afi, safi,
6967 rmap, route_map);
6968 } else
6969 ret = peer_default_originate_unset(peer, afi, safi);
6970
6971 return bgp_vty_return(vty, ret);
6972 }
6973
6974 /* neighbor default-originate. */
6975 DEFUN (neighbor_default_originate,
6976 neighbor_default_originate_cmd,
6977 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6978 NEIGHBOR_STR
6979 NEIGHBOR_ADDR_STR2
6980 "Originate default route to this neighbor\n")
6981 {
6982 int idx_peer = 1;
6983 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6984 bgp_node_afi(vty),
6985 bgp_node_safi(vty), NULL, 1);
6986 }
6987
6988 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6989 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6990 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6991 "Originate default route to this neighbor\n")
6992
6993 DEFUN (neighbor_default_originate_rmap,
6994 neighbor_default_originate_rmap_cmd,
6995 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6996 NEIGHBOR_STR
6997 NEIGHBOR_ADDR_STR2
6998 "Originate default route to this neighbor\n"
6999 "Route-map to specify criteria to originate default\n"
7000 "route-map name\n")
7001 {
7002 int idx_peer = 1;
7003 int idx_word = 4;
7004 return peer_default_originate_set_vty(
7005 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7006 argv[idx_word]->arg, 1);
7007 }
7008
7009 ALIAS_HIDDEN(
7010 neighbor_default_originate_rmap,
7011 neighbor_default_originate_rmap_hidden_cmd,
7012 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
7013 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7014 "Originate default route to this neighbor\n"
7015 "Route-map to specify criteria to originate default\n"
7016 "route-map name\n")
7017
7018 DEFUN (no_neighbor_default_originate,
7019 no_neighbor_default_originate_cmd,
7020 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
7021 NO_STR
7022 NEIGHBOR_STR
7023 NEIGHBOR_ADDR_STR2
7024 "Originate default route to this neighbor\n"
7025 "Route-map to specify criteria to originate default\n"
7026 "route-map name\n")
7027 {
7028 int idx_peer = 2;
7029 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7030 bgp_node_afi(vty),
7031 bgp_node_safi(vty), NULL, 0);
7032 }
7033
7034 ALIAS_HIDDEN(
7035 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7036 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
7037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7038 "Originate default route to this neighbor\n"
7039 "Route-map to specify criteria to originate default\n"
7040 "route-map name\n")
7041
7042
7043 /* Set neighbor's BGP port. */
7044 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7045 const char *port_str)
7046 {
7047 struct peer *peer;
7048 uint16_t port;
7049 struct servent *sp;
7050
7051 peer = peer_and_group_lookup_vty(vty, ip_str);
7052 if (!peer)
7053 return CMD_WARNING_CONFIG_FAILED;
7054
7055 if (!port_str) {
7056 sp = getservbyname("bgp", "tcp");
7057 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7058 } else {
7059 port = strtoul(port_str, NULL, 10);
7060 }
7061
7062 peer_port_set(peer, port);
7063
7064 return CMD_SUCCESS;
7065 }
7066
7067 /* Set specified peer's BGP port. */
7068 DEFUN (neighbor_port,
7069 neighbor_port_cmd,
7070 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7071 NEIGHBOR_STR
7072 NEIGHBOR_ADDR_STR2
7073 "Neighbor's BGP port\n"
7074 "TCP port number\n")
7075 {
7076 int idx_ip = 1;
7077 int idx_number = 3;
7078 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7079 argv[idx_number]->arg);
7080 }
7081
7082 DEFUN (no_neighbor_port,
7083 no_neighbor_port_cmd,
7084 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7085 NO_STR
7086 NEIGHBOR_STR
7087 NEIGHBOR_ADDR_STR2
7088 "Neighbor's BGP port\n"
7089 "TCP port number\n")
7090 {
7091 int idx_ip = 2;
7092 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7093 }
7094
7095
7096 /* neighbor weight. */
7097 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7098 safi_t safi, const char *weight_str)
7099 {
7100 int ret;
7101 struct peer *peer;
7102 unsigned long weight;
7103
7104 peer = peer_and_group_lookup_vty(vty, ip_str);
7105 if (!peer)
7106 return CMD_WARNING_CONFIG_FAILED;
7107
7108 weight = strtoul(weight_str, NULL, 10);
7109
7110 ret = peer_weight_set(peer, afi, safi, weight);
7111 return bgp_vty_return(vty, ret);
7112 }
7113
7114 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7115 safi_t safi)
7116 {
7117 int ret;
7118 struct peer *peer;
7119
7120 peer = peer_and_group_lookup_vty(vty, ip_str);
7121 if (!peer)
7122 return CMD_WARNING_CONFIG_FAILED;
7123
7124 ret = peer_weight_unset(peer, afi, safi);
7125 return bgp_vty_return(vty, ret);
7126 }
7127
7128 DEFUN (neighbor_weight,
7129 neighbor_weight_cmd,
7130 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7131 NEIGHBOR_STR
7132 NEIGHBOR_ADDR_STR2
7133 "Set default weight for routes from this neighbor\n"
7134 "default weight\n")
7135 {
7136 int idx_peer = 1;
7137 int idx_number = 3;
7138 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7139 bgp_node_safi(vty), argv[idx_number]->arg);
7140 }
7141
7142 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7143 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7144 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7145 "Set default weight for routes from this neighbor\n"
7146 "default weight\n")
7147
7148 DEFUN (no_neighbor_weight,
7149 no_neighbor_weight_cmd,
7150 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7151 NO_STR
7152 NEIGHBOR_STR
7153 NEIGHBOR_ADDR_STR2
7154 "Set default weight for routes from this neighbor\n"
7155 "default weight\n")
7156 {
7157 int idx_peer = 2;
7158 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7159 bgp_node_afi(vty), bgp_node_safi(vty));
7160 }
7161
7162 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7163 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7164 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7165 "Set default weight for routes from this neighbor\n"
7166 "default weight\n")
7167
7168
7169 /* Override capability negotiation. */
7170 DEFUN (neighbor_override_capability,
7171 neighbor_override_capability_cmd,
7172 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7173 NEIGHBOR_STR
7174 NEIGHBOR_ADDR_STR2
7175 "Override capability negotiation result\n")
7176 {
7177 int idx_peer = 1;
7178 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7179 PEER_FLAG_OVERRIDE_CAPABILITY);
7180 }
7181
7182 DEFUN (no_neighbor_override_capability,
7183 no_neighbor_override_capability_cmd,
7184 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7185 NO_STR
7186 NEIGHBOR_STR
7187 NEIGHBOR_ADDR_STR2
7188 "Override capability negotiation result\n")
7189 {
7190 int idx_peer = 2;
7191 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7192 PEER_FLAG_OVERRIDE_CAPABILITY);
7193 }
7194
7195 DEFUN (neighbor_strict_capability,
7196 neighbor_strict_capability_cmd,
7197 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7198 NEIGHBOR_STR
7199 NEIGHBOR_ADDR_STR2
7200 "Strict capability negotiation match\n")
7201 {
7202 int idx_peer = 1;
7203
7204 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7205 PEER_FLAG_STRICT_CAP_MATCH);
7206 }
7207
7208 DEFUN (no_neighbor_strict_capability,
7209 no_neighbor_strict_capability_cmd,
7210 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7211 NO_STR
7212 NEIGHBOR_STR
7213 NEIGHBOR_ADDR_STR2
7214 "Strict capability negotiation match\n")
7215 {
7216 int idx_peer = 2;
7217
7218 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7219 PEER_FLAG_STRICT_CAP_MATCH);
7220 }
7221
7222 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7223 const char *keep_str, const char *hold_str)
7224 {
7225 int ret;
7226 struct peer *peer;
7227 uint32_t keepalive;
7228 uint32_t holdtime;
7229
7230 peer = peer_and_group_lookup_vty(vty, ip_str);
7231 if (!peer)
7232 return CMD_WARNING_CONFIG_FAILED;
7233
7234 keepalive = strtoul(keep_str, NULL, 10);
7235 holdtime = strtoul(hold_str, NULL, 10);
7236
7237 ret = peer_timers_set(peer, keepalive, holdtime);
7238
7239 return bgp_vty_return(vty, ret);
7240 }
7241
7242 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7243 {
7244 int ret;
7245 struct peer *peer;
7246
7247 peer = peer_and_group_lookup_vty(vty, ip_str);
7248 if (!peer)
7249 return CMD_WARNING_CONFIG_FAILED;
7250
7251 ret = peer_timers_unset(peer);
7252
7253 return bgp_vty_return(vty, ret);
7254 }
7255
7256 DEFUN (neighbor_timers,
7257 neighbor_timers_cmd,
7258 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7259 NEIGHBOR_STR
7260 NEIGHBOR_ADDR_STR2
7261 "BGP per neighbor timers\n"
7262 "Keepalive interval\n"
7263 "Holdtime\n")
7264 {
7265 int idx_peer = 1;
7266 int idx_number = 3;
7267 int idx_number_2 = 4;
7268 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7269 argv[idx_number]->arg,
7270 argv[idx_number_2]->arg);
7271 }
7272
7273 DEFUN (no_neighbor_timers,
7274 no_neighbor_timers_cmd,
7275 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7276 NO_STR
7277 NEIGHBOR_STR
7278 NEIGHBOR_ADDR_STR2
7279 "BGP per neighbor timers\n"
7280 "Keepalive interval\n"
7281 "Holdtime\n")
7282 {
7283 int idx_peer = 2;
7284 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7285 }
7286
7287
7288 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7289 const char *time_str)
7290 {
7291 int ret;
7292 struct peer *peer;
7293 uint32_t connect;
7294
7295 peer = peer_and_group_lookup_vty(vty, ip_str);
7296 if (!peer)
7297 return CMD_WARNING_CONFIG_FAILED;
7298
7299 connect = strtoul(time_str, NULL, 10);
7300
7301 ret = peer_timers_connect_set(peer, connect);
7302
7303 return bgp_vty_return(vty, ret);
7304 }
7305
7306 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7307 {
7308 int ret;
7309 struct peer *peer;
7310
7311 peer = peer_and_group_lookup_vty(vty, ip_str);
7312 if (!peer)
7313 return CMD_WARNING_CONFIG_FAILED;
7314
7315 ret = peer_timers_connect_unset(peer);
7316
7317 return bgp_vty_return(vty, ret);
7318 }
7319
7320 DEFUN (neighbor_timers_connect,
7321 neighbor_timers_connect_cmd,
7322 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7323 NEIGHBOR_STR
7324 NEIGHBOR_ADDR_STR2
7325 "BGP per neighbor timers\n"
7326 "BGP connect timer\n"
7327 "Connect timer\n")
7328 {
7329 int idx_peer = 1;
7330 int idx_number = 4;
7331 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7332 argv[idx_number]->arg);
7333 }
7334
7335 DEFUN (no_neighbor_timers_connect,
7336 no_neighbor_timers_connect_cmd,
7337 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7338 NO_STR
7339 NEIGHBOR_STR
7340 NEIGHBOR_ADDR_STR2
7341 "BGP per neighbor timers\n"
7342 "BGP connect timer\n"
7343 "Connect timer\n")
7344 {
7345 int idx_peer = 2;
7346 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7347 }
7348
7349 DEFPY (neighbor_timers_delayopen,
7350 neighbor_timers_delayopen_cmd,
7351 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7352 NEIGHBOR_STR
7353 NEIGHBOR_ADDR_STR2
7354 "BGP per neighbor timers\n"
7355 "RFC 4271 DelayOpenTimer\n"
7356 "DelayOpenTime timer interval\n")
7357 {
7358 struct peer *peer;
7359
7360 peer = peer_and_group_lookup_vty(vty, neighbor);
7361 if (!peer)
7362 return CMD_WARNING_CONFIG_FAILED;
7363
7364 if (!interval) {
7365 if (peer_timers_delayopen_unset(peer))
7366 return CMD_WARNING_CONFIG_FAILED;
7367 } else {
7368 if (peer_timers_delayopen_set(peer, interval))
7369 return CMD_WARNING_CONFIG_FAILED;
7370 }
7371
7372 return CMD_SUCCESS;
7373 }
7374
7375 DEFPY (no_neighbor_timers_delayopen,
7376 no_neighbor_timers_delayopen_cmd,
7377 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7378 NO_STR
7379 NEIGHBOR_STR
7380 NEIGHBOR_ADDR_STR2
7381 "BGP per neighbor timers\n"
7382 "RFC 4271 DelayOpenTimer\n"
7383 "DelayOpenTime timer interval\n")
7384 {
7385 struct peer *peer;
7386
7387 peer = peer_and_group_lookup_vty(vty, neighbor);
7388 if (!peer)
7389 return CMD_WARNING_CONFIG_FAILED;
7390
7391 if (peer_timers_delayopen_unset(peer))
7392 return CMD_WARNING_CONFIG_FAILED;
7393
7394 return CMD_SUCCESS;
7395 }
7396
7397 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7398 const char *time_str, int set)
7399 {
7400 int ret;
7401 struct peer *peer;
7402 uint32_t routeadv = 0;
7403
7404 peer = peer_and_group_lookup_vty(vty, ip_str);
7405 if (!peer)
7406 return CMD_WARNING_CONFIG_FAILED;
7407
7408 if (time_str)
7409 routeadv = strtoul(time_str, NULL, 10);
7410
7411 if (set)
7412 ret = peer_advertise_interval_set(peer, routeadv);
7413 else
7414 ret = peer_advertise_interval_unset(peer);
7415
7416 return bgp_vty_return(vty, ret);
7417 }
7418
7419 DEFUN (neighbor_advertise_interval,
7420 neighbor_advertise_interval_cmd,
7421 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7422 NEIGHBOR_STR
7423 NEIGHBOR_ADDR_STR2
7424 "Minimum interval between sending BGP routing updates\n"
7425 "time in seconds\n")
7426 {
7427 int idx_peer = 1;
7428 int idx_number = 3;
7429 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7430 argv[idx_number]->arg, 1);
7431 }
7432
7433 DEFUN (no_neighbor_advertise_interval,
7434 no_neighbor_advertise_interval_cmd,
7435 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7436 NO_STR
7437 NEIGHBOR_STR
7438 NEIGHBOR_ADDR_STR2
7439 "Minimum interval between sending BGP routing updates\n"
7440 "time in seconds\n")
7441 {
7442 int idx_peer = 2;
7443 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7444 }
7445
7446
7447 /* Time to wait before processing route-map updates */
7448 DEFUN (bgp_set_route_map_delay_timer,
7449 bgp_set_route_map_delay_timer_cmd,
7450 "bgp route-map delay-timer (0-600)",
7451 SET_STR
7452 "BGP route-map delay timer\n"
7453 "Time in secs to wait before processing route-map changes\n"
7454 "0 disables the timer, no route updates happen when route-maps change\n")
7455 {
7456 int idx_number = 3;
7457 uint32_t rmap_delay_timer;
7458
7459 if (argv[idx_number]->arg) {
7460 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7461 bm->rmap_update_timer = rmap_delay_timer;
7462
7463 /* if the dynamic update handling is being disabled, and a timer
7464 * is
7465 * running, stop the timer and act as if the timer has already
7466 * fired.
7467 */
7468 if (!rmap_delay_timer && bm->t_rmap_update) {
7469 THREAD_OFF(bm->t_rmap_update);
7470 thread_execute(bm->master, bgp_route_map_update_timer,
7471 NULL, 0);
7472 }
7473 return CMD_SUCCESS;
7474 } else {
7475 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7476 return CMD_WARNING_CONFIG_FAILED;
7477 }
7478 }
7479
7480 DEFUN (no_bgp_set_route_map_delay_timer,
7481 no_bgp_set_route_map_delay_timer_cmd,
7482 "no bgp route-map delay-timer [(0-600)]",
7483 NO_STR
7484 BGP_STR
7485 "Default BGP route-map delay timer\n"
7486 "Reset to default time to wait for processing route-map changes\n"
7487 "0 disables the timer, no route updates happen when route-maps change\n")
7488 {
7489
7490 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7491
7492 return CMD_SUCCESS;
7493 }
7494
7495 /* neighbor interface */
7496 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7497 const char *str)
7498 {
7499 struct peer *peer;
7500
7501 peer = peer_lookup_vty(vty, ip_str);
7502 if (!peer || peer->conf_if) {
7503 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7504 return CMD_WARNING_CONFIG_FAILED;
7505 }
7506
7507 if (str)
7508 peer_interface_set(peer, str);
7509 else
7510 peer_interface_unset(peer);
7511
7512 return CMD_SUCCESS;
7513 }
7514
7515 DEFUN (neighbor_interface,
7516 neighbor_interface_cmd,
7517 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7518 NEIGHBOR_STR
7519 NEIGHBOR_ADDR_STR
7520 "Interface\n"
7521 "Interface name\n")
7522 {
7523 int idx_ip = 1;
7524 int idx_word = 3;
7525
7526 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7527 }
7528
7529 DEFUN (no_neighbor_interface,
7530 no_neighbor_interface_cmd,
7531 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7532 NO_STR
7533 NEIGHBOR_STR
7534 NEIGHBOR_ADDR_STR
7535 "Interface\n"
7536 "Interface name\n")
7537 {
7538 int idx_peer = 2;
7539
7540 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7541 }
7542
7543 DEFUN (neighbor_distribute_list,
7544 neighbor_distribute_list_cmd,
7545 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7546 NEIGHBOR_STR
7547 NEIGHBOR_ADDR_STR2
7548 "Filter updates to/from this neighbor\n"
7549 "IP Access-list name\n"
7550 "Filter incoming updates\n"
7551 "Filter outgoing updates\n")
7552 {
7553 int idx_peer = 1;
7554 int idx_acl = 3;
7555 int direct, ret;
7556 struct peer *peer;
7557
7558 const char *pstr = argv[idx_peer]->arg;
7559 const char *acl = argv[idx_acl]->arg;
7560 const char *inout = argv[argc - 1]->text;
7561
7562 peer = peer_and_group_lookup_vty(vty, pstr);
7563 if (!peer)
7564 return CMD_WARNING_CONFIG_FAILED;
7565
7566 /* Check filter direction. */
7567 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7568 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7569 direct, acl);
7570
7571 return bgp_vty_return(vty, ret);
7572 }
7573
7574 ALIAS_HIDDEN(
7575 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7576 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7578 "Filter updates to/from this neighbor\n"
7579 "IP Access-list name\n"
7580 "Filter incoming updates\n"
7581 "Filter outgoing updates\n")
7582
7583 DEFUN (no_neighbor_distribute_list,
7584 no_neighbor_distribute_list_cmd,
7585 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7586 NO_STR
7587 NEIGHBOR_STR
7588 NEIGHBOR_ADDR_STR2
7589 "Filter updates to/from this neighbor\n"
7590 "IP Access-list name\n"
7591 "Filter incoming updates\n"
7592 "Filter outgoing updates\n")
7593 {
7594 int idx_peer = 2;
7595 int direct, ret;
7596 struct peer *peer;
7597
7598 const char *pstr = argv[idx_peer]->arg;
7599 const char *inout = argv[argc - 1]->text;
7600
7601 peer = peer_and_group_lookup_vty(vty, pstr);
7602 if (!peer)
7603 return CMD_WARNING_CONFIG_FAILED;
7604
7605 /* Check filter direction. */
7606 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7607 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7608 direct);
7609
7610 return bgp_vty_return(vty, ret);
7611 }
7612
7613 ALIAS_HIDDEN(
7614 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7615 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7616 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7617 "Filter updates to/from this neighbor\n"
7618 "IP Access-list name\n"
7619 "Filter incoming updates\n"
7620 "Filter outgoing updates\n")
7621
7622 /* Set prefix list to the peer. */
7623 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7624 afi_t afi, safi_t safi,
7625 const char *name_str,
7626 const char *direct_str)
7627 {
7628 int ret;
7629 int direct = FILTER_IN;
7630 struct peer *peer;
7631
7632 peer = peer_and_group_lookup_vty(vty, ip_str);
7633 if (!peer)
7634 return CMD_WARNING_CONFIG_FAILED;
7635
7636 /* Check filter direction. */
7637 if (strncmp(direct_str, "i", 1) == 0)
7638 direct = FILTER_IN;
7639 else if (strncmp(direct_str, "o", 1) == 0)
7640 direct = FILTER_OUT;
7641
7642 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7643
7644 return bgp_vty_return(vty, ret);
7645 }
7646
7647 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7648 afi_t afi, safi_t safi,
7649 const char *direct_str)
7650 {
7651 int ret;
7652 struct peer *peer;
7653 int direct = FILTER_IN;
7654
7655 peer = peer_and_group_lookup_vty(vty, ip_str);
7656 if (!peer)
7657 return CMD_WARNING_CONFIG_FAILED;
7658
7659 /* Check filter direction. */
7660 if (strncmp(direct_str, "i", 1) == 0)
7661 direct = FILTER_IN;
7662 else if (strncmp(direct_str, "o", 1) == 0)
7663 direct = FILTER_OUT;
7664
7665 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7666
7667 return bgp_vty_return(vty, ret);
7668 }
7669
7670 DEFUN (neighbor_prefix_list,
7671 neighbor_prefix_list_cmd,
7672 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7673 NEIGHBOR_STR
7674 NEIGHBOR_ADDR_STR2
7675 "Filter updates to/from this neighbor\n"
7676 "Name of a prefix list\n"
7677 "Filter incoming updates\n"
7678 "Filter outgoing updates\n")
7679 {
7680 int idx_peer = 1;
7681 int idx_word = 3;
7682 int idx_in_out = 4;
7683 return peer_prefix_list_set_vty(
7684 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7685 argv[idx_word]->arg, argv[idx_in_out]->arg);
7686 }
7687
7688 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7689 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7690 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7691 "Filter updates to/from this neighbor\n"
7692 "Name of a prefix list\n"
7693 "Filter incoming updates\n"
7694 "Filter outgoing updates\n")
7695
7696 DEFUN (no_neighbor_prefix_list,
7697 no_neighbor_prefix_list_cmd,
7698 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7699 NO_STR
7700 NEIGHBOR_STR
7701 NEIGHBOR_ADDR_STR2
7702 "Filter updates to/from this neighbor\n"
7703 "Name of a prefix list\n"
7704 "Filter incoming updates\n"
7705 "Filter outgoing updates\n")
7706 {
7707 int idx_peer = 2;
7708 int idx_in_out = 5;
7709 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7710 bgp_node_afi(vty), bgp_node_safi(vty),
7711 argv[idx_in_out]->arg);
7712 }
7713
7714 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7715 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7717 "Filter updates to/from this neighbor\n"
7718 "Name of a prefix list\n"
7719 "Filter incoming updates\n"
7720 "Filter outgoing updates\n")
7721
7722 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7723 safi_t safi, const char *name_str,
7724 const char *direct_str)
7725 {
7726 int ret;
7727 struct peer *peer;
7728 int direct = FILTER_IN;
7729
7730 peer = peer_and_group_lookup_vty(vty, ip_str);
7731 if (!peer)
7732 return CMD_WARNING_CONFIG_FAILED;
7733
7734 /* Check filter direction. */
7735 if (strncmp(direct_str, "i", 1) == 0)
7736 direct = FILTER_IN;
7737 else if (strncmp(direct_str, "o", 1) == 0)
7738 direct = FILTER_OUT;
7739
7740 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7741
7742 return bgp_vty_return(vty, ret);
7743 }
7744
7745 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7746 safi_t safi, const char *direct_str)
7747 {
7748 int ret;
7749 struct peer *peer;
7750 int direct = FILTER_IN;
7751
7752 peer = peer_and_group_lookup_vty(vty, ip_str);
7753 if (!peer)
7754 return CMD_WARNING_CONFIG_FAILED;
7755
7756 /* Check filter direction. */
7757 if (strncmp(direct_str, "i", 1) == 0)
7758 direct = FILTER_IN;
7759 else if (strncmp(direct_str, "o", 1) == 0)
7760 direct = FILTER_OUT;
7761
7762 ret = peer_aslist_unset(peer, afi, safi, direct);
7763
7764 return bgp_vty_return(vty, ret);
7765 }
7766
7767 DEFUN (neighbor_filter_list,
7768 neighbor_filter_list_cmd,
7769 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7770 NEIGHBOR_STR
7771 NEIGHBOR_ADDR_STR2
7772 "Establish BGP filters\n"
7773 "AS path access-list name\n"
7774 "Filter incoming routes\n"
7775 "Filter outgoing routes\n")
7776 {
7777 int idx_peer = 1;
7778 int idx_word = 3;
7779 int idx_in_out = 4;
7780 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7781 bgp_node_safi(vty), argv[idx_word]->arg,
7782 argv[idx_in_out]->arg);
7783 }
7784
7785 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7786 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7787 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7788 "Establish BGP filters\n"
7789 "AS path access-list name\n"
7790 "Filter incoming routes\n"
7791 "Filter outgoing routes\n")
7792
7793 DEFUN (no_neighbor_filter_list,
7794 no_neighbor_filter_list_cmd,
7795 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7796 NO_STR
7797 NEIGHBOR_STR
7798 NEIGHBOR_ADDR_STR2
7799 "Establish BGP filters\n"
7800 "AS path access-list name\n"
7801 "Filter incoming routes\n"
7802 "Filter outgoing routes\n")
7803 {
7804 int idx_peer = 2;
7805 int idx_in_out = 5;
7806 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7807 bgp_node_afi(vty), bgp_node_safi(vty),
7808 argv[idx_in_out]->arg);
7809 }
7810
7811 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7812 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7813 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7814 "Establish BGP filters\n"
7815 "AS path access-list name\n"
7816 "Filter incoming routes\n"
7817 "Filter outgoing routes\n")
7818
7819 /* Set advertise-map to the peer. */
7820 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7821 afi_t afi, safi_t safi,
7822 const char *advertise_str,
7823 const char *condition_str, bool condition,
7824 bool set)
7825 {
7826 int ret = CMD_WARNING_CONFIG_FAILED;
7827 struct peer *peer;
7828 struct route_map *advertise_map;
7829 struct route_map *condition_map;
7830
7831 peer = peer_and_group_lookup_vty(vty, ip_str);
7832 if (!peer)
7833 return ret;
7834
7835 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7836 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7837
7838 if (set)
7839 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7840 advertise_map, condition_str,
7841 condition_map, condition);
7842 else
7843 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7844 advertise_map, condition_str,
7845 condition_map, condition);
7846
7847 return bgp_vty_return(vty, ret);
7848 }
7849
7850 DEFPY (bgp_condadv_period,
7851 bgp_condadv_period_cmd,
7852 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7853 NO_STR
7854 BGP_STR
7855 "Conditional advertisement settings\n"
7856 "Set period to rescan BGP table to check if condition is met\n"
7857 "Period between BGP table scans, in seconds; default 60\n")
7858 {
7859 VTY_DECLVAR_CONTEXT(bgp, bgp);
7860
7861 bgp->condition_check_period =
7862 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7863
7864 return CMD_SUCCESS;
7865 }
7866
7867 DEFPY (neighbor_advertise_map,
7868 neighbor_advertise_map_cmd,
7869 "[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",
7870 NO_STR
7871 NEIGHBOR_STR
7872 NEIGHBOR_ADDR_STR2
7873 "Route-map to conditionally advertise routes\n"
7874 "Name of advertise map\n"
7875 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7876 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7877 "Name of the exist or non exist map\n")
7878 {
7879 bool condition = CONDITION_EXIST;
7880
7881 if (!strcmp(exist, "non-exist-map"))
7882 condition = CONDITION_NON_EXIST;
7883
7884 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7885 bgp_node_safi(vty), advertise_str,
7886 condition_str, condition, !no);
7887 }
7888
7889 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7890 "[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",
7891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7892 "Route-map to conditionally advertise routes\n"
7893 "Name of advertise map\n"
7894 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7895 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7896 "Name of the exist or non exist map\n")
7897
7898 /* Set route-map to the peer. */
7899 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7900 afi_t afi, safi_t safi, const char *name_str,
7901 const char *direct_str)
7902 {
7903 int ret;
7904 struct peer *peer;
7905 int direct = RMAP_IN;
7906 struct route_map *route_map;
7907
7908 peer = peer_and_group_lookup_vty(vty, ip_str);
7909 if (!peer)
7910 return CMD_WARNING_CONFIG_FAILED;
7911
7912 /* Check filter direction. */
7913 if (strncmp(direct_str, "in", 2) == 0)
7914 direct = RMAP_IN;
7915 else if (strncmp(direct_str, "o", 1) == 0)
7916 direct = RMAP_OUT;
7917
7918 route_map = route_map_lookup_warn_noexist(vty, name_str);
7919 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7920
7921 return bgp_vty_return(vty, ret);
7922 }
7923
7924 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7925 afi_t afi, safi_t safi,
7926 const char *direct_str)
7927 {
7928 int ret;
7929 struct peer *peer;
7930 int direct = RMAP_IN;
7931
7932 peer = peer_and_group_lookup_vty(vty, ip_str);
7933 if (!peer)
7934 return CMD_WARNING_CONFIG_FAILED;
7935
7936 /* Check filter direction. */
7937 if (strncmp(direct_str, "in", 2) == 0)
7938 direct = RMAP_IN;
7939 else if (strncmp(direct_str, "o", 1) == 0)
7940 direct = RMAP_OUT;
7941
7942 ret = peer_route_map_unset(peer, afi, safi, direct);
7943
7944 return bgp_vty_return(vty, ret);
7945 }
7946
7947 DEFUN (neighbor_route_map,
7948 neighbor_route_map_cmd,
7949 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7950 NEIGHBOR_STR
7951 NEIGHBOR_ADDR_STR2
7952 "Apply route map to neighbor\n"
7953 "Name of route map\n"
7954 "Apply map to incoming routes\n"
7955 "Apply map to outbound routes\n")
7956 {
7957 int idx_peer = 1;
7958 int idx_word = 3;
7959 int idx_in_out = 4;
7960 return peer_route_map_set_vty(
7961 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7962 argv[idx_word]->arg, argv[idx_in_out]->arg);
7963 }
7964
7965 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7966 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7968 "Apply route map to neighbor\n"
7969 "Name of route map\n"
7970 "Apply map to incoming routes\n"
7971 "Apply map to outbound routes\n")
7972
7973 DEFUN (no_neighbor_route_map,
7974 no_neighbor_route_map_cmd,
7975 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7976 NO_STR
7977 NEIGHBOR_STR
7978 NEIGHBOR_ADDR_STR2
7979 "Apply route map to neighbor\n"
7980 "Name of route map\n"
7981 "Apply map to incoming routes\n"
7982 "Apply map to outbound routes\n")
7983 {
7984 int idx_peer = 2;
7985 int idx_in_out = 5;
7986 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7987 bgp_node_afi(vty), bgp_node_safi(vty),
7988 argv[idx_in_out]->arg);
7989 }
7990
7991 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7992 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7993 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7994 "Apply route map to neighbor\n"
7995 "Name of route map\n"
7996 "Apply map to incoming routes\n"
7997 "Apply map to outbound routes\n")
7998
7999 /* Set unsuppress-map to the peer. */
8000 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8001 afi_t afi, safi_t safi,
8002 const char *name_str)
8003 {
8004 int ret;
8005 struct peer *peer;
8006 struct route_map *route_map;
8007
8008 peer = peer_and_group_lookup_vty(vty, ip_str);
8009 if (!peer)
8010 return CMD_WARNING_CONFIG_FAILED;
8011
8012 route_map = route_map_lookup_warn_noexist(vty, name_str);
8013 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8014
8015 return bgp_vty_return(vty, ret);
8016 }
8017
8018 /* Unset route-map from the peer. */
8019 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8020 afi_t afi, safi_t safi)
8021 {
8022 int ret;
8023 struct peer *peer;
8024
8025 peer = peer_and_group_lookup_vty(vty, ip_str);
8026 if (!peer)
8027 return CMD_WARNING_CONFIG_FAILED;
8028
8029 ret = peer_unsuppress_map_unset(peer, afi, safi);
8030
8031 return bgp_vty_return(vty, ret);
8032 }
8033
8034 DEFUN (neighbor_unsuppress_map,
8035 neighbor_unsuppress_map_cmd,
8036 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8037 NEIGHBOR_STR
8038 NEIGHBOR_ADDR_STR2
8039 "Route-map to selectively unsuppress suppressed routes\n"
8040 "Name of route map\n")
8041 {
8042 int idx_peer = 1;
8043 int idx_word = 3;
8044 return peer_unsuppress_map_set_vty(
8045 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8046 argv[idx_word]->arg);
8047 }
8048
8049 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8050 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8051 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8052 "Route-map to selectively unsuppress suppressed routes\n"
8053 "Name of route map\n")
8054
8055 DEFUN (no_neighbor_unsuppress_map,
8056 no_neighbor_unsuppress_map_cmd,
8057 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8058 NO_STR
8059 NEIGHBOR_STR
8060 NEIGHBOR_ADDR_STR2
8061 "Route-map to selectively unsuppress suppressed routes\n"
8062 "Name of route map\n")
8063 {
8064 int idx_peer = 2;
8065 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8066 bgp_node_afi(vty),
8067 bgp_node_safi(vty));
8068 }
8069
8070 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8071 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8072 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8073 "Route-map to selectively unsuppress suppressed routes\n"
8074 "Name of route map\n")
8075
8076 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8077 afi_t afi, safi_t safi,
8078 const char *num_str,
8079 const char *threshold_str, int warning,
8080 const char *restart_str,
8081 const char *force_str)
8082 {
8083 int ret;
8084 struct peer *peer;
8085 uint32_t max;
8086 uint8_t threshold;
8087 uint16_t restart;
8088
8089 peer = peer_and_group_lookup_vty(vty, ip_str);
8090 if (!peer)
8091 return CMD_WARNING_CONFIG_FAILED;
8092
8093 max = strtoul(num_str, NULL, 10);
8094 if (threshold_str)
8095 threshold = atoi(threshold_str);
8096 else
8097 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8098
8099 if (restart_str)
8100 restart = atoi(restart_str);
8101 else
8102 restart = 0;
8103
8104 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8105 restart, force_str ? true : false);
8106
8107 return bgp_vty_return(vty, ret);
8108 }
8109
8110 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8111 afi_t afi, safi_t safi)
8112 {
8113 int ret;
8114 struct peer *peer;
8115
8116 peer = peer_and_group_lookup_vty(vty, ip_str);
8117 if (!peer)
8118 return CMD_WARNING_CONFIG_FAILED;
8119
8120 ret = peer_maximum_prefix_unset(peer, afi, safi);
8121
8122 return bgp_vty_return(vty, ret);
8123 }
8124
8125 /* Maximum number of prefix to be sent to the neighbor. */
8126 DEFUN(neighbor_maximum_prefix_out,
8127 neighbor_maximum_prefix_out_cmd,
8128 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8129 NEIGHBOR_STR
8130 NEIGHBOR_ADDR_STR2
8131 "Maximum number of prefixes to be sent to this peer\n"
8132 "Maximum no. of prefix limit\n")
8133 {
8134 int ret;
8135 int idx_peer = 1;
8136 int idx_number = 3;
8137 struct peer *peer;
8138 uint32_t max;
8139 afi_t afi = bgp_node_afi(vty);
8140 safi_t safi = bgp_node_safi(vty);
8141
8142 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8143 if (!peer)
8144 return CMD_WARNING_CONFIG_FAILED;
8145
8146 max = strtoul(argv[idx_number]->arg, NULL, 10);
8147
8148 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8149
8150 return bgp_vty_return(vty, ret);
8151 }
8152
8153 DEFUN(no_neighbor_maximum_prefix_out,
8154 no_neighbor_maximum_prefix_out_cmd,
8155 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8156 NO_STR
8157 NEIGHBOR_STR
8158 NEIGHBOR_ADDR_STR2
8159 "Maximum number of prefixes to be sent to this peer\n"
8160 "Maximum no. of prefix limit\n")
8161 {
8162 int ret;
8163 int idx_peer = 2;
8164 struct peer *peer;
8165 afi_t afi = bgp_node_afi(vty);
8166 safi_t safi = bgp_node_safi(vty);
8167
8168 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8169 if (!peer)
8170 return CMD_WARNING_CONFIG_FAILED;
8171
8172 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8173
8174 return bgp_vty_return(vty, ret);
8175 }
8176
8177 /* Maximum number of prefix configuration. Prefix count is different
8178 for each peer configuration. So this configuration can be set for
8179 each peer configuration. */
8180 DEFUN (neighbor_maximum_prefix,
8181 neighbor_maximum_prefix_cmd,
8182 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8183 NEIGHBOR_STR
8184 NEIGHBOR_ADDR_STR2
8185 "Maximum number of prefix accept from this peer\n"
8186 "maximum no. of prefix limit\n"
8187 "Force checking all received routes not only accepted\n")
8188 {
8189 int idx_peer = 1;
8190 int idx_number = 3;
8191 int idx_force = 0;
8192 char *force = NULL;
8193
8194 if (argv_find(argv, argc, "force", &idx_force))
8195 force = argv[idx_force]->arg;
8196
8197 return peer_maximum_prefix_set_vty(
8198 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8199 argv[idx_number]->arg, NULL, 0, NULL, force);
8200 }
8201
8202 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8203 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8204 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8205 "Maximum number of prefix accept from this peer\n"
8206 "maximum no. of prefix limit\n"
8207 "Force checking all received routes not only accepted\n")
8208
8209 DEFUN (neighbor_maximum_prefix_threshold,
8210 neighbor_maximum_prefix_threshold_cmd,
8211 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [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 "Threshold value (%) at which to generate a warning msg\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_number_2 = 4;
8222 int idx_force = 0;
8223 char *force = NULL;
8224
8225 if (argv_find(argv, argc, "force", &idx_force))
8226 force = argv[idx_force]->arg;
8227
8228 return peer_maximum_prefix_set_vty(
8229 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8230 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8231 }
8232
8233 ALIAS_HIDDEN(
8234 neighbor_maximum_prefix_threshold,
8235 neighbor_maximum_prefix_threshold_hidden_cmd,
8236 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8237 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8238 "Maximum number of prefix accept from this peer\n"
8239 "maximum no. of prefix limit\n"
8240 "Threshold value (%) at which to generate a warning msg\n"
8241 "Force checking all received routes not only accepted\n")
8242
8243 DEFUN (neighbor_maximum_prefix_warning,
8244 neighbor_maximum_prefix_warning_cmd,
8245 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8246 NEIGHBOR_STR
8247 NEIGHBOR_ADDR_STR2
8248 "Maximum number of prefix accept from this peer\n"
8249 "maximum no. of prefix limit\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_force = 0;
8256 char *force = NULL;
8257
8258 if (argv_find(argv, argc, "force", &idx_force))
8259 force = argv[idx_force]->arg;
8260
8261 return peer_maximum_prefix_set_vty(
8262 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8263 argv[idx_number]->arg, NULL, 1, NULL, force);
8264 }
8265
8266 ALIAS_HIDDEN(
8267 neighbor_maximum_prefix_warning,
8268 neighbor_maximum_prefix_warning_hidden_cmd,
8269 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8270 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8271 "Maximum number of prefix accept from this peer\n"
8272 "maximum no. of prefix limit\n"
8273 "Only give warning message when limit is exceeded\n"
8274 "Force checking all received routes not only accepted\n")
8275
8276 DEFUN (neighbor_maximum_prefix_threshold_warning,
8277 neighbor_maximum_prefix_threshold_warning_cmd,
8278 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8279 NEIGHBOR_STR
8280 NEIGHBOR_ADDR_STR2
8281 "Maximum number of prefix accept from this peer\n"
8282 "maximum no. of prefix limit\n"
8283 "Threshold value (%) at which to generate a warning msg\n"
8284 "Only give warning message when limit is exceeded\n"
8285 "Force checking all received routes not only accepted\n")
8286 {
8287 int idx_peer = 1;
8288 int idx_number = 3;
8289 int idx_number_2 = 4;
8290 int idx_force = 0;
8291 char *force = NULL;
8292
8293 if (argv_find(argv, argc, "force", &idx_force))
8294 force = argv[idx_force]->arg;
8295
8296 return peer_maximum_prefix_set_vty(
8297 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8298 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8299 }
8300
8301 ALIAS_HIDDEN(
8302 neighbor_maximum_prefix_threshold_warning,
8303 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8304 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8305 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8306 "Maximum number of prefix accept from this peer\n"
8307 "maximum no. of prefix limit\n"
8308 "Threshold value (%) at which to generate a warning msg\n"
8309 "Only give warning message when limit is exceeded\n"
8310 "Force checking all received routes not only accepted\n")
8311
8312 DEFUN (neighbor_maximum_prefix_restart,
8313 neighbor_maximum_prefix_restart_cmd,
8314 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8315 NEIGHBOR_STR
8316 NEIGHBOR_ADDR_STR2
8317 "Maximum number of prefix accept from this peer\n"
8318 "maximum no. of prefix limit\n"
8319 "Restart bgp connection after limit is exceeded\n"
8320 "Restart interval in minutes\n"
8321 "Force checking all received routes not only accepted\n")
8322 {
8323 int idx_peer = 1;
8324 int idx_number = 3;
8325 int idx_number_2 = 5;
8326 int idx_force = 0;
8327 char *force = NULL;
8328
8329 if (argv_find(argv, argc, "force", &idx_force))
8330 force = argv[idx_force]->arg;
8331
8332 return peer_maximum_prefix_set_vty(
8333 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8334 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8335 }
8336
8337 ALIAS_HIDDEN(
8338 neighbor_maximum_prefix_restart,
8339 neighbor_maximum_prefix_restart_hidden_cmd,
8340 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8341 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8342 "Maximum number of prefix accept from this peer\n"
8343 "maximum no. of prefix limit\n"
8344 "Restart bgp connection after limit is exceeded\n"
8345 "Restart interval in minutes\n"
8346 "Force checking all received routes not only accepted\n")
8347
8348 DEFUN (neighbor_maximum_prefix_threshold_restart,
8349 neighbor_maximum_prefix_threshold_restart_cmd,
8350 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8351 NEIGHBOR_STR
8352 NEIGHBOR_ADDR_STR2
8353 "Maximum number of prefixes to accept from this peer\n"
8354 "maximum no. of prefix limit\n"
8355 "Threshold value (%) at which to generate a warning msg\n"
8356 "Restart bgp connection after limit is exceeded\n"
8357 "Restart interval in minutes\n"
8358 "Force checking all received routes not only accepted\n")
8359 {
8360 int idx_peer = 1;
8361 int idx_number = 3;
8362 int idx_number_2 = 4;
8363 int idx_number_3 = 6;
8364 int idx_force = 0;
8365 char *force = NULL;
8366
8367 if (argv_find(argv, argc, "force", &idx_force))
8368 force = argv[idx_force]->arg;
8369
8370 return peer_maximum_prefix_set_vty(
8371 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8372 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8373 argv[idx_number_3]->arg, force);
8374 }
8375
8376 ALIAS_HIDDEN(
8377 neighbor_maximum_prefix_threshold_restart,
8378 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8379 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8380 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8381 "Maximum number of prefixes to accept from this peer\n"
8382 "maximum no. of prefix limit\n"
8383 "Threshold value (%) at which to generate a warning msg\n"
8384 "Restart bgp connection after limit is exceeded\n"
8385 "Restart interval in minutes\n"
8386 "Force checking all received routes not only accepted\n")
8387
8388 DEFUN (no_neighbor_maximum_prefix,
8389 no_neighbor_maximum_prefix_cmd,
8390 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8391 NO_STR
8392 NEIGHBOR_STR
8393 NEIGHBOR_ADDR_STR2
8394 "Maximum number of prefixes to accept from this peer\n"
8395 "maximum no. of prefix limit\n"
8396 "Threshold value (%) at which to generate a warning msg\n"
8397 "Restart bgp connection after limit is exceeded\n"
8398 "Restart interval in minutes\n"
8399 "Only give warning message when limit is exceeded\n"
8400 "Force checking all received routes not only accepted\n")
8401 {
8402 int idx_peer = 2;
8403 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8404 bgp_node_afi(vty),
8405 bgp_node_safi(vty));
8406 }
8407
8408 ALIAS_HIDDEN(
8409 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8410 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8411 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8412 "Maximum number of prefixes to accept from this peer\n"
8413 "maximum no. of prefix limit\n"
8414 "Threshold value (%) at which to generate a warning msg\n"
8415 "Restart bgp connection after limit is exceeded\n"
8416 "Restart interval in minutes\n"
8417 "Only give warning message when limit is exceeded\n"
8418 "Force checking all received routes not only accepted\n")
8419
8420 /* "neighbor accept-own" */
8421 DEFPY (neighbor_accept_own,
8422 neighbor_accept_own_cmd,
8423 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8424 NO_STR
8425 NEIGHBOR_STR
8426 NEIGHBOR_ADDR_STR2
8427 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8428 {
8429 struct peer *peer;
8430 afi_t afi = bgp_node_afi(vty);
8431 safi_t safi = bgp_node_safi(vty);
8432 int ret;
8433
8434 peer = peer_and_group_lookup_vty(vty, neighbor);
8435 if (!peer)
8436 return CMD_WARNING_CONFIG_FAILED;
8437
8438 if (no)
8439 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8440 else
8441 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8442
8443 return bgp_vty_return(vty, ret);
8444 }
8445
8446 /* "neighbor soo" */
8447 DEFPY (neighbor_soo,
8448 neighbor_soo_cmd,
8449 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8450 NEIGHBOR_STR
8451 NEIGHBOR_ADDR_STR2
8452 "Set the Site-of-Origin (SoO) extended community\n"
8453 "VPN extended community\n")
8454 {
8455 struct peer *peer;
8456 afi_t afi = bgp_node_afi(vty);
8457 safi_t safi = bgp_node_safi(vty);
8458 struct ecommunity *ecomm_soo;
8459
8460 peer = peer_and_group_lookup_vty(vty, neighbor);
8461 if (!peer)
8462 return CMD_WARNING_CONFIG_FAILED;
8463
8464 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8465 if (!ecomm_soo) {
8466 vty_out(vty, "%% Malformed SoO extended community\n");
8467 return CMD_WARNING;
8468 }
8469 ecommunity_str(ecomm_soo);
8470
8471 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8472 ecommunity_free(&peer->soo[afi][safi]);
8473 peer->soo[afi][safi] = ecomm_soo;
8474 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8475 }
8476
8477 return bgp_vty_return(vty,
8478 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8479 }
8480
8481 DEFPY (no_neighbor_soo,
8482 no_neighbor_soo_cmd,
8483 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8484 NO_STR
8485 NEIGHBOR_STR
8486 NEIGHBOR_ADDR_STR2
8487 "Set the Site-of-Origin (SoO) extended community\n"
8488 "VPN extended community\n")
8489 {
8490 struct peer *peer;
8491 afi_t afi = bgp_node_afi(vty);
8492 safi_t safi = bgp_node_safi(vty);
8493
8494 peer = peer_and_group_lookup_vty(vty, neighbor);
8495 if (!peer)
8496 return CMD_WARNING_CONFIG_FAILED;
8497
8498 ecommunity_free(&peer->soo[afi][safi]);
8499
8500 return bgp_vty_return(
8501 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8502 }
8503
8504 /* "neighbor allowas-in" */
8505 DEFUN (neighbor_allowas_in,
8506 neighbor_allowas_in_cmd,
8507 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8508 NEIGHBOR_STR
8509 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 int idx_peer = 1;
8515 int idx_number_origin = 3;
8516 int ret;
8517 int origin = 0;
8518 struct peer *peer;
8519 int allow_num = 0;
8520
8521 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8522 if (!peer)
8523 return CMD_WARNING_CONFIG_FAILED;
8524
8525 if (argc <= idx_number_origin)
8526 allow_num = 3;
8527 else {
8528 if (argv[idx_number_origin]->type == WORD_TKN)
8529 origin = 1;
8530 else
8531 allow_num = atoi(argv[idx_number_origin]->arg);
8532 }
8533
8534 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8535 allow_num, origin);
8536
8537 return bgp_vty_return(vty, ret);
8538 }
8539
8540 ALIAS_HIDDEN(
8541 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8542 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8543 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8544 "Accept as-path with my AS present in it\n"
8545 "Number of occurrences of AS number\n"
8546 "Only accept my AS in the as-path if the route was originated in my AS\n")
8547
8548 DEFUN (no_neighbor_allowas_in,
8549 no_neighbor_allowas_in_cmd,
8550 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8551 NO_STR
8552 NEIGHBOR_STR
8553 NEIGHBOR_ADDR_STR2
8554 "allow local ASN appears in aspath attribute\n"
8555 "Number of occurrences of AS number\n"
8556 "Only accept my AS in the as-path if the route was originated in my AS\n")
8557 {
8558 int idx_peer = 2;
8559 int ret;
8560 struct peer *peer;
8561
8562 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8563 if (!peer)
8564 return CMD_WARNING_CONFIG_FAILED;
8565
8566 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8567 bgp_node_safi(vty));
8568
8569 return bgp_vty_return(vty, ret);
8570 }
8571
8572 ALIAS_HIDDEN(
8573 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8574 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8575 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8576 "allow local ASN appears in aspath attribute\n"
8577 "Number of occurrences of AS number\n"
8578 "Only accept my AS in the as-path if the route was originated in my AS\n")
8579
8580 DEFUN (neighbor_ttl_security,
8581 neighbor_ttl_security_cmd,
8582 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8583 NEIGHBOR_STR
8584 NEIGHBOR_ADDR_STR2
8585 "BGP ttl-security parameters\n"
8586 "Specify the maximum number of hops to the BGP peer\n"
8587 "Number of hops to BGP peer\n")
8588 {
8589 int idx_peer = 1;
8590 int idx_number = 4;
8591 struct peer *peer;
8592 int gtsm_hops;
8593
8594 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8595 if (!peer)
8596 return CMD_WARNING_CONFIG_FAILED;
8597
8598 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8599
8600 /*
8601 * If 'neighbor swpX', then this is for directly connected peers,
8602 * we should not accept a ttl-security hops value greater than 1.
8603 */
8604 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8605 vty_out(vty,
8606 "%s is directly connected peer, hops cannot exceed 1\n",
8607 argv[idx_peer]->arg);
8608 return CMD_WARNING_CONFIG_FAILED;
8609 }
8610
8611 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8612 }
8613
8614 DEFUN (no_neighbor_ttl_security,
8615 no_neighbor_ttl_security_cmd,
8616 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8617 NO_STR
8618 NEIGHBOR_STR
8619 NEIGHBOR_ADDR_STR2
8620 "BGP ttl-security parameters\n"
8621 "Specify the maximum number of hops to the BGP peer\n"
8622 "Number of hops to BGP peer\n")
8623 {
8624 int idx_peer = 2;
8625 struct peer *peer;
8626
8627 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8628 if (!peer)
8629 return CMD_WARNING_CONFIG_FAILED;
8630
8631 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8632 }
8633
8634 /* disable-addpath-rx */
8635 DEFUN(neighbor_disable_addpath_rx,
8636 neighbor_disable_addpath_rx_cmd,
8637 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8638 NEIGHBOR_STR
8639 NEIGHBOR_ADDR_STR2
8640 "Do not accept additional paths\n")
8641 {
8642 char *peer_str = argv[1]->arg;
8643 struct peer *peer;
8644 afi_t afi = bgp_node_afi(vty);
8645 safi_t safi = bgp_node_safi(vty);
8646
8647 peer = peer_and_group_lookup_vty(vty, peer_str);
8648 if (!peer)
8649 return CMD_WARNING_CONFIG_FAILED;
8650
8651 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8652 PEER_FLAG_DISABLE_ADDPATH_RX);
8653 }
8654
8655 DEFUN(no_neighbor_disable_addpath_rx,
8656 no_neighbor_disable_addpath_rx_cmd,
8657 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8658 NO_STR
8659 NEIGHBOR_STR
8660 NEIGHBOR_ADDR_STR2
8661 "Do not accept additional paths\n")
8662 {
8663 char *peer_str = argv[2]->arg;
8664 struct peer *peer;
8665 afi_t afi = bgp_node_afi(vty);
8666 safi_t safi = bgp_node_safi(vty);
8667
8668 peer = peer_and_group_lookup_vty(vty, peer_str);
8669 if (!peer)
8670 return CMD_WARNING_CONFIG_FAILED;
8671
8672 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8673 PEER_FLAG_DISABLE_ADDPATH_RX);
8674 }
8675
8676 DEFUN (neighbor_addpath_tx_all_paths,
8677 neighbor_addpath_tx_all_paths_cmd,
8678 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8679 NEIGHBOR_STR
8680 NEIGHBOR_ADDR_STR2
8681 "Use addpath to advertise all paths to a neighbor\n")
8682 {
8683 int idx_peer = 1;
8684 struct peer *peer;
8685
8686 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8687 if (!peer)
8688 return CMD_WARNING_CONFIG_FAILED;
8689
8690 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8691 BGP_ADDPATH_ALL);
8692 return CMD_SUCCESS;
8693 }
8694
8695 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8696 neighbor_addpath_tx_all_paths_hidden_cmd,
8697 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8698 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8699 "Use addpath to advertise all paths to a neighbor\n")
8700
8701 DEFUN (no_neighbor_addpath_tx_all_paths,
8702 no_neighbor_addpath_tx_all_paths_cmd,
8703 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8704 NO_STR
8705 NEIGHBOR_STR
8706 NEIGHBOR_ADDR_STR2
8707 "Use addpath to advertise all paths to a neighbor\n")
8708 {
8709 int idx_peer = 2;
8710 struct peer *peer;
8711
8712 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8713 if (!peer)
8714 return CMD_WARNING_CONFIG_FAILED;
8715
8716 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8717 != BGP_ADDPATH_ALL) {
8718 vty_out(vty,
8719 "%% Peer not currently configured to transmit all paths.");
8720 return CMD_WARNING_CONFIG_FAILED;
8721 }
8722
8723 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8724 BGP_ADDPATH_NONE);
8725
8726 return CMD_SUCCESS;
8727 }
8728
8729 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8730 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8731 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8732 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8733 "Use addpath to advertise all paths to a neighbor\n")
8734
8735 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8736 neighbor_addpath_tx_bestpath_per_as_cmd,
8737 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8738 NEIGHBOR_STR
8739 NEIGHBOR_ADDR_STR2
8740 "Use addpath to advertise the bestpath per each neighboring AS\n")
8741 {
8742 int idx_peer = 1;
8743 struct peer *peer;
8744
8745 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8746 if (!peer)
8747 return CMD_WARNING_CONFIG_FAILED;
8748
8749 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8750 BGP_ADDPATH_BEST_PER_AS);
8751
8752 return CMD_SUCCESS;
8753 }
8754
8755 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8756 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8757 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8758 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8759 "Use addpath to advertise the bestpath per each neighboring AS\n")
8760
8761 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8762 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8763 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8764 NO_STR
8765 NEIGHBOR_STR
8766 NEIGHBOR_ADDR_STR2
8767 "Use addpath to advertise the bestpath per each neighboring AS\n")
8768 {
8769 int idx_peer = 2;
8770 struct peer *peer;
8771
8772 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8773 if (!peer)
8774 return CMD_WARNING_CONFIG_FAILED;
8775
8776 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8777 != BGP_ADDPATH_BEST_PER_AS) {
8778 vty_out(vty,
8779 "%% Peer not currently configured to transmit all best path per as.");
8780 return CMD_WARNING_CONFIG_FAILED;
8781 }
8782
8783 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8784 BGP_ADDPATH_NONE);
8785
8786 return CMD_SUCCESS;
8787 }
8788
8789 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8790 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8791 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8792 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8793 "Use addpath to advertise the bestpath per each neighboring AS\n")
8794
8795 DEFPY(
8796 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8797 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8798 NEIGHBOR_STR
8799 NEIGHBOR_ADDR_STR2
8800 "Detect AS loops before sending to neighbor\n")
8801 {
8802 struct peer *peer;
8803
8804 peer = peer_and_group_lookup_vty(vty, neighbor);
8805 if (!peer)
8806 return CMD_WARNING_CONFIG_FAILED;
8807
8808 peer->as_path_loop_detection = true;
8809
8810 return CMD_SUCCESS;
8811 }
8812
8813 DEFPY(
8814 no_neighbor_aspath_loop_detection,
8815 no_neighbor_aspath_loop_detection_cmd,
8816 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8817 NO_STR
8818 NEIGHBOR_STR
8819 NEIGHBOR_ADDR_STR2
8820 "Detect AS loops before sending to neighbor\n")
8821 {
8822 struct peer *peer;
8823
8824 peer = peer_and_group_lookup_vty(vty, neighbor);
8825 if (!peer)
8826 return CMD_WARNING_CONFIG_FAILED;
8827
8828 peer->as_path_loop_detection = false;
8829
8830 return CMD_SUCCESS;
8831 }
8832
8833 DEFPY(neighbor_path_attribute_discard,
8834 neighbor_path_attribute_discard_cmd,
8835 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8836 NEIGHBOR_STR
8837 NEIGHBOR_ADDR_STR2
8838 "Manipulate path attributes from incoming UPDATE messages\n"
8839 "Drop specified attributes from incoming UPDATE messages\n"
8840 "Attribute number\n")
8841 {
8842 struct peer *peer;
8843 int idx = 0;
8844 const char *discard_attrs = NULL;
8845
8846 peer = peer_and_group_lookup_vty(vty, neighbor);
8847 if (!peer)
8848 return CMD_WARNING_CONFIG_FAILED;
8849
8850 argv_find(argv, argc, "(1-255)", &idx);
8851 if (idx)
8852 discard_attrs = argv_concat(argv, argc, idx);
8853
8854 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8855
8856 return CMD_SUCCESS;
8857 }
8858
8859 DEFPY(no_neighbor_path_attribute_discard,
8860 no_neighbor_path_attribute_discard_cmd,
8861 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8862 NO_STR
8863 NEIGHBOR_STR
8864 NEIGHBOR_ADDR_STR2
8865 "Manipulate path attributes from incoming UPDATE messages\n"
8866 "Drop specified attributes from incoming UPDATE messages\n"
8867 "Attribute number\n")
8868 {
8869 struct peer *peer;
8870 int idx = 0;
8871 const char *discard_attrs = NULL;
8872
8873 peer = peer_and_group_lookup_vty(vty, neighbor);
8874 if (!peer)
8875 return CMD_WARNING_CONFIG_FAILED;
8876
8877 argv_find(argv, argc, "(1-255)", &idx);
8878 if (idx)
8879 discard_attrs = argv[idx]->arg;
8880
8881 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
8882
8883 return CMD_SUCCESS;
8884 }
8885
8886 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8887 struct ecommunity **list, bool is_rt6)
8888 {
8889 struct ecommunity *ecom = NULL;
8890 struct ecommunity *ecomadd;
8891
8892 for (; argc; --argc, ++argv) {
8893 if (is_rt6)
8894 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8895 ECOMMUNITY_ROUTE_TARGET,
8896 0);
8897 else
8898 ecomadd = ecommunity_str2com(argv[0]->arg,
8899 ECOMMUNITY_ROUTE_TARGET,
8900 0);
8901 if (!ecomadd) {
8902 vty_out(vty, "Malformed community-list value\n");
8903 if (ecom)
8904 ecommunity_free(&ecom);
8905 return CMD_WARNING_CONFIG_FAILED;
8906 }
8907
8908 if (ecom) {
8909 ecommunity_merge(ecom, ecomadd);
8910 ecommunity_free(&ecomadd);
8911 } else {
8912 ecom = ecomadd;
8913 }
8914 }
8915
8916 if (*list) {
8917 ecommunity_free(&*list);
8918 }
8919 *list = ecom;
8920
8921 return CMD_SUCCESS;
8922 }
8923
8924 /*
8925 * v2vimport is true if we are handling a `import vrf ...` command
8926 */
8927 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8928 {
8929 afi_t afi;
8930
8931 switch (vty->node) {
8932 case BGP_IPV4_NODE:
8933 afi = AFI_IP;
8934 break;
8935 case BGP_IPV6_NODE:
8936 afi = AFI_IP6;
8937 break;
8938 default:
8939 vty_out(vty,
8940 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8941 return AFI_MAX;
8942 }
8943
8944 if (!v2vimport) {
8945 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8946 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8947 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8948 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8949 vty_out(vty,
8950 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8951 return AFI_MAX;
8952 }
8953 } else {
8954 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8955 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8956 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8957 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8958 vty_out(vty,
8959 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8960 return AFI_MAX;
8961 }
8962 }
8963 return afi;
8964 }
8965
8966 DEFPY (af_rd_vpn_export,
8967 af_rd_vpn_export_cmd,
8968 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8969 NO_STR
8970 "Specify route distinguisher\n"
8971 "Between current address-family and vpn\n"
8972 "For routes leaked from current address-family to vpn\n"
8973 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8974 {
8975 VTY_DECLVAR_CONTEXT(bgp, bgp);
8976 struct prefix_rd prd;
8977 int ret;
8978 afi_t afi;
8979 int idx = 0;
8980 bool yes = true;
8981
8982 if (argv_find(argv, argc, "no", &idx))
8983 yes = false;
8984
8985 if (yes) {
8986 ret = str2prefix_rd(rd_str, &prd);
8987 if (!ret) {
8988 vty_out(vty, "%% Malformed rd\n");
8989 return CMD_WARNING_CONFIG_FAILED;
8990 }
8991 }
8992
8993 afi = vpn_policy_getafi(vty, bgp, false);
8994 if (afi == AFI_MAX)
8995 return CMD_WARNING_CONFIG_FAILED;
8996
8997 /*
8998 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8999 */
9000 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9001 bgp_get_default(), bgp);
9002
9003 if (yes) {
9004 bgp->vpn_policy[afi].tovpn_rd = prd;
9005 SET_FLAG(bgp->vpn_policy[afi].flags,
9006 BGP_VPN_POLICY_TOVPN_RD_SET);
9007 } else {
9008 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9009 BGP_VPN_POLICY_TOVPN_RD_SET);
9010 }
9011
9012 /* post-change: re-export vpn routes */
9013 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9014 bgp_get_default(), bgp);
9015
9016 return CMD_SUCCESS;
9017 }
9018
9019 ALIAS (af_rd_vpn_export,
9020 af_no_rd_vpn_export_cmd,
9021 "no rd vpn export",
9022 NO_STR
9023 "Specify route distinguisher\n"
9024 "Between current address-family and vpn\n"
9025 "For routes leaked from current address-family to vpn\n")
9026
9027 DEFPY (af_label_vpn_export,
9028 af_label_vpn_export_cmd,
9029 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9030 NO_STR
9031 "label value for VRF\n"
9032 "Between current address-family and vpn\n"
9033 "For routes leaked from current address-family to vpn\n"
9034 "Label Value <0-1048575>\n"
9035 "Automatically assign a label\n")
9036 {
9037 VTY_DECLVAR_CONTEXT(bgp, bgp);
9038 mpls_label_t label = MPLS_LABEL_NONE;
9039 afi_t afi;
9040 int idx = 0;
9041 bool yes = true;
9042
9043 if (argv_find(argv, argc, "no", &idx))
9044 yes = false;
9045
9046 /* If "no ...", squash trailing parameter */
9047 if (!yes)
9048 label_auto = NULL;
9049
9050 if (yes) {
9051 if (!label_auto)
9052 label = label_val; /* parser should force unsigned */
9053 }
9054
9055 afi = vpn_policy_getafi(vty, bgp, false);
9056 if (afi == AFI_MAX)
9057 return CMD_WARNING_CONFIG_FAILED;
9058
9059
9060 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9061 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9062 /* no change */
9063 return CMD_SUCCESS;
9064
9065 /*
9066 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9067 */
9068 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9069 bgp_get_default(), bgp);
9070
9071 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9072 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9073
9074 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9075
9076 /*
9077 * label has previously been automatically
9078 * assigned by labelpool: release it
9079 *
9080 * NB if tovpn_label == MPLS_LABEL_NONE it
9081 * means the automatic assignment is in flight
9082 * and therefore the labelpool callback must
9083 * detect that the auto label is not needed.
9084 */
9085
9086 bgp_lp_release(LP_TYPE_VRF,
9087 &bgp->vpn_policy[afi],
9088 bgp->vpn_policy[afi].tovpn_label);
9089 }
9090 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9091 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9092 }
9093
9094 bgp->vpn_policy[afi].tovpn_label = label;
9095 if (label_auto) {
9096 SET_FLAG(bgp->vpn_policy[afi].flags,
9097 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9098 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9099 vpn_leak_label_callback);
9100 }
9101
9102 /* post-change: re-export vpn routes */
9103 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9104 bgp_get_default(), bgp);
9105
9106 hook_call(bgp_snmp_update_last_changed, bgp);
9107 return CMD_SUCCESS;
9108 }
9109
9110 DEFPY (af_sid_vpn_export,
9111 af_sid_vpn_export_cmd,
9112 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9113 NO_STR
9114 "sid value for VRF\n"
9115 "Between current address-family and vpn\n"
9116 "For routes leaked from current address-family to vpn\n"
9117 "Sid allocation index\n"
9118 "Automatically assign a label\n")
9119 {
9120 VTY_DECLVAR_CONTEXT(bgp, bgp);
9121 afi_t afi;
9122 int debug = 0;
9123 int idx = 0;
9124 bool yes = true;
9125
9126 if (argv_find(argv, argc, "no", &idx))
9127 yes = false;
9128 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9129 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9130
9131 afi = vpn_policy_getafi(vty, bgp, false);
9132 if (afi == AFI_MAX)
9133 return CMD_WARNING_CONFIG_FAILED;
9134
9135 if (!yes) {
9136 /* implement me */
9137 vty_out(vty, "It's not implemented\n");
9138 return CMD_WARNING_CONFIG_FAILED;
9139 }
9140
9141 if (bgp->tovpn_sid_index != 0 ||
9142 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9143 vty_out(vty,
9144 "per-vrf sid and per-af sid are mutually exclusive\n"
9145 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9146 return CMD_WARNING_CONFIG_FAILED;
9147 }
9148
9149 /* skip when it's already configured */
9150 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9151 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9152 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9153 return CMD_SUCCESS;
9154
9155 /*
9156 * mode change between sid_idx and sid_auto isn't supported.
9157 * user must negate sid vpn export when they want to change the mode
9158 */
9159 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9160 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9161 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9162 vty_out(vty, "it's already configured as %s.\n",
9163 sid_auto ? "auto-mode" : "idx-mode");
9164 return CMD_WARNING_CONFIG_FAILED;
9165 }
9166
9167 /* pre-change */
9168 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9169 bgp_get_default(), bgp);
9170
9171 if (sid_auto) {
9172 /* SID allocation auto-mode */
9173 if (debug)
9174 zlog_debug("%s: auto sid alloc.", __func__);
9175 SET_FLAG(bgp->vpn_policy[afi].flags,
9176 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9177 } else {
9178 /* SID allocation index-mode */
9179 if (debug)
9180 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9181 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9182 }
9183
9184 /* post-change */
9185 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9186 bgp_get_default(), bgp);
9187 return CMD_SUCCESS;
9188 }
9189
9190 DEFPY (bgp_sid_vpn_export,
9191 bgp_sid_vpn_export_cmd,
9192 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9193 NO_STR
9194 "sid value for VRF\n"
9195 "Between current vrf and vpn\n"
9196 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9197 "For routes leaked from current vrf to vpn\n"
9198 "Sid allocation index\n"
9199 "Automatically assign a label\n")
9200 {
9201 VTY_DECLVAR_CONTEXT(bgp, bgp);
9202 int debug;
9203
9204 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9205 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9206
9207 if (no) {
9208 /* when per-VRF SID is not set, do nothing */
9209 if (bgp->tovpn_sid_index == 0 &&
9210 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9211 return CMD_SUCCESS;
9212
9213 sid_idx = 0;
9214 sid_auto = false;
9215 bgp->tovpn_sid_index = 0;
9216 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9217 }
9218
9219 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9220 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9221 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9222 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9223 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9224 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9225 vty_out(vty,
9226 "per-vrf sid and per-af sid are mutually exclusive\n"
9227 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9228 return CMD_WARNING_CONFIG_FAILED;
9229 }
9230
9231 /* skip when it's already configured */
9232 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9233 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9234 return CMD_SUCCESS;
9235
9236 /*
9237 * mode change between sid_idx and sid_auto isn't supported.
9238 * user must negate sid vpn export when they want to change the mode
9239 */
9240 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9241 (sid_idx != 0 &&
9242 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9243 vty_out(vty, "it's already configured as %s.\n",
9244 sid_auto ? "auto-mode" : "idx-mode");
9245 return CMD_WARNING_CONFIG_FAILED;
9246 }
9247
9248 /* pre-change */
9249 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9250 bgp);
9251 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9252 bgp);
9253
9254 if (sid_auto) {
9255 /* SID allocation auto-mode */
9256 if (debug)
9257 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9258 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9259 } else if (sid_idx != 0) {
9260 /* SID allocation index-mode */
9261 if (debug)
9262 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9263 sid_idx);
9264 bgp->tovpn_sid_index = sid_idx;
9265 }
9266
9267 /* post-change */
9268 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9269 bgp);
9270 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9271 bgp_get_default(), bgp);
9272
9273 return CMD_SUCCESS;
9274 }
9275
9276 ALIAS (af_label_vpn_export,
9277 af_no_label_vpn_export_cmd,
9278 "no label vpn export",
9279 NO_STR
9280 "label value for VRF\n"
9281 "Between current address-family and vpn\n"
9282 "For routes leaked from current address-family to vpn\n")
9283
9284 ALIAS (bgp_sid_vpn_export,
9285 no_bgp_sid_vpn_export_cmd,
9286 "no$no sid vpn per-vrf export",
9287 NO_STR
9288 "sid value for VRF\n"
9289 "Between current vrf and vpn\n"
9290 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9291 "For routes leaked from current vrf to vpn\n")
9292
9293 DEFPY (af_nexthop_vpn_export,
9294 af_nexthop_vpn_export_cmd,
9295 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9296 NO_STR
9297 "Specify next hop to use for VRF advertised prefixes\n"
9298 "Between current address-family and vpn\n"
9299 "For routes leaked from current address-family to vpn\n"
9300 "IPv4 prefix\n"
9301 "IPv6 prefix\n")
9302 {
9303 VTY_DECLVAR_CONTEXT(bgp, bgp);
9304 afi_t afi;
9305 struct prefix p;
9306
9307 if (!no) {
9308 if (!nexthop_su) {
9309 vty_out(vty, "%% Nexthop required\n");
9310 return CMD_WARNING_CONFIG_FAILED;
9311 }
9312 if (!sockunion2hostprefix(nexthop_su, &p))
9313 return CMD_WARNING_CONFIG_FAILED;
9314 }
9315
9316 afi = vpn_policy_getafi(vty, bgp, false);
9317 if (afi == AFI_MAX)
9318 return CMD_WARNING_CONFIG_FAILED;
9319
9320 /*
9321 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9322 */
9323 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9324 bgp_get_default(), bgp);
9325
9326 if (!no) {
9327 bgp->vpn_policy[afi].tovpn_nexthop = p;
9328 SET_FLAG(bgp->vpn_policy[afi].flags,
9329 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9330 } else {
9331 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9332 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9333 }
9334
9335 /* post-change: re-export vpn routes */
9336 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9337 bgp_get_default(), bgp);
9338
9339 return CMD_SUCCESS;
9340 }
9341
9342 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9343 {
9344 if (!strcmp(dstr, "import")) {
9345 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9346 } else if (!strcmp(dstr, "export")) {
9347 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9348 } else if (!strcmp(dstr, "both")) {
9349 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9350 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9351 } else {
9352 vty_out(vty, "%% direction parse error\n");
9353 return CMD_WARNING_CONFIG_FAILED;
9354 }
9355 return CMD_SUCCESS;
9356 }
9357
9358 DEFPY (af_rt_vpn_imexport,
9359 af_rt_vpn_imexport_cmd,
9360 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9361 NO_STR
9362 "Specify route target list\n"
9363 "Specify route target list\n"
9364 "Between current address-family and vpn\n"
9365 "For routes leaked from vpn to current address-family: match any\n"
9366 "For routes leaked from current address-family to vpn: set\n"
9367 "both import: match any and export: set\n"
9368 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9369 {
9370 VTY_DECLVAR_CONTEXT(bgp, bgp);
9371 int ret;
9372 struct ecommunity *ecom = NULL;
9373 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9374 enum vpn_policy_direction dir;
9375 afi_t afi;
9376 int idx = 0;
9377 bool yes = true;
9378
9379 if (argv_find(argv, argc, "no", &idx))
9380 yes = false;
9381
9382 afi = vpn_policy_getafi(vty, bgp, false);
9383 if (afi == AFI_MAX)
9384 return CMD_WARNING_CONFIG_FAILED;
9385
9386 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9387 if (ret != CMD_SUCCESS)
9388 return ret;
9389
9390 if (yes) {
9391 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9392 vty_out(vty, "%% Missing RTLIST\n");
9393 return CMD_WARNING_CONFIG_FAILED;
9394 }
9395 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9396 if (ret != CMD_SUCCESS) {
9397 return ret;
9398 }
9399 }
9400
9401 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9402 if (!dodir[dir])
9403 continue;
9404
9405 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9406
9407 if (yes) {
9408 if (bgp->vpn_policy[afi].rtlist[dir])
9409 ecommunity_free(
9410 &bgp->vpn_policy[afi].rtlist[dir]);
9411 bgp->vpn_policy[afi].rtlist[dir] =
9412 ecommunity_dup(ecom);
9413 } else {
9414 if (bgp->vpn_policy[afi].rtlist[dir])
9415 ecommunity_free(
9416 &bgp->vpn_policy[afi].rtlist[dir]);
9417 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9418 }
9419
9420 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9421 }
9422
9423 if (ecom)
9424 ecommunity_free(&ecom);
9425
9426 return CMD_SUCCESS;
9427 }
9428
9429 ALIAS (af_rt_vpn_imexport,
9430 af_no_rt_vpn_imexport_cmd,
9431 "no <rt|route-target> vpn <import|export|both>$direction_str",
9432 NO_STR
9433 "Specify route target list\n"
9434 "Specify route target list\n"
9435 "Between current address-family and vpn\n"
9436 "For routes leaked from vpn to current address-family\n"
9437 "For routes leaked from current address-family to vpn\n"
9438 "both import and export\n")
9439
9440 DEFPY (af_route_map_vpn_imexport,
9441 af_route_map_vpn_imexport_cmd,
9442 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9443 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9444 NO_STR
9445 "Specify route map\n"
9446 "Between current address-family and vpn\n"
9447 "For routes leaked from vpn to current address-family\n"
9448 "For routes leaked from current address-family to vpn\n"
9449 "name of route-map\n")
9450 {
9451 VTY_DECLVAR_CONTEXT(bgp, bgp);
9452 int ret;
9453 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9454 enum vpn_policy_direction dir;
9455 afi_t afi;
9456 int idx = 0;
9457 bool yes = true;
9458
9459 if (argv_find(argv, argc, "no", &idx))
9460 yes = false;
9461
9462 afi = vpn_policy_getafi(vty, bgp, false);
9463 if (afi == AFI_MAX)
9464 return CMD_WARNING_CONFIG_FAILED;
9465
9466 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9467 if (ret != CMD_SUCCESS)
9468 return ret;
9469
9470 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9471 if (!dodir[dir])
9472 continue;
9473
9474 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9475
9476 if (yes) {
9477 if (bgp->vpn_policy[afi].rmap_name[dir])
9478 XFREE(MTYPE_ROUTE_MAP_NAME,
9479 bgp->vpn_policy[afi].rmap_name[dir]);
9480 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9481 MTYPE_ROUTE_MAP_NAME, rmap_str);
9482 bgp->vpn_policy[afi].rmap[dir] =
9483 route_map_lookup_warn_noexist(vty, rmap_str);
9484 if (!bgp->vpn_policy[afi].rmap[dir])
9485 return CMD_SUCCESS;
9486 } else {
9487 if (bgp->vpn_policy[afi].rmap_name[dir])
9488 XFREE(MTYPE_ROUTE_MAP_NAME,
9489 bgp->vpn_policy[afi].rmap_name[dir]);
9490 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9491 bgp->vpn_policy[afi].rmap[dir] = NULL;
9492 }
9493
9494 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9495 }
9496
9497 return CMD_SUCCESS;
9498 }
9499
9500 ALIAS (af_route_map_vpn_imexport,
9501 af_no_route_map_vpn_imexport_cmd,
9502 "no route-map vpn <import|export>$direction_str",
9503 NO_STR
9504 "Specify route map\n"
9505 "Between current address-family and vpn\n"
9506 "For routes leaked from vpn to current address-family\n"
9507 "For routes leaked from current address-family to vpn\n")
9508
9509 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9510 "import vrf route-map RMAP$rmap_str",
9511 "Import routes from another VRF\n"
9512 "Vrf routes being filtered\n"
9513 "Specify route map\n"
9514 "name of route-map\n")
9515 {
9516 VTY_DECLVAR_CONTEXT(bgp, bgp);
9517 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9518 afi_t afi;
9519 struct bgp *bgp_default;
9520
9521 afi = vpn_policy_getafi(vty, bgp, true);
9522 if (afi == AFI_MAX)
9523 return CMD_WARNING_CONFIG_FAILED;
9524
9525 bgp_default = bgp_get_default();
9526 if (!bgp_default) {
9527 int32_t ret;
9528 as_t as = bgp->as;
9529
9530 /* Auto-create assuming the same AS */
9531 ret = bgp_get_vty(&bgp_default, &as, NULL,
9532 BGP_INSTANCE_TYPE_DEFAULT, NULL);
9533
9534 if (ret) {
9535 vty_out(vty,
9536 "VRF default is not configured as a bgp instance\n");
9537 return CMD_WARNING;
9538 }
9539 }
9540
9541 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9542
9543 if (bgp->vpn_policy[afi].rmap_name[dir])
9544 XFREE(MTYPE_ROUTE_MAP_NAME,
9545 bgp->vpn_policy[afi].rmap_name[dir]);
9546 bgp->vpn_policy[afi].rmap_name[dir] =
9547 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9548 bgp->vpn_policy[afi].rmap[dir] =
9549 route_map_lookup_warn_noexist(vty, rmap_str);
9550 if (!bgp->vpn_policy[afi].rmap[dir])
9551 return CMD_SUCCESS;
9552
9553 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9554 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9555
9556 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9557
9558 return CMD_SUCCESS;
9559 }
9560
9561 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9562 "no import vrf route-map [RMAP$rmap_str]",
9563 NO_STR
9564 "Import routes from another VRF\n"
9565 "Vrf routes being filtered\n"
9566 "Specify route map\n"
9567 "name of route-map\n")
9568 {
9569 VTY_DECLVAR_CONTEXT(bgp, bgp);
9570 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9571 afi_t afi;
9572
9573 afi = vpn_policy_getafi(vty, bgp, true);
9574 if (afi == AFI_MAX)
9575 return CMD_WARNING_CONFIG_FAILED;
9576
9577 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9578
9579 if (bgp->vpn_policy[afi].rmap_name[dir])
9580 XFREE(MTYPE_ROUTE_MAP_NAME,
9581 bgp->vpn_policy[afi].rmap_name[dir]);
9582 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9583 bgp->vpn_policy[afi].rmap[dir] = NULL;
9584
9585 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9586 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9587 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9588
9589 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9590
9591 return CMD_SUCCESS;
9592 }
9593
9594 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9595 "[no] import vrf VIEWVRFNAME$import_name",
9596 NO_STR
9597 "Import routes from another VRF\n"
9598 "VRF to import from\n"
9599 "The name of the VRF\n")
9600 {
9601 VTY_DECLVAR_CONTEXT(bgp, bgp);
9602 struct listnode *node;
9603 struct bgp *vrf_bgp, *bgp_default;
9604 int32_t ret = 0;
9605 as_t as = bgp->as;
9606 bool remove = false;
9607 int32_t idx = 0;
9608 char *vname;
9609 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9610 safi_t safi;
9611 afi_t afi;
9612
9613 if (import_name == NULL) {
9614 vty_out(vty, "%% Missing import name\n");
9615 return CMD_WARNING;
9616 }
9617
9618 if (strcmp(import_name, "route-map") == 0) {
9619 vty_out(vty, "%% Must include route-map name\n");
9620 return CMD_WARNING;
9621 }
9622
9623 if (argv_find(argv, argc, "no", &idx))
9624 remove = true;
9625
9626 afi = vpn_policy_getafi(vty, bgp, true);
9627 if (afi == AFI_MAX)
9628 return CMD_WARNING_CONFIG_FAILED;
9629
9630 safi = bgp_node_safi(vty);
9631
9632 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9633 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9634 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9635 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9636 remove ? "unimport" : "import", import_name);
9637 return CMD_WARNING;
9638 }
9639
9640 bgp_default = bgp_get_default();
9641 if (!bgp_default) {
9642 /* Auto-create assuming the same AS */
9643 ret = bgp_get_vty(&bgp_default, &as, NULL,
9644 BGP_INSTANCE_TYPE_DEFAULT, NULL);
9645
9646 if (ret) {
9647 vty_out(vty,
9648 "VRF default is not configured as a bgp instance\n");
9649 return CMD_WARNING;
9650 }
9651 }
9652
9653 vrf_bgp = bgp_lookup_by_name(import_name);
9654 if (!vrf_bgp) {
9655 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9656 vrf_bgp = bgp_default;
9657 else
9658 /* Auto-create assuming the same AS */
9659 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type, NULL);
9660
9661 if (ret) {
9662 vty_out(vty,
9663 "VRF %s is not configured as a bgp instance\n",
9664 import_name);
9665 return CMD_WARNING;
9666 }
9667 }
9668
9669 if (remove) {
9670 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9671 } else {
9672 /* Already importing from "import_vrf"? */
9673 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9674 vname)) {
9675 if (strcmp(vname, import_name) == 0)
9676 return CMD_WARNING;
9677 }
9678
9679 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9680 }
9681
9682 return CMD_SUCCESS;
9683 }
9684
9685 /* This command is valid only in a bgp vrf instance or the default instance */
9686 DEFPY (bgp_imexport_vpn,
9687 bgp_imexport_vpn_cmd,
9688 "[no] <import|export>$direction_str vpn",
9689 NO_STR
9690 "Import routes to this address-family\n"
9691 "Export routes from this address-family\n"
9692 "to/from default instance VPN RIB\n")
9693 {
9694 VTY_DECLVAR_CONTEXT(bgp, bgp);
9695 int previous_state;
9696 afi_t afi;
9697 safi_t safi;
9698 int idx = 0;
9699 bool yes = true;
9700 int flag;
9701 enum vpn_policy_direction dir;
9702
9703 if (argv_find(argv, argc, "no", &idx))
9704 yes = false;
9705
9706 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9707 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9708
9709 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9710 return CMD_WARNING_CONFIG_FAILED;
9711 }
9712
9713 afi = bgp_node_afi(vty);
9714 safi = bgp_node_safi(vty);
9715 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9716 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9717 return CMD_WARNING_CONFIG_FAILED;
9718 }
9719
9720 if (!strcmp(direction_str, "import")) {
9721 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9722 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9723 } else if (!strcmp(direction_str, "export")) {
9724 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9725 dir = BGP_VPN_POLICY_DIR_TOVPN;
9726 } else {
9727 vty_out(vty, "%% unknown direction %s\n", direction_str);
9728 return CMD_WARNING_CONFIG_FAILED;
9729 }
9730
9731 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9732
9733 if (yes) {
9734 SET_FLAG(bgp->af_flags[afi][safi], flag);
9735 if (!previous_state) {
9736 /* trigger export current vrf */
9737 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9738 }
9739 } else {
9740 if (previous_state) {
9741 /* trigger un-export current vrf */
9742 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9743 }
9744 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9745 }
9746
9747 hook_call(bgp_snmp_init_stats, bgp);
9748
9749 return CMD_SUCCESS;
9750 }
9751
9752 DEFPY (af_routetarget_import,
9753 af_routetarget_import_cmd,
9754 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9755 NO_STR
9756 "Specify route target list\n"
9757 "Specify route target list\n"
9758 "Specify route target list\n"
9759 "Specify route target list\n"
9760 "Flow-spec redirect type route target\n"
9761 "Import routes to this address-family\n"
9762 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9763 {
9764 VTY_DECLVAR_CONTEXT(bgp, bgp);
9765 int ret;
9766 struct ecommunity *ecom = NULL;
9767 afi_t afi;
9768 int idx = 0, idx_unused = 0;
9769 bool yes = true;
9770 bool rt6 = false;
9771
9772 if (argv_find(argv, argc, "no", &idx))
9773 yes = false;
9774
9775 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9776 argv_find(argv, argc, "route-target6", &idx_unused))
9777 rt6 = true;
9778
9779 afi = vpn_policy_getafi(vty, bgp, false);
9780 if (afi == AFI_MAX)
9781 return CMD_WARNING_CONFIG_FAILED;
9782
9783 if (rt6 && afi != AFI_IP6)
9784 return CMD_WARNING_CONFIG_FAILED;
9785
9786 if (yes) {
9787 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9788 vty_out(vty, "%% Missing RTLIST\n");
9789 return CMD_WARNING_CONFIG_FAILED;
9790 }
9791 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9792 if (ret != CMD_SUCCESS)
9793 return ret;
9794 }
9795
9796 if (yes) {
9797 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9798 ecommunity_free(&bgp->vpn_policy[afi]
9799 .import_redirect_rtlist);
9800 bgp->vpn_policy[afi].import_redirect_rtlist =
9801 ecommunity_dup(ecom);
9802 } else {
9803 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9804 ecommunity_free(&bgp->vpn_policy[afi]
9805 .import_redirect_rtlist);
9806 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9807 }
9808
9809 if (ecom)
9810 ecommunity_free(&ecom);
9811
9812 return CMD_SUCCESS;
9813 }
9814
9815 DEFUN_NOSH (address_family_ipv4_safi,
9816 address_family_ipv4_safi_cmd,
9817 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9818 "Enter Address Family command mode\n"
9819 BGP_AF_STR
9820 BGP_SAFI_WITH_LABEL_HELP_STR)
9821 {
9822
9823 if (argc == 3) {
9824 VTY_DECLVAR_CONTEXT(bgp, bgp);
9825 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9826 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9827 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9828 && safi != SAFI_EVPN) {
9829 vty_out(vty,
9830 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9831 return CMD_WARNING_CONFIG_FAILED;
9832 }
9833 vty->node = bgp_node_type(AFI_IP, safi);
9834 } else
9835 vty->node = BGP_IPV4_NODE;
9836
9837 return CMD_SUCCESS;
9838 }
9839
9840 DEFUN_NOSH (address_family_ipv6_safi,
9841 address_family_ipv6_safi_cmd,
9842 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9843 "Enter Address Family command mode\n"
9844 BGP_AF_STR
9845 BGP_SAFI_WITH_LABEL_HELP_STR)
9846 {
9847 if (argc == 3) {
9848 VTY_DECLVAR_CONTEXT(bgp, bgp);
9849 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9850 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9851 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9852 && safi != SAFI_EVPN) {
9853 vty_out(vty,
9854 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9855 return CMD_WARNING_CONFIG_FAILED;
9856 }
9857 vty->node = bgp_node_type(AFI_IP6, safi);
9858 } else
9859 vty->node = BGP_IPV6_NODE;
9860
9861 return CMD_SUCCESS;
9862 }
9863
9864 #ifdef KEEP_OLD_VPN_COMMANDS
9865 DEFUN_NOSH (address_family_vpnv4,
9866 address_family_vpnv4_cmd,
9867 "address-family vpnv4 [unicast]",
9868 "Enter Address Family command mode\n"
9869 BGP_AF_STR
9870 BGP_AF_MODIFIER_STR)
9871 {
9872 vty->node = BGP_VPNV4_NODE;
9873 return CMD_SUCCESS;
9874 }
9875
9876 DEFUN_NOSH (address_family_vpnv6,
9877 address_family_vpnv6_cmd,
9878 "address-family vpnv6 [unicast]",
9879 "Enter Address Family command mode\n"
9880 BGP_AF_STR
9881 BGP_AF_MODIFIER_STR)
9882 {
9883 vty->node = BGP_VPNV6_NODE;
9884 return CMD_SUCCESS;
9885 }
9886 #endif /* KEEP_OLD_VPN_COMMANDS */
9887
9888 DEFUN_NOSH (address_family_evpn,
9889 address_family_evpn_cmd,
9890 "address-family l2vpn evpn",
9891 "Enter Address Family command mode\n"
9892 BGP_AF_STR
9893 BGP_AF_MODIFIER_STR)
9894 {
9895 VTY_DECLVAR_CONTEXT(bgp, bgp);
9896 vty->node = BGP_EVPN_NODE;
9897 return CMD_SUCCESS;
9898 }
9899
9900 DEFUN_NOSH (bgp_segment_routing_srv6,
9901 bgp_segment_routing_srv6_cmd,
9902 "segment-routing srv6",
9903 "Segment-Routing configuration\n"
9904 "Segment-Routing SRv6 configuration\n")
9905 {
9906 VTY_DECLVAR_CONTEXT(bgp, bgp);
9907 bgp->srv6_enabled = true;
9908 vty->node = BGP_SRV6_NODE;
9909 return CMD_SUCCESS;
9910 }
9911
9912 DEFUN (no_bgp_segment_routing_srv6,
9913 no_bgp_segment_routing_srv6_cmd,
9914 "no segment-routing srv6",
9915 NO_STR
9916 "Segment-Routing configuration\n"
9917 "Segment-Routing SRv6 configuration\n")
9918 {
9919 VTY_DECLVAR_CONTEXT(bgp, bgp);
9920
9921 if (strlen(bgp->srv6_locator_name) > 0)
9922 if (bgp_srv6_locator_unset(bgp) < 0)
9923 return CMD_WARNING_CONFIG_FAILED;
9924
9925 bgp->srv6_enabled = false;
9926 return CMD_SUCCESS;
9927 }
9928
9929 DEFPY (bgp_srv6_locator,
9930 bgp_srv6_locator_cmd,
9931 "locator NAME$name",
9932 "Specify SRv6 locator\n"
9933 "Specify SRv6 locator\n")
9934 {
9935 VTY_DECLVAR_CONTEXT(bgp, bgp);
9936 int ret;
9937
9938 if (strlen(bgp->srv6_locator_name) > 0
9939 && strcmp(name, bgp->srv6_locator_name) != 0) {
9940 vty_out(vty, "srv6 locator is already configured\n");
9941 return CMD_WARNING_CONFIG_FAILED;
9942 }
9943
9944 snprintf(bgp->srv6_locator_name,
9945 sizeof(bgp->srv6_locator_name), "%s", name);
9946
9947 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9948 if (ret < 0)
9949 return CMD_WARNING_CONFIG_FAILED;
9950
9951 return CMD_SUCCESS;
9952 }
9953
9954 DEFPY (no_bgp_srv6_locator,
9955 no_bgp_srv6_locator_cmd,
9956 "no locator NAME$name",
9957 NO_STR
9958 "Specify SRv6 locator\n"
9959 "Specify SRv6 locator\n")
9960 {
9961 VTY_DECLVAR_CONTEXT(bgp, bgp);
9962
9963 /* when locator isn't configured, do nothing */
9964 if (strlen(bgp->srv6_locator_name) < 1)
9965 return CMD_SUCCESS;
9966
9967 /* name validation */
9968 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9969 vty_out(vty, "%% No srv6 locator is configured\n");
9970 return CMD_WARNING_CONFIG_FAILED;
9971 }
9972
9973 /* unset locator */
9974 if (bgp_srv6_locator_unset(bgp) < 0)
9975 return CMD_WARNING_CONFIG_FAILED;
9976
9977 return CMD_SUCCESS;
9978 }
9979
9980 DEFPY (show_bgp_srv6,
9981 show_bgp_srv6_cmd,
9982 "show bgp segment-routing srv6",
9983 SHOW_STR
9984 BGP_STR
9985 "BGP Segment Routing\n"
9986 "BGP Segment Routing SRv6\n")
9987 {
9988 struct bgp *bgp;
9989 struct listnode *node;
9990 struct srv6_locator_chunk *chunk;
9991 struct bgp_srv6_function *func;
9992
9993 bgp = bgp_get_default();
9994 if (!bgp)
9995 return CMD_SUCCESS;
9996
9997 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9998 vty_out(vty, "locator_chunks:\n");
9999 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
10000 vty_out(vty, "- %pFX\n", &chunk->prefix);
10001 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10002 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10003 vty_out(vty, " func-length: %d\n",
10004 chunk->function_bits_length);
10005 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10006 }
10007
10008 vty_out(vty, "functions:\n");
10009 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
10010 vty_out(vty, "- sid: %pI6\n", &func->sid);
10011 vty_out(vty, " locator: %s\n", func->locator_name);
10012 }
10013
10014 vty_out(vty, "bgps:\n");
10015 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10016 vty_out(vty, "- name: %s\n",
10017 bgp->name ? bgp->name : "default");
10018
10019 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10020 bgp->vpn_policy[AFI_IP].tovpn_sid);
10021 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10022 bgp->vpn_policy[AFI_IP6].tovpn_sid);
10023 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
10024 }
10025
10026 return CMD_SUCCESS;
10027 }
10028
10029 DEFUN_NOSH (exit_address_family,
10030 exit_address_family_cmd,
10031 "exit-address-family",
10032 "Exit from Address Family configuration mode\n")
10033 {
10034 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10035 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10036 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10037 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
10038 || vty->node == BGP_EVPN_NODE
10039 || vty->node == BGP_FLOWSPECV4_NODE
10040 || vty->node == BGP_FLOWSPECV6_NODE)
10041 vty->node = BGP_NODE;
10042 return CMD_SUCCESS;
10043 }
10044
10045 /* Recalculate bestpath and re-advertise a prefix */
10046 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10047 const char *ip_str, afi_t afi, safi_t safi,
10048 struct prefix_rd *prd)
10049 {
10050 int ret;
10051 struct prefix match;
10052 struct bgp_dest *dest;
10053 struct bgp_dest *rm;
10054 struct bgp *bgp;
10055 struct bgp_table *table;
10056 struct bgp_table *rib;
10057
10058 /* BGP structure lookup. */
10059 if (view_name) {
10060 bgp = bgp_lookup_by_name(view_name);
10061 if (bgp == NULL) {
10062 vty_out(vty, "%% Can't find BGP instance %s\n",
10063 view_name);
10064 return CMD_WARNING;
10065 }
10066 } else {
10067 bgp = bgp_get_default();
10068 if (bgp == NULL) {
10069 vty_out(vty, "%% No BGP process is configured\n");
10070 return CMD_WARNING;
10071 }
10072 }
10073
10074 /* Check IP address argument. */
10075 ret = str2prefix(ip_str, &match);
10076 if (!ret) {
10077 vty_out(vty, "%% address is malformed\n");
10078 return CMD_WARNING;
10079 }
10080
10081 match.family = afi2family(afi);
10082 rib = bgp->rib[afi][safi];
10083
10084 if (safi == SAFI_MPLS_VPN) {
10085 for (dest = bgp_table_top(rib); dest;
10086 dest = bgp_route_next(dest)) {
10087 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10088
10089 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10090 continue;
10091
10092 table = bgp_dest_get_bgp_table_info(dest);
10093 if (table == NULL)
10094 continue;
10095
10096 rm = bgp_node_match(table, &match);
10097 if (rm != NULL) {
10098 const struct prefix *rm_p =
10099 bgp_dest_get_prefix(rm);
10100
10101 if (rm_p->prefixlen == match.prefixlen) {
10102 SET_FLAG(rm->flags,
10103 BGP_NODE_USER_CLEAR);
10104 bgp_process(bgp, rm, afi, safi);
10105 }
10106 bgp_dest_unlock_node(rm);
10107 }
10108 }
10109 } else {
10110 dest = bgp_node_match(rib, &match);
10111 if (dest != NULL) {
10112 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10113
10114 if (dest_p->prefixlen == match.prefixlen) {
10115 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10116 bgp_process(bgp, dest, afi, safi);
10117 }
10118 bgp_dest_unlock_node(dest);
10119 }
10120 }
10121
10122 return CMD_SUCCESS;
10123 }
10124
10125 /* one clear bgp command to rule them all */
10126 DEFUN (clear_ip_bgp_all,
10127 clear_ip_bgp_all_cmd,
10128 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|ASNUM|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
10129 CLEAR_STR
10130 IP_STR
10131 BGP_STR
10132 BGP_INSTANCE_HELP_STR
10133 BGP_AFI_HELP_STR
10134 BGP_AF_STR
10135 BGP_SAFI_WITH_LABEL_HELP_STR
10136 BGP_AF_MODIFIER_STR
10137 "Clear all peers\n"
10138 "BGP IPv4 neighbor to clear\n"
10139 "BGP IPv6 neighbor to clear\n"
10140 "BGP neighbor on interface to clear\n"
10141 "Clear peers with the AS number in plain or dotted format\n"
10142 "Clear all external peers\n"
10143 "Clear all members of peer-group\n"
10144 "BGP peer-group name\n"
10145 BGP_SOFT_STR
10146 BGP_SOFT_IN_STR
10147 BGP_SOFT_OUT_STR
10148 BGP_SOFT_IN_STR
10149 "Push out prefix-list ORF and do inbound soft reconfig\n"
10150 BGP_SOFT_OUT_STR
10151 "Reset message statistics\n")
10152 {
10153 char *vrf = NULL;
10154
10155 afi_t afi = AFI_UNSPEC;
10156 safi_t safi = SAFI_UNSPEC;
10157 enum clear_sort clr_sort = clear_peer;
10158 enum bgp_clear_type clr_type;
10159 char *clr_arg = NULL;
10160
10161 int idx = 0;
10162
10163 /* clear [ip] bgp */
10164 if (argv_find(argv, argc, "ip", &idx))
10165 afi = AFI_IP;
10166
10167 /* [<vrf> VIEWVRFNAME] */
10168 if (argv_find(argv, argc, "vrf", &idx)) {
10169 vrf = argv[idx + 1]->arg;
10170 idx += 2;
10171 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10172 vrf = NULL;
10173 } else if (argv_find(argv, argc, "view", &idx)) {
10174 /* [<view> VIEWVRFNAME] */
10175 vrf = argv[idx + 1]->arg;
10176 idx += 2;
10177 }
10178 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10179 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10180 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10181
10182 /* <*|A.B.C.D|X:X::X:X|WORD|ASNUM|external|peer-group PGNAME> */
10183 if (argv_find(argv, argc, "*", &idx)) {
10184 clr_sort = clear_all;
10185 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10186 clr_sort = clear_peer;
10187 clr_arg = argv[idx]->arg;
10188 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10189 clr_sort = clear_peer;
10190 clr_arg = argv[idx]->arg;
10191 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10192 clr_sort = clear_group;
10193 idx++;
10194 clr_arg = argv[idx]->arg;
10195 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10196 clr_sort = clear_peer;
10197 clr_arg = argv[idx]->arg;
10198 } else if (argv_find(argv, argc, "WORD", &idx)) {
10199 clr_sort = clear_peer;
10200 clr_arg = argv[idx]->arg;
10201 } else if (argv_find(argv, argc, "ASNUM", &idx)) {
10202 clr_sort = clear_as;
10203 clr_arg = argv[idx]->arg;
10204 } else if (argv_find(argv, argc, "external", &idx)) {
10205 clr_sort = clear_external;
10206 }
10207
10208 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10209 if (argv_find(argv, argc, "soft", &idx)) {
10210 if (argv_find(argv, argc, "in", &idx)
10211 || argv_find(argv, argc, "out", &idx))
10212 clr_type = strmatch(argv[idx]->text, "in")
10213 ? BGP_CLEAR_SOFT_IN
10214 : BGP_CLEAR_SOFT_OUT;
10215 else
10216 clr_type = BGP_CLEAR_SOFT_BOTH;
10217 } else if (argv_find(argv, argc, "in", &idx)) {
10218 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10219 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10220 : BGP_CLEAR_SOFT_IN;
10221 } else if (argv_find(argv, argc, "out", &idx)) {
10222 clr_type = BGP_CLEAR_SOFT_OUT;
10223 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10224 clr_type = BGP_CLEAR_MESSAGE_STATS;
10225 } else
10226 clr_type = BGP_CLEAR_SOFT_NONE;
10227
10228 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10229 }
10230
10231 DEFUN (clear_ip_bgp_prefix,
10232 clear_ip_bgp_prefix_cmd,
10233 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10234 CLEAR_STR
10235 IP_STR
10236 BGP_STR
10237 BGP_INSTANCE_HELP_STR
10238 "Clear bestpath and re-advertise\n"
10239 "IPv4 prefix\n")
10240 {
10241 char *vrf = NULL;
10242 char *prefix = NULL;
10243
10244 int idx = 0;
10245
10246 /* [<view|vrf> VIEWVRFNAME] */
10247 if (argv_find(argv, argc, "vrf", &idx)) {
10248 vrf = argv[idx + 1]->arg;
10249 idx += 2;
10250 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10251 vrf = NULL;
10252 } else if (argv_find(argv, argc, "view", &idx)) {
10253 /* [<view> VIEWVRFNAME] */
10254 vrf = argv[idx + 1]->arg;
10255 idx += 2;
10256 }
10257
10258 prefix = argv[argc - 1]->arg;
10259
10260 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10261 }
10262
10263 DEFUN (clear_bgp_ipv6_safi_prefix,
10264 clear_bgp_ipv6_safi_prefix_cmd,
10265 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10266 CLEAR_STR
10267 IP_STR
10268 BGP_STR
10269 BGP_AF_STR
10270 BGP_SAFI_HELP_STR
10271 "Clear bestpath and re-advertise\n"
10272 "IPv6 prefix\n")
10273 {
10274 int idx_safi = 0;
10275 int idx_ipv6_prefix = 0;
10276 safi_t safi = SAFI_UNICAST;
10277 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10278 argv[idx_ipv6_prefix]->arg : NULL;
10279
10280 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10281 return bgp_clear_prefix(
10282 vty, NULL, prefix, AFI_IP6,
10283 safi, NULL);
10284 }
10285
10286 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10287 clear_bgp_instance_ipv6_safi_prefix_cmd,
10288 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10289 CLEAR_STR
10290 IP_STR
10291 BGP_STR
10292 BGP_INSTANCE_HELP_STR
10293 BGP_AF_STR
10294 BGP_SAFI_HELP_STR
10295 "Clear bestpath and re-advertise\n"
10296 "IPv6 prefix\n")
10297 {
10298 int idx_safi = 0;
10299 int idx_vrfview = 0;
10300 int idx_ipv6_prefix = 0;
10301 safi_t safi = SAFI_UNICAST;
10302 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10303 argv[idx_ipv6_prefix]->arg : NULL;
10304 char *vrfview = NULL;
10305
10306 /* [<view|vrf> VIEWVRFNAME] */
10307 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10308 vrfview = argv[idx_vrfview + 1]->arg;
10309 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10310 vrfview = NULL;
10311 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10312 /* [<view> VIEWVRFNAME] */
10313 vrfview = argv[idx_vrfview + 1]->arg;
10314 }
10315 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10316
10317 return bgp_clear_prefix(
10318 vty, vrfview, prefix,
10319 AFI_IP6, safi, NULL);
10320 }
10321
10322 DEFUN (show_bgp_views,
10323 show_bgp_views_cmd,
10324 "show [ip] bgp views",
10325 SHOW_STR
10326 IP_STR
10327 BGP_STR
10328 "Show the defined BGP views\n")
10329 {
10330 struct list *inst = bm->bgp;
10331 struct listnode *node;
10332 struct bgp *bgp;
10333
10334 vty_out(vty, "Defined BGP views:\n");
10335 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10336 /* Skip VRFs. */
10337 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10338 continue;
10339 vty_out(vty, "\t%s (AS%s)\n", bgp->name ? bgp->name : "(null)",
10340 bgp->as_pretty);
10341 }
10342
10343 return CMD_SUCCESS;
10344 }
10345
10346 static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10347 int *peers_estbd)
10348 {
10349 struct peer *peer;
10350 struct listnode *node;
10351
10352 *peers_cfgd = *peers_estbd = 0;
10353 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10354 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10355 continue;
10356 (*peers_cfgd)++;
10357 if (peer_established(peer))
10358 (*peers_estbd)++;
10359 }
10360 }
10361
10362 static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10363 const char *type)
10364 {
10365 int peers_cfg, peers_estb;
10366
10367 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10368
10369 if (json) {
10370 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10371 ? -1
10372 : (int64_t)bgp->vrf_id;
10373 json_object_string_add(json, "type", type);
10374 json_object_int_add(json, "vrfId", vrf_id_ui);
10375 json_object_string_addf(json, "routerId", "%pI4",
10376 &bgp->router_id);
10377 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10378 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10379 json_object_int_add(json, "l3vni", bgp->l3vni);
10380 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10381 json_object_string_add(
10382 json, "interface",
10383 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10384 }
10385 }
10386
10387 static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10388 json_object *json, const char *name,
10389 const char *type, bool use_vrf)
10390 {
10391 int peers_cfg, peers_estb;
10392
10393 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10394
10395 if (use_vrf) {
10396 if (json) {
10397 print_bgp_vrfs(bgp, vty, json, type);
10398 } else {
10399 vty_out(vty, "BGP instance %s VRF id %d\n",
10400 bgp->name_pretty,
10401 bgp->vrf_id == VRF_UNKNOWN ? -1
10402 : (int)bgp->vrf_id);
10403 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10404 vty_out(vty,
10405 "Num Configured Peers %d, Established %d\n",
10406 peers_cfg, peers_estb);
10407 if (bgp->l3vni) {
10408 vty_out(vty,
10409 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10410 bgp->l3vni,
10411 ifindex2ifname(bgp->l3vni_svi_ifindex,
10412 bgp->vrf_id),
10413 &bgp->rmac);
10414 }
10415 }
10416 } else {
10417 if (json) {
10418 print_bgp_vrfs(bgp, vty, json, type);
10419 } else {
10420 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10421 type,
10422 bgp->vrf_id == VRF_UNKNOWN ? -1
10423 : (int)bgp->vrf_id,
10424 &bgp->router_id, peers_cfg, peers_estb, name);
10425 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10426 bgp->l3vni, &bgp->rmac,
10427 ifindex2ifname(bgp->l3vni_svi_ifindex,
10428 bgp->vrf_id));
10429 }
10430 }
10431
10432 return CMD_SUCCESS;
10433 }
10434
10435 DEFPY (show_bgp_vrfs,
10436 show_bgp_vrfs_cmd,
10437 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10438 SHOW_STR
10439 IP_STR
10440 BGP_STR
10441 "Show BGP VRFs\n"
10442 "Specific VRF name\n"
10443 JSON_STR)
10444 {
10445 struct list *inst = bm->bgp;
10446 struct listnode *node;
10447 struct bgp *bgp;
10448 bool uj = use_json(argc, argv);
10449 json_object *json = NULL;
10450 json_object *json_vrfs = NULL;
10451 json_object *json_vrf = NULL;
10452 int count = 0;
10453 const char *name = vrf_name;
10454 const char *type;
10455
10456 if (uj)
10457 json = json_object_new_object();
10458
10459 if (name) {
10460 if (strmatch(name, VRF_DEFAULT_NAME)) {
10461 bgp = bgp_get_default();
10462 type = "DFLT";
10463 } else {
10464 bgp = bgp_lookup_by_name(name);
10465 type = "VRF";
10466 }
10467 if (!bgp) {
10468 if (uj)
10469 vty_json(vty, json);
10470 else
10471 vty_out(vty,
10472 "%% Specified BGP instance not found\n");
10473
10474 return CMD_WARNING;
10475 }
10476 }
10477
10478 if (vrf_name) {
10479 if (uj)
10480 json_vrf = json_object_new_object();
10481
10482 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10483 true);
10484
10485 if (uj) {
10486 json_object_object_add(json, name, json_vrf);
10487 vty_json(vty, json);
10488 }
10489
10490 return CMD_SUCCESS;
10491 }
10492
10493 if (uj)
10494 json_vrfs = json_object_new_object();
10495
10496 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10497 const char *name;
10498
10499 /* Skip Views. */
10500 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10501 continue;
10502
10503 count++;
10504 if (!uj && count == 1) {
10505 vty_out(vty,
10506 "%4s %-5s %-16s %9s %10s %-37s\n",
10507 "Type", "Id", "routerId", "#PeersCfg",
10508 "#PeersEstb", "Name");
10509 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10510 "L3-VNI", "RouterMAC", "Interface");
10511 }
10512 if (uj)
10513 json_vrf = json_object_new_object();
10514
10515 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10516 name = VRF_DEFAULT_NAME;
10517 type = "DFLT";
10518 } else {
10519 name = bgp->name;
10520 type = "VRF";
10521 }
10522
10523 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10524 false);
10525
10526 if (uj)
10527 json_object_object_add(json_vrfs, name, json_vrf);
10528 }
10529
10530 if (uj) {
10531 json_object_object_add(json, "vrfs", json_vrfs);
10532 json_object_int_add(json, "totalVrfs", count);
10533 vty_json(vty, json);
10534 } else {
10535 if (count)
10536 vty_out(vty,
10537 "\nTotal number of VRFs (including default): %d\n",
10538 count);
10539 }
10540
10541 return CMD_SUCCESS;
10542 }
10543
10544 DEFUN (show_bgp_mac_hash,
10545 show_bgp_mac_hash_cmd,
10546 "show bgp mac hash",
10547 SHOW_STR
10548 BGP_STR
10549 "Mac Address\n"
10550 "Mac Address database\n")
10551 {
10552 bgp_mac_dump_table(vty);
10553
10554 return CMD_SUCCESS;
10555 }
10556
10557 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10558 {
10559 struct vty *vty = (struct vty *)args;
10560 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10561
10562 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10563 }
10564
10565 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10566 {
10567 vty_out(vty, "self nexthop database:\n");
10568 bgp_nexthop_show_address_hash(vty, bgp);
10569
10570 vty_out(vty, "Tunnel-ip database:\n");
10571 hash_iterate(bgp->tip_hash,
10572 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10573 vty);
10574 }
10575
10576 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10577 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10578 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10579 "martian next-hops\n"
10580 "martian next-hop database\n")
10581 {
10582 struct bgp *bgp = NULL;
10583 int idx = 0;
10584 char *name = NULL;
10585
10586 /* [<vrf> VIEWVRFNAME] */
10587 if (argv_find(argv, argc, "vrf", &idx)) {
10588 name = argv[idx + 1]->arg;
10589 if (name && strmatch(name, VRF_DEFAULT_NAME))
10590 name = NULL;
10591 } else if (argv_find(argv, argc, "view", &idx))
10592 /* [<view> VIEWVRFNAME] */
10593 name = argv[idx + 1]->arg;
10594 if (name)
10595 bgp = bgp_lookup_by_name(name);
10596 else
10597 bgp = bgp_get_default();
10598
10599 if (!bgp) {
10600 vty_out(vty, "%% No BGP process is configured\n");
10601 return CMD_WARNING;
10602 }
10603 bgp_show_martian_nexthops(vty, bgp);
10604
10605 return CMD_SUCCESS;
10606 }
10607
10608 DEFUN (show_bgp_memory,
10609 show_bgp_memory_cmd,
10610 "show [ip] bgp memory",
10611 SHOW_STR
10612 IP_STR
10613 BGP_STR
10614 "Global BGP memory statistics\n")
10615 {
10616 char memstrbuf[MTYPE_MEMSTR_LEN];
10617 unsigned long count;
10618
10619 /* RIB related usage stats */
10620 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10621 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10622 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10623 count * sizeof(struct bgp_dest)));
10624
10625 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10626 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10627 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10628 count * sizeof(struct bgp_path_info)));
10629 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10630 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10631 count,
10632 mtype_memstr(
10633 memstrbuf, sizeof(memstrbuf),
10634 count * sizeof(struct bgp_path_info_extra)));
10635
10636 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10637 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10638 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10639 count * sizeof(struct bgp_static)));
10640
10641 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10642 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10643 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10644 count * sizeof(struct bpacket)));
10645
10646 /* Adj-In/Out */
10647 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10648 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10649 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10650 count * sizeof(struct bgp_adj_in)));
10651 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10652 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10653 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10654 count * sizeof(struct bgp_adj_out)));
10655
10656 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10657 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10658 count,
10659 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10660 count * sizeof(struct bgp_nexthop_cache)));
10661
10662 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10663 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10664 count,
10665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10666 count * sizeof(struct bgp_damp_info)));
10667
10668 /* Attributes */
10669 count = attr_count();
10670 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10671 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10672 count * sizeof(struct attr)));
10673
10674 if ((count = attr_unknown_count()))
10675 vty_out(vty, "%ld unknown attributes\n", count);
10676
10677 /* AS_PATH attributes */
10678 count = aspath_count();
10679 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10680 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10681 count * sizeof(struct aspath)));
10682
10683 count = mtype_stats_alloc(MTYPE_AS_SEG);
10684 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10685 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10686 count * sizeof(struct assegment)));
10687
10688 /* Other attributes */
10689 if ((count = community_count()))
10690 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10691 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10692 count * sizeof(struct community)));
10693 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10694 vty_out(vty,
10695 "%ld BGP ext-community entries, using %s of memory\n",
10696 count,
10697 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10698 count * sizeof(struct ecommunity)));
10699 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10700 vty_out(vty,
10701 "%ld BGP large-community entries, using %s of memory\n",
10702 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10703 count * sizeof(struct lcommunity)));
10704
10705 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10706 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10708 count * sizeof(struct cluster_list)));
10709
10710 /* Peer related usage */
10711 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10712 vty_out(vty, "%ld peers, using %s of memory\n", count,
10713 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10714 count * sizeof(struct peer)));
10715
10716 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10717 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10719 count * sizeof(struct peer_group)));
10720
10721 /* Other */
10722 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10723 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10724 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10725 count * sizeof(regex_t)));
10726 return CMD_SUCCESS;
10727 }
10728
10729 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10730 {
10731 json_object *bestpath = json_object_new_object();
10732
10733 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10734 json_object_string_add(bestpath, "asPath", "ignore");
10735
10736 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10737 json_object_string_add(bestpath, "asPath", "confed");
10738
10739 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10740 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10741 json_object_string_add(bestpath, "multiPathRelax",
10742 "as-set");
10743 else
10744 json_object_string_add(bestpath, "multiPathRelax",
10745 "true");
10746 } else
10747 json_object_string_add(bestpath, "multiPathRelax", "false");
10748
10749 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10750 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10751
10752 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10753 json_object_string_add(bestpath, "compareRouterId", "true");
10754 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10755 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10756 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10757 json_object_string_add(bestpath, "med", "confed");
10758 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10759 json_object_string_add(bestpath, "med",
10760 "missing-as-worst");
10761 else
10762 json_object_string_add(bestpath, "med", "true");
10763 }
10764
10765 json_object_object_add(json, "bestPath", bestpath);
10766 }
10767
10768 /* Print the error code/subcode for why the peer is down */
10769 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10770 json_object *json_peer, bool use_json)
10771 {
10772 const char *code_str;
10773 const char *subcode_str;
10774
10775 if (use_json) {
10776 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10777 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10778 char errorcodesubcode_hexstr[5];
10779 char errorcodesubcode_str[256];
10780
10781 code_str = bgp_notify_code_str(peer->notify.code);
10782 subcode_str = bgp_notify_subcode_str(
10783 peer->notify.code,
10784 peer->notify.subcode);
10785
10786 snprintf(errorcodesubcode_hexstr,
10787 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10788 peer->notify.code, peer->notify.subcode);
10789 json_object_string_add(json_peer,
10790 "lastErrorCodeSubcode",
10791 errorcodesubcode_hexstr);
10792 snprintf(errorcodesubcode_str, 255, "%s%s",
10793 code_str, subcode_str);
10794 json_object_string_add(json_peer,
10795 "lastNotificationReason",
10796 errorcodesubcode_str);
10797 json_object_boolean_add(json_peer,
10798 "lastNotificationHardReset",
10799 peer->notify.hard_reset);
10800 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10801 && peer->notify.code == BGP_NOTIFY_CEASE
10802 && (peer->notify.subcode
10803 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10804 || peer->notify.subcode
10805 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10806 && peer->notify.length) {
10807 char msgbuf[1024];
10808 const char *msg_str;
10809
10810 msg_str = bgp_notify_admin_message(
10811 msgbuf, sizeof(msgbuf),
10812 (uint8_t *)peer->notify.data,
10813 peer->notify.length);
10814 if (msg_str)
10815 json_object_string_add(
10816 json_peer,
10817 "lastShutdownDescription",
10818 msg_str);
10819 }
10820
10821 }
10822 json_object_string_add(json_peer, "lastResetDueTo",
10823 peer_down_str[(int)peer->last_reset]);
10824 json_object_int_add(json_peer, "lastResetCode",
10825 peer->last_reset);
10826 } else {
10827 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10828 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10829 code_str = bgp_notify_code_str(peer->notify.code);
10830 subcode_str =
10831 bgp_notify_subcode_str(peer->notify.code,
10832 peer->notify.subcode);
10833 vty_out(vty, " Notification %s (%s%s%s)\n",
10834 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10835 ? "sent"
10836 : "received",
10837 code_str, subcode_str,
10838 peer->notify.hard_reset
10839 ? bgp_notify_subcode_str(
10840 BGP_NOTIFY_CEASE,
10841 BGP_NOTIFY_CEASE_HARD_RESET)
10842 : "");
10843 } else {
10844 vty_out(vty, " %s\n",
10845 peer_down_str[(int)peer->last_reset]);
10846 }
10847 }
10848 }
10849
10850 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10851 safi_t safi)
10852 {
10853 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10854 }
10855
10856 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10857 struct peer *peer, json_object *json_peer,
10858 int max_neighbor_width, bool use_json)
10859 {
10860 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10861 int len;
10862
10863 if (use_json) {
10864 if (peer_dynamic_neighbor(peer))
10865 json_object_boolean_true_add(json_peer,
10866 "dynamicPeer");
10867 if (peer->hostname)
10868 json_object_string_add(json_peer, "hostname",
10869 peer->hostname);
10870
10871 if (peer->domainname)
10872 json_object_string_add(json_peer, "domainname",
10873 peer->domainname);
10874 json_object_int_add(json_peer, "connectionsEstablished",
10875 peer->established);
10876 json_object_int_add(json_peer, "connectionsDropped",
10877 peer->dropped);
10878 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10879 use_json, json_peer);
10880 if (peer_established(peer))
10881 json_object_string_add(json_peer, "lastResetDueTo",
10882 "AFI/SAFI Not Negotiated");
10883 else
10884 bgp_show_peer_reset(NULL, peer, json_peer, true);
10885 } else {
10886 dn_flag[1] = '\0';
10887 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10888 if (peer->hostname
10889 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10890 len = vty_out(vty, "%s%s(%s)", dn_flag,
10891 peer->hostname, peer->host);
10892 else
10893 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10894
10895 /* pad the neighbor column with spaces */
10896 if (len < max_neighbor_width)
10897 vty_out(vty, "%*s", max_neighbor_width - len,
10898 " ");
10899 vty_out(vty, "%7d %7d %9s", peer->established,
10900 peer->dropped,
10901 peer_uptime(peer->uptime, timebuf,
10902 BGP_UPTIME_LEN, 0, NULL));
10903 if (peer_established(peer))
10904 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10905 else
10906 bgp_show_peer_reset(vty, peer, NULL,
10907 false);
10908 }
10909 }
10910
10911 /* Strip peer's description to the given size. */
10912 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10913 {
10914 static char stripped[BUFSIZ];
10915 uint32_t i = 0;
10916 uint32_t last_space = 0;
10917
10918 while (i < size) {
10919 if (*(desc + i) == 0) {
10920 stripped[i] = '\0';
10921 return stripped;
10922 }
10923 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10924 last_space = i;
10925 stripped[i] = *(desc + i);
10926 i++;
10927 }
10928
10929 if (last_space > size)
10930 stripped[size + 1] = '\0';
10931 else
10932 stripped[last_space] = '\0';
10933
10934 return stripped;
10935 }
10936
10937 /* Determine whether var peer should be filtered out of the summary. */
10938 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10939 struct peer *fpeer, int as_type,
10940 as_t as)
10941 {
10942
10943 /* filter neighbor XXXX */
10944 if (fpeer && fpeer != peer)
10945 return true;
10946
10947 /* filter remote-as (internal|external) */
10948 if (as_type != AS_UNSPECIFIED) {
10949 if (peer->as_type == AS_SPECIFIED) {
10950 if (as_type == AS_INTERNAL) {
10951 if (peer->as != peer->local_as)
10952 return true;
10953 } else if (peer->as == peer->local_as)
10954 return true;
10955 } else if (as_type != peer->as_type)
10956 return true;
10957 } else if (as && as != peer->as) /* filter remote-as XXX */
10958 return true;
10959
10960 return false;
10961 }
10962
10963 /* Show BGP peer's summary information.
10964 *
10965 * Peer's description is stripped according to if `wide` option is given
10966 * or not.
10967 *
10968 * When adding new columns to `show bgp summary` output, please make
10969 * sure `Desc` is the lastest column to show because it can contain
10970 * whitespaces and the whole output will be tricky.
10971 */
10972 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10973 struct peer *fpeer, int as_type, as_t as,
10974 uint16_t show_flags)
10975 {
10976 struct peer *peer;
10977 struct listnode *node, *nnode;
10978 unsigned int count = 0, dn_count = 0;
10979 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10980 char neighbor_buf[VTY_BUFSIZ];
10981 int neighbor_col_default_width = 16;
10982 int len, failed_count = 0;
10983 unsigned int filtered_count = 0;
10984 int max_neighbor_width = 0;
10985 int pfx_rcd_safi;
10986 json_object *json = NULL;
10987 json_object *json_peer = NULL;
10988 json_object *json_peers = NULL;
10989 struct peer_af *paf;
10990 struct bgp_filter *filter;
10991 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10992 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10993 bool show_established =
10994 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10995 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10996 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10997
10998 /* labeled-unicast routes are installed in the unicast table so in order
10999 * to
11000 * display the correct PfxRcd value we must look at SAFI_UNICAST
11001 */
11002
11003 if (safi == SAFI_LABELED_UNICAST)
11004 pfx_rcd_safi = SAFI_UNICAST;
11005 else
11006 pfx_rcd_safi = safi;
11007
11008 if (use_json) {
11009 json = json_object_new_object();
11010 json_peers = json_object_new_object();
11011 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11012 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11013 as_type, as)) {
11014 filtered_count++;
11015 count++;
11016 continue;
11017 }
11018
11019 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11020 continue;
11021
11022 if (peer->afc[afi][safi]) {
11023 /* See if we have at least a single failed peer */
11024 if (bgp_has_peer_failed(peer, afi, safi))
11025 failed_count++;
11026 count++;
11027 }
11028 if (peer_dynamic_neighbor(peer))
11029 dn_count++;
11030 }
11031
11032 } else {
11033 /* Loop over all neighbors that will be displayed to determine
11034 * how many
11035 * characters are needed for the Neighbor column
11036 */
11037 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11038 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11039 as_type, as)) {
11040 filtered_count++;
11041 count++;
11042 continue;
11043 }
11044
11045 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11046 continue;
11047
11048 if (peer->afc[afi][safi]) {
11049 memset(dn_flag, '\0', sizeof(dn_flag));
11050 if (peer_dynamic_neighbor(peer))
11051 dn_flag[0] = '*';
11052
11053 if (peer->hostname
11054 && CHECK_FLAG(bgp->flags,
11055 BGP_FLAG_SHOW_HOSTNAME))
11056 snprintf(neighbor_buf,
11057 sizeof(neighbor_buf),
11058 "%s%s(%s) ", dn_flag,
11059 peer->hostname, peer->host);
11060 else
11061 snprintf(neighbor_buf,
11062 sizeof(neighbor_buf), "%s%s ",
11063 dn_flag, peer->host);
11064
11065 len = strlen(neighbor_buf);
11066
11067 if (len > max_neighbor_width)
11068 max_neighbor_width = len;
11069
11070 /* See if we have at least a single failed peer */
11071 if (bgp_has_peer_failed(peer, afi, safi))
11072 failed_count++;
11073 count++;
11074 }
11075 }
11076
11077 /* Originally we displayed the Neighbor column as 16
11078 * characters wide so make that the default
11079 */
11080 if (max_neighbor_width < neighbor_col_default_width)
11081 max_neighbor_width = neighbor_col_default_width;
11082 }
11083
11084 if (show_failed && !failed_count) {
11085 if (use_json) {
11086 json_object_int_add(json, "failedPeersCount", 0);
11087 json_object_int_add(json, "dynamicPeers", dn_count);
11088 json_object_int_add(json, "totalPeers", count);
11089
11090 vty_json(vty, json);
11091 } else {
11092 vty_out(vty, "%% No failed BGP neighbors found\n");
11093 }
11094 return CMD_SUCCESS;
11095 }
11096
11097 count = 0; /* Reset the value as its used again */
11098 filtered_count = 0;
11099 dn_count = 0;
11100 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11101 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11102 continue;
11103
11104 if (!peer->afc[afi][safi])
11105 continue;
11106
11107 if (!count) {
11108 unsigned long ents;
11109 char memstrbuf[MTYPE_MEMSTR_LEN];
11110 int64_t vrf_id_ui;
11111
11112 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11113 ? -1
11114 : (int64_t)bgp->vrf_id;
11115
11116 /* Usage summary and header */
11117 if (use_json) {
11118 json_object_string_addf(json, "routerId",
11119 "%pI4",
11120 &bgp->router_id);
11121 json_object_int_add(json, "as", bgp->as);
11122 json_object_int_add(json, "vrfId", vrf_id_ui);
11123 json_object_string_add(
11124 json, "vrfName",
11125 (bgp->inst_type
11126 == BGP_INSTANCE_TYPE_DEFAULT)
11127 ? VRF_DEFAULT_NAME
11128 : bgp->name);
11129 } else {
11130 vty_out(vty,
11131 "BGP router identifier %pI4, local AS number %s vrf-id %d",
11132 &bgp->router_id, bgp->as_pretty,
11133 bgp->vrf_id == VRF_UNKNOWN
11134 ? -1
11135 : (int)bgp->vrf_id);
11136 vty_out(vty, "\n");
11137 }
11138
11139 if (bgp_update_delay_configured(bgp)) {
11140 if (use_json) {
11141 json_object_int_add(
11142 json, "updateDelayLimit",
11143 bgp->v_update_delay);
11144
11145 if (bgp->v_update_delay
11146 != bgp->v_establish_wait)
11147 json_object_int_add(
11148 json,
11149 "updateDelayEstablishWait",
11150 bgp->v_establish_wait);
11151
11152 if (bgp_update_delay_active(bgp)) {
11153 json_object_string_add(
11154 json,
11155 "updateDelayFirstNeighbor",
11156 bgp->update_delay_begin_time);
11157 json_object_boolean_true_add(
11158 json,
11159 "updateDelayInProgress");
11160 } else {
11161 if (bgp->update_delay_over) {
11162 json_object_string_add(
11163 json,
11164 "updateDelayFirstNeighbor",
11165 bgp->update_delay_begin_time);
11166 json_object_string_add(
11167 json,
11168 "updateDelayBestpathResumed",
11169 bgp->update_delay_end_time);
11170 json_object_string_add(
11171 json,
11172 "updateDelayZebraUpdateResume",
11173 bgp->update_delay_zebra_resume_time);
11174 json_object_string_add(
11175 json,
11176 "updateDelayPeerUpdateResume",
11177 bgp->update_delay_peers_resume_time);
11178 }
11179 }
11180 } else {
11181 vty_out(vty,
11182 "Read-only mode update-delay limit: %d seconds\n",
11183 bgp->v_update_delay);
11184 if (bgp->v_update_delay
11185 != bgp->v_establish_wait)
11186 vty_out(vty,
11187 " Establish wait: %d seconds\n",
11188 bgp->v_establish_wait);
11189
11190 if (bgp_update_delay_active(bgp)) {
11191 vty_out(vty,
11192 " First neighbor established: %s\n",
11193 bgp->update_delay_begin_time);
11194 vty_out(vty,
11195 " Delay in progress\n");
11196 } else {
11197 if (bgp->update_delay_over) {
11198 vty_out(vty,
11199 " First neighbor established: %s\n",
11200 bgp->update_delay_begin_time);
11201 vty_out(vty,
11202 " Best-paths resumed: %s\n",
11203 bgp->update_delay_end_time);
11204 vty_out(vty,
11205 " zebra update resumed: %s\n",
11206 bgp->update_delay_zebra_resume_time);
11207 vty_out(vty,
11208 " peers update resumed: %s\n",
11209 bgp->update_delay_peers_resume_time);
11210 }
11211 }
11212 }
11213 }
11214
11215 if (use_json) {
11216 if (bgp_maxmed_onstartup_configured(bgp)
11217 && bgp->maxmed_active)
11218 json_object_boolean_true_add(
11219 json, "maxMedOnStartup");
11220 if (bgp->v_maxmed_admin)
11221 json_object_boolean_true_add(
11222 json, "maxMedAdministrative");
11223
11224 json_object_int_add(
11225 json, "tableVersion",
11226 bgp_table_version(bgp->rib[afi][safi]));
11227
11228 ents = bgp_table_count(bgp->rib[afi][safi]);
11229 json_object_int_add(json, "ribCount", ents);
11230 json_object_int_add(
11231 json, "ribMemory",
11232 ents * sizeof(struct bgp_dest));
11233
11234 ents = bgp->af_peer_count[afi][safi];
11235 json_object_int_add(json, "peerCount", ents);
11236 json_object_int_add(json, "peerMemory",
11237 ents * sizeof(struct peer));
11238
11239 if ((ents = listcount(bgp->group))) {
11240 json_object_int_add(
11241 json, "peerGroupCount", ents);
11242 json_object_int_add(
11243 json, "peerGroupMemory",
11244 ents * sizeof(struct
11245 peer_group));
11246 }
11247
11248 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11249 BGP_CONFIG_DAMPENING))
11250 json_object_boolean_true_add(
11251 json, "dampeningEnabled");
11252 } else {
11253 if (!show_terse) {
11254 if (bgp_maxmed_onstartup_configured(bgp)
11255 && bgp->maxmed_active)
11256 vty_out(vty,
11257 "Max-med on-startup active\n");
11258 if (bgp->v_maxmed_admin)
11259 vty_out(vty,
11260 "Max-med administrative active\n");
11261
11262 vty_out(vty,
11263 "BGP table version %" PRIu64
11264 "\n",
11265 bgp_table_version(
11266 bgp->rib[afi][safi]));
11267
11268 ents = bgp_table_count(
11269 bgp->rib[afi][safi]);
11270 vty_out(vty,
11271 "RIB entries %ld, using %s of memory\n",
11272 ents,
11273 mtype_memstr(
11274 memstrbuf,
11275 sizeof(memstrbuf),
11276 ents
11277 * sizeof(
11278 struct
11279 bgp_dest)));
11280
11281 /* Peer related usage */
11282 ents = bgp->af_peer_count[afi][safi];
11283 vty_out(vty,
11284 "Peers %ld, using %s of memory\n",
11285 ents,
11286 mtype_memstr(
11287 memstrbuf,
11288 sizeof(memstrbuf),
11289 ents
11290 * sizeof(
11291 struct
11292 peer)));
11293
11294 if ((ents = listcount(bgp->group)))
11295 vty_out(vty,
11296 "Peer groups %ld, using %s of memory\n",
11297 ents,
11298 mtype_memstr(
11299 memstrbuf,
11300 sizeof(memstrbuf),
11301 ents
11302 * sizeof(
11303 struct
11304 peer_group)));
11305
11306 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11307 BGP_CONFIG_DAMPENING))
11308 vty_out(vty,
11309 "Dampening enabled.\n");
11310 }
11311 if (show_failed) {
11312 vty_out(vty, "\n");
11313
11314 /* Subtract 8 here because 'Neighbor' is
11315 * 8 characters */
11316 vty_out(vty, "Neighbor");
11317 vty_out(vty, "%*s",
11318 max_neighbor_width - 8, " ");
11319 vty_out(vty,
11320 BGP_SHOW_SUMMARY_HEADER_FAILED);
11321 }
11322 }
11323 }
11324
11325 paf = peer_af_find(peer, afi, safi);
11326 filter = &peer->filter[afi][safi];
11327
11328 count++;
11329 /* Works for both failed & successful cases */
11330 if (peer_dynamic_neighbor(peer))
11331 dn_count++;
11332
11333 if (use_json) {
11334 json_peer = NULL;
11335 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11336 as_type, as)) {
11337 filtered_count++;
11338 continue;
11339 }
11340 if (show_failed &&
11341 bgp_has_peer_failed(peer, afi, safi)) {
11342 json_peer = json_object_new_object();
11343 bgp_show_failed_summary(vty, bgp, peer,
11344 json_peer, 0, use_json);
11345 } else if (!show_failed) {
11346 if (show_established
11347 && bgp_has_peer_failed(peer, afi, safi)) {
11348 filtered_count++;
11349 continue;
11350 }
11351
11352 json_peer = json_object_new_object();
11353 if (peer_dynamic_neighbor(peer)) {
11354 json_object_boolean_true_add(json_peer,
11355 "dynamicPeer");
11356 }
11357
11358 if (peer->hostname)
11359 json_object_string_add(json_peer, "hostname",
11360 peer->hostname);
11361
11362 if (peer->domainname)
11363 json_object_string_add(json_peer, "domainname",
11364 peer->domainname);
11365
11366 json_object_int_add(json_peer, "remoteAs", peer->as);
11367 json_object_int_add(
11368 json_peer, "localAs",
11369 peer->change_local_as
11370 ? peer->change_local_as
11371 : peer->local_as);
11372 json_object_int_add(json_peer, "version", 4);
11373 json_object_int_add(json_peer, "msgRcvd",
11374 PEER_TOTAL_RX(peer));
11375 json_object_int_add(json_peer, "msgSent",
11376 PEER_TOTAL_TX(peer));
11377
11378 atomic_size_t outq_count, inq_count;
11379 outq_count = atomic_load_explicit(
11380 &peer->obuf->count,
11381 memory_order_relaxed);
11382 inq_count = atomic_load_explicit(
11383 &peer->ibuf->count,
11384 memory_order_relaxed);
11385
11386 json_object_int_add(json_peer, "tableVersion",
11387 peer->version[afi][safi]);
11388 json_object_int_add(json_peer, "outq",
11389 outq_count);
11390 json_object_int_add(json_peer, "inq",
11391 inq_count);
11392 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11393 use_json, json_peer);
11394
11395 json_object_int_add(json_peer, "pfxRcd",
11396 peer->pcount[afi][pfx_rcd_safi]);
11397
11398 if (paf && PAF_SUBGRP(paf))
11399 json_object_int_add(
11400 json_peer, "pfxSnt",
11401 (PAF_SUBGRP(paf))->scount);
11402 else
11403 json_object_int_add(json_peer, "pfxSnt",
11404 0);
11405
11406 /* BGP FSM state */
11407 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11408 || CHECK_FLAG(peer->bgp->flags,
11409 BGP_FLAG_SHUTDOWN))
11410 json_object_string_add(json_peer,
11411 "state",
11412 "Idle (Admin)");
11413 else if (peer->afc_recv[afi][safi])
11414 json_object_string_add(
11415 json_peer, "state",
11416 lookup_msg(bgp_status_msg,
11417 peer->status, NULL));
11418 else if (CHECK_FLAG(
11419 peer->sflags,
11420 PEER_STATUS_PREFIX_OVERFLOW))
11421 json_object_string_add(json_peer,
11422 "state",
11423 "Idle (PfxCt)");
11424 else
11425 json_object_string_add(
11426 json_peer, "state",
11427 lookup_msg(bgp_status_msg,
11428 peer->status, NULL));
11429
11430 /* BGP peer 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 "peerState",
11436 "Admin");
11437 else if (CHECK_FLAG(
11438 peer->sflags,
11439 PEER_STATUS_PREFIX_OVERFLOW))
11440 json_object_string_add(json_peer,
11441 "peerState",
11442 "PfxCt");
11443 else if (CHECK_FLAG(peer->flags,
11444 PEER_FLAG_PASSIVE))
11445 json_object_string_add(json_peer,
11446 "peerState",
11447 "Passive");
11448 else if (CHECK_FLAG(peer->sflags,
11449 PEER_STATUS_NSF_WAIT))
11450 json_object_string_add(json_peer,
11451 "peerState",
11452 "NSF passive");
11453 else if (CHECK_FLAG(
11454 peer->bgp->flags,
11455 BGP_FLAG_EBGP_REQUIRES_POLICY)
11456 && (!bgp_inbound_policy_exists(peer,
11457 filter)
11458 || !bgp_outbound_policy_exists(
11459 peer, filter)))
11460 json_object_string_add(json_peer,
11461 "peerState",
11462 "Policy");
11463 else
11464 json_object_string_add(
11465 json_peer, "peerState", "OK");
11466
11467 json_object_int_add(json_peer, "connectionsEstablished",
11468 peer->established);
11469 json_object_int_add(json_peer, "connectionsDropped",
11470 peer->dropped);
11471 if (peer->desc)
11472 json_object_string_add(
11473 json_peer, "desc", peer->desc);
11474 }
11475 /* Avoid creating empty peer dicts in JSON */
11476 if (json_peer == NULL)
11477 continue;
11478
11479 if (peer->conf_if)
11480 json_object_string_add(json_peer, "idType",
11481 "interface");
11482 else if (peer->su.sa.sa_family == AF_INET)
11483 json_object_string_add(json_peer, "idType",
11484 "ipv4");
11485 else if (peer->su.sa.sa_family == AF_INET6)
11486 json_object_string_add(json_peer, "idType",
11487 "ipv6");
11488 json_object_object_add(json_peers, peer->host,
11489 json_peer);
11490 } else {
11491 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11492 as_type, as)) {
11493 filtered_count++;
11494 continue;
11495 }
11496 if (show_failed &&
11497 bgp_has_peer_failed(peer, afi, safi)) {
11498 bgp_show_failed_summary(vty, bgp, peer, NULL,
11499 max_neighbor_width,
11500 use_json);
11501 } else if (!show_failed) {
11502 if (show_established
11503 && bgp_has_peer_failed(peer, afi, safi)) {
11504 filtered_count++;
11505 continue;
11506 }
11507
11508 if ((count - filtered_count) == 1) {
11509 /* display headline before the first
11510 * neighbor line */
11511 vty_out(vty, "\n");
11512
11513 /* Subtract 8 here because 'Neighbor' is
11514 * 8 characters */
11515 vty_out(vty, "Neighbor");
11516 vty_out(vty, "%*s",
11517 max_neighbor_width - 8, " ");
11518 vty_out(vty,
11519 show_wide
11520 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11521 : BGP_SHOW_SUMMARY_HEADER_ALL);
11522 }
11523
11524 memset(dn_flag, '\0', sizeof(dn_flag));
11525 if (peer_dynamic_neighbor(peer)) {
11526 dn_flag[0] = '*';
11527 }
11528
11529 if (peer->hostname
11530 && CHECK_FLAG(bgp->flags,
11531 BGP_FLAG_SHOW_HOSTNAME))
11532 len = vty_out(vty, "%s%s(%s)", dn_flag,
11533 peer->hostname,
11534 peer->host);
11535 else
11536 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11537
11538 /* pad the neighbor column with spaces */
11539 if (len < max_neighbor_width)
11540 vty_out(vty, "%*s", max_neighbor_width - len,
11541 " ");
11542
11543 atomic_size_t outq_count, inq_count;
11544 outq_count = atomic_load_explicit(
11545 &peer->obuf->count,
11546 memory_order_relaxed);
11547 inq_count = atomic_load_explicit(
11548 &peer->ibuf->count,
11549 memory_order_relaxed);
11550
11551 if (show_wide)
11552 vty_out(vty,
11553 "4 %10u %10u %9u %9u %8" PRIu64
11554 " %4zu %4zu %8s",
11555 peer->as,
11556 peer->change_local_as
11557 ? peer->change_local_as
11558 : peer->local_as,
11559 PEER_TOTAL_RX(peer),
11560 PEER_TOTAL_TX(peer),
11561 peer->version[afi][safi],
11562 inq_count, outq_count,
11563 peer_uptime(peer->uptime,
11564 timebuf,
11565 BGP_UPTIME_LEN, 0,
11566 NULL));
11567 else
11568 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11569 " %4zu %4zu %8s",
11570 peer->as, PEER_TOTAL_RX(peer),
11571 PEER_TOTAL_TX(peer),
11572 peer->version[afi][safi],
11573 inq_count, outq_count,
11574 peer_uptime(peer->uptime,
11575 timebuf,
11576 BGP_UPTIME_LEN, 0,
11577 NULL));
11578
11579 if (peer_established(peer)) {
11580 if (peer->afc_recv[afi][safi]) {
11581 if (CHECK_FLAG(
11582 bgp->flags,
11583 BGP_FLAG_EBGP_REQUIRES_POLICY)
11584 && !bgp_inbound_policy_exists(
11585 peer, filter))
11586 vty_out(vty, " %12s",
11587 "(Policy)");
11588 else
11589 vty_out(vty,
11590 " %12u",
11591 peer->pcount
11592 [afi]
11593 [pfx_rcd_safi]);
11594 } else {
11595 vty_out(vty, " NoNeg");
11596 }
11597
11598 if (paf && PAF_SUBGRP(paf)) {
11599 if (CHECK_FLAG(
11600 bgp->flags,
11601 BGP_FLAG_EBGP_REQUIRES_POLICY)
11602 && !bgp_outbound_policy_exists(
11603 peer, filter))
11604 vty_out(vty, " %8s",
11605 "(Policy)");
11606 else
11607 vty_out(vty,
11608 " %8u",
11609 (PAF_SUBGRP(
11610 paf))
11611 ->scount);
11612 } else {
11613 vty_out(vty, " NoNeg");
11614 }
11615 } else {
11616 if (CHECK_FLAG(peer->flags,
11617 PEER_FLAG_SHUTDOWN)
11618 || CHECK_FLAG(peer->bgp->flags,
11619 BGP_FLAG_SHUTDOWN))
11620 vty_out(vty, " Idle (Admin)");
11621 else if (CHECK_FLAG(
11622 peer->sflags,
11623 PEER_STATUS_PREFIX_OVERFLOW))
11624 vty_out(vty, " Idle (PfxCt)");
11625 else
11626 vty_out(vty, " %12s",
11627 lookup_msg(bgp_status_msg,
11628 peer->status, NULL));
11629
11630 vty_out(vty, " %8u", 0);
11631 }
11632 /* Make sure `Desc` column is the lastest in
11633 * the output.
11634 */
11635 if (peer->desc)
11636 vty_out(vty, " %s",
11637 bgp_peer_description_stripped(
11638 peer->desc,
11639 show_wide ? 64 : 20));
11640 else
11641 vty_out(vty, " N/A");
11642 vty_out(vty, "\n");
11643 }
11644
11645 }
11646 }
11647
11648 if (use_json) {
11649 json_object_object_add(json, "peers", json_peers);
11650 json_object_int_add(json, "failedPeers", failed_count);
11651 json_object_int_add(json, "displayedPeers",
11652 count - filtered_count);
11653 json_object_int_add(json, "totalPeers", count);
11654 json_object_int_add(json, "dynamicPeers", dn_count);
11655
11656 if (!show_failed)
11657 bgp_show_bestpath_json(bgp, json);
11658
11659 vty_json(vty, json);
11660 } else {
11661 if (count) {
11662 if (filtered_count == count)
11663 vty_out(vty, "\n%% No matching neighbor\n");
11664 else {
11665 if (show_failed)
11666 vty_out(vty, "\nDisplayed neighbors %d",
11667 failed_count);
11668 else if (as_type != AS_UNSPECIFIED || as
11669 || fpeer || show_established)
11670 vty_out(vty, "\nDisplayed neighbors %d",
11671 count - filtered_count);
11672
11673 vty_out(vty, "\nTotal number of neighbors %d\n",
11674 count);
11675 }
11676 } else {
11677 vty_out(vty, "No %s neighbor is configured\n",
11678 get_afi_safi_str(afi, safi, false));
11679 }
11680
11681 if (dn_count) {
11682 vty_out(vty, "* - dynamic neighbor\n");
11683 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11684 dn_count, bgp->dynamic_neighbors_limit);
11685 }
11686 }
11687
11688 return CMD_SUCCESS;
11689 }
11690
11691 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11692 int safi, struct peer *fpeer, int as_type,
11693 as_t as, uint16_t show_flags)
11694 {
11695 int is_first = 1;
11696 int afi_wildcard = (afi == AFI_MAX);
11697 int safi_wildcard = (safi == SAFI_MAX);
11698 int is_wildcard = (afi_wildcard || safi_wildcard);
11699 bool nbr_output = false;
11700 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11701
11702 if (use_json && is_wildcard)
11703 vty_out(vty, "{\n");
11704 if (afi_wildcard)
11705 afi = 1; /* AFI_IP */
11706 while (afi < AFI_MAX) {
11707 if (safi_wildcard)
11708 safi = 1; /* SAFI_UNICAST */
11709 while (safi < SAFI_MAX) {
11710 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11711 nbr_output = true;
11712
11713 if (is_wildcard) {
11714 /*
11715 * So limit output to those afi/safi
11716 * pairs that
11717 * actualy have something interesting in
11718 * them
11719 */
11720 if (use_json) {
11721 if (!is_first)
11722 vty_out(vty, ",\n");
11723 else
11724 is_first = 0;
11725
11726 vty_out(vty, "\"%s\":",
11727 get_afi_safi_str(afi,
11728 safi,
11729 true));
11730 } else {
11731 vty_out(vty,
11732 "\n%s Summary (%s):\n",
11733 get_afi_safi_str(afi,
11734 safi,
11735 false),
11736 bgp->name_pretty);
11737 }
11738 }
11739 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11740 as_type, as, show_flags);
11741 }
11742 safi++;
11743 if (!safi_wildcard)
11744 safi = SAFI_MAX;
11745 }
11746 afi++;
11747 if (!afi_wildcard)
11748 afi = AFI_MAX;
11749 }
11750
11751 if (use_json && is_wildcard)
11752 vty_out(vty, "}\n");
11753 else if (!nbr_output) {
11754 if (use_json)
11755 vty_out(vty, "{}\n");
11756 else
11757 vty_out(vty, "%% No BGP neighbors found in %s\n",
11758 bgp->name_pretty);
11759 }
11760 }
11761
11762 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11763 safi_t safi,
11764 const char *neighbor,
11765 int as_type, as_t as,
11766 uint16_t show_flags)
11767 {
11768 struct listnode *node, *nnode;
11769 struct bgp *bgp;
11770 struct peer *fpeer = NULL;
11771 int is_first = 1;
11772 bool nbr_output = false;
11773 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11774
11775 if (use_json)
11776 vty_out(vty, "{\n");
11777
11778 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11779 nbr_output = true;
11780 if (use_json) {
11781 if (!is_first)
11782 vty_out(vty, ",\n");
11783 else
11784 is_first = 0;
11785
11786 vty_out(vty, "\"%s\":",
11787 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11788 ? VRF_DEFAULT_NAME
11789 : bgp->name);
11790 }
11791 if (neighbor) {
11792 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11793 use_json);
11794 if (!fpeer)
11795 continue;
11796 }
11797 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11798 as, show_flags);
11799 }
11800
11801 if (use_json)
11802 vty_out(vty, "}\n");
11803 else if (!nbr_output)
11804 vty_out(vty, "%% BGP instance not found\n");
11805 }
11806
11807 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11808 safi_t safi, const char *neighbor, int as_type,
11809 as_t as, uint16_t show_flags)
11810 {
11811 struct bgp *bgp;
11812 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11813 struct peer *fpeer = NULL;
11814
11815 if (name) {
11816 if (strmatch(name, "all")) {
11817 bgp_show_all_instances_summary_vty(vty, afi, safi,
11818 neighbor, as_type,
11819 as, show_flags);
11820 return CMD_SUCCESS;
11821 } else {
11822 bgp = bgp_lookup_by_name(name);
11823
11824 if (!bgp) {
11825 if (use_json)
11826 vty_out(vty, "{}\n");
11827 else
11828 vty_out(vty,
11829 "%% BGP instance not found\n");
11830 return CMD_WARNING;
11831 }
11832
11833 if (neighbor) {
11834 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11835 use_json);
11836 if (!fpeer)
11837 return CMD_WARNING;
11838 }
11839 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11840 as_type, as, show_flags);
11841 return CMD_SUCCESS;
11842 }
11843 }
11844
11845 bgp = bgp_get_default();
11846
11847 if (bgp) {
11848 if (neighbor) {
11849 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11850 use_json);
11851 if (!fpeer)
11852 return CMD_WARNING;
11853 }
11854 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11855 as, show_flags);
11856 } else {
11857 if (use_json)
11858 vty_out(vty, "{}\n");
11859 else
11860 vty_out(vty, "%% BGP instance not found\n");
11861 return CMD_WARNING;
11862 }
11863
11864 return CMD_SUCCESS;
11865 }
11866
11867 /* `show [ip] bgp summary' commands. */
11868 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11869 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11870 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11871 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <ASNUM|internal|external>>] [terse] [wide] [json$uj]",
11872 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11873 BGP_SAFI_WITH_LABEL_HELP_STR
11874 "Display the entries for all address families\n"
11875 "Summary of BGP neighbor status\n"
11876 "Show only sessions in Established state\n"
11877 "Show only sessions not in Established state\n"
11878 "Show only the specified neighbor session\n"
11879 "Neighbor to display information about\n"
11880 "Neighbor to display information about\n"
11881 "Neighbor on BGP configured interface\n"
11882 "Show only the specified remote AS sessions\n" AS_STR
11883 "Internal (iBGP) AS sessions\n"
11884 "External (eBGP) AS sessions\n"
11885 "Shorten the information on BGP instances\n"
11886 "Increase table width for longer output\n" JSON_STR)
11887 {
11888 char *vrf = NULL;
11889 afi_t afi = AFI_MAX;
11890 safi_t safi = SAFI_MAX;
11891 as_t as = 0; /* 0 means AS filter not set */
11892 int as_type = AS_UNSPECIFIED;
11893 uint16_t show_flags = 0;
11894
11895 int idx = 0;
11896
11897 /* show [ip] bgp */
11898 if (!all && argv_find(argv, argc, "ip", &idx))
11899 afi = AFI_IP;
11900 /* [<vrf> VIEWVRFNAME] */
11901 if (argv_find(argv, argc, "vrf", &idx)) {
11902 vrf = argv[idx + 1]->arg;
11903 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11904 vrf = NULL;
11905 } else if (argv_find(argv, argc, "view", &idx))
11906 /* [<view> VIEWVRFNAME] */
11907 vrf = argv[idx + 1]->arg;
11908 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11909 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11910 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11911 }
11912
11913 if (argv_find(argv, argc, "failed", &idx))
11914 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11915
11916 if (argv_find(argv, argc, "established", &idx))
11917 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11918
11919 if (argv_find(argv, argc, "remote-as", &idx)) {
11920 if (argv[idx + 1]->arg[0] == 'i')
11921 as_type = AS_INTERNAL;
11922 else if (argv[idx + 1]->arg[0] == 'e')
11923 as_type = AS_EXTERNAL;
11924 else if (!asn_str2asn(argv[idx + 1]->arg, &as)) {
11925 vty_out(vty,
11926 "%% Invalid neighbor remote-as value: %s\n",
11927 argv[idx + 1]->arg);
11928 return CMD_SUCCESS;
11929 }
11930 }
11931
11932 if (argv_find(argv, argc, "terse", &idx))
11933 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11934
11935 if (argv_find(argv, argc, "wide", &idx))
11936 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11937
11938 if (argv_find(argv, argc, "json", &idx))
11939 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11940
11941 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11942 show_flags);
11943 }
11944
11945 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11946 {
11947 if (for_json)
11948 return get_afi_safi_json_str(afi, safi);
11949 else
11950 return get_afi_safi_vty_str(afi, safi);
11951 }
11952
11953
11954 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11955 afi_t afi, safi_t safi,
11956 uint16_t adv_smcap, uint16_t adv_rmcap,
11957 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11958 bool use_json, json_object *json_pref)
11959 {
11960 /* Send-Mode */
11961 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11962 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11963 if (use_json) {
11964 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11965 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11966 json_object_string_add(json_pref, "sendMode",
11967 "advertisedAndReceived");
11968 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11969 json_object_string_add(json_pref, "sendMode",
11970 "advertised");
11971 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11972 json_object_string_add(json_pref, "sendMode",
11973 "received");
11974 } else {
11975 vty_out(vty, " Send-mode: ");
11976 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11977 vty_out(vty, "advertised");
11978 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11979 vty_out(vty, "%sreceived",
11980 CHECK_FLAG(p->af_cap[afi][safi],
11981 adv_smcap)
11982 ? ", "
11983 : "");
11984 vty_out(vty, "\n");
11985 }
11986 }
11987
11988 /* Receive-Mode */
11989 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11990 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11991 if (use_json) {
11992 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11993 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11994 json_object_string_add(json_pref, "recvMode",
11995 "advertisedAndReceived");
11996 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11997 json_object_string_add(json_pref, "recvMode",
11998 "advertised");
11999 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12000 json_object_string_add(json_pref, "recvMode",
12001 "received");
12002 } else {
12003 vty_out(vty, " Receive-mode: ");
12004 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12005 vty_out(vty, "advertised");
12006 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12007 vty_out(vty, "%sreceived",
12008 CHECK_FLAG(p->af_cap[afi][safi],
12009 adv_rmcap)
12010 ? ", "
12011 : "");
12012 vty_out(vty, "\n");
12013 }
12014 }
12015 }
12016
12017 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12018 struct peer *p,
12019 json_object *json)
12020 {
12021 bool rbit = false;
12022 bool nbit = false;
12023
12024 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12025 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
12026 && (peer_established(p))) {
12027 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12028 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
12029 }
12030
12031 if (json) {
12032 json_object_boolean_add(json, "rBit", rbit);
12033 json_object_boolean_add(json, "nBit", nbit);
12034 } else {
12035 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12036 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
12037 }
12038 }
12039
12040 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12041 struct peer *peer,
12042 json_object *json)
12043 {
12044 const char *mode = "NotApplicable";
12045
12046 if (!json)
12047 vty_out(vty, "\n Remote GR Mode: ");
12048
12049 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12050 && (peer_established(peer))) {
12051
12052 if ((peer->nsf_af_count == 0)
12053 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12054
12055 mode = "Disable";
12056
12057 } else if (peer->nsf_af_count == 0
12058 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12059
12060 mode = "Helper";
12061
12062 } else if (peer->nsf_af_count != 0
12063 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12064
12065 mode = "Restart";
12066 }
12067 }
12068
12069 if (json)
12070 json_object_string_add(json, "remoteGrMode", mode);
12071 else
12072 vty_out(vty, "%s\n", mode);
12073 }
12074
12075 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12076 struct peer *p,
12077 json_object *json)
12078 {
12079 const char *mode = "Invalid";
12080
12081 if (!json)
12082 vty_out(vty, " Local GR Mode: ");
12083
12084 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12085 mode = "Helper";
12086 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12087 mode = "Restart";
12088 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12089 mode = "Disable";
12090 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12091 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12092 mode = "Helper*";
12093 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12094 mode = "Restart*";
12095 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12096 mode = "Disable*";
12097 else
12098 mode = "Invalid*";
12099 }
12100
12101 if (json)
12102 json_object_string_add(json, "localGrMode", mode);
12103 else
12104 vty_out(vty, "%s\n", mode);
12105 }
12106
12107 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12108 struct vty *vty, struct peer *peer, json_object *json)
12109 {
12110 afi_t afi;
12111 safi_t safi;
12112 json_object *json_afi_safi = NULL;
12113 json_object *json_timer = NULL;
12114 json_object *json_endofrib_status = NULL;
12115 bool eor_flag = false;
12116
12117 FOREACH_AFI_SAFI_NSF (afi, safi) {
12118 if (!peer->afc[afi][safi])
12119 continue;
12120
12121 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12122 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12123 continue;
12124
12125 if (json) {
12126 json_afi_safi = json_object_new_object();
12127 json_endofrib_status = json_object_new_object();
12128 json_timer = json_object_new_object();
12129 }
12130
12131 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12132 eor_flag = true;
12133 else
12134 eor_flag = false;
12135
12136 if (!json) {
12137 vty_out(vty, " %s:\n",
12138 get_afi_safi_str(afi, safi, false));
12139
12140 vty_out(vty, " F bit: ");
12141 }
12142
12143 if (peer->nsf[afi][safi] &&
12144 CHECK_FLAG(peer->af_cap[afi][safi],
12145 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12146
12147 if (json) {
12148 json_object_boolean_true_add(json_afi_safi,
12149 "fBit");
12150 } else
12151 vty_out(vty, "True\n");
12152 } else {
12153 if (json)
12154 json_object_boolean_false_add(json_afi_safi,
12155 "fBit");
12156 else
12157 vty_out(vty, "False\n");
12158 }
12159
12160 if (!json)
12161 vty_out(vty, " End-of-RIB sent: ");
12162
12163 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12164 PEER_STATUS_EOR_SEND)) {
12165 if (json) {
12166 json_object_boolean_true_add(
12167 json_endofrib_status, "endOfRibSend");
12168
12169 PRINT_EOR_JSON(eor_flag);
12170 } else {
12171 vty_out(vty, "Yes\n");
12172 vty_out(vty,
12173 " End-of-RIB sent after update: ");
12174
12175 PRINT_EOR(eor_flag);
12176 }
12177 } else {
12178 if (json) {
12179 json_object_boolean_false_add(
12180 json_endofrib_status, "endOfRibSend");
12181 json_object_boolean_false_add(
12182 json_endofrib_status,
12183 "endOfRibSentAfterUpdate");
12184 } else {
12185 vty_out(vty, "No\n");
12186 vty_out(vty,
12187 " End-of-RIB sent after update: ");
12188 vty_out(vty, "No\n");
12189 }
12190 }
12191
12192 if (!json)
12193 vty_out(vty, " End-of-RIB received: ");
12194
12195 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12196 PEER_STATUS_EOR_RECEIVED)) {
12197 if (json)
12198 json_object_boolean_true_add(
12199 json_endofrib_status, "endOfRibRecv");
12200 else
12201 vty_out(vty, "Yes\n");
12202 } else {
12203 if (json)
12204 json_object_boolean_false_add(
12205 json_endofrib_status, "endOfRibRecv");
12206 else
12207 vty_out(vty, "No\n");
12208 }
12209
12210 if (json) {
12211 json_object_int_add(json_timer, "stalePathTimer",
12212 peer->bgp->stalepath_time);
12213
12214 if (peer->t_gr_stale != NULL) {
12215 json_object_int_add(json_timer,
12216 "stalePathTimerRemaining",
12217 thread_timer_remain_second(
12218 peer->t_gr_stale));
12219 }
12220
12221 /* Display Configured Selection
12222 * Deferral only when when
12223 * Gr mode is enabled.
12224 */
12225 if (CHECK_FLAG(peer->flags,
12226 PEER_FLAG_GRACEFUL_RESTART)) {
12227 json_object_int_add(json_timer,
12228 "selectionDeferralTimer",
12229 peer->bgp->stalepath_time);
12230 }
12231
12232 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12233 NULL) {
12234
12235 json_object_int_add(
12236 json_timer,
12237 "selectionDeferralTimerRemaining",
12238 thread_timer_remain_second(
12239 peer->bgp->gr_info[afi][safi]
12240 .t_select_deferral));
12241 }
12242 } else {
12243 vty_out(vty, " Timers:\n");
12244 vty_out(vty,
12245 " Configured Stale Path Time(sec): %u\n",
12246 peer->bgp->stalepath_time);
12247
12248 if (peer->t_gr_stale != NULL)
12249 vty_out(vty,
12250 " Stale Path Remaining(sec): %ld\n",
12251 thread_timer_remain_second(
12252 peer->t_gr_stale));
12253 /* Display Configured Selection
12254 * Deferral only when when
12255 * Gr mode is enabled.
12256 */
12257 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12258 vty_out(vty,
12259 " Configured Selection Deferral Time(sec): %u\n",
12260 peer->bgp->select_defer_time);
12261
12262 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12263 NULL)
12264 vty_out(vty,
12265 " Selection Deferral Time Remaining(sec): %ld\n",
12266 thread_timer_remain_second(
12267 peer->bgp->gr_info[afi][safi]
12268 .t_select_deferral));
12269 }
12270 if (json) {
12271 json_object_object_add(json_afi_safi, "endOfRibStatus",
12272 json_endofrib_status);
12273 json_object_object_add(json_afi_safi, "timers",
12274 json_timer);
12275 json_object_object_add(
12276 json, get_afi_safi_str(afi, safi, true),
12277 json_afi_safi);
12278 }
12279 }
12280 }
12281
12282 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12283 struct peer *p,
12284 json_object *json)
12285 {
12286 if (json) {
12287 json_object *json_timer = NULL;
12288
12289 json_timer = json_object_new_object();
12290
12291 json_object_int_add(json_timer, "configuredRestartTimer",
12292 p->bgp->restart_time);
12293
12294 json_object_int_add(json_timer, "receivedRestartTimer",
12295 p->v_gr_restart);
12296
12297 if (p->t_gr_restart != NULL)
12298 json_object_int_add(
12299 json_timer, "restartTimerRemaining",
12300 thread_timer_remain_second(p->t_gr_restart));
12301
12302 json_object_object_add(json, "timers", json_timer);
12303 } else {
12304
12305 vty_out(vty, " Timers:\n");
12306 vty_out(vty, " Configured Restart Time(sec): %u\n",
12307 p->bgp->restart_time);
12308
12309 vty_out(vty, " Received Restart Time(sec): %u\n",
12310 p->v_gr_restart);
12311 if (p->t_gr_restart != NULL)
12312 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12313 thread_timer_remain_second(p->t_gr_restart));
12314 if (p->t_gr_restart != NULL) {
12315 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12316 thread_timer_remain_second(p->t_gr_restart));
12317 }
12318 }
12319 }
12320
12321 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12322 json_object *json)
12323 {
12324 char dn_flag[2] = {0};
12325 /* '*' + v6 address of neighbor */
12326 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12327
12328 if (!p->conf_if && peer_dynamic_neighbor(p))
12329 dn_flag[0] = '*';
12330
12331 if (p->conf_if) {
12332 if (json)
12333 json_object_string_addf(json, "neighborAddr", "%pSU",
12334 &p->su);
12335 else
12336 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12337 &p->su);
12338 } else {
12339 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12340 p->host);
12341
12342 if (json)
12343 json_object_string_add(json, "neighborAddr",
12344 neighborAddr);
12345 else
12346 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12347 }
12348
12349 /* more gr info in new format */
12350 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12351 }
12352
12353 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12354 safi_t safi, bool use_json,
12355 json_object *json_neigh)
12356 {
12357 struct bgp_filter *filter;
12358 struct peer_af *paf;
12359 char orf_pfx_name[BUFSIZ];
12360 int orf_pfx_count;
12361 json_object *json_af = NULL;
12362 json_object *json_prefA = NULL;
12363 json_object *json_prefB = NULL;
12364 json_object *json_addr = NULL;
12365 json_object *json_advmap = NULL;
12366
12367 if (use_json) {
12368 json_addr = json_object_new_object();
12369 json_af = json_object_new_object();
12370 filter = &p->filter[afi][safi];
12371
12372 if (peer_group_active(p))
12373 json_object_string_add(json_addr, "peerGroupMember",
12374 p->group->name);
12375
12376 paf = peer_af_find(p, afi, safi);
12377 if (paf && PAF_SUBGRP(paf)) {
12378 json_object_int_add(json_addr, "updateGroupId",
12379 PAF_UPDGRP(paf)->id);
12380 json_object_int_add(json_addr, "subGroupId",
12381 PAF_SUBGRP(paf)->id);
12382 json_object_int_add(json_addr, "packetQueueLength",
12383 bpacket_queue_virtual_length(paf));
12384 }
12385
12386 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12387 || CHECK_FLAG(p->af_cap[afi][safi],
12388 PEER_CAP_ORF_PREFIX_SM_RCV)
12389 || CHECK_FLAG(p->af_cap[afi][safi],
12390 PEER_CAP_ORF_PREFIX_RM_ADV)
12391 || CHECK_FLAG(p->af_cap[afi][safi],
12392 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12393 json_object_int_add(json_af, "orfType",
12394 ORF_TYPE_PREFIX);
12395 json_prefA = json_object_new_object();
12396 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12397 PEER_CAP_ORF_PREFIX_SM_ADV,
12398 PEER_CAP_ORF_PREFIX_RM_ADV,
12399 PEER_CAP_ORF_PREFIX_SM_RCV,
12400 PEER_CAP_ORF_PREFIX_RM_RCV,
12401 use_json, json_prefA);
12402 json_object_object_add(json_af, "orfPrefixList",
12403 json_prefA);
12404 }
12405
12406 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12407 || CHECK_FLAG(p->af_cap[afi][safi],
12408 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12409 || CHECK_FLAG(p->af_cap[afi][safi],
12410 PEER_CAP_ORF_PREFIX_RM_ADV)
12411 || CHECK_FLAG(p->af_cap[afi][safi],
12412 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12413 json_object_int_add(json_af, "orfOldType",
12414 ORF_TYPE_PREFIX_OLD);
12415 json_prefB = json_object_new_object();
12416 bgp_show_peer_afi_orf_cap(
12417 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12418 PEER_CAP_ORF_PREFIX_RM_ADV,
12419 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12420 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12421 json_prefB);
12422 json_object_object_add(json_af, "orfOldPrefixList",
12423 json_prefB);
12424 }
12425
12426 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12427 || CHECK_FLAG(p->af_cap[afi][safi],
12428 PEER_CAP_ORF_PREFIX_SM_RCV)
12429 || CHECK_FLAG(p->af_cap[afi][safi],
12430 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12431 || CHECK_FLAG(p->af_cap[afi][safi],
12432 PEER_CAP_ORF_PREFIX_RM_ADV)
12433 || CHECK_FLAG(p->af_cap[afi][safi],
12434 PEER_CAP_ORF_PREFIX_RM_RCV)
12435 || CHECK_FLAG(p->af_cap[afi][safi],
12436 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12437 json_object_object_add(json_addr, "afDependentCap",
12438 json_af);
12439 else
12440 json_object_free(json_af);
12441
12442 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12443 p->host, afi, safi);
12444 orf_pfx_count = prefix_bgp_show_prefix_list(
12445 NULL, afi, orf_pfx_name, use_json);
12446
12447 if (CHECK_FLAG(p->af_sflags[afi][safi],
12448 PEER_STATUS_ORF_PREFIX_SEND)
12449 || orf_pfx_count) {
12450 if (CHECK_FLAG(p->af_sflags[afi][safi],
12451 PEER_STATUS_ORF_PREFIX_SEND))
12452 json_object_boolean_true_add(json_neigh,
12453 "orfSent");
12454 if (orf_pfx_count)
12455 json_object_int_add(json_addr, "orfRecvCounter",
12456 orf_pfx_count);
12457 }
12458 if (CHECK_FLAG(p->af_sflags[afi][safi],
12459 PEER_STATUS_ORF_WAIT_REFRESH))
12460 json_object_string_add(
12461 json_addr, "orfFirstUpdate",
12462 "deferredUntilORFOrRouteRefreshRecvd");
12463
12464 if (CHECK_FLAG(p->af_flags[afi][safi],
12465 PEER_FLAG_REFLECTOR_CLIENT))
12466 json_object_boolean_true_add(json_addr,
12467 "routeReflectorClient");
12468 if (CHECK_FLAG(p->af_flags[afi][safi],
12469 PEER_FLAG_RSERVER_CLIENT))
12470 json_object_boolean_true_add(json_addr,
12471 "routeServerClient");
12472 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12473 json_object_boolean_true_add(json_addr,
12474 "inboundSoftConfigPermit");
12475
12476 if (CHECK_FLAG(p->af_flags[afi][safi],
12477 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12478 json_object_boolean_true_add(
12479 json_addr,
12480 "privateAsNumsAllReplacedInUpdatesToNbr");
12481 else if (CHECK_FLAG(p->af_flags[afi][safi],
12482 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12483 json_object_boolean_true_add(
12484 json_addr,
12485 "privateAsNumsReplacedInUpdatesToNbr");
12486 else if (CHECK_FLAG(p->af_flags[afi][safi],
12487 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12488 json_object_boolean_true_add(
12489 json_addr,
12490 "privateAsNumsAllRemovedInUpdatesToNbr");
12491 else if (CHECK_FLAG(p->af_flags[afi][safi],
12492 PEER_FLAG_REMOVE_PRIVATE_AS))
12493 json_object_boolean_true_add(
12494 json_addr,
12495 "privateAsNumsRemovedInUpdatesToNbr");
12496
12497 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12498 if (CHECK_FLAG(p->af_flags[afi][safi],
12499 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12500 json_object_boolean_true_add(json_addr,
12501 "allowAsInOrigin");
12502 else
12503 json_object_int_add(json_addr, "allowAsInCount",
12504 p->allowas_in[afi][safi]);
12505 }
12506
12507 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12508 json_object_boolean_true_add(
12509 json_addr,
12510 bgp_addpath_names(p->addpath_type[afi][safi])
12511 ->type_json_name);
12512
12513 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12514 json_object_string_add(json_addr,
12515 "overrideASNsInOutboundUpdates",
12516 "ifAspathEqualRemoteAs");
12517
12518 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12519 || CHECK_FLAG(p->af_flags[afi][safi],
12520 PEER_FLAG_FORCE_NEXTHOP_SELF))
12521 json_object_boolean_true_add(json_addr,
12522 "routerAlwaysNextHop");
12523 if (CHECK_FLAG(p->af_flags[afi][safi],
12524 PEER_FLAG_AS_PATH_UNCHANGED))
12525 json_object_boolean_true_add(
12526 json_addr, "unchangedAsPathPropogatedToNbr");
12527 if (CHECK_FLAG(p->af_flags[afi][safi],
12528 PEER_FLAG_NEXTHOP_UNCHANGED))
12529 json_object_boolean_true_add(
12530 json_addr, "unchangedNextHopPropogatedToNbr");
12531 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12532 json_object_boolean_true_add(
12533 json_addr, "unchangedMedPropogatedToNbr");
12534 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12535 || CHECK_FLAG(p->af_flags[afi][safi],
12536 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12537 if (CHECK_FLAG(p->af_flags[afi][safi],
12538 PEER_FLAG_SEND_COMMUNITY)
12539 && CHECK_FLAG(p->af_flags[afi][safi],
12540 PEER_FLAG_SEND_EXT_COMMUNITY))
12541 json_object_string_add(json_addr,
12542 "commAttriSentToNbr",
12543 "extendedAndStandard");
12544 else if (CHECK_FLAG(p->af_flags[afi][safi],
12545 PEER_FLAG_SEND_EXT_COMMUNITY))
12546 json_object_string_add(json_addr,
12547 "commAttriSentToNbr",
12548 "extended");
12549 else
12550 json_object_string_add(json_addr,
12551 "commAttriSentToNbr",
12552 "standard");
12553 }
12554 if (CHECK_FLAG(p->af_flags[afi][safi],
12555 PEER_FLAG_DEFAULT_ORIGINATE)) {
12556 if (p->default_rmap[afi][safi].name)
12557 json_object_string_add(
12558 json_addr, "defaultRouteMap",
12559 p->default_rmap[afi][safi].name);
12560
12561 if (paf && PAF_SUBGRP(paf)
12562 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12563 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12564 json_object_boolean_true_add(json_addr,
12565 "defaultSent");
12566 else
12567 json_object_boolean_true_add(json_addr,
12568 "defaultNotSent");
12569 }
12570
12571 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12572 if (is_evpn_enabled())
12573 json_object_boolean_true_add(
12574 json_addr, "advertiseAllVnis");
12575 }
12576
12577 if (filter->plist[FILTER_IN].name
12578 || filter->dlist[FILTER_IN].name
12579 || filter->aslist[FILTER_IN].name
12580 || filter->map[RMAP_IN].name)
12581 json_object_boolean_true_add(json_addr,
12582 "inboundPathPolicyConfig");
12583 if (filter->plist[FILTER_OUT].name
12584 || filter->dlist[FILTER_OUT].name
12585 || filter->aslist[FILTER_OUT].name
12586 || filter->map[RMAP_OUT].name || filter->usmap.name)
12587 json_object_boolean_true_add(
12588 json_addr, "outboundPathPolicyConfig");
12589
12590 /* prefix-list */
12591 if (filter->plist[FILTER_IN].name)
12592 json_object_string_add(json_addr,
12593 "incomingUpdatePrefixFilterList",
12594 filter->plist[FILTER_IN].name);
12595 if (filter->plist[FILTER_OUT].name)
12596 json_object_string_add(json_addr,
12597 "outgoingUpdatePrefixFilterList",
12598 filter->plist[FILTER_OUT].name);
12599
12600 /* distribute-list */
12601 if (filter->dlist[FILTER_IN].name)
12602 json_object_string_add(
12603 json_addr, "incomingUpdateNetworkFilterList",
12604 filter->dlist[FILTER_IN].name);
12605 if (filter->dlist[FILTER_OUT].name)
12606 json_object_string_add(
12607 json_addr, "outgoingUpdateNetworkFilterList",
12608 filter->dlist[FILTER_OUT].name);
12609
12610 /* filter-list. */
12611 if (filter->aslist[FILTER_IN].name)
12612 json_object_string_add(json_addr,
12613 "incomingUpdateAsPathFilterList",
12614 filter->aslist[FILTER_IN].name);
12615 if (filter->aslist[FILTER_OUT].name)
12616 json_object_string_add(json_addr,
12617 "outgoingUpdateAsPathFilterList",
12618 filter->aslist[FILTER_OUT].name);
12619
12620 /* route-map. */
12621 if (filter->map[RMAP_IN].name)
12622 json_object_string_add(
12623 json_addr, "routeMapForIncomingAdvertisements",
12624 filter->map[RMAP_IN].name);
12625 if (filter->map[RMAP_OUT].name)
12626 json_object_string_add(
12627 json_addr, "routeMapForOutgoingAdvertisements",
12628 filter->map[RMAP_OUT].name);
12629
12630 /* ebgp-requires-policy (inbound) */
12631 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12632 && !bgp_inbound_policy_exists(p, filter))
12633 json_object_string_add(
12634 json_addr, "inboundEbgpRequiresPolicy",
12635 "Inbound updates discarded due to missing policy");
12636
12637 /* ebgp-requires-policy (outbound) */
12638 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12639 && (!bgp_outbound_policy_exists(p, filter)))
12640 json_object_string_add(
12641 json_addr, "outboundEbgpRequiresPolicy",
12642 "Outbound updates discarded due to missing policy");
12643
12644 /* unsuppress-map */
12645 if (filter->usmap.name)
12646 json_object_string_add(json_addr,
12647 "selectiveUnsuppressRouteMap",
12648 filter->usmap.name);
12649
12650 /* advertise-map */
12651 if (filter->advmap.aname) {
12652 json_advmap = json_object_new_object();
12653 json_object_string_add(json_advmap, "condition",
12654 filter->advmap.condition
12655 ? "EXIST"
12656 : "NON_EXIST");
12657 json_object_string_add(json_advmap, "conditionMap",
12658 filter->advmap.cname);
12659 json_object_string_add(json_advmap, "advertiseMap",
12660 filter->advmap.aname);
12661 json_object_string_add(
12662 json_advmap, "advertiseStatus",
12663 filter->advmap.update_type ==
12664 UPDATE_TYPE_ADVERTISE
12665 ? "Advertise"
12666 : "Withdraw");
12667 json_object_object_add(json_addr, "advertiseMap",
12668 json_advmap);
12669 }
12670
12671 /* Receive prefix count */
12672 json_object_int_add(json_addr, "acceptedPrefixCounter",
12673 p->pcount[afi][safi]);
12674 if (paf && PAF_SUBGRP(paf))
12675 json_object_int_add(json_addr, "sentPrefixCounter",
12676 (PAF_SUBGRP(paf))->scount);
12677
12678 /* Maximum prefix */
12679 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12680 json_object_int_add(json_addr, "prefixOutAllowedMax",
12681 p->pmax_out[afi][safi]);
12682
12683 /* Maximum prefix */
12684 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12685 json_object_int_add(json_addr, "prefixAllowedMax",
12686 p->pmax[afi][safi]);
12687 if (CHECK_FLAG(p->af_flags[afi][safi],
12688 PEER_FLAG_MAX_PREFIX_WARNING))
12689 json_object_boolean_true_add(
12690 json_addr, "prefixAllowedMaxWarning");
12691 json_object_int_add(json_addr,
12692 "prefixAllowedWarningThresh",
12693 p->pmax_threshold[afi][safi]);
12694 if (p->pmax_restart[afi][safi])
12695 json_object_int_add(
12696 json_addr,
12697 "prefixAllowedRestartIntervalMsecs",
12698 p->pmax_restart[afi][safi] * 60000);
12699 }
12700 json_object_object_add(json_neigh,
12701 get_afi_safi_str(afi, safi, true),
12702 json_addr);
12703
12704 } else {
12705 filter = &p->filter[afi][safi];
12706
12707 vty_out(vty, " For address family: %s\n",
12708 get_afi_safi_str(afi, safi, false));
12709
12710 if (peer_group_active(p))
12711 vty_out(vty, " %s peer-group member\n",
12712 p->group->name);
12713
12714 paf = peer_af_find(p, afi, safi);
12715 if (paf && PAF_SUBGRP(paf)) {
12716 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12717 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12718 vty_out(vty, " Packet Queue length %d\n",
12719 bpacket_queue_virtual_length(paf));
12720 } else {
12721 vty_out(vty, " Not part of any update group\n");
12722 }
12723 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12724 || CHECK_FLAG(p->af_cap[afi][safi],
12725 PEER_CAP_ORF_PREFIX_SM_RCV)
12726 || CHECK_FLAG(p->af_cap[afi][safi],
12727 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12728 || CHECK_FLAG(p->af_cap[afi][safi],
12729 PEER_CAP_ORF_PREFIX_RM_ADV)
12730 || CHECK_FLAG(p->af_cap[afi][safi],
12731 PEER_CAP_ORF_PREFIX_RM_RCV)
12732 || CHECK_FLAG(p->af_cap[afi][safi],
12733 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12734 vty_out(vty, " AF-dependant capabilities:\n");
12735
12736 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12737 || CHECK_FLAG(p->af_cap[afi][safi],
12738 PEER_CAP_ORF_PREFIX_SM_RCV)
12739 || CHECK_FLAG(p->af_cap[afi][safi],
12740 PEER_CAP_ORF_PREFIX_RM_ADV)
12741 || CHECK_FLAG(p->af_cap[afi][safi],
12742 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12743 vty_out(vty,
12744 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12745 ORF_TYPE_PREFIX);
12746 bgp_show_peer_afi_orf_cap(
12747 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12748 PEER_CAP_ORF_PREFIX_RM_ADV,
12749 PEER_CAP_ORF_PREFIX_SM_RCV,
12750 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12751 }
12752 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12753 || CHECK_FLAG(p->af_cap[afi][safi],
12754 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12755 || CHECK_FLAG(p->af_cap[afi][safi],
12756 PEER_CAP_ORF_PREFIX_RM_ADV)
12757 || CHECK_FLAG(p->af_cap[afi][safi],
12758 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12759 vty_out(vty,
12760 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12761 ORF_TYPE_PREFIX_OLD);
12762 bgp_show_peer_afi_orf_cap(
12763 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12764 PEER_CAP_ORF_PREFIX_RM_ADV,
12765 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12766 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12767 }
12768
12769 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12770 p->host, afi, safi);
12771 orf_pfx_count = prefix_bgp_show_prefix_list(
12772 NULL, afi, orf_pfx_name, use_json);
12773
12774 if (CHECK_FLAG(p->af_sflags[afi][safi],
12775 PEER_STATUS_ORF_PREFIX_SEND)
12776 || orf_pfx_count) {
12777 vty_out(vty, " Outbound Route Filter (ORF):");
12778 if (CHECK_FLAG(p->af_sflags[afi][safi],
12779 PEER_STATUS_ORF_PREFIX_SEND))
12780 vty_out(vty, " sent;");
12781 if (orf_pfx_count)
12782 vty_out(vty, " received (%d entries)",
12783 orf_pfx_count);
12784 vty_out(vty, "\n");
12785 }
12786 if (CHECK_FLAG(p->af_sflags[afi][safi],
12787 PEER_STATUS_ORF_WAIT_REFRESH))
12788 vty_out(vty,
12789 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12790
12791 if (CHECK_FLAG(p->af_flags[afi][safi],
12792 PEER_FLAG_REFLECTOR_CLIENT))
12793 vty_out(vty, " Route-Reflector Client\n");
12794 if (CHECK_FLAG(p->af_flags[afi][safi],
12795 PEER_FLAG_RSERVER_CLIENT))
12796 vty_out(vty, " Route-Server Client\n");
12797 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12798 vty_out(vty,
12799 " Inbound soft reconfiguration allowed\n");
12800
12801 if (CHECK_FLAG(p->af_flags[afi][safi],
12802 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12803 vty_out(vty,
12804 " Private AS numbers (all) replaced in updates to this neighbor\n");
12805 else if (CHECK_FLAG(p->af_flags[afi][safi],
12806 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12807 vty_out(vty,
12808 " Private AS numbers replaced in updates to this neighbor\n");
12809 else if (CHECK_FLAG(p->af_flags[afi][safi],
12810 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12811 vty_out(vty,
12812 " Private AS numbers (all) removed in updates to this neighbor\n");
12813 else if (CHECK_FLAG(p->af_flags[afi][safi],
12814 PEER_FLAG_REMOVE_PRIVATE_AS))
12815 vty_out(vty,
12816 " Private AS numbers removed in updates to this neighbor\n");
12817
12818 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12819 if (CHECK_FLAG(p->af_flags[afi][safi],
12820 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12821 vty_out(vty,
12822 " Local AS allowed as path origin\n");
12823 else
12824 vty_out(vty,
12825 " Local AS allowed in path, %d occurrences\n",
12826 p->allowas_in[afi][safi]);
12827 }
12828
12829 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12830 vty_out(vty, " %s\n",
12831 bgp_addpath_names(p->addpath_type[afi][safi])
12832 ->human_description);
12833
12834 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12835 vty_out(vty,
12836 " Override ASNs in outbound updates if aspath equals remote-as\n");
12837
12838 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12839 || CHECK_FLAG(p->af_flags[afi][safi],
12840 PEER_FLAG_FORCE_NEXTHOP_SELF))
12841 vty_out(vty, " NEXT_HOP is always this router\n");
12842 if (CHECK_FLAG(p->af_flags[afi][safi],
12843 PEER_FLAG_AS_PATH_UNCHANGED))
12844 vty_out(vty,
12845 " AS_PATH is propagated unchanged to this neighbor\n");
12846 if (CHECK_FLAG(p->af_flags[afi][safi],
12847 PEER_FLAG_NEXTHOP_UNCHANGED))
12848 vty_out(vty,
12849 " NEXT_HOP is propagated unchanged to this neighbor\n");
12850 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12851 vty_out(vty,
12852 " MED is propagated unchanged to this neighbor\n");
12853 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12854 || CHECK_FLAG(p->af_flags[afi][safi],
12855 PEER_FLAG_SEND_EXT_COMMUNITY)
12856 || CHECK_FLAG(p->af_flags[afi][safi],
12857 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12858 vty_out(vty,
12859 " Community attribute sent to this neighbor");
12860 if (CHECK_FLAG(p->af_flags[afi][safi],
12861 PEER_FLAG_SEND_COMMUNITY)
12862 && CHECK_FLAG(p->af_flags[afi][safi],
12863 PEER_FLAG_SEND_EXT_COMMUNITY)
12864 && CHECK_FLAG(p->af_flags[afi][safi],
12865 PEER_FLAG_SEND_LARGE_COMMUNITY))
12866 vty_out(vty, "(all)\n");
12867 else if (CHECK_FLAG(p->af_flags[afi][safi],
12868 PEER_FLAG_SEND_LARGE_COMMUNITY))
12869 vty_out(vty, "(large)\n");
12870 else if (CHECK_FLAG(p->af_flags[afi][safi],
12871 PEER_FLAG_SEND_EXT_COMMUNITY))
12872 vty_out(vty, "(extended)\n");
12873 else
12874 vty_out(vty, "(standard)\n");
12875 }
12876 if (CHECK_FLAG(p->af_flags[afi][safi],
12877 PEER_FLAG_DEFAULT_ORIGINATE)) {
12878 vty_out(vty, " Default information originate,");
12879
12880 if (p->default_rmap[afi][safi].name)
12881 vty_out(vty, " default route-map %s%s,",
12882 p->default_rmap[afi][safi].map ? "*"
12883 : "",
12884 p->default_rmap[afi][safi].name);
12885 if (paf && PAF_SUBGRP(paf)
12886 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12887 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12888 vty_out(vty, " default sent\n");
12889 else
12890 vty_out(vty, " default not sent\n");
12891 }
12892
12893 /* advertise-vni-all */
12894 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12895 if (is_evpn_enabled())
12896 vty_out(vty, " advertise-all-vni\n");
12897 }
12898
12899 if (filter->plist[FILTER_IN].name
12900 || filter->dlist[FILTER_IN].name
12901 || filter->aslist[FILTER_IN].name
12902 || filter->map[RMAP_IN].name)
12903 vty_out(vty, " Inbound path policy configured\n");
12904 if (filter->plist[FILTER_OUT].name
12905 || filter->dlist[FILTER_OUT].name
12906 || filter->aslist[FILTER_OUT].name
12907 || filter->map[RMAP_OUT].name || filter->usmap.name)
12908 vty_out(vty, " Outbound path policy configured\n");
12909
12910 /* prefix-list */
12911 if (filter->plist[FILTER_IN].name)
12912 vty_out(vty,
12913 " Incoming update prefix filter list is %s%s\n",
12914 filter->plist[FILTER_IN].plist ? "*" : "",
12915 filter->plist[FILTER_IN].name);
12916 if (filter->plist[FILTER_OUT].name)
12917 vty_out(vty,
12918 " Outgoing update prefix filter list is %s%s\n",
12919 filter->plist[FILTER_OUT].plist ? "*" : "",
12920 filter->plist[FILTER_OUT].name);
12921
12922 /* distribute-list */
12923 if (filter->dlist[FILTER_IN].name)
12924 vty_out(vty,
12925 " Incoming update network filter list is %s%s\n",
12926 filter->dlist[FILTER_IN].alist ? "*" : "",
12927 filter->dlist[FILTER_IN].name);
12928 if (filter->dlist[FILTER_OUT].name)
12929 vty_out(vty,
12930 " Outgoing update network filter list is %s%s\n",
12931 filter->dlist[FILTER_OUT].alist ? "*" : "",
12932 filter->dlist[FILTER_OUT].name);
12933
12934 /* filter-list. */
12935 if (filter->aslist[FILTER_IN].name)
12936 vty_out(vty,
12937 " Incoming update AS path filter list is %s%s\n",
12938 filter->aslist[FILTER_IN].aslist ? "*" : "",
12939 filter->aslist[FILTER_IN].name);
12940 if (filter->aslist[FILTER_OUT].name)
12941 vty_out(vty,
12942 " Outgoing update AS path filter list is %s%s\n",
12943 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12944 filter->aslist[FILTER_OUT].name);
12945
12946 /* route-map. */
12947 if (filter->map[RMAP_IN].name)
12948 vty_out(vty,
12949 " Route map for incoming advertisements is %s%s\n",
12950 filter->map[RMAP_IN].map ? "*" : "",
12951 filter->map[RMAP_IN].name);
12952 if (filter->map[RMAP_OUT].name)
12953 vty_out(vty,
12954 " Route map for outgoing advertisements is %s%s\n",
12955 filter->map[RMAP_OUT].map ? "*" : "",
12956 filter->map[RMAP_OUT].name);
12957
12958 /* ebgp-requires-policy (inbound) */
12959 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12960 && !bgp_inbound_policy_exists(p, filter))
12961 vty_out(vty,
12962 " Inbound updates discarded due to missing policy\n");
12963
12964 /* ebgp-requires-policy (outbound) */
12965 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12966 && !bgp_outbound_policy_exists(p, filter))
12967 vty_out(vty,
12968 " Outbound updates discarded due to missing policy\n");
12969
12970 /* unsuppress-map */
12971 if (filter->usmap.name)
12972 vty_out(vty,
12973 " Route map for selective unsuppress is %s%s\n",
12974 filter->usmap.map ? "*" : "",
12975 filter->usmap.name);
12976
12977 /* advertise-map */
12978 if (filter->advmap.aname && filter->advmap.cname)
12979 vty_out(vty,
12980 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12981 filter->advmap.condition ? "EXIST"
12982 : "NON_EXIST",
12983 filter->advmap.cmap ? "*" : "",
12984 filter->advmap.cname,
12985 filter->advmap.amap ? "*" : "",
12986 filter->advmap.aname,
12987 filter->advmap.update_type ==
12988 UPDATE_TYPE_ADVERTISE
12989 ? "Advertise"
12990 : "Withdraw");
12991
12992 /* Receive prefix count */
12993 vty_out(vty, " %u accepted prefixes\n",
12994 p->pcount[afi][safi]);
12995
12996 /* maximum-prefix-out */
12997 if (CHECK_FLAG(p->af_flags[afi][safi],
12998 PEER_FLAG_MAX_PREFIX_OUT))
12999 vty_out(vty,
13000 " Maximum allowed prefixes sent %u\n",
13001 p->pmax_out[afi][safi]);
13002
13003 /* Maximum prefix */
13004 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
13005 vty_out(vty,
13006 " Maximum prefixes allowed %u%s\n",
13007 p->pmax[afi][safi],
13008 CHECK_FLAG(p->af_flags[afi][safi],
13009 PEER_FLAG_MAX_PREFIX_WARNING)
13010 ? " (warning-only)"
13011 : "");
13012 vty_out(vty, " Threshold for warning message %d%%",
13013 p->pmax_threshold[afi][safi]);
13014 if (p->pmax_restart[afi][safi])
13015 vty_out(vty, ", restart interval %d min",
13016 p->pmax_restart[afi][safi]);
13017 vty_out(vty, "\n");
13018 }
13019
13020 vty_out(vty, "\n");
13021 }
13022 }
13023
13024 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
13025 json_object *json)
13026 {
13027 struct bgp *bgp;
13028 char timebuf[BGP_UPTIME_LEN];
13029 char dn_flag[2];
13030 afi_t afi;
13031 safi_t safi;
13032 uint16_t i;
13033 uint8_t *msg;
13034 json_object *json_neigh = NULL;
13035 time_t epoch_tbuf;
13036 uint32_t sync_tcp_mss;
13037
13038 bgp = p->bgp;
13039
13040 if (use_json)
13041 json_neigh = json_object_new_object();
13042
13043 memset(dn_flag, '\0', sizeof(dn_flag));
13044 if (!p->conf_if && peer_dynamic_neighbor(p))
13045 dn_flag[0] = '*';
13046
13047 if (!use_json) {
13048 if (p->conf_if) /* Configured interface name. */
13049 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13050 &p->su);
13051 else /* Configured IP address. */
13052 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13053 p->host);
13054 }
13055
13056 if (use_json) {
13057 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13058 json_object_string_add(json_neigh, "bgpNeighborAddr",
13059 "none");
13060 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13061 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13062 "%pSU", &p->su);
13063
13064 json_object_int_add(json_neigh, "remoteAs", p->as);
13065
13066 if (p->change_local_as)
13067 json_object_int_add(json_neigh, "localAs",
13068 p->change_local_as);
13069 else
13070 json_object_int_add(json_neigh, "localAs", p->local_as);
13071
13072 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13073 json_object_boolean_true_add(json_neigh,
13074 "localAsNoPrepend");
13075
13076 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13077 json_object_boolean_true_add(json_neigh,
13078 "localAsReplaceAs");
13079 } else {
13080 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13081 || (p->as_type == AS_INTERNAL))
13082 vty_out(vty, "remote AS %u, ", p->as);
13083 else
13084 vty_out(vty, "remote AS Unspecified, ");
13085 vty_out(vty, "local AS %u%s%s, ",
13086 p->change_local_as ? p->change_local_as : p->local_as,
13087 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13088 ? " no-prepend"
13089 : "",
13090 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13091 ? " replace-as"
13092 : "");
13093 }
13094 /* peer type internal or confed-internal */
13095 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13096 if (use_json) {
13097 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13098 json_object_boolean_true_add(
13099 json_neigh, "nbrConfedInternalLink");
13100 else
13101 json_object_boolean_true_add(json_neigh,
13102 "nbrInternalLink");
13103 } else {
13104 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13105 vty_out(vty, "confed-internal link\n");
13106 else
13107 vty_out(vty, "internal link\n");
13108 }
13109 /* peer type external or confed-external */
13110 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13111 if (use_json) {
13112 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13113 json_object_boolean_true_add(
13114 json_neigh, "nbrConfedExternalLink");
13115 else
13116 json_object_boolean_true_add(json_neigh,
13117 "nbrExternalLink");
13118 } else {
13119 if (bgp_confederation_peers_check(bgp, p->as))
13120 vty_out(vty, "confed-external link\n");
13121 else
13122 vty_out(vty, "external link\n");
13123 }
13124 } else {
13125 if (use_json)
13126 json_object_boolean_true_add(json_neigh,
13127 "nbrUnspecifiedLink");
13128 else
13129 vty_out(vty, "unspecified link\n");
13130 }
13131
13132 /* Roles */
13133 if (use_json) {
13134 json_object_string_add(json_neigh, "localRole",
13135 bgp_get_name_by_role(p->local_role));
13136 json_object_string_add(json_neigh, "remoteRole",
13137 bgp_get_name_by_role(p->remote_role));
13138 } else {
13139 vty_out(vty, " Local Role: %s\n",
13140 bgp_get_name_by_role(p->local_role));
13141 vty_out(vty, " Remote Role: %s\n",
13142 bgp_get_name_by_role(p->remote_role));
13143 }
13144
13145
13146 /* Description. */
13147 if (p->desc) {
13148 if (use_json)
13149 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13150 else
13151 vty_out(vty, " Description: %s\n", p->desc);
13152 }
13153
13154 if (p->hostname) {
13155 if (use_json) {
13156 json_object_string_add(json_neigh, "hostname",
13157 p->hostname);
13158
13159 if (p->domainname)
13160 json_object_string_add(json_neigh, "domainname",
13161 p->domainname);
13162 } else {
13163 if (p->domainname && (p->domainname[0] != '\0'))
13164 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13165 p->domainname);
13166 else
13167 vty_out(vty, "Hostname: %s\n", p->hostname);
13168 }
13169 } else {
13170 if (use_json)
13171 json_object_string_add(json_neigh, "hostname",
13172 "Unknown");
13173 }
13174
13175 /* Peer-group */
13176 if (p->group) {
13177 if (use_json) {
13178 json_object_string_add(json_neigh, "peerGroup",
13179 p->group->name);
13180
13181 if (dn_flag[0]) {
13182 struct prefix prefix, *range = NULL;
13183
13184 if (sockunion2hostprefix(&(p->su), &prefix))
13185 range = peer_group_lookup_dynamic_neighbor_range(
13186 p->group, &prefix);
13187
13188 if (range) {
13189 json_object_string_addf(
13190 json_neigh,
13191 "peerSubnetRangeGroup", "%pFX",
13192 range);
13193 }
13194 }
13195 } else {
13196 vty_out(vty,
13197 " Member of peer-group %s for session parameters\n",
13198 p->group->name);
13199
13200 if (dn_flag[0]) {
13201 struct prefix prefix, *range = NULL;
13202
13203 if (sockunion2hostprefix(&(p->su), &prefix))
13204 range = peer_group_lookup_dynamic_neighbor_range(
13205 p->group, &prefix);
13206
13207 if (range) {
13208 vty_out(vty,
13209 " Belongs to the subnet range group: %pFX\n",
13210 range);
13211 }
13212 }
13213 }
13214 }
13215
13216 if (use_json) {
13217 /* Administrative shutdown. */
13218 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13219 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13220 json_object_boolean_true_add(json_neigh,
13221 "adminShutDown");
13222
13223 /* BGP Version. */
13224 json_object_int_add(json_neigh, "bgpVersion", 4);
13225 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13226 &p->remote_id);
13227 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13228 &bgp->router_id);
13229
13230 /* Confederation */
13231 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13232 && bgp_confederation_peers_check(bgp, p->as))
13233 json_object_boolean_true_add(json_neigh,
13234 "nbrCommonAdmin");
13235
13236 /* Status. */
13237 json_object_string_add(
13238 json_neigh, "bgpState",
13239 lookup_msg(bgp_status_msg, p->status, NULL));
13240
13241 if (peer_established(p)) {
13242 time_t uptime;
13243
13244 uptime = monotime(NULL);
13245 uptime -= p->uptime;
13246 epoch_tbuf = time(NULL) - uptime;
13247
13248 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13249 uptime * 1000);
13250 json_object_string_add(json_neigh, "bgpTimerUpString",
13251 peer_uptime(p->uptime, timebuf,
13252 BGP_UPTIME_LEN, 0,
13253 NULL));
13254 json_object_int_add(json_neigh,
13255 "bgpTimerUpEstablishedEpoch",
13256 epoch_tbuf);
13257 }
13258
13259 else if (p->status == Active) {
13260 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13261 json_object_string_add(json_neigh, "bgpStateIs",
13262 "passive");
13263 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13264 json_object_string_add(json_neigh, "bgpStateIs",
13265 "passiveNSF");
13266 }
13267
13268 /* read timer */
13269 time_t uptime;
13270 struct tm tm;
13271
13272 uptime = monotime(NULL);
13273 uptime -= p->readtime;
13274 gmtime_r(&uptime, &tm);
13275
13276 json_object_int_add(json_neigh, "bgpTimerLastRead",
13277 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13278 + (tm.tm_hour * 3600000));
13279
13280 uptime = monotime(NULL);
13281 uptime -= p->last_write;
13282 gmtime_r(&uptime, &tm);
13283
13284 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13285 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13286 + (tm.tm_hour * 3600000));
13287
13288 uptime = monotime(NULL);
13289 uptime -= p->update_time;
13290 gmtime_r(&uptime, &tm);
13291
13292 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13293 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13294 + (tm.tm_hour * 3600000));
13295
13296 /* Configured timer values. */
13297 json_object_int_add(json_neigh,
13298 "bgpTimerConfiguredHoldTimeMsecs",
13299 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13300 ? p->holdtime * 1000
13301 : bgp->default_holdtime * 1000);
13302 json_object_int_add(json_neigh,
13303 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13304 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13305 ? p->keepalive * 1000
13306 : bgp->default_keepalive * 1000);
13307 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13308 p->v_holdtime * 1000);
13309 json_object_int_add(json_neigh,
13310 "bgpTimerKeepAliveIntervalMsecs",
13311 p->v_keepalive * 1000);
13312 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13313 json_object_int_add(json_neigh,
13314 "bgpTimerDelayOpenTimeMsecs",
13315 p->v_delayopen * 1000);
13316 }
13317
13318 /* Configured and Synced tcp-mss value for peer */
13319 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13320 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13321 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13322 p->tcp_mss);
13323 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13324 sync_tcp_mss);
13325 }
13326
13327 /* Extended Optional Parameters Length for BGP OPEN Message */
13328 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13329 json_object_boolean_true_add(
13330 json_neigh, "extendedOptionalParametersLength");
13331 else
13332 json_object_boolean_false_add(
13333 json_neigh, "extendedOptionalParametersLength");
13334
13335 /* Conditional advertisements */
13336 json_object_int_add(
13337 json_neigh,
13338 "bgpTimerConfiguredConditionalAdvertisementsSec",
13339 bgp->condition_check_period);
13340 if (thread_is_scheduled(bgp->t_condition_check))
13341 json_object_int_add(
13342 json_neigh,
13343 "bgpTimerUntilConditionalAdvertisementsSec",
13344 thread_timer_remain_second(
13345 bgp->t_condition_check));
13346 } else {
13347 /* Administrative shutdown. */
13348 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13349 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13350 vty_out(vty, " Administratively shut down\n");
13351
13352 /* BGP Version. */
13353 vty_out(vty, " BGP version 4");
13354 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13355 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13356
13357 /* Confederation */
13358 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13359 && bgp_confederation_peers_check(bgp, p->as))
13360 vty_out(vty,
13361 " Neighbor under common administration\n");
13362
13363 /* Status. */
13364 vty_out(vty, " BGP state = %s",
13365 lookup_msg(bgp_status_msg, p->status, NULL));
13366
13367 if (peer_established(p))
13368 vty_out(vty, ", up for %8s",
13369 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13370 0, NULL));
13371
13372 else if (p->status == Active) {
13373 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13374 vty_out(vty, " (passive)");
13375 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13376 vty_out(vty, " (NSF passive)");
13377 }
13378 vty_out(vty, "\n");
13379
13380 /* read timer */
13381 vty_out(vty, " Last read %s",
13382 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13383 NULL));
13384 vty_out(vty, ", Last write %s\n",
13385 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13386 NULL));
13387
13388 /* Configured timer values. */
13389 vty_out(vty,
13390 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13391 p->v_holdtime, p->v_keepalive);
13392 vty_out(vty, " Configured hold time is %d seconds",
13393 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13394 ? p->holdtime
13395 : bgp->default_holdtime);
13396 vty_out(vty, ", keepalive interval is %d seconds\n",
13397 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13398 ? p->keepalive
13399 : bgp->default_keepalive);
13400 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13401 vty_out(vty,
13402 " Configured DelayOpenTime is %d seconds\n",
13403 p->delayopen);
13404
13405 /* Configured and synced tcp-mss value for peer */
13406 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13407 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13408 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13409 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13410 }
13411
13412 /* Extended Optional Parameters Length for BGP OPEN Message */
13413 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13414 vty_out(vty,
13415 " Extended Optional Parameters Length is enabled\n");
13416
13417 /* Conditional advertisements */
13418 vty_out(vty,
13419 " Configured conditional advertisements interval is %d seconds\n",
13420 bgp->condition_check_period);
13421 if (thread_is_scheduled(bgp->t_condition_check))
13422 vty_out(vty,
13423 " Time until conditional advertisements begin is %lu seconds\n",
13424 thread_timer_remain_second(
13425 bgp->t_condition_check));
13426 }
13427 /* Capability. */
13428 if (peer_established(p) &&
13429 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13430 if (use_json) {
13431 json_object *json_cap = NULL;
13432
13433 json_cap = json_object_new_object();
13434
13435 /* AS4 */
13436 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13437 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13438 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13439 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13440 json_object_string_add(
13441 json_cap, "4byteAs",
13442 "advertisedAndReceived");
13443 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13444 json_object_string_add(json_cap,
13445 "4byteAs",
13446 "advertised");
13447 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13448 json_object_string_add(json_cap,
13449 "4byteAs",
13450 "received");
13451 }
13452
13453 /* Extended Message Support */
13454 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13455 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13456 json_object_string_add(json_cap,
13457 "extendedMessage",
13458 "advertisedAndReceived");
13459 else if (CHECK_FLAG(p->cap,
13460 PEER_CAP_EXTENDED_MESSAGE_ADV))
13461 json_object_string_add(json_cap,
13462 "extendedMessage",
13463 "advertised");
13464 else if (CHECK_FLAG(p->cap,
13465 PEER_CAP_EXTENDED_MESSAGE_RCV))
13466 json_object_string_add(json_cap,
13467 "extendedMessage",
13468 "received");
13469
13470 /* AddPath */
13471 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13472 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13473 json_object *json_add = NULL;
13474 const char *print_store;
13475
13476 json_add = json_object_new_object();
13477
13478 FOREACH_AFI_SAFI (afi, safi) {
13479 json_object *json_sub = NULL;
13480 json_sub = json_object_new_object();
13481 print_store = get_afi_safi_str(
13482 afi, safi, true);
13483
13484 if (CHECK_FLAG(
13485 p->af_cap[afi][safi],
13486 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13487 CHECK_FLAG(
13488 p->af_cap[afi][safi],
13489 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13490 if (CHECK_FLAG(
13491 p->af_cap[afi]
13492 [safi],
13493 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13494 CHECK_FLAG(
13495 p->af_cap[afi]
13496 [safi],
13497 PEER_CAP_ADDPATH_AF_TX_RCV))
13498 json_object_boolean_true_add(
13499 json_sub,
13500 "txAdvertisedAndReceived");
13501 else if (
13502 CHECK_FLAG(
13503 p->af_cap[afi]
13504 [safi],
13505 PEER_CAP_ADDPATH_AF_TX_ADV))
13506 json_object_boolean_true_add(
13507 json_sub,
13508 "txAdvertised");
13509 else if (
13510 CHECK_FLAG(
13511 p->af_cap[afi]
13512 [safi],
13513 PEER_CAP_ADDPATH_AF_TX_RCV))
13514 json_object_boolean_true_add(
13515 json_sub,
13516 "txReceived");
13517 }
13518
13519 if (CHECK_FLAG(
13520 p->af_cap[afi][safi],
13521 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13522 CHECK_FLAG(
13523 p->af_cap[afi][safi],
13524 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13525 if (CHECK_FLAG(
13526 p->af_cap[afi]
13527 [safi],
13528 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13529 CHECK_FLAG(
13530 p->af_cap[afi]
13531 [safi],
13532 PEER_CAP_ADDPATH_AF_RX_RCV))
13533 json_object_boolean_true_add(
13534 json_sub,
13535 "rxAdvertisedAndReceived");
13536 else if (
13537 CHECK_FLAG(
13538 p->af_cap[afi]
13539 [safi],
13540 PEER_CAP_ADDPATH_AF_RX_ADV))
13541 json_object_boolean_true_add(
13542 json_sub,
13543 "rxAdvertised");
13544 else if (
13545 CHECK_FLAG(
13546 p->af_cap[afi]
13547 [safi],
13548 PEER_CAP_ADDPATH_AF_RX_RCV))
13549 json_object_boolean_true_add(
13550 json_sub,
13551 "rxReceived");
13552 }
13553
13554 if (CHECK_FLAG(
13555 p->af_cap[afi][safi],
13556 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13557 CHECK_FLAG(
13558 p->af_cap[afi][safi],
13559 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13560 CHECK_FLAG(
13561 p->af_cap[afi][safi],
13562 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13563 CHECK_FLAG(
13564 p->af_cap[afi][safi],
13565 PEER_CAP_ADDPATH_AF_RX_RCV))
13566 json_object_object_add(
13567 json_add, print_store,
13568 json_sub);
13569 else
13570 json_object_free(json_sub);
13571 }
13572
13573 json_object_object_add(json_cap, "addPath",
13574 json_add);
13575 }
13576
13577 /* Dynamic */
13578 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13579 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13580 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13581 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13582 json_object_string_add(
13583 json_cap, "dynamic",
13584 "advertisedAndReceived");
13585 else if (CHECK_FLAG(p->cap,
13586 PEER_CAP_DYNAMIC_ADV))
13587 json_object_string_add(json_cap,
13588 "dynamic",
13589 "advertised");
13590 else if (CHECK_FLAG(p->cap,
13591 PEER_CAP_DYNAMIC_RCV))
13592 json_object_string_add(json_cap,
13593 "dynamic",
13594 "received");
13595 }
13596
13597 /* Role */
13598 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13599 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13600 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13601 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13602 json_object_string_add(
13603 json_cap, "role",
13604 "advertisedAndReceived");
13605 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13606 json_object_string_add(json_cap, "role",
13607 "advertised");
13608 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13609 json_object_string_add(json_cap, "role",
13610 "received");
13611 }
13612
13613 /* Extended nexthop */
13614 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13615 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13616 json_object *json_nxt = NULL;
13617 const char *print_store;
13618
13619
13620 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13621 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13622 json_object_string_add(
13623 json_cap, "extendedNexthop",
13624 "advertisedAndReceived");
13625 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13626 json_object_string_add(
13627 json_cap, "extendedNexthop",
13628 "advertised");
13629 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13630 json_object_string_add(
13631 json_cap, "extendedNexthop",
13632 "received");
13633
13634 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13635 json_nxt = json_object_new_object();
13636
13637 for (safi = SAFI_UNICAST;
13638 safi < SAFI_MAX; safi++) {
13639 if (CHECK_FLAG(
13640 p->af_cap[AFI_IP]
13641 [safi],
13642 PEER_CAP_ENHE_AF_RCV)) {
13643 print_store =
13644 get_afi_safi_str(
13645 AFI_IP,
13646 safi,
13647 true);
13648 json_object_string_add(
13649 json_nxt,
13650 print_store,
13651 "recieved"); /* misspelled for compatibility */
13652 }
13653 }
13654 json_object_object_add(
13655 json_cap,
13656 "extendedNexthopFamililesByPeer",
13657 json_nxt);
13658 }
13659 }
13660
13661 /* Long-lived Graceful Restart */
13662 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13663 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13664 json_object *json_llgr = NULL;
13665 const char *afi_safi_str;
13666
13667 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13668 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13669 json_object_string_add(
13670 json_cap,
13671 "longLivedGracefulRestart",
13672 "advertisedAndReceived");
13673 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13674 json_object_string_add(
13675 json_cap,
13676 "longLivedGracefulRestart",
13677 "advertised");
13678 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13679 json_object_string_add(
13680 json_cap,
13681 "longLivedGracefulRestart",
13682 "received");
13683
13684 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13685 json_llgr = json_object_new_object();
13686
13687 FOREACH_AFI_SAFI (afi, safi) {
13688 if (CHECK_FLAG(
13689 p->af_cap[afi]
13690 [safi],
13691 PEER_CAP_ENHE_AF_RCV)) {
13692 afi_safi_str =
13693 get_afi_safi_str(
13694 afi,
13695 safi,
13696 true);
13697 json_object_string_add(
13698 json_llgr,
13699 afi_safi_str,
13700 "received");
13701 }
13702 }
13703 json_object_object_add(
13704 json_cap,
13705 "longLivedGracefulRestartByPeer",
13706 json_llgr);
13707 }
13708 }
13709
13710 /* Route Refresh */
13711 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13712 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13713 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13714 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13715 (CHECK_FLAG(p->cap,
13716 PEER_CAP_REFRESH_NEW_RCV) ||
13717 CHECK_FLAG(p->cap,
13718 PEER_CAP_REFRESH_OLD_RCV))) {
13719 if (CHECK_FLAG(
13720 p->cap,
13721 PEER_CAP_REFRESH_OLD_RCV) &&
13722 CHECK_FLAG(
13723 p->cap,
13724 PEER_CAP_REFRESH_NEW_RCV))
13725 json_object_string_add(
13726 json_cap,
13727 "routeRefresh",
13728 "advertisedAndReceivedOldNew");
13729 else {
13730 if (CHECK_FLAG(
13731 p->cap,
13732 PEER_CAP_REFRESH_OLD_RCV))
13733 json_object_string_add(
13734 json_cap,
13735 "routeRefresh",
13736 "advertisedAndReceivedOld");
13737 else
13738 json_object_string_add(
13739 json_cap,
13740 "routeRefresh",
13741 "advertisedAndReceivedNew");
13742 }
13743 } else if (CHECK_FLAG(p->cap,
13744 PEER_CAP_REFRESH_ADV))
13745 json_object_string_add(json_cap,
13746 "routeRefresh",
13747 "advertised");
13748 else if (CHECK_FLAG(p->cap,
13749 PEER_CAP_REFRESH_NEW_RCV) ||
13750 CHECK_FLAG(p->cap,
13751 PEER_CAP_REFRESH_OLD_RCV))
13752 json_object_string_add(json_cap,
13753 "routeRefresh",
13754 "received");
13755 }
13756
13757 /* Enhanced Route Refresh */
13758 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13759 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13760 if (CHECK_FLAG(p->cap,
13761 PEER_CAP_ENHANCED_RR_ADV) &&
13762 CHECK_FLAG(p->cap,
13763 PEER_CAP_ENHANCED_RR_RCV))
13764 json_object_string_add(
13765 json_cap,
13766 "enhancedRouteRefresh",
13767 "advertisedAndReceived");
13768 else if (CHECK_FLAG(p->cap,
13769 PEER_CAP_ENHANCED_RR_ADV))
13770 json_object_string_add(
13771 json_cap,
13772 "enhancedRouteRefresh",
13773 "advertised");
13774 else if (CHECK_FLAG(p->cap,
13775 PEER_CAP_ENHANCED_RR_RCV))
13776 json_object_string_add(
13777 json_cap,
13778 "enhancedRouteRefresh",
13779 "received");
13780 }
13781
13782 /* Multiprotocol Extensions */
13783 json_object *json_multi = NULL;
13784
13785 json_multi = json_object_new_object();
13786
13787 FOREACH_AFI_SAFI (afi, safi) {
13788 if (p->afc_adv[afi][safi] ||
13789 p->afc_recv[afi][safi]) {
13790 json_object *json_exten = NULL;
13791 json_exten = json_object_new_object();
13792
13793 if (p->afc_adv[afi][safi] &&
13794 p->afc_recv[afi][safi])
13795 json_object_boolean_true_add(
13796 json_exten,
13797 "advertisedAndReceived");
13798 else if (p->afc_adv[afi][safi])
13799 json_object_boolean_true_add(
13800 json_exten,
13801 "advertised");
13802 else if (p->afc_recv[afi][safi])
13803 json_object_boolean_true_add(
13804 json_exten, "received");
13805
13806 json_object_object_add(
13807 json_multi,
13808 get_afi_safi_str(afi, safi,
13809 true),
13810 json_exten);
13811 }
13812 }
13813 json_object_object_add(json_cap,
13814 "multiprotocolExtensions",
13815 json_multi);
13816
13817 /* Hostname capabilities */
13818 json_object *json_hname = NULL;
13819
13820 json_hname = json_object_new_object();
13821
13822 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13823 json_object_string_add(
13824 json_hname, "advHostName",
13825 bgp->peer_self->hostname
13826 ? bgp->peer_self->hostname
13827 : "n/a");
13828 json_object_string_add(
13829 json_hname, "advDomainName",
13830 bgp->peer_self->domainname
13831 ? bgp->peer_self->domainname
13832 : "n/a");
13833 }
13834
13835
13836 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13837 json_object_string_add(
13838 json_hname, "rcvHostName",
13839 p->hostname ? p->hostname : "n/a");
13840 json_object_string_add(
13841 json_hname, "rcvDomainName",
13842 p->domainname ? p->domainname : "n/a");
13843 }
13844
13845 json_object_object_add(json_cap, "hostName",
13846 json_hname);
13847
13848 /* Graceful Restart */
13849 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13850 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13851 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13852 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13853 json_object_string_add(
13854 json_cap, "gracefulRestart",
13855 "advertisedAndReceived");
13856 else if (CHECK_FLAG(p->cap,
13857 PEER_CAP_RESTART_ADV))
13858 json_object_string_add(
13859 json_cap,
13860 "gracefulRestartCapability",
13861 "advertised");
13862 else if (CHECK_FLAG(p->cap,
13863 PEER_CAP_RESTART_RCV))
13864 json_object_string_add(
13865 json_cap,
13866 "gracefulRestartCapability",
13867 "received");
13868
13869 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13870 int restart_af_count = 0;
13871 json_object *json_restart = NULL;
13872 json_restart = json_object_new_object();
13873
13874 json_object_int_add(
13875 json_cap,
13876 "gracefulRestartRemoteTimerMsecs",
13877 p->v_gr_restart * 1000);
13878
13879 FOREACH_AFI_SAFI (afi, safi) {
13880 if (CHECK_FLAG(
13881 p->af_cap[afi]
13882 [safi],
13883 PEER_CAP_RESTART_AF_RCV)) {
13884 json_object *json_sub =
13885 NULL;
13886 json_sub =
13887 json_object_new_object();
13888
13889 if (CHECK_FLAG(
13890 p->af_cap
13891 [afi]
13892 [safi],
13893 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13894 json_object_boolean_true_add(
13895 json_sub,
13896 "preserved");
13897 restart_af_count++;
13898 json_object_object_add(
13899 json_restart,
13900 get_afi_safi_str(
13901 afi,
13902 safi,
13903 true),
13904 json_sub);
13905 }
13906 }
13907 if (!restart_af_count) {
13908 json_object_string_add(
13909 json_cap,
13910 "addressFamiliesByPeer",
13911 "none");
13912 json_object_free(json_restart);
13913 } else
13914 json_object_object_add(
13915 json_cap,
13916 "addressFamiliesByPeer",
13917 json_restart);
13918 }
13919 }
13920 json_object_object_add(
13921 json_neigh, "neighborCapabilities", json_cap);
13922 } else {
13923 vty_out(vty, " Neighbor capabilities:\n");
13924
13925 /* AS4 */
13926 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13927 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13928 vty_out(vty, " 4 Byte AS:");
13929 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13930 vty_out(vty, " advertised");
13931 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13932 vty_out(vty, " %sreceived",
13933 CHECK_FLAG(p->cap,
13934 PEER_CAP_AS4_ADV)
13935 ? "and "
13936 : "");
13937 vty_out(vty, "\n");
13938 }
13939
13940 /* Extended Message Support */
13941 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13942 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13943 vty_out(vty, " Extended Message:");
13944 if (CHECK_FLAG(p->cap,
13945 PEER_CAP_EXTENDED_MESSAGE_ADV))
13946 vty_out(vty, " advertised");
13947 if (CHECK_FLAG(p->cap,
13948 PEER_CAP_EXTENDED_MESSAGE_RCV))
13949 vty_out(vty, " %sreceived",
13950 CHECK_FLAG(
13951 p->cap,
13952 PEER_CAP_EXTENDED_MESSAGE_ADV)
13953 ? "and "
13954 : "");
13955 vty_out(vty, "\n");
13956 }
13957
13958 /* AddPath */
13959 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13960 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13961 vty_out(vty, " AddPath:\n");
13962
13963 FOREACH_AFI_SAFI (afi, safi) {
13964 if (CHECK_FLAG(
13965 p->af_cap[afi][safi],
13966 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13967 CHECK_FLAG(
13968 p->af_cap[afi][safi],
13969 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13970 vty_out(vty, " %s: TX ",
13971 get_afi_safi_str(
13972 afi, safi,
13973 false));
13974
13975 if (CHECK_FLAG(
13976 p->af_cap[afi]
13977 [safi],
13978 PEER_CAP_ADDPATH_AF_TX_ADV))
13979 vty_out(vty,
13980 "advertised");
13981
13982 if (CHECK_FLAG(
13983 p->af_cap[afi]
13984 [safi],
13985 PEER_CAP_ADDPATH_AF_TX_RCV))
13986 vty_out(vty,
13987 "%sreceived",
13988 CHECK_FLAG(
13989 p->af_cap
13990 [afi]
13991 [safi],
13992 PEER_CAP_ADDPATH_AF_TX_ADV)
13993 ? " and "
13994 : "");
13995
13996 vty_out(vty, "\n");
13997 }
13998
13999 if (CHECK_FLAG(
14000 p->af_cap[afi][safi],
14001 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14002 CHECK_FLAG(
14003 p->af_cap[afi][safi],
14004 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14005 vty_out(vty, " %s: RX ",
14006 get_afi_safi_str(
14007 afi, safi,
14008 false));
14009
14010 if (CHECK_FLAG(
14011 p->af_cap[afi]
14012 [safi],
14013 PEER_CAP_ADDPATH_AF_RX_ADV))
14014 vty_out(vty,
14015 "advertised");
14016
14017 if (CHECK_FLAG(
14018 p->af_cap[afi]
14019 [safi],
14020 PEER_CAP_ADDPATH_AF_RX_RCV))
14021 vty_out(vty,
14022 "%sreceived",
14023 CHECK_FLAG(
14024 p->af_cap
14025 [afi]
14026 [safi],
14027 PEER_CAP_ADDPATH_AF_RX_ADV)
14028 ? " and "
14029 : "");
14030
14031 vty_out(vty, "\n");
14032 }
14033 }
14034 }
14035
14036 /* Dynamic */
14037 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14038 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14039 vty_out(vty, " Dynamic:");
14040 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14041 vty_out(vty, " advertised");
14042 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14043 vty_out(vty, " %sreceived",
14044 CHECK_FLAG(p->cap,
14045 PEER_CAP_DYNAMIC_ADV)
14046 ? "and "
14047 : "");
14048 vty_out(vty, "\n");
14049 }
14050
14051 /* Role */
14052 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14053 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14054 vty_out(vty, " Role:");
14055 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14056 vty_out(vty, " advertised");
14057 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14058 vty_out(vty, " %sreceived",
14059 CHECK_FLAG(p->cap,
14060 PEER_CAP_ROLE_ADV)
14061 ? "and "
14062 : "");
14063 vty_out(vty, "\n");
14064 }
14065
14066 /* Extended nexthop */
14067 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14068 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14069 vty_out(vty, " Extended nexthop:");
14070 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14071 vty_out(vty, " advertised");
14072 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14073 vty_out(vty, " %sreceived",
14074 CHECK_FLAG(p->cap,
14075 PEER_CAP_ENHE_ADV)
14076 ? "and "
14077 : "");
14078 vty_out(vty, "\n");
14079
14080 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
14081 vty_out(vty,
14082 " Address families by peer:\n ");
14083 for (safi = SAFI_UNICAST;
14084 safi < SAFI_MAX; safi++)
14085 if (CHECK_FLAG(
14086 p->af_cap[AFI_IP]
14087 [safi],
14088 PEER_CAP_ENHE_AF_RCV))
14089 vty_out(vty,
14090 " %s\n",
14091 get_afi_safi_str(
14092 AFI_IP,
14093 safi,
14094 false));
14095 }
14096 }
14097
14098 /* Long-lived Graceful Restart */
14099 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14100 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14101 vty_out(vty,
14102 " Long-lived Graceful Restart:");
14103 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14104 vty_out(vty, " advertised");
14105 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14106 vty_out(vty, " %sreceived",
14107 CHECK_FLAG(p->cap,
14108 PEER_CAP_LLGR_ADV)
14109 ? "and "
14110 : "");
14111 vty_out(vty, "\n");
14112
14113 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14114 vty_out(vty,
14115 " Address families by peer:\n");
14116 FOREACH_AFI_SAFI (afi, safi)
14117 if (CHECK_FLAG(
14118 p->af_cap[afi]
14119 [safi],
14120 PEER_CAP_LLGR_AF_RCV))
14121 vty_out(vty,
14122 " %s\n",
14123 get_afi_safi_str(
14124 afi,
14125 safi,
14126 false));
14127 }
14128 }
14129
14130 /* Route Refresh */
14131 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14132 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14133 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14134 vty_out(vty, " Route refresh:");
14135 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14136 vty_out(vty, " advertised");
14137 if (CHECK_FLAG(p->cap,
14138 PEER_CAP_REFRESH_NEW_RCV) ||
14139 CHECK_FLAG(p->cap,
14140 PEER_CAP_REFRESH_OLD_RCV))
14141 vty_out(vty, " %sreceived(%s)",
14142 CHECK_FLAG(p->cap,
14143 PEER_CAP_REFRESH_ADV)
14144 ? "and "
14145 : "",
14146 (CHECK_FLAG(
14147 p->cap,
14148 PEER_CAP_REFRESH_OLD_RCV) &&
14149 CHECK_FLAG(
14150 p->cap,
14151 PEER_CAP_REFRESH_NEW_RCV))
14152 ? "old & new"
14153 : CHECK_FLAG(
14154 p->cap,
14155 PEER_CAP_REFRESH_OLD_RCV)
14156 ? "old"
14157 : "new");
14158
14159 vty_out(vty, "\n");
14160 }
14161
14162 /* Enhanced Route Refresh */
14163 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14164 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14165 vty_out(vty, " Enhanced Route Refresh:");
14166 if (CHECK_FLAG(p->cap,
14167 PEER_CAP_ENHANCED_RR_ADV))
14168 vty_out(vty, " advertised");
14169 if (CHECK_FLAG(p->cap,
14170 PEER_CAP_ENHANCED_RR_RCV))
14171 vty_out(vty, " %sreceived",
14172 CHECK_FLAG(p->cap,
14173 PEER_CAP_REFRESH_ADV)
14174 ? "and "
14175 : "");
14176 vty_out(vty, "\n");
14177 }
14178
14179 /* Multiprotocol Extensions */
14180 FOREACH_AFI_SAFI (afi, safi)
14181 if (p->afc_adv[afi][safi] ||
14182 p->afc_recv[afi][safi]) {
14183 vty_out(vty, " Address Family %s:",
14184 get_afi_safi_str(afi, safi,
14185 false));
14186 if (p->afc_adv[afi][safi])
14187 vty_out(vty, " advertised");
14188 if (p->afc_recv[afi][safi])
14189 vty_out(vty, " %sreceived",
14190 p->afc_adv[afi][safi]
14191 ? "and "
14192 : "");
14193 vty_out(vty, "\n");
14194 }
14195
14196 /* Hostname capability */
14197 vty_out(vty, " Hostname Capability:");
14198
14199 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14200 vty_out(vty,
14201 " advertised (name: %s,domain name: %s)",
14202 bgp->peer_self->hostname
14203 ? bgp->peer_self->hostname
14204 : "n/a",
14205 bgp->peer_self->domainname
14206 ? bgp->peer_self->domainname
14207 : "n/a");
14208 } else {
14209 vty_out(vty, " not advertised");
14210 }
14211
14212 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14213 vty_out(vty,
14214 " received (name: %s,domain name: %s)",
14215 p->hostname ? p->hostname : "n/a",
14216 p->domainname ? p->domainname : "n/a");
14217 } else {
14218 vty_out(vty, " not received");
14219 }
14220
14221 vty_out(vty, "\n");
14222
14223 /* Graceful Restart */
14224 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14225 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14226 vty_out(vty,
14227 " Graceful Restart Capability:");
14228 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14229 vty_out(vty, " advertised");
14230 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14231 vty_out(vty, " %sreceived",
14232 CHECK_FLAG(p->cap,
14233 PEER_CAP_RESTART_ADV)
14234 ? "and "
14235 : "");
14236 vty_out(vty, "\n");
14237
14238 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14239 int restart_af_count = 0;
14240
14241 vty_out(vty,
14242 " Remote Restart timer is %d seconds\n",
14243 p->v_gr_restart);
14244 vty_out(vty,
14245 " Address families by peer:\n ");
14246
14247 FOREACH_AFI_SAFI (afi, safi)
14248 if (CHECK_FLAG(
14249 p->af_cap[afi]
14250 [safi],
14251 PEER_CAP_RESTART_AF_RCV)) {
14252 vty_out(vty, "%s%s(%s)",
14253 restart_af_count
14254 ? ", "
14255 : "",
14256 get_afi_safi_str(
14257 afi,
14258 safi,
14259 false),
14260 CHECK_FLAG(
14261 p->af_cap
14262 [afi]
14263 [safi],
14264 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14265 ? "preserved"
14266 : "not preserved");
14267 restart_af_count++;
14268 }
14269 if (!restart_af_count)
14270 vty_out(vty, "none");
14271 vty_out(vty, "\n");
14272 }
14273 } /* Graceful Restart */
14274 }
14275 }
14276
14277 /* graceful restart information */
14278 json_object *json_grace = NULL;
14279 json_object *json_grace_send = NULL;
14280 json_object *json_grace_recv = NULL;
14281 int eor_send_af_count = 0;
14282 int eor_receive_af_count = 0;
14283
14284 if (use_json) {
14285 json_grace = json_object_new_object();
14286 json_grace_send = json_object_new_object();
14287 json_grace_recv = json_object_new_object();
14288
14289 if ((peer_established(p)) &&
14290 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14291 FOREACH_AFI_SAFI (afi, safi) {
14292 if (CHECK_FLAG(p->af_sflags[afi][safi],
14293 PEER_STATUS_EOR_SEND)) {
14294 json_object_boolean_true_add(
14295 json_grace_send,
14296 get_afi_safi_str(afi, safi,
14297 true));
14298 eor_send_af_count++;
14299 }
14300 }
14301 FOREACH_AFI_SAFI (afi, safi) {
14302 if (CHECK_FLAG(p->af_sflags[afi][safi],
14303 PEER_STATUS_EOR_RECEIVED)) {
14304 json_object_boolean_true_add(
14305 json_grace_recv,
14306 get_afi_safi_str(afi, safi,
14307 true));
14308 eor_receive_af_count++;
14309 }
14310 }
14311 }
14312 json_object_object_add(json_grace, "endOfRibSend",
14313 json_grace_send);
14314 json_object_object_add(json_grace, "endOfRibRecv",
14315 json_grace_recv);
14316
14317
14318 if (p->t_gr_restart)
14319 json_object_int_add(
14320 json_grace, "gracefulRestartTimerMsecs",
14321 thread_timer_remain_second(p->t_gr_restart) *
14322 1000);
14323
14324 if (p->t_gr_stale)
14325 json_object_int_add(
14326 json_grace, "gracefulStalepathTimerMsecs",
14327 thread_timer_remain_second(p->t_gr_stale) *
14328 1000);
14329 /* more gr info in new format */
14330 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14331 json_object_object_add(json_neigh, "gracefulRestartInfo",
14332 json_grace);
14333 } else {
14334 vty_out(vty, " Graceful restart information:\n");
14335 if ((peer_established(p)) &&
14336 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14337
14338 vty_out(vty, " End-of-RIB send: ");
14339 FOREACH_AFI_SAFI (afi, safi) {
14340 if (CHECK_FLAG(p->af_sflags[afi][safi],
14341 PEER_STATUS_EOR_SEND)) {
14342 vty_out(vty, "%s%s",
14343 eor_send_af_count ? ", " : "",
14344 get_afi_safi_str(afi, safi,
14345 false));
14346 eor_send_af_count++;
14347 }
14348 }
14349 vty_out(vty, "\n");
14350 vty_out(vty, " End-of-RIB received: ");
14351 FOREACH_AFI_SAFI (afi, safi) {
14352 if (CHECK_FLAG(p->af_sflags[afi][safi],
14353 PEER_STATUS_EOR_RECEIVED)) {
14354 vty_out(vty, "%s%s",
14355 eor_receive_af_count ? ", "
14356 : "",
14357 get_afi_safi_str(afi, safi,
14358 false));
14359 eor_receive_af_count++;
14360 }
14361 }
14362 vty_out(vty, "\n");
14363 }
14364
14365 if (p->t_gr_restart)
14366 vty_out(vty,
14367 " The remaining time of restart timer is %ld\n",
14368 thread_timer_remain_second(p->t_gr_restart));
14369
14370 if (p->t_gr_stale)
14371 vty_out(vty,
14372 " The remaining time of stalepath timer is %ld\n",
14373 thread_timer_remain_second(p->t_gr_stale));
14374
14375 /* more gr info in new format */
14376 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14377 }
14378
14379 if (use_json) {
14380 json_object *json_stat = NULL;
14381 json_stat = json_object_new_object();
14382 /* Packet counts. */
14383
14384 atomic_size_t outq_count, inq_count;
14385 outq_count = atomic_load_explicit(&p->obuf->count,
14386 memory_order_relaxed);
14387 inq_count = atomic_load_explicit(&p->ibuf->count,
14388 memory_order_relaxed);
14389
14390 json_object_int_add(json_stat, "depthInq",
14391 (unsigned long)inq_count);
14392 json_object_int_add(json_stat, "depthOutq",
14393 (unsigned long)outq_count);
14394 json_object_int_add(json_stat, "opensSent",
14395 atomic_load_explicit(&p->open_out,
14396 memory_order_relaxed));
14397 json_object_int_add(json_stat, "opensRecv",
14398 atomic_load_explicit(&p->open_in,
14399 memory_order_relaxed));
14400 json_object_int_add(json_stat, "notificationsSent",
14401 atomic_load_explicit(&p->notify_out,
14402 memory_order_relaxed));
14403 json_object_int_add(json_stat, "notificationsRecv",
14404 atomic_load_explicit(&p->notify_in,
14405 memory_order_relaxed));
14406 json_object_int_add(json_stat, "updatesSent",
14407 atomic_load_explicit(&p->update_out,
14408 memory_order_relaxed));
14409 json_object_int_add(json_stat, "updatesRecv",
14410 atomic_load_explicit(&p->update_in,
14411 memory_order_relaxed));
14412 json_object_int_add(json_stat, "keepalivesSent",
14413 atomic_load_explicit(&p->keepalive_out,
14414 memory_order_relaxed));
14415 json_object_int_add(json_stat, "keepalivesRecv",
14416 atomic_load_explicit(&p->keepalive_in,
14417 memory_order_relaxed));
14418 json_object_int_add(json_stat, "routeRefreshSent",
14419 atomic_load_explicit(&p->refresh_out,
14420 memory_order_relaxed));
14421 json_object_int_add(json_stat, "routeRefreshRecv",
14422 atomic_load_explicit(&p->refresh_in,
14423 memory_order_relaxed));
14424 json_object_int_add(json_stat, "capabilitySent",
14425 atomic_load_explicit(&p->dynamic_cap_out,
14426 memory_order_relaxed));
14427 json_object_int_add(json_stat, "capabilityRecv",
14428 atomic_load_explicit(&p->dynamic_cap_in,
14429 memory_order_relaxed));
14430 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14431 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14432 json_object_object_add(json_neigh, "messageStats", json_stat);
14433 } else {
14434 atomic_size_t outq_count, inq_count, open_out, open_in,
14435 notify_out, notify_in, update_out, update_in,
14436 keepalive_out, keepalive_in, refresh_out, refresh_in,
14437 dynamic_cap_out, dynamic_cap_in;
14438 outq_count = atomic_load_explicit(&p->obuf->count,
14439 memory_order_relaxed);
14440 inq_count = atomic_load_explicit(&p->ibuf->count,
14441 memory_order_relaxed);
14442 open_out = atomic_load_explicit(&p->open_out,
14443 memory_order_relaxed);
14444 open_in =
14445 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14446 notify_out = atomic_load_explicit(&p->notify_out,
14447 memory_order_relaxed);
14448 notify_in = atomic_load_explicit(&p->notify_in,
14449 memory_order_relaxed);
14450 update_out = atomic_load_explicit(&p->update_out,
14451 memory_order_relaxed);
14452 update_in = atomic_load_explicit(&p->update_in,
14453 memory_order_relaxed);
14454 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14455 memory_order_relaxed);
14456 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14457 memory_order_relaxed);
14458 refresh_out = atomic_load_explicit(&p->refresh_out,
14459 memory_order_relaxed);
14460 refresh_in = atomic_load_explicit(&p->refresh_in,
14461 memory_order_relaxed);
14462 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14463 memory_order_relaxed);
14464 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14465 memory_order_relaxed);
14466
14467 /* Packet counts. */
14468 vty_out(vty, " Message statistics:\n");
14469 vty_out(vty, " Inq depth is %zu\n", inq_count);
14470 vty_out(vty, " Outq depth is %zu\n", outq_count);
14471 vty_out(vty, " Sent Rcvd\n");
14472 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14473 open_in);
14474 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14475 notify_in);
14476 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14477 update_in);
14478 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14479 keepalive_in);
14480 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14481 refresh_in);
14482 vty_out(vty, " Capability: %10zu %10zu\n",
14483 dynamic_cap_out, dynamic_cap_in);
14484 vty_out(vty, " Total: %10u %10u\n",
14485 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14486 }
14487
14488 if (use_json) {
14489 /* advertisement-interval */
14490 json_object_int_add(json_neigh,
14491 "minBtwnAdvertisementRunsTimerMsecs",
14492 p->v_routeadv * 1000);
14493
14494 /* Update-source. */
14495 if (p->update_if || p->update_source) {
14496 if (p->update_if)
14497 json_object_string_add(json_neigh,
14498 "updateSource",
14499 p->update_if);
14500 else if (p->update_source)
14501 json_object_string_addf(json_neigh,
14502 "updateSource", "%pSU",
14503 p->update_source);
14504 }
14505 } else {
14506 /* advertisement-interval */
14507 vty_out(vty,
14508 " Minimum time between advertisement runs is %d seconds\n",
14509 p->v_routeadv);
14510
14511 /* Update-source. */
14512 if (p->update_if || p->update_source) {
14513 vty_out(vty, " Update source is ");
14514 if (p->update_if)
14515 vty_out(vty, "%s", p->update_if);
14516 else if (p->update_source)
14517 vty_out(vty, "%pSU", p->update_source);
14518 vty_out(vty, "\n");
14519 }
14520
14521 vty_out(vty, "\n");
14522 }
14523
14524 /* Address Family Information */
14525 json_object *json_hold = NULL;
14526
14527 if (use_json)
14528 json_hold = json_object_new_object();
14529
14530 FOREACH_AFI_SAFI (afi, safi)
14531 if (p->afc[afi][safi])
14532 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14533 json_hold);
14534
14535 if (use_json) {
14536 json_object_object_add(json_neigh, "addressFamilyInfo",
14537 json_hold);
14538 json_object_int_add(json_neigh, "connectionsEstablished",
14539 p->established);
14540 json_object_int_add(json_neigh, "connectionsDropped",
14541 p->dropped);
14542 } else
14543 vty_out(vty, " Connections established %d; dropped %d\n",
14544 p->established, p->dropped);
14545
14546 if (!p->last_reset) {
14547 if (use_json)
14548 json_object_string_add(json_neigh, "lastReset",
14549 "never");
14550 else
14551 vty_out(vty, " Last reset never\n");
14552 } else {
14553 if (use_json) {
14554 time_t uptime;
14555 struct tm tm;
14556
14557 uptime = monotime(NULL);
14558 uptime -= p->resettime;
14559 gmtime_r(&uptime, &tm);
14560
14561 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14562 (tm.tm_sec * 1000)
14563 + (tm.tm_min * 60000)
14564 + (tm.tm_hour * 3600000));
14565 bgp_show_peer_reset(NULL, p, json_neigh, true);
14566 } else {
14567 vty_out(vty, " Last reset %s, ",
14568 peer_uptime(p->resettime, timebuf,
14569 BGP_UPTIME_LEN, 0, NULL));
14570
14571 bgp_show_peer_reset(vty, p, NULL, false);
14572 if (p->last_reset_cause_size) {
14573 msg = p->last_reset_cause;
14574 vty_out(vty,
14575 " Message received that caused BGP to send a NOTIFICATION:\n ");
14576 for (i = 1; i <= p->last_reset_cause_size;
14577 i++) {
14578 vty_out(vty, "%02X", *msg++);
14579
14580 if (i != p->last_reset_cause_size) {
14581 if (i % 16 == 0) {
14582 vty_out(vty, "\n ");
14583 } else if (i % 4 == 0) {
14584 vty_out(vty, " ");
14585 }
14586 }
14587 }
14588 vty_out(vty, "\n");
14589 }
14590 }
14591 }
14592
14593 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14594 if (use_json)
14595 json_object_boolean_true_add(json_neigh,
14596 "prefixesConfigExceedMax");
14597 else
14598 vty_out(vty,
14599 " Peer had exceeded the max. no. of prefixes configured.\n");
14600
14601 if (p->t_pmax_restart) {
14602 if (use_json) {
14603 json_object_boolean_true_add(
14604 json_neigh, "reducePrefixNumFrom");
14605 json_object_int_add(json_neigh,
14606 "restartInTimerMsec",
14607 thread_timer_remain_second(
14608 p->t_pmax_restart)
14609 * 1000);
14610 } else
14611 vty_out(vty,
14612 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14613 p->host, thread_timer_remain_second(
14614 p->t_pmax_restart));
14615 } else {
14616 if (use_json)
14617 json_object_boolean_true_add(
14618 json_neigh,
14619 "reducePrefixNumAndClearIpBgp");
14620 else
14621 vty_out(vty,
14622 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14623 p->host);
14624 }
14625 }
14626
14627 /* EBGP Multihop and GTSM */
14628 if (p->sort != BGP_PEER_IBGP) {
14629 if (use_json) {
14630 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14631 json_object_int_add(json_neigh,
14632 "externalBgpNbrMaxHopsAway",
14633 p->gtsm_hops);
14634 else
14635 json_object_int_add(json_neigh,
14636 "externalBgpNbrMaxHopsAway",
14637 p->ttl);
14638 } else {
14639 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14640 vty_out(vty,
14641 " External BGP neighbor may be up to %d hops away.\n",
14642 p->gtsm_hops);
14643 else
14644 vty_out(vty,
14645 " External BGP neighbor may be up to %d hops away.\n",
14646 p->ttl);
14647 }
14648 } else {
14649 if (use_json) {
14650 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14651 json_object_int_add(json_neigh,
14652 "internalBgpNbrMaxHopsAway",
14653 p->gtsm_hops);
14654 else
14655 json_object_int_add(json_neigh,
14656 "internalBgpNbrMaxHopsAway",
14657 p->ttl);
14658 } else {
14659 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14660 vty_out(vty,
14661 " Internal BGP neighbor may be up to %d hops away.\n",
14662 p->gtsm_hops);
14663 else
14664 vty_out(vty,
14665 " Internal BGP neighbor may be up to %d hops away.\n",
14666 p->ttl);
14667 }
14668 }
14669
14670 /* Local address. */
14671 if (p->su_local) {
14672 if (use_json) {
14673 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14674 p->su_local);
14675 json_object_int_add(json_neigh, "portLocal",
14676 ntohs(p->su_local->sin.sin_port));
14677 } else
14678 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14679 p->su_local, ntohs(p->su_local->sin.sin_port));
14680 } else {
14681 if (use_json) {
14682 json_object_string_add(json_neigh, "hostLocal",
14683 "Unknown");
14684 json_object_int_add(json_neigh, "portLocal", -1);
14685 }
14686 }
14687
14688 /* Remote address. */
14689 if (p->su_remote) {
14690 if (use_json) {
14691 json_object_string_addf(json_neigh, "hostForeign",
14692 "%pSU", p->su_remote);
14693 json_object_int_add(json_neigh, "portForeign",
14694 ntohs(p->su_remote->sin.sin_port));
14695 } else
14696 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14697 p->su_remote,
14698 ntohs(p->su_remote->sin.sin_port));
14699 } else {
14700 if (use_json) {
14701 json_object_string_add(json_neigh, "hostForeign",
14702 "Unknown");
14703 json_object_int_add(json_neigh, "portForeign", -1);
14704 }
14705 }
14706
14707 /* Nexthop display. */
14708 if (p->su_local) {
14709 if (use_json) {
14710 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14711 &p->nexthop.v4);
14712 json_object_string_addf(json_neigh, "nexthopGlobal",
14713 "%pI6", &p->nexthop.v6_global);
14714 json_object_string_addf(json_neigh, "nexthopLocal",
14715 "%pI6", &p->nexthop.v6_local);
14716 if (p->shared_network)
14717 json_object_string_add(json_neigh,
14718 "bgpConnection",
14719 "sharedNetwork");
14720 else
14721 json_object_string_add(json_neigh,
14722 "bgpConnection",
14723 "nonSharedNetwork");
14724 } else {
14725 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14726 vty_out(vty, "Nexthop global: %pI6\n",
14727 &p->nexthop.v6_global);
14728 vty_out(vty, "Nexthop local: %pI6\n",
14729 &p->nexthop.v6_local);
14730 vty_out(vty, "BGP connection: %s\n",
14731 p->shared_network ? "shared network"
14732 : "non shared network");
14733 }
14734 } else {
14735 if (use_json) {
14736 json_object_string_add(json_neigh, "nexthop",
14737 "Unknown");
14738 json_object_string_add(json_neigh, "nexthopGlobal",
14739 "Unknown");
14740 json_object_string_add(json_neigh, "nexthopLocal",
14741 "Unknown");
14742 json_object_string_add(json_neigh, "bgpConnection",
14743 "Unknown");
14744 }
14745 }
14746
14747 /* Timer information. */
14748 if (use_json) {
14749 json_object_int_add(json_neigh, "connectRetryTimer",
14750 p->v_connect);
14751 if (peer_established(p)) {
14752 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14753 p->rtt);
14754 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14755 json_object_int_add(json_neigh,
14756 "shutdownRttInMsecs",
14757 p->rtt_expected);
14758 json_object_int_add(json_neigh,
14759 "shutdownRttAfterCount",
14760 p->rtt_keepalive_rcv);
14761 }
14762 }
14763 if (p->t_start)
14764 json_object_int_add(
14765 json_neigh, "nextStartTimerDueInMsecs",
14766 thread_timer_remain_second(p->t_start) * 1000);
14767 if (p->t_connect)
14768 json_object_int_add(
14769 json_neigh, "nextConnectTimerDueInMsecs",
14770 thread_timer_remain_second(p->t_connect)
14771 * 1000);
14772 if (p->t_routeadv) {
14773 json_object_int_add(json_neigh, "mraiInterval",
14774 p->v_routeadv);
14775 json_object_int_add(
14776 json_neigh, "mraiTimerExpireInMsecs",
14777 thread_timer_remain_second(p->t_routeadv)
14778 * 1000);
14779 }
14780 if (p->password)
14781 json_object_int_add(json_neigh, "authenticationEnabled",
14782 1);
14783
14784 if (p->t_read)
14785 json_object_string_add(json_neigh, "readThread", "on");
14786 else
14787 json_object_string_add(json_neigh, "readThread", "off");
14788
14789 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14790 json_object_string_add(json_neigh, "writeThread", "on");
14791 else
14792 json_object_string_add(json_neigh, "writeThread",
14793 "off");
14794 } else {
14795 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14796 p->v_connect);
14797 if (peer_established(p)) {
14798 vty_out(vty, "Estimated round trip time: %d ms\n",
14799 p->rtt);
14800 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14801 vty_out(vty,
14802 "Shutdown when RTT > %dms, count > %u\n",
14803 p->rtt_expected, p->rtt_keepalive_rcv);
14804 }
14805 if (p->t_start)
14806 vty_out(vty, "Next start timer due in %ld seconds\n",
14807 thread_timer_remain_second(p->t_start));
14808 if (p->t_connect)
14809 vty_out(vty, "Next connect timer due in %ld seconds\n",
14810 thread_timer_remain_second(p->t_connect));
14811 if (p->t_routeadv)
14812 vty_out(vty,
14813 "MRAI (interval %u) timer expires in %ld seconds\n",
14814 p->v_routeadv,
14815 thread_timer_remain_second(p->t_routeadv));
14816 if (p->password)
14817 vty_out(vty, "Peer Authentication Enabled\n");
14818
14819 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14820 p->t_read ? "on" : "off",
14821 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14822 ? "on"
14823 : "off", p->fd);
14824 }
14825
14826 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14827 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14828 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14829
14830 if (!use_json)
14831 vty_out(vty, "\n");
14832
14833 /* BFD information. */
14834 if (p->bfd_config)
14835 bgp_bfd_show_info(vty, p, json_neigh);
14836
14837 if (use_json) {
14838 if (p->conf_if) /* Configured interface name. */
14839 json_object_object_add(json, p->conf_if, json_neigh);
14840 else /* Configured IP address. */
14841 json_object_object_add(json, p->host, json_neigh);
14842 }
14843 }
14844
14845 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14846 enum show_type type,
14847 union sockunion *su,
14848 const char *conf_if, afi_t afi,
14849 json_object *json)
14850 {
14851 struct listnode *node, *nnode;
14852 struct peer *peer;
14853 bool found = false;
14854 safi_t safi = SAFI_UNICAST;
14855 json_object *json_neighbor = NULL;
14856
14857 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14858
14859 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14860 continue;
14861
14862 if ((peer->afc[afi][safi]) == 0)
14863 continue;
14864
14865 if (json)
14866 json_neighbor = json_object_new_object();
14867
14868 if (type == show_all) {
14869 bgp_show_peer_gr_status(vty, peer, json_neighbor);
14870
14871 if (json)
14872 json_object_object_add(json, peer->host,
14873 json_neighbor);
14874
14875 } else if (type == show_peer) {
14876 if (conf_if) {
14877 if ((peer->conf_if
14878 && !strcmp(peer->conf_if, conf_if))
14879 || (peer->hostname
14880 && !strcmp(peer->hostname, conf_if))) {
14881 found = true;
14882 bgp_show_peer_gr_status(vty, peer,
14883 json_neighbor);
14884 }
14885 } else {
14886 if (sockunion_same(&peer->su, su)) {
14887 found = true;
14888 bgp_show_peer_gr_status(vty, peer,
14889 json_neighbor);
14890 }
14891 }
14892 if (json) {
14893 if (found)
14894 json_object_object_add(json, peer->host,
14895 json_neighbor);
14896 else
14897 json_object_free(json_neighbor);
14898 }
14899 }
14900
14901 if (found)
14902 break;
14903 }
14904
14905 if (type == show_peer && !found) {
14906 if (json)
14907 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14908 else
14909 vty_out(vty, "%% No such neighbor\n");
14910 }
14911
14912 if (!json)
14913 vty_out(vty, "\n");
14914
14915 return CMD_SUCCESS;
14916 }
14917
14918 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14919 enum show_type type, union sockunion *su,
14920 const char *conf_if, bool use_json,
14921 json_object *json)
14922 {
14923 struct listnode *node, *nnode;
14924 struct peer *peer;
14925 int find = 0;
14926 bool nbr_output = false;
14927 afi_t afi = AFI_MAX;
14928 safi_t safi = SAFI_MAX;
14929
14930 if (type == show_ipv4_peer || type == show_ipv4_all) {
14931 afi = AFI_IP;
14932 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14933 afi = AFI_IP6;
14934 }
14935
14936 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14937 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14938 continue;
14939
14940 switch (type) {
14941 case show_all:
14942 bgp_show_peer(vty, peer, use_json, json);
14943 nbr_output = true;
14944 break;
14945 case show_peer:
14946 if (conf_if) {
14947 if ((peer->conf_if
14948 && !strcmp(peer->conf_if, conf_if))
14949 || (peer->hostname
14950 && !strcmp(peer->hostname, conf_if))) {
14951 find = 1;
14952 bgp_show_peer(vty, peer, use_json,
14953 json);
14954 }
14955 } else {
14956 if (sockunion_same(&peer->su, su)) {
14957 find = 1;
14958 bgp_show_peer(vty, peer, use_json,
14959 json);
14960 }
14961 }
14962 break;
14963 case show_ipv4_peer:
14964 case show_ipv6_peer:
14965 FOREACH_SAFI (safi) {
14966 if (peer->afc[afi][safi]) {
14967 if (conf_if) {
14968 if ((peer->conf_if
14969 && !strcmp(peer->conf_if, conf_if))
14970 || (peer->hostname
14971 && !strcmp(peer->hostname, conf_if))) {
14972 find = 1;
14973 bgp_show_peer(vty, peer, use_json,
14974 json);
14975 break;
14976 }
14977 } else {
14978 if (sockunion_same(&peer->su, su)) {
14979 find = 1;
14980 bgp_show_peer(vty, peer, use_json,
14981 json);
14982 break;
14983 }
14984 }
14985 }
14986 }
14987 break;
14988 case show_ipv4_all:
14989 case show_ipv6_all:
14990 FOREACH_SAFI (safi) {
14991 if (peer->afc[afi][safi]) {
14992 bgp_show_peer(vty, peer, use_json, json);
14993 nbr_output = true;
14994 break;
14995 }
14996 }
14997 break;
14998 }
14999 }
15000
15001 if ((type == show_peer || type == show_ipv4_peer ||
15002 type == show_ipv6_peer) && !find) {
15003 if (use_json)
15004 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15005 else
15006 vty_out(vty, "%% No such neighbor in this view/vrf\n");
15007 }
15008
15009 if (type != show_peer && type != show_ipv4_peer &&
15010 type != show_ipv6_peer && !nbr_output && !use_json)
15011 vty_out(vty, "%% No BGP neighbors found\n");
15012
15013 if (use_json) {
15014 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15015 json, JSON_C_TO_STRING_PRETTY));
15016 } else {
15017 vty_out(vty, "\n");
15018 }
15019
15020 return CMD_SUCCESS;
15021 }
15022
15023 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15024 enum show_type type,
15025 const char *ip_str,
15026 afi_t afi, json_object *json)
15027 {
15028
15029 int ret;
15030 struct bgp *bgp;
15031 union sockunion su;
15032
15033 bgp = bgp_get_default();
15034
15035 if (!bgp)
15036 return;
15037
15038 if (!json)
15039 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
15040
15041 if (ip_str) {
15042 ret = str2sockunion(ip_str, &su);
15043 if (ret < 0)
15044 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15045 ip_str, afi, json);
15046 else
15047 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15048 NULL, afi, json);
15049 } else
15050 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15051 afi, json);
15052 }
15053
15054 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15055 enum show_type type,
15056 const char *ip_str,
15057 bool use_json)
15058 {
15059 struct listnode *node, *nnode;
15060 struct bgp *bgp;
15061 union sockunion su;
15062 json_object *json = NULL;
15063 int ret, is_first = 1;
15064 bool nbr_output = false;
15065
15066 if (use_json)
15067 vty_out(vty, "{\n");
15068
15069 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15070 nbr_output = true;
15071 if (use_json) {
15072 if (!(json = json_object_new_object())) {
15073 flog_err(
15074 EC_BGP_JSON_MEM_ERROR,
15075 "Unable to allocate memory for JSON object");
15076 vty_out(vty,
15077 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15078 return;
15079 }
15080
15081 json_object_int_add(json, "vrfId",
15082 (bgp->vrf_id == VRF_UNKNOWN)
15083 ? -1
15084 : (int64_t)bgp->vrf_id);
15085 json_object_string_add(
15086 json, "vrfName",
15087 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15088 ? VRF_DEFAULT_NAME
15089 : bgp->name);
15090
15091 if (!is_first)
15092 vty_out(vty, ",\n");
15093 else
15094 is_first = 0;
15095
15096 vty_out(vty, "\"%s\":",
15097 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15098 ? VRF_DEFAULT_NAME
15099 : bgp->name);
15100 } else {
15101 vty_out(vty, "\nInstance %s:\n",
15102 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15103 ? VRF_DEFAULT_NAME
15104 : bgp->name);
15105 }
15106
15107 if (type == show_peer || type == show_ipv4_peer ||
15108 type == show_ipv6_peer) {
15109 ret = str2sockunion(ip_str, &su);
15110 if (ret < 0)
15111 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15112 use_json, json);
15113 else
15114 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15115 use_json, json);
15116 } else {
15117 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15118 use_json, json);
15119 }
15120 json_object_free(json);
15121 json = NULL;
15122 }
15123
15124 if (use_json)
15125 vty_out(vty, "}\n");
15126 else if (!nbr_output)
15127 vty_out(vty, "%% BGP instance not found\n");
15128 }
15129
15130 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15131 enum show_type type, const char *ip_str,
15132 bool use_json)
15133 {
15134 int ret;
15135 struct bgp *bgp;
15136 union sockunion su;
15137 json_object *json = NULL;
15138
15139 if (name) {
15140 if (strmatch(name, "all")) {
15141 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15142 use_json);
15143 return CMD_SUCCESS;
15144 } else {
15145 bgp = bgp_lookup_by_name(name);
15146 if (!bgp) {
15147 if (use_json) {
15148 json = json_object_new_object();
15149 vty_json(vty, json);
15150 } else
15151 vty_out(vty,
15152 "%% BGP instance not found\n");
15153
15154 return CMD_WARNING;
15155 }
15156 }
15157 } else {
15158 bgp = bgp_get_default();
15159 }
15160
15161 if (bgp) {
15162 json = json_object_new_object();
15163 if (ip_str) {
15164 ret = str2sockunion(ip_str, &su);
15165 if (ret < 0)
15166 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15167 use_json, json);
15168 else
15169 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15170 use_json, json);
15171 } else {
15172 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15173 json);
15174 }
15175 json_object_free(json);
15176 } else {
15177 if (use_json)
15178 vty_out(vty, "{}\n");
15179 else
15180 vty_out(vty, "%% BGP instance not found\n");
15181 }
15182
15183 return CMD_SUCCESS;
15184 }
15185
15186
15187
15188 /* "show [ip] bgp neighbors graceful-restart" commands. */
15189 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15190 show_ip_bgp_neighbors_graceful_restart_cmd,
15191 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15192 SHOW_STR
15193 BGP_STR
15194 IP_STR
15195 IPV6_STR
15196 NEIGHBOR_STR
15197 "Neighbor to display information about\n"
15198 "Neighbor to display information about\n"
15199 "Neighbor on BGP configured interface\n"
15200 GR_SHOW
15201 JSON_STR)
15202 {
15203 char *sh_arg = NULL;
15204 enum show_type sh_type;
15205 int idx = 0;
15206 afi_t afi = AFI_MAX;
15207 bool uj = use_json(argc, argv);
15208
15209 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15210 afi = AFI_MAX;
15211
15212 idx++;
15213
15214 if (argv_find(argv, argc, "A.B.C.D", &idx)
15215 || argv_find(argv, argc, "X:X::X:X", &idx)
15216 || argv_find(argv, argc, "WORD", &idx)) {
15217 sh_type = show_peer;
15218 sh_arg = argv[idx]->arg;
15219 } else
15220 sh_type = show_all;
15221
15222 if (!argv_find(argv, argc, "graceful-restart", &idx))
15223 return CMD_SUCCESS;
15224
15225
15226 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15227 afi, uj);
15228 }
15229
15230 /* "show [ip] bgp neighbors" commands. */
15231 DEFUN (show_ip_bgp_neighbors,
15232 show_ip_bgp_neighbors_cmd,
15233 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15234 SHOW_STR
15235 IP_STR
15236 BGP_STR
15237 BGP_INSTANCE_HELP_STR
15238 BGP_AF_STR
15239 BGP_AF_STR
15240 "Detailed information on TCP and BGP neighbor connections\n"
15241 "Neighbor to display information about\n"
15242 "Neighbor to display information about\n"
15243 "Neighbor on BGP configured interface\n"
15244 JSON_STR)
15245 {
15246 char *vrf = NULL;
15247 char *sh_arg = NULL;
15248 enum show_type sh_type;
15249 afi_t afi = AFI_MAX;
15250
15251 bool uj = use_json(argc, argv);
15252
15253 int idx = 0;
15254
15255 /* [<vrf> VIEWVRFNAME] */
15256 if (argv_find(argv, argc, "vrf", &idx)) {
15257 vrf = argv[idx + 1]->arg;
15258 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15259 vrf = NULL;
15260 } else if (argv_find(argv, argc, "view", &idx))
15261 /* [<view> VIEWVRFNAME] */
15262 vrf = argv[idx + 1]->arg;
15263
15264 idx++;
15265
15266 if (argv_find(argv, argc, "ipv4", &idx)) {
15267 sh_type = show_ipv4_all;
15268 afi = AFI_IP;
15269 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15270 sh_type = show_ipv6_all;
15271 afi = AFI_IP6;
15272 } else {
15273 sh_type = show_all;
15274 }
15275
15276 if (argv_find(argv, argc, "A.B.C.D", &idx)
15277 || argv_find(argv, argc, "X:X::X:X", &idx)
15278 || argv_find(argv, argc, "WORD", &idx)) {
15279 sh_type = show_peer;
15280 sh_arg = argv[idx]->arg;
15281 }
15282
15283 if (sh_type == show_peer && afi == AFI_IP) {
15284 sh_type = show_ipv4_peer;
15285 } else if (sh_type == show_peer && afi == AFI_IP6) {
15286 sh_type = show_ipv6_peer;
15287 }
15288
15289 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15290 }
15291
15292 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15293 paths' and `show ip mbgp paths'. Those functions results are the
15294 same.*/
15295 DEFUN (show_ip_bgp_paths,
15296 show_ip_bgp_paths_cmd,
15297 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15298 SHOW_STR
15299 IP_STR
15300 BGP_STR
15301 BGP_SAFI_HELP_STR
15302 "Path information\n")
15303 {
15304 vty_out(vty, "Address Refcnt Path\n");
15305 aspath_print_all_vty(vty);
15306 return CMD_SUCCESS;
15307 }
15308
15309 #include "hash.h"
15310
15311 static void community_show_all_iterator(struct hash_bucket *bucket,
15312 struct vty *vty)
15313 {
15314 struct community *com;
15315
15316 com = (struct community *)bucket->data;
15317 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15318 community_str(com, false, false));
15319 }
15320
15321 /* Show BGP's community internal data. */
15322 DEFUN (show_ip_bgp_community_info,
15323 show_ip_bgp_community_info_cmd,
15324 "show [ip] bgp community-info",
15325 SHOW_STR
15326 IP_STR
15327 BGP_STR
15328 "List all bgp community information\n")
15329 {
15330 vty_out(vty, "Address Refcnt Community\n");
15331
15332 hash_iterate(community_hash(),
15333 (void (*)(struct hash_bucket *,
15334 void *))community_show_all_iterator,
15335 vty);
15336
15337 return CMD_SUCCESS;
15338 }
15339
15340 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15341 struct vty *vty)
15342 {
15343 struct lcommunity *lcom;
15344
15345 lcom = (struct lcommunity *)bucket->data;
15346 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15347 lcommunity_str(lcom, false, false));
15348 }
15349
15350 /* Show BGP's community internal data. */
15351 DEFUN (show_ip_bgp_lcommunity_info,
15352 show_ip_bgp_lcommunity_info_cmd,
15353 "show ip bgp large-community-info",
15354 SHOW_STR
15355 IP_STR
15356 BGP_STR
15357 "List all bgp large-community information\n")
15358 {
15359 vty_out(vty, "Address Refcnt Large-community\n");
15360
15361 hash_iterate(lcommunity_hash(),
15362 (void (*)(struct hash_bucket *,
15363 void *))lcommunity_show_all_iterator,
15364 vty);
15365
15366 return CMD_SUCCESS;
15367 }
15368 /* Graceful Restart */
15369
15370 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15371 struct bgp *bgp)
15372 {
15373
15374
15375 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15376
15377 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15378
15379 switch (bgp_global_gr_mode) {
15380
15381 case GLOBAL_HELPER:
15382 vty_out(vty, "Global BGP GR Mode : Helper\n");
15383 break;
15384
15385 case GLOBAL_GR:
15386 vty_out(vty, "Global BGP GR Mode : Restart\n");
15387 break;
15388
15389 case GLOBAL_DISABLE:
15390 vty_out(vty, "Global BGP GR Mode : Disable\n");
15391 break;
15392
15393 case GLOBAL_INVALID:
15394 vty_out(vty,
15395 "Global BGP GR Mode Invalid\n");
15396 break;
15397 }
15398 vty_out(vty, "\n");
15399 }
15400
15401 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15402 enum show_type type,
15403 const char *ip_str,
15404 afi_t afi, bool use_json)
15405 {
15406 json_object *json = NULL;
15407
15408 if (use_json)
15409 json = json_object_new_object();
15410
15411 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15412 afi = AFI_IP;
15413
15414 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15415
15416 bgp_show_neighbor_graceful_restart_vty(
15417 vty, type, ip_str, afi, json);
15418 afi++;
15419 }
15420 } else if (afi != AFI_MAX) {
15421 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15422 json);
15423 } else {
15424 if (json)
15425 json_object_free(json);
15426 return CMD_ERR_INCOMPLETE;
15427 }
15428
15429 if (json)
15430 vty_json(vty, json);
15431
15432 return CMD_SUCCESS;
15433 }
15434 /* Graceful Restart */
15435
15436 DEFUN (show_ip_bgp_attr_info,
15437 show_ip_bgp_attr_info_cmd,
15438 "show [ip] bgp attribute-info",
15439 SHOW_STR
15440 IP_STR
15441 BGP_STR
15442 "List all bgp attribute information\n")
15443 {
15444 attr_show_all(vty);
15445 return CMD_SUCCESS;
15446 }
15447
15448 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15449 afi_t afi, safi_t safi,
15450 bool use_json, json_object *json)
15451 {
15452 struct bgp *bgp;
15453 struct listnode *node;
15454 char *vname;
15455 char *ecom_str;
15456 enum vpn_policy_direction dir;
15457
15458 if (json) {
15459 json_object *json_import_vrfs = NULL;
15460 json_object *json_export_vrfs = NULL;
15461
15462 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15463
15464 if (!bgp) {
15465 vty_json(vty, json);
15466
15467 return CMD_WARNING;
15468 }
15469
15470 /* Provide context for the block */
15471 json_object_string_add(json, "vrf", name ? name : "default");
15472 json_object_string_add(json, "afiSafi",
15473 get_afi_safi_str(afi, safi, true));
15474
15475 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15476 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15477 json_object_string_add(json, "importFromVrfs", "none");
15478 json_object_string_add(json, "importRts", "none");
15479 } else {
15480 json_import_vrfs = json_object_new_array();
15481
15482 for (ALL_LIST_ELEMENTS_RO(
15483 bgp->vpn_policy[afi].import_vrf,
15484 node, vname))
15485 json_object_array_add(json_import_vrfs,
15486 json_object_new_string(vname));
15487
15488 json_object_object_add(json, "importFromVrfs",
15489 json_import_vrfs);
15490 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15491 if (bgp->vpn_policy[afi].rtlist[dir]) {
15492 ecom_str = ecommunity_ecom2str(
15493 bgp->vpn_policy[afi].rtlist[dir],
15494 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15495 json_object_string_add(json, "importRts",
15496 ecom_str);
15497 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15498 } else
15499 json_object_string_add(json, "importRts",
15500 "none");
15501 }
15502
15503 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15504 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15505 json_object_string_add(json, "exportToVrfs", "none");
15506 json_object_string_add(json, "routeDistinguisher",
15507 "none");
15508 json_object_string_add(json, "exportRts", "none");
15509 } else {
15510 json_export_vrfs = json_object_new_array();
15511
15512 for (ALL_LIST_ELEMENTS_RO(
15513 bgp->vpn_policy[afi].export_vrf,
15514 node, vname))
15515 json_object_array_add(json_export_vrfs,
15516 json_object_new_string(vname));
15517 json_object_object_add(json, "exportToVrfs",
15518 json_export_vrfs);
15519 json_object_string_addf(json, "routeDistinguisher",
15520 "%pRD",
15521 &bgp->vpn_policy[afi].tovpn_rd);
15522
15523 dir = BGP_VPN_POLICY_DIR_TOVPN;
15524 if (bgp->vpn_policy[afi].rtlist[dir]) {
15525 ecom_str = ecommunity_ecom2str(
15526 bgp->vpn_policy[afi].rtlist[dir],
15527 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15528 json_object_string_add(json, "exportRts",
15529 ecom_str);
15530 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15531 } else
15532 json_object_string_add(json, "exportRts",
15533 "none");
15534 }
15535
15536 if (use_json) {
15537 vty_json(vty, json);
15538 }
15539 } else {
15540 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15541
15542 if (!bgp) {
15543 vty_out(vty, "%% No such BGP instance exist\n");
15544 return CMD_WARNING;
15545 }
15546
15547 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15548 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15549 vty_out(vty,
15550 "This VRF is not importing %s routes from any other VRF\n",
15551 get_afi_safi_str(afi, safi, false));
15552 else {
15553 vty_out(vty,
15554 "This VRF is importing %s routes from the following VRFs:\n",
15555 get_afi_safi_str(afi, safi, false));
15556
15557 for (ALL_LIST_ELEMENTS_RO(
15558 bgp->vpn_policy[afi].import_vrf,
15559 node, vname))
15560 vty_out(vty, " %s\n", vname);
15561
15562 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15563 ecom_str = NULL;
15564 if (bgp->vpn_policy[afi].rtlist[dir]) {
15565 ecom_str = ecommunity_ecom2str(
15566 bgp->vpn_policy[afi].rtlist[dir],
15567 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15568 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15569
15570 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15571 } else
15572 vty_out(vty, "Import RT(s):\n");
15573 }
15574
15575 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15576 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15577 vty_out(vty,
15578 "This VRF is not exporting %s routes to any other VRF\n",
15579 get_afi_safi_str(afi, safi, false));
15580 else {
15581 vty_out(vty,
15582 "This VRF is exporting %s routes to the following VRFs:\n",
15583 get_afi_safi_str(afi, safi, false));
15584
15585 for (ALL_LIST_ELEMENTS_RO(
15586 bgp->vpn_policy[afi].export_vrf,
15587 node, vname))
15588 vty_out(vty, " %s\n", vname);
15589
15590 vty_out(vty, "RD: %pRD\n",
15591 &bgp->vpn_policy[afi].tovpn_rd);
15592
15593 dir = BGP_VPN_POLICY_DIR_TOVPN;
15594 if (bgp->vpn_policy[afi].rtlist[dir]) {
15595 ecom_str = ecommunity_ecom2str(
15596 bgp->vpn_policy[afi].rtlist[dir],
15597 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15598 vty_out(vty, "Export RT: %s\n", ecom_str);
15599 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15600 } else
15601 vty_out(vty, "Import RT(s):\n");
15602 }
15603 }
15604
15605 return CMD_SUCCESS;
15606 }
15607
15608 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15609 safi_t safi, bool use_json)
15610 {
15611 struct listnode *node, *nnode;
15612 struct bgp *bgp;
15613 char *vrf_name = NULL;
15614 json_object *json = NULL;
15615 json_object *json_vrf = NULL;
15616 json_object *json_vrfs = NULL;
15617
15618 if (use_json) {
15619 json = json_object_new_object();
15620 json_vrfs = json_object_new_object();
15621 }
15622
15623 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15624
15625 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15626 vrf_name = bgp->name;
15627
15628 if (use_json) {
15629 json_vrf = json_object_new_object();
15630 } else {
15631 vty_out(vty, "\nInstance %s:\n",
15632 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15633 ? VRF_DEFAULT_NAME : bgp->name);
15634 }
15635 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15636 if (use_json) {
15637 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15638 json_object_object_add(json_vrfs,
15639 VRF_DEFAULT_NAME, json_vrf);
15640 else
15641 json_object_object_add(json_vrfs, vrf_name,
15642 json_vrf);
15643 }
15644 }
15645
15646 if (use_json) {
15647 json_object_object_add(json, "vrfs", json_vrfs);
15648 vty_json(vty, json);
15649 }
15650
15651 return CMD_SUCCESS;
15652 }
15653
15654 /* "show [ip] bgp route-leak" command. */
15655 DEFUN (show_ip_bgp_route_leak,
15656 show_ip_bgp_route_leak_cmd,
15657 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15658 SHOW_STR
15659 IP_STR
15660 BGP_STR
15661 BGP_INSTANCE_HELP_STR
15662 BGP_AFI_HELP_STR
15663 BGP_SAFI_HELP_STR
15664 "Route leaking information\n"
15665 JSON_STR)
15666 {
15667 char *vrf = NULL;
15668 afi_t afi = AFI_MAX;
15669 safi_t safi = SAFI_MAX;
15670
15671 bool uj = use_json(argc, argv);
15672 int idx = 0;
15673 json_object *json = NULL;
15674
15675 /* show [ip] bgp */
15676 if (argv_find(argv, argc, "ip", &idx)) {
15677 afi = AFI_IP;
15678 safi = SAFI_UNICAST;
15679 }
15680 /* [vrf VIEWVRFNAME] */
15681 if (argv_find(argv, argc, "view", &idx)) {
15682 vty_out(vty,
15683 "%% This command is not applicable to BGP views\n");
15684 return CMD_WARNING;
15685 }
15686
15687 if (argv_find(argv, argc, "vrf", &idx)) {
15688 vrf = argv[idx + 1]->arg;
15689 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15690 vrf = NULL;
15691 }
15692 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15693 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15694 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15695
15696 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15697 vty_out(vty,
15698 "%% This command is applicable only for unicast ipv4|ipv6\n");
15699 return CMD_WARNING;
15700 }
15701
15702 if (vrf && strmatch(vrf, "all"))
15703 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15704
15705 if (uj)
15706 json = json_object_new_object();
15707
15708 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15709 }
15710
15711 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15712 safi_t safi, bool uj)
15713 {
15714 struct listnode *node, *nnode;
15715 struct bgp *bgp;
15716
15717 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15718 if (!uj)
15719 vty_out(vty, "\nInstance %s:\n",
15720 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15721 ? VRF_DEFAULT_NAME
15722 : bgp->name);
15723
15724 update_group_show(bgp, afi, safi, vty, 0, uj);
15725 }
15726 }
15727
15728 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15729 int safi, uint64_t subgrp_id, bool uj)
15730 {
15731 struct bgp *bgp;
15732
15733 if (name) {
15734 if (strmatch(name, "all")) {
15735 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15736 return CMD_SUCCESS;
15737 } else {
15738 bgp = bgp_lookup_by_name(name);
15739 }
15740 } else {
15741 bgp = bgp_get_default();
15742 }
15743
15744 if (bgp)
15745 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15746 return CMD_SUCCESS;
15747 }
15748
15749 DEFUN (show_ip_bgp_updgrps,
15750 show_ip_bgp_updgrps_cmd,
15751 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15752 SHOW_STR
15753 IP_STR
15754 BGP_STR
15755 BGP_INSTANCE_HELP_STR
15756 BGP_AFI_HELP_STR
15757 BGP_SAFI_WITH_LABEL_HELP_STR
15758 "Detailed info about dynamic update groups\n"
15759 "Specific subgroup to display detailed info for\n"
15760 JSON_STR)
15761 {
15762 char *vrf = NULL;
15763 afi_t afi = AFI_IP6;
15764 safi_t safi = SAFI_UNICAST;
15765 uint64_t subgrp_id = 0;
15766
15767 int idx = 0;
15768
15769 bool uj = use_json(argc, argv);
15770
15771 /* show [ip] bgp */
15772 if (argv_find(argv, argc, "ip", &idx))
15773 afi = AFI_IP;
15774 /* [<vrf> VIEWVRFNAME] */
15775 if (argv_find(argv, argc, "vrf", &idx)) {
15776 vrf = argv[idx + 1]->arg;
15777 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15778 vrf = NULL;
15779 } else if (argv_find(argv, argc, "view", &idx))
15780 /* [<view> VIEWVRFNAME] */
15781 vrf = argv[idx + 1]->arg;
15782 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15783 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15784 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15785 }
15786
15787 /* get subgroup id, if provided */
15788 idx = argc - 1;
15789 if (argv[idx]->type == VARIABLE_TKN)
15790 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15791
15792 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15793 }
15794
15795 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15796 show_bgp_instance_all_ipv6_updgrps_cmd,
15797 "show [ip] bgp <view|vrf> all update-groups [json]",
15798 SHOW_STR
15799 IP_STR
15800 BGP_STR
15801 BGP_INSTANCE_ALL_HELP_STR
15802 "Detailed info about dynamic update groups\n"
15803 JSON_STR)
15804 {
15805 bool uj = use_json(argc, argv);
15806
15807 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15808 return CMD_SUCCESS;
15809 }
15810
15811 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15812 show_bgp_l2vpn_evpn_updgrps_cmd,
15813 "show [ip] bgp l2vpn evpn update-groups",
15814 SHOW_STR
15815 IP_STR
15816 BGP_STR
15817 "l2vpn address family\n"
15818 "evpn sub-address family\n"
15819 "Detailed info about dynamic update groups\n")
15820 {
15821 char *vrf = NULL;
15822 uint64_t subgrp_id = 0;
15823
15824 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15825 return CMD_SUCCESS;
15826 }
15827
15828 DEFUN (show_bgp_updgrps_stats,
15829 show_bgp_updgrps_stats_cmd,
15830 "show [ip] bgp update-groups statistics",
15831 SHOW_STR
15832 IP_STR
15833 BGP_STR
15834 "Detailed info about dynamic update groups\n"
15835 "Statistics\n")
15836 {
15837 struct bgp *bgp;
15838
15839 bgp = bgp_get_default();
15840 if (bgp)
15841 update_group_show_stats(bgp, vty);
15842
15843 return CMD_SUCCESS;
15844 }
15845
15846 DEFUN (show_bgp_instance_updgrps_stats,
15847 show_bgp_instance_updgrps_stats_cmd,
15848 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15849 SHOW_STR
15850 IP_STR
15851 BGP_STR
15852 BGP_INSTANCE_HELP_STR
15853 "Detailed info about dynamic update groups\n"
15854 "Statistics\n")
15855 {
15856 int idx_word = 3;
15857 struct bgp *bgp;
15858
15859 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15860 if (bgp)
15861 update_group_show_stats(bgp, vty);
15862
15863 return CMD_SUCCESS;
15864 }
15865
15866 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15867 afi_t afi, safi_t safi,
15868 const char *what, uint64_t subgrp_id)
15869 {
15870 struct bgp *bgp;
15871
15872 if (name)
15873 bgp = bgp_lookup_by_name(name);
15874 else
15875 bgp = bgp_get_default();
15876
15877 if (bgp) {
15878 if (!strcmp(what, "advertise-queue"))
15879 update_group_show_adj_queue(bgp, afi, safi, vty,
15880 subgrp_id);
15881 else if (!strcmp(what, "advertised-routes"))
15882 update_group_show_advertised(bgp, afi, safi, vty,
15883 subgrp_id);
15884 else if (!strcmp(what, "packet-queue"))
15885 update_group_show_packet_queue(bgp, afi, safi, vty,
15886 subgrp_id);
15887 }
15888 }
15889
15890 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15891 show_ip_bgp_instance_updgrps_adj_s_cmd,
15892 "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",
15893 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15894 BGP_SAFI_HELP_STR
15895 "Detailed info about dynamic update groups\n"
15896 "Specific subgroup to display info for\n"
15897 "Advertisement queue\n"
15898 "Announced routes\n"
15899 "Packet queue\n")
15900 {
15901 uint64_t subgrp_id = 0;
15902 afi_t afiz;
15903 safi_t safiz;
15904 if (sgid)
15905 subgrp_id = strtoull(sgid, NULL, 10);
15906
15907 if (!ip && !afi)
15908 afiz = AFI_IP6;
15909 if (!ip && afi)
15910 afiz = bgp_vty_afi_from_str(afi);
15911 if (ip && !afi)
15912 afiz = AFI_IP;
15913 if (ip && afi) {
15914 afiz = bgp_vty_afi_from_str(afi);
15915 if (afiz != AFI_IP)
15916 vty_out(vty,
15917 "%% Cannot specify both 'ip' and 'ipv6'\n");
15918 return CMD_WARNING;
15919 }
15920
15921 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15922
15923 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15924 return CMD_SUCCESS;
15925 }
15926
15927 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15928 json_object *json)
15929 {
15930 struct listnode *node, *nnode;
15931 struct prefix *range;
15932 struct peer *conf;
15933 struct peer *peer;
15934 afi_t afi;
15935 safi_t safi;
15936 const char *peer_status;
15937 int lr_count;
15938 int dynamic;
15939 bool af_cfgd;
15940 json_object *json_peer_group = NULL;
15941 json_object *json_peer_group_afc = NULL;
15942 json_object *json_peer_group_members = NULL;
15943 json_object *json_peer_group_dynamic = NULL;
15944 json_object *json_peer_group_dynamic_af = NULL;
15945 json_object *json_peer_group_ranges = NULL;
15946
15947 conf = group->conf;
15948
15949 if (json) {
15950 json_peer_group = json_object_new_object();
15951 json_peer_group_afc = json_object_new_array();
15952 }
15953
15954 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15955 if (json)
15956 json_object_int_add(json_peer_group, "remoteAs",
15957 conf->as);
15958 else
15959 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15960 group->name, conf->as);
15961 } else if (conf->as_type == AS_INTERNAL) {
15962 if (json)
15963 json_object_int_add(json_peer_group, "remoteAs",
15964 group->bgp->as);
15965 else
15966 vty_out(vty, "\nBGP peer-group %s, remote AS %s\n",
15967 group->name, group->bgp->as_pretty);
15968 } else {
15969 if (!json)
15970 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15971 }
15972
15973 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15974 if (json)
15975 json_object_string_add(json_peer_group, "type",
15976 "internal");
15977 else
15978 vty_out(vty, " Peer-group type is internal\n");
15979 } else {
15980 if (json)
15981 json_object_string_add(json_peer_group, "type",
15982 "external");
15983 else
15984 vty_out(vty, " Peer-group type is external\n");
15985 }
15986
15987 /* Display AFs configured. */
15988 if (!json)
15989 vty_out(vty, " Configured address-families:");
15990
15991 FOREACH_AFI_SAFI (afi, safi) {
15992 if (conf->afc[afi][safi]) {
15993 af_cfgd = true;
15994 if (json)
15995 json_object_array_add(
15996 json_peer_group_afc,
15997 json_object_new_string(get_afi_safi_str(
15998 afi, safi, false)));
15999 else
16000 vty_out(vty, " %s;",
16001 get_afi_safi_str(afi, safi, false));
16002 }
16003 }
16004
16005 if (json) {
16006 json_object_object_add(json_peer_group,
16007 "addressFamiliesConfigured",
16008 json_peer_group_afc);
16009 } else {
16010 if (!af_cfgd)
16011 vty_out(vty, " none\n");
16012 else
16013 vty_out(vty, "\n");
16014 }
16015
16016 /* Display listen ranges (for dynamic neighbors), if any */
16017 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
16018 lr_count = listcount(group->listen_range[afi]);
16019 if (lr_count) {
16020 if (json) {
16021 if (!json_peer_group_dynamic)
16022 json_peer_group_dynamic =
16023 json_object_new_object();
16024
16025 json_peer_group_dynamic_af =
16026 json_object_new_object();
16027 json_peer_group_ranges =
16028 json_object_new_array();
16029 json_object_int_add(json_peer_group_dynamic_af,
16030 "count", lr_count);
16031 } else {
16032 vty_out(vty, " %d %s listen range(s)\n",
16033 lr_count, afi2str(afi));
16034 }
16035
16036 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
16037 nnode, range)) {
16038 if (json) {
16039 char buf[BUFSIZ];
16040
16041 snprintfrr(buf, sizeof(buf), "%pFX",
16042 range);
16043
16044 json_object_array_add(
16045 json_peer_group_ranges,
16046 json_object_new_string(buf));
16047 } else {
16048 vty_out(vty, " %pFX\n", range);
16049 }
16050 }
16051
16052 if (json) {
16053 json_object_object_add(
16054 json_peer_group_dynamic_af, "ranges",
16055 json_peer_group_ranges);
16056
16057 json_object_object_add(
16058 json_peer_group_dynamic, afi2str(afi),
16059 json_peer_group_dynamic_af);
16060 }
16061 }
16062 }
16063
16064 if (json_peer_group_dynamic)
16065 json_object_object_add(json_peer_group, "dynamicRanges",
16066 json_peer_group_dynamic);
16067
16068 /* Display group members and their status */
16069 if (listcount(group->peer)) {
16070 if (json)
16071 json_peer_group_members = json_object_new_object();
16072 else
16073 vty_out(vty, " Peer-group members:\n");
16074 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16075 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16076 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16077 peer_status = "Idle (Admin)";
16078 else if (CHECK_FLAG(peer->sflags,
16079 PEER_STATUS_PREFIX_OVERFLOW))
16080 peer_status = "Idle (PfxCt)";
16081 else
16082 peer_status = lookup_msg(bgp_status_msg,
16083 peer->status, NULL);
16084
16085 dynamic = peer_dynamic_neighbor(peer);
16086
16087 if (json) {
16088 json_object *json_peer_group_member =
16089 json_object_new_object();
16090
16091 json_object_string_add(json_peer_group_member,
16092 "status", peer_status);
16093
16094 if (dynamic)
16095 json_object_boolean_true_add(
16096 json_peer_group_member,
16097 "dynamic");
16098
16099 json_object_object_add(json_peer_group_members,
16100 peer->host,
16101 json_peer_group_member);
16102 } else {
16103 vty_out(vty, " %s %s %s \n", peer->host,
16104 dynamic ? "(dynamic)" : "",
16105 peer_status);
16106 }
16107 }
16108 if (json)
16109 json_object_object_add(json_peer_group, "members",
16110 json_peer_group_members);
16111 }
16112
16113 if (json)
16114 json_object_object_add(json, group->name, json_peer_group);
16115
16116 return CMD_SUCCESS;
16117 }
16118
16119 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16120 const char *group_name, bool uj)
16121 {
16122 struct bgp *bgp;
16123 struct listnode *node, *nnode;
16124 struct peer_group *group;
16125 bool found = false;
16126 json_object *json = NULL;
16127
16128 if (uj)
16129 json = json_object_new_object();
16130
16131 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16132
16133 if (!bgp) {
16134 if (uj)
16135 vty_json(vty, json);
16136 else
16137 vty_out(vty, "%% BGP instance not found\n");
16138
16139 return CMD_WARNING;
16140 }
16141
16142 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16143 if (group_name) {
16144 if (strmatch(group->name, group_name)) {
16145 bgp_show_one_peer_group(vty, group, json);
16146 found = true;
16147 break;
16148 }
16149 } else {
16150 bgp_show_one_peer_group(vty, group, json);
16151 }
16152 }
16153
16154 if (group_name && !found && !uj)
16155 vty_out(vty, "%% No such peer-group\n");
16156
16157 if (uj)
16158 vty_json(vty, json);
16159
16160 return CMD_SUCCESS;
16161 }
16162
16163 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16164 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16165 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16166 "Detailed information on BGP peer groups\n"
16167 "Peer group name\n" JSON_STR)
16168 {
16169 char *vrf, *pg;
16170 int idx = 0;
16171 bool uj = use_json(argc, argv);
16172
16173 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16174 : NULL;
16175 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16176
16177 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16178 }
16179
16180
16181 /* Redistribute VTY commands. */
16182
16183 DEFUN (bgp_redistribute_ipv4,
16184 bgp_redistribute_ipv4_cmd,
16185 "redistribute " FRR_IP_REDIST_STR_BGPD,
16186 "Redistribute information from another routing protocol\n"
16187 FRR_IP_REDIST_HELP_STR_BGPD)
16188 {
16189 VTY_DECLVAR_CONTEXT(bgp, bgp);
16190 int idx_protocol = 1;
16191 int type;
16192
16193 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16194 if (type < 0) {
16195 vty_out(vty, "%% Invalid route type\n");
16196 return CMD_WARNING_CONFIG_FAILED;
16197 }
16198
16199 bgp_redist_add(bgp, AFI_IP, type, 0);
16200 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16201 }
16202
16203 ALIAS_HIDDEN(
16204 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16205 "redistribute " FRR_IP_REDIST_STR_BGPD,
16206 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16207
16208 DEFUN (bgp_redistribute_ipv4_rmap,
16209 bgp_redistribute_ipv4_rmap_cmd,
16210 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16211 "Redistribute information from another routing protocol\n"
16212 FRR_IP_REDIST_HELP_STR_BGPD
16213 "Route map reference\n"
16214 "Pointer to route-map entries\n")
16215 {
16216 VTY_DECLVAR_CONTEXT(bgp, bgp);
16217 int idx_protocol = 1;
16218 int idx_word = 3;
16219 int type;
16220 struct bgp_redist *red;
16221 bool changed;
16222 struct route_map *route_map = route_map_lookup_warn_noexist(
16223 vty, argv[idx_word]->arg);
16224
16225 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16226 if (type < 0) {
16227 vty_out(vty, "%% Invalid route type\n");
16228 return CMD_WARNING_CONFIG_FAILED;
16229 }
16230
16231 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16232 changed =
16233 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16234 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16235 }
16236
16237 ALIAS_HIDDEN(
16238 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16239 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16240 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16241 "Route map reference\n"
16242 "Pointer to route-map entries\n")
16243
16244 DEFUN (bgp_redistribute_ipv4_metric,
16245 bgp_redistribute_ipv4_metric_cmd,
16246 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16247 "Redistribute information from another routing protocol\n"
16248 FRR_IP_REDIST_HELP_STR_BGPD
16249 "Metric for redistributed routes\n"
16250 "Default metric\n")
16251 {
16252 VTY_DECLVAR_CONTEXT(bgp, bgp);
16253 int idx_protocol = 1;
16254 int idx_number = 3;
16255 int type;
16256 uint32_t metric;
16257 struct bgp_redist *red;
16258 bool changed;
16259
16260 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16261 if (type < 0) {
16262 vty_out(vty, "%% Invalid route type\n");
16263 return CMD_WARNING_CONFIG_FAILED;
16264 }
16265 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16266
16267 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16268 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16269 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16270 }
16271
16272 ALIAS_HIDDEN(
16273 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16274 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16275 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16276 "Metric for redistributed routes\n"
16277 "Default metric\n")
16278
16279 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16280 bgp_redistribute_ipv4_rmap_metric_cmd,
16281 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16282 "Redistribute information from another routing protocol\n"
16283 FRR_IP_REDIST_HELP_STR_BGPD
16284 "Route map reference\n"
16285 "Pointer to route-map entries\n"
16286 "Metric for redistributed routes\n"
16287 "Default metric\n")
16288 {
16289 VTY_DECLVAR_CONTEXT(bgp, bgp);
16290 int idx_protocol = 1;
16291 int idx_word = 3;
16292 int idx_number = 5;
16293 int type;
16294 uint32_t metric;
16295 struct bgp_redist *red;
16296 bool changed;
16297 struct route_map *route_map =
16298 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16299
16300 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16301 if (type < 0) {
16302 vty_out(vty, "%% Invalid route type\n");
16303 return CMD_WARNING_CONFIG_FAILED;
16304 }
16305 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16306
16307 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16308 changed =
16309 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16310 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16311 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16312 }
16313
16314 ALIAS_HIDDEN(
16315 bgp_redistribute_ipv4_rmap_metric,
16316 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16317 "redistribute " FRR_IP_REDIST_STR_BGPD
16318 " route-map RMAP_NAME metric (0-4294967295)",
16319 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16320 "Route map reference\n"
16321 "Pointer to route-map entries\n"
16322 "Metric for redistributed routes\n"
16323 "Default metric\n")
16324
16325 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16326 bgp_redistribute_ipv4_metric_rmap_cmd,
16327 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16328 "Redistribute information from another routing protocol\n"
16329 FRR_IP_REDIST_HELP_STR_BGPD
16330 "Metric for redistributed routes\n"
16331 "Default metric\n"
16332 "Route map reference\n"
16333 "Pointer to route-map entries\n")
16334 {
16335 VTY_DECLVAR_CONTEXT(bgp, bgp);
16336 int idx_protocol = 1;
16337 int idx_number = 3;
16338 int idx_word = 5;
16339 int type;
16340 uint32_t metric;
16341 struct bgp_redist *red;
16342 bool changed;
16343 struct route_map *route_map =
16344 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16345
16346 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16347 if (type < 0) {
16348 vty_out(vty, "%% Invalid route type\n");
16349 return CMD_WARNING_CONFIG_FAILED;
16350 }
16351 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16352
16353 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16354 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16355 changed |=
16356 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16357 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16358 }
16359
16360 ALIAS_HIDDEN(
16361 bgp_redistribute_ipv4_metric_rmap,
16362 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16363 "redistribute " FRR_IP_REDIST_STR_BGPD
16364 " metric (0-4294967295) route-map RMAP_NAME",
16365 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16366 "Metric for redistributed routes\n"
16367 "Default metric\n"
16368 "Route map reference\n"
16369 "Pointer to route-map entries\n")
16370
16371 DEFUN (bgp_redistribute_ipv4_ospf,
16372 bgp_redistribute_ipv4_ospf_cmd,
16373 "redistribute <ospf|table> (1-65535)",
16374 "Redistribute information from another routing protocol\n"
16375 "Open Shortest Path First (OSPFv2)\n"
16376 "Non-main Kernel Routing Table\n"
16377 "Instance ID/Table ID\n")
16378 {
16379 VTY_DECLVAR_CONTEXT(bgp, bgp);
16380 int idx_ospf_table = 1;
16381 int idx_number = 2;
16382 unsigned short instance;
16383 unsigned short protocol;
16384
16385 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16386
16387 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16388 protocol = ZEBRA_ROUTE_OSPF;
16389 else
16390 protocol = ZEBRA_ROUTE_TABLE;
16391
16392 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16393 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16394 }
16395
16396 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16397 "redistribute <ospf|table> (1-65535)",
16398 "Redistribute information from another routing protocol\n"
16399 "Open Shortest Path First (OSPFv2)\n"
16400 "Non-main Kernel Routing Table\n"
16401 "Instance ID/Table ID\n")
16402
16403 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16404 bgp_redistribute_ipv4_ospf_rmap_cmd,
16405 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16406 "Redistribute information from another routing protocol\n"
16407 "Open Shortest Path First (OSPFv2)\n"
16408 "Non-main Kernel Routing Table\n"
16409 "Instance ID/Table ID\n"
16410 "Route map reference\n"
16411 "Pointer to route-map entries\n")
16412 {
16413 VTY_DECLVAR_CONTEXT(bgp, bgp);
16414 int idx_ospf_table = 1;
16415 int idx_number = 2;
16416 int idx_word = 4;
16417 struct bgp_redist *red;
16418 unsigned short instance;
16419 int protocol;
16420 bool changed;
16421 struct route_map *route_map =
16422 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16423
16424 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16425 protocol = ZEBRA_ROUTE_OSPF;
16426 else
16427 protocol = ZEBRA_ROUTE_TABLE;
16428
16429 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16430 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16431 changed =
16432 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16433 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16434 }
16435
16436 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16437 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16438 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16439 "Redistribute information from another routing protocol\n"
16440 "Open Shortest Path First (OSPFv2)\n"
16441 "Non-main Kernel Routing Table\n"
16442 "Instance ID/Table ID\n"
16443 "Route map reference\n"
16444 "Pointer to route-map entries\n")
16445
16446 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16447 bgp_redistribute_ipv4_ospf_metric_cmd,
16448 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16449 "Redistribute information from another routing protocol\n"
16450 "Open Shortest Path First (OSPFv2)\n"
16451 "Non-main Kernel Routing Table\n"
16452 "Instance ID/Table ID\n"
16453 "Metric for redistributed routes\n"
16454 "Default metric\n")
16455 {
16456 VTY_DECLVAR_CONTEXT(bgp, bgp);
16457 int idx_ospf_table = 1;
16458 int idx_number = 2;
16459 int idx_number_2 = 4;
16460 uint32_t metric;
16461 struct bgp_redist *red;
16462 unsigned short instance;
16463 int protocol;
16464 bool changed;
16465
16466 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16467 protocol = ZEBRA_ROUTE_OSPF;
16468 else
16469 protocol = ZEBRA_ROUTE_TABLE;
16470
16471 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16472 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16473
16474 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16475 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16476 metric);
16477 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16478 }
16479
16480 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16481 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16482 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16483 "Redistribute information from another routing protocol\n"
16484 "Open Shortest Path First (OSPFv2)\n"
16485 "Non-main Kernel Routing Table\n"
16486 "Instance ID/Table ID\n"
16487 "Metric for redistributed routes\n"
16488 "Default metric\n")
16489
16490 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16491 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16492 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16493 "Redistribute information from another routing protocol\n"
16494 "Open Shortest Path First (OSPFv2)\n"
16495 "Non-main Kernel Routing Table\n"
16496 "Instance ID/Table ID\n"
16497 "Route map reference\n"
16498 "Pointer to route-map entries\n"
16499 "Metric for redistributed routes\n"
16500 "Default metric\n")
16501 {
16502 VTY_DECLVAR_CONTEXT(bgp, bgp);
16503 int idx_ospf_table = 1;
16504 int idx_number = 2;
16505 int idx_word = 4;
16506 int idx_number_2 = 6;
16507 uint32_t metric;
16508 struct bgp_redist *red;
16509 unsigned short instance;
16510 int protocol;
16511 bool changed;
16512 struct route_map *route_map =
16513 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16514
16515 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16516 protocol = ZEBRA_ROUTE_OSPF;
16517 else
16518 protocol = ZEBRA_ROUTE_TABLE;
16519
16520 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16521 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16522
16523 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16524 changed =
16525 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16526 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16527 metric);
16528 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16529 }
16530
16531 ALIAS_HIDDEN(
16532 bgp_redistribute_ipv4_ospf_rmap_metric,
16533 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16534 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16535 "Redistribute information from another routing protocol\n"
16536 "Open Shortest Path First (OSPFv2)\n"
16537 "Non-main Kernel Routing Table\n"
16538 "Instance ID/Table ID\n"
16539 "Route map reference\n"
16540 "Pointer to route-map entries\n"
16541 "Metric for redistributed routes\n"
16542 "Default metric\n")
16543
16544 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16545 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16546 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16547 "Redistribute information from another routing protocol\n"
16548 "Open Shortest Path First (OSPFv2)\n"
16549 "Non-main Kernel Routing Table\n"
16550 "Instance ID/Table ID\n"
16551 "Metric for redistributed routes\n"
16552 "Default metric\n"
16553 "Route map reference\n"
16554 "Pointer to route-map entries\n")
16555 {
16556 VTY_DECLVAR_CONTEXT(bgp, bgp);
16557 int idx_ospf_table = 1;
16558 int idx_number = 2;
16559 int idx_number_2 = 4;
16560 int idx_word = 6;
16561 uint32_t metric;
16562 struct bgp_redist *red;
16563 unsigned short instance;
16564 int protocol;
16565 bool changed;
16566 struct route_map *route_map =
16567 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16568
16569 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16570 protocol = ZEBRA_ROUTE_OSPF;
16571 else
16572 protocol = ZEBRA_ROUTE_TABLE;
16573
16574 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16575 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16576
16577 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16578 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16579 metric);
16580 changed |=
16581 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16582 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16583 }
16584
16585 ALIAS_HIDDEN(
16586 bgp_redistribute_ipv4_ospf_metric_rmap,
16587 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16588 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16589 "Redistribute information from another routing protocol\n"
16590 "Open Shortest Path First (OSPFv2)\n"
16591 "Non-main Kernel Routing Table\n"
16592 "Instance ID/Table ID\n"
16593 "Metric for redistributed routes\n"
16594 "Default metric\n"
16595 "Route map reference\n"
16596 "Pointer to route-map entries\n")
16597
16598 DEFUN (no_bgp_redistribute_ipv4_ospf,
16599 no_bgp_redistribute_ipv4_ospf_cmd,
16600 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16601 NO_STR
16602 "Redistribute information from another routing protocol\n"
16603 "Open Shortest Path First (OSPFv2)\n"
16604 "Non-main Kernel Routing Table\n"
16605 "Instance ID/Table ID\n"
16606 "Metric for redistributed routes\n"
16607 "Default metric\n"
16608 "Route map reference\n"
16609 "Pointer to route-map entries\n")
16610 {
16611 VTY_DECLVAR_CONTEXT(bgp, bgp);
16612 int idx_ospf_table = 2;
16613 int idx_number = 3;
16614 unsigned short instance;
16615 int protocol;
16616
16617 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16618 protocol = ZEBRA_ROUTE_OSPF;
16619 else
16620 protocol = ZEBRA_ROUTE_TABLE;
16621
16622 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16623 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16624 }
16625
16626 ALIAS_HIDDEN(
16627 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16628 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16629 NO_STR
16630 "Redistribute information from another routing protocol\n"
16631 "Open Shortest Path First (OSPFv2)\n"
16632 "Non-main Kernel Routing Table\n"
16633 "Instance ID/Table ID\n"
16634 "Metric for redistributed routes\n"
16635 "Default metric\n"
16636 "Route map reference\n"
16637 "Pointer to route-map entries\n")
16638
16639 DEFUN (no_bgp_redistribute_ipv4,
16640 no_bgp_redistribute_ipv4_cmd,
16641 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16642 NO_STR
16643 "Redistribute information from another routing protocol\n"
16644 FRR_IP_REDIST_HELP_STR_BGPD
16645 "Metric for redistributed routes\n"
16646 "Default metric\n"
16647 "Route map reference\n"
16648 "Pointer to route-map entries\n")
16649 {
16650 VTY_DECLVAR_CONTEXT(bgp, bgp);
16651 int idx_protocol = 2;
16652 int type;
16653
16654 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16655 if (type < 0) {
16656 vty_out(vty, "%% Invalid route type\n");
16657 return CMD_WARNING_CONFIG_FAILED;
16658 }
16659 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16660 }
16661
16662 ALIAS_HIDDEN(
16663 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16664 "no redistribute " FRR_IP_REDIST_STR_BGPD
16665 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16666 NO_STR
16667 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16668 "Metric for redistributed routes\n"
16669 "Default metric\n"
16670 "Route map reference\n"
16671 "Pointer to route-map entries\n")
16672
16673 DEFUN (bgp_redistribute_ipv6,
16674 bgp_redistribute_ipv6_cmd,
16675 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16676 "Redistribute information from another routing protocol\n"
16677 FRR_IP6_REDIST_HELP_STR_BGPD)
16678 {
16679 VTY_DECLVAR_CONTEXT(bgp, bgp);
16680 int idx_protocol = 1;
16681 int type;
16682
16683 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16684 if (type < 0) {
16685 vty_out(vty, "%% Invalid route type\n");
16686 return CMD_WARNING_CONFIG_FAILED;
16687 }
16688
16689 bgp_redist_add(bgp, AFI_IP6, type, 0);
16690 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16691 }
16692
16693 DEFUN (bgp_redistribute_ipv6_rmap,
16694 bgp_redistribute_ipv6_rmap_cmd,
16695 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16696 "Redistribute information from another routing protocol\n"
16697 FRR_IP6_REDIST_HELP_STR_BGPD
16698 "Route map reference\n"
16699 "Pointer to route-map entries\n")
16700 {
16701 VTY_DECLVAR_CONTEXT(bgp, bgp);
16702 int idx_protocol = 1;
16703 int idx_word = 3;
16704 int type;
16705 struct bgp_redist *red;
16706 bool changed;
16707 struct route_map *route_map =
16708 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16709
16710 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16711 if (type < 0) {
16712 vty_out(vty, "%% Invalid route type\n");
16713 return CMD_WARNING_CONFIG_FAILED;
16714 }
16715
16716 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16717 changed =
16718 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16719 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16720 }
16721
16722 DEFUN (bgp_redistribute_ipv6_metric,
16723 bgp_redistribute_ipv6_metric_cmd,
16724 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16725 "Redistribute information from another routing protocol\n"
16726 FRR_IP6_REDIST_HELP_STR_BGPD
16727 "Metric for redistributed routes\n"
16728 "Default metric\n")
16729 {
16730 VTY_DECLVAR_CONTEXT(bgp, bgp);
16731 int idx_protocol = 1;
16732 int idx_number = 3;
16733 int type;
16734 uint32_t metric;
16735 struct bgp_redist *red;
16736 bool changed;
16737
16738 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16739 if (type < 0) {
16740 vty_out(vty, "%% Invalid route type\n");
16741 return CMD_WARNING_CONFIG_FAILED;
16742 }
16743 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16744
16745 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16746 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16747 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16748 }
16749
16750 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16751 bgp_redistribute_ipv6_rmap_metric_cmd,
16752 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16753 "Redistribute information from another routing protocol\n"
16754 FRR_IP6_REDIST_HELP_STR_BGPD
16755 "Route map reference\n"
16756 "Pointer to route-map entries\n"
16757 "Metric for redistributed routes\n"
16758 "Default metric\n")
16759 {
16760 VTY_DECLVAR_CONTEXT(bgp, bgp);
16761 int idx_protocol = 1;
16762 int idx_word = 3;
16763 int idx_number = 5;
16764 int type;
16765 uint32_t metric;
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 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16777
16778 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16779 changed =
16780 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16781 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16782 metric);
16783 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16784 }
16785
16786 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16787 bgp_redistribute_ipv6_metric_rmap_cmd,
16788 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16789 "Redistribute information from another routing protocol\n"
16790 FRR_IP6_REDIST_HELP_STR_BGPD
16791 "Metric for redistributed routes\n"
16792 "Default metric\n"
16793 "Route map reference\n"
16794 "Pointer to route-map entries\n")
16795 {
16796 VTY_DECLVAR_CONTEXT(bgp, bgp);
16797 int idx_protocol = 1;
16798 int idx_number = 3;
16799 int idx_word = 5;
16800 int type;
16801 uint32_t metric;
16802 struct bgp_redist *red;
16803 bool changed;
16804 struct route_map *route_map =
16805 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16806
16807 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16808 if (type < 0) {
16809 vty_out(vty, "%% Invalid route type\n");
16810 return CMD_WARNING_CONFIG_FAILED;
16811 }
16812 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16813
16814 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16815 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16816 metric);
16817 changed |=
16818 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16819 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16820 }
16821
16822 DEFUN (no_bgp_redistribute_ipv6,
16823 no_bgp_redistribute_ipv6_cmd,
16824 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16825 NO_STR
16826 "Redistribute information from another routing protocol\n"
16827 FRR_IP6_REDIST_HELP_STR_BGPD
16828 "Metric for redistributed routes\n"
16829 "Default metric\n"
16830 "Route map reference\n"
16831 "Pointer to route-map entries\n")
16832 {
16833 VTY_DECLVAR_CONTEXT(bgp, bgp);
16834 int idx_protocol = 2;
16835 int type;
16836
16837 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16838 if (type < 0) {
16839 vty_out(vty, "%% Invalid route type\n");
16840 return CMD_WARNING_CONFIG_FAILED;
16841 }
16842
16843 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16844 }
16845
16846 /* Neighbor update tcp-mss. */
16847 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16848 const char *tcp_mss_str)
16849 {
16850 struct peer *peer;
16851 uint32_t tcp_mss_val = 0;
16852
16853 peer = peer_and_group_lookup_vty(vty, peer_str);
16854 if (!peer)
16855 return CMD_WARNING_CONFIG_FAILED;
16856
16857 if (tcp_mss_str) {
16858 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16859 peer_tcp_mss_set(peer, tcp_mss_val);
16860 } else {
16861 peer_tcp_mss_unset(peer);
16862 }
16863
16864 return CMD_SUCCESS;
16865 }
16866
16867 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16868 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16869 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16870 "TCP max segment size\n"
16871 "TCP MSS value\n")
16872 {
16873 int peer_index = 1;
16874 int mss_index = 3;
16875
16876 vty_out(vty,
16877 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16878 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16879 argv[mss_index]->arg);
16880 }
16881
16882 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16883 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16884 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16885 "TCP max segment size\n"
16886 "TCP MSS value\n")
16887 {
16888 int peer_index = 2;
16889
16890 vty_out(vty,
16891 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16892 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16893 }
16894
16895 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16896 "[no$no] bgp retain route-target all",
16897 NO_STR BGP_STR
16898 "Retain BGP updates\n"
16899 "Retain BGP updates based on route-target values\n"
16900 "Retain all BGP updates\n")
16901 {
16902 bool check;
16903 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16904
16905 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16906 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16907 if (check != !no) {
16908 if (!no)
16909 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16910 [bgp_node_safi(vty)],
16911 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16912 else
16913 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16914 [bgp_node_safi(vty)],
16915 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16916 /* trigger a flush to re-sync with ADJ-RIB-in */
16917 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16918 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16919 }
16920 return CMD_SUCCESS;
16921 }
16922
16923 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16924 afi_t afi, safi_t safi)
16925 {
16926 int i;
16927
16928 /* Unicast redistribution only. */
16929 if (safi != SAFI_UNICAST)
16930 return;
16931
16932 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16933 /* Redistribute BGP does not make sense. */
16934 if (i != ZEBRA_ROUTE_BGP) {
16935 struct list *red_list;
16936 struct listnode *node;
16937 struct bgp_redist *red;
16938
16939 red_list = bgp->redist[afi][i];
16940 if (!red_list)
16941 continue;
16942
16943 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16944 /* "redistribute" configuration. */
16945 vty_out(vty, " redistribute %s",
16946 zebra_route_string(i));
16947 if (red->instance)
16948 vty_out(vty, " %d", red->instance);
16949 if (red->redist_metric_flag)
16950 vty_out(vty, " metric %u",
16951 red->redist_metric);
16952 if (red->rmap.name)
16953 vty_out(vty, " route-map %s",
16954 red->rmap.name);
16955 vty_out(vty, "\n");
16956 }
16957 }
16958 }
16959 }
16960
16961 /* peer-group helpers for config-write */
16962
16963 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16964 {
16965 if (!peer_group_active(peer)) {
16966 if (CHECK_FLAG(peer->flags_invert, flag))
16967 return !CHECK_FLAG(peer->flags, flag);
16968 else
16969 return !!CHECK_FLAG(peer->flags, flag);
16970 }
16971
16972 return !!CHECK_FLAG(peer->flags_override, flag);
16973 }
16974
16975 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16976 uint64_t flag)
16977 {
16978 if (!peer_group_active(peer)) {
16979 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16980 return !peer_af_flag_check(peer, afi, safi, flag);
16981 else
16982 return !!peer_af_flag_check(peer, afi, safi, flag);
16983 }
16984
16985 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16986 }
16987
16988 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16989 uint8_t type, int direct)
16990 {
16991 struct bgp_filter *filter;
16992
16993 if (peer_group_active(peer))
16994 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16995 type);
16996
16997 filter = &peer->filter[afi][safi];
16998 switch (type) {
16999 case PEER_FT_DISTRIBUTE_LIST:
17000 return !!(filter->dlist[direct].name);
17001 case PEER_FT_FILTER_LIST:
17002 return !!(filter->aslist[direct].name);
17003 case PEER_FT_PREFIX_LIST:
17004 return !!(filter->plist[direct].name);
17005 case PEER_FT_ROUTE_MAP:
17006 return !!(filter->map[direct].name);
17007 case PEER_FT_UNSUPPRESS_MAP:
17008 return !!(filter->usmap.name);
17009 case PEER_FT_ADVERTISE_MAP:
17010 return !!(filter->advmap.aname
17011 && ((filter->advmap.condition == direct)
17012 && filter->advmap.cname));
17013 default:
17014 return false;
17015 }
17016 }
17017
17018 /* Return true if the addpath type is set for peer and different from
17019 * peer-group.
17020 */
17021 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17022 safi_t safi)
17023 {
17024 enum bgp_addpath_strat type, g_type;
17025
17026 type = peer->addpath_type[afi][safi];
17027
17028 if (type != BGP_ADDPATH_NONE) {
17029 if (peer_group_active(peer)) {
17030 g_type = peer->group->conf->addpath_type[afi][safi];
17031
17032 if (type != g_type)
17033 return true;
17034 else
17035 return false;
17036 }
17037
17038 return true;
17039 }
17040
17041 return false;
17042 }
17043
17044 /* This is part of the address-family block (unicast only) */
17045 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17046 afi_t afi)
17047 {
17048 int indent = 2;
17049 uint32_t tovpn_sid_index = 0;
17050
17051 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17052 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17053 BGP_CONFIG_VRF_TO_VRF_IMPORT))
17054 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17055 bgp->vpn_policy[afi]
17056 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17057 else
17058 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17059 bgp->vpn_policy[afi]
17060 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17061 }
17062 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17063 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17064 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17065 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17066 return;
17067
17068 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17069 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17070
17071 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17072
17073 } else {
17074 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17075 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17076 bgp->vpn_policy[afi].tovpn_label);
17077 }
17078 }
17079
17080 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17081 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17082 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17083 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17084 } else if (tovpn_sid_index != 0) {
17085 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17086 tovpn_sid_index);
17087 }
17088
17089 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17090 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17091 &bgp->vpn_policy[afi].tovpn_rd);
17092
17093 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17094 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17095
17096 char buf[PREFIX_STRLEN];
17097 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17098 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17099 sizeof(buf))) {
17100
17101 vty_out(vty, "%*snexthop vpn export %s\n",
17102 indent, "", buf);
17103 }
17104 }
17105 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17106 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17107 && ecommunity_cmp(
17108 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17109 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17110
17111 char *b = ecommunity_ecom2str(
17112 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17113 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17114 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17115 XFREE(MTYPE_ECOMMUNITY_STR, b);
17116 } else {
17117 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17118 char *b = ecommunity_ecom2str(
17119 bgp->vpn_policy[afi]
17120 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17121 ECOMMUNITY_FORMAT_ROUTE_MAP,
17122 ECOMMUNITY_ROUTE_TARGET);
17123 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17124 XFREE(MTYPE_ECOMMUNITY_STR, b);
17125 }
17126 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17127 char *b = ecommunity_ecom2str(
17128 bgp->vpn_policy[afi]
17129 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17130 ECOMMUNITY_FORMAT_ROUTE_MAP,
17131 ECOMMUNITY_ROUTE_TARGET);
17132 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17133 XFREE(MTYPE_ECOMMUNITY_STR, b);
17134 }
17135 }
17136
17137 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17138 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17139 bgp->vpn_policy[afi]
17140 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17141
17142 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17143 char *b = ecommunity_ecom2str(
17144 bgp->vpn_policy[afi]
17145 .import_redirect_rtlist,
17146 ECOMMUNITY_FORMAT_ROUTE_MAP,
17147 ECOMMUNITY_ROUTE_TARGET);
17148
17149 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17150 != ECOMMUNITY_SIZE)
17151 vty_out(vty, "%*srt6 redirect import %s\n",
17152 indent, "", b);
17153 else
17154 vty_out(vty, "%*srt redirect import %s\n",
17155 indent, "", b);
17156 XFREE(MTYPE_ECOMMUNITY_STR, b);
17157 }
17158 }
17159
17160 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17161 afi_t afi, safi_t safi)
17162 {
17163 struct bgp_filter *filter;
17164 char *addr;
17165
17166 addr = peer->host;
17167 filter = &peer->filter[afi][safi];
17168
17169 /* distribute-list. */
17170 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17171 FILTER_IN))
17172 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17173 filter->dlist[FILTER_IN].name);
17174
17175 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17176 FILTER_OUT))
17177 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17178 filter->dlist[FILTER_OUT].name);
17179
17180 /* prefix-list. */
17181 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17182 FILTER_IN))
17183 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17184 filter->plist[FILTER_IN].name);
17185
17186 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17187 FILTER_OUT))
17188 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17189 filter->plist[FILTER_OUT].name);
17190
17191 /* route-map. */
17192 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17193 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17194 filter->map[RMAP_IN].name);
17195
17196 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17197 RMAP_OUT))
17198 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17199 filter->map[RMAP_OUT].name);
17200
17201 /* unsuppress-map */
17202 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17203 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17204 filter->usmap.name);
17205
17206 /* advertise-map : always applied in OUT direction*/
17207 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17208 CONDITION_NON_EXIST))
17209 vty_out(vty,
17210 " neighbor %s advertise-map %s non-exist-map %s\n",
17211 addr, filter->advmap.aname, filter->advmap.cname);
17212
17213 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17214 CONDITION_EXIST))
17215 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17216 addr, filter->advmap.aname, filter->advmap.cname);
17217
17218 /* filter-list. */
17219 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17220 FILTER_IN))
17221 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17222 filter->aslist[FILTER_IN].name);
17223
17224 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17225 FILTER_OUT))
17226 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17227 filter->aslist[FILTER_OUT].name);
17228 }
17229
17230 /* BGP peer configuration display function. */
17231 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17232 struct peer *peer)
17233 {
17234 struct peer *g_peer = NULL;
17235 char *addr;
17236 int if_pg_printed = false;
17237 int if_ras_printed = false;
17238
17239 /* Skip dynamic neighbors. */
17240 if (peer_dynamic_neighbor(peer))
17241 return;
17242
17243 if (peer->conf_if)
17244 addr = peer->conf_if;
17245 else
17246 addr = peer->host;
17247
17248 /************************************
17249 ****** Global to the neighbor ******
17250 ************************************/
17251 if (peer->conf_if) {
17252 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17253 vty_out(vty, " neighbor %s interface v6only", addr);
17254 else
17255 vty_out(vty, " neighbor %s interface", addr);
17256
17257 if (peer_group_active(peer)) {
17258 vty_out(vty, " peer-group %s", peer->group->name);
17259 if_pg_printed = true;
17260 } else if (peer->as_type == AS_SPECIFIED) {
17261 vty_out(vty, " remote-as %u", peer->as);
17262 if_ras_printed = true;
17263 } else if (peer->as_type == AS_INTERNAL) {
17264 vty_out(vty, " remote-as internal");
17265 if_ras_printed = true;
17266 } else if (peer->as_type == AS_EXTERNAL) {
17267 vty_out(vty, " remote-as external");
17268 if_ras_printed = true;
17269 }
17270
17271 vty_out(vty, "\n");
17272 }
17273
17274 /* remote-as and peer-group */
17275 /* peer is a member of a peer-group */
17276 if (peer_group_active(peer)) {
17277 g_peer = peer->group->conf;
17278
17279 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17280 if (peer->as_type == AS_SPECIFIED) {
17281 vty_out(vty, " neighbor %s remote-as %u\n",
17282 addr, peer->as);
17283 } else if (peer->as_type == AS_INTERNAL) {
17284 vty_out(vty,
17285 " neighbor %s remote-as internal\n",
17286 addr);
17287 } else if (peer->as_type == AS_EXTERNAL) {
17288 vty_out(vty,
17289 " neighbor %s remote-as external\n",
17290 addr);
17291 }
17292 }
17293
17294 /* For swpX peers we displayed the peer-group
17295 * via 'neighbor swpX interface peer-group PGNAME' */
17296 if (!if_pg_printed)
17297 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17298 peer->group->name);
17299 }
17300
17301 /* peer is NOT a member of a peer-group */
17302 else {
17303 /* peer is a peer-group, declare the peer-group */
17304 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17305 vty_out(vty, " neighbor %s peer-group\n", addr);
17306 }
17307
17308 if (!if_ras_printed) {
17309 if (peer->as_type == AS_SPECIFIED) {
17310 vty_out(vty, " neighbor %s remote-as %u\n",
17311 addr, peer->as);
17312 } else if (peer->as_type == AS_INTERNAL) {
17313 vty_out(vty,
17314 " neighbor %s remote-as internal\n",
17315 addr);
17316 } else if (peer->as_type == AS_EXTERNAL) {
17317 vty_out(vty,
17318 " neighbor %s remote-as external\n",
17319 addr);
17320 }
17321 }
17322 }
17323
17324 /* local-as */
17325 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17326 vty_out(vty, " neighbor %s local-as %u", addr,
17327 peer->change_local_as);
17328 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17329 vty_out(vty, " no-prepend");
17330 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17331 vty_out(vty, " replace-as");
17332 vty_out(vty, "\n");
17333 }
17334
17335 /* description */
17336 if (peer->desc) {
17337 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17338 }
17339
17340 /* shutdown */
17341 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17342 if (peer->tx_shutdown_message)
17343 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17344 peer->tx_shutdown_message);
17345 else
17346 vty_out(vty, " neighbor %s shutdown\n", addr);
17347 }
17348
17349 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17350 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17351 peer->rtt_expected, peer->rtt_keepalive_conf);
17352
17353 /* bfd */
17354 if (peer->bfd_config)
17355 bgp_bfd_peer_config_write(vty, peer, addr);
17356
17357 /* password */
17358 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17359 vty_out(vty, " neighbor %s password %s\n", addr,
17360 peer->password);
17361
17362 /* neighbor solo */
17363 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17364 if (!peer_group_active(peer)) {
17365 vty_out(vty, " neighbor %s solo\n", addr);
17366 }
17367 }
17368
17369 /* BGP port */
17370 if (peer->port != BGP_PORT_DEFAULT) {
17371 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17372 }
17373
17374 /* Local interface name */
17375 if (peer->ifname) {
17376 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17377 }
17378
17379 /* TCP max segment size */
17380 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17381 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17382
17383 /* passive */
17384 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17385 vty_out(vty, " neighbor %s passive\n", addr);
17386
17387 /* ebgp-multihop */
17388 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17389 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17390 && peer->ttl == MAXTTL)) {
17391 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17392 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17393 peer->ttl);
17394 }
17395 }
17396
17397 /* aigp */
17398 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17399 vty_out(vty, " neighbor %s aigp\n", addr);
17400
17401 /* graceful-shutdown */
17402 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17403 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17404
17405 /* role */
17406 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17407 peer->local_role != ROLE_UNDEFINED)
17408 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17409 bgp_get_name_by_role(peer->local_role),
17410 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17411 ? " strict-mode"
17412 : "");
17413
17414 /* ttl-security hops */
17415 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17416 if (!peer_group_active(peer)
17417 || g_peer->gtsm_hops != peer->gtsm_hops) {
17418 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17419 addr, peer->gtsm_hops);
17420 }
17421 }
17422
17423 /* disable-connected-check */
17424 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17425 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17426
17427 /* link-bw-encoding-ieee */
17428 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17429 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17430 addr);
17431
17432 /* extended-optional-parameters */
17433 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17434 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17435 addr);
17436
17437 /* enforce-first-as */
17438 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17439 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17440
17441 /* update-source */
17442 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17443 if (peer->update_source)
17444 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17445 peer->update_source);
17446 else if (peer->update_if)
17447 vty_out(vty, " neighbor %s update-source %s\n", addr,
17448 peer->update_if);
17449 }
17450
17451 /* advertisement-interval */
17452 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17453 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17454 peer->routeadv);
17455
17456 /* timers */
17457 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17458 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17459 peer->keepalive, peer->holdtime);
17460
17461 /* timers connect */
17462 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17463 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17464 peer->connect);
17465 /* need special-case handling for changed default values due to
17466 * config profile / version (because there is no "timers bgp connect"
17467 * command, we need to save this per-peer :/)
17468 */
17469 else if (!peer_group_active(peer) && !peer->connect &&
17470 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17471 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17472 peer->bgp->default_connect_retry);
17473
17474 /* timers delayopen */
17475 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17476 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17477 peer->delayopen);
17478 /* Save config even though flag is not set if default values have been
17479 * changed
17480 */
17481 else if (!peer_group_active(peer) && !peer->delayopen
17482 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17483 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17484 peer->bgp->default_delayopen);
17485
17486 /* capability dynamic */
17487 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17488 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17489
17490 /* capability extended-nexthop */
17491 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17492 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17493 !peer->conf_if)
17494 vty_out(vty,
17495 " no neighbor %s capability extended-nexthop\n",
17496 addr);
17497 else if (!peer->conf_if)
17498 vty_out(vty,
17499 " neighbor %s capability extended-nexthop\n",
17500 addr);
17501 }
17502
17503 /* dont-capability-negotiation */
17504 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17505 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17506
17507 /* override-capability */
17508 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17509 vty_out(vty, " neighbor %s override-capability\n", addr);
17510
17511 /* strict-capability-match */
17512 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17513 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17514
17515 /* Sender side AS path loop detection. */
17516 if (peer->as_path_loop_detection)
17517 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17518 addr);
17519
17520 /* path-attribute discard */
17521 char discard_attrs_str[BUFSIZ] = {0};
17522 bool discard_attrs = bgp_path_attribute_discard(
17523 peer, discard_attrs_str, sizeof(discard_attrs_str));
17524
17525 if (discard_attrs)
17526 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17527 discard_attrs_str);
17528
17529 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17530 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17531
17532 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17533 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17534 vty_out(vty,
17535 " neighbor %s graceful-restart-helper\n", addr);
17536 } else if (CHECK_FLAG(
17537 peer->peer_gr_new_status_flag,
17538 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17539 vty_out(vty,
17540 " neighbor %s graceful-restart\n", addr);
17541 } else if (
17542 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17543 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17544 && !(CHECK_FLAG(
17545 peer->peer_gr_new_status_flag,
17546 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17547 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17548 addr);
17549 }
17550 }
17551 }
17552
17553 /* BGP peer configuration display function. */
17554 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17555 struct peer *peer, afi_t afi, safi_t safi)
17556 {
17557 struct peer *g_peer = NULL;
17558 char *addr;
17559 bool flag_scomm, flag_secomm, flag_slcomm;
17560
17561 /* Skip dynamic neighbors. */
17562 if (peer_dynamic_neighbor(peer))
17563 return;
17564
17565 if (peer->conf_if)
17566 addr = peer->conf_if;
17567 else
17568 addr = peer->host;
17569
17570 /************************************
17571 ****** Per AF to the neighbor ******
17572 ************************************/
17573 if (peer_group_active(peer)) {
17574 g_peer = peer->group->conf;
17575
17576 /* If the peer-group is active but peer is not, print a 'no
17577 * activate' */
17578 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17579 vty_out(vty, " no neighbor %s activate\n", addr);
17580 }
17581
17582 /* If the peer-group is not active but peer is, print an
17583 'activate' */
17584 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17585 vty_out(vty, " neighbor %s activate\n", addr);
17586 }
17587 } else {
17588 if (peer->afc[afi][safi]) {
17589 if (safi == SAFI_ENCAP)
17590 vty_out(vty, " neighbor %s activate\n", addr);
17591 else if (!bgp->default_af[afi][safi])
17592 vty_out(vty, " neighbor %s activate\n", addr);
17593 } else {
17594 if (bgp->default_af[afi][safi])
17595 vty_out(vty, " no neighbor %s activate\n",
17596 addr);
17597 }
17598 }
17599
17600 /* addpath TX knobs */
17601 if (peergroup_af_addpath_check(peer, afi, safi)) {
17602 switch (peer->addpath_type[afi][safi]) {
17603 case BGP_ADDPATH_ALL:
17604 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17605 addr);
17606 break;
17607 case BGP_ADDPATH_BEST_PER_AS:
17608 vty_out(vty,
17609 " neighbor %s addpath-tx-bestpath-per-AS\n",
17610 addr);
17611 break;
17612 case BGP_ADDPATH_MAX:
17613 case BGP_ADDPATH_NONE:
17614 break;
17615 }
17616 }
17617
17618 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17619 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17620
17621 /* ORF capability. */
17622 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17623 || peergroup_af_flag_check(peer, afi, safi,
17624 PEER_FLAG_ORF_PREFIX_RM)) {
17625 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17626
17627 if (peergroup_af_flag_check(peer, afi, safi,
17628 PEER_FLAG_ORF_PREFIX_SM)
17629 && peergroup_af_flag_check(peer, afi, safi,
17630 PEER_FLAG_ORF_PREFIX_RM))
17631 vty_out(vty, " both");
17632 else if (peergroup_af_flag_check(peer, afi, safi,
17633 PEER_FLAG_ORF_PREFIX_SM))
17634 vty_out(vty, " send");
17635 else
17636 vty_out(vty, " receive");
17637 vty_out(vty, "\n");
17638 }
17639
17640 /* Route reflector client. */
17641 if (peergroup_af_flag_check(peer, afi, safi,
17642 PEER_FLAG_REFLECTOR_CLIENT)) {
17643 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17644 }
17645
17646 /* next-hop-self force */
17647 if (peergroup_af_flag_check(peer, afi, safi,
17648 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17649 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17650 }
17651
17652 /* next-hop-self */
17653 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17654 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17655 }
17656
17657 /* remove-private-AS */
17658 if (peergroup_af_flag_check(peer, afi, safi,
17659 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17660 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17661 addr);
17662 }
17663
17664 else if (peergroup_af_flag_check(peer, afi, safi,
17665 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17666 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17667 addr);
17668 }
17669
17670 else if (peergroup_af_flag_check(peer, afi, safi,
17671 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17672 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17673 }
17674
17675 else if (peergroup_af_flag_check(peer, afi, safi,
17676 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17677 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17678 }
17679
17680 /* as-override */
17681 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17682 vty_out(vty, " neighbor %s as-override\n", addr);
17683 }
17684
17685 /* send-community print. */
17686 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17687 PEER_FLAG_SEND_COMMUNITY);
17688 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17689 PEER_FLAG_SEND_EXT_COMMUNITY);
17690 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17691 PEER_FLAG_SEND_LARGE_COMMUNITY);
17692
17693 if (flag_scomm && flag_secomm && flag_slcomm) {
17694 vty_out(vty, " no neighbor %s send-community all\n", addr);
17695 } else {
17696 if (flag_scomm)
17697 vty_out(vty, " no neighbor %s send-community\n", addr);
17698 if (flag_secomm)
17699 vty_out(vty,
17700 " no neighbor %s send-community extended\n",
17701 addr);
17702
17703 if (flag_slcomm)
17704 vty_out(vty, " no neighbor %s send-community large\n",
17705 addr);
17706 }
17707
17708 /* Default information */
17709 if (peergroup_af_flag_check(peer, afi, safi,
17710 PEER_FLAG_DEFAULT_ORIGINATE)) {
17711 vty_out(vty, " neighbor %s default-originate", addr);
17712
17713 if (peer->default_rmap[afi][safi].name)
17714 vty_out(vty, " route-map %s",
17715 peer->default_rmap[afi][safi].name);
17716
17717 vty_out(vty, "\n");
17718 }
17719
17720 /* Soft reconfiguration inbound. */
17721 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17722 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17723 addr);
17724 }
17725
17726 /* maximum-prefix. */
17727 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17728 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17729 peer->pmax[afi][safi]);
17730
17731 if (peer->pmax_threshold[afi][safi]
17732 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17733 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17734 if (peer_af_flag_check(peer, afi, safi,
17735 PEER_FLAG_MAX_PREFIX_WARNING))
17736 vty_out(vty, " warning-only");
17737 if (peer->pmax_restart[afi][safi])
17738 vty_out(vty, " restart %u",
17739 peer->pmax_restart[afi][safi]);
17740 if (peer_af_flag_check(peer, afi, safi,
17741 PEER_FLAG_MAX_PREFIX_FORCE))
17742 vty_out(vty, " force");
17743
17744 vty_out(vty, "\n");
17745 }
17746
17747 /* maximum-prefix-out */
17748 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17749 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17750 addr, peer->pmax_out[afi][safi]);
17751
17752 /* Route server client. */
17753 if (peergroup_af_flag_check(peer, afi, safi,
17754 PEER_FLAG_RSERVER_CLIENT)) {
17755 vty_out(vty, " neighbor %s route-server-client\n", addr);
17756 }
17757
17758 /* Nexthop-local unchanged. */
17759 if (peergroup_af_flag_check(peer, afi, safi,
17760 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17761 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17762 }
17763
17764 /* allowas-in <1-10> */
17765 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17766 if (peer_af_flag_check(peer, afi, safi,
17767 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17768 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17769 } else if (peer->allowas_in[afi][safi] == 3) {
17770 vty_out(vty, " neighbor %s allowas-in\n", addr);
17771 } else {
17772 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17773 peer->allowas_in[afi][safi]);
17774 }
17775 }
17776
17777 /* accept-own */
17778 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17779 vty_out(vty, " neighbor %s accept-own\n", addr);
17780
17781 /* soo */
17782 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17783 char *soo_str = ecommunity_ecom2str(
17784 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17785
17786 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17787 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17788 }
17789
17790 /* weight */
17791 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17792 vty_out(vty, " neighbor %s weight %lu\n", addr,
17793 peer->weight[afi][safi]);
17794
17795 /* Filter. */
17796 bgp_config_write_filter(vty, peer, afi, safi);
17797
17798 /* atribute-unchanged. */
17799 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17800 || (safi != SAFI_EVPN
17801 && peer_af_flag_check(peer, afi, safi,
17802 PEER_FLAG_NEXTHOP_UNCHANGED))
17803 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17804
17805 if (!peer_group_active(peer)
17806 || peergroup_af_flag_check(peer, afi, safi,
17807 PEER_FLAG_AS_PATH_UNCHANGED)
17808 || peergroup_af_flag_check(peer, afi, safi,
17809 PEER_FLAG_NEXTHOP_UNCHANGED)
17810 || peergroup_af_flag_check(peer, afi, safi,
17811 PEER_FLAG_MED_UNCHANGED)) {
17812
17813 vty_out(vty,
17814 " neighbor %s attribute-unchanged%s%s%s\n",
17815 addr,
17816 peer_af_flag_check(peer, afi, safi,
17817 PEER_FLAG_AS_PATH_UNCHANGED)
17818 ? " as-path"
17819 : "",
17820 peer_af_flag_check(peer, afi, safi,
17821 PEER_FLAG_NEXTHOP_UNCHANGED)
17822 ? " next-hop"
17823 : "",
17824 peer_af_flag_check(peer, afi, safi,
17825 PEER_FLAG_MED_UNCHANGED)
17826 ? " med"
17827 : "");
17828 }
17829 }
17830 }
17831
17832 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17833 safi_t safi)
17834 {
17835 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17836 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17837 vty_out(vty, " no bgp retain route-target all\n");
17838 }
17839
17840 /* Address family based peer configuration display. */
17841 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17842 safi_t safi)
17843 {
17844 struct peer *peer;
17845 struct peer_group *group;
17846 struct listnode *node, *nnode;
17847
17848
17849 vty_frame(vty, " !\n address-family ");
17850 if (afi == AFI_IP) {
17851 if (safi == SAFI_UNICAST)
17852 vty_frame(vty, "ipv4 unicast");
17853 else if (safi == SAFI_LABELED_UNICAST)
17854 vty_frame(vty, "ipv4 labeled-unicast");
17855 else if (safi == SAFI_MULTICAST)
17856 vty_frame(vty, "ipv4 multicast");
17857 else if (safi == SAFI_MPLS_VPN)
17858 vty_frame(vty, "ipv4 vpn");
17859 else if (safi == SAFI_ENCAP)
17860 vty_frame(vty, "ipv4 encap");
17861 else if (safi == SAFI_FLOWSPEC)
17862 vty_frame(vty, "ipv4 flowspec");
17863 } else if (afi == AFI_IP6) {
17864 if (safi == SAFI_UNICAST)
17865 vty_frame(vty, "ipv6 unicast");
17866 else if (safi == SAFI_LABELED_UNICAST)
17867 vty_frame(vty, "ipv6 labeled-unicast");
17868 else if (safi == SAFI_MULTICAST)
17869 vty_frame(vty, "ipv6 multicast");
17870 else if (safi == SAFI_MPLS_VPN)
17871 vty_frame(vty, "ipv6 vpn");
17872 else if (safi == SAFI_ENCAP)
17873 vty_frame(vty, "ipv6 encap");
17874 else if (safi == SAFI_FLOWSPEC)
17875 vty_frame(vty, "ipv6 flowspec");
17876 } else if (afi == AFI_L2VPN) {
17877 if (safi == SAFI_EVPN)
17878 vty_frame(vty, "l2vpn evpn");
17879 }
17880 vty_frame(vty, "\n");
17881
17882 bgp_config_write_distance(vty, bgp, afi, safi);
17883
17884 bgp_config_write_network(vty, bgp, afi, safi);
17885
17886 bgp_config_write_redistribute(vty, bgp, afi, safi);
17887
17888 /* BGP flag dampening. */
17889 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17890 bgp_config_write_damp(vty, afi, safi);
17891
17892 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17893 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17894
17895 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17896 /* Do not display doppelganger peers */
17897 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17898 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17899 }
17900
17901 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17902 bgp_config_write_table_map(vty, bgp, afi, safi);
17903
17904 if (safi == SAFI_EVPN)
17905 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17906
17907 if (safi == SAFI_FLOWSPEC)
17908 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17909
17910 if (safi == SAFI_MPLS_VPN)
17911 bgp_vpn_config_write(vty, bgp, afi, safi);
17912
17913 if (safi == SAFI_UNICAST) {
17914 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17915 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17916 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17917
17918 vty_out(vty, " export vpn\n");
17919 }
17920 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17921 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17922
17923 vty_out(vty, " import vpn\n");
17924 }
17925 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17926 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17927 char *name;
17928
17929 for (ALL_LIST_ELEMENTS_RO(
17930 bgp->vpn_policy[afi].import_vrf, node,
17931 name))
17932 vty_out(vty, " import vrf %s\n", name);
17933 }
17934 }
17935
17936 vty_endframe(vty, " exit-address-family\n");
17937 }
17938
17939 int bgp_config_write(struct vty *vty)
17940 {
17941 struct bgp *bgp;
17942 struct peer_group *group;
17943 struct peer *peer;
17944 struct listnode *node, *nnode;
17945 struct listnode *mnode, *mnnode;
17946 afi_t afi;
17947 safi_t safi;
17948 uint32_t tovpn_sid_index = 0;
17949
17950 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17951 vty_out(vty, "bgp route-map delay-timer %u\n",
17952 bm->rmap_update_timer);
17953
17954 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17955 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17956 if (bm->v_update_delay != bm->v_establish_wait)
17957 vty_out(vty, " %d", bm->v_establish_wait);
17958 vty_out(vty, "\n");
17959 }
17960
17961 if (bm->wait_for_fib)
17962 vty_out(vty, "bgp suppress-fib-pending\n");
17963
17964 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17965 vty_out(vty, "bgp graceful-shutdown\n");
17966
17967 /* No-RIB (Zebra) option flag configuration */
17968 if (bgp_option_check(BGP_OPT_NO_FIB))
17969 vty_out(vty, "bgp no-rib\n");
17970
17971 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17972 vty_out(vty, "bgp send-extra-data zebra\n");
17973
17974 /* BGP session DSCP value */
17975 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17976 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17977
17978 /* BGP InQ limit */
17979 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
17980 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17981
17982 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
17983 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
17984
17985 /* BGP configuration. */
17986 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17987
17988 /* skip all auto created vrf as they dont have user config */
17989 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17990 continue;
17991
17992 /* Router bgp ASN */
17993 vty_out(vty, "router bgp %s", bgp->as_pretty);
17994
17995 if (bgp->name)
17996 vty_out(vty, " %s %s",
17997 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17998 ? "view" : "vrf", bgp->name);
17999 vty_out(vty, "\n");
18000
18001 /* BGP fast-external-failover. */
18002 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18003 vty_out(vty, " no bgp fast-external-failover\n");
18004
18005 /* BGP router ID. */
18006 if (bgp->router_id_static.s_addr != INADDR_ANY)
18007 vty_out(vty, " bgp router-id %pI4\n",
18008 &bgp->router_id_static);
18009
18010 /* Suppress fib pending */
18011 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18012 vty_out(vty, " bgp suppress-fib-pending\n");
18013
18014 /* BGP log-neighbor-changes. */
18015 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18016 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
18017 vty_out(vty, " %sbgp log-neighbor-changes\n",
18018 CHECK_FLAG(bgp->flags,
18019 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
18020 ? ""
18021 : "no ");
18022
18023 /* BGP configuration. */
18024 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
18025 vty_out(vty, " bgp always-compare-med\n");
18026
18027 /* RFC8212 default eBGP policy. */
18028 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18029 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18030 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18031 CHECK_FLAG(bgp->flags,
18032 BGP_FLAG_EBGP_REQUIRES_POLICY)
18033 ? ""
18034 : "no ");
18035
18036 /* draft-ietf-idr-deprecate-as-set-confed-set */
18037 if (bgp->reject_as_sets)
18038 vty_out(vty, " bgp reject-as-sets\n");
18039
18040 /* Suppress duplicate updates if the route actually not changed
18041 */
18042 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18043 != SAVE_BGP_SUPPRESS_DUPLICATES)
18044 vty_out(vty, " %sbgp suppress-duplicates\n",
18045 CHECK_FLAG(bgp->flags,
18046 BGP_FLAG_SUPPRESS_DUPLICATES)
18047 ? ""
18048 : "no ");
18049
18050 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18051 */
18052 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18053 SAVE_BGP_HARD_ADMIN_RESET)
18054 vty_out(vty, " %sbgp hard-administrative-reset\n",
18055 CHECK_FLAG(bgp->flags,
18056 BGP_FLAG_HARD_ADMIN_RESET)
18057 ? ""
18058 : "no ");
18059
18060 /* BGP default <afi>-<safi> */
18061 FOREACH_AFI_SAFI (afi, safi) {
18062 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18063 if (!bgp->default_af[afi][safi])
18064 vty_out(vty, " no bgp default %s\n",
18065 get_bgp_default_af_flag(afi,
18066 safi));
18067 } else if (bgp->default_af[afi][safi])
18068 vty_out(vty, " bgp default %s\n",
18069 get_bgp_default_af_flag(afi, safi));
18070 }
18071
18072 /* BGP default local-preference. */
18073 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18074 vty_out(vty, " bgp default local-preference %u\n",
18075 bgp->default_local_pref);
18076
18077 /* BGP default show-hostname */
18078 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18079 != SAVE_BGP_SHOW_HOSTNAME)
18080 vty_out(vty, " %sbgp default show-hostname\n",
18081 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18082 ? ""
18083 : "no ");
18084
18085 /* BGP default show-nexthop-hostname */
18086 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18087 != SAVE_BGP_SHOW_HOSTNAME)
18088 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18089 CHECK_FLAG(bgp->flags,
18090 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18091 ? ""
18092 : "no ");
18093
18094 /* BGP default subgroup-pkt-queue-max. */
18095 if (bgp->default_subgroup_pkt_queue_max
18096 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18097 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18098 bgp->default_subgroup_pkt_queue_max);
18099
18100 /* BGP client-to-client reflection. */
18101 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18102 vty_out(vty, " no bgp client-to-client reflection\n");
18103
18104 /* BGP cluster ID. */
18105 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18106 vty_out(vty, " bgp cluster-id %pI4\n",
18107 &bgp->cluster_id);
18108
18109 /* Disable ebgp connected nexthop check */
18110 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18111 vty_out(vty,
18112 " bgp disable-ebgp-connected-route-check\n");
18113
18114 /* Confederation identifier*/
18115 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18116 vty_out(vty, " bgp confederation identifier %u\n",
18117 bgp->confed_id);
18118
18119 /* Confederation peer */
18120 if (bgp->confed_peers_cnt > 0) {
18121 int i;
18122
18123 vty_out(vty, " bgp confederation peers");
18124
18125 for (i = 0; i < bgp->confed_peers_cnt; i++)
18126 vty_out(vty, " %u", bgp->confed_peers[i]);
18127
18128 vty_out(vty, "\n");
18129 }
18130
18131 /* BGP deterministic-med. */
18132 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18133 != SAVE_BGP_DETERMINISTIC_MED)
18134 vty_out(vty, " %sbgp deterministic-med\n",
18135 CHECK_FLAG(bgp->flags,
18136 BGP_FLAG_DETERMINISTIC_MED)
18137 ? ""
18138 : "no ");
18139
18140 /* BGP update-delay. */
18141 bgp_config_write_update_delay(vty, bgp);
18142
18143 if (bgp->v_maxmed_onstartup
18144 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18145 vty_out(vty, " bgp max-med on-startup %u",
18146 bgp->v_maxmed_onstartup);
18147 if (bgp->maxmed_onstartup_value
18148 != BGP_MAXMED_VALUE_DEFAULT)
18149 vty_out(vty, " %u",
18150 bgp->maxmed_onstartup_value);
18151 vty_out(vty, "\n");
18152 }
18153 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18154 vty_out(vty, " bgp max-med administrative");
18155 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18156 vty_out(vty, " %u", bgp->maxmed_admin_value);
18157 vty_out(vty, "\n");
18158 }
18159
18160 /* write quanta */
18161 bgp_config_write_wpkt_quanta(vty, bgp);
18162 /* read quanta */
18163 bgp_config_write_rpkt_quanta(vty, bgp);
18164
18165 /* coalesce time */
18166 bgp_config_write_coalesce_time(vty, bgp);
18167
18168 /* BGP per-instance graceful-shutdown */
18169 /* BGP-wide settings and per-instance settings are mutually
18170 * exclusive.
18171 */
18172 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18173 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18174 vty_out(vty, " bgp graceful-shutdown\n");
18175
18176 /* Long-lived Graceful Restart */
18177 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18178 vty_out(vty,
18179 " bgp long-lived-graceful-restart stale-time %u\n",
18180 bgp->llgr_stale_time);
18181
18182 /* BGP graceful-restart. */
18183 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18184 vty_out(vty,
18185 " bgp graceful-restart stalepath-time %u\n",
18186 bgp->stalepath_time);
18187
18188 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18189 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18190 bgp->restart_time);
18191
18192 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18193 SAVE_BGP_GRACEFUL_NOTIFICATION)
18194 vty_out(vty, " %sbgp graceful-restart notification\n",
18195 CHECK_FLAG(bgp->flags,
18196 BGP_FLAG_GRACEFUL_NOTIFICATION)
18197 ? ""
18198 : "no ");
18199
18200 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18201 vty_out(vty,
18202 " bgp graceful-restart select-defer-time %u\n",
18203 bgp->select_defer_time);
18204
18205 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18206 vty_out(vty, " bgp graceful-restart\n");
18207
18208 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18209 vty_out(vty, " bgp graceful-restart-disable\n");
18210
18211 /* BGP graceful-restart Preserve State F bit. */
18212 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18213 vty_out(vty,
18214 " bgp graceful-restart preserve-fw-state\n");
18215
18216 /* BGP TCP keepalive */
18217 bgp_config_tcp_keepalive(vty, bgp);
18218
18219 /* Stale timer for RIB */
18220 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18221 vty_out(vty,
18222 " bgp graceful-restart rib-stale-time %u\n",
18223 bgp->rib_stale_time);
18224
18225 /* BGP bestpath method. */
18226 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18227 vty_out(vty, " bgp bestpath as-path ignore\n");
18228 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18229 vty_out(vty, " bgp bestpath as-path confed\n");
18230
18231 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18232 if (CHECK_FLAG(bgp->flags,
18233 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18234 vty_out(vty,
18235 " bgp bestpath as-path multipath-relax as-set\n");
18236 } else {
18237 vty_out(vty,
18238 " bgp bestpath as-path multipath-relax\n");
18239 }
18240 }
18241
18242 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18243 vty_out(vty,
18244 " bgp route-reflector allow-outbound-policy\n");
18245 }
18246 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18247 vty_out(vty, " bgp bestpath compare-routerid\n");
18248 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18249 vty_out(vty, " bgp bestpath aigp\n");
18250 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18251 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18252 vty_out(vty, " bgp bestpath med");
18253 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18254 vty_out(vty, " confed");
18255 if (CHECK_FLAG(bgp->flags,
18256 BGP_FLAG_MED_MISSING_AS_WORST))
18257 vty_out(vty, " missing-as-worst");
18258 vty_out(vty, "\n");
18259 }
18260
18261 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18262 vty_out(vty,
18263 " bgp bestpath peer-type multipath-relax\n");
18264
18265 /* Link bandwidth handling. */
18266 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18267 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18268 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18269 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18270 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18271 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18272
18273 /* BGP network import check. */
18274 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18275 != SAVE_BGP_IMPORT_CHECK)
18276 vty_out(vty, " %sbgp network import-check\n",
18277 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18278 ? ""
18279 : "no ");
18280
18281 /* BGP timers configuration. */
18282 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18283 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18284 vty_out(vty, " timers bgp %u %u\n",
18285 bgp->default_keepalive, bgp->default_holdtime);
18286
18287 /* BGP minimum holdtime configuration. */
18288 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18289 && bgp->default_min_holdtime != 0)
18290 vty_out(vty, " bgp minimum-holdtime %u\n",
18291 bgp->default_min_holdtime);
18292
18293 /* Conditional advertisement timer configuration */
18294 if (bgp->condition_check_period
18295 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18296 vty_out(vty,
18297 " bgp conditional-advertisement timer %u\n",
18298 bgp->condition_check_period);
18299
18300 /* peer-group */
18301 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18302 bgp_config_write_peer_global(vty, bgp, group->conf);
18303 }
18304
18305 /* Normal neighbor configuration. */
18306 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18307 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18308 bgp_config_write_peer_global(vty, bgp, peer);
18309 }
18310
18311 /* listen range and limit for dynamic BGP neighbors */
18312 bgp_config_write_listen(vty, bgp);
18313
18314 /*
18315 * BGP default autoshutdown neighbors
18316 *
18317 * This must be placed after any peer and peer-group
18318 * configuration, to avoid setting all peers to shutdown after
18319 * a daemon restart, which is undesired behavior. (see #2286)
18320 */
18321 if (bgp->autoshutdown)
18322 vty_out(vty, " bgp default shutdown\n");
18323
18324 /* BGP instance administrative shutdown */
18325 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18326 vty_out(vty, " bgp shutdown\n");
18327
18328 if (bgp->allow_martian)
18329 vty_out(vty, " bgp allow-martian-nexthop\n");
18330
18331 if (bgp->fast_convergence)
18332 vty_out(vty, " bgp fast-convergence\n");
18333
18334 if (bgp->srv6_enabled) {
18335 vty_frame(vty, " !\n segment-routing srv6\n");
18336 if (strlen(bgp->srv6_locator_name))
18337 vty_out(vty, " locator %s\n",
18338 bgp->srv6_locator_name);
18339 vty_endframe(vty, " exit\n");
18340 }
18341
18342 tovpn_sid_index = bgp->tovpn_sid_index;
18343 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18344 vty_out(vty, " sid vpn per-vrf export auto\n");
18345 } else if (tovpn_sid_index != 0) {
18346 vty_out(vty, " sid vpn per-vrf export %d\n",
18347 tovpn_sid_index);
18348 }
18349
18350 /* IPv4 unicast configuration. */
18351 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18352
18353 /* IPv4 multicast configuration. */
18354 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18355
18356 /* IPv4 labeled-unicast configuration. */
18357 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18358
18359 /* IPv4 VPN configuration. */
18360 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18361
18362 /* ENCAPv4 configuration. */
18363 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18364
18365 /* FLOWSPEC v4 configuration. */
18366 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18367
18368 /* IPv6 unicast configuration. */
18369 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18370
18371 /* IPv6 multicast configuration. */
18372 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18373
18374 /* IPv6 labeled-unicast configuration. */
18375 bgp_config_write_family(vty, bgp, AFI_IP6,
18376 SAFI_LABELED_UNICAST);
18377
18378 /* IPv6 VPN configuration. */
18379 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18380
18381 /* ENCAPv6 configuration. */
18382 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18383
18384 /* FLOWSPEC v6 configuration. */
18385 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18386
18387 /* EVPN configuration. */
18388 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18389
18390 hook_call(bgp_inst_config_write, bgp, vty);
18391
18392 #ifdef ENABLE_BGP_VNC
18393 bgp_rfapi_cfg_write(vty, bgp);
18394 #endif
18395
18396 vty_out(vty, "exit\n");
18397 vty_out(vty, "!\n");
18398 }
18399 return 0;
18400 }
18401
18402
18403 /* BGP node structure. */
18404 static struct cmd_node bgp_node = {
18405 .name = "bgp",
18406 .node = BGP_NODE,
18407 .parent_node = CONFIG_NODE,
18408 .prompt = "%s(config-router)# ",
18409 .config_write = bgp_config_write,
18410 };
18411
18412 static struct cmd_node bgp_ipv4_unicast_node = {
18413 .name = "bgp ipv4 unicast",
18414 .node = BGP_IPV4_NODE,
18415 .parent_node = BGP_NODE,
18416 .prompt = "%s(config-router-af)# ",
18417 .no_xpath = true,
18418 };
18419
18420 static struct cmd_node bgp_ipv4_multicast_node = {
18421 .name = "bgp ipv4 multicast",
18422 .node = BGP_IPV4M_NODE,
18423 .parent_node = BGP_NODE,
18424 .prompt = "%s(config-router-af)# ",
18425 .no_xpath = true,
18426 };
18427
18428 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18429 .name = "bgp ipv4 labeled unicast",
18430 .node = BGP_IPV4L_NODE,
18431 .parent_node = BGP_NODE,
18432 .prompt = "%s(config-router-af)# ",
18433 .no_xpath = true,
18434 };
18435
18436 static struct cmd_node bgp_ipv6_unicast_node = {
18437 .name = "bgp ipv6 unicast",
18438 .node = BGP_IPV6_NODE,
18439 .parent_node = BGP_NODE,
18440 .prompt = "%s(config-router-af)# ",
18441 .no_xpath = true,
18442 };
18443
18444 static struct cmd_node bgp_ipv6_multicast_node = {
18445 .name = "bgp ipv6 multicast",
18446 .node = BGP_IPV6M_NODE,
18447 .parent_node = BGP_NODE,
18448 .prompt = "%s(config-router-af)# ",
18449 .no_xpath = true,
18450 };
18451
18452 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18453 .name = "bgp ipv6 labeled unicast",
18454 .node = BGP_IPV6L_NODE,
18455 .parent_node = BGP_NODE,
18456 .prompt = "%s(config-router-af)# ",
18457 .no_xpath = true,
18458 };
18459
18460 static struct cmd_node bgp_vpnv4_node = {
18461 .name = "bgp vpnv4",
18462 .node = BGP_VPNV4_NODE,
18463 .parent_node = BGP_NODE,
18464 .prompt = "%s(config-router-af)# ",
18465 .no_xpath = true,
18466 };
18467
18468 static struct cmd_node bgp_vpnv6_node = {
18469 .name = "bgp vpnv6",
18470 .node = BGP_VPNV6_NODE,
18471 .parent_node = BGP_NODE,
18472 .prompt = "%s(config-router-af-vpnv6)# ",
18473 .no_xpath = true,
18474 };
18475
18476 static struct cmd_node bgp_evpn_node = {
18477 .name = "bgp evpn",
18478 .node = BGP_EVPN_NODE,
18479 .parent_node = BGP_NODE,
18480 .prompt = "%s(config-router-evpn)# ",
18481 .no_xpath = true,
18482 };
18483
18484 static struct cmd_node bgp_evpn_vni_node = {
18485 .name = "bgp evpn vni",
18486 .node = BGP_EVPN_VNI_NODE,
18487 .parent_node = BGP_EVPN_NODE,
18488 .prompt = "%s(config-router-af-vni)# ",
18489 };
18490
18491 static struct cmd_node bgp_flowspecv4_node = {
18492 .name = "bgp ipv4 flowspec",
18493 .node = BGP_FLOWSPECV4_NODE,
18494 .parent_node = BGP_NODE,
18495 .prompt = "%s(config-router-af)# ",
18496 .no_xpath = true,
18497 };
18498
18499 static struct cmd_node bgp_flowspecv6_node = {
18500 .name = "bgp ipv6 flowspec",
18501 .node = BGP_FLOWSPECV6_NODE,
18502 .parent_node = BGP_NODE,
18503 .prompt = "%s(config-router-af-vpnv6)# ",
18504 .no_xpath = true,
18505 };
18506
18507 static struct cmd_node bgp_srv6_node = {
18508 .name = "bgp srv6",
18509 .node = BGP_SRV6_NODE,
18510 .parent_node = BGP_NODE,
18511 .prompt = "%s(config-router-srv6)# ",
18512 };
18513
18514 static void community_list_vty(void);
18515
18516 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18517 {
18518 struct bgp *bgp;
18519 struct peer_group *group;
18520 struct listnode *lnbgp, *lnpeer;
18521
18522 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18523 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18524 vector_set(comps,
18525 XSTRDUP(MTYPE_COMPLETION, group->name));
18526 }
18527 }
18528
18529 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18530 {
18531 struct bgp *bgp;
18532 struct peer *peer;
18533 struct listnode *lnbgp, *lnpeer;
18534
18535 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18536 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18537 /* only provide suggestions on the appropriate input
18538 * token type,
18539 * they'll otherwise show up multiple times */
18540 enum cmd_token_type match_type;
18541 char *name = peer->host;
18542
18543 if (peer->conf_if) {
18544 match_type = VARIABLE_TKN;
18545 name = peer->conf_if;
18546 } else if (strchr(peer->host, ':'))
18547 match_type = IPV6_TKN;
18548 else
18549 match_type = IPV4_TKN;
18550
18551 if (token->type != match_type)
18552 continue;
18553
18554 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18555 }
18556 }
18557 }
18558
18559 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18560 {
18561 bgp_ac_peer(comps, token);
18562
18563 if (token->type == VARIABLE_TKN)
18564 bgp_ac_peergroup(comps, token);
18565 }
18566
18567 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18568 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18569 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18570 {.varname = "peer", .completions = bgp_ac_neighbor},
18571 {.completions = NULL}};
18572
18573 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18574 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18575 {.completions = NULL} };
18576
18577 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18578
18579 static struct thread *t_bgp_cfg;
18580
18581 bool bgp_config_inprocess(void)
18582 {
18583 return thread_is_scheduled(t_bgp_cfg);
18584 }
18585
18586 static void bgp_config_finish(struct thread *t)
18587 {
18588 struct listnode *node;
18589 struct bgp *bgp;
18590
18591 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18592 hook_call(bgp_config_end, bgp);
18593 }
18594
18595 static void bgp_config_start(void)
18596 {
18597 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18598 THREAD_OFF(t_bgp_cfg);
18599 thread_add_timer(bm->master, bgp_config_finish, NULL,
18600 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18601 }
18602
18603 /* When we receive a hook the configuration is read,
18604 * we start a timer to make sure we postpone sending
18605 * EoR before route-maps are processed.
18606 * This is especially valid if using `bgp route-map delay-timer`.
18607 */
18608 static void bgp_config_end(void)
18609 {
18610 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18611 uint32_t bgp_post_config_delay =
18612 thread_is_scheduled(bm->t_rmap_update)
18613 ? thread_timer_remain_second(bm->t_rmap_update)
18614 : BGP_POST_CONFIG_DELAY_SECONDS;
18615
18616 /* If BGP config processing thread isn't running, then
18617 * we can return and rely it's properly handled.
18618 */
18619 if (!bgp_config_inprocess())
18620 return;
18621
18622 THREAD_OFF(t_bgp_cfg);
18623
18624 /* Start a new timer to make sure we don't send EoR
18625 * before route-maps are processed.
18626 */
18627 thread_add_timer(bm->master, bgp_config_finish, NULL,
18628 bgp_post_config_delay, &t_bgp_cfg);
18629 }
18630
18631 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18632 {
18633 int write = 0;
18634 struct interface *ifp;
18635 struct bgp_interface *iifp;
18636
18637 FOR_ALL_INTERFACES (vrf, ifp) {
18638 iifp = ifp->info;
18639 if (!iifp)
18640 continue;
18641
18642 if_vty_config_start(vty, ifp);
18643
18644 if (CHECK_FLAG(iifp->flags,
18645 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18646 vty_out(vty, " mpls bgp forwarding\n");
18647 write++;
18648 }
18649
18650 if_vty_config_end(vty);
18651 }
18652
18653 return write;
18654 }
18655
18656 /* Configuration write function for bgpd. */
18657 static int config_write_interface(struct vty *vty)
18658 {
18659 int write = 0;
18660 struct vrf *vrf = NULL;
18661
18662 /* Display all VRF aware OSPF interface configuration */
18663 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18664 write += config_write_interface_one(vty, vrf);
18665 }
18666
18667 return write;
18668 }
18669
18670 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18671 "[no$no] mpls bgp forwarding",
18672 NO_STR MPLS_STR BGP_STR
18673 "Enable MPLS forwarding for eBGP directly connected peers\n")
18674 {
18675 bool check;
18676 struct bgp_interface *iifp;
18677
18678 VTY_DECLVAR_CONTEXT(interface, ifp);
18679 iifp = ifp->info;
18680 if (!iifp) {
18681 vty_out(vty, "Interface %s not available\n", ifp->name);
18682 return CMD_WARNING_CONFIG_FAILED;
18683 }
18684 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18685 if (check != !no) {
18686 if (no)
18687 UNSET_FLAG(iifp->flags,
18688 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18689 else
18690 SET_FLAG(iifp->flags,
18691 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18692 /* trigger a nht update on eBGP sessions */
18693 if (if_is_operative(ifp))
18694 bgp_nht_ifp_up(ifp);
18695 }
18696 return CMD_SUCCESS;
18697 }
18698
18699 DEFPY (bgp_inq_limit,
18700 bgp_inq_limit_cmd,
18701 "bgp input-queue-limit (1-4294967295)$limit",
18702 BGP_STR
18703 "Set the BGP Input Queue limit for all peers when message parsing\n"
18704 "Input-Queue limit\n")
18705 {
18706 bm->inq_limit = limit;
18707
18708 return CMD_SUCCESS;
18709 }
18710
18711 DEFPY (no_bgp_inq_limit,
18712 no_bgp_inq_limit_cmd,
18713 "no bgp input-queue-limit [(1-4294967295)$limit]",
18714 NO_STR
18715 BGP_STR
18716 "Set the BGP Input Queue limit for all peers when message parsing\n"
18717 "Input-Queue limit\n")
18718 {
18719 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18720
18721 return CMD_SUCCESS;
18722 }
18723
18724 DEFPY (bgp_outq_limit,
18725 bgp_outq_limit_cmd,
18726 "bgp output-queue-limit (1-4294967295)$limit",
18727 BGP_STR
18728 "Set the BGP Output Queue limit for all peers when message parsing\n"
18729 "Output-Queue limit\n")
18730 {
18731 bm->outq_limit = limit;
18732
18733 return CMD_SUCCESS;
18734 }
18735
18736 DEFPY (no_bgp_outq_limit,
18737 no_bgp_outq_limit_cmd,
18738 "no bgp output-queue-limit [(1-4294967295)$limit]",
18739 NO_STR
18740 BGP_STR
18741 "Set the BGP Output Queue limit for all peers when message parsing\n"
18742 "Output-Queue limit\n")
18743 {
18744 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18745
18746 return CMD_SUCCESS;
18747 }
18748
18749
18750 /* Initialization of BGP interface. */
18751 static void bgp_vty_if_init(void)
18752 {
18753 /* Install interface node. */
18754 if_cmd_init(config_write_interface);
18755
18756 /* "mpls bgp forwarding" commands. */
18757 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18758 }
18759
18760 void bgp_vty_init(void)
18761 {
18762 cmd_variable_handler_register(bgp_var_neighbor);
18763 cmd_variable_handler_register(bgp_var_peergroup);
18764
18765 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18766
18767 /* Install bgp top node. */
18768 install_node(&bgp_node);
18769 install_node(&bgp_ipv4_unicast_node);
18770 install_node(&bgp_ipv4_multicast_node);
18771 install_node(&bgp_ipv4_labeled_unicast_node);
18772 install_node(&bgp_ipv6_unicast_node);
18773 install_node(&bgp_ipv6_multicast_node);
18774 install_node(&bgp_ipv6_labeled_unicast_node);
18775 install_node(&bgp_vpnv4_node);
18776 install_node(&bgp_vpnv6_node);
18777 install_node(&bgp_evpn_node);
18778 install_node(&bgp_evpn_vni_node);
18779 install_node(&bgp_flowspecv4_node);
18780 install_node(&bgp_flowspecv6_node);
18781 install_node(&bgp_srv6_node);
18782
18783 /* Install default VTY commands to new nodes. */
18784 install_default(BGP_NODE);
18785 install_default(BGP_IPV4_NODE);
18786 install_default(BGP_IPV4M_NODE);
18787 install_default(BGP_IPV4L_NODE);
18788 install_default(BGP_IPV6_NODE);
18789 install_default(BGP_IPV6M_NODE);
18790 install_default(BGP_IPV6L_NODE);
18791 install_default(BGP_VPNV4_NODE);
18792 install_default(BGP_VPNV6_NODE);
18793 install_default(BGP_FLOWSPECV4_NODE);
18794 install_default(BGP_FLOWSPECV6_NODE);
18795 install_default(BGP_EVPN_NODE);
18796 install_default(BGP_EVPN_VNI_NODE);
18797 install_default(BGP_SRV6_NODE);
18798
18799 /* "global bgp inq-limit command */
18800 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18801 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18802 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18803 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
18804
18805 /* "bgp local-mac" hidden commands. */
18806 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18807 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18808
18809 /* "bgp suppress-fib-pending" global */
18810 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18811
18812 /* bgp route-map delay-timer commands. */
18813 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18814 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18815
18816 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18817
18818 /* bgp fast-convergence command */
18819 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18820 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18821
18822 /* global bgp update-delay command */
18823 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18824 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18825
18826 /* global bgp graceful-shutdown command */
18827 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18828 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18829
18830 /* Dummy commands (Currently not supported) */
18831 install_element(BGP_NODE, &no_synchronization_cmd);
18832 install_element(BGP_NODE, &no_auto_summary_cmd);
18833
18834 /* "router bgp" commands. */
18835 install_element(CONFIG_NODE, &router_bgp_cmd);
18836
18837 /* "no router bgp" commands. */
18838 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18839
18840 /* "bgp session-dscp command */
18841 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18842 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18843
18844 /* "bgp router-id" commands. */
18845 install_element(BGP_NODE, &bgp_router_id_cmd);
18846 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18847
18848 /* "bgp suppress-fib-pending" command */
18849 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18850
18851 /* "bgp cluster-id" commands. */
18852 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18853 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18854
18855 /* "bgp no-rib" commands. */
18856 install_element(CONFIG_NODE, &bgp_norib_cmd);
18857 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18858
18859 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18860
18861 /* "bgp confederation" commands. */
18862 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18863 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18864
18865 /* "bgp confederation peers" commands. */
18866 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18867 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18868
18869 /* bgp max-med command */
18870 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18871 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18872 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18873 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18874 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18875
18876 /* "neighbor role" commands. */
18877 install_element(BGP_NODE, &neighbor_role_cmd);
18878 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18879 install_element(BGP_NODE, &no_neighbor_role_cmd);
18880
18881 /* "neighbor aigp" commands. */
18882 install_element(BGP_NODE, &neighbor_aigp_cmd);
18883
18884 /* "neighbor graceful-shutdown" command */
18885 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18886
18887 /* bgp disable-ebgp-connected-nh-check */
18888 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18889 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18890
18891 /* bgp update-delay command */
18892 install_element(BGP_NODE, &bgp_update_delay_cmd);
18893 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18894
18895 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18896 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18897
18898 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18899 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18900
18901 /* "maximum-paths" commands. */
18902 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18903 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18904 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18905 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18906 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18907 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18908 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18909 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18910 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18911 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18912 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18913 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18914 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18915 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18916 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18917
18918 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18919 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18920 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18921 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18922 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18923 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18924 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18925 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18926 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18927 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18928
18929 /* "timers bgp" commands. */
18930 install_element(BGP_NODE, &bgp_timers_cmd);
18931 install_element(BGP_NODE, &no_bgp_timers_cmd);
18932
18933 /* "minimum-holdtime" commands. */
18934 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18935 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18936
18937 /* route-map delay-timer commands - per instance for backwards compat.
18938 */
18939 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18940 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18941
18942 /* "bgp client-to-client reflection" commands */
18943 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18944 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18945
18946 /* "bgp always-compare-med" commands */
18947 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18948 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18949
18950 /* bgp ebgp-requires-policy */
18951 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18952 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18953
18954 /* bgp suppress-duplicates */
18955 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18956 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18957
18958 /* bgp reject-as-sets */
18959 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18960 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18961
18962 /* "bgp deterministic-med" commands */
18963 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18964 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18965
18966 /* "bgp graceful-restart" command */
18967 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18968 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18969
18970 /* "bgp graceful-restart-disable" command */
18971 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18972 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18973
18974 /* "neighbor a:b:c:d graceful-restart" command */
18975 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18976 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18977
18978 /* "neighbor a:b:c:d graceful-restart-disable" command */
18979 install_element(BGP_NODE,
18980 &bgp_neighbor_graceful_restart_disable_set_cmd);
18981 install_element(BGP_NODE,
18982 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18983
18984 /* "neighbor a:b:c:d graceful-restart-helper" command */
18985 install_element(BGP_NODE,
18986 &bgp_neighbor_graceful_restart_helper_set_cmd);
18987 install_element(BGP_NODE,
18988 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18989
18990 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18991 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18992 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18993 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18994 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18995 install_element(BGP_NODE,
18996 &no_bgp_graceful_restart_select_defer_time_cmd);
18997 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18998 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18999 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
19000
19001 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19002 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
19003 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19004 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
19005
19006 /* "bgp graceful-shutdown" commands */
19007 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19008 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19009
19010 /* "bgp hard-administrative-reset" commands */
19011 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19012
19013 /* "bgp long-lived-graceful-restart" commands */
19014 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19015 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19016
19017 /* "bgp fast-external-failover" commands */
19018 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19019 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19020
19021 /* "bgp bestpath aigp" commands */
19022 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19023
19024 /* "bgp bestpath compare-routerid" commands */
19025 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19026 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19027
19028 /* "bgp bestpath as-path ignore" commands */
19029 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19030 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19031
19032 /* "bgp bestpath as-path confed" commands */
19033 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19034 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19035
19036 /* "bgp bestpath as-path multipath-relax" commands */
19037 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19038 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19039
19040 /* "bgp bestpath peer-type multipath-relax" commands */
19041 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19042 install_element(BGP_NODE,
19043 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19044
19045 /* "bgp log-neighbor-changes" commands */
19046 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19047 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19048
19049 /* "bgp bestpath med" commands */
19050 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19051 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19052
19053 /* "bgp bestpath bandwidth" commands */
19054 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
19055 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
19056
19057 /* "no bgp default <afi>-<safi>" commands. */
19058 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
19059
19060 /* "bgp network import-check" commands. */
19061 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19062 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19063 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19064
19065 /* "bgp default local-preference" commands. */
19066 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19067 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19068
19069 /* bgp default show-hostname */
19070 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19071 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19072
19073 /* bgp default show-nexthop-hostname */
19074 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19075 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19076
19077 /* "bgp default subgroup-pkt-queue-max" commands. */
19078 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19079 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19080
19081 /* bgp ibgp-allow-policy-mods command */
19082 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19083 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19084
19085 /* "bgp listen limit" commands. */
19086 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19087 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19088
19089 /* "bgp listen range" commands. */
19090 install_element(BGP_NODE, &bgp_listen_range_cmd);
19091 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19092
19093 /* "bgp default shutdown" command */
19094 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19095
19096 /* "bgp shutdown" commands */
19097 install_element(BGP_NODE, &bgp_shutdown_cmd);
19098 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19099 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19100 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19101
19102 /* "neighbor remote-as" commands. */
19103 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19104 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19105 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19106 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19107 install_element(BGP_NODE,
19108 &neighbor_interface_v6only_config_remote_as_cmd);
19109 install_element(BGP_NODE, &no_neighbor_cmd);
19110 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19111
19112 /* "neighbor peer-group" commands. */
19113 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19114 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19115 install_element(BGP_NODE,
19116 &no_neighbor_interface_peer_group_remote_as_cmd);
19117
19118 /* "neighbor local-as" commands. */
19119 install_element(BGP_NODE, &neighbor_local_as_cmd);
19120 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19121 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19122 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19123
19124 /* "neighbor solo" commands. */
19125 install_element(BGP_NODE, &neighbor_solo_cmd);
19126 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19127
19128 /* "neighbor password" commands. */
19129 install_element(BGP_NODE, &neighbor_password_cmd);
19130 install_element(BGP_NODE, &no_neighbor_password_cmd);
19131
19132 /* "neighbor activate" commands. */
19133 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19134 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19135 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19136 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19137 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19138 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19139 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19140 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19141 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19142 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19143 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19144 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19145
19146 /* "no neighbor activate" commands. */
19147 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19148 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19149 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19150 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19151 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19152 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19153 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19154 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19155 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19156 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19157 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19158 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19159
19160 /* "neighbor peer-group" set commands. */
19161 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19162 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19163 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19164 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19165 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19166 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19167 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19168 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19169 install_element(BGP_FLOWSPECV4_NODE,
19170 &neighbor_set_peer_group_hidden_cmd);
19171 install_element(BGP_FLOWSPECV6_NODE,
19172 &neighbor_set_peer_group_hidden_cmd);
19173
19174 /* "no neighbor peer-group unset" commands. */
19175 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19176 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19177 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19178 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19179 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19180 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19181 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19182 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19183 install_element(BGP_FLOWSPECV4_NODE,
19184 &no_neighbor_set_peer_group_hidden_cmd);
19185 install_element(BGP_FLOWSPECV6_NODE,
19186 &no_neighbor_set_peer_group_hidden_cmd);
19187
19188 /* "neighbor softreconfiguration inbound" commands.*/
19189 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19190 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19191 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19192 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19193 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19194 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19195 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19196 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19197 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19198 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19199 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19200 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19201 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19202 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19203 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19204 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19205 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19206 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19207 install_element(BGP_FLOWSPECV4_NODE,
19208 &neighbor_soft_reconfiguration_cmd);
19209 install_element(BGP_FLOWSPECV4_NODE,
19210 &no_neighbor_soft_reconfiguration_cmd);
19211 install_element(BGP_FLOWSPECV6_NODE,
19212 &neighbor_soft_reconfiguration_cmd);
19213 install_element(BGP_FLOWSPECV6_NODE,
19214 &no_neighbor_soft_reconfiguration_cmd);
19215 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19216 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19217
19218 /* "neighbor attribute-unchanged" commands. */
19219 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19220 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19221 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19222 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19223 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19224 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19225 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19226 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19227 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19228 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19229 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19230 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19231 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19232 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19233 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19234 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19235 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19236 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19237
19238 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19239 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19240
19241 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19242 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19243 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19244 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19245
19246 /* "nexthop-local unchanged" commands */
19247 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19248 install_element(BGP_IPV6_NODE,
19249 &no_neighbor_nexthop_local_unchanged_cmd);
19250
19251 /* "neighbor next-hop-self" commands. */
19252 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19253 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19254 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19255 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19256 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19257 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19258 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19259 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19260 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19261 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19262 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19263 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19264 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19265 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19266 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19267 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19268 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19269 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19270 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19271 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19272
19273 /* "neighbor next-hop-self force" commands. */
19274 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19275 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19276 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19277 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19278 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19279 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19280 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19281 install_element(BGP_IPV4_NODE,
19282 &no_neighbor_nexthop_self_all_hidden_cmd);
19283 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19284 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19285 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19286 install_element(BGP_IPV4M_NODE,
19287 &no_neighbor_nexthop_self_all_hidden_cmd);
19288 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19289 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19290 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19291 install_element(BGP_IPV4L_NODE,
19292 &no_neighbor_nexthop_self_all_hidden_cmd);
19293 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19294 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19295 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19296 install_element(BGP_IPV6_NODE,
19297 &no_neighbor_nexthop_self_all_hidden_cmd);
19298 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19299 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19300 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19301 install_element(BGP_IPV6M_NODE,
19302 &no_neighbor_nexthop_self_all_hidden_cmd);
19303 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19304 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19305 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19306 install_element(BGP_IPV6L_NODE,
19307 &no_neighbor_nexthop_self_all_hidden_cmd);
19308 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19309 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19310 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19311 install_element(BGP_VPNV4_NODE,
19312 &no_neighbor_nexthop_self_all_hidden_cmd);
19313 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19314 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19315 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19316 install_element(BGP_VPNV6_NODE,
19317 &no_neighbor_nexthop_self_all_hidden_cmd);
19318 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19319 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19320
19321 /* "neighbor as-override" commands. */
19322 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19323 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19324 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19325 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19326 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19327 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19328 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19329 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19330 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19331 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19332 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19333 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19334 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19335 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19336 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19337 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19338 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19339 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19340
19341 /* "neighbor remove-private-AS" commands. */
19342 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19343 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19344 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19345 install_element(BGP_NODE,
19346 &no_neighbor_remove_private_as_all_hidden_cmd);
19347 install_element(BGP_NODE,
19348 &neighbor_remove_private_as_replace_as_hidden_cmd);
19349 install_element(BGP_NODE,
19350 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19351 install_element(BGP_NODE,
19352 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19353 install_element(
19354 BGP_NODE,
19355 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19356 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19357 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19358 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19359 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19360 install_element(BGP_IPV4_NODE,
19361 &neighbor_remove_private_as_replace_as_cmd);
19362 install_element(BGP_IPV4_NODE,
19363 &no_neighbor_remove_private_as_replace_as_cmd);
19364 install_element(BGP_IPV4_NODE,
19365 &neighbor_remove_private_as_all_replace_as_cmd);
19366 install_element(BGP_IPV4_NODE,
19367 &no_neighbor_remove_private_as_all_replace_as_cmd);
19368 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19369 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19370 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19371 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19372 install_element(BGP_IPV4M_NODE,
19373 &neighbor_remove_private_as_replace_as_cmd);
19374 install_element(BGP_IPV4M_NODE,
19375 &no_neighbor_remove_private_as_replace_as_cmd);
19376 install_element(BGP_IPV4M_NODE,
19377 &neighbor_remove_private_as_all_replace_as_cmd);
19378 install_element(BGP_IPV4M_NODE,
19379 &no_neighbor_remove_private_as_all_replace_as_cmd);
19380 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19381 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19382 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19383 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19384 install_element(BGP_IPV4L_NODE,
19385 &neighbor_remove_private_as_replace_as_cmd);
19386 install_element(BGP_IPV4L_NODE,
19387 &no_neighbor_remove_private_as_replace_as_cmd);
19388 install_element(BGP_IPV4L_NODE,
19389 &neighbor_remove_private_as_all_replace_as_cmd);
19390 install_element(BGP_IPV4L_NODE,
19391 &no_neighbor_remove_private_as_all_replace_as_cmd);
19392 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19393 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19394 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19395 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19396 install_element(BGP_IPV6_NODE,
19397 &neighbor_remove_private_as_replace_as_cmd);
19398 install_element(BGP_IPV6_NODE,
19399 &no_neighbor_remove_private_as_replace_as_cmd);
19400 install_element(BGP_IPV6_NODE,
19401 &neighbor_remove_private_as_all_replace_as_cmd);
19402 install_element(BGP_IPV6_NODE,
19403 &no_neighbor_remove_private_as_all_replace_as_cmd);
19404 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19405 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19406 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19407 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19408 install_element(BGP_IPV6M_NODE,
19409 &neighbor_remove_private_as_replace_as_cmd);
19410 install_element(BGP_IPV6M_NODE,
19411 &no_neighbor_remove_private_as_replace_as_cmd);
19412 install_element(BGP_IPV6M_NODE,
19413 &neighbor_remove_private_as_all_replace_as_cmd);
19414 install_element(BGP_IPV6M_NODE,
19415 &no_neighbor_remove_private_as_all_replace_as_cmd);
19416 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19417 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19418 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19419 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19420 install_element(BGP_IPV6L_NODE,
19421 &neighbor_remove_private_as_replace_as_cmd);
19422 install_element(BGP_IPV6L_NODE,
19423 &no_neighbor_remove_private_as_replace_as_cmd);
19424 install_element(BGP_IPV6L_NODE,
19425 &neighbor_remove_private_as_all_replace_as_cmd);
19426 install_element(BGP_IPV6L_NODE,
19427 &no_neighbor_remove_private_as_all_replace_as_cmd);
19428 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19429 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19430 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19431 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19432 install_element(BGP_VPNV4_NODE,
19433 &neighbor_remove_private_as_replace_as_cmd);
19434 install_element(BGP_VPNV4_NODE,
19435 &no_neighbor_remove_private_as_replace_as_cmd);
19436 install_element(BGP_VPNV4_NODE,
19437 &neighbor_remove_private_as_all_replace_as_cmd);
19438 install_element(BGP_VPNV4_NODE,
19439 &no_neighbor_remove_private_as_all_replace_as_cmd);
19440 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19441 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19442 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19443 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19444 install_element(BGP_VPNV6_NODE,
19445 &neighbor_remove_private_as_replace_as_cmd);
19446 install_element(BGP_VPNV6_NODE,
19447 &no_neighbor_remove_private_as_replace_as_cmd);
19448 install_element(BGP_VPNV6_NODE,
19449 &neighbor_remove_private_as_all_replace_as_cmd);
19450 install_element(BGP_VPNV6_NODE,
19451 &no_neighbor_remove_private_as_all_replace_as_cmd);
19452
19453 /* "neighbor send-community" commands.*/
19454 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19455 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19456 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19457 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19458 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19459 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19460 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19461 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19462 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19463 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19464 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19465 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19466 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19467 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19468 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19469 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19470 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19471 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19472 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19473 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19474 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19475 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19476 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19477 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19478 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19479 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19480 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19481 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19482 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19483 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19484 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19485 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19486 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19487 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19488 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19489 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19490
19491 /* "neighbor route-reflector" commands.*/
19492 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19493 install_element(BGP_NODE,
19494 &no_neighbor_route_reflector_client_hidden_cmd);
19495 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19496 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19497 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19498 install_element(BGP_IPV4M_NODE,
19499 &no_neighbor_route_reflector_client_cmd);
19500 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19501 install_element(BGP_IPV4L_NODE,
19502 &no_neighbor_route_reflector_client_cmd);
19503 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19504 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19505 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19506 install_element(BGP_IPV6M_NODE,
19507 &no_neighbor_route_reflector_client_cmd);
19508 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19509 install_element(BGP_IPV6L_NODE,
19510 &no_neighbor_route_reflector_client_cmd);
19511 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19512 install_element(BGP_VPNV4_NODE,
19513 &no_neighbor_route_reflector_client_cmd);
19514 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19515 install_element(BGP_VPNV6_NODE,
19516 &no_neighbor_route_reflector_client_cmd);
19517 install_element(BGP_FLOWSPECV4_NODE,
19518 &neighbor_route_reflector_client_cmd);
19519 install_element(BGP_FLOWSPECV4_NODE,
19520 &no_neighbor_route_reflector_client_cmd);
19521 install_element(BGP_FLOWSPECV6_NODE,
19522 &neighbor_route_reflector_client_cmd);
19523 install_element(BGP_FLOWSPECV6_NODE,
19524 &no_neighbor_route_reflector_client_cmd);
19525 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19526 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19527
19528 /* "neighbor route-server" commands.*/
19529 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19530 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19531 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19532 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19533 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19534 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19535 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19536 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19537 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19538 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19539 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19540 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19541 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19542 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19543 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19544 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19545 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19546 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19547 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19548 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19549 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19550 install_element(BGP_FLOWSPECV4_NODE,
19551 &no_neighbor_route_server_client_cmd);
19552 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19553 install_element(BGP_FLOWSPECV6_NODE,
19554 &no_neighbor_route_server_client_cmd);
19555
19556 /* "neighbor disable-addpath-rx" commands. */
19557 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19558 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19559 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19560 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19561 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19562 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19563 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19564 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19565 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19566 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19567 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19568 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19569 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19570 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19571 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19572 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19573
19574 /* "neighbor addpath-tx-all-paths" commands.*/
19575 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19576 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19577 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19578 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19579 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19580 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19581 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19582 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19583 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19584 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19585 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19586 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19587 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19588 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19589 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19590 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19591 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19592 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19593
19594 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19595 install_element(BGP_NODE,
19596 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19597 install_element(BGP_NODE,
19598 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19599 install_element(BGP_IPV4_NODE,
19600 &neighbor_addpath_tx_bestpath_per_as_cmd);
19601 install_element(BGP_IPV4_NODE,
19602 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19603 install_element(BGP_IPV4M_NODE,
19604 &neighbor_addpath_tx_bestpath_per_as_cmd);
19605 install_element(BGP_IPV4M_NODE,
19606 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19607 install_element(BGP_IPV4L_NODE,
19608 &neighbor_addpath_tx_bestpath_per_as_cmd);
19609 install_element(BGP_IPV4L_NODE,
19610 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19611 install_element(BGP_IPV6_NODE,
19612 &neighbor_addpath_tx_bestpath_per_as_cmd);
19613 install_element(BGP_IPV6_NODE,
19614 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19615 install_element(BGP_IPV6M_NODE,
19616 &neighbor_addpath_tx_bestpath_per_as_cmd);
19617 install_element(BGP_IPV6M_NODE,
19618 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19619 install_element(BGP_IPV6L_NODE,
19620 &neighbor_addpath_tx_bestpath_per_as_cmd);
19621 install_element(BGP_IPV6L_NODE,
19622 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19623 install_element(BGP_VPNV4_NODE,
19624 &neighbor_addpath_tx_bestpath_per_as_cmd);
19625 install_element(BGP_VPNV4_NODE,
19626 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19627 install_element(BGP_VPNV6_NODE,
19628 &neighbor_addpath_tx_bestpath_per_as_cmd);
19629 install_element(BGP_VPNV6_NODE,
19630 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19631
19632 /* "neighbor sender-as-path-loop-detection" commands. */
19633 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19634 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19635
19636 /* "neighbor path-attribute discard" commands. */
19637 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19638 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
19639
19640 /* "neighbor passive" commands. */
19641 install_element(BGP_NODE, &neighbor_passive_cmd);
19642 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19643
19644
19645 /* "neighbor shutdown" commands. */
19646 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19647 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19648 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19649 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19650 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19651 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19652
19653 /* "neighbor capability extended-nexthop" commands.*/
19654 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19655 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19656
19657 /* "neighbor capability orf prefix-list" commands.*/
19658 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19659 install_element(BGP_NODE,
19660 &no_neighbor_capability_orf_prefix_hidden_cmd);
19661 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19662 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19663 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19664 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19665 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19666 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19667 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19668 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19669 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19670 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19671 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19672 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19673
19674 /* "neighbor capability dynamic" commands.*/
19675 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19676 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19677
19678 /* "neighbor dont-capability-negotiate" commands. */
19679 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19680 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19681
19682 /* "neighbor ebgp-multihop" commands. */
19683 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19684 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19685 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19686
19687 /* "neighbor disable-connected-check" commands. */
19688 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19689 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19690
19691 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19692 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19693 install_element(BGP_NODE,
19694 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19695
19696 /* "neighbor extended-optional-parameters" commands. */
19697 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19698 install_element(BGP_NODE,
19699 &no_neighbor_extended_optional_parameters_cmd);
19700
19701 /* "neighbor enforce-first-as" commands. */
19702 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19703 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19704
19705 /* "neighbor description" commands. */
19706 install_element(BGP_NODE, &neighbor_description_cmd);
19707 install_element(BGP_NODE, &no_neighbor_description_cmd);
19708 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19709
19710 /* "neighbor update-source" commands. "*/
19711 install_element(BGP_NODE, &neighbor_update_source_cmd);
19712 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19713
19714 /* "neighbor default-originate" commands. */
19715 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19716 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19717 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19718 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19719 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19720 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19721 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19722 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19723 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19724 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19725 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19726 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19727 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19728 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19729 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19730 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19731 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19732 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19733 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19734 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19735 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19736
19737 /* "neighbor port" commands. */
19738 install_element(BGP_NODE, &neighbor_port_cmd);
19739 install_element(BGP_NODE, &no_neighbor_port_cmd);
19740
19741 /* "neighbor weight" commands. */
19742 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19743 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19744
19745 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19746 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19747 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19748 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19749 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19750 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19751 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19752 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19753 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19754 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19755 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19756 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19757 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19758 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19759 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19760 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19761
19762 /* "neighbor override-capability" commands. */
19763 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19764 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19765
19766 /* "neighbor strict-capability-match" commands. */
19767 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19768 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19769
19770 /* "neighbor timers" commands. */
19771 install_element(BGP_NODE, &neighbor_timers_cmd);
19772 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19773
19774 /* "neighbor timers connect" commands. */
19775 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19776 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19777
19778 /* "neighbor timers delayopen" commands. */
19779 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19780 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19781
19782 /* "neighbor advertisement-interval" commands. */
19783 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19784 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19785
19786 /* "neighbor interface" commands. */
19787 install_element(BGP_NODE, &neighbor_interface_cmd);
19788 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19789
19790 /* "neighbor distribute" commands. */
19791 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19792 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19793 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19794 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19795 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19796 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19797 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19798 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19799 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19800 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19801 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19802 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19803 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19804 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19805 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19806 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19807 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19808 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19809
19810 /* "neighbor prefix-list" commands. */
19811 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19812 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19813 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19814 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19815 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19816 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19817 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19818 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19819 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19820 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19821 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19822 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19823 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19824 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19825 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19826 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19827 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19828 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19829 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19830 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19831 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19832 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19833
19834 /* "neighbor filter-list" commands. */
19835 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19836 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19837 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19838 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19839 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19840 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19841 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19842 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19843 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19844 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19845 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19846 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19847 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19848 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19849 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19850 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19851 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19852 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19853 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19854 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19855 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19856 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19857
19858 /* "neighbor route-map" commands. */
19859 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19860 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19861 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19862 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19863 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19864 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19865 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19866 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19867 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19868 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19869 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19870 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19871 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19872 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19873 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19874 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19875 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19876 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19877 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19878 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19879 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19880 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19881 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19882 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19883
19884 /* "neighbor unsuppress-map" commands. */
19885 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19886 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19887 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19888 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19889 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19890 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19891 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19892 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19893 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19894 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19895 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19896 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19897 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19898 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19899 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19900 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19901 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19902 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19903
19904 /* "neighbor advertise-map" commands. */
19905 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19906 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19907 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19908 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19909 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19910 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19911 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19912 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19913 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19914 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19915
19916 /* neighbor maximum-prefix-out commands. */
19917 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19918 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19919 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19920 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19921 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19922 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19923 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19924 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19925 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19926 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19927 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19928 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19929 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19930 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19931 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19932 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19933 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19934 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19935
19936 /* "neighbor maximum-prefix" commands. */
19937 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19938 install_element(BGP_NODE,
19939 &neighbor_maximum_prefix_threshold_hidden_cmd);
19940 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19941 install_element(BGP_NODE,
19942 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19943 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19944 install_element(BGP_NODE,
19945 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19946 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19947 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19948 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19949 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19950 install_element(BGP_IPV4_NODE,
19951 &neighbor_maximum_prefix_threshold_warning_cmd);
19952 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19953 install_element(BGP_IPV4_NODE,
19954 &neighbor_maximum_prefix_threshold_restart_cmd);
19955 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19956 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19957 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19958 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19959 install_element(BGP_IPV4M_NODE,
19960 &neighbor_maximum_prefix_threshold_warning_cmd);
19961 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19962 install_element(BGP_IPV4M_NODE,
19963 &neighbor_maximum_prefix_threshold_restart_cmd);
19964 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19965 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19966 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19967 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19968 install_element(BGP_IPV4L_NODE,
19969 &neighbor_maximum_prefix_threshold_warning_cmd);
19970 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19971 install_element(BGP_IPV4L_NODE,
19972 &neighbor_maximum_prefix_threshold_restart_cmd);
19973 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19974 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19975 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19976 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19977 install_element(BGP_IPV6_NODE,
19978 &neighbor_maximum_prefix_threshold_warning_cmd);
19979 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19980 install_element(BGP_IPV6_NODE,
19981 &neighbor_maximum_prefix_threshold_restart_cmd);
19982 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19983 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19984 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19985 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19986 install_element(BGP_IPV6M_NODE,
19987 &neighbor_maximum_prefix_threshold_warning_cmd);
19988 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19989 install_element(BGP_IPV6M_NODE,
19990 &neighbor_maximum_prefix_threshold_restart_cmd);
19991 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19992 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19993 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19994 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19995 install_element(BGP_IPV6L_NODE,
19996 &neighbor_maximum_prefix_threshold_warning_cmd);
19997 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19998 install_element(BGP_IPV6L_NODE,
19999 &neighbor_maximum_prefix_threshold_restart_cmd);
20000 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20001 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20002 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20003 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20004 install_element(BGP_VPNV4_NODE,
20005 &neighbor_maximum_prefix_threshold_warning_cmd);
20006 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20007 install_element(BGP_VPNV4_NODE,
20008 &neighbor_maximum_prefix_threshold_restart_cmd);
20009 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20010 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20011 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20012 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20013 install_element(BGP_VPNV6_NODE,
20014 &neighbor_maximum_prefix_threshold_warning_cmd);
20015 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20016 install_element(BGP_VPNV6_NODE,
20017 &neighbor_maximum_prefix_threshold_restart_cmd);
20018 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20019
20020 /* "neighbor allowas-in" */
20021 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20022 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20023 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20024 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20025 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20026 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20027 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20028 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20029 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20030 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20031 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20032 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20033 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20034 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20035 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20036 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20037 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20038 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20039 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20040 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20041
20042 /* neighbor accept-own */
20043 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20044 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20045
20046 /* "neighbor soo" */
20047 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20048 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20049 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20050 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20051 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20052 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20053 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20054 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20055 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20056 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20057 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20058 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20059 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20060 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20061 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20062 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20063 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20064 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20065
20066 /* address-family commands. */
20067 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20068 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
20069 #ifdef KEEP_OLD_VPN_COMMANDS
20070 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20071 install_element(BGP_NODE, &address_family_vpnv6_cmd);
20072 #endif /* KEEP_OLD_VPN_COMMANDS */
20073
20074 install_element(BGP_NODE, &address_family_evpn_cmd);
20075
20076 /* "exit-address-family" command. */
20077 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20078 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20079 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20080 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20081 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20082 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20083 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20084 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
20085 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20086 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
20087 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20088
20089 /* BGP retain all route-target */
20090 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20091 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20092
20093 /* "clear ip bgp commands" */
20094 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20095
20096 /* clear ip bgp prefix */
20097 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20098 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20099 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20100
20101 /* "show [ip] bgp summary" commands. */
20102 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20103 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20104 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20105 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20106 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20107 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20108 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20109
20110 /* "show [ip] bgp neighbors" commands. */
20111 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20112
20113 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20114
20115 /* "show [ip] bgp peer-group" commands. */
20116 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20117
20118 /* "show [ip] bgp paths" commands. */
20119 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20120
20121 /* "show [ip] bgp community" commands. */
20122 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20123
20124 /* "show ip bgp large-community" commands. */
20125 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20126 /* "show [ip] bgp attribute-info" commands. */
20127 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20128 /* "show [ip] bgp route-leak" command */
20129 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20130
20131 /* "redistribute" commands. */
20132 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20133 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20134 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20135 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20136 install_element(BGP_NODE,
20137 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20138 install_element(BGP_NODE,
20139 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20140 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20141 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20142 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20143 install_element(BGP_NODE,
20144 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20145 install_element(BGP_NODE,
20146 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20147 install_element(BGP_NODE,
20148 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20149 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20150 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20151 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20152 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20153 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20154 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20155 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20156 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20157 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20158 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20159 install_element(BGP_IPV4_NODE,
20160 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20161 install_element(BGP_IPV4_NODE,
20162 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20163 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20164 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20165 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20166 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20167 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20168 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20169
20170 /* import|export vpn [route-map RMAP_NAME] */
20171 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20172 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20173
20174 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20175 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20176
20177 /* ttl_security commands */
20178 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20179 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20180
20181 /* "bgp tcp-keepalive" commands */
20182 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20183 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20184
20185 /* "show [ip] bgp memory" commands. */
20186 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20187
20188 /* "show bgp martian next-hop" */
20189 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20190
20191 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20192
20193 /* "show [ip] bgp views" commands. */
20194 install_element(VIEW_NODE, &show_bgp_views_cmd);
20195
20196 /* "show [ip] bgp vrfs" commands. */
20197 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20198
20199 /* Community-list. */
20200 community_list_vty();
20201
20202 community_alias_vty();
20203
20204 /* vpn-policy commands */
20205 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20206 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20207 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20208 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20209 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20210 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20211 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20212 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20213 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20214 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20215 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20216 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20217
20218 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20219 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20220
20221 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20222 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20223 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20224 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20225 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20226 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20227 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20228 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20229 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20230 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20231
20232 /* tcp-mss command */
20233 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20234 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20235
20236 /* srv6 commands */
20237 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20238 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20239 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20240 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20241 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20242 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20243 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20244 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20245 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20246
20247 bgp_vty_if_init();
20248 }
20249
20250 #include "memory.h"
20251 #include "bgp_regex.h"
20252 #include "bgp_clist.h"
20253 #include "bgp_ecommunity.h"
20254
20255 /* VTY functions. */
20256
20257 /* Direction value to string conversion. */
20258 static const char *community_direct_str(int direct)
20259 {
20260 switch (direct) {
20261 case COMMUNITY_DENY:
20262 return "deny";
20263 case COMMUNITY_PERMIT:
20264 return "permit";
20265 default:
20266 return "unknown";
20267 }
20268 }
20269
20270 /* Display error string. */
20271 static void community_list_perror(struct vty *vty, int ret)
20272 {
20273 switch (ret) {
20274 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20275 vty_out(vty, "%% Can't find community-list\n");
20276 break;
20277 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20278 vty_out(vty, "%% Malformed community-list value\n");
20279 break;
20280 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20281 vty_out(vty,
20282 "%% Community name conflict, previously defined as standard community\n");
20283 break;
20284 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20285 vty_out(vty,
20286 "%% Community name conflict, previously defined as expanded community\n");
20287 break;
20288 }
20289 }
20290
20291 /* "community-list" keyword help string. */
20292 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20293
20294 /*community-list standard */
20295 DEFUN (community_list_standard,
20296 bgp_community_list_standard_cmd,
20297 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20298 BGP_STR
20299 COMMUNITY_LIST_STR
20300 "Community list number (standard)\n"
20301 "Add an standard community-list entry\n"
20302 "Community list name\n"
20303 "Sequence number of an entry\n"
20304 "Sequence number\n"
20305 "Specify community to reject\n"
20306 "Specify community to accept\n"
20307 COMMUNITY_VAL_STR)
20308 {
20309 char *cl_name_or_number = NULL;
20310 char *seq = NULL;
20311 int direct = 0;
20312 int style = COMMUNITY_LIST_STANDARD;
20313 int idx = 0;
20314
20315 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20316 seq = argv[idx]->arg;
20317
20318 idx = 0;
20319 argv_find(argv, argc, "(1-99)", &idx);
20320 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20321 cl_name_or_number = argv[idx]->arg;
20322 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20323 : COMMUNITY_DENY;
20324 argv_find(argv, argc, "AA:NN", &idx);
20325 char *str = argv_concat(argv, argc, idx);
20326
20327 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20328 direct, style);
20329
20330 XFREE(MTYPE_TMP, str);
20331
20332 if (ret < 0) {
20333 /* Display error string. */
20334 community_list_perror(vty, ret);
20335 return CMD_WARNING_CONFIG_FAILED;
20336 }
20337
20338 return CMD_SUCCESS;
20339 }
20340
20341 DEFUN (no_community_list_standard_all,
20342 no_bgp_community_list_standard_all_cmd,
20343 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20344 NO_STR
20345 BGP_STR
20346 COMMUNITY_LIST_STR
20347 "Community list number (standard)\n"
20348 "Add an standard community-list entry\n"
20349 "Community list name\n"
20350 "Sequence number of an entry\n"
20351 "Sequence number\n"
20352 "Specify community to reject\n"
20353 "Specify community to accept\n"
20354 COMMUNITY_VAL_STR)
20355 {
20356 char *cl_name_or_number = NULL;
20357 char *str = NULL;
20358 int direct = 0;
20359 int style = COMMUNITY_LIST_STANDARD;
20360 char *seq = NULL;
20361 int idx = 0;
20362
20363 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20364 seq = argv[idx]->arg;
20365
20366 idx = 0;
20367 argv_find(argv, argc, "permit", &idx);
20368 argv_find(argv, argc, "deny", &idx);
20369
20370 if (idx) {
20371 direct = argv_find(argv, argc, "permit", &idx)
20372 ? COMMUNITY_PERMIT
20373 : COMMUNITY_DENY;
20374
20375 idx = 0;
20376 argv_find(argv, argc, "AA:NN", &idx);
20377 str = argv_concat(argv, argc, idx);
20378 }
20379
20380 idx = 0;
20381 argv_find(argv, argc, "(1-99)", &idx);
20382 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20383 cl_name_or_number = argv[idx]->arg;
20384
20385 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20386 direct, style);
20387
20388 XFREE(MTYPE_TMP, str);
20389
20390 if (ret < 0) {
20391 community_list_perror(vty, ret);
20392 return CMD_WARNING_CONFIG_FAILED;
20393 }
20394
20395 return CMD_SUCCESS;
20396 }
20397
20398 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20399 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20400 NO_STR BGP_STR COMMUNITY_LIST_STR
20401 "Community list number (standard)\n"
20402 "Add an standard community-list entry\n"
20403 "Community list name\n")
20404
20405 /*community-list expanded */
20406 DEFUN (community_list_expanded_all,
20407 bgp_community_list_expanded_all_cmd,
20408 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20409 BGP_STR
20410 COMMUNITY_LIST_STR
20411 "Community list number (expanded)\n"
20412 "Add an expanded community-list entry\n"
20413 "Community list name\n"
20414 "Sequence number of an entry\n"
20415 "Sequence number\n"
20416 "Specify community to reject\n"
20417 "Specify community to accept\n"
20418 COMMUNITY_VAL_STR)
20419 {
20420 char *cl_name_or_number = NULL;
20421 char *seq = NULL;
20422 int direct = 0;
20423 int style = COMMUNITY_LIST_EXPANDED;
20424 int idx = 0;
20425
20426 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20427 seq = argv[idx]->arg;
20428
20429 idx = 0;
20430
20431 argv_find(argv, argc, "(100-500)", &idx);
20432 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20433 cl_name_or_number = argv[idx]->arg;
20434 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20435 : COMMUNITY_DENY;
20436 argv_find(argv, argc, "AA:NN", &idx);
20437 char *str = argv_concat(argv, argc, idx);
20438
20439 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20440 direct, style);
20441
20442 XFREE(MTYPE_TMP, str);
20443
20444 if (ret < 0) {
20445 /* Display error string. */
20446 community_list_perror(vty, ret);
20447 return CMD_WARNING_CONFIG_FAILED;
20448 }
20449
20450 return CMD_SUCCESS;
20451 }
20452
20453 DEFUN (no_community_list_expanded_all,
20454 no_bgp_community_list_expanded_all_cmd,
20455 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20456 NO_STR
20457 BGP_STR
20458 COMMUNITY_LIST_STR
20459 "Community list number (expanded)\n"
20460 "Add an expanded community-list entry\n"
20461 "Community list name\n"
20462 "Sequence number of an entry\n"
20463 "Sequence number\n"
20464 "Specify community to reject\n"
20465 "Specify community to accept\n"
20466 COMMUNITY_VAL_STR)
20467 {
20468 char *cl_name_or_number = NULL;
20469 char *seq = NULL;
20470 char *str = NULL;
20471 int direct = 0;
20472 int style = COMMUNITY_LIST_EXPANDED;
20473 int idx = 0;
20474
20475 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20476 seq = argv[idx]->arg;
20477
20478 idx = 0;
20479 argv_find(argv, argc, "permit", &idx);
20480 argv_find(argv, argc, "deny", &idx);
20481
20482 if (idx) {
20483 direct = argv_find(argv, argc, "permit", &idx)
20484 ? COMMUNITY_PERMIT
20485 : COMMUNITY_DENY;
20486
20487 idx = 0;
20488 argv_find(argv, argc, "AA:NN", &idx);
20489 str = argv_concat(argv, argc, idx);
20490 }
20491
20492 idx = 0;
20493 argv_find(argv, argc, "(100-500)", &idx);
20494 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20495 cl_name_or_number = argv[idx]->arg;
20496
20497 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20498 direct, style);
20499
20500 XFREE(MTYPE_TMP, str);
20501
20502 if (ret < 0) {
20503 community_list_perror(vty, ret);
20504 return CMD_WARNING_CONFIG_FAILED;
20505 }
20506
20507 return CMD_SUCCESS;
20508 }
20509
20510 ALIAS(no_community_list_expanded_all,
20511 no_bgp_community_list_expanded_all_list_cmd,
20512 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20513 NO_STR BGP_STR COMMUNITY_LIST_STR
20514 "Community list number (expanded)\n"
20515 "Add an expanded community-list entry\n"
20516 "Community list name\n")
20517
20518 /* Return configuration string of community-list entry. */
20519 static const char *community_list_config_str(struct community_entry *entry)
20520 {
20521 const char *str;
20522
20523 if (entry->any)
20524 str = "";
20525 else {
20526 if (entry->style == COMMUNITY_LIST_STANDARD)
20527 str = community_str(entry->u.com, false, false);
20528 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20529 str = lcommunity_str(entry->u.lcom, false, false);
20530 else
20531 str = entry->config;
20532 }
20533 return str;
20534 }
20535
20536 static void community_list_show(struct vty *vty, struct community_list *list)
20537 {
20538 struct community_entry *entry;
20539
20540 for (entry = list->head; entry; entry = entry->next) {
20541 if (entry == list->head) {
20542 if (all_digit(list->name))
20543 vty_out(vty, "Community %s list %s\n",
20544 entry->style == COMMUNITY_LIST_STANDARD
20545 ? "standard"
20546 : "(expanded) access",
20547 list->name);
20548 else
20549 vty_out(vty, "Named Community %s list %s\n",
20550 entry->style == COMMUNITY_LIST_STANDARD
20551 ? "standard"
20552 : "expanded",
20553 list->name);
20554 }
20555 if (entry->any)
20556 vty_out(vty, " %s\n",
20557 community_direct_str(entry->direct));
20558 else
20559 vty_out(vty, " %s %s\n",
20560 community_direct_str(entry->direct),
20561 community_list_config_str(entry));
20562 }
20563 }
20564
20565 DEFUN (show_community_list,
20566 show_bgp_community_list_cmd,
20567 "show bgp community-list",
20568 SHOW_STR
20569 BGP_STR
20570 "List community-list\n")
20571 {
20572 struct community_list *list;
20573 struct community_list_master *cm;
20574
20575 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20576 if (!cm)
20577 return CMD_SUCCESS;
20578
20579 for (list = cm->num.head; list; list = list->next)
20580 community_list_show(vty, list);
20581
20582 for (list = cm->str.head; list; list = list->next)
20583 community_list_show(vty, list);
20584
20585 return CMD_SUCCESS;
20586 }
20587
20588 DEFUN (show_community_list_arg,
20589 show_bgp_community_list_arg_cmd,
20590 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20591 SHOW_STR
20592 BGP_STR
20593 "List community-list\n"
20594 "Community-list number\n"
20595 "Community-list name\n"
20596 "Detailed information on community-list\n")
20597 {
20598 int idx_comm_list = 3;
20599 struct community_list *list;
20600
20601 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20602 COMMUNITY_LIST_MASTER);
20603 if (!list) {
20604 vty_out(vty, "%% Can't find community-list\n");
20605 return CMD_WARNING;
20606 }
20607
20608 community_list_show(vty, list);
20609
20610 return CMD_SUCCESS;
20611 }
20612
20613 /*
20614 * Large Community code.
20615 */
20616 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20617 struct cmd_token **argv, int style,
20618 int reject_all_digit_name)
20619 {
20620 int ret;
20621 int direct;
20622 char *str;
20623 int idx = 0;
20624 char *cl_name;
20625 char *seq = NULL;
20626
20627 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20628 seq = argv[idx]->arg;
20629
20630 idx = 0;
20631 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20632 : COMMUNITY_DENY;
20633
20634 /* All digit name check. */
20635 idx = 0;
20636 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20637 argv_find(argv, argc, "(1-99)", &idx);
20638 argv_find(argv, argc, "(100-500)", &idx);
20639 cl_name = argv[idx]->arg;
20640 if (reject_all_digit_name && all_digit(cl_name)) {
20641 vty_out(vty, "%% Community name cannot have all digits\n");
20642 return CMD_WARNING_CONFIG_FAILED;
20643 }
20644
20645 idx = 0;
20646 argv_find(argv, argc, "AA:BB:CC", &idx);
20647 argv_find(argv, argc, "LINE", &idx);
20648 /* Concat community string argument. */
20649 if (idx)
20650 str = argv_concat(argv, argc, idx);
20651 else
20652 str = NULL;
20653
20654 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20655
20656 /* Free temporary community list string allocated by
20657 argv_concat(). */
20658 XFREE(MTYPE_TMP, str);
20659
20660 if (ret < 0) {
20661 community_list_perror(vty, ret);
20662 return CMD_WARNING_CONFIG_FAILED;
20663 }
20664 return CMD_SUCCESS;
20665 }
20666
20667 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20668 struct cmd_token **argv, int style)
20669 {
20670 int ret;
20671 int direct = 0;
20672 char *str = NULL;
20673 int idx = 0;
20674 char *seq = NULL;
20675
20676 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20677 seq = argv[idx]->arg;
20678
20679 idx = 0;
20680 argv_find(argv, argc, "permit", &idx);
20681 argv_find(argv, argc, "deny", &idx);
20682
20683 if (idx) {
20684 /* Check the list direct. */
20685 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20686 direct = COMMUNITY_PERMIT;
20687 else
20688 direct = COMMUNITY_DENY;
20689
20690 idx = 0;
20691 argv_find(argv, argc, "LINE", &idx);
20692 argv_find(argv, argc, "AA:AA:NN", &idx);
20693 /* Concat community string argument. */
20694 str = argv_concat(argv, argc, idx);
20695 }
20696
20697 idx = 0;
20698 argv_find(argv, argc, "(1-99)", &idx);
20699 argv_find(argv, argc, "(100-500)", &idx);
20700 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20701
20702 /* Unset community list. */
20703 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20704 style);
20705
20706 /* Free temporary community list string allocated by
20707 argv_concat(). */
20708 XFREE(MTYPE_TMP, str);
20709
20710 if (ret < 0) {
20711 community_list_perror(vty, ret);
20712 return CMD_WARNING_CONFIG_FAILED;
20713 }
20714
20715 return CMD_SUCCESS;
20716 }
20717
20718 /* "large-community-list" keyword help string. */
20719 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20720 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20721
20722 DEFUN (lcommunity_list_standard,
20723 bgp_lcommunity_list_standard_cmd,
20724 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20725 BGP_STR
20726 LCOMMUNITY_LIST_STR
20727 "Large Community list number (standard)\n"
20728 "Sequence number of an entry\n"
20729 "Sequence number\n"
20730 "Specify large community to reject\n"
20731 "Specify large community to accept\n"
20732 LCOMMUNITY_VAL_STR)
20733 {
20734 return lcommunity_list_set_vty(vty, argc, argv,
20735 LARGE_COMMUNITY_LIST_STANDARD, 0);
20736 }
20737
20738 DEFUN (lcommunity_list_expanded,
20739 bgp_lcommunity_list_expanded_cmd,
20740 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20741 BGP_STR
20742 LCOMMUNITY_LIST_STR
20743 "Large Community list number (expanded)\n"
20744 "Sequence number of an entry\n"
20745 "Sequence number\n"
20746 "Specify large community to reject\n"
20747 "Specify large community to accept\n"
20748 "An ordered list as a regular-expression\n")
20749 {
20750 return lcommunity_list_set_vty(vty, argc, argv,
20751 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20752 }
20753
20754 DEFUN (lcommunity_list_name_standard,
20755 bgp_lcommunity_list_name_standard_cmd,
20756 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20757 BGP_STR
20758 LCOMMUNITY_LIST_STR
20759 "Specify standard large-community-list\n"
20760 "Large Community list name\n"
20761 "Sequence number of an entry\n"
20762 "Sequence number\n"
20763 "Specify large community to reject\n"
20764 "Specify large community to accept\n"
20765 LCOMMUNITY_VAL_STR)
20766 {
20767 return lcommunity_list_set_vty(vty, argc, argv,
20768 LARGE_COMMUNITY_LIST_STANDARD, 1);
20769 }
20770
20771 DEFUN (lcommunity_list_name_expanded,
20772 bgp_lcommunity_list_name_expanded_cmd,
20773 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20774 BGP_STR
20775 LCOMMUNITY_LIST_STR
20776 "Specify expanded large-community-list\n"
20777 "Large Community list name\n"
20778 "Sequence number of an entry\n"
20779 "Sequence number\n"
20780 "Specify large community to reject\n"
20781 "Specify large community to accept\n"
20782 "An ordered list as a regular-expression\n")
20783 {
20784 return lcommunity_list_set_vty(vty, argc, argv,
20785 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20786 }
20787
20788 DEFUN (no_lcommunity_list_all,
20789 no_bgp_lcommunity_list_all_cmd,
20790 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20791 NO_STR
20792 BGP_STR
20793 LCOMMUNITY_LIST_STR
20794 "Large Community list number (standard)\n"
20795 "Large Community list number (expanded)\n"
20796 "Large Community list name\n")
20797 {
20798 return lcommunity_list_unset_vty(vty, argc, argv,
20799 LARGE_COMMUNITY_LIST_STANDARD);
20800 }
20801
20802 DEFUN (no_lcommunity_list_name_standard_all,
20803 no_bgp_lcommunity_list_name_standard_all_cmd,
20804 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20805 NO_STR
20806 BGP_STR
20807 LCOMMUNITY_LIST_STR
20808 "Specify standard large-community-list\n"
20809 "Large Community list name\n")
20810 {
20811 return lcommunity_list_unset_vty(vty, argc, argv,
20812 LARGE_COMMUNITY_LIST_STANDARD);
20813 }
20814
20815 DEFUN (no_lcommunity_list_name_expanded_all,
20816 no_bgp_lcommunity_list_name_expanded_all_cmd,
20817 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20818 NO_STR
20819 BGP_STR
20820 LCOMMUNITY_LIST_STR
20821 "Specify expanded large-community-list\n"
20822 "Large Community list name\n")
20823 {
20824 return lcommunity_list_unset_vty(vty, argc, argv,
20825 LARGE_COMMUNITY_LIST_EXPANDED);
20826 }
20827
20828 DEFUN (no_lcommunity_list_standard,
20829 no_bgp_lcommunity_list_standard_cmd,
20830 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20831 NO_STR
20832 BGP_STR
20833 LCOMMUNITY_LIST_STR
20834 "Large Community list number (standard)\n"
20835 "Sequence number of an entry\n"
20836 "Sequence number\n"
20837 "Specify large community to reject\n"
20838 "Specify large community to accept\n"
20839 LCOMMUNITY_VAL_STR)
20840 {
20841 return lcommunity_list_unset_vty(vty, argc, argv,
20842 LARGE_COMMUNITY_LIST_STANDARD);
20843 }
20844
20845 DEFUN (no_lcommunity_list_expanded,
20846 no_bgp_lcommunity_list_expanded_cmd,
20847 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20848 NO_STR
20849 BGP_STR
20850 LCOMMUNITY_LIST_STR
20851 "Large Community list number (expanded)\n"
20852 "Sequence number of an entry\n"
20853 "Sequence number\n"
20854 "Specify large community to reject\n"
20855 "Specify large community to accept\n"
20856 "An ordered list as a regular-expression\n")
20857 {
20858 return lcommunity_list_unset_vty(vty, argc, argv,
20859 LARGE_COMMUNITY_LIST_EXPANDED);
20860 }
20861
20862 DEFUN (no_lcommunity_list_name_standard,
20863 no_bgp_lcommunity_list_name_standard_cmd,
20864 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20865 NO_STR
20866 BGP_STR
20867 LCOMMUNITY_LIST_STR
20868 "Specify standard large-community-list\n"
20869 "Large Community list name\n"
20870 "Sequence number of an entry\n"
20871 "Sequence number\n"
20872 "Specify large community to reject\n"
20873 "Specify large community to accept\n"
20874 LCOMMUNITY_VAL_STR)
20875 {
20876 return lcommunity_list_unset_vty(vty, argc, argv,
20877 LARGE_COMMUNITY_LIST_STANDARD);
20878 }
20879
20880 DEFUN (no_lcommunity_list_name_expanded,
20881 no_bgp_lcommunity_list_name_expanded_cmd,
20882 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20883 NO_STR
20884 BGP_STR
20885 LCOMMUNITY_LIST_STR
20886 "Specify expanded large-community-list\n"
20887 "Large community list name\n"
20888 "Sequence number of an entry\n"
20889 "Sequence number\n"
20890 "Specify large community to reject\n"
20891 "Specify large community to accept\n"
20892 "An ordered list as a regular-expression\n")
20893 {
20894 return lcommunity_list_unset_vty(vty, argc, argv,
20895 LARGE_COMMUNITY_LIST_EXPANDED);
20896 }
20897
20898 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20899 {
20900 struct community_entry *entry;
20901
20902 for (entry = list->head; entry; entry = entry->next) {
20903 if (entry == list->head) {
20904 if (all_digit(list->name))
20905 vty_out(vty, "Large community %s list %s\n",
20906 entry->style ==
20907 LARGE_COMMUNITY_LIST_STANDARD
20908 ? "standard"
20909 : "(expanded) access",
20910 list->name);
20911 else
20912 vty_out(vty,
20913 "Named large community %s list %s\n",
20914 entry->style ==
20915 LARGE_COMMUNITY_LIST_STANDARD
20916 ? "standard"
20917 : "expanded",
20918 list->name);
20919 }
20920 if (entry->any)
20921 vty_out(vty, " %s\n",
20922 community_direct_str(entry->direct));
20923 else
20924 vty_out(vty, " %s %s\n",
20925 community_direct_str(entry->direct),
20926 community_list_config_str(entry));
20927 }
20928 }
20929
20930 DEFUN (show_lcommunity_list,
20931 show_bgp_lcommunity_list_cmd,
20932 "show bgp large-community-list",
20933 SHOW_STR
20934 BGP_STR
20935 "List large-community list\n")
20936 {
20937 struct community_list *list;
20938 struct community_list_master *cm;
20939
20940 cm = community_list_master_lookup(bgp_clist,
20941 LARGE_COMMUNITY_LIST_MASTER);
20942 if (!cm)
20943 return CMD_SUCCESS;
20944
20945 for (list = cm->num.head; list; list = list->next)
20946 lcommunity_list_show(vty, list);
20947
20948 for (list = cm->str.head; list; list = list->next)
20949 lcommunity_list_show(vty, list);
20950
20951 return CMD_SUCCESS;
20952 }
20953
20954 DEFUN (show_lcommunity_list_arg,
20955 show_bgp_lcommunity_list_arg_cmd,
20956 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20957 SHOW_STR
20958 BGP_STR
20959 "List large-community list\n"
20960 "Large-community-list number\n"
20961 "Large-community-list name\n"
20962 "Detailed information on large-community-list\n")
20963 {
20964 struct community_list *list;
20965
20966 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20967 LARGE_COMMUNITY_LIST_MASTER);
20968 if (!list) {
20969 vty_out(vty, "%% Can't find large-community-list\n");
20970 return CMD_WARNING;
20971 }
20972
20973 lcommunity_list_show(vty, list);
20974
20975 return CMD_SUCCESS;
20976 }
20977
20978 /* "extcommunity-list" keyword help string. */
20979 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20980 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20981
20982 DEFUN (extcommunity_list_standard,
20983 bgp_extcommunity_list_standard_cmd,
20984 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20985 BGP_STR
20986 EXTCOMMUNITY_LIST_STR
20987 "Extended Community list number (standard)\n"
20988 "Specify standard extcommunity-list\n"
20989 "Community list name\n"
20990 "Sequence number of an entry\n"
20991 "Sequence number\n"
20992 "Specify community to reject\n"
20993 "Specify community to accept\n"
20994 EXTCOMMUNITY_VAL_STR)
20995 {
20996 int style = EXTCOMMUNITY_LIST_STANDARD;
20997 int direct = 0;
20998 char *cl_number_or_name = NULL;
20999 char *seq = NULL;
21000
21001 int idx = 0;
21002
21003 argv_find(argv, argc, "(1-99)", &idx);
21004 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21005 cl_number_or_name = argv[idx]->arg;
21006
21007 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21008 seq = argv[idx]->arg;
21009
21010 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21011 : COMMUNITY_DENY;
21012 argv_find(argv, argc, "AA:NN", &idx);
21013 char *str = argv_concat(argv, argc, idx);
21014
21015 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21016 direct, style);
21017
21018 XFREE(MTYPE_TMP, str);
21019
21020 if (ret < 0) {
21021 community_list_perror(vty, ret);
21022 return CMD_WARNING_CONFIG_FAILED;
21023 }
21024
21025 return CMD_SUCCESS;
21026 }
21027
21028 DEFUN (extcommunity_list_name_expanded,
21029 bgp_extcommunity_list_name_expanded_cmd,
21030 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21031 BGP_STR
21032 EXTCOMMUNITY_LIST_STR
21033 "Extended Community list number (expanded)\n"
21034 "Specify expanded extcommunity-list\n"
21035 "Extended Community list name\n"
21036 "Sequence number of an entry\n"
21037 "Sequence number\n"
21038 "Specify community to reject\n"
21039 "Specify community to accept\n"
21040 "An ordered list as a regular-expression\n")
21041 {
21042 int style = EXTCOMMUNITY_LIST_EXPANDED;
21043 int direct = 0;
21044 char *cl_number_or_name = NULL;
21045 char *seq = NULL;
21046 int idx = 0;
21047
21048 argv_find(argv, argc, "(100-500)", &idx);
21049 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21050 cl_number_or_name = argv[idx]->arg;
21051
21052 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21053 seq = argv[idx]->arg;
21054
21055 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21056 : COMMUNITY_DENY;
21057 argv_find(argv, argc, "LINE", &idx);
21058 char *str = argv_concat(argv, argc, idx);
21059
21060 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21061 direct, style);
21062
21063 XFREE(MTYPE_TMP, str);
21064
21065 if (ret < 0) {
21066 community_list_perror(vty, ret);
21067 return CMD_WARNING_CONFIG_FAILED;
21068 }
21069
21070 return CMD_SUCCESS;
21071 }
21072
21073 DEFUN (no_extcommunity_list_standard_all,
21074 no_bgp_extcommunity_list_standard_all_cmd,
21075 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21076 NO_STR
21077 BGP_STR
21078 EXTCOMMUNITY_LIST_STR
21079 "Extended Community list number (standard)\n"
21080 "Specify standard extcommunity-list\n"
21081 "Community list name\n"
21082 "Sequence number of an entry\n"
21083 "Sequence number\n"
21084 "Specify community to reject\n"
21085 "Specify community to accept\n"
21086 EXTCOMMUNITY_VAL_STR)
21087 {
21088 int style = EXTCOMMUNITY_LIST_STANDARD;
21089 int direct = 0;
21090 char *cl_number_or_name = NULL;
21091 char *str = NULL;
21092 char *seq = NULL;
21093 int idx = 0;
21094
21095 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21096 seq = argv[idx]->arg;
21097
21098 idx = 0;
21099 argv_find(argv, argc, "permit", &idx);
21100 argv_find(argv, argc, "deny", &idx);
21101 if (idx) {
21102 direct = argv_find(argv, argc, "permit", &idx)
21103 ? COMMUNITY_PERMIT
21104 : COMMUNITY_DENY;
21105
21106 idx = 0;
21107 argv_find(argv, argc, "AA:NN", &idx);
21108 str = argv_concat(argv, argc, idx);
21109 }
21110
21111 idx = 0;
21112 argv_find(argv, argc, "(1-99)", &idx);
21113 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21114 cl_number_or_name = argv[idx]->arg;
21115
21116 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21117 seq, direct, style);
21118
21119 XFREE(MTYPE_TMP, str);
21120
21121 if (ret < 0) {
21122 community_list_perror(vty, ret);
21123 return CMD_WARNING_CONFIG_FAILED;
21124 }
21125
21126 return CMD_SUCCESS;
21127 }
21128
21129 ALIAS(no_extcommunity_list_standard_all,
21130 no_bgp_extcommunity_list_standard_all_list_cmd,
21131 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21132 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21133 "Extended Community list number (standard)\n"
21134 "Specify standard extcommunity-list\n"
21135 "Community list name\n")
21136
21137 DEFUN (no_extcommunity_list_expanded_all,
21138 no_bgp_extcommunity_list_expanded_all_cmd,
21139 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21140 NO_STR
21141 BGP_STR
21142 EXTCOMMUNITY_LIST_STR
21143 "Extended Community list number (expanded)\n"
21144 "Specify expanded extcommunity-list\n"
21145 "Extended Community list name\n"
21146 "Sequence number of an entry\n"
21147 "Sequence number\n"
21148 "Specify community to reject\n"
21149 "Specify community to accept\n"
21150 "An ordered list as a regular-expression\n")
21151 {
21152 int style = EXTCOMMUNITY_LIST_EXPANDED;
21153 int direct = 0;
21154 char *cl_number_or_name = NULL;
21155 char *str = NULL;
21156 char *seq = NULL;
21157 int idx = 0;
21158
21159 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21160 seq = argv[idx]->arg;
21161
21162 idx = 0;
21163 argv_find(argv, argc, "permit", &idx);
21164 argv_find(argv, argc, "deny", &idx);
21165
21166 if (idx) {
21167 direct = argv_find(argv, argc, "permit", &idx)
21168 ? COMMUNITY_PERMIT
21169 : COMMUNITY_DENY;
21170
21171 idx = 0;
21172 argv_find(argv, argc, "LINE", &idx);
21173 str = argv_concat(argv, argc, idx);
21174 }
21175
21176 idx = 0;
21177 argv_find(argv, argc, "(100-500)", &idx);
21178 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21179 cl_number_or_name = argv[idx]->arg;
21180
21181 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21182 seq, direct, style);
21183
21184 XFREE(MTYPE_TMP, str);
21185
21186 if (ret < 0) {
21187 community_list_perror(vty, ret);
21188 return CMD_WARNING_CONFIG_FAILED;
21189 }
21190
21191 return CMD_SUCCESS;
21192 }
21193
21194 ALIAS(no_extcommunity_list_expanded_all,
21195 no_bgp_extcommunity_list_expanded_all_list_cmd,
21196 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21197 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21198 "Extended Community list number (expanded)\n"
21199 "Specify expanded extcommunity-list\n"
21200 "Extended Community list name\n")
21201
21202 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21203 {
21204 struct community_entry *entry;
21205
21206 for (entry = list->head; entry; entry = entry->next) {
21207 if (entry == list->head) {
21208 if (all_digit(list->name))
21209 vty_out(vty, "Extended community %s list %s\n",
21210 entry->style == EXTCOMMUNITY_LIST_STANDARD
21211 ? "standard"
21212 : "(expanded) access",
21213 list->name);
21214 else
21215 vty_out(vty,
21216 "Named extended community %s list %s\n",
21217 entry->style == EXTCOMMUNITY_LIST_STANDARD
21218 ? "standard"
21219 : "expanded",
21220 list->name);
21221 }
21222 if (entry->any)
21223 vty_out(vty, " %s\n",
21224 community_direct_str(entry->direct));
21225 else
21226 vty_out(vty, " %s %s\n",
21227 community_direct_str(entry->direct),
21228 community_list_config_str(entry));
21229 }
21230 }
21231
21232 DEFUN (show_extcommunity_list,
21233 show_bgp_extcommunity_list_cmd,
21234 "show bgp extcommunity-list",
21235 SHOW_STR
21236 BGP_STR
21237 "List extended-community list\n")
21238 {
21239 struct community_list *list;
21240 struct community_list_master *cm;
21241
21242 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21243 if (!cm)
21244 return CMD_SUCCESS;
21245
21246 for (list = cm->num.head; list; list = list->next)
21247 extcommunity_list_show(vty, list);
21248
21249 for (list = cm->str.head; list; list = list->next)
21250 extcommunity_list_show(vty, list);
21251
21252 return CMD_SUCCESS;
21253 }
21254
21255 DEFUN (show_extcommunity_list_arg,
21256 show_bgp_extcommunity_list_arg_cmd,
21257 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21258 SHOW_STR
21259 BGP_STR
21260 "List extended-community list\n"
21261 "Extcommunity-list number\n"
21262 "Extcommunity-list name\n"
21263 "Detailed information on extcommunity-list\n")
21264 {
21265 int idx_comm_list = 3;
21266 struct community_list *list;
21267
21268 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21269 EXTCOMMUNITY_LIST_MASTER);
21270 if (!list) {
21271 vty_out(vty, "%% Can't find extcommunity-list\n");
21272 return CMD_WARNING;
21273 }
21274
21275 extcommunity_list_show(vty, list);
21276
21277 return CMD_SUCCESS;
21278 }
21279
21280 /* Display community-list and extcommunity-list configuration. */
21281 static int community_list_config_write(struct vty *vty)
21282 {
21283 struct community_list *list;
21284 struct community_entry *entry;
21285 struct community_list_master *cm;
21286 int write = 0;
21287
21288 /* Community-list. */
21289 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21290
21291 for (list = cm->num.head; list; list = list->next)
21292 for (entry = list->head; entry; entry = entry->next) {
21293 vty_out(vty,
21294 "bgp community-list %s seq %" PRId64 " %s %s\n",
21295 list->name, entry->seq,
21296 community_direct_str(entry->direct),
21297 community_list_config_str(entry));
21298 write++;
21299 }
21300 for (list = cm->str.head; list; list = list->next)
21301 for (entry = list->head; entry; entry = entry->next) {
21302 vty_out(vty,
21303 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21304 entry->style == COMMUNITY_LIST_STANDARD
21305 ? "standard"
21306 : "expanded",
21307 list->name, entry->seq,
21308 community_direct_str(entry->direct),
21309 community_list_config_str(entry));
21310 write++;
21311 }
21312
21313 /* Extcommunity-list. */
21314 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21315
21316 for (list = cm->num.head; list; list = list->next)
21317 for (entry = list->head; entry; entry = entry->next) {
21318 vty_out(vty,
21319 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21320 list->name, entry->seq,
21321 community_direct_str(entry->direct),
21322 community_list_config_str(entry));
21323 write++;
21324 }
21325 for (list = cm->str.head; list; list = list->next)
21326 for (entry = list->head; entry; entry = entry->next) {
21327 vty_out(vty,
21328 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21329 entry->style == EXTCOMMUNITY_LIST_STANDARD
21330 ? "standard"
21331 : "expanded",
21332 list->name, entry->seq,
21333 community_direct_str(entry->direct),
21334 community_list_config_str(entry));
21335 write++;
21336 }
21337
21338
21339 /* lcommunity-list. */
21340 cm = community_list_master_lookup(bgp_clist,
21341 LARGE_COMMUNITY_LIST_MASTER);
21342
21343 for (list = cm->num.head; list; list = list->next)
21344 for (entry = list->head; entry; entry = entry->next) {
21345 vty_out(vty,
21346 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21347 list->name, entry->seq,
21348 community_direct_str(entry->direct),
21349 community_list_config_str(entry));
21350 write++;
21351 }
21352 for (list = cm->str.head; list; list = list->next)
21353 for (entry = list->head; entry; entry = entry->next) {
21354 vty_out(vty,
21355 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21356
21357 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21358 ? "standard"
21359 : "expanded",
21360 list->name, entry->seq, community_direct_str(entry->direct),
21361 community_list_config_str(entry));
21362 write++;
21363 }
21364
21365 return write;
21366 }
21367
21368 static int community_list_config_write(struct vty *vty);
21369 static struct cmd_node community_list_node = {
21370 .name = "community list",
21371 .node = COMMUNITY_LIST_NODE,
21372 .prompt = "",
21373 .config_write = community_list_config_write,
21374 };
21375
21376 static void community_list_vty(void)
21377 {
21378 install_node(&community_list_node);
21379
21380 /* Community-list. */
21381 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21382 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21383 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21384 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21385 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21386 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21387 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21388 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21389
21390 /* Extcommunity-list. */
21391 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21392 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21393 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21394 install_element(CONFIG_NODE,
21395 &no_bgp_extcommunity_list_standard_all_list_cmd);
21396 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21397 install_element(CONFIG_NODE,
21398 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21399 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21400 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21401
21402 /* Large Community List */
21403 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21404 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21405 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21406 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21407 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21408 install_element(CONFIG_NODE,
21409 &no_bgp_lcommunity_list_name_standard_all_cmd);
21410 install_element(CONFIG_NODE,
21411 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21412 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21413 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21414 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21415 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21416 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21417 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21418
21419 bgp_community_list_command_completion_setup();
21420 }
21421
21422 static struct cmd_node community_alias_node = {
21423 .name = "community alias",
21424 .node = COMMUNITY_ALIAS_NODE,
21425 .prompt = "",
21426 .config_write = bgp_community_alias_write,
21427 };
21428
21429 void community_alias_vty(void)
21430 {
21431 install_node(&community_alias_node);
21432
21433 /* Community-list. */
21434 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21435
21436 bgp_community_alias_command_completion_setup();
21437 }