]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12491 from opensourcerouting/fix/crash_bgp_graceful-restart_json
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/sockopt.h"
26 #include "lib_errors.h"
27 #include "lib/zclient.h"
28 #include "lib/printfrr.h"
29 #include "prefix.h"
30 #include "plist.h"
31 #include "buffer.h"
32 #include "linklist.h"
33 #include "stream.h"
34 #include "thread.h"
35 #include "log.h"
36 #include "memory.h"
37 #include "lib_vty.h"
38 #include "hash.h"
39 #include "queue.h"
40 #include "filter.h"
41 #include "frrstr.h"
42
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_attr_evpn.h"
45 #include "bgpd/bgp_advertise.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_community_alias.h"
50 #include "bgpd/bgp_ecommunity.h"
51 #include "bgpd/bgp_lcommunity.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_debug.h"
54 #include "bgpd/bgp_errors.h"
55 #include "bgpd/bgp_fsm.h"
56 #include "bgpd/bgp_nht.h"
57 #include "bgpd/bgp_nexthop.h"
58 #include "bgpd/bgp_network.h"
59 #include "bgpd/bgp_open.h"
60 #include "bgpd/bgp_regex.h"
61 #include "bgpd/bgp_route.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_zebra.h"
64 #include "bgpd/bgp_table.h"
65 #include "bgpd/bgp_vty.h"
66 #include "bgpd/bgp_mpath.h"
67 #include "bgpd/bgp_packet.h"
68 #include "bgpd/bgp_updgrp.h"
69 #include "bgpd/bgp_bfd.h"
70 #include "bgpd/bgp_io.h"
71 #include "bgpd/bgp_evpn.h"
72 #include "bgpd/bgp_evpn_vty.h"
73 #include "bgpd/bgp_evpn_mh.h"
74 #include "bgpd/bgp_addpath.h"
75 #include "bgpd/bgp_mac.h"
76 #include "bgpd/bgp_flowspec.h"
77 #include "bgpd/bgp_conditional_adv.h"
78 #ifdef ENABLE_BGP_VNC
79 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
80 #endif
81 #include "bgpd/bgp_orr.h"
82
83
84 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
91 );
92 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
95 );
96 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
99 );
100 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
103 );
104 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
107 );
108 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
111 );
112 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
115 );
116 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
119 );
120 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
124 );
125 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
128 );
129 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
130 { .val_bool = false, .match_version = "< 8.3", },
131 { .val_bool = true },
132 );
133 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
134 { .val_bool = false, .match_version = "< 8.3", },
135 { .val_bool = true },
136 );
137
138 DEFINE_HOOK(bgp_inst_config_write,
139 (struct bgp *bgp, struct vty *vty),
140 (bgp, vty));
141 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
142 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
143
144 static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
146
147 /* Show BGP peer's information. */
148 enum show_type {
149 show_all,
150 show_peer,
151 show_ipv4_all,
152 show_ipv6_all,
153 show_ipv4_peer,
154 show_ipv6_peer
155 };
156
157 static struct peer_group *listen_range_exists(struct bgp *bgp,
158 struct prefix *range, int exact);
159
160 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
161 struct bgp *bgp);
162
163 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
164 enum show_type type,
165 const char *ip_str,
166 afi_t afi, bool use_json);
167
168 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
169 {
170 switch (afi) {
171 case AFI_IP:
172 switch (safi) {
173 case SAFI_UNICAST:
174 return BGP_IPV4_NODE;
175 case SAFI_MULTICAST:
176 return BGP_IPV4M_NODE;
177 case SAFI_LABELED_UNICAST:
178 return BGP_IPV4L_NODE;
179 case SAFI_MPLS_VPN:
180 return BGP_VPNV4_NODE;
181 case SAFI_FLOWSPEC:
182 return BGP_FLOWSPECV4_NODE;
183 default:
184 /* not expected */
185 return BGP_IPV4_NODE;
186 }
187 case AFI_IP6:
188 switch (safi) {
189 case SAFI_UNICAST:
190 return BGP_IPV6_NODE;
191 case SAFI_MULTICAST:
192 return BGP_IPV6M_NODE;
193 case SAFI_LABELED_UNICAST:
194 return BGP_IPV6L_NODE;
195 case SAFI_MPLS_VPN:
196 return BGP_VPNV6_NODE;
197 case SAFI_FLOWSPEC:
198 return BGP_FLOWSPECV6_NODE;
199 default:
200 /* not expected */
201 return BGP_IPV4_NODE;
202 }
203 case AFI_L2VPN:
204 return BGP_EVPN_NODE;
205 case AFI_UNSPEC:
206 case AFI_MAX:
207 // We should never be here but to clarify the switch statement..
208 return BGP_IPV4_NODE;
209 }
210
211 // Impossible to happen
212 return BGP_IPV4_NODE;
213 }
214
215 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
216 {
217 if (afi == AFI_IP) {
218 if (safi == SAFI_UNICAST)
219 return "IPv4 Unicast";
220 if (safi == SAFI_MULTICAST)
221 return "IPv4 Multicast";
222 if (safi == SAFI_LABELED_UNICAST)
223 return "IPv4 Labeled Unicast";
224 if (safi == SAFI_MPLS_VPN)
225 return "IPv4 VPN";
226 if (safi == SAFI_ENCAP)
227 return "IPv4 Encap";
228 if (safi == SAFI_FLOWSPEC)
229 return "IPv4 Flowspec";
230 } else if (afi == AFI_IP6) {
231 if (safi == SAFI_UNICAST)
232 return "IPv6 Unicast";
233 if (safi == SAFI_MULTICAST)
234 return "IPv6 Multicast";
235 if (safi == SAFI_LABELED_UNICAST)
236 return "IPv6 Labeled Unicast";
237 if (safi == SAFI_MPLS_VPN)
238 return "IPv6 VPN";
239 if (safi == SAFI_ENCAP)
240 return "IPv6 Encap";
241 if (safi == SAFI_FLOWSPEC)
242 return "IPv6 Flowspec";
243 } else if (afi == AFI_L2VPN) {
244 if (safi == SAFI_EVPN)
245 return "L2VPN EVPN";
246 }
247
248 return "Unknown";
249 }
250
251 /*
252 * Please note that we have intentionally camelCased
253 * the return strings here. So if you want
254 * to use this function, please ensure you
255 * are doing this within json output
256 */
257 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
258 {
259 if (afi == AFI_IP) {
260 if (safi == SAFI_UNICAST)
261 return "ipv4Unicast";
262 if (safi == SAFI_MULTICAST)
263 return "ipv4Multicast";
264 if (safi == SAFI_LABELED_UNICAST)
265 return "ipv4LabeledUnicast";
266 if (safi == SAFI_MPLS_VPN)
267 return "ipv4Vpn";
268 if (safi == SAFI_ENCAP)
269 return "ipv4Encap";
270 if (safi == SAFI_FLOWSPEC)
271 return "ipv4Flowspec";
272 } else if (afi == AFI_IP6) {
273 if (safi == SAFI_UNICAST)
274 return "ipv6Unicast";
275 if (safi == SAFI_MULTICAST)
276 return "ipv6Multicast";
277 if (safi == SAFI_LABELED_UNICAST)
278 return "ipv6LabeledUnicast";
279 if (safi == SAFI_MPLS_VPN)
280 return "ipv6Vpn";
281 if (safi == SAFI_ENCAP)
282 return "ipv6Encap";
283 if (safi == SAFI_FLOWSPEC)
284 return "ipv6Flowspec";
285 } else if (afi == AFI_L2VPN) {
286 if (safi == SAFI_EVPN)
287 return "l2VpnEvpn";
288 }
289
290 return "Unknown";
291 }
292
293 /* unset srv6 locator */
294 static int bgp_srv6_locator_unset(struct bgp *bgp)
295 {
296 int ret;
297 struct listnode *node, *nnode;
298 struct srv6_locator_chunk *chunk;
299 struct bgp_srv6_function *func;
300 struct bgp *bgp_vrf;
301
302 /* release chunk notification via ZAPI */
303 ret = bgp_zebra_srv6_manager_release_locator_chunk(
304 bgp->srv6_locator_name);
305 if (ret < 0)
306 return -1;
307
308 /* refresh chunks */
309 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
310 listnode_delete(bgp->srv6_locator_chunks, chunk);
311 srv6_locator_chunk_free(&chunk);
312 }
313
314 /* refresh functions */
315 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
316 listnode_delete(bgp->srv6_functions, func);
317 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
318 }
319
320 /* refresh tovpn_sid */
321 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
322 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
323 continue;
324
325 /* refresh vpnv4 tovpn_sid */
326 XFREE(MTYPE_BGP_SRV6_SID,
327 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
328
329 /* refresh vpnv6 tovpn_sid */
330 XFREE(MTYPE_BGP_SRV6_SID,
331 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
332
333 /* refresh per-vrf tovpn_sid */
334 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
335 }
336
337 /* update vpn bgp processes */
338 vpn_leak_postchange_all();
339
340 /* refresh tovpn_sid_locator */
341 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
342 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
343 continue;
344
345 /* refresh vpnv4 tovpn_sid_locator */
346 srv6_locator_chunk_free(
347 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
348
349 /* refresh vpnv6 tovpn_sid_locator */
350 srv6_locator_chunk_free(
351 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
352
353 /* refresh per-vrf tovpn_sid_locator */
354 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
355 }
356
357 /* clear locator name */
358 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
359
360 return 0;
361 }
362
363 /* Utility function to get address family from current node. */
364 afi_t bgp_node_afi(struct vty *vty)
365 {
366 afi_t afi;
367 switch (vty->node) {
368 case BGP_IPV6_NODE:
369 case BGP_IPV6M_NODE:
370 case BGP_IPV6L_NODE:
371 case BGP_VPNV6_NODE:
372 case BGP_FLOWSPECV6_NODE:
373 afi = AFI_IP6;
374 break;
375 case BGP_EVPN_NODE:
376 afi = AFI_L2VPN;
377 break;
378 default:
379 afi = AFI_IP;
380 break;
381 }
382 return afi;
383 }
384
385 /* Utility function to get subsequent address family from current
386 node. */
387 safi_t bgp_node_safi(struct vty *vty)
388 {
389 safi_t safi;
390 switch (vty->node) {
391 case BGP_VPNV4_NODE:
392 case BGP_VPNV6_NODE:
393 safi = SAFI_MPLS_VPN;
394 break;
395 case BGP_IPV4M_NODE:
396 case BGP_IPV6M_NODE:
397 safi = SAFI_MULTICAST;
398 break;
399 case BGP_EVPN_NODE:
400 safi = SAFI_EVPN;
401 break;
402 case BGP_IPV4L_NODE:
403 case BGP_IPV6L_NODE:
404 safi = SAFI_LABELED_UNICAST;
405 break;
406 case BGP_FLOWSPECV4_NODE:
407 case BGP_FLOWSPECV6_NODE:
408 safi = SAFI_FLOWSPEC;
409 break;
410 default:
411 safi = SAFI_UNICAST;
412 break;
413 }
414 return safi;
415 }
416
417 /**
418 * Converts an AFI in string form to afi_t
419 *
420 * @param afi string, one of
421 * - "ipv4"
422 * - "ipv6"
423 * - "l2vpn"
424 * @return the corresponding afi_t
425 */
426 afi_t bgp_vty_afi_from_str(const char *afi_str)
427 {
428 afi_t afi = AFI_MAX; /* unknown */
429 if (strmatch(afi_str, "ipv4"))
430 afi = AFI_IP;
431 else if (strmatch(afi_str, "ipv6"))
432 afi = AFI_IP6;
433 else if (strmatch(afi_str, "l2vpn"))
434 afi = AFI_L2VPN;
435 return afi;
436 }
437
438 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
439 afi_t *afi)
440 {
441 int ret = 0;
442 if (argv_find(argv, argc, "ipv4", index)) {
443 ret = 1;
444 if (afi)
445 *afi = AFI_IP;
446 } else if (argv_find(argv, argc, "ipv6", index)) {
447 ret = 1;
448 if (afi)
449 *afi = AFI_IP6;
450 } else if (argv_find(argv, argc, "l2vpn", index)) {
451 ret = 1;
452 if (afi)
453 *afi = AFI_L2VPN;
454 }
455 return ret;
456 }
457
458 /* supports <unicast|multicast|vpn|labeled-unicast> */
459 safi_t bgp_vty_safi_from_str(const char *safi_str)
460 {
461 safi_t safi = SAFI_MAX; /* unknown */
462 if (strmatch(safi_str, "multicast"))
463 safi = SAFI_MULTICAST;
464 else if (strmatch(safi_str, "unicast"))
465 safi = SAFI_UNICAST;
466 else if (strmatch(safi_str, "vpn"))
467 safi = SAFI_MPLS_VPN;
468 else if (strmatch(safi_str, "evpn"))
469 safi = SAFI_EVPN;
470 else if (strmatch(safi_str, "labeled-unicast"))
471 safi = SAFI_LABELED_UNICAST;
472 else if (strmatch(safi_str, "flowspec"))
473 safi = SAFI_FLOWSPEC;
474 return safi;
475 }
476
477 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
478 safi_t *safi)
479 {
480 int ret = 0;
481 if (argv_find(argv, argc, "unicast", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_UNICAST;
485 } else if (argv_find(argv, argc, "multicast", index)) {
486 ret = 1;
487 if (safi)
488 *safi = SAFI_MULTICAST;
489 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
490 ret = 1;
491 if (safi)
492 *safi = SAFI_LABELED_UNICAST;
493 } else if (argv_find(argv, argc, "vpn", index)) {
494 ret = 1;
495 if (safi)
496 *safi = SAFI_MPLS_VPN;
497 } else if (argv_find(argv, argc, "evpn", index)) {
498 ret = 1;
499 if (safi)
500 *safi = SAFI_EVPN;
501 } else if (argv_find(argv, argc, "flowspec", index)) {
502 ret = 1;
503 if (safi)
504 *safi = SAFI_FLOWSPEC;
505 }
506 return ret;
507 }
508
509 /*
510 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
511 *
512 * afi
513 * address-family identifier
514 *
515 * safi
516 * subsequent address-family identifier
517 *
518 * Returns:
519 * default_af string corresponding to the supplied afi/safi pair.
520 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
521 * return -1.
522 */
523 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
524 {
525 switch (afi) {
526 case AFI_IP:
527 switch (safi) {
528 case SAFI_UNICAST:
529 return "ipv4-unicast";
530 case SAFI_MULTICAST:
531 return "ipv4-multicast";
532 case SAFI_MPLS_VPN:
533 return "ipv4-vpn";
534 case SAFI_ENCAP:
535 return "ipv4-encap";
536 case SAFI_LABELED_UNICAST:
537 return "ipv4-labeled-unicast";
538 case SAFI_FLOWSPEC:
539 return "ipv4-flowspec";
540 default:
541 return "unknown-afi/safi";
542 }
543 break;
544 case AFI_IP6:
545 switch (safi) {
546 case SAFI_UNICAST:
547 return "ipv6-unicast";
548 case SAFI_MULTICAST:
549 return "ipv6-multicast";
550 case SAFI_MPLS_VPN:
551 return "ipv6-vpn";
552 case SAFI_ENCAP:
553 return "ipv6-encap";
554 case SAFI_LABELED_UNICAST:
555 return "ipv6-labeled-unicast";
556 case SAFI_FLOWSPEC:
557 return "ipv6-flowspec";
558 default:
559 return "unknown-afi/safi";
560 }
561 break;
562 case AFI_L2VPN:
563 switch (safi) {
564 case SAFI_EVPN:
565 return "l2vpn-evpn";
566 default:
567 return "unknown-afi/safi";
568 }
569 case AFI_UNSPEC:
570 case AFI_MAX:
571 return "unknown-afi/safi";
572 }
573 /* all AFIs are accounted for above, so this shouldn't happen */
574 return "unknown-afi/safi";
575 }
576
577 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
578 enum bgp_instance_type inst_type)
579 {
580 int ret = bgp_get(bgp, as, name, inst_type);
581
582 if (ret == BGP_CREATED) {
583 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
584 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
585
586 if (DFLT_BGP_IMPORT_CHECK)
587 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
588 if (DFLT_BGP_SHOW_HOSTNAME)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
590 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
592 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
594 if (DFLT_BGP_DETERMINISTIC_MED)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
596 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
598 if (DFLT_BGP_SUPPRESS_DUPLICATES)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
600 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
602 if (DFLT_BGP_HARD_ADMIN_RESET)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
604
605 ret = BGP_SUCCESS;
606 }
607 return ret;
608 }
609
610 /*
611 * bgp_vty_find_and_parse_afi_safi_bgp
612 *
613 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
614 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
615 * to appropriate values for the calling function. This is to allow the
616 * calling function to make decisions appropriate for the show command
617 * that is being parsed.
618 *
619 * The show commands are generally of the form:
620 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
621 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
622 *
623 * Since we use argv_find if the show command in particular doesn't have:
624 * [ip]
625 * [<view|vrf> VIEWVRFNAME]
626 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
627 * The command parsing should still be ok.
628 *
629 * vty -> The vty for the command so we can output some useful data in
630 * the event of a parse error in the vrf.
631 * argv -> The command tokens
632 * argc -> How many command tokens we have
633 * idx -> The current place in the command, generally should be 0 for this
634 * function
635 * afi -> The parsed afi if it was included in the show command, returned here
636 * safi -> The parsed safi if it was included in the show command, returned here
637 * bgp -> Pointer to the bgp data structure we need to fill in.
638 * use_json -> json is configured or not
639 *
640 * The function returns the correct location in the parse tree for the
641 * last token found.
642 *
643 * Returns 0 for failure to parse correctly, else the idx position of where
644 * it found the last token.
645 */
646 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
647 struct cmd_token **argv, int argc,
648 int *idx, afi_t *afi, safi_t *safi,
649 struct bgp **bgp, bool use_json)
650 {
651 char *vrf_name = NULL;
652
653 assert(afi);
654 assert(safi);
655 assert(bgp);
656
657 if (argv_find(argv, argc, "ip", idx))
658 *afi = AFI_IP;
659
660 if (argv_find(argv, argc, "view", idx))
661 vrf_name = argv[*idx + 1]->arg;
662 else if (argv_find(argv, argc, "vrf", idx)) {
663 vrf_name = argv[*idx + 1]->arg;
664 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
665 vrf_name = NULL;
666 }
667 if (vrf_name) {
668 if (strmatch(vrf_name, "all"))
669 *bgp = NULL;
670 else {
671 *bgp = bgp_lookup_by_name(vrf_name);
672 if (!*bgp) {
673 if (use_json) {
674 json_object *json = NULL;
675 json = json_object_new_object();
676 json_object_string_add(
677 json, "warning",
678 "View/Vrf is unknown");
679 vty_json(vty, json);
680 }
681 else
682 vty_out(vty, "View/Vrf %s is unknown\n",
683 vrf_name);
684 *idx = 0;
685 return 0;
686 }
687 }
688 } else {
689 *bgp = bgp_get_default();
690 if (!*bgp) {
691 if (use_json) {
692 json_object *json = NULL;
693 json = json_object_new_object();
694 json_object_string_add(
695 json, "warning",
696 "Default BGP instance not found");
697 vty_json(vty, json);
698 }
699 else
700 vty_out(vty,
701 "Default BGP instance not found\n");
702 *idx = 0;
703 return 0;
704 }
705 }
706
707 if (argv_find_and_parse_afi(argv, argc, idx, afi))
708 argv_find_and_parse_safi(argv, argc, idx, safi);
709
710 *idx += 1;
711 return *idx;
712 }
713
714 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
715 {
716 struct interface *ifp = NULL;
717 struct listnode *node;
718 struct bgp_listener *listener;
719 union sockunion all_su;
720
721 if (su->sa.sa_family == AF_INET) {
722 (void)str2sockunion("0.0.0.0", &all_su);
723 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
724 } else if (su->sa.sa_family == AF_INET6) {
725 (void)str2sockunion("::", &all_su);
726 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
727 su->sin6.sin6_scope_id,
728 bgp->vrf_id);
729 }
730
731 if (ifp) {
732 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
733 if (sockunion_family(su) !=
734 sockunion_family(&listener->su))
735 continue;
736
737 /* If 0.0.0.0/:: is a listener, then treat as self and
738 * reject.
739 */
740 if (!sockunion_cmp(&listener->su, su) ||
741 !sockunion_cmp(&listener->su, &all_su))
742 return true;
743 }
744 }
745
746 return false;
747 }
748
749 /* Utility function for looking up peer from VTY. */
750 /* This is used only for configuration, so disallow if attempted on
751 * a dynamic neighbor.
752 */
753 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
754 {
755 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
756 int ret;
757 union sockunion su;
758 struct peer *peer;
759
760 if (!bgp) {
761 return NULL;
762 }
763
764 ret = str2sockunion(ip_str, &su);
765 if (ret < 0) {
766 peer = peer_lookup_by_conf_if(bgp, ip_str);
767 if (!peer) {
768 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
769 == NULL) {
770 vty_out(vty,
771 "%% Malformed address or name: %s\n",
772 ip_str);
773 return NULL;
774 }
775 }
776 } else {
777 peer = peer_lookup(bgp, &su);
778 if (!peer) {
779 vty_out(vty,
780 "%% Specify remote-as or peer-group commands first\n");
781 return NULL;
782 }
783 if (peer_dynamic_neighbor(peer)) {
784 vty_out(vty,
785 "%% Operation not allowed on a dynamic neighbor\n");
786 return NULL;
787 }
788 }
789 return peer;
790 }
791
792 /* Utility function for looking up peer or peer group. */
793 /* This is used only for configuration, so disallow if attempted on
794 * a dynamic neighbor.
795 */
796 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
797 {
798 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
799 int ret;
800 union sockunion su;
801 struct peer *peer = NULL;
802 struct peer_group *group = NULL;
803
804 if (!bgp) {
805 return NULL;
806 }
807
808 ret = str2sockunion(peer_str, &su);
809 if (ret == 0) {
810 /* IP address, locate peer. */
811 peer = peer_lookup(bgp, &su);
812 } else {
813 /* Not IP, could match either peer configured on interface or a
814 * group. */
815 peer = peer_lookup_by_conf_if(bgp, peer_str);
816 if (!peer)
817 group = peer_group_lookup(bgp, peer_str);
818 }
819
820 if (peer) {
821 if (peer_dynamic_neighbor(peer)) {
822 vty_out(vty,
823 "%% Operation not allowed on a dynamic neighbor\n");
824 return NULL;
825 }
826
827 return peer;
828 }
829
830 if (group)
831 return group->conf;
832
833 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
834
835 return NULL;
836 }
837
838 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
839 {
840 const char *str = NULL;
841
842 switch (ret) {
843 case BGP_SUCCESS:
844 case BGP_CREATED:
845 case BGP_GR_NO_OPERATION:
846 break;
847 case BGP_ERR_INVALID_VALUE:
848 str = "Invalid value";
849 break;
850 case BGP_ERR_INVALID_FLAG:
851 str = "Invalid flag";
852 break;
853 case BGP_ERR_PEER_GROUP_SHUTDOWN:
854 str = "Peer-group has been shutdown. Activate the peer-group first";
855 break;
856 case BGP_ERR_PEER_FLAG_CONFLICT:
857 str = "Can't set override-capability and strict-capability-match at the same time";
858 break;
859 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
860 str = "Specify remote-as or peer-group remote AS first";
861 break;
862 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
863 str = "Cannot change the peer-group. Deconfigure first";
864 break;
865 case BGP_ERR_PEER_GROUP_MISMATCH:
866 str = "Peer is not a member of this peer-group";
867 break;
868 case BGP_ERR_PEER_FILTER_CONFLICT:
869 str = "Prefix/distribute list can not co-exist";
870 break;
871 case BGP_ERR_NOT_INTERNAL_PEER:
872 str = "Invalid command. Not an internal neighbor";
873 break;
874 case BGP_ERR_REMOVE_PRIVATE_AS:
875 str = "remove-private-AS cannot be configured for IBGP peers";
876 break;
877 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
878 str = "Cannot have local-as same as BGP AS number";
879 break;
880 case BGP_ERR_TCPSIG_FAILED:
881 str = "Error while applying TCP-Sig to session(s)";
882 break;
883 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
884 str = "ebgp-multihop and ttl-security cannot be configured together";
885 break;
886 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
887 str = "ttl-security only allowed for EBGP peers";
888 break;
889 case BGP_ERR_AS_OVERRIDE:
890 str = "as-override cannot be configured for IBGP peers";
891 break;
892 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
893 str = "Invalid limit for number of dynamic neighbors";
894 break;
895 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
896 str = "Dynamic neighbor listen range already exists";
897 break;
898 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
899 str = "Operation not allowed on a dynamic neighbor";
900 break;
901 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
902 str = "Operation not allowed on a directly connected neighbor";
903 break;
904 case BGP_ERR_PEER_SAFI_CONFLICT:
905 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
906 break;
907 case BGP_ERR_GR_INVALID_CMD:
908 str = "The Graceful Restart command used is not valid at this moment.";
909 break;
910 case BGP_ERR_GR_OPERATION_FAILED:
911 str = "The Graceful Restart Operation failed due to an err.";
912 break;
913 case BGP_ERR_PEER_GROUP_MEMBER:
914 str = "Peer-group member cannot override remote-as of peer-group.";
915 break;
916 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
917 str = "Peer-group members must be all internal or all external.";
918 break;
919 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
920 str = "Range specified cannot be deleted because it is not part of current config.";
921 break;
922 case BGP_ERR_INSTANCE_MISMATCH:
923 str = "Instance specified does not match the current instance.";
924 break;
925 case BGP_ERR_NO_INTERFACE_CONFIG:
926 str = "Interface specified is not being used for interface based peer.";
927 break;
928 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
929 str = "No configuration already specified for soft reconfiguration.";
930 break;
931 case BGP_ERR_AS_MISMATCH:
932 str = "BGP is already running.";
933 break;
934 case BGP_ERR_AF_UNCONFIGURED:
935 str = "AFI/SAFI specified is not currently configured.";
936 break;
937 case BGP_ERR_INVALID_AS:
938 str = "Confederation AS specified is the same AS as our AS.";
939 break;
940 case BGP_ERR_INVALID_ROLE_NAME:
941 str = "Invalid role name";
942 break;
943 case BGP_ERR_INVALID_INTERNAL_ROLE:
944 str = "External roles can be set only on eBGP session";
945 break;
946 case BGP_ERR_PEER_ORR_CONFIGURED:
947 str = "Deconfigure optimal-route-reflection on this peer first";
948 break;
949 }
950 if (str) {
951 vty_out(vty, "%% %s\n", str);
952 return CMD_WARNING_CONFIG_FAILED;
953 }
954 return CMD_SUCCESS;
955 }
956
957 /* BGP clear sort. */
958 enum clear_sort {
959 clear_all,
960 clear_peer,
961 clear_group,
962 clear_external,
963 clear_as
964 };
965
966 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
967 safi_t safi, int error)
968 {
969 switch (error) {
970 case BGP_ERR_AF_UNCONFIGURED:
971 if (vty)
972 vty_out(vty,
973 "%% BGP: Enable %s address family for the neighbor %s\n",
974 get_afi_safi_str(afi, safi, false), peer->host);
975 else
976 zlog_warn(
977 "%% BGP: Enable %s address family for the neighbor %s",
978 get_afi_safi_str(afi, safi, false), peer->host);
979 break;
980 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
981 if (vty)
982 vty_out(vty,
983 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
984 peer->host);
985 else
986 zlog_warn(
987 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
988 peer->host);
989 break;
990 default:
991 break;
992 }
993 }
994
995 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
996 struct listnode **nnode, enum bgp_clear_type stype)
997 {
998 int ret = 0;
999 struct peer_af *paf;
1000
1001 /* if afi/.safi not specified, spin thru all of them */
1002 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1003 afi_t tmp_afi;
1004 safi_t tmp_safi;
1005 enum bgp_af_index index;
1006
1007 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1008 paf = peer->peer_af_array[index];
1009 if (!paf)
1010 continue;
1011
1012 if (paf && paf->subgroup)
1013 SET_FLAG(paf->subgroup->sflags,
1014 SUBGRP_STATUS_FORCE_UPDATES);
1015
1016 tmp_afi = paf->afi;
1017 tmp_safi = paf->safi;
1018 if (!peer->afc[tmp_afi][tmp_safi])
1019 continue;
1020
1021 if (stype == BGP_CLEAR_SOFT_NONE)
1022 ret = peer_clear(peer, nnode);
1023 else
1024 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1025 stype);
1026 }
1027 /* if afi specified and safi not, spin thru safis on this afi */
1028 } else if (safi == SAFI_UNSPEC) {
1029 safi_t tmp_safi;
1030
1031 for (tmp_safi = SAFI_UNICAST;
1032 tmp_safi < SAFI_MAX; tmp_safi++) {
1033 if (!peer->afc[afi][tmp_safi])
1034 continue;
1035
1036 paf = peer_af_find(peer, afi, tmp_safi);
1037 if (paf && paf->subgroup)
1038 SET_FLAG(paf->subgroup->sflags,
1039 SUBGRP_STATUS_FORCE_UPDATES);
1040
1041 if (stype == BGP_CLEAR_SOFT_NONE)
1042 ret = peer_clear(peer, nnode);
1043 else
1044 ret = peer_clear_soft(peer, afi,
1045 tmp_safi, stype);
1046 }
1047 /* both afi/safi specified, let the caller know if not defined */
1048 } else {
1049 if (!peer->afc[afi][safi])
1050 return 1;
1051
1052 paf = peer_af_find(peer, afi, safi);
1053 if (paf && paf->subgroup)
1054 SET_FLAG(paf->subgroup->sflags,
1055 SUBGRP_STATUS_FORCE_UPDATES);
1056
1057 if (stype == BGP_CLEAR_SOFT_NONE)
1058 ret = peer_clear(peer, nnode);
1059 else
1060 ret = peer_clear_soft(peer, afi, safi, stype);
1061 }
1062
1063 return ret;
1064 }
1065
1066 /* `clear ip bgp' functions. */
1067 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1068 enum clear_sort sort, enum bgp_clear_type stype,
1069 const char *arg)
1070 {
1071 int ret = 0;
1072 bool found = false;
1073 struct peer *peer;
1074
1075 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1076
1077 /* Clear all neighbors. */
1078 /*
1079 * Pass along pointer to next node to peer_clear() when walking all
1080 * nodes on the BGP instance as that may get freed if it is a
1081 * doppelganger
1082 */
1083 if (sort == clear_all) {
1084 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1085
1086 bgp_peer_gr_flags_update(peer);
1087
1088 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1089 gr_router_detected = true;
1090
1091 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1092 stype);
1093
1094 if (ret < 0)
1095 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1096 }
1097
1098 if (gr_router_detected
1099 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1100 bgp_zebra_send_capabilities(bgp, false);
1101 } else if (!gr_router_detected
1102 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1103 bgp_zebra_send_capabilities(bgp, true);
1104 }
1105
1106 /* This is to apply read-only mode on this clear. */
1107 if (stype == BGP_CLEAR_SOFT_NONE)
1108 bgp->update_delay_over = 0;
1109
1110 return CMD_SUCCESS;
1111 }
1112
1113 /* Clear specified neighbor. */
1114 if (sort == clear_peer) {
1115 union sockunion su;
1116
1117 /* Make sockunion for lookup. */
1118 ret = str2sockunion(arg, &su);
1119 if (ret < 0) {
1120 peer = peer_lookup_by_conf_if(bgp, arg);
1121 if (!peer) {
1122 peer = peer_lookup_by_hostname(bgp, arg);
1123 if (!peer) {
1124 vty_out(vty,
1125 "Malformed address or name: %s\n",
1126 arg);
1127 return CMD_WARNING;
1128 }
1129 }
1130 } else {
1131 peer = peer_lookup(bgp, &su);
1132 if (!peer) {
1133 vty_out(vty,
1134 "%% BGP: Unknown neighbor - \"%s\"\n",
1135 arg);
1136 return CMD_WARNING;
1137 }
1138 }
1139
1140 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1141 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1142
1143 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1144
1145 /* if afi/safi not defined for this peer, let caller know */
1146 if (ret == 1)
1147 ret = BGP_ERR_AF_UNCONFIGURED;
1148
1149 if (ret < 0)
1150 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1151
1152 return CMD_SUCCESS;
1153 }
1154
1155 /* Clear all neighbors belonging to a specific peer-group. */
1156 if (sort == clear_group) {
1157 struct peer_group *group;
1158
1159 group = peer_group_lookup(bgp, arg);
1160 if (!group) {
1161 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1162 return CMD_WARNING;
1163 }
1164
1165 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1166 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1167
1168 if (ret < 0)
1169 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1170 else
1171 found = true;
1172 }
1173
1174 if (!found)
1175 vty_out(vty,
1176 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1177 get_afi_safi_str(afi, safi, false), arg);
1178
1179 return CMD_SUCCESS;
1180 }
1181
1182 /* Clear all external (eBGP) neighbors. */
1183 if (sort == clear_external) {
1184 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1185 if (peer->sort == BGP_PEER_IBGP)
1186 continue;
1187
1188 bgp_peer_gr_flags_update(peer);
1189
1190 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1191 gr_router_detected = true;
1192
1193 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1194
1195 if (ret < 0)
1196 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1197 else
1198 found = true;
1199 }
1200
1201 if (gr_router_detected
1202 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1203 bgp_zebra_send_capabilities(bgp, false);
1204 } else if (!gr_router_detected
1205 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1206 bgp_zebra_send_capabilities(bgp, true);
1207 }
1208
1209 if (!found)
1210 vty_out(vty,
1211 "%% BGP: No external %s peer is configured\n",
1212 get_afi_safi_str(afi, safi, false));
1213
1214 return CMD_SUCCESS;
1215 }
1216
1217 /* Clear all neighbors belonging to a specific AS. */
1218 if (sort == clear_as) {
1219 as_t as = strtoul(arg, NULL, 10);
1220
1221 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1222 if (peer->as != as)
1223 continue;
1224
1225 bgp_peer_gr_flags_update(peer);
1226
1227 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1228 gr_router_detected = true;
1229
1230 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1231
1232 if (ret < 0)
1233 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1234 else
1235 found = true;
1236 }
1237
1238 if (gr_router_detected
1239 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1240 bgp_zebra_send_capabilities(bgp, false);
1241 } else if (!gr_router_detected
1242 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1243 bgp_zebra_send_capabilities(bgp, true);
1244 }
1245
1246 if (!found)
1247 vty_out(vty,
1248 "%% BGP: No %s peer is configured with AS %s\n",
1249 get_afi_safi_str(afi, safi, false), arg);
1250
1251 return CMD_SUCCESS;
1252 }
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1258 safi_t safi, enum clear_sort sort,
1259 enum bgp_clear_type stype, const char *arg)
1260 {
1261 struct bgp *bgp;
1262
1263 /* BGP structure lookup. */
1264 if (name) {
1265 bgp = bgp_lookup_by_name(name);
1266 if (bgp == NULL) {
1267 vty_out(vty, "Can't find BGP instance %s\n", name);
1268 return CMD_WARNING;
1269 }
1270 } else {
1271 bgp = bgp_get_default();
1272 if (bgp == NULL) {
1273 vty_out(vty, "No BGP process is configured\n");
1274 return CMD_WARNING;
1275 }
1276 }
1277
1278 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1279 }
1280
1281 /* clear soft inbound */
1282 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1283 {
1284 afi_t afi;
1285 safi_t safi;
1286
1287 FOREACH_AFI_SAFI (afi, safi)
1288 bgp_clear_vty(vty, name, afi, safi, clear_all,
1289 BGP_CLEAR_SOFT_IN, NULL);
1290 }
1291
1292 /* clear soft outbound */
1293 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1294 {
1295 afi_t afi;
1296 safi_t safi;
1297
1298 FOREACH_AFI_SAFI (afi, safi)
1299 bgp_clear_vty(vty, name, afi, safi, clear_all,
1300 BGP_CLEAR_SOFT_OUT, NULL);
1301 }
1302
1303
1304 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1305 {
1306 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1307 }
1308
1309 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1310 uint64_t flag, int set)
1311 {
1312 int ret;
1313 struct peer *peer;
1314
1315 peer = peer_and_group_lookup_vty(vty, ip_str);
1316 if (!peer)
1317 return CMD_WARNING_CONFIG_FAILED;
1318
1319 /*
1320 * If 'neighbor <interface>', then this is for directly connected peers,
1321 * we should not accept disable-connected-check.
1322 */
1323 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1324 vty_out(vty,
1325 "%s is directly connected peer, cannot accept disable-connected-check\n",
1326 ip_str);
1327 return CMD_WARNING_CONFIG_FAILED;
1328 }
1329
1330 if (!set && flag == PEER_FLAG_SHUTDOWN)
1331 peer_tx_shutdown_message_unset(peer);
1332
1333 if (set)
1334 ret = peer_flag_set(peer, flag);
1335 else
1336 ret = peer_flag_unset(peer, flag);
1337
1338 return bgp_vty_return(vty, ret);
1339 }
1340
1341 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1342 {
1343 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1344 }
1345
1346 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1347 uint64_t flag)
1348 {
1349 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1350 }
1351
1352 #include "bgpd/bgp_vty_clippy.c"
1353
1354 DEFUN_HIDDEN (bgp_local_mac,
1355 bgp_local_mac_cmd,
1356 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1357 BGP_STR
1358 "Local MAC config\n"
1359 "VxLAN Network Identifier\n"
1360 "VNI number\n"
1361 "local mac\n"
1362 "mac address\n"
1363 "mac-mobility sequence\n"
1364 "seq number\n")
1365 {
1366 int rv;
1367 vni_t vni;
1368 struct ethaddr mac;
1369 struct ipaddr ip;
1370 uint32_t seq;
1371 struct bgp *bgp;
1372
1373 vni = strtoul(argv[3]->arg, NULL, 10);
1374 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1375 vty_out(vty, "%% Malformed MAC address\n");
1376 return CMD_WARNING;
1377 }
1378 memset(&ip, 0, sizeof(ip));
1379 seq = strtoul(argv[7]->arg, NULL, 10);
1380
1381 bgp = bgp_get_default();
1382 if (!bgp) {
1383 vty_out(vty, "Default BGP instance is not there\n");
1384 return CMD_WARNING;
1385 }
1386
1387 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1388 zero_esi);
1389 if (rv < 0) {
1390 vty_out(vty, "Internal error\n");
1391 return CMD_WARNING;
1392 }
1393
1394 return CMD_SUCCESS;
1395 }
1396
1397 DEFUN_HIDDEN (no_bgp_local_mac,
1398 no_bgp_local_mac_cmd,
1399 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1400 NO_STR
1401 BGP_STR
1402 "Local MAC config\n"
1403 "VxLAN Network Identifier\n"
1404 "VNI number\n"
1405 "local mac\n"
1406 "mac address\n")
1407 {
1408 int rv;
1409 vni_t vni;
1410 struct ethaddr mac;
1411 struct ipaddr ip;
1412 struct bgp *bgp;
1413
1414 vni = strtoul(argv[4]->arg, NULL, 10);
1415 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1416 vty_out(vty, "%% Malformed MAC address\n");
1417 return CMD_WARNING;
1418 }
1419 memset(&ip, 0, sizeof(ip));
1420
1421 bgp = bgp_get_default();
1422 if (!bgp) {
1423 vty_out(vty, "Default BGP instance is not there\n");
1424 return CMD_WARNING;
1425 }
1426
1427 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1428 if (rv < 0) {
1429 vty_out(vty, "Internal error\n");
1430 return CMD_WARNING;
1431 }
1432
1433 return CMD_SUCCESS;
1434 }
1435
1436 DEFUN (no_synchronization,
1437 no_synchronization_cmd,
1438 "no synchronization",
1439 NO_STR
1440 "Perform IGP synchronization\n")
1441 {
1442 return CMD_SUCCESS;
1443 }
1444
1445 DEFUN (no_auto_summary,
1446 no_auto_summary_cmd,
1447 "no auto-summary",
1448 NO_STR
1449 "Enable automatic network number summarization\n")
1450 {
1451 return CMD_SUCCESS;
1452 }
1453
1454 /* "router bgp" commands. */
1455 DEFUN_NOSH (router_bgp,
1456 router_bgp_cmd,
1457 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1458 ROUTER_STR
1459 BGP_STR
1460 AS_STR
1461 BGP_INSTANCE_HELP_STR)
1462 {
1463 int idx_asn = 2;
1464 int idx_view_vrf = 3;
1465 int idx_vrf = 4;
1466 int is_new_bgp = 0;
1467 int ret;
1468 as_t as;
1469 struct bgp *bgp;
1470 const char *name = NULL;
1471 enum bgp_instance_type inst_type;
1472
1473 // "router bgp" without an ASN
1474 if (argc == 2) {
1475 // Pending: Make VRF option available for ASN less config
1476 bgp = bgp_get_default();
1477
1478 if (bgp == NULL) {
1479 vty_out(vty, "%% No BGP process is configured\n");
1480 return CMD_WARNING_CONFIG_FAILED;
1481 }
1482
1483 if (listcount(bm->bgp) > 1) {
1484 vty_out(vty, "%% Please specify ASN and VRF\n");
1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
1487 }
1488
1489 // "router bgp X"
1490 else {
1491 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1492
1493 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1494 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1495 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1496
1497 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1498 if (argc > 3) {
1499 name = argv[idx_vrf]->arg;
1500
1501 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1502 if (strmatch(name, VRF_DEFAULT_NAME))
1503 name = NULL;
1504 else
1505 inst_type = BGP_INSTANCE_TYPE_VRF;
1506 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1507 inst_type = BGP_INSTANCE_TYPE_VIEW;
1508 }
1509
1510 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1511 is_new_bgp = (bgp_lookup(as, name) == NULL);
1512
1513 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1514 switch (ret) {
1515 case BGP_ERR_AS_MISMATCH:
1516 vty_out(vty, "BGP is already running; AS is %u\n", as);
1517 return CMD_WARNING_CONFIG_FAILED;
1518 case BGP_ERR_INSTANCE_MISMATCH:
1519 vty_out(vty,
1520 "BGP instance name and AS number mismatch\n");
1521 vty_out(vty,
1522 "BGP instance is already running; AS is %u\n",
1523 as);
1524 return CMD_WARNING_CONFIG_FAILED;
1525 }
1526
1527 /*
1528 * If we just instantiated the default instance, complete
1529 * any pending VRF-VPN leaking that was configured via
1530 * earlier "router bgp X vrf FOO" blocks.
1531 */
1532 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1533 vpn_leak_postchange_all();
1534
1535 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1536 bgp_vpn_leak_export(bgp);
1537 /* Pending: handle when user tries to change a view to vrf n vv.
1538 */
1539 }
1540
1541 /* unset the auto created flag as the user config is now present */
1542 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1543 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1544
1545 return CMD_SUCCESS;
1546 }
1547
1548 /* "no router bgp" commands. */
1549 DEFUN (no_router_bgp,
1550 no_router_bgp_cmd,
1551 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1552 NO_STR
1553 ROUTER_STR
1554 BGP_STR
1555 AS_STR
1556 BGP_INSTANCE_HELP_STR)
1557 {
1558 int idx_asn = 3;
1559 int idx_vrf = 5;
1560 as_t as;
1561 struct bgp *bgp;
1562 const char *name = NULL;
1563
1564 // "no router bgp" without an ASN
1565 if (argc == 3) {
1566 // Pending: Make VRF option available for ASN less config
1567 bgp = bgp_get_default();
1568
1569 if (bgp == NULL) {
1570 vty_out(vty, "%% No BGP process is configured\n");
1571 return CMD_WARNING_CONFIG_FAILED;
1572 }
1573
1574 if (listcount(bm->bgp) > 1) {
1575 vty_out(vty, "%% Please specify ASN and VRF\n");
1576 return CMD_WARNING_CONFIG_FAILED;
1577 }
1578
1579 if (bgp->l3vni) {
1580 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1581 bgp->l3vni);
1582 return CMD_WARNING_CONFIG_FAILED;
1583 }
1584 } else {
1585 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1586
1587 if (argc > 4) {
1588 name = argv[idx_vrf]->arg;
1589 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1590 && strmatch(name, VRF_DEFAULT_NAME))
1591 name = NULL;
1592 }
1593
1594 /* Lookup bgp structure. */
1595 bgp = bgp_lookup(as, name);
1596 if (!bgp) {
1597 vty_out(vty, "%% Can't find BGP instance\n");
1598 return CMD_WARNING_CONFIG_FAILED;
1599 }
1600
1601 if (bgp->l3vni) {
1602 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1603 bgp->l3vni);
1604 return CMD_WARNING_CONFIG_FAILED;
1605 }
1606
1607 /* Cannot delete default instance if vrf instances exist */
1608 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1609 struct listnode *node;
1610 struct bgp *tmp_bgp;
1611
1612 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1613 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1614 continue;
1615 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1616 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1617 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1618 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1619 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1620 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1621 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1622 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1623 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1624 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1625 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1626 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1627 (bgp == bgp_get_evpn() &&
1628 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1629 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1630 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1631 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1632 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1633 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1634 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1635 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1636 (hashcount(tmp_bgp->vnihash))) {
1637 vty_out(vty,
1638 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1639 return CMD_WARNING_CONFIG_FAILED;
1640 }
1641 }
1642 }
1643 }
1644
1645 bgp_delete(bgp);
1646
1647 return CMD_SUCCESS;
1648 }
1649
1650 /* bgp session-dscp */
1651
1652 DEFPY (bgp_session_dscp,
1653 bgp_session_dscp_cmd,
1654 "bgp session-dscp (0-63)$dscp",
1655 BGP_STR
1656 "Override default (C6) bgp TCP session DSCP value\n"
1657 "Manually configured dscp parameter\n")
1658 {
1659 bm->tcp_dscp = dscp << 2;
1660
1661 return CMD_SUCCESS;
1662 }
1663
1664 DEFPY (no_bgp_session_dscp,
1665 no_bgp_session_dscp_cmd,
1666 "no bgp session-dscp [(0-63)]",
1667 NO_STR
1668 BGP_STR
1669 "Override default (C6) bgp TCP session DSCP value\n"
1670 "Manually configured dscp parameter\n")
1671 {
1672 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1673
1674 return CMD_SUCCESS;
1675 }
1676
1677 /* BGP router-id. */
1678
1679 DEFPY (bgp_router_id,
1680 bgp_router_id_cmd,
1681 "bgp router-id A.B.C.D",
1682 BGP_STR
1683 "Override configured router identifier\n"
1684 "Manually configured router identifier\n")
1685 {
1686 VTY_DECLVAR_CONTEXT(bgp, bgp);
1687 bgp_router_id_static_set(bgp, router_id);
1688 return CMD_SUCCESS;
1689 }
1690
1691 DEFPY (no_bgp_router_id,
1692 no_bgp_router_id_cmd,
1693 "no bgp router-id [A.B.C.D]",
1694 NO_STR
1695 BGP_STR
1696 "Override configured router identifier\n"
1697 "Manually configured router identifier\n")
1698 {
1699 VTY_DECLVAR_CONTEXT(bgp, bgp);
1700
1701 if (router_id_str) {
1702 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1703 vty_out(vty, "%% BGP router-id doesn't match\n");
1704 return CMD_WARNING_CONFIG_FAILED;
1705 }
1706 }
1707
1708 router_id.s_addr = 0;
1709 bgp_router_id_static_set(bgp, router_id);
1710
1711 return CMD_SUCCESS;
1712 }
1713
1714 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1715 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1716 NO_STR BGP_STR
1717 "Add community specific parameters\n"
1718 "Create an alias for a community\n"
1719 "Community (AA:BB or AA:BB:CC)\n"
1720 "Alias name\n")
1721 {
1722 struct community_alias ca = {};
1723 struct community_alias *lookup_community;
1724 struct community_alias *lookup_alias;
1725 struct community *comm;
1726 struct lcommunity *lcomm;
1727 uint8_t invalid = 0;
1728
1729 comm = community_str2com(community);
1730 if (!comm)
1731 invalid++;
1732 community_free(&comm);
1733
1734 lcomm = lcommunity_str2com(community);
1735 if (!lcomm)
1736 invalid++;
1737 lcommunity_free(&lcomm);
1738
1739 if (invalid > 1) {
1740 vty_out(vty, "Invalid community format\n");
1741 return CMD_WARNING;
1742 }
1743
1744 strlcpy(ca.community, community, sizeof(ca.community));
1745 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1746
1747 lookup_community = bgp_ca_community_lookup(&ca);
1748 lookup_alias = bgp_ca_alias_lookup(&ca);
1749
1750 if (no) {
1751 bgp_ca_alias_delete(&ca);
1752 bgp_ca_community_delete(&ca);
1753 } else {
1754 if (lookup_alias) {
1755 /* Lookup if community hash table has an item
1756 * with the same alias name.
1757 */
1758 strlcpy(ca.community, lookup_alias->community,
1759 sizeof(ca.community));
1760 if (bgp_ca_community_lookup(&ca)) {
1761 vty_out(vty,
1762 "community (%s) already has this alias (%s)\n",
1763 lookup_alias->community,
1764 lookup_alias->alias);
1765 return CMD_WARNING;
1766 }
1767 bgp_ca_alias_delete(&ca);
1768 }
1769
1770 if (lookup_community) {
1771 /* Lookup if alias hash table has an item
1772 * with the same community.
1773 */
1774 strlcpy(ca.alias, lookup_community->alias,
1775 sizeof(ca.alias));
1776 if (bgp_ca_alias_lookup(&ca)) {
1777 vty_out(vty,
1778 "alias (%s) already has this community (%s)\n",
1779 lookup_community->alias,
1780 lookup_community->community);
1781 return CMD_WARNING;
1782 }
1783 bgp_ca_community_delete(&ca);
1784 }
1785
1786 bgp_ca_alias_insert(&ca);
1787 bgp_ca_community_insert(&ca);
1788 }
1789
1790 return CMD_SUCCESS;
1791 }
1792
1793 DEFPY (bgp_global_suppress_fib_pending,
1794 bgp_global_suppress_fib_pending_cmd,
1795 "[no] bgp suppress-fib-pending",
1796 NO_STR
1797 BGP_STR
1798 "Advertise only routes that are programmed in kernel to peers globally\n")
1799 {
1800 bm_wait_for_fib_set(!no);
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805 DEFPY (bgp_suppress_fib_pending,
1806 bgp_suppress_fib_pending_cmd,
1807 "[no] bgp suppress-fib-pending",
1808 NO_STR
1809 BGP_STR
1810 "Advertise only routes that are programmed in kernel to peers\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813
1814 bgp_suppress_fib_pending_set(bgp, !no);
1815 return CMD_SUCCESS;
1816 }
1817
1818
1819 /* BGP Cluster ID. */
1820 DEFUN (bgp_cluster_id,
1821 bgp_cluster_id_cmd,
1822 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1823 BGP_STR
1824 "Configure Route-Reflector Cluster-id\n"
1825 "Route-Reflector Cluster-id in IP address format\n"
1826 "Route-Reflector Cluster-id as 32 bit quantity\n")
1827 {
1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 int idx_ipv4 = 2;
1830 int ret;
1831 struct in_addr cluster;
1832
1833 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1834 if (!ret) {
1835 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1836 return CMD_WARNING_CONFIG_FAILED;
1837 }
1838
1839 bgp_cluster_id_set(bgp, &cluster);
1840 bgp_clear_star_soft_out(vty, bgp->name);
1841
1842 return CMD_SUCCESS;
1843 }
1844
1845 DEFUN (no_bgp_cluster_id,
1846 no_bgp_cluster_id_cmd,
1847 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1848 NO_STR
1849 BGP_STR
1850 "Configure Route-Reflector Cluster-id\n"
1851 "Route-Reflector Cluster-id in IP address format\n"
1852 "Route-Reflector Cluster-id as 32 bit quantity\n")
1853 {
1854 VTY_DECLVAR_CONTEXT(bgp, bgp);
1855 bgp_cluster_id_unset(bgp);
1856 bgp_clear_star_soft_out(vty, bgp->name);
1857
1858 return CMD_SUCCESS;
1859 }
1860
1861 DEFPY (bgp_norib,
1862 bgp_norib_cmd,
1863 "bgp no-rib",
1864 BGP_STR
1865 "Disable BGP route installation to RIB (Zebra)\n")
1866 {
1867 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1868 vty_out(vty,
1869 "%% No-RIB option is already set, nothing to do here.\n");
1870 return CMD_SUCCESS;
1871 }
1872
1873 bgp_option_norib_set_runtime();
1874
1875 return CMD_SUCCESS;
1876 }
1877
1878 DEFPY (no_bgp_norib,
1879 no_bgp_norib_cmd,
1880 "no bgp no-rib",
1881 NO_STR
1882 BGP_STR
1883 "Disable BGP route installation to RIB (Zebra)\n")
1884 {
1885 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1886 vty_out(vty,
1887 "%% No-RIB option is not set, nothing to do here.\n");
1888 return CMD_SUCCESS;
1889 }
1890
1891 bgp_option_norib_unset_runtime();
1892
1893 return CMD_SUCCESS;
1894 }
1895
1896 DEFPY (no_bgp_send_extra_data,
1897 no_bgp_send_extra_data_cmd,
1898 "[no] bgp send-extra-data zebra",
1899 NO_STR
1900 BGP_STR
1901 "Extra data to Zebra for display/use\n"
1902 "To zebra\n")
1903 {
1904 if (no)
1905 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1906 else
1907 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1908
1909 return CMD_SUCCESS;
1910 }
1911
1912 DEFUN (bgp_confederation_identifier,
1913 bgp_confederation_identifier_cmd,
1914 "bgp confederation identifier (1-4294967295)",
1915 BGP_STR
1916 "AS confederation parameters\n"
1917 "AS number\n"
1918 "Set routing domain confederation AS\n")
1919 {
1920 VTY_DECLVAR_CONTEXT(bgp, bgp);
1921 int idx_number = 3;
1922 as_t as;
1923
1924 as = strtoul(argv[idx_number]->arg, NULL, 10);
1925
1926 bgp_confederation_id_set(bgp, as);
1927
1928 return CMD_SUCCESS;
1929 }
1930
1931 DEFUN (no_bgp_confederation_identifier,
1932 no_bgp_confederation_identifier_cmd,
1933 "no bgp confederation identifier [(1-4294967295)]",
1934 NO_STR
1935 BGP_STR
1936 "AS confederation parameters\n"
1937 "AS number\n"
1938 "Set routing domain confederation AS\n")
1939 {
1940 VTY_DECLVAR_CONTEXT(bgp, bgp);
1941 bgp_confederation_id_unset(bgp);
1942
1943 return CMD_SUCCESS;
1944 }
1945
1946 DEFUN (bgp_confederation_peers,
1947 bgp_confederation_peers_cmd,
1948 "bgp confederation peers (1-4294967295)...",
1949 BGP_STR
1950 "AS confederation parameters\n"
1951 "Peer ASs in BGP confederation\n"
1952 AS_STR)
1953 {
1954 VTY_DECLVAR_CONTEXT(bgp, bgp);
1955 int idx_asn = 3;
1956 as_t as;
1957 int i;
1958
1959 for (i = idx_asn; i < argc; i++) {
1960 as = strtoul(argv[i]->arg, NULL, 10);
1961 bgp_confederation_peers_add(bgp, as);
1962 }
1963 return CMD_SUCCESS;
1964 }
1965
1966 DEFUN (no_bgp_confederation_peers,
1967 no_bgp_confederation_peers_cmd,
1968 "no bgp confederation peers (1-4294967295)...",
1969 NO_STR
1970 BGP_STR
1971 "AS confederation parameters\n"
1972 "Peer ASs in BGP confederation\n"
1973 AS_STR)
1974 {
1975 VTY_DECLVAR_CONTEXT(bgp, bgp);
1976 int idx_asn = 4;
1977 as_t as;
1978 int i;
1979
1980 for (i = idx_asn; i < argc; i++) {
1981 as = strtoul(argv[i]->arg, NULL, 10);
1982
1983 bgp_confederation_peers_remove(bgp, as);
1984 }
1985 return CMD_SUCCESS;
1986 }
1987
1988 /**
1989 * Central routine for maximum-paths configuration.
1990 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1991 * @set: 1 for setting values, 0 for removing the max-paths config.
1992 */
1993 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1994 const char *mpaths, uint16_t options,
1995 int set)
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998 uint16_t maxpaths = 0;
1999 int ret;
2000 afi_t afi;
2001 safi_t safi;
2002
2003 afi = bgp_node_afi(vty);
2004 safi = bgp_node_safi(vty);
2005
2006 if (set) {
2007 maxpaths = strtol(mpaths, NULL, 10);
2008 if (maxpaths > multipath_num) {
2009 vty_out(vty,
2010 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2011 maxpaths, multipath_num);
2012 return CMD_WARNING_CONFIG_FAILED;
2013 }
2014 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2015 options);
2016 } else
2017 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2018
2019 if (ret < 0) {
2020 vty_out(vty,
2021 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2022 (set == 1) ? "" : "un",
2023 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2024 maxpaths, afi, safi);
2025 return CMD_WARNING_CONFIG_FAILED;
2026 }
2027
2028 bgp_recalculate_all_bestpaths(bgp);
2029
2030 return CMD_SUCCESS;
2031 }
2032
2033 DEFUN (bgp_maxmed_admin,
2034 bgp_maxmed_admin_cmd,
2035 "bgp max-med administrative ",
2036 BGP_STR
2037 "Advertise routes with max-med\n"
2038 "Administratively applied, for an indefinite period\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041
2042 bgp->v_maxmed_admin = 1;
2043 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2044
2045 bgp_maxmed_update(bgp);
2046
2047 return CMD_SUCCESS;
2048 }
2049
2050 DEFUN (bgp_maxmed_admin_medv,
2051 bgp_maxmed_admin_medv_cmd,
2052 "bgp max-med administrative (0-4294967295)",
2053 BGP_STR
2054 "Advertise routes with max-med\n"
2055 "Administratively applied, for an indefinite period\n"
2056 "Max MED value to be used\n")
2057 {
2058 VTY_DECLVAR_CONTEXT(bgp, bgp);
2059 int idx_number = 3;
2060
2061 bgp->v_maxmed_admin = 1;
2062 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2063
2064 bgp_maxmed_update(bgp);
2065
2066 return CMD_SUCCESS;
2067 }
2068
2069 DEFUN (no_bgp_maxmed_admin,
2070 no_bgp_maxmed_admin_cmd,
2071 "no bgp max-med administrative [(0-4294967295)]",
2072 NO_STR
2073 BGP_STR
2074 "Advertise routes with max-med\n"
2075 "Administratively applied, for an indefinite period\n"
2076 "Max MED value to be used\n")
2077 {
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2080 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2081 bgp_maxmed_update(bgp);
2082
2083 return CMD_SUCCESS;
2084 }
2085
2086 DEFUN (bgp_maxmed_onstartup,
2087 bgp_maxmed_onstartup_cmd,
2088 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2089 BGP_STR
2090 "Advertise routes with max-med\n"
2091 "Effective on a startup\n"
2092 "Time (seconds) period for max-med\n"
2093 "Max MED value to be used\n")
2094 {
2095 VTY_DECLVAR_CONTEXT(bgp, bgp);
2096 int idx = 0;
2097
2098 if (argv_find(argv, argc, "(5-86400)", &idx))
2099 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2100 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2101 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2102 else
2103 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2104
2105 bgp_maxmed_update(bgp);
2106
2107 return CMD_SUCCESS;
2108 }
2109
2110 DEFUN (no_bgp_maxmed_onstartup,
2111 no_bgp_maxmed_onstartup_cmd,
2112 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2113 NO_STR
2114 BGP_STR
2115 "Advertise routes with max-med\n"
2116 "Effective on a startup\n"
2117 "Time (seconds) period for max-med\n"
2118 "Max MED value to be used\n")
2119 {
2120 VTY_DECLVAR_CONTEXT(bgp, bgp);
2121
2122 /* Cancel max-med onstartup if its on */
2123 if (bgp->t_maxmed_onstartup) {
2124 THREAD_OFF(bgp->t_maxmed_onstartup);
2125 bgp->maxmed_onstartup_over = 1;
2126 }
2127
2128 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2129 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2130
2131 bgp_maxmed_update(bgp);
2132
2133 return CMD_SUCCESS;
2134 }
2135
2136 static int bgp_global_update_delay_config_vty(struct vty *vty,
2137 uint16_t update_delay,
2138 uint16_t establish_wait)
2139 {
2140 struct listnode *node, *nnode;
2141 struct bgp *bgp;
2142 bool vrf_cfg = false;
2143
2144 /*
2145 * See if update-delay is set per-vrf and warn user to delete it
2146 * Note that we only need to check this if this is the first time
2147 * setting the global config.
2148 */
2149 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2150 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2151 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2152 vty_out(vty,
2153 "%% update-delay configuration found in vrf %s\n",
2154 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2155 ? VRF_DEFAULT_NAME
2156 : bgp->name);
2157 vrf_cfg = true;
2158 }
2159 }
2160 }
2161
2162 if (vrf_cfg) {
2163 vty_out(vty,
2164 "%%Failed: global update-delay config not permitted\n");
2165 return CMD_WARNING;
2166 }
2167
2168 if (!establish_wait) { /* update-delay <delay> */
2169 bm->v_update_delay = update_delay;
2170 bm->v_establish_wait = bm->v_update_delay;
2171 } else {
2172 /* update-delay <delay> <establish-wait> */
2173 if (update_delay < establish_wait) {
2174 vty_out(vty,
2175 "%%Failed: update-delay less than the establish-wait!\n");
2176 return CMD_WARNING_CONFIG_FAILED;
2177 }
2178
2179 bm->v_update_delay = update_delay;
2180 bm->v_establish_wait = establish_wait;
2181 }
2182
2183 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2184 bgp->v_update_delay = bm->v_update_delay;
2185 bgp->v_establish_wait = bm->v_establish_wait;
2186 }
2187
2188 return CMD_SUCCESS;
2189 }
2190
2191 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2192 {
2193 struct listnode *node, *nnode;
2194 struct bgp *bgp;
2195
2196 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2197 bm->v_establish_wait = bm->v_update_delay;
2198
2199 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2200 bgp->v_update_delay = bm->v_update_delay;
2201 bgp->v_establish_wait = bm->v_establish_wait;
2202 }
2203
2204 return CMD_SUCCESS;
2205 }
2206
2207 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2208 uint16_t establish_wait)
2209 {
2210 VTY_DECLVAR_CONTEXT(bgp, bgp);
2211
2212 /* if configured globally, per-instance config is not allowed */
2213 if (bm->v_update_delay) {
2214 vty_out(vty,
2215 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2216 return CMD_WARNING_CONFIG_FAILED;
2217 }
2218
2219
2220 if (!establish_wait) /* update-delay <delay> */
2221 {
2222 bgp->v_update_delay = update_delay;
2223 bgp->v_establish_wait = bgp->v_update_delay;
2224 return CMD_SUCCESS;
2225 }
2226
2227 /* update-delay <delay> <establish-wait> */
2228 if (update_delay < establish_wait) {
2229 vty_out(vty,
2230 "%%Failed: update-delay less than the establish-wait!\n");
2231 return CMD_WARNING_CONFIG_FAILED;
2232 }
2233
2234 bgp->v_update_delay = update_delay;
2235 bgp->v_establish_wait = establish_wait;
2236
2237 return CMD_SUCCESS;
2238 }
2239
2240 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2241 {
2242 VTY_DECLVAR_CONTEXT(bgp, bgp);
2243
2244 /* If configured globally, cannot remove from one bgp instance */
2245 if (bm->v_update_delay) {
2246 vty_out(vty,
2247 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2248 return CMD_WARNING_CONFIG_FAILED;
2249 }
2250 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2251 bgp->v_establish_wait = bgp->v_update_delay;
2252
2253 return CMD_SUCCESS;
2254 }
2255
2256 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2257 {
2258 /* If configured globally, no need to display per-instance value */
2259 if (bgp->v_update_delay != bm->v_update_delay) {
2260 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2261 if (bgp->v_update_delay != bgp->v_establish_wait)
2262 vty_out(vty, " %d", bgp->v_establish_wait);
2263 vty_out(vty, "\n");
2264 }
2265 }
2266
2267 /* Global update-delay configuration */
2268 DEFPY (bgp_global_update_delay,
2269 bgp_global_update_delay_cmd,
2270 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2271 BGP_STR
2272 "Force initial delay for best-path and updates for all bgp instances\n"
2273 "Max delay in seconds\n"
2274 "Establish wait in seconds\n")
2275 {
2276 return bgp_global_update_delay_config_vty(vty, delay, wait);
2277 }
2278
2279 /* Global update-delay deconfiguration */
2280 DEFPY (no_bgp_global_update_delay,
2281 no_bgp_global_update_delay_cmd,
2282 "no bgp update-delay [(0-3600) [(1-3600)]]",
2283 NO_STR
2284 BGP_STR
2285 "Force initial delay for best-path and updates\n"
2286 "Max delay in seconds\n"
2287 "Establish wait in seconds\n")
2288 {
2289 return bgp_global_update_delay_deconfig_vty(vty);
2290 }
2291
2292 /* Update-delay configuration */
2293
2294 DEFPY (bgp_update_delay,
2295 bgp_update_delay_cmd,
2296 "update-delay (0-3600)$delay [(1-3600)$wait]",
2297 "Force initial delay for best-path and updates\n"
2298 "Max delay in seconds\n"
2299 "Establish wait in seconds\n")
2300 {
2301 return bgp_update_delay_config_vty(vty, delay, wait);
2302 }
2303
2304 /* Update-delay deconfiguration */
2305 DEFPY (no_bgp_update_delay,
2306 no_bgp_update_delay_cmd,
2307 "no update-delay [(0-3600) [(1-3600)]]",
2308 NO_STR
2309 "Force initial delay for best-path and updates\n"
2310 "Max delay in seconds\n"
2311 "Establish wait in seconds\n")
2312 {
2313 return bgp_update_delay_deconfig_vty(vty);
2314 }
2315
2316
2317 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2318 bool set)
2319 {
2320 VTY_DECLVAR_CONTEXT(bgp, bgp);
2321
2322 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2323 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2324
2325 return CMD_SUCCESS;
2326 }
2327
2328 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2329 bool set)
2330 {
2331 VTY_DECLVAR_CONTEXT(bgp, bgp);
2332
2333 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2334 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2335
2336 return CMD_SUCCESS;
2337 }
2338
2339 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2340 {
2341 uint32_t quanta =
2342 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2343 if (quanta != BGP_WRITE_PACKET_MAX)
2344 vty_out(vty, " write-quanta %d\n", quanta);
2345 }
2346
2347 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2348 {
2349 uint32_t quanta =
2350 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2351 if (quanta != BGP_READ_PACKET_MAX)
2352 vty_out(vty, " read-quanta %d\n", quanta);
2353 }
2354
2355 /* Packet quanta configuration
2356 *
2357 * XXX: The value set here controls the size of a stack buffer in the IO
2358 * thread. When changing these limits be careful to prevent stack overflow.
2359 *
2360 * Furthermore, the maximums used here should correspond to
2361 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2362 */
2363 DEFPY (bgp_wpkt_quanta,
2364 bgp_wpkt_quanta_cmd,
2365 "[no] write-quanta (1-64)$quanta",
2366 NO_STR
2367 "How many packets to write to peer socket per run\n"
2368 "Number of packets\n")
2369 {
2370 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2371 }
2372
2373 DEFPY (bgp_rpkt_quanta,
2374 bgp_rpkt_quanta_cmd,
2375 "[no] read-quanta (1-10)$quanta",
2376 NO_STR
2377 "How many packets to read from peer socket per I/O cycle\n"
2378 "Number of packets\n")
2379 {
2380 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2381 }
2382
2383 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2384 {
2385 if (!bgp->heuristic_coalesce)
2386 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2387 }
2388
2389 /* BGP TCP keepalive */
2390 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2391 {
2392 if (bgp->tcp_keepalive_idle) {
2393 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2394 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2395 bgp->tcp_keepalive_probes);
2396 }
2397 }
2398
2399 DEFUN (bgp_coalesce_time,
2400 bgp_coalesce_time_cmd,
2401 "coalesce-time (0-4294967295)",
2402 "Subgroup coalesce timer\n"
2403 "Subgroup coalesce timer value (in ms)\n")
2404 {
2405 VTY_DECLVAR_CONTEXT(bgp, bgp);
2406
2407 int idx = 0;
2408
2409 bgp->heuristic_coalesce = false;
2410
2411 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2412 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2413
2414 return CMD_SUCCESS;
2415 }
2416
2417 DEFUN (no_bgp_coalesce_time,
2418 no_bgp_coalesce_time_cmd,
2419 "no coalesce-time (0-4294967295)",
2420 NO_STR
2421 "Subgroup coalesce timer\n"
2422 "Subgroup coalesce timer value (in ms)\n")
2423 {
2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425
2426 bgp->heuristic_coalesce = true;
2427 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2428 return CMD_SUCCESS;
2429 }
2430
2431 /* Maximum-paths configuration */
2432 DEFUN (bgp_maxpaths,
2433 bgp_maxpaths_cmd,
2434 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2435 "Forward packets over multiple paths\n"
2436 "Number of paths\n")
2437 {
2438 int idx_number = 1;
2439 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2440 argv[idx_number]->arg, 0, 1);
2441 }
2442
2443 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2444 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2445 "Forward packets over multiple paths\n"
2446 "Number of paths\n")
2447
2448 DEFUN (bgp_maxpaths_ibgp,
2449 bgp_maxpaths_ibgp_cmd,
2450 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2451 "Forward packets over multiple paths\n"
2452 "iBGP-multipath\n"
2453 "Number of paths\n")
2454 {
2455 int idx_number = 2;
2456 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2457 argv[idx_number]->arg, 0, 1);
2458 }
2459
2460 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2461 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2462 "Forward packets over multiple paths\n"
2463 "iBGP-multipath\n"
2464 "Number of paths\n")
2465
2466 DEFUN (bgp_maxpaths_ibgp_cluster,
2467 bgp_maxpaths_ibgp_cluster_cmd,
2468 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2469 "Forward packets over multiple paths\n"
2470 "iBGP-multipath\n"
2471 "Number of paths\n"
2472 "Match the cluster length\n")
2473 {
2474 int idx_number = 2;
2475 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2476 argv[idx_number]->arg, true, 1);
2477 }
2478
2479 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2480 "maximum-paths ibgp " CMD_RANGE_STR(
2481 1, MULTIPATH_NUM) " equal-cluster-length",
2482 "Forward packets over multiple paths\n"
2483 "iBGP-multipath\n"
2484 "Number of paths\n"
2485 "Match the cluster length\n")
2486
2487 DEFUN (no_bgp_maxpaths,
2488 no_bgp_maxpaths_cmd,
2489 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2490 NO_STR
2491 "Forward packets over multiple paths\n"
2492 "Number of paths\n")
2493 {
2494 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2495 }
2496
2497 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2498 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2499 "Forward packets over multiple paths\n"
2500 "Number of paths\n")
2501
2502 DEFUN (no_bgp_maxpaths_ibgp,
2503 no_bgp_maxpaths_ibgp_cmd,
2504 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2505 NO_STR
2506 "Forward packets over multiple paths\n"
2507 "iBGP-multipath\n"
2508 "Number of paths\n"
2509 "Match the cluster length\n")
2510 {
2511 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2512 }
2513
2514 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2515 "no maximum-paths ibgp [" CMD_RANGE_STR(
2516 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2517 NO_STR
2518 "Forward packets over multiple paths\n"
2519 "iBGP-multipath\n"
2520 "Number of paths\n"
2521 "Match the cluster length\n")
2522
2523 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2524 afi_t afi, safi_t safi)
2525 {
2526 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2527 vty_out(vty, " maximum-paths %d\n",
2528 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2529 }
2530
2531 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2532 vty_out(vty, " maximum-paths ibgp %d",
2533 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2534 if (bgp->maxpaths[afi][safi].same_clusterlen)
2535 vty_out(vty, " equal-cluster-length");
2536 vty_out(vty, "\n");
2537 }
2538 }
2539
2540 /* BGP timers. */
2541
2542 DEFUN (bgp_timers,
2543 bgp_timers_cmd,
2544 "timers bgp (0-65535) (0-65535)",
2545 "Adjust routing timers\n"
2546 "BGP timers\n"
2547 "Keepalive interval\n"
2548 "Holdtime\n")
2549 {
2550 VTY_DECLVAR_CONTEXT(bgp, bgp);
2551 int idx_number = 2;
2552 int idx_number_2 = 3;
2553 unsigned long keepalive = 0;
2554 unsigned long holdtime = 0;
2555
2556 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2557 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2558
2559 /* Holdtime value check. */
2560 if (holdtime < 3 && holdtime != 0) {
2561 vty_out(vty,
2562 "%% hold time value must be either 0 or greater than 3\n");
2563 return CMD_WARNING_CONFIG_FAILED;
2564 }
2565
2566 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2567 BGP_DEFAULT_DELAYOPEN);
2568
2569 return CMD_SUCCESS;
2570 }
2571
2572 DEFUN (no_bgp_timers,
2573 no_bgp_timers_cmd,
2574 "no timers bgp [(0-65535) (0-65535)]",
2575 NO_STR
2576 "Adjust routing timers\n"
2577 "BGP timers\n"
2578 "Keepalive interval\n"
2579 "Holdtime\n")
2580 {
2581 VTY_DECLVAR_CONTEXT(bgp, bgp);
2582 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2583 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2584
2585 return CMD_SUCCESS;
2586 }
2587
2588 /* BGP minimum holdtime. */
2589
2590 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2591 "bgp minimum-holdtime (1-65535)",
2592 "BGP specific commands\n"
2593 "BGP minimum holdtime\n"
2594 "Seconds\n")
2595 {
2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
2597 int idx_number = 2;
2598 unsigned long min_holdtime;
2599
2600 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2601
2602 bgp->default_min_holdtime = min_holdtime;
2603
2604 return CMD_SUCCESS;
2605 }
2606
2607 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2608 "no bgp minimum-holdtime [(1-65535)]",
2609 NO_STR
2610 "BGP specific commands\n"
2611 "BGP minimum holdtime\n"
2612 "Seconds\n")
2613 {
2614 VTY_DECLVAR_CONTEXT(bgp, bgp);
2615
2616 bgp->default_min_holdtime = 0;
2617
2618 return CMD_SUCCESS;
2619 }
2620
2621 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2622 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2623 BGP_STR
2624 "TCP keepalive parameters\n"
2625 "TCP keepalive idle time (seconds)\n"
2626 "TCP keepalive interval (seconds)\n"
2627 "TCP keepalive maximum probes\n")
2628 {
2629 VTY_DECLVAR_CONTEXT(bgp, bgp);
2630
2631 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2632 (uint16_t)probes);
2633
2634 return CMD_SUCCESS;
2635 }
2636
2637 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2638 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2639 NO_STR
2640 BGP_STR
2641 "TCP keepalive parameters\n"
2642 "TCP keepalive idle time (seconds)\n"
2643 "TCP keepalive interval (seconds)\n"
2644 "TCP keepalive maximum probes\n")
2645 {
2646 VTY_DECLVAR_CONTEXT(bgp, bgp);
2647
2648 bgp_tcp_keepalive_unset(bgp);
2649
2650 return CMD_SUCCESS;
2651 }
2652
2653 DEFUN (bgp_client_to_client_reflection,
2654 bgp_client_to_client_reflection_cmd,
2655 "bgp client-to-client reflection",
2656 BGP_STR
2657 "Configure client to client route reflection\n"
2658 "reflection of routes allowed\n")
2659 {
2660 VTY_DECLVAR_CONTEXT(bgp, bgp);
2661 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2662 bgp_clear_star_soft_out(vty, bgp->name);
2663
2664 return CMD_SUCCESS;
2665 }
2666
2667 DEFUN (no_bgp_client_to_client_reflection,
2668 no_bgp_client_to_client_reflection_cmd,
2669 "no bgp client-to-client reflection",
2670 NO_STR
2671 BGP_STR
2672 "Configure client to client route reflection\n"
2673 "reflection of routes allowed\n")
2674 {
2675 VTY_DECLVAR_CONTEXT(bgp, bgp);
2676 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2677 bgp_clear_star_soft_out(vty, bgp->name);
2678
2679 return CMD_SUCCESS;
2680 }
2681
2682 /* "bgp always-compare-med" configuration. */
2683 DEFUN (bgp_always_compare_med,
2684 bgp_always_compare_med_cmd,
2685 "bgp always-compare-med",
2686 BGP_STR
2687 "Allow comparing MED from different neighbors\n")
2688 {
2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
2690 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2691 bgp_recalculate_all_bestpaths(bgp);
2692
2693 return CMD_SUCCESS;
2694 }
2695
2696 DEFUN (no_bgp_always_compare_med,
2697 no_bgp_always_compare_med_cmd,
2698 "no bgp always-compare-med",
2699 NO_STR
2700 BGP_STR
2701 "Allow comparing MED from different neighbors\n")
2702 {
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2705 bgp_recalculate_all_bestpaths(bgp);
2706
2707 return CMD_SUCCESS;
2708 }
2709
2710
2711 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2712 "bgp ebgp-requires-policy",
2713 BGP_STR
2714 "Require in and out policy for eBGP peers (RFC8212)\n")
2715 {
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2718 return CMD_SUCCESS;
2719 }
2720
2721 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2722 "no bgp ebgp-requires-policy",
2723 NO_STR
2724 BGP_STR
2725 "Require in and out policy for eBGP peers (RFC8212)\n")
2726 {
2727 VTY_DECLVAR_CONTEXT(bgp, bgp);
2728 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2729 return CMD_SUCCESS;
2730 }
2731
2732 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2733 "bgp suppress-duplicates",
2734 BGP_STR
2735 "Suppress duplicate updates if the route actually not changed\n")
2736 {
2737 VTY_DECLVAR_CONTEXT(bgp, bgp);
2738 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2739 return CMD_SUCCESS;
2740 }
2741
2742 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2743 "no bgp suppress-duplicates",
2744 NO_STR
2745 BGP_STR
2746 "Suppress duplicate updates if the route actually not changed\n")
2747 {
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2750 return CMD_SUCCESS;
2751 }
2752
2753 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2754 "bgp reject-as-sets",
2755 BGP_STR
2756 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2757 {
2758 VTY_DECLVAR_CONTEXT(bgp, bgp);
2759 struct listnode *node, *nnode;
2760 struct peer *peer;
2761
2762 bgp->reject_as_sets = true;
2763
2764 /* Reset existing BGP sessions to reject routes
2765 * with aspath containing AS_SET or AS_CONFED_SET.
2766 */
2767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2768 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2769 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2770 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2771 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2772 }
2773 }
2774
2775 return CMD_SUCCESS;
2776 }
2777
2778 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2779 "no bgp reject-as-sets",
2780 NO_STR
2781 BGP_STR
2782 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2783 {
2784 VTY_DECLVAR_CONTEXT(bgp, bgp);
2785 struct listnode *node, *nnode;
2786 struct peer *peer;
2787
2788 bgp->reject_as_sets = false;
2789
2790 /* Reset existing BGP sessions to reject routes
2791 * with aspath containing AS_SET or AS_CONFED_SET.
2792 */
2793 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2794 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2795 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2796 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2797 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2798 }
2799 }
2800
2801 return CMD_SUCCESS;
2802 }
2803
2804 /* "bgp deterministic-med" configuration. */
2805 DEFUN (bgp_deterministic_med,
2806 bgp_deterministic_med_cmd,
2807 "bgp deterministic-med",
2808 BGP_STR
2809 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2810 {
2811 VTY_DECLVAR_CONTEXT(bgp, bgp);
2812
2813 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2814 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2815 bgp_recalculate_all_bestpaths(bgp);
2816 }
2817
2818 return CMD_SUCCESS;
2819 }
2820
2821 DEFUN (no_bgp_deterministic_med,
2822 no_bgp_deterministic_med_cmd,
2823 "no bgp deterministic-med",
2824 NO_STR
2825 BGP_STR
2826 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2827 {
2828 VTY_DECLVAR_CONTEXT(bgp, bgp);
2829 int bestpath_per_as_used;
2830 afi_t afi;
2831 safi_t safi;
2832 struct peer *peer;
2833 struct listnode *node, *nnode;
2834
2835 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2836 bestpath_per_as_used = 0;
2837
2838 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2839 FOREACH_AFI_SAFI (afi, safi)
2840 if (bgp_addpath_dmed_required(
2841 peer->addpath_type[afi][safi])) {
2842 bestpath_per_as_used = 1;
2843 break;
2844 }
2845
2846 if (bestpath_per_as_used)
2847 break;
2848 }
2849
2850 if (bestpath_per_as_used) {
2851 vty_out(vty,
2852 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2853 return CMD_WARNING_CONFIG_FAILED;
2854 } else {
2855 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2856 bgp_recalculate_all_bestpaths(bgp);
2857 }
2858 }
2859
2860 return CMD_SUCCESS;
2861 }
2862
2863 /* "bgp graceful-restart mode" configuration. */
2864 DEFUN (bgp_graceful_restart,
2865 bgp_graceful_restart_cmd,
2866 "bgp graceful-restart",
2867 BGP_STR
2868 GR_CMD
2869 )
2870 {
2871 int ret = BGP_GR_FAILURE;
2872
2873 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2874 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2875
2876 VTY_DECLVAR_CONTEXT(bgp, bgp);
2877
2878 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2879
2880 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2881 ret);
2882
2883 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2884 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2885 vty_out(vty,
2886 "Graceful restart configuration changed, reset all peers to take effect\n");
2887 return bgp_vty_return(vty, ret);
2888 }
2889
2890 DEFUN (no_bgp_graceful_restart,
2891 no_bgp_graceful_restart_cmd,
2892 "no bgp graceful-restart",
2893 NO_STR
2894 BGP_STR
2895 NO_GR_CMD
2896 )
2897 {
2898 VTY_DECLVAR_CONTEXT(bgp, bgp);
2899
2900 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2901 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2902
2903 int ret = BGP_GR_FAILURE;
2904
2905 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2906
2907 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2908 ret);
2909
2910 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2911 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2912 vty_out(vty,
2913 "Graceful restart configuration changed, reset all peers to take effect\n");
2914
2915 return bgp_vty_return(vty, ret);
2916 }
2917
2918 DEFUN (bgp_graceful_restart_stalepath_time,
2919 bgp_graceful_restart_stalepath_time_cmd,
2920 "bgp graceful-restart stalepath-time (1-4095)",
2921 BGP_STR
2922 "Graceful restart capability parameters\n"
2923 "Set the max time to hold onto restarting peer's stale paths\n"
2924 "Delay value (seconds)\n")
2925 {
2926 VTY_DECLVAR_CONTEXT(bgp, bgp);
2927 int idx_number = 3;
2928 uint32_t stalepath;
2929
2930 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2931 bgp->stalepath_time = stalepath;
2932 return CMD_SUCCESS;
2933 }
2934
2935 DEFUN (bgp_graceful_restart_restart_time,
2936 bgp_graceful_restart_restart_time_cmd,
2937 "bgp graceful-restart restart-time (0-4095)",
2938 BGP_STR
2939 "Graceful restart capability parameters\n"
2940 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2941 "Delay value (seconds)\n")
2942 {
2943 VTY_DECLVAR_CONTEXT(bgp, bgp);
2944 int idx_number = 3;
2945 uint32_t restart;
2946
2947 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2948 bgp->restart_time = restart;
2949 return CMD_SUCCESS;
2950 }
2951
2952 DEFUN (bgp_graceful_restart_select_defer_time,
2953 bgp_graceful_restart_select_defer_time_cmd,
2954 "bgp graceful-restart select-defer-time (0-3600)",
2955 BGP_STR
2956 "Graceful restart capability parameters\n"
2957 "Set the time to defer the BGP route selection after restart\n"
2958 "Delay value (seconds, 0 - disable)\n")
2959 {
2960 VTY_DECLVAR_CONTEXT(bgp, bgp);
2961 int idx_number = 3;
2962 uint32_t defer_time;
2963
2964 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2965 bgp->select_defer_time = defer_time;
2966 if (defer_time == 0)
2967 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2968 else
2969 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2970
2971 return CMD_SUCCESS;
2972 }
2973
2974 DEFUN (no_bgp_graceful_restart_stalepath_time,
2975 no_bgp_graceful_restart_stalepath_time_cmd,
2976 "no bgp graceful-restart stalepath-time [(1-4095)]",
2977 NO_STR
2978 BGP_STR
2979 "Graceful restart capability parameters\n"
2980 "Set the max time to hold onto restarting peer's stale paths\n"
2981 "Delay value (seconds)\n")
2982 {
2983 VTY_DECLVAR_CONTEXT(bgp, bgp);
2984
2985 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2986 return CMD_SUCCESS;
2987 }
2988
2989 DEFUN (no_bgp_graceful_restart_restart_time,
2990 no_bgp_graceful_restart_restart_time_cmd,
2991 "no bgp graceful-restart restart-time [(0-4095)]",
2992 NO_STR
2993 BGP_STR
2994 "Graceful restart capability parameters\n"
2995 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2996 "Delay value (seconds)\n")
2997 {
2998 VTY_DECLVAR_CONTEXT(bgp, bgp);
2999
3000 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3001 return CMD_SUCCESS;
3002 }
3003
3004 DEFUN (no_bgp_graceful_restart_select_defer_time,
3005 no_bgp_graceful_restart_select_defer_time_cmd,
3006 "no bgp graceful-restart select-defer-time [(0-3600)]",
3007 NO_STR
3008 BGP_STR
3009 "Graceful restart capability parameters\n"
3010 "Set the time to defer the BGP route selection after restart\n"
3011 "Delay value (seconds)\n")
3012 {
3013 VTY_DECLVAR_CONTEXT(bgp, bgp);
3014
3015 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3016 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3017
3018 return CMD_SUCCESS;
3019 }
3020
3021 DEFUN (bgp_graceful_restart_preserve_fw,
3022 bgp_graceful_restart_preserve_fw_cmd,
3023 "bgp graceful-restart preserve-fw-state",
3024 BGP_STR
3025 "Graceful restart capability parameters\n"
3026 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3027 {
3028 VTY_DECLVAR_CONTEXT(bgp, bgp);
3029 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3030 return CMD_SUCCESS;
3031 }
3032
3033 DEFUN (no_bgp_graceful_restart_preserve_fw,
3034 no_bgp_graceful_restart_preserve_fw_cmd,
3035 "no bgp graceful-restart preserve-fw-state",
3036 NO_STR
3037 BGP_STR
3038 "Graceful restart capability parameters\n"
3039 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3040 {
3041 VTY_DECLVAR_CONTEXT(bgp, bgp);
3042 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3043 return CMD_SUCCESS;
3044 }
3045
3046 DEFPY (bgp_graceful_restart_notification,
3047 bgp_graceful_restart_notification_cmd,
3048 "[no$no] bgp graceful-restart notification",
3049 NO_STR
3050 BGP_STR
3051 "Graceful restart capability parameters\n"
3052 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3053 {
3054 VTY_DECLVAR_CONTEXT(bgp, bgp);
3055
3056 if (no)
3057 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3058 else
3059 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3060
3061 return CMD_SUCCESS;
3062 }
3063
3064 DEFPY (bgp_administrative_reset,
3065 bgp_administrative_reset_cmd,
3066 "[no$no] bgp hard-administrative-reset",
3067 NO_STR
3068 BGP_STR
3069 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3070 {
3071 VTY_DECLVAR_CONTEXT(bgp, bgp);
3072
3073 if (no)
3074 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3075 else
3076 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3077
3078 return CMD_SUCCESS;
3079 }
3080
3081 DEFUN (bgp_graceful_restart_disable,
3082 bgp_graceful_restart_disable_cmd,
3083 "bgp graceful-restart-disable",
3084 BGP_STR
3085 GR_DISABLE)
3086 {
3087 int ret = BGP_GR_FAILURE;
3088
3089 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3090 zlog_debug(
3091 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3092
3093 VTY_DECLVAR_CONTEXT(bgp, bgp);
3094
3095 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3096
3097 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3098 bgp->peer, ret);
3099
3100 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3101 zlog_debug(
3102 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3103 vty_out(vty,
3104 "Graceful restart configuration changed, reset all peers to take effect\n");
3105
3106 return bgp_vty_return(vty, ret);
3107 }
3108
3109 DEFUN (no_bgp_graceful_restart_disable,
3110 no_bgp_graceful_restart_disable_cmd,
3111 "no bgp graceful-restart-disable",
3112 NO_STR
3113 BGP_STR
3114 NO_GR_DISABLE
3115 )
3116 {
3117 VTY_DECLVAR_CONTEXT(bgp, bgp);
3118
3119 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3120 zlog_debug(
3121 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3122
3123 int ret = BGP_GR_FAILURE;
3124
3125 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3126
3127 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3128 ret);
3129
3130 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3131 zlog_debug(
3132 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3133 vty_out(vty,
3134 "Graceful restart configuration changed, reset all peers to take effect\n");
3135
3136 return bgp_vty_return(vty, ret);
3137 }
3138
3139 DEFUN (bgp_neighbor_graceful_restart_set,
3140 bgp_neighbor_graceful_restart_set_cmd,
3141 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3142 NEIGHBOR_STR
3143 NEIGHBOR_ADDR_STR2
3144 GR_NEIGHBOR_CMD
3145 )
3146 {
3147 int idx_peer = 1;
3148 struct peer *peer;
3149 int ret = BGP_GR_FAILURE;
3150
3151 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3152
3153 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3154 zlog_debug(
3155 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3156
3157 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3158 if (!peer)
3159 return CMD_WARNING_CONFIG_FAILED;
3160
3161 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3162
3163 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3164 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3165
3166 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3167 zlog_debug(
3168 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3169 vty_out(vty,
3170 "Graceful restart configuration changed, reset this peer to take effect\n");
3171
3172 return bgp_vty_return(vty, ret);
3173 }
3174
3175 DEFUN (no_bgp_neighbor_graceful_restart,
3176 no_bgp_neighbor_graceful_restart_set_cmd,
3177 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3178 NO_STR
3179 NEIGHBOR_STR
3180 NEIGHBOR_ADDR_STR2
3181 NO_GR_NEIGHBOR_CMD
3182 )
3183 {
3184 int idx_peer = 2;
3185 int ret = BGP_GR_FAILURE;
3186 struct peer *peer;
3187
3188 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3189
3190 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3191 if (!peer)
3192 return CMD_WARNING_CONFIG_FAILED;
3193
3194 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3195 zlog_debug(
3196 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3197
3198 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3199
3200 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3201 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3202
3203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3204 zlog_debug(
3205 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3206 vty_out(vty,
3207 "Graceful restart configuration changed, reset this peer to take effect\n");
3208
3209 return bgp_vty_return(vty, ret);
3210 }
3211
3212 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3213 bgp_neighbor_graceful_restart_helper_set_cmd,
3214 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
3217 GR_NEIGHBOR_HELPER_CMD
3218 )
3219 {
3220 int idx_peer = 1;
3221 struct peer *peer;
3222 int ret = BGP_GR_FAILURE;
3223
3224 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3225
3226 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3227 zlog_debug(
3228 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3229
3230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3231
3232 if (!peer)
3233 return CMD_WARNING_CONFIG_FAILED;
3234
3235
3236 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3237
3238 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3239 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3240
3241 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3242 zlog_debug(
3243 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3244 vty_out(vty,
3245 "Graceful restart configuration changed, reset this peer to take effect\n");
3246
3247 return bgp_vty_return(vty, ret);
3248 }
3249
3250 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3251 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3252 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3253 NO_STR
3254 NEIGHBOR_STR
3255 NEIGHBOR_ADDR_STR2
3256 NO_GR_NEIGHBOR_HELPER_CMD
3257 )
3258 {
3259 int idx_peer = 2;
3260 int ret = BGP_GR_FAILURE;
3261 struct peer *peer;
3262
3263 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3264
3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3268
3269 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3270 zlog_debug(
3271 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3272
3273 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3274
3275 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3276 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3277
3278 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3279 zlog_debug(
3280 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3281 vty_out(vty,
3282 "Graceful restart configuration changed, reset this peer to take effect\n");
3283
3284 return bgp_vty_return(vty, ret);
3285 }
3286
3287 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3288 bgp_neighbor_graceful_restart_disable_set_cmd,
3289 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3290 NEIGHBOR_STR
3291 NEIGHBOR_ADDR_STR2
3292 GR_NEIGHBOR_DISABLE_CMD
3293 )
3294 {
3295 int idx_peer = 1;
3296 struct peer *peer;
3297 int ret = BGP_GR_FAILURE;
3298
3299 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3300
3301 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3302 zlog_debug(
3303 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3304
3305 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3306 if (!peer)
3307 return CMD_WARNING_CONFIG_FAILED;
3308
3309 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3310
3311 if (peer->bgp->t_startup)
3312 bgp_peer_gr_flags_update(peer);
3313
3314 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3315 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3316
3317 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3318 zlog_debug(
3319 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3320 vty_out(vty,
3321 "Graceful restart configuration changed, reset this peer to take effect\n");
3322
3323 return bgp_vty_return(vty, ret);
3324 }
3325
3326 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3327 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3328 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3329 NO_STR
3330 NEIGHBOR_STR
3331 NEIGHBOR_ADDR_STR2
3332 NO_GR_NEIGHBOR_DISABLE_CMD
3333 )
3334 {
3335 int idx_peer = 2;
3336 int ret = BGP_GR_FAILURE;
3337 struct peer *peer;
3338
3339 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3340
3341 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3342 if (!peer)
3343 return CMD_WARNING_CONFIG_FAILED;
3344
3345 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3346 zlog_debug(
3347 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3348
3349 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3350
3351 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3352 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3353
3354 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3355 zlog_debug(
3356 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3357 vty_out(vty,
3358 "Graceful restart configuration changed, reset this peer to take effect\n");
3359
3360 return bgp_vty_return(vty, ret);
3361 }
3362
3363 DEFPY (neighbor_graceful_shutdown,
3364 neighbor_graceful_shutdown_cmd,
3365 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3366 NO_STR
3367 NEIGHBOR_STR
3368 NEIGHBOR_ADDR_STR2
3369 "Graceful shutdown\n")
3370 {
3371 afi_t afi;
3372 safi_t safi;
3373 struct peer *peer;
3374 VTY_DECLVAR_CONTEXT(bgp, bgp);
3375 int ret;
3376
3377 peer = peer_and_group_lookup_vty(vty, neighbor);
3378 if (!peer)
3379 return CMD_WARNING_CONFIG_FAILED;
3380
3381 if (no)
3382 ret = peer_flag_unset_vty(vty, neighbor,
3383 PEER_FLAG_GRACEFUL_SHUTDOWN);
3384 else
3385 ret = peer_flag_set_vty(vty, neighbor,
3386 PEER_FLAG_GRACEFUL_SHUTDOWN);
3387
3388 FOREACH_AFI_SAFI (afi, safi) {
3389 if (!peer->afc[afi][safi])
3390 continue;
3391
3392 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3393 neighbor);
3394 }
3395
3396 return ret;
3397 }
3398
3399 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3400 bgp_graceful_restart_disable_eor_cmd,
3401 "bgp graceful-restart disable-eor",
3402 BGP_STR
3403 "Graceful restart configuration parameters\n"
3404 "Disable EOR Check\n")
3405 {
3406 VTY_DECLVAR_CONTEXT(bgp, bgp);
3407 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3408
3409 return CMD_SUCCESS;
3410 }
3411
3412 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3413 no_bgp_graceful_restart_disable_eor_cmd,
3414 "no bgp graceful-restart disable-eor",
3415 NO_STR
3416 BGP_STR
3417 "Graceful restart configuration parameters\n"
3418 "Disable EOR Check\n")
3419 {
3420 VTY_DECLVAR_CONTEXT(bgp, bgp);
3421 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3422
3423 return CMD_SUCCESS;
3424 }
3425
3426 DEFUN (bgp_graceful_restart_rib_stale_time,
3427 bgp_graceful_restart_rib_stale_time_cmd,
3428 "bgp graceful-restart rib-stale-time (1-3600)",
3429 BGP_STR
3430 "Graceful restart configuration parameters\n"
3431 "Specify the stale route removal timer in rib\n"
3432 "Delay value (seconds)\n")
3433 {
3434 VTY_DECLVAR_CONTEXT(bgp, bgp);
3435 int idx_number = 3;
3436 uint32_t stale_time;
3437
3438 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3439 bgp->rib_stale_time = stale_time;
3440 /* Send the stale timer update message to RIB */
3441 if (bgp_zebra_stale_timer_update(bgp))
3442 return CMD_WARNING;
3443
3444 return CMD_SUCCESS;
3445 }
3446
3447 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3448 no_bgp_graceful_restart_rib_stale_time_cmd,
3449 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3450 NO_STR
3451 BGP_STR
3452 "Graceful restart configuration parameters\n"
3453 "Specify the stale route removal timer in rib\n"
3454 "Delay value (seconds)\n")
3455 {
3456 VTY_DECLVAR_CONTEXT(bgp, bgp);
3457
3458 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3459 /* Send the stale timer update message to RIB */
3460 if (bgp_zebra_stale_timer_update(bgp))
3461 return CMD_WARNING;
3462
3463 return CMD_SUCCESS;
3464 }
3465
3466 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3467 "bgp long-lived-graceful-restart stale-time (1-16777215)",
3468 BGP_STR
3469 "Enable Long-lived Graceful Restart\n"
3470 "Specifies maximum time to wait before purging long-lived stale routes\n"
3471 "Stale time value (seconds)\n")
3472 {
3473 VTY_DECLVAR_CONTEXT(bgp, bgp);
3474
3475 uint32_t llgr_stale_time;
3476
3477 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3478 bgp->llgr_stale_time = llgr_stale_time;
3479
3480 return CMD_SUCCESS;
3481 }
3482
3483 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3484 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3485 NO_STR BGP_STR
3486 "Enable Long-lived Graceful Restart\n"
3487 "Specifies maximum time to wait before purging long-lived stale routes\n"
3488 "Stale time value (seconds)\n")
3489 {
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491
3492 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3493
3494 return CMD_SUCCESS;
3495 }
3496
3497 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3498 struct bgp *bgp)
3499 {
3500 bgp_static_redo_import_check(bgp);
3501 bgp_redistribute_redo(bgp);
3502 bgp_clear_star_soft_out(vty, bgp->name);
3503 bgp_clear_star_soft_in(vty, bgp->name);
3504 }
3505
3506 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3507 {
3508 struct listnode *node, *nnode;
3509 struct bgp *bgp;
3510 bool vrf_cfg = false;
3511
3512 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3513 return CMD_SUCCESS;
3514
3515 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3516 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3517 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3518 vty_out(vty,
3519 "%% graceful-shutdown configuration found in vrf %s\n",
3520 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3521 VRF_DEFAULT_NAME : bgp->name);
3522 vrf_cfg = true;
3523 }
3524 }
3525
3526 if (vrf_cfg) {
3527 vty_out(vty,
3528 "%%Failed: global graceful-shutdown not permitted\n");
3529 return CMD_WARNING;
3530 }
3531
3532 /* Set flag globally */
3533 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3534
3535 /* Initiate processing for all BGP instances. */
3536 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3537 bgp_initiate_graceful_shut_unshut(vty, bgp);
3538
3539 return CMD_SUCCESS;
3540 }
3541
3542 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3543 {
3544 struct listnode *node, *nnode;
3545 struct bgp *bgp;
3546
3547 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3548 return CMD_SUCCESS;
3549
3550 /* Unset flag globally */
3551 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3552
3553 /* Initiate processing for all BGP instances. */
3554 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3555 bgp_initiate_graceful_shut_unshut(vty, bgp);
3556
3557 return CMD_SUCCESS;
3558 }
3559
3560 /* "bgp graceful-shutdown" configuration */
3561 DEFUN (bgp_graceful_shutdown,
3562 bgp_graceful_shutdown_cmd,
3563 "bgp graceful-shutdown",
3564 BGP_STR
3565 "Graceful shutdown parameters\n")
3566 {
3567 if (vty->node == CONFIG_NODE)
3568 return bgp_global_graceful_shutdown_config_vty(vty);
3569
3570 VTY_DECLVAR_CONTEXT(bgp, bgp);
3571
3572 /* if configured globally, per-instance config is not allowed */
3573 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3574 vty_out(vty,
3575 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3576 return CMD_WARNING_CONFIG_FAILED;
3577 }
3578
3579 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3580 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3581 bgp_initiate_graceful_shut_unshut(vty, bgp);
3582 }
3583
3584 return CMD_SUCCESS;
3585 }
3586
3587 DEFUN (no_bgp_graceful_shutdown,
3588 no_bgp_graceful_shutdown_cmd,
3589 "no bgp graceful-shutdown",
3590 NO_STR
3591 BGP_STR
3592 "Graceful shutdown parameters\n")
3593 {
3594 if (vty->node == CONFIG_NODE)
3595 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3596
3597 VTY_DECLVAR_CONTEXT(bgp, bgp);
3598
3599 /* If configured globally, cannot remove from one bgp instance */
3600 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3601 vty_out(vty,
3602 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3603 return CMD_WARNING_CONFIG_FAILED;
3604 }
3605
3606 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3607 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3608 bgp_initiate_graceful_shut_unshut(vty, bgp);
3609 }
3610
3611 return CMD_SUCCESS;
3612 }
3613
3614 /* "bgp fast-external-failover" configuration. */
3615 DEFUN (bgp_fast_external_failover,
3616 bgp_fast_external_failover_cmd,
3617 "bgp fast-external-failover",
3618 BGP_STR
3619 "Immediately reset session if a link to a directly connected external peer goes down\n")
3620 {
3621 VTY_DECLVAR_CONTEXT(bgp, bgp);
3622 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3623 return CMD_SUCCESS;
3624 }
3625
3626 DEFUN (no_bgp_fast_external_failover,
3627 no_bgp_fast_external_failover_cmd,
3628 "no bgp fast-external-failover",
3629 NO_STR
3630 BGP_STR
3631 "Immediately reset session if a link to a directly connected external peer goes down\n")
3632 {
3633 VTY_DECLVAR_CONTEXT(bgp, bgp);
3634 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3635 return CMD_SUCCESS;
3636 }
3637
3638 DEFPY (bgp_bestpath_aigp,
3639 bgp_bestpath_aigp_cmd,
3640 "[no$no] bgp bestpath aigp",
3641 NO_STR
3642 BGP_STR
3643 "Change the default bestpath selection\n"
3644 "Evaluate the AIGP attribute during the best path selection process\n")
3645 {
3646 VTY_DECLVAR_CONTEXT(bgp, bgp);
3647
3648 if (no)
3649 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3650 else
3651 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3652
3653 bgp_recalculate_all_bestpaths(bgp);
3654
3655 return CMD_SUCCESS;
3656 }
3657
3658 /* "bgp bestpath compare-routerid" configuration. */
3659 DEFUN (bgp_bestpath_compare_router_id,
3660 bgp_bestpath_compare_router_id_cmd,
3661 "bgp bestpath compare-routerid",
3662 BGP_STR
3663 "Change the default bestpath selection\n"
3664 "Compare router-id for identical EBGP paths\n")
3665 {
3666 VTY_DECLVAR_CONTEXT(bgp, bgp);
3667 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3668 bgp_recalculate_all_bestpaths(bgp);
3669
3670 return CMD_SUCCESS;
3671 }
3672
3673 DEFUN (no_bgp_bestpath_compare_router_id,
3674 no_bgp_bestpath_compare_router_id_cmd,
3675 "no bgp bestpath compare-routerid",
3676 NO_STR
3677 BGP_STR
3678 "Change the default bestpath selection\n"
3679 "Compare router-id for identical EBGP paths\n")
3680 {
3681 VTY_DECLVAR_CONTEXT(bgp, bgp);
3682 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3683 bgp_recalculate_all_bestpaths(bgp);
3684
3685 return CMD_SUCCESS;
3686 }
3687
3688 /* "bgp bestpath as-path ignore" configuration. */
3689 DEFUN (bgp_bestpath_aspath_ignore,
3690 bgp_bestpath_aspath_ignore_cmd,
3691 "bgp bestpath as-path ignore",
3692 BGP_STR
3693 "Change the default bestpath selection\n"
3694 "AS-path attribute\n"
3695 "Ignore as-path length in selecting a route\n")
3696 {
3697 VTY_DECLVAR_CONTEXT(bgp, bgp);
3698 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3699 bgp_recalculate_all_bestpaths(bgp);
3700
3701 return CMD_SUCCESS;
3702 }
3703
3704 DEFUN (no_bgp_bestpath_aspath_ignore,
3705 no_bgp_bestpath_aspath_ignore_cmd,
3706 "no bgp bestpath as-path ignore",
3707 NO_STR
3708 BGP_STR
3709 "Change the default bestpath selection\n"
3710 "AS-path attribute\n"
3711 "Ignore as-path length in selecting a route\n")
3712 {
3713 VTY_DECLVAR_CONTEXT(bgp, bgp);
3714 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3715 bgp_recalculate_all_bestpaths(bgp);
3716
3717 return CMD_SUCCESS;
3718 }
3719
3720 /* "bgp bestpath as-path confed" configuration. */
3721 DEFUN (bgp_bestpath_aspath_confed,
3722 bgp_bestpath_aspath_confed_cmd,
3723 "bgp bestpath as-path confed",
3724 BGP_STR
3725 "Change the default bestpath selection\n"
3726 "AS-path attribute\n"
3727 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3728 {
3729 VTY_DECLVAR_CONTEXT(bgp, bgp);
3730 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3731 bgp_recalculate_all_bestpaths(bgp);
3732
3733 return CMD_SUCCESS;
3734 }
3735
3736 DEFUN (no_bgp_bestpath_aspath_confed,
3737 no_bgp_bestpath_aspath_confed_cmd,
3738 "no bgp bestpath as-path confed",
3739 NO_STR
3740 BGP_STR
3741 "Change the default bestpath selection\n"
3742 "AS-path attribute\n"
3743 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3744 {
3745 VTY_DECLVAR_CONTEXT(bgp, bgp);
3746 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3747 bgp_recalculate_all_bestpaths(bgp);
3748
3749 return CMD_SUCCESS;
3750 }
3751
3752 /* "bgp bestpath as-path multipath-relax" configuration. */
3753 DEFUN (bgp_bestpath_aspath_multipath_relax,
3754 bgp_bestpath_aspath_multipath_relax_cmd,
3755 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3756 BGP_STR
3757 "Change the default bestpath selection\n"
3758 "AS-path attribute\n"
3759 "Allow load sharing across routes that have different AS paths (but same length)\n"
3760 "Generate an AS_SET\n"
3761 "Do not generate an AS_SET\n")
3762 {
3763 VTY_DECLVAR_CONTEXT(bgp, bgp);
3764 int idx = 0;
3765 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3766
3767 /* no-as-set is now the default behavior so we can silently
3768 * ignore it */
3769 if (argv_find(argv, argc, "as-set", &idx))
3770 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3771 else
3772 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3773
3774 bgp_recalculate_all_bestpaths(bgp);
3775
3776 return CMD_SUCCESS;
3777 }
3778
3779 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3780 no_bgp_bestpath_aspath_multipath_relax_cmd,
3781 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3782 NO_STR
3783 BGP_STR
3784 "Change the default bestpath selection\n"
3785 "AS-path attribute\n"
3786 "Allow load sharing across routes that have different AS paths (but same length)\n"
3787 "Generate an AS_SET\n"
3788 "Do not generate an AS_SET\n")
3789 {
3790 VTY_DECLVAR_CONTEXT(bgp, bgp);
3791 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3792 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3793 bgp_recalculate_all_bestpaths(bgp);
3794
3795 return CMD_SUCCESS;
3796 }
3797
3798 /* "bgp bestpath peer-type multipath-relax" configuration. */
3799 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3800 bgp_bestpath_peer_type_multipath_relax_cmd,
3801 "bgp bestpath peer-type multipath-relax",
3802 BGP_STR
3803 "Change the default bestpath selection\n"
3804 "Peer type\n"
3805 "Allow load sharing across routes learned from different peer types\n")
3806 {
3807 VTY_DECLVAR_CONTEXT(bgp, bgp);
3808 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3809 bgp_recalculate_all_bestpaths(bgp);
3810
3811 return CMD_SUCCESS;
3812 }
3813
3814 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3815 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3816 "no bgp bestpath peer-type multipath-relax",
3817 NO_STR BGP_STR
3818 "Change the default bestpath selection\n"
3819 "Peer type\n"
3820 "Allow load sharing across routes learned from different peer types\n")
3821 {
3822 VTY_DECLVAR_CONTEXT(bgp, bgp);
3823 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3824 bgp_recalculate_all_bestpaths(bgp);
3825
3826 return CMD_SUCCESS;
3827 }
3828
3829 /* "bgp log-neighbor-changes" configuration. */
3830 DEFUN (bgp_log_neighbor_changes,
3831 bgp_log_neighbor_changes_cmd,
3832 "bgp log-neighbor-changes",
3833 BGP_STR
3834 "Log neighbor up/down and reset reason\n")
3835 {
3836 VTY_DECLVAR_CONTEXT(bgp, bgp);
3837 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3838 return CMD_SUCCESS;
3839 }
3840
3841 DEFUN (no_bgp_log_neighbor_changes,
3842 no_bgp_log_neighbor_changes_cmd,
3843 "no bgp log-neighbor-changes",
3844 NO_STR
3845 BGP_STR
3846 "Log neighbor up/down and reset reason\n")
3847 {
3848 VTY_DECLVAR_CONTEXT(bgp, bgp);
3849 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3850 return CMD_SUCCESS;
3851 }
3852
3853 /* "bgp bestpath med" configuration. */
3854 DEFUN (bgp_bestpath_med,
3855 bgp_bestpath_med_cmd,
3856 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3857 BGP_STR
3858 "Change the default bestpath selection\n"
3859 "MED attribute\n"
3860 "Compare MED among confederation paths\n"
3861 "Treat missing MED as the least preferred one\n"
3862 "Treat missing MED as the least preferred one\n"
3863 "Compare MED among confederation paths\n")
3864 {
3865 VTY_DECLVAR_CONTEXT(bgp, bgp);
3866
3867 int idx = 0;
3868 if (argv_find(argv, argc, "confed", &idx))
3869 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3870 idx = 0;
3871 if (argv_find(argv, argc, "missing-as-worst", &idx))
3872 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3873
3874 bgp_recalculate_all_bestpaths(bgp);
3875
3876 return CMD_SUCCESS;
3877 }
3878
3879 DEFUN (no_bgp_bestpath_med,
3880 no_bgp_bestpath_med_cmd,
3881 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3882 NO_STR
3883 BGP_STR
3884 "Change the default bestpath selection\n"
3885 "MED attribute\n"
3886 "Compare MED among confederation paths\n"
3887 "Treat missing MED as the least preferred one\n"
3888 "Treat missing MED as the least preferred one\n"
3889 "Compare MED among confederation paths\n")
3890 {
3891 VTY_DECLVAR_CONTEXT(bgp, bgp);
3892
3893 int idx = 0;
3894 if (argv_find(argv, argc, "confed", &idx))
3895 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3896 idx = 0;
3897 if (argv_find(argv, argc, "missing-as-worst", &idx))
3898 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3899
3900 bgp_recalculate_all_bestpaths(bgp);
3901
3902 return CMD_SUCCESS;
3903 }
3904
3905 /* "bgp bestpath bandwidth" configuration. */
3906 DEFPY (bgp_bestpath_bw,
3907 bgp_bestpath_bw_cmd,
3908 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3909 BGP_STR
3910 "Change the default bestpath selection\n"
3911 "Link Bandwidth attribute\n"
3912 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3913 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3914 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3915 {
3916 VTY_DECLVAR_CONTEXT(bgp, bgp);
3917 afi_t afi;
3918 safi_t safi;
3919
3920 if (!bw_cfg) {
3921 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3922 return CMD_ERR_INCOMPLETE;
3923 }
3924 if (!strcmp(bw_cfg, "ignore"))
3925 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3926 else if (!strcmp(bw_cfg, "skip-missing"))
3927 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3928 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3929 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3930 else
3931 return CMD_ERR_NO_MATCH;
3932
3933 /* This config is used in route install, so redo that. */
3934 FOREACH_AFI_SAFI (afi, safi) {
3935 if (!bgp_fibupd_safi(safi))
3936 continue;
3937 bgp_zebra_announce_table(bgp, afi, safi);
3938 }
3939
3940 return CMD_SUCCESS;
3941 }
3942
3943 DEFPY (no_bgp_bestpath_bw,
3944 no_bgp_bestpath_bw_cmd,
3945 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3946 NO_STR
3947 BGP_STR
3948 "Change the default bestpath selection\n"
3949 "Link Bandwidth attribute\n"
3950 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3951 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3952 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3953 {
3954 VTY_DECLVAR_CONTEXT(bgp, bgp);
3955 afi_t afi;
3956 safi_t safi;
3957
3958 bgp->lb_handling = BGP_LINK_BW_ECMP;
3959
3960 /* This config is used in route install, so redo that. */
3961 FOREACH_AFI_SAFI (afi, safi) {
3962 if (!bgp_fibupd_safi(safi))
3963 continue;
3964 bgp_zebra_announce_table(bgp, afi, safi);
3965 }
3966 return CMD_SUCCESS;
3967 }
3968
3969 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3970 "[no] bgp default <ipv4-unicast|"
3971 "ipv4-multicast|"
3972 "ipv4-vpn|"
3973 "ipv4-labeled-unicast|"
3974 "ipv4-flowspec|"
3975 "ipv6-unicast|"
3976 "ipv6-multicast|"
3977 "ipv6-vpn|"
3978 "ipv6-labeled-unicast|"
3979 "ipv6-flowspec|"
3980 "l2vpn-evpn>$afi_safi",
3981 NO_STR
3982 BGP_STR
3983 "Configure BGP defaults\n"
3984 "Activate ipv4-unicast for a peer by default\n"
3985 "Activate ipv4-multicast for a peer by default\n"
3986 "Activate ipv4-vpn for a peer by default\n"
3987 "Activate ipv4-labeled-unicast for a peer by default\n"
3988 "Activate ipv4-flowspec for a peer by default\n"
3989 "Activate ipv6-unicast for a peer by default\n"
3990 "Activate ipv6-multicast for a peer by default\n"
3991 "Activate ipv6-vpn for a peer by default\n"
3992 "Activate ipv6-labeled-unicast for a peer by default\n"
3993 "Activate ipv6-flowspec for a peer by default\n"
3994 "Activate l2vpn-evpn for a peer by default\n")
3995 {
3996 VTY_DECLVAR_CONTEXT(bgp, bgp);
3997 char afi_safi_str[strlen(afi_safi) + 1];
3998 char *afi_safi_str_tok;
3999
4000 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4001 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4002 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4003 afi_t afi = bgp_vty_afi_from_str(afi_str);
4004 safi_t safi;
4005
4006 /*
4007 * Impossible situation but making coverity happy
4008 */
4009 assert(afi != AFI_MAX);
4010
4011 if (strmatch(safi_str, "labeled"))
4012 safi = bgp_vty_safi_from_str("labeled-unicast");
4013 else
4014 safi = bgp_vty_safi_from_str(safi_str);
4015
4016 assert(safi != SAFI_MAX);
4017 if (no)
4018 bgp->default_af[afi][safi] = false;
4019 else {
4020 if ((safi == SAFI_LABELED_UNICAST
4021 && bgp->default_af[afi][SAFI_UNICAST])
4022 || (safi == SAFI_UNICAST
4023 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4024 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4025 else
4026 bgp->default_af[afi][safi] = true;
4027 }
4028
4029 return CMD_SUCCESS;
4030 }
4031
4032 /* Display hostname in certain command outputs */
4033 DEFUN (bgp_default_show_hostname,
4034 bgp_default_show_hostname_cmd,
4035 "bgp default show-hostname",
4036 BGP_STR
4037 "Configure BGP defaults\n"
4038 "Show hostname in certain command outputs\n")
4039 {
4040 VTY_DECLVAR_CONTEXT(bgp, bgp);
4041 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4042 return CMD_SUCCESS;
4043 }
4044
4045 DEFUN (no_bgp_default_show_hostname,
4046 no_bgp_default_show_hostname_cmd,
4047 "no bgp default show-hostname",
4048 NO_STR
4049 BGP_STR
4050 "Configure BGP defaults\n"
4051 "Show hostname in certain command outputs\n")
4052 {
4053 VTY_DECLVAR_CONTEXT(bgp, bgp);
4054 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4055 return CMD_SUCCESS;
4056 }
4057
4058 /* Display hostname in certain command outputs */
4059 DEFUN (bgp_default_show_nexthop_hostname,
4060 bgp_default_show_nexthop_hostname_cmd,
4061 "bgp default show-nexthop-hostname",
4062 BGP_STR
4063 "Configure BGP defaults\n"
4064 "Show hostname for nexthop in certain command outputs\n")
4065 {
4066 VTY_DECLVAR_CONTEXT(bgp, bgp);
4067 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4068 return CMD_SUCCESS;
4069 }
4070
4071 DEFUN (no_bgp_default_show_nexthop_hostname,
4072 no_bgp_default_show_nexthop_hostname_cmd,
4073 "no bgp default show-nexthop-hostname",
4074 NO_STR
4075 BGP_STR
4076 "Configure BGP defaults\n"
4077 "Show hostname for nexthop in certain command outputs\n")
4078 {
4079 VTY_DECLVAR_CONTEXT(bgp, bgp);
4080 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4081 return CMD_SUCCESS;
4082 }
4083
4084 /* "bgp network import-check" configuration. */
4085 DEFUN (bgp_network_import_check,
4086 bgp_network_import_check_cmd,
4087 "bgp network import-check",
4088 BGP_STR
4089 "BGP network command\n"
4090 "Check BGP network route exists in IGP\n")
4091 {
4092 VTY_DECLVAR_CONTEXT(bgp, bgp);
4093 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4094 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4095 bgp_static_redo_import_check(bgp);
4096 }
4097
4098 return CMD_SUCCESS;
4099 }
4100
4101 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4102 "bgp network import-check exact",
4103 BGP_STR
4104 "BGP network command\n"
4105 "Check BGP network route exists in IGP\n"
4106 "Match route precisely\n")
4107
4108 DEFUN (no_bgp_network_import_check,
4109 no_bgp_network_import_check_cmd,
4110 "no bgp network import-check",
4111 NO_STR
4112 BGP_STR
4113 "BGP network command\n"
4114 "Check BGP network route exists in IGP\n")
4115 {
4116 VTY_DECLVAR_CONTEXT(bgp, bgp);
4117 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4118 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4119 bgp_static_redo_import_check(bgp);
4120 }
4121
4122 return CMD_SUCCESS;
4123 }
4124
4125 DEFUN (bgp_default_local_preference,
4126 bgp_default_local_preference_cmd,
4127 "bgp default local-preference (0-4294967295)",
4128 BGP_STR
4129 "Configure BGP defaults\n"
4130 "local preference (higher=more preferred)\n"
4131 "Configure default local preference value\n")
4132 {
4133 VTY_DECLVAR_CONTEXT(bgp, bgp);
4134 int idx_number = 3;
4135 uint32_t local_pref;
4136
4137 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4138
4139 bgp_default_local_preference_set(bgp, local_pref);
4140 bgp_clear_star_soft_in(vty, bgp->name);
4141
4142 return CMD_SUCCESS;
4143 }
4144
4145 DEFUN (no_bgp_default_local_preference,
4146 no_bgp_default_local_preference_cmd,
4147 "no bgp default local-preference [(0-4294967295)]",
4148 NO_STR
4149 BGP_STR
4150 "Configure BGP defaults\n"
4151 "local preference (higher=more preferred)\n"
4152 "Configure default local preference value\n")
4153 {
4154 VTY_DECLVAR_CONTEXT(bgp, bgp);
4155 bgp_default_local_preference_unset(bgp);
4156 bgp_clear_star_soft_in(vty, bgp->name);
4157
4158 return CMD_SUCCESS;
4159 }
4160
4161
4162 DEFUN (bgp_default_subgroup_pkt_queue_max,
4163 bgp_default_subgroup_pkt_queue_max_cmd,
4164 "bgp default subgroup-pkt-queue-max (20-100)",
4165 BGP_STR
4166 "Configure BGP defaults\n"
4167 "subgroup-pkt-queue-max\n"
4168 "Configure subgroup packet queue max\n")
4169 {
4170 VTY_DECLVAR_CONTEXT(bgp, bgp);
4171 int idx_number = 3;
4172 uint32_t max_size;
4173
4174 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4175
4176 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4177
4178 return CMD_SUCCESS;
4179 }
4180
4181 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4182 no_bgp_default_subgroup_pkt_queue_max_cmd,
4183 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4184 NO_STR
4185 BGP_STR
4186 "Configure BGP defaults\n"
4187 "subgroup-pkt-queue-max\n"
4188 "Configure subgroup packet queue max\n")
4189 {
4190 VTY_DECLVAR_CONTEXT(bgp, bgp);
4191 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4192 return CMD_SUCCESS;
4193 }
4194
4195
4196 DEFUN (bgp_rr_allow_outbound_policy,
4197 bgp_rr_allow_outbound_policy_cmd,
4198 "bgp route-reflector allow-outbound-policy",
4199 BGP_STR
4200 "Allow modifications made by out route-map\n"
4201 "on ibgp neighbors\n")
4202 {
4203 VTY_DECLVAR_CONTEXT(bgp, bgp);
4204
4205 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4206 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4207 update_group_announce_rrclients(bgp);
4208 bgp_clear_star_soft_out(vty, bgp->name);
4209 }
4210
4211 return CMD_SUCCESS;
4212 }
4213
4214 DEFUN (no_bgp_rr_allow_outbound_policy,
4215 no_bgp_rr_allow_outbound_policy_cmd,
4216 "no bgp route-reflector allow-outbound-policy",
4217 NO_STR
4218 BGP_STR
4219 "Allow modifications made by out route-map\n"
4220 "on ibgp neighbors\n")
4221 {
4222 VTY_DECLVAR_CONTEXT(bgp, bgp);
4223
4224 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4225 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4226 update_group_announce_rrclients(bgp);
4227 bgp_clear_star_soft_out(vty, bgp->name);
4228 }
4229
4230 return CMD_SUCCESS;
4231 }
4232
4233 DEFUN (bgp_listen_limit,
4234 bgp_listen_limit_cmd,
4235 "bgp listen limit (1-65535)",
4236 BGP_STR
4237 "BGP Dynamic Neighbors listen commands\n"
4238 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4239 "Configure Dynamic Neighbors listen limit value\n")
4240 {
4241 VTY_DECLVAR_CONTEXT(bgp, bgp);
4242 int idx_number = 3;
4243 int listen_limit;
4244
4245 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4246
4247 bgp_listen_limit_set(bgp, listen_limit);
4248
4249 return CMD_SUCCESS;
4250 }
4251
4252 DEFUN (no_bgp_listen_limit,
4253 no_bgp_listen_limit_cmd,
4254 "no bgp listen limit [(1-65535)]",
4255 NO_STR
4256 BGP_STR
4257 "BGP Dynamic Neighbors listen commands\n"
4258 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4259 "Configure Dynamic Neighbors listen limit value\n")
4260 {
4261 VTY_DECLVAR_CONTEXT(bgp, bgp);
4262 bgp_listen_limit_unset(bgp);
4263 return CMD_SUCCESS;
4264 }
4265
4266
4267 /*
4268 * Check if this listen range is already configured. Check for exact
4269 * match or overlap based on input.
4270 */
4271 static struct peer_group *listen_range_exists(struct bgp *bgp,
4272 struct prefix *range, int exact)
4273 {
4274 struct listnode *node, *nnode;
4275 struct listnode *node1, *nnode1;
4276 struct peer_group *group;
4277 struct prefix *lr;
4278 afi_t afi;
4279 int match;
4280
4281 afi = family2afi(range->family);
4282 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4283 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4284 lr)) {
4285 if (exact)
4286 match = prefix_same(range, lr);
4287 else
4288 match = (prefix_match(range, lr)
4289 || prefix_match(lr, range));
4290 if (match)
4291 return group;
4292 }
4293 }
4294
4295 return NULL;
4296 }
4297
4298 DEFUN (bgp_listen_range,
4299 bgp_listen_range_cmd,
4300 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4301 BGP_STR
4302 "Configure BGP dynamic neighbors listen range\n"
4303 "Configure BGP dynamic neighbors listen range\n"
4304 NEIGHBOR_ADDR_STR
4305 "Member of the peer-group\n"
4306 "Peer-group name\n")
4307 {
4308 VTY_DECLVAR_CONTEXT(bgp, bgp);
4309 struct prefix range;
4310 struct peer_group *group, *existing_group;
4311 afi_t afi;
4312 int ret;
4313 int idx = 0;
4314
4315 argv_find(argv, argc, "A.B.C.D/M", &idx);
4316 argv_find(argv, argc, "X:X::X:X/M", &idx);
4317 char *prefix = argv[idx]->arg;
4318 argv_find(argv, argc, "PGNAME", &idx);
4319 char *peergroup = argv[idx]->arg;
4320
4321 /* Convert IP prefix string to struct prefix. */
4322 ret = str2prefix(prefix, &range);
4323 if (!ret) {
4324 vty_out(vty, "%% Malformed listen range\n");
4325 return CMD_WARNING_CONFIG_FAILED;
4326 }
4327
4328 afi = family2afi(range.family);
4329
4330 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4331 vty_out(vty,
4332 "%% Malformed listen range (link-local address)\n");
4333 return CMD_WARNING_CONFIG_FAILED;
4334 }
4335
4336 apply_mask(&range);
4337
4338 /* Check if same listen range is already configured. */
4339 existing_group = listen_range_exists(bgp, &range, 1);
4340 if (existing_group) {
4341 if (strcmp(existing_group->name, peergroup) == 0)
4342 return CMD_SUCCESS;
4343 else {
4344 vty_out(vty,
4345 "%% Same listen range is attached to peer-group %s\n",
4346 existing_group->name);
4347 return CMD_WARNING_CONFIG_FAILED;
4348 }
4349 }
4350
4351 /* Check if an overlapping listen range exists. */
4352 if (listen_range_exists(bgp, &range, 0)) {
4353 vty_out(vty,
4354 "%% Listen range overlaps with existing listen range\n");
4355 return CMD_WARNING_CONFIG_FAILED;
4356 }
4357
4358 group = peer_group_lookup(bgp, peergroup);
4359 if (!group) {
4360 vty_out(vty, "%% Configure the peer-group first\n");
4361 return CMD_WARNING_CONFIG_FAILED;
4362 }
4363
4364 ret = peer_group_listen_range_add(group, &range);
4365 return bgp_vty_return(vty, ret);
4366 }
4367
4368 DEFUN (no_bgp_listen_range,
4369 no_bgp_listen_range_cmd,
4370 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4371 NO_STR
4372 BGP_STR
4373 "Unconfigure BGP dynamic neighbors listen range\n"
4374 "Unconfigure BGP dynamic neighbors listen range\n"
4375 NEIGHBOR_ADDR_STR
4376 "Member of the peer-group\n"
4377 "Peer-group name\n")
4378 {
4379 VTY_DECLVAR_CONTEXT(bgp, bgp);
4380 struct prefix range;
4381 struct peer_group *group;
4382 afi_t afi;
4383 int ret;
4384 int idx = 0;
4385
4386 argv_find(argv, argc, "A.B.C.D/M", &idx);
4387 argv_find(argv, argc, "X:X::X:X/M", &idx);
4388 char *prefix = argv[idx]->arg;
4389 argv_find(argv, argc, "PGNAME", &idx);
4390 char *peergroup = argv[idx]->arg;
4391
4392 /* Convert IP prefix string to struct prefix. */
4393 ret = str2prefix(prefix, &range);
4394 if (!ret) {
4395 vty_out(vty, "%% Malformed listen range\n");
4396 return CMD_WARNING_CONFIG_FAILED;
4397 }
4398
4399 afi = family2afi(range.family);
4400
4401 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4402 vty_out(vty,
4403 "%% Malformed listen range (link-local address)\n");
4404 return CMD_WARNING_CONFIG_FAILED;
4405 }
4406
4407 apply_mask(&range);
4408
4409 group = peer_group_lookup(bgp, peergroup);
4410 if (!group) {
4411 vty_out(vty, "%% Peer-group does not exist\n");
4412 return CMD_WARNING_CONFIG_FAILED;
4413 }
4414
4415 ret = peer_group_listen_range_del(group, &range);
4416 return bgp_vty_return(vty, ret);
4417 }
4418
4419 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4420 {
4421 struct peer_group *group;
4422 struct listnode *node, *nnode, *rnode, *nrnode;
4423 struct prefix *range;
4424 afi_t afi;
4425
4426 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4427 vty_out(vty, " bgp listen limit %d\n",
4428 bgp->dynamic_neighbors_limit);
4429
4430 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4431 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4432 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4433 nrnode, range)) {
4434 vty_out(vty,
4435 " bgp listen range %pFX peer-group %s\n",
4436 range, group->name);
4437 }
4438 }
4439 }
4440 }
4441
4442
4443 DEFUN (bgp_disable_connected_route_check,
4444 bgp_disable_connected_route_check_cmd,
4445 "bgp disable-ebgp-connected-route-check",
4446 BGP_STR
4447 "Disable checking if nexthop is connected on ebgp sessions\n")
4448 {
4449 VTY_DECLVAR_CONTEXT(bgp, bgp);
4450 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4451 bgp_clear_star_soft_in(vty, bgp->name);
4452
4453 return CMD_SUCCESS;
4454 }
4455
4456 DEFUN (no_bgp_disable_connected_route_check,
4457 no_bgp_disable_connected_route_check_cmd,
4458 "no bgp disable-ebgp-connected-route-check",
4459 NO_STR
4460 BGP_STR
4461 "Disable checking if nexthop is connected on ebgp sessions\n")
4462 {
4463 VTY_DECLVAR_CONTEXT(bgp, bgp);
4464 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4465 bgp_clear_star_soft_in(vty, bgp->name);
4466
4467 return CMD_SUCCESS;
4468 }
4469
4470
4471 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4472 const char *as_str)
4473 {
4474 VTY_DECLVAR_CONTEXT(bgp, bgp);
4475 int ret;
4476 as_t as;
4477 int as_type = AS_SPECIFIED;
4478 union sockunion su;
4479
4480 if (as_str[0] == 'i') {
4481 as = 0;
4482 as_type = AS_INTERNAL;
4483 } else if (as_str[0] == 'e') {
4484 as = 0;
4485 as_type = AS_EXTERNAL;
4486 } else {
4487 /* Get AS number. */
4488 as = strtoul(as_str, NULL, 10);
4489 }
4490
4491 /* If peer is peer group or interface peer, call proper function. */
4492 ret = str2sockunion(peer_str, &su);
4493 if (ret < 0) {
4494 struct peer *peer;
4495
4496 /* Check if existing interface peer */
4497 peer = peer_lookup_by_conf_if(bgp, peer_str);
4498
4499 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4500
4501 /* if not interface peer, check peer-group settings */
4502 if (ret < 0 && !peer) {
4503 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4504 if (ret < 0) {
4505 vty_out(vty,
4506 "%% Create the peer-group or interface first\n");
4507 return CMD_WARNING_CONFIG_FAILED;
4508 }
4509 return CMD_SUCCESS;
4510 }
4511 } else {
4512 if (peer_address_self_check(bgp, &su)) {
4513 vty_out(vty,
4514 "%% Can not configure the local system as neighbor\n");
4515 return CMD_WARNING_CONFIG_FAILED;
4516 }
4517 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4518 }
4519
4520 return bgp_vty_return(vty, ret);
4521 }
4522
4523 DEFUN (bgp_default_shutdown,
4524 bgp_default_shutdown_cmd,
4525 "[no] bgp default shutdown",
4526 NO_STR
4527 BGP_STR
4528 "Configure BGP defaults\n"
4529 "Apply administrative shutdown to newly configured peers\n")
4530 {
4531 VTY_DECLVAR_CONTEXT(bgp, bgp);
4532 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4533 return CMD_SUCCESS;
4534 }
4535
4536 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4537 BGP_STR
4538 "Administrative shutdown of the BGP instance\n"
4539 "Add a shutdown message (RFC 8203)\n"
4540 "Shutdown message\n")
4541 {
4542 char *msgstr = NULL;
4543
4544 VTY_DECLVAR_CONTEXT(bgp, bgp);
4545
4546 if (argc > 3)
4547 msgstr = argv_concat(argv, argc, 3);
4548
4549 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4550 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4551 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4552 return CMD_WARNING_CONFIG_FAILED;
4553 }
4554
4555 bgp_shutdown_enable(bgp, msgstr);
4556 XFREE(MTYPE_TMP, msgstr);
4557
4558 return CMD_SUCCESS;
4559 }
4560
4561 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4562 BGP_STR "Administrative shutdown of the BGP instance\n")
4563 {
4564 VTY_DECLVAR_CONTEXT(bgp, bgp);
4565
4566 bgp_shutdown_enable(bgp, NULL);
4567
4568 return CMD_SUCCESS;
4569 }
4570
4571 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4572 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4573 {
4574 VTY_DECLVAR_CONTEXT(bgp, bgp);
4575
4576 bgp_shutdown_disable(bgp);
4577
4578 return CMD_SUCCESS;
4579 }
4580
4581 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4582 "no bgp shutdown message MSG...", NO_STR BGP_STR
4583 "Administrative shutdown of the BGP instance\n"
4584 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4585
4586 DEFUN (neighbor_remote_as,
4587 neighbor_remote_as_cmd,
4588 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4589 NEIGHBOR_STR
4590 NEIGHBOR_ADDR_STR2
4591 "Specify a BGP neighbor\n"
4592 AS_STR
4593 "Internal BGP peer\n"
4594 "External BGP peer\n")
4595 {
4596 int idx_peer = 1;
4597 int idx_remote_as = 3;
4598 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4599 argv[idx_remote_as]->arg);
4600 }
4601
4602 DEFPY (bgp_allow_martian,
4603 bgp_allow_martian_cmd,
4604 "[no]$no bgp allow-martian-nexthop",
4605 NO_STR
4606 BGP_STR
4607 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4608 {
4609 VTY_DECLVAR_CONTEXT(bgp, bgp);
4610
4611 if (no)
4612 bgp->allow_martian = false;
4613 else
4614 bgp->allow_martian = true;
4615
4616 return CMD_SUCCESS;
4617 }
4618
4619 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4620 * sessions do not wait for hold timer expiry to bring down the sessions
4621 * when nexthop becomes unreachable
4622 */
4623 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4624 BGP_STR "Fast convergence for bgp sessions\n")
4625 {
4626 VTY_DECLVAR_CONTEXT(bgp, bgp);
4627 bgp->fast_convergence = true;
4628
4629 return CMD_SUCCESS;
4630 }
4631
4632 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4633 "no bgp fast-convergence",
4634 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4635 {
4636 VTY_DECLVAR_CONTEXT(bgp, bgp);
4637 bgp->fast_convergence = false;
4638
4639 return CMD_SUCCESS;
4640 }
4641
4642 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4643 int v6only,
4644 const char *peer_group_name,
4645 const char *as_str)
4646 {
4647 VTY_DECLVAR_CONTEXT(bgp, bgp);
4648 as_t as = 0;
4649 int as_type = AS_UNSPECIFIED;
4650 struct peer *peer;
4651 struct peer_group *group;
4652 int ret = 0;
4653
4654 group = peer_group_lookup(bgp, conf_if);
4655
4656 if (group) {
4657 vty_out(vty, "%% Name conflict with peer-group \n");
4658 return CMD_WARNING_CONFIG_FAILED;
4659 }
4660
4661 if (as_str) {
4662 if (as_str[0] == 'i') {
4663 as_type = AS_INTERNAL;
4664 } else if (as_str[0] == 'e') {
4665 as_type = AS_EXTERNAL;
4666 } else {
4667 /* Get AS number. */
4668 as = strtoul(as_str, NULL, 10);
4669 as_type = AS_SPECIFIED;
4670 }
4671 }
4672
4673 peer = peer_lookup_by_conf_if(bgp, conf_if);
4674 if (peer) {
4675 if (as_str)
4676 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4677 } else {
4678 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4679 NULL, true);
4680
4681 if (!peer) {
4682 vty_out(vty, "%% BGP failed to create peer\n");
4683 return CMD_WARNING_CONFIG_FAILED;
4684 }
4685
4686 if (v6only)
4687 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4688
4689 /* Request zebra to initiate IPv6 RAs on this interface. We do
4690 * this
4691 * any unnumbered peer in order to not worry about run-time
4692 * transitions
4693 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4694 * address
4695 * gets deleted later etc.)
4696 */
4697 if (peer->ifp)
4698 bgp_zebra_initiate_radv(bgp, peer);
4699 }
4700
4701 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4702 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4703 if (v6only)
4704 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4705 else
4706 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4707
4708 /* v6only flag changed. Reset bgp seesion */
4709 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4710 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4711 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4712 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4713 } else
4714 bgp_session_reset(peer);
4715 }
4716
4717 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4718 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4719 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4720 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4721 }
4722
4723 if (peer_group_name) {
4724 group = peer_group_lookup(bgp, peer_group_name);
4725 if (!group) {
4726 vty_out(vty, "%% Configure the peer-group first\n");
4727 return CMD_WARNING_CONFIG_FAILED;
4728 }
4729
4730 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4731 }
4732
4733 return bgp_vty_return(vty, ret);
4734 }
4735
4736 DEFUN (neighbor_interface_config,
4737 neighbor_interface_config_cmd,
4738 "neighbor WORD interface [peer-group PGNAME]",
4739 NEIGHBOR_STR
4740 "Interface name or neighbor tag\n"
4741 "Enable BGP on interface\n"
4742 "Member of the peer-group\n"
4743 "Peer-group name\n")
4744 {
4745 int idx_word = 1;
4746 int idx_peer_group_word = 4;
4747
4748 if (argc > idx_peer_group_word)
4749 return peer_conf_interface_get(
4750 vty, argv[idx_word]->arg, 0,
4751 argv[idx_peer_group_word]->arg, NULL);
4752 else
4753 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4754 NULL, NULL);
4755 }
4756
4757 DEFUN (neighbor_interface_config_v6only,
4758 neighbor_interface_config_v6only_cmd,
4759 "neighbor WORD interface v6only [peer-group PGNAME]",
4760 NEIGHBOR_STR
4761 "Interface name or neighbor tag\n"
4762 "Enable BGP on interface\n"
4763 "Enable BGP with v6 link-local only\n"
4764 "Member of the peer-group\n"
4765 "Peer-group name\n")
4766 {
4767 int idx_word = 1;
4768 int idx_peer_group_word = 5;
4769
4770 if (argc > idx_peer_group_word)
4771 return peer_conf_interface_get(
4772 vty, argv[idx_word]->arg, 1,
4773 argv[idx_peer_group_word]->arg, NULL);
4774
4775 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4776 }
4777
4778
4779 DEFUN (neighbor_interface_config_remote_as,
4780 neighbor_interface_config_remote_as_cmd,
4781 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4782 NEIGHBOR_STR
4783 "Interface name or neighbor tag\n"
4784 "Enable BGP on interface\n"
4785 "Specify a BGP neighbor\n"
4786 AS_STR
4787 "Internal BGP peer\n"
4788 "External BGP peer\n")
4789 {
4790 int idx_word = 1;
4791 int idx_remote_as = 4;
4792 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4793 argv[idx_remote_as]->arg);
4794 }
4795
4796 DEFUN (neighbor_interface_v6only_config_remote_as,
4797 neighbor_interface_v6only_config_remote_as_cmd,
4798 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4799 NEIGHBOR_STR
4800 "Interface name or neighbor tag\n"
4801 "Enable BGP with v6 link-local only\n"
4802 "Enable BGP on interface\n"
4803 "Specify a BGP neighbor\n"
4804 AS_STR
4805 "Internal BGP peer\n"
4806 "External BGP peer\n")
4807 {
4808 int idx_word = 1;
4809 int idx_remote_as = 5;
4810 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4811 argv[idx_remote_as]->arg);
4812 }
4813
4814 DEFUN (neighbor_peer_group,
4815 neighbor_peer_group_cmd,
4816 "neighbor WORD peer-group",
4817 NEIGHBOR_STR
4818 "Interface name or neighbor tag\n"
4819 "Configure peer-group\n")
4820 {
4821 VTY_DECLVAR_CONTEXT(bgp, bgp);
4822 int idx_word = 1;
4823 struct peer *peer;
4824 struct peer_group *group;
4825
4826 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4827 if (peer) {
4828 vty_out(vty, "%% Name conflict with interface: \n");
4829 return CMD_WARNING_CONFIG_FAILED;
4830 }
4831
4832 group = peer_group_get(bgp, argv[idx_word]->arg);
4833 if (!group) {
4834 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4835 return CMD_WARNING_CONFIG_FAILED;
4836 }
4837
4838 return CMD_SUCCESS;
4839 }
4840
4841 DEFUN (no_neighbor,
4842 no_neighbor_cmd,
4843 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4844 NO_STR
4845 NEIGHBOR_STR
4846 NEIGHBOR_ADDR_STR2
4847 "Specify a BGP neighbor\n"
4848 AS_STR
4849 "Internal BGP peer\n"
4850 "External BGP peer\n")
4851 {
4852 VTY_DECLVAR_CONTEXT(bgp, bgp);
4853 int idx_peer = 2;
4854 int ret;
4855 union sockunion su;
4856 struct peer_group *group;
4857 struct peer *peer;
4858 struct peer *other;
4859
4860 ret = str2sockunion(argv[idx_peer]->arg, &su);
4861 if (ret < 0) {
4862 /* look up for neighbor by interface name config. */
4863 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4864 if (peer) {
4865 /* Request zebra to terminate IPv6 RAs on this
4866 * interface. */
4867 if (peer->ifp)
4868 bgp_zebra_terminate_radv(peer->bgp, peer);
4869 peer_notify_unconfig(peer);
4870 peer_delete(peer);
4871 return CMD_SUCCESS;
4872 }
4873
4874 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4875 if (group) {
4876 peer_group_notify_unconfig(group);
4877 peer_group_delete(group);
4878 } else {
4879 vty_out(vty, "%% Create the peer-group first\n");
4880 return CMD_WARNING_CONFIG_FAILED;
4881 }
4882 } else {
4883 peer = peer_lookup(bgp, &su);
4884 if (peer) {
4885 if (peer_dynamic_neighbor(peer)) {
4886 vty_out(vty,
4887 "%% Operation not allowed on a dynamic neighbor\n");
4888 return CMD_WARNING_CONFIG_FAILED;
4889 }
4890
4891 other = peer->doppelganger;
4892
4893 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4894 bgp_zebra_terminate_radv(peer->bgp, peer);
4895
4896 peer_notify_unconfig(peer);
4897 peer_delete(peer);
4898 if (other && other->status != Deleted) {
4899 peer_notify_unconfig(other);
4900 peer_delete(other);
4901 }
4902 }
4903 }
4904
4905 return CMD_SUCCESS;
4906 }
4907
4908 DEFUN (no_neighbor_interface_config,
4909 no_neighbor_interface_config_cmd,
4910 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4911 NO_STR
4912 NEIGHBOR_STR
4913 "Interface name\n"
4914 "Configure BGP on interface\n"
4915 "Enable BGP with v6 link-local only\n"
4916 "Member of the peer-group\n"
4917 "Peer-group name\n"
4918 "Specify a BGP neighbor\n"
4919 AS_STR
4920 "Internal BGP peer\n"
4921 "External BGP peer\n")
4922 {
4923 VTY_DECLVAR_CONTEXT(bgp, bgp);
4924 int idx_word = 2;
4925 struct peer *peer;
4926
4927 /* look up for neighbor by interface name config. */
4928 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4929 if (peer) {
4930 /* Request zebra to terminate IPv6 RAs on this interface. */
4931 if (peer->ifp)
4932 bgp_zebra_terminate_radv(peer->bgp, peer);
4933 peer_notify_unconfig(peer);
4934 peer_delete(peer);
4935 } else {
4936 vty_out(vty, "%% Create the bgp interface first\n");
4937 return CMD_WARNING_CONFIG_FAILED;
4938 }
4939 return CMD_SUCCESS;
4940 }
4941
4942 DEFUN (no_neighbor_peer_group,
4943 no_neighbor_peer_group_cmd,
4944 "no neighbor WORD peer-group",
4945 NO_STR
4946 NEIGHBOR_STR
4947 "Neighbor tag\n"
4948 "Configure peer-group\n")
4949 {
4950 VTY_DECLVAR_CONTEXT(bgp, bgp);
4951 int idx_word = 2;
4952 struct peer_group *group;
4953
4954 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4955 if (group) {
4956 peer_group_notify_unconfig(group);
4957 peer_group_delete(group);
4958 } else {
4959 vty_out(vty, "%% Create the peer-group first\n");
4960 return CMD_WARNING_CONFIG_FAILED;
4961 }
4962 return CMD_SUCCESS;
4963 }
4964
4965 DEFUN (no_neighbor_interface_peer_group_remote_as,
4966 no_neighbor_interface_peer_group_remote_as_cmd,
4967 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4968 NO_STR
4969 NEIGHBOR_STR
4970 "Interface name or neighbor tag\n"
4971 "Specify a BGP neighbor\n"
4972 AS_STR
4973 "Internal BGP peer\n"
4974 "External BGP peer\n")
4975 {
4976 VTY_DECLVAR_CONTEXT(bgp, bgp);
4977 int idx_word = 2;
4978 struct peer_group *group;
4979 struct peer *peer;
4980
4981 /* look up for neighbor by interface name config. */
4982 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4983 if (peer) {
4984 peer_as_change(peer, 0, AS_UNSPECIFIED);
4985 return CMD_SUCCESS;
4986 }
4987
4988 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4989 if (group)
4990 peer_group_remote_as_delete(group);
4991 else {
4992 vty_out(vty, "%% Create the peer-group or interface first\n");
4993 return CMD_WARNING_CONFIG_FAILED;
4994 }
4995 return CMD_SUCCESS;
4996 }
4997
4998 DEFUN (neighbor_local_as,
4999 neighbor_local_as_cmd,
5000 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
5001 NEIGHBOR_STR
5002 NEIGHBOR_ADDR_STR2
5003 "Specify a local-as number\n"
5004 "AS number used as local AS\n")
5005 {
5006 int idx_peer = 1;
5007 int idx_number = 3;
5008 struct peer *peer;
5009 int ret;
5010 as_t as;
5011
5012 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5013 if (!peer)
5014 return CMD_WARNING_CONFIG_FAILED;
5015
5016 as = strtoul(argv[idx_number]->arg, NULL, 10);
5017 ret = peer_local_as_set(peer, as, 0, 0);
5018 return bgp_vty_return(vty, ret);
5019 }
5020
5021 DEFUN (neighbor_local_as_no_prepend,
5022 neighbor_local_as_no_prepend_cmd,
5023 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
5024 NEIGHBOR_STR
5025 NEIGHBOR_ADDR_STR2
5026 "Specify a local-as number\n"
5027 "AS number used as local AS\n"
5028 "Do not prepend local-as to updates from ebgp peers\n")
5029 {
5030 int idx_peer = 1;
5031 int idx_number = 3;
5032 struct peer *peer;
5033 int ret;
5034 as_t as;
5035
5036 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5037 if (!peer)
5038 return CMD_WARNING_CONFIG_FAILED;
5039
5040 as = strtoul(argv[idx_number]->arg, NULL, 10);
5041 ret = peer_local_as_set(peer, as, 1, 0);
5042 return bgp_vty_return(vty, ret);
5043 }
5044
5045 DEFUN (neighbor_local_as_no_prepend_replace_as,
5046 neighbor_local_as_no_prepend_replace_as_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
5048 NEIGHBOR_STR
5049 NEIGHBOR_ADDR_STR2
5050 "Specify a local-as number\n"
5051 "AS number used as local AS\n"
5052 "Do not prepend local-as to updates from ebgp peers\n"
5053 "Do not prepend local-as to updates from ibgp peers\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 as = strtoul(argv[idx_number]->arg, NULL, 10);
5066 ret = peer_local_as_set(peer, as, 1, 1);
5067 return bgp_vty_return(vty, ret);
5068 }
5069
5070 DEFUN (no_neighbor_local_as,
5071 no_neighbor_local_as_cmd,
5072 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5073 NO_STR
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR2
5076 "Specify a local-as number\n"
5077 "AS number used as local AS\n"
5078 "Do not prepend local-as to updates from ebgp peers\n"
5079 "Do not prepend local-as to updates from ibgp peers\n")
5080 {
5081 int idx_peer = 2;
5082 struct peer *peer;
5083 int ret;
5084
5085 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5086 if (!peer)
5087 return CMD_WARNING_CONFIG_FAILED;
5088
5089 ret = peer_local_as_unset(peer);
5090 return bgp_vty_return(vty, ret);
5091 }
5092
5093
5094 DEFUN (neighbor_solo,
5095 neighbor_solo_cmd,
5096 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5097 NEIGHBOR_STR
5098 NEIGHBOR_ADDR_STR2
5099 "Solo peer - part of its own update group\n")
5100 {
5101 int idx_peer = 1;
5102 struct peer *peer;
5103 int ret;
5104
5105 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5106 if (!peer)
5107 return CMD_WARNING_CONFIG_FAILED;
5108
5109 ret = update_group_adjust_soloness(peer, 1);
5110 return bgp_vty_return(vty, ret);
5111 }
5112
5113 DEFUN (no_neighbor_solo,
5114 no_neighbor_solo_cmd,
5115 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5116 NO_STR
5117 NEIGHBOR_STR
5118 NEIGHBOR_ADDR_STR2
5119 "Solo peer - part of its own update group\n")
5120 {
5121 int idx_peer = 2;
5122 struct peer *peer;
5123 int ret;
5124
5125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5126 if (!peer)
5127 return CMD_WARNING_CONFIG_FAILED;
5128
5129 ret = update_group_adjust_soloness(peer, 0);
5130 return bgp_vty_return(vty, ret);
5131 }
5132
5133 DEFUN (neighbor_password,
5134 neighbor_password_cmd,
5135 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5136 NEIGHBOR_STR
5137 NEIGHBOR_ADDR_STR2
5138 "Set a password\n"
5139 "The password\n")
5140 {
5141 int idx_peer = 1;
5142 int idx_line = 3;
5143 struct peer *peer;
5144 int ret;
5145
5146 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5147 if (!peer)
5148 return CMD_WARNING_CONFIG_FAILED;
5149
5150 ret = peer_password_set(peer, argv[idx_line]->arg);
5151 return bgp_vty_return(vty, ret);
5152 }
5153
5154 DEFUN (no_neighbor_password,
5155 no_neighbor_password_cmd,
5156 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5157 NO_STR
5158 NEIGHBOR_STR
5159 NEIGHBOR_ADDR_STR2
5160 "Set a password\n"
5161 "The password\n")
5162 {
5163 int idx_peer = 2;
5164 struct peer *peer;
5165 int ret;
5166
5167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5168 if (!peer)
5169 return CMD_WARNING_CONFIG_FAILED;
5170
5171 ret = peer_password_unset(peer);
5172 return bgp_vty_return(vty, ret);
5173 }
5174
5175 DEFUN (neighbor_activate,
5176 neighbor_activate_cmd,
5177 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5178 NEIGHBOR_STR
5179 NEIGHBOR_ADDR_STR2
5180 "Enable the Address Family for this Neighbor\n")
5181 {
5182 int idx_peer = 1;
5183 int ret;
5184 struct peer *peer;
5185
5186 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5187 if (!peer)
5188 return CMD_WARNING_CONFIG_FAILED;
5189
5190 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5191 return bgp_vty_return(vty, ret);
5192 }
5193
5194 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5195 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5196 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5197 "Enable the Address Family for this Neighbor\n")
5198
5199 DEFUN (no_neighbor_activate,
5200 no_neighbor_activate_cmd,
5201 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5202 NO_STR
5203 NEIGHBOR_STR
5204 NEIGHBOR_ADDR_STR2
5205 "Enable the Address Family for this Neighbor\n")
5206 {
5207 int idx_peer = 2;
5208 int ret;
5209 struct peer *peer;
5210
5211 /* Lookup peer. */
5212 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5213 if (!peer)
5214 return CMD_WARNING_CONFIG_FAILED;
5215
5216 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5217 return bgp_vty_return(vty, ret);
5218 }
5219
5220 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5221 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5223 "Enable the Address Family for this Neighbor\n")
5224
5225 DEFUN (neighbor_set_peer_group,
5226 neighbor_set_peer_group_cmd,
5227 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Member of the peer-group\n"
5231 "Peer-group name\n")
5232 {
5233 VTY_DECLVAR_CONTEXT(bgp, bgp);
5234 int idx_peer = 1;
5235 int idx_word = 3;
5236 int ret;
5237 as_t as;
5238 union sockunion su;
5239 struct peer *peer;
5240 struct peer_group *group;
5241
5242 ret = str2sockunion(argv[idx_peer]->arg, &su);
5243 if (ret < 0) {
5244 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5245 if (!peer) {
5246 vty_out(vty, "%% Malformed address or name: %s\n",
5247 argv[idx_peer]->arg);
5248 return CMD_WARNING_CONFIG_FAILED;
5249 }
5250 } else {
5251 if (peer_address_self_check(bgp, &su)) {
5252 vty_out(vty,
5253 "%% Can not configure the local system as neighbor\n");
5254 return CMD_WARNING_CONFIG_FAILED;
5255 }
5256
5257 /* Disallow for dynamic neighbor. */
5258 peer = peer_lookup(bgp, &su);
5259 if (peer && peer_dynamic_neighbor(peer)) {
5260 vty_out(vty,
5261 "%% Operation not allowed on a dynamic neighbor\n");
5262 return CMD_WARNING_CONFIG_FAILED;
5263 }
5264 }
5265
5266 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5267 if (!group) {
5268 vty_out(vty, "%% Configure the peer-group first\n");
5269 return CMD_WARNING_CONFIG_FAILED;
5270 }
5271
5272 ret = peer_group_bind(bgp, &su, peer, group, &as);
5273
5274 return bgp_vty_return(vty, ret);
5275 }
5276
5277 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5278 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5279 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5280 "Member of the peer-group\n"
5281 "Peer-group name\n")
5282
5283 DEFUN (no_neighbor_set_peer_group,
5284 no_neighbor_set_peer_group_cmd,
5285 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5286 NO_STR
5287 NEIGHBOR_STR
5288 NEIGHBOR_ADDR_STR2
5289 "Member of the peer-group\n"
5290 "Peer-group name\n")
5291 {
5292 VTY_DECLVAR_CONTEXT(bgp, bgp);
5293 int idx_peer = 2;
5294 int idx_word = 4;
5295 int ret;
5296 struct peer *peer;
5297 struct peer_group *group;
5298
5299 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5300 if (!peer)
5301 return CMD_WARNING_CONFIG_FAILED;
5302
5303 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5304 if (!group) {
5305 vty_out(vty, "%% Configure the peer-group first\n");
5306 return CMD_WARNING_CONFIG_FAILED;
5307 }
5308
5309 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5310 bgp_zebra_terminate_radv(peer->bgp, peer);
5311
5312 peer_notify_unconfig(peer);
5313 ret = peer_delete(peer);
5314
5315 return bgp_vty_return(vty, ret);
5316 }
5317
5318 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5319 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5320 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5321 "Member of the peer-group\n"
5322 "Peer-group name\n")
5323
5324 /* neighbor passive. */
5325 DEFUN (neighbor_passive,
5326 neighbor_passive_cmd,
5327 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5328 NEIGHBOR_STR
5329 NEIGHBOR_ADDR_STR2
5330 "Don't send open messages to this neighbor\n")
5331 {
5332 int idx_peer = 1;
5333 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5334 }
5335
5336 DEFUN (no_neighbor_passive,
5337 no_neighbor_passive_cmd,
5338 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5339 NO_STR
5340 NEIGHBOR_STR
5341 NEIGHBOR_ADDR_STR2
5342 "Don't send open messages to this neighbor\n")
5343 {
5344 int idx_peer = 2;
5345 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5346 }
5347
5348 /* neighbor shutdown. */
5349 DEFUN (neighbor_shutdown_msg,
5350 neighbor_shutdown_msg_cmd,
5351 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5352 NEIGHBOR_STR
5353 NEIGHBOR_ADDR_STR2
5354 "Administratively shut down this neighbor\n"
5355 "Add a shutdown message (RFC 8203)\n"
5356 "Shutdown message\n")
5357 {
5358 int idx_peer = 1;
5359
5360 if (argc >= 5) {
5361 struct peer *peer =
5362 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5363 char *message;
5364
5365 if (!peer)
5366 return CMD_WARNING_CONFIG_FAILED;
5367 message = argv_concat(argv, argc, 4);
5368 peer_tx_shutdown_message_set(peer, message);
5369 XFREE(MTYPE_TMP, message);
5370 }
5371
5372 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5373 }
5374
5375 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5376 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5377 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5378 "Administratively shut down this neighbor\n")
5379
5380 DEFUN (no_neighbor_shutdown_msg,
5381 no_neighbor_shutdown_msg_cmd,
5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5383 NO_STR
5384 NEIGHBOR_STR
5385 NEIGHBOR_ADDR_STR2
5386 "Administratively shut down this neighbor\n"
5387 "Remove a shutdown message (RFC 8203)\n"
5388 "Shutdown message\n")
5389 {
5390 int idx_peer = 2;
5391
5392 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5393 PEER_FLAG_SHUTDOWN);
5394 }
5395
5396 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5397 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5398 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5399 "Administratively shut down this neighbor\n")
5400
5401 DEFUN(neighbor_shutdown_rtt,
5402 neighbor_shutdown_rtt_cmd,
5403 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5404 NEIGHBOR_STR
5405 NEIGHBOR_ADDR_STR2
5406 "Administratively shut down this neighbor\n"
5407 "Shutdown if round-trip-time is higher than expected\n"
5408 "Round-trip-time in milliseconds\n"
5409 "Specify the number of keepalives before shutdown\n"
5410 "The number of keepalives with higher RTT to shutdown\n")
5411 {
5412 int idx_peer = 1;
5413 int idx_rtt = 4;
5414 int idx_count = 0;
5415 struct peer *peer;
5416
5417 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5418
5419 if (!peer)
5420 return CMD_WARNING_CONFIG_FAILED;
5421
5422 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5423
5424 if (argv_find(argv, argc, "count", &idx_count))
5425 peer->rtt_keepalive_conf =
5426 strtol(argv[idx_count + 1]->arg, NULL, 10);
5427
5428 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5429 PEER_FLAG_RTT_SHUTDOWN);
5430 }
5431
5432 DEFUN(no_neighbor_shutdown_rtt,
5433 no_neighbor_shutdown_rtt_cmd,
5434 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5435 NO_STR
5436 NEIGHBOR_STR
5437 NEIGHBOR_ADDR_STR2
5438 "Administratively shut down this neighbor\n"
5439 "Shutdown if round-trip-time is higher than expected\n"
5440 "Round-trip-time in milliseconds\n"
5441 "Specify the number of keepalives before shutdown\n"
5442 "The number of keepalives with higher RTT to shutdown\n")
5443 {
5444 int idx_peer = 2;
5445 struct peer *peer;
5446
5447 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5448
5449 if (!peer)
5450 return CMD_WARNING_CONFIG_FAILED;
5451
5452 peer->rtt_expected = 0;
5453 peer->rtt_keepalive_conf = 1;
5454
5455 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5456 PEER_FLAG_RTT_SHUTDOWN);
5457 }
5458
5459 /* neighbor capability dynamic. */
5460 DEFUN (neighbor_capability_dynamic,
5461 neighbor_capability_dynamic_cmd,
5462 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5463 NEIGHBOR_STR
5464 NEIGHBOR_ADDR_STR2
5465 "Advertise capability to the peer\n"
5466 "Advertise dynamic capability to this neighbor\n")
5467 {
5468 int idx_peer = 1;
5469 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5470 PEER_FLAG_DYNAMIC_CAPABILITY);
5471 }
5472
5473 DEFUN (no_neighbor_capability_dynamic,
5474 no_neighbor_capability_dynamic_cmd,
5475 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5476 NO_STR
5477 NEIGHBOR_STR
5478 NEIGHBOR_ADDR_STR2
5479 "Advertise capability to the peer\n"
5480 "Advertise dynamic capability to this neighbor\n")
5481 {
5482 int idx_peer = 2;
5483 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5484 PEER_FLAG_DYNAMIC_CAPABILITY);
5485 }
5486
5487 /* neighbor dont-capability-negotiate */
5488 DEFUN (neighbor_dont_capability_negotiate,
5489 neighbor_dont_capability_negotiate_cmd,
5490 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5491 NEIGHBOR_STR
5492 NEIGHBOR_ADDR_STR2
5493 "Do not perform capability negotiation\n")
5494 {
5495 int idx_peer = 1;
5496 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5497 PEER_FLAG_DONT_CAPABILITY);
5498 }
5499
5500 DEFUN (no_neighbor_dont_capability_negotiate,
5501 no_neighbor_dont_capability_negotiate_cmd,
5502 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5503 NO_STR
5504 NEIGHBOR_STR
5505 NEIGHBOR_ADDR_STR2
5506 "Do not perform capability negotiation\n")
5507 {
5508 int idx_peer = 2;
5509 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5510 PEER_FLAG_DONT_CAPABILITY);
5511 }
5512
5513 /* neighbor capability extended next hop encoding */
5514 DEFUN (neighbor_capability_enhe,
5515 neighbor_capability_enhe_cmd,
5516 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5517 NEIGHBOR_STR
5518 NEIGHBOR_ADDR_STR2
5519 "Advertise capability to the peer\n"
5520 "Advertise extended next-hop capability to the peer\n")
5521 {
5522 int idx_peer = 1;
5523 struct peer *peer;
5524
5525 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5526 if (peer && peer->conf_if)
5527 return CMD_SUCCESS;
5528
5529 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5530 PEER_FLAG_CAPABILITY_ENHE);
5531 }
5532
5533 DEFUN (no_neighbor_capability_enhe,
5534 no_neighbor_capability_enhe_cmd,
5535 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5536 NO_STR
5537 NEIGHBOR_STR
5538 NEIGHBOR_ADDR_STR2
5539 "Advertise capability to the peer\n"
5540 "Advertise extended next-hop capability to the peer\n")
5541 {
5542 int idx_peer = 2;
5543 struct peer *peer;
5544
5545 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5546 if (peer && peer->conf_if) {
5547 vty_out(vty,
5548 "Peer %s cannot have capability extended-nexthop turned off\n",
5549 argv[idx_peer]->arg);
5550 return CMD_WARNING_CONFIG_FAILED;
5551 }
5552
5553 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5554 PEER_FLAG_CAPABILITY_ENHE);
5555 }
5556
5557 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5558 afi_t afi, safi_t safi, uint32_t flag,
5559 int set)
5560 {
5561 int ret;
5562 struct peer *peer;
5563
5564 peer = peer_and_group_lookup_vty(vty, peer_str);
5565 if (!peer)
5566 return CMD_WARNING_CONFIG_FAILED;
5567
5568 if (set)
5569 ret = peer_af_flag_set(peer, afi, safi, flag);
5570 else
5571 ret = peer_af_flag_unset(peer, afi, safi, flag);
5572
5573 return bgp_vty_return(vty, ret);
5574 }
5575
5576 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5577 afi_t afi, safi_t safi, uint32_t flag)
5578 {
5579 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5580 }
5581
5582 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5583 afi_t afi, safi_t safi, uint32_t flag)
5584 {
5585 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5586 }
5587
5588 /* neighbor capability orf prefix-list. */
5589 DEFUN (neighbor_capability_orf_prefix,
5590 neighbor_capability_orf_prefix_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5592 NEIGHBOR_STR
5593 NEIGHBOR_ADDR_STR2
5594 "Advertise capability to the peer\n"
5595 "Advertise ORF capability to the peer\n"
5596 "Advertise prefixlist ORF capability to this neighbor\n"
5597 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5598 "Capability to RECEIVE the ORF from this neighbor\n"
5599 "Capability to SEND the ORF to this neighbor\n")
5600 {
5601 int idx_send_recv = 5;
5602 char *peer_str = argv[1]->arg;
5603 struct peer *peer;
5604 afi_t afi = bgp_node_afi(vty);
5605 safi_t safi = bgp_node_safi(vty);
5606
5607 peer = peer_and_group_lookup_vty(vty, peer_str);
5608 if (!peer)
5609 return CMD_WARNING_CONFIG_FAILED;
5610
5611 if (strmatch(argv[idx_send_recv]->text, "send"))
5612 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5613 PEER_FLAG_ORF_PREFIX_SM);
5614
5615 if (strmatch(argv[idx_send_recv]->text, "receive"))
5616 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5617 PEER_FLAG_ORF_PREFIX_RM);
5618
5619 if (strmatch(argv[idx_send_recv]->text, "both"))
5620 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5621 PEER_FLAG_ORF_PREFIX_SM)
5622 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5623 PEER_FLAG_ORF_PREFIX_RM);
5624
5625 return CMD_WARNING_CONFIG_FAILED;
5626 }
5627
5628 ALIAS_HIDDEN(
5629 neighbor_capability_orf_prefix,
5630 neighbor_capability_orf_prefix_hidden_cmd,
5631 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5632 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5633 "Advertise capability to the peer\n"
5634 "Advertise ORF capability to the peer\n"
5635 "Advertise prefixlist ORF capability to this neighbor\n"
5636 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5637 "Capability to RECEIVE the ORF from this neighbor\n"
5638 "Capability to SEND the ORF to this neighbor\n")
5639
5640 DEFUN (no_neighbor_capability_orf_prefix,
5641 no_neighbor_capability_orf_prefix_cmd,
5642 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5643 NO_STR
5644 NEIGHBOR_STR
5645 NEIGHBOR_ADDR_STR2
5646 "Advertise capability to the peer\n"
5647 "Advertise ORF capability to the peer\n"
5648 "Advertise prefixlist ORF capability to this neighbor\n"
5649 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5650 "Capability to RECEIVE the ORF from this neighbor\n"
5651 "Capability to SEND the ORF to this neighbor\n")
5652 {
5653 int idx_send_recv = 6;
5654 char *peer_str = argv[2]->arg;
5655 struct peer *peer;
5656 afi_t afi = bgp_node_afi(vty);
5657 safi_t safi = bgp_node_safi(vty);
5658
5659 peer = peer_and_group_lookup_vty(vty, peer_str);
5660 if (!peer)
5661 return CMD_WARNING_CONFIG_FAILED;
5662
5663 if (strmatch(argv[idx_send_recv]->text, "send"))
5664 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5665 PEER_FLAG_ORF_PREFIX_SM);
5666
5667 if (strmatch(argv[idx_send_recv]->text, "receive"))
5668 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5669 PEER_FLAG_ORF_PREFIX_RM);
5670
5671 if (strmatch(argv[idx_send_recv]->text, "both"))
5672 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5673 PEER_FLAG_ORF_PREFIX_SM)
5674 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5675 PEER_FLAG_ORF_PREFIX_RM);
5676
5677 return CMD_WARNING_CONFIG_FAILED;
5678 }
5679
5680 ALIAS_HIDDEN(
5681 no_neighbor_capability_orf_prefix,
5682 no_neighbor_capability_orf_prefix_hidden_cmd,
5683 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5684 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5685 "Advertise capability to the peer\n"
5686 "Advertise ORF capability to the peer\n"
5687 "Advertise prefixlist ORF capability to this neighbor\n"
5688 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5689 "Capability to RECEIVE the ORF from this neighbor\n"
5690 "Capability to SEND the ORF to this neighbor\n")
5691
5692 /* neighbor next-hop-self. */
5693 DEFUN (neighbor_nexthop_self,
5694 neighbor_nexthop_self_cmd,
5695 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5696 NEIGHBOR_STR
5697 NEIGHBOR_ADDR_STR2
5698 "Disable the next hop calculation for this neighbor\n")
5699 {
5700 int idx_peer = 1;
5701 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5702 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5703 }
5704
5705 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5706 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5707 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5708 "Disable the next hop calculation for this neighbor\n")
5709
5710 /* neighbor next-hop-self. */
5711 DEFUN (neighbor_nexthop_self_force,
5712 neighbor_nexthop_self_force_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5714 NEIGHBOR_STR
5715 NEIGHBOR_ADDR_STR2
5716 "Disable the next hop calculation for this neighbor\n"
5717 "Set the next hop to self for reflected routes\n")
5718 {
5719 int idx_peer = 1;
5720 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5721 bgp_node_safi(vty),
5722 PEER_FLAG_FORCE_NEXTHOP_SELF);
5723 }
5724
5725 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5726 neighbor_nexthop_self_force_hidden_cmd,
5727 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 "Disable the next hop calculation for this neighbor\n"
5730 "Set the next hop to self for reflected routes\n")
5731
5732 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5733 neighbor_nexthop_self_all_hidden_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Disable the next hop calculation for this neighbor\n"
5737 "Set the next hop to self for reflected routes\n")
5738
5739 DEFUN (no_neighbor_nexthop_self,
5740 no_neighbor_nexthop_self_cmd,
5741 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5742 NO_STR
5743 NEIGHBOR_STR
5744 NEIGHBOR_ADDR_STR2
5745 "Disable the next hop calculation for this neighbor\n")
5746 {
5747 int idx_peer = 2;
5748 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5749 bgp_node_afi(vty), bgp_node_safi(vty),
5750 PEER_FLAG_NEXTHOP_SELF);
5751 }
5752
5753 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5754 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5755 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5756 "Disable the next hop calculation for this neighbor\n")
5757
5758 DEFUN (no_neighbor_nexthop_self_force,
5759 no_neighbor_nexthop_self_force_cmd,
5760 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5761 NO_STR
5762 NEIGHBOR_STR
5763 NEIGHBOR_ADDR_STR2
5764 "Disable the next hop calculation for this neighbor\n"
5765 "Set the next hop to self for reflected routes\n")
5766 {
5767 int idx_peer = 2;
5768 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5769 bgp_node_afi(vty), bgp_node_safi(vty),
5770 PEER_FLAG_FORCE_NEXTHOP_SELF);
5771 }
5772
5773 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5774 no_neighbor_nexthop_self_force_hidden_cmd,
5775 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 "Disable the next hop calculation for this neighbor\n"
5778 "Set the next hop to self for reflected routes\n")
5779
5780 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5781 no_neighbor_nexthop_self_all_hidden_cmd,
5782 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5784 "Disable the next hop calculation for this neighbor\n"
5785 "Set the next hop to self for reflected routes\n")
5786
5787 /* neighbor as-override */
5788 DEFUN (neighbor_as_override,
5789 neighbor_as_override_cmd,
5790 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5791 NEIGHBOR_STR
5792 NEIGHBOR_ADDR_STR2
5793 "Override ASNs in outbound updates if aspath equals remote-as\n")
5794 {
5795 int idx_peer = 1;
5796 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5797 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5798 }
5799
5800 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5801 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5803 "Override ASNs in outbound updates if aspath equals remote-as\n")
5804
5805 DEFUN (no_neighbor_as_override,
5806 no_neighbor_as_override_cmd,
5807 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5808 NO_STR
5809 NEIGHBOR_STR
5810 NEIGHBOR_ADDR_STR2
5811 "Override ASNs in outbound updates if aspath equals remote-as\n")
5812 {
5813 int idx_peer = 2;
5814 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5815 bgp_node_afi(vty), bgp_node_safi(vty),
5816 PEER_FLAG_AS_OVERRIDE);
5817 }
5818
5819 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5820 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5822 "Override ASNs in outbound updates if aspath equals remote-as\n")
5823
5824 /* neighbor remove-private-AS. */
5825 DEFUN (neighbor_remove_private_as,
5826 neighbor_remove_private_as_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5828 NEIGHBOR_STR
5829 NEIGHBOR_ADDR_STR2
5830 "Remove private ASNs in outbound updates\n")
5831 {
5832 int idx_peer = 1;
5833 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5834 bgp_node_safi(vty),
5835 PEER_FLAG_REMOVE_PRIVATE_AS);
5836 }
5837
5838 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5840 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5841 "Remove private ASNs in outbound updates\n")
5842
5843 DEFUN (neighbor_remove_private_as_all,
5844 neighbor_remove_private_as_all_cmd,
5845 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5846 NEIGHBOR_STR
5847 NEIGHBOR_ADDR_STR2
5848 "Remove private ASNs in outbound updates\n"
5849 "Apply to all AS numbers\n")
5850 {
5851 int idx_peer = 1;
5852 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5853 bgp_node_safi(vty),
5854 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5855 }
5856
5857 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5858 neighbor_remove_private_as_all_hidden_cmd,
5859 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5861 "Remove private ASNs in outbound updates\n"
5862 "Apply to all AS numbers\n")
5863
5864 DEFUN (neighbor_remove_private_as_replace_as,
5865 neighbor_remove_private_as_replace_as_cmd,
5866 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
5869 "Remove private ASNs in outbound updates\n"
5870 "Replace private ASNs with our ASN in outbound updates\n")
5871 {
5872 int idx_peer = 1;
5873 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5874 bgp_node_safi(vty),
5875 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5876 }
5877
5878 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5879 neighbor_remove_private_as_replace_as_hidden_cmd,
5880 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5882 "Remove private ASNs in outbound updates\n"
5883 "Replace private ASNs with our ASN in outbound updates\n")
5884
5885 DEFUN (neighbor_remove_private_as_all_replace_as,
5886 neighbor_remove_private_as_all_replace_as_cmd,
5887 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5888 NEIGHBOR_STR
5889 NEIGHBOR_ADDR_STR2
5890 "Remove private ASNs in outbound updates\n"
5891 "Apply to all AS numbers\n"
5892 "Replace private ASNs with our ASN in outbound updates\n")
5893 {
5894 int idx_peer = 1;
5895 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5896 bgp_node_safi(vty),
5897 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5898 }
5899
5900 ALIAS_HIDDEN(
5901 neighbor_remove_private_as_all_replace_as,
5902 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5903 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5904 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5905 "Remove private ASNs in outbound updates\n"
5906 "Apply to all AS numbers\n"
5907 "Replace private ASNs with our ASN in outbound updates\n")
5908
5909 DEFUN (no_neighbor_remove_private_as,
5910 no_neighbor_remove_private_as_cmd,
5911 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5912 NO_STR
5913 NEIGHBOR_STR
5914 NEIGHBOR_ADDR_STR2
5915 "Remove private ASNs in outbound updates\n")
5916 {
5917 int idx_peer = 2;
5918 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5919 bgp_node_afi(vty), bgp_node_safi(vty),
5920 PEER_FLAG_REMOVE_PRIVATE_AS);
5921 }
5922
5923 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5924 no_neighbor_remove_private_as_hidden_cmd,
5925 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5926 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5927 "Remove private ASNs in outbound updates\n")
5928
5929 DEFUN (no_neighbor_remove_private_as_all,
5930 no_neighbor_remove_private_as_all_cmd,
5931 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5932 NO_STR
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
5935 "Remove private ASNs in outbound updates\n"
5936 "Apply to all AS numbers\n")
5937 {
5938 int idx_peer = 2;
5939 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5940 bgp_node_afi(vty), bgp_node_safi(vty),
5941 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5942 }
5943
5944 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5945 no_neighbor_remove_private_as_all_hidden_cmd,
5946 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Remove private ASNs in outbound updates\n"
5949 "Apply to all AS numbers\n")
5950
5951 DEFUN (no_neighbor_remove_private_as_replace_as,
5952 no_neighbor_remove_private_as_replace_as_cmd,
5953 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5954 NO_STR
5955 NEIGHBOR_STR
5956 NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n"
5958 "Replace private ASNs with our ASN in outbound updates\n")
5959 {
5960 int idx_peer = 2;
5961 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5962 bgp_node_afi(vty), bgp_node_safi(vty),
5963 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5964 }
5965
5966 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5967 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5968 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5970 "Remove private ASNs in outbound updates\n"
5971 "Replace private ASNs with our ASN in outbound updates\n")
5972
5973 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5974 no_neighbor_remove_private_as_all_replace_as_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5976 NO_STR
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Remove private ASNs in outbound updates\n"
5980 "Apply to all AS numbers\n"
5981 "Replace private ASNs with our ASN in outbound updates\n")
5982 {
5983 int idx_peer = 2;
5984 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5985 bgp_node_afi(vty), bgp_node_safi(vty),
5986 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5987 }
5988
5989 ALIAS_HIDDEN(
5990 no_neighbor_remove_private_as_all_replace_as,
5991 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5992 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5993 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5994 "Remove private ASNs in outbound updates\n"
5995 "Apply to all AS numbers\n"
5996 "Replace private ASNs with our ASN in outbound updates\n")
5997
5998
5999 /* neighbor send-community. */
6000 DEFUN (neighbor_send_community,
6001 neighbor_send_community_cmd,
6002 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6003 NEIGHBOR_STR
6004 NEIGHBOR_ADDR_STR2
6005 "Send Community attribute to this neighbor\n")
6006 {
6007 int idx_peer = 1;
6008
6009 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6010 bgp_node_safi(vty),
6011 PEER_FLAG_SEND_COMMUNITY);
6012 }
6013
6014 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6015 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6017 "Send Community attribute to this neighbor\n")
6018
6019 DEFUN (no_neighbor_send_community,
6020 no_neighbor_send_community_cmd,
6021 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6022 NO_STR
6023 NEIGHBOR_STR
6024 NEIGHBOR_ADDR_STR2
6025 "Send Community attribute to this neighbor\n")
6026 {
6027 int idx_peer = 2;
6028
6029 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6030 bgp_node_afi(vty), bgp_node_safi(vty),
6031 PEER_FLAG_SEND_COMMUNITY);
6032 }
6033
6034 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6035 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6036 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6037 "Send Community attribute to this neighbor\n")
6038
6039 /* neighbor send-community extended. */
6040 DEFUN (neighbor_send_community_type,
6041 neighbor_send_community_type_cmd,
6042 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6043 NEIGHBOR_STR
6044 NEIGHBOR_ADDR_STR2
6045 "Send Community attribute to this neighbor\n"
6046 "Send Standard and Extended Community attributes\n"
6047 "Send Standard, Large and Extended Community attributes\n"
6048 "Send Extended Community attributes\n"
6049 "Send Standard Community attributes\n"
6050 "Send Large Community attributes\n")
6051 {
6052 const char *type = argv[argc - 1]->text;
6053 char *peer_str = argv[1]->arg;
6054 struct peer *peer;
6055 afi_t afi = bgp_node_afi(vty);
6056 safi_t safi = bgp_node_safi(vty);
6057
6058 peer = peer_and_group_lookup_vty(vty, peer_str);
6059 if (!peer)
6060 return CMD_WARNING_CONFIG_FAILED;
6061
6062 if (strmatch(type, "standard"))
6063 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6064 PEER_FLAG_SEND_COMMUNITY);
6065
6066 if (strmatch(type, "extended"))
6067 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6068 PEER_FLAG_SEND_EXT_COMMUNITY);
6069
6070 if (strmatch(type, "large"))
6071 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6072 PEER_FLAG_SEND_LARGE_COMMUNITY);
6073
6074 if (strmatch(type, "both")) {
6075 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6076 PEER_FLAG_SEND_COMMUNITY)
6077 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6078 PEER_FLAG_SEND_EXT_COMMUNITY);
6079 }
6080 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6081 PEER_FLAG_SEND_COMMUNITY)
6082 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6083 PEER_FLAG_SEND_EXT_COMMUNITY)
6084 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6085 PEER_FLAG_SEND_LARGE_COMMUNITY);
6086 }
6087
6088 ALIAS_HIDDEN(
6089 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6090 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6091 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6092 "Send Community attribute to this neighbor\n"
6093 "Send Standard and Extended Community attributes\n"
6094 "Send Standard, Large and Extended Community attributes\n"
6095 "Send Extended Community attributes\n"
6096 "Send Standard Community attributes\n"
6097 "Send Large Community attributes\n")
6098
6099 DEFUN (no_neighbor_send_community_type,
6100 no_neighbor_send_community_type_cmd,
6101 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6102 NO_STR
6103 NEIGHBOR_STR
6104 NEIGHBOR_ADDR_STR2
6105 "Send Community attribute to this neighbor\n"
6106 "Send Standard and Extended Community attributes\n"
6107 "Send Standard, Large and Extended Community attributes\n"
6108 "Send Extended Community attributes\n"
6109 "Send Standard Community attributes\n"
6110 "Send Large Community attributes\n")
6111 {
6112 const char *type = argv[argc - 1]->text;
6113 char *peer_str = argv[2]->arg;
6114 struct peer *peer;
6115 afi_t afi = bgp_node_afi(vty);
6116 safi_t safi = bgp_node_safi(vty);
6117
6118 peer = peer_and_group_lookup_vty(vty, peer_str);
6119 if (!peer)
6120 return CMD_WARNING_CONFIG_FAILED;
6121
6122 if (strmatch(type, "standard"))
6123 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6124 PEER_FLAG_SEND_COMMUNITY);
6125
6126 if (strmatch(type, "extended"))
6127 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6128 PEER_FLAG_SEND_EXT_COMMUNITY);
6129
6130 if (strmatch(type, "large"))
6131 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6132 PEER_FLAG_SEND_LARGE_COMMUNITY);
6133
6134 if (strmatch(type, "both")) {
6135
6136 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6137 PEER_FLAG_SEND_COMMUNITY)
6138 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6139 PEER_FLAG_SEND_EXT_COMMUNITY);
6140 }
6141
6142 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6143 PEER_FLAG_SEND_COMMUNITY)
6144 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6145 PEER_FLAG_SEND_EXT_COMMUNITY)
6146 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6147 PEER_FLAG_SEND_LARGE_COMMUNITY);
6148 }
6149
6150 ALIAS_HIDDEN(
6151 no_neighbor_send_community_type,
6152 no_neighbor_send_community_type_hidden_cmd,
6153 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6154 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6155 "Send Community attribute to this neighbor\n"
6156 "Send Standard and Extended Community attributes\n"
6157 "Send Standard, Large and Extended Community attributes\n"
6158 "Send Extended Community attributes\n"
6159 "Send Standard Community attributes\n"
6160 "Send Large Community attributes\n")
6161
6162 /* neighbor soft-reconfig. */
6163 DEFUN (neighbor_soft_reconfiguration,
6164 neighbor_soft_reconfiguration_cmd,
6165 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6166 NEIGHBOR_STR
6167 NEIGHBOR_ADDR_STR2
6168 "Per neighbor soft reconfiguration\n"
6169 "Allow inbound soft reconfiguration for this neighbor\n")
6170 {
6171 int idx_peer = 1;
6172 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6173 bgp_node_safi(vty),
6174 PEER_FLAG_SOFT_RECONFIG);
6175 }
6176
6177 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6178 neighbor_soft_reconfiguration_hidden_cmd,
6179 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6180 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6181 "Per neighbor soft reconfiguration\n"
6182 "Allow inbound soft reconfiguration for this neighbor\n")
6183
6184 DEFUN (no_neighbor_soft_reconfiguration,
6185 no_neighbor_soft_reconfiguration_cmd,
6186 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6187 NO_STR
6188 NEIGHBOR_STR
6189 NEIGHBOR_ADDR_STR2
6190 "Per neighbor soft reconfiguration\n"
6191 "Allow inbound soft reconfiguration for this neighbor\n")
6192 {
6193 int idx_peer = 2;
6194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6195 bgp_node_afi(vty), bgp_node_safi(vty),
6196 PEER_FLAG_SOFT_RECONFIG);
6197 }
6198
6199 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6200 no_neighbor_soft_reconfiguration_hidden_cmd,
6201 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6203 "Per neighbor soft reconfiguration\n"
6204 "Allow inbound soft reconfiguration for this neighbor\n")
6205
6206 DEFUN (neighbor_route_reflector_client,
6207 neighbor_route_reflector_client_cmd,
6208 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6209 NEIGHBOR_STR
6210 NEIGHBOR_ADDR_STR2
6211 "Configure a neighbor as Route Reflector client\n")
6212 {
6213 int idx_peer = 1;
6214 struct peer *peer;
6215
6216
6217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6218 if (!peer)
6219 return CMD_WARNING_CONFIG_FAILED;
6220
6221 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6222 bgp_node_safi(vty),
6223 PEER_FLAG_REFLECTOR_CLIENT);
6224 }
6225
6226 ALIAS_HIDDEN(neighbor_route_reflector_client,
6227 neighbor_route_reflector_client_hidden_cmd,
6228 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6229 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6230 "Configure a neighbor as Route Reflector client\n")
6231
6232 DEFUN (no_neighbor_route_reflector_client,
6233 no_neighbor_route_reflector_client_cmd,
6234 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6235 NO_STR
6236 NEIGHBOR_STR
6237 NEIGHBOR_ADDR_STR2
6238 "Configure a neighbor as Route Reflector client\n")
6239 {
6240 int idx_peer = 2;
6241 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6242 bgp_node_afi(vty), bgp_node_safi(vty),
6243 PEER_FLAG_REFLECTOR_CLIENT);
6244 }
6245
6246 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6247 no_neighbor_route_reflector_client_hidden_cmd,
6248 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6249 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6250 "Configure a neighbor as Route Reflector client\n")
6251
6252 /* optimal-route-reflection Root Routers configuration */
6253 DEFPY (optimal_route_reflection,
6254 optimal_route_reflection_cmd,
6255 "[no$no] optimal-route-reflection WORD$orr_group [<A.B.C.D|X:X::X:X>$primary [<A.B.C.D|X:X::X:X>$secondary [<A.B.C.D|X:X::X:X>$tertiary]]]",
6256 NO_STR
6257 "Create ORR group and assign root router(s)\n"
6258 "ORR Group name\n"
6259 "Primary Root address\n"
6260 "Primary Root IPv6 address\n"
6261 "Secondary Root address\n"
6262 "Secondary Root IPv6 address\n"
6263 "Tertiary Root address\n"
6264 "Tertiary Root IPv6 address\n")
6265 {
6266 if (!no && !primary) {
6267 vty_out(vty, "%% Specify Primary Root address\n");
6268 return CMD_WARNING_CONFIG_FAILED;
6269 }
6270 return bgp_afi_safi_orr_group_set_vty(
6271 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
6272 primary_str, secondary_str, tertiary_str, !!no);
6273 }
6274
6275 /* neighbor optimal-route-reflection group*/
6276 DEFPY (neighbor_optimal_route_reflection,
6277 neighbor_optimal_route_reflection_cmd,
6278 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6279 NO_STR
6280 NEIGHBOR_STR
6281 NEIGHBOR_ADDR_STR2
6282 "Apply ORR group configuration to the neighbor\n"
6283 "ORR group name\n")
6284 {
6285 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
6286 bgp_node_safi(vty), orr_group, !!no);
6287 }
6288
6289 /* neighbor route-server-client. */
6290 DEFUN (neighbor_route_server_client,
6291 neighbor_route_server_client_cmd,
6292 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6293 NEIGHBOR_STR
6294 NEIGHBOR_ADDR_STR2
6295 "Configure a neighbor as Route Server client\n")
6296 {
6297 int idx_peer = 1;
6298 struct peer *peer;
6299
6300 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6301 if (!peer)
6302 return CMD_WARNING_CONFIG_FAILED;
6303 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6304 bgp_node_safi(vty),
6305 PEER_FLAG_RSERVER_CLIENT);
6306 }
6307
6308 ALIAS_HIDDEN(neighbor_route_server_client,
6309 neighbor_route_server_client_hidden_cmd,
6310 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6312 "Configure a neighbor as Route Server client\n")
6313
6314 DEFUN (no_neighbor_route_server_client,
6315 no_neighbor_route_server_client_cmd,
6316 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6317 NO_STR
6318 NEIGHBOR_STR
6319 NEIGHBOR_ADDR_STR2
6320 "Configure a neighbor as Route Server client\n")
6321 {
6322 int idx_peer = 2;
6323 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6324 bgp_node_afi(vty), bgp_node_safi(vty),
6325 PEER_FLAG_RSERVER_CLIENT);
6326 }
6327
6328 ALIAS_HIDDEN(no_neighbor_route_server_client,
6329 no_neighbor_route_server_client_hidden_cmd,
6330 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6331 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6332 "Configure a neighbor as Route Server client\n")
6333
6334 DEFUN (neighbor_nexthop_local_unchanged,
6335 neighbor_nexthop_local_unchanged_cmd,
6336 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6337 NEIGHBOR_STR
6338 NEIGHBOR_ADDR_STR2
6339 "Configure treatment of outgoing link-local nexthop attribute\n"
6340 "Leave link-local nexthop unchanged for this peer\n")
6341 {
6342 int idx_peer = 1;
6343 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6344 bgp_node_safi(vty),
6345 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6346 }
6347
6348 DEFUN (no_neighbor_nexthop_local_unchanged,
6349 no_neighbor_nexthop_local_unchanged_cmd,
6350 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6351 NO_STR
6352 NEIGHBOR_STR
6353 NEIGHBOR_ADDR_STR2
6354 "Configure treatment of outgoing link-local-nexthop attribute\n"
6355 "Leave link-local nexthop unchanged for this peer\n")
6356 {
6357 int idx_peer = 2;
6358 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6359 bgp_node_afi(vty), bgp_node_safi(vty),
6360 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6361 }
6362
6363 DEFUN (neighbor_attr_unchanged,
6364 neighbor_attr_unchanged_cmd,
6365 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6366 NEIGHBOR_STR
6367 NEIGHBOR_ADDR_STR2
6368 "BGP attribute is propagated unchanged to this neighbor\n"
6369 "As-path attribute\n"
6370 "Nexthop attribute\n"
6371 "Med attribute\n")
6372 {
6373 int idx = 0;
6374 char *peer_str = argv[1]->arg;
6375 struct peer *peer;
6376 bool aspath = false;
6377 bool nexthop = false;
6378 bool med = false;
6379 afi_t afi = bgp_node_afi(vty);
6380 safi_t safi = bgp_node_safi(vty);
6381 int ret = 0;
6382
6383 peer = peer_and_group_lookup_vty(vty, peer_str);
6384 if (!peer)
6385 return CMD_WARNING_CONFIG_FAILED;
6386
6387 if (argv_find(argv, argc, "as-path", &idx))
6388 aspath = true;
6389
6390 idx = 0;
6391 if (argv_find(argv, argc, "next-hop", &idx))
6392 nexthop = true;
6393
6394 idx = 0;
6395 if (argv_find(argv, argc, "med", &idx))
6396 med = true;
6397
6398 /* no flags means all of them! */
6399 if (!aspath && !nexthop && !med) {
6400 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6401 PEER_FLAG_AS_PATH_UNCHANGED);
6402 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6403 PEER_FLAG_NEXTHOP_UNCHANGED);
6404 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6405 PEER_FLAG_MED_UNCHANGED);
6406 } else {
6407 if (!aspath) {
6408 if (peer_af_flag_check(peer, afi, safi,
6409 PEER_FLAG_AS_PATH_UNCHANGED)) {
6410 ret |= peer_af_flag_unset_vty(
6411 vty, peer_str, afi, safi,
6412 PEER_FLAG_AS_PATH_UNCHANGED);
6413 }
6414 } else
6415 ret |= peer_af_flag_set_vty(
6416 vty, peer_str, afi, safi,
6417 PEER_FLAG_AS_PATH_UNCHANGED);
6418
6419 if (!nexthop) {
6420 if (peer_af_flag_check(peer, afi, safi,
6421 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6422 ret |= peer_af_flag_unset_vty(
6423 vty, peer_str, afi, safi,
6424 PEER_FLAG_NEXTHOP_UNCHANGED);
6425 }
6426 } else
6427 ret |= peer_af_flag_set_vty(
6428 vty, peer_str, afi, safi,
6429 PEER_FLAG_NEXTHOP_UNCHANGED);
6430
6431 if (!med) {
6432 if (peer_af_flag_check(peer, afi, safi,
6433 PEER_FLAG_MED_UNCHANGED)) {
6434 ret |= peer_af_flag_unset_vty(
6435 vty, peer_str, afi, safi,
6436 PEER_FLAG_MED_UNCHANGED);
6437 }
6438 } else
6439 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6440 PEER_FLAG_MED_UNCHANGED);
6441 }
6442
6443 return ret;
6444 }
6445
6446 ALIAS_HIDDEN(
6447 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6448 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6449 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6450 "BGP attribute is propagated unchanged to this neighbor\n"
6451 "As-path attribute\n"
6452 "Nexthop attribute\n"
6453 "Med attribute\n")
6454
6455 DEFUN (no_neighbor_attr_unchanged,
6456 no_neighbor_attr_unchanged_cmd,
6457 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6458 NO_STR
6459 NEIGHBOR_STR
6460 NEIGHBOR_ADDR_STR2
6461 "BGP attribute is propagated unchanged to this neighbor\n"
6462 "As-path attribute\n"
6463 "Nexthop attribute\n"
6464 "Med attribute\n")
6465 {
6466 int idx = 0;
6467 char *peer_str = argv[2]->arg;
6468 struct peer *peer;
6469 bool aspath = false;
6470 bool nexthop = false;
6471 bool med = false;
6472 afi_t afi = bgp_node_afi(vty);
6473 safi_t safi = bgp_node_safi(vty);
6474 int ret = 0;
6475
6476 peer = peer_and_group_lookup_vty(vty, peer_str);
6477 if (!peer)
6478 return CMD_WARNING_CONFIG_FAILED;
6479
6480 if (argv_find(argv, argc, "as-path", &idx))
6481 aspath = true;
6482
6483 idx = 0;
6484 if (argv_find(argv, argc, "next-hop", &idx))
6485 nexthop = true;
6486
6487 idx = 0;
6488 if (argv_find(argv, argc, "med", &idx))
6489 med = true;
6490
6491 if (!aspath && !nexthop && !med) // no flags means all of them!
6492 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6493 PEER_FLAG_AS_PATH_UNCHANGED)
6494 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6495 PEER_FLAG_NEXTHOP_UNCHANGED)
6496 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6497 PEER_FLAG_MED_UNCHANGED);
6498
6499 if (aspath)
6500 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6501 PEER_FLAG_AS_PATH_UNCHANGED);
6502
6503 if (nexthop)
6504 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6505 PEER_FLAG_NEXTHOP_UNCHANGED);
6506
6507 if (med)
6508 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6509 PEER_FLAG_MED_UNCHANGED);
6510
6511 return ret;
6512 }
6513
6514 ALIAS_HIDDEN(
6515 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6516 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6518 "BGP attribute is propagated unchanged to this neighbor\n"
6519 "As-path attribute\n"
6520 "Nexthop attribute\n"
6521 "Med attribute\n")
6522
6523 /* EBGP multihop configuration. */
6524 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6525 const char *ttl_str)
6526 {
6527 struct peer *peer;
6528 unsigned int ttl;
6529
6530 peer = peer_and_group_lookup_vty(vty, ip_str);
6531 if (!peer)
6532 return CMD_WARNING_CONFIG_FAILED;
6533
6534 if (peer->conf_if)
6535 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6536
6537 if (!ttl_str)
6538 ttl = MAXTTL;
6539 else
6540 ttl = strtoul(ttl_str, NULL, 10);
6541
6542 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6543 }
6544
6545 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6546 {
6547 struct peer *peer;
6548
6549 peer = peer_and_group_lookup_vty(vty, ip_str);
6550 if (!peer)
6551 return CMD_WARNING_CONFIG_FAILED;
6552
6553 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6554 }
6555
6556 /* neighbor ebgp-multihop. */
6557 DEFUN (neighbor_ebgp_multihop,
6558 neighbor_ebgp_multihop_cmd,
6559 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6560 NEIGHBOR_STR
6561 NEIGHBOR_ADDR_STR2
6562 "Allow EBGP neighbors not on directly connected networks\n")
6563 {
6564 int idx_peer = 1;
6565 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6566 }
6567
6568 DEFUN (neighbor_ebgp_multihop_ttl,
6569 neighbor_ebgp_multihop_ttl_cmd,
6570 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6571 NEIGHBOR_STR
6572 NEIGHBOR_ADDR_STR2
6573 "Allow EBGP neighbors not on directly connected networks\n"
6574 "maximum hop count\n")
6575 {
6576 int idx_peer = 1;
6577 int idx_number = 3;
6578 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6579 argv[idx_number]->arg);
6580 }
6581
6582 DEFUN (no_neighbor_ebgp_multihop,
6583 no_neighbor_ebgp_multihop_cmd,
6584 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6585 NO_STR
6586 NEIGHBOR_STR
6587 NEIGHBOR_ADDR_STR2
6588 "Allow EBGP neighbors not on directly connected networks\n"
6589 "maximum hop count\n")
6590 {
6591 int idx_peer = 2;
6592 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6593 }
6594
6595 DEFPY (neighbor_aigp,
6596 neighbor_aigp_cmd,
6597 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6598 NO_STR
6599 NEIGHBOR_STR
6600 NEIGHBOR_ADDR_STR2
6601 "Enable send and receive of the AIGP attribute per neighbor\n")
6602 {
6603 struct peer *peer;
6604
6605 peer = peer_and_group_lookup_vty(vty, neighbor);
6606 if (!peer)
6607 return CMD_WARNING_CONFIG_FAILED;
6608
6609 if (no)
6610 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6611 else
6612 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6613 }
6614
6615 static uint8_t get_role_by_name(const char *role_str)
6616 {
6617 if (strncmp(role_str, "peer", 2) == 0)
6618 return ROLE_PEER;
6619 if (strncmp(role_str, "provider", 2) == 0)
6620 return ROLE_PROVIDER;
6621 if (strncmp(role_str, "customer", 2) == 0)
6622 return ROLE_CUSTOMER;
6623 if (strncmp(role_str, "rs-server", 4) == 0)
6624 return ROLE_RS_SERVER;
6625 if (strncmp(role_str, "rs-client", 4) == 0)
6626 return ROLE_RS_CLIENT;
6627 return ROLE_UNDEFINED;
6628 }
6629
6630 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6631 const char *role_str, bool strict_mode)
6632 {
6633 struct peer *peer;
6634
6635 peer = peer_and_group_lookup_vty(vty, ip_str);
6636 if (!peer)
6637 return CMD_WARNING_CONFIG_FAILED;
6638 uint8_t role = get_role_by_name(role_str);
6639
6640 if (role == ROLE_UNDEFINED)
6641 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6642 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6643 }
6644
6645 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6646 {
6647 struct peer *peer;
6648
6649 peer = peer_and_group_lookup_vty(vty, ip_str);
6650 if (!peer)
6651 return CMD_WARNING_CONFIG_FAILED;
6652 return bgp_vty_return(vty, peer_role_unset(peer));
6653 }
6654
6655 DEFPY(neighbor_role,
6656 neighbor_role_cmd,
6657 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6658 NEIGHBOR_STR
6659 NEIGHBOR_ADDR_STR2
6660 "Set session role\n"
6661 ROLE_STR)
6662 {
6663 int idx_peer = 1;
6664 int idx_role = 3;
6665
6666 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6667 false);
6668 }
6669
6670 DEFPY(neighbor_role_strict,
6671 neighbor_role_strict_cmd,
6672 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6673 NEIGHBOR_STR
6674 NEIGHBOR_ADDR_STR2
6675 "Set session role\n"
6676 ROLE_STR
6677 "Use additional restriction on peer\n")
6678 {
6679 int idx_peer = 1;
6680 int idx_role = 3;
6681
6682 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6683 true);
6684 }
6685
6686 DEFPY(no_neighbor_role,
6687 no_neighbor_role_cmd,
6688 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6689 NO_STR
6690 NEIGHBOR_STR
6691 NEIGHBOR_ADDR_STR2
6692 "Set session role\n"
6693 ROLE_STR
6694 "Use additional restriction on peer\n")
6695 {
6696 int idx_peer = 2;
6697
6698 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6699 }
6700
6701 /* disable-connected-check */
6702 DEFUN (neighbor_disable_connected_check,
6703 neighbor_disable_connected_check_cmd,
6704 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6705 NEIGHBOR_STR
6706 NEIGHBOR_ADDR_STR2
6707 "one-hop away EBGP peer using loopback address\n"
6708 "Enforce EBGP neighbors perform multihop\n")
6709 {
6710 int idx_peer = 1;
6711 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6712 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6713 }
6714
6715 DEFUN (no_neighbor_disable_connected_check,
6716 no_neighbor_disable_connected_check_cmd,
6717 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6718 NO_STR
6719 NEIGHBOR_STR
6720 NEIGHBOR_ADDR_STR2
6721 "one-hop away EBGP peer using loopback address\n"
6722 "Enforce EBGP neighbors perform multihop\n")
6723 {
6724 int idx_peer = 2;
6725 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6726 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6727 }
6728
6729 /* disable-link-bw-encoding-ieee */
6730 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6731 neighbor_disable_link_bw_encoding_ieee_cmd,
6732 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6734 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6735 {
6736 int idx_peer = 1;
6737
6738 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6739 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6740 }
6741
6742 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6743 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6744 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6746 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6747 {
6748 int idx_peer = 2;
6749
6750 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6751 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6752 }
6753
6754 /* extended-optional-parameters */
6755 DEFUN(neighbor_extended_optional_parameters,
6756 neighbor_extended_optional_parameters_cmd,
6757 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6758 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6759 "Force the extended optional parameters format for OPEN messages\n")
6760 {
6761 int idx_peer = 1;
6762
6763 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6764 PEER_FLAG_EXTENDED_OPT_PARAMS);
6765 }
6766
6767 DEFUN(no_neighbor_extended_optional_parameters,
6768 no_neighbor_extended_optional_parameters_cmd,
6769 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6770 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6771 "Force the extended optional parameters format for OPEN messages\n")
6772 {
6773 int idx_peer = 2;
6774
6775 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6776 PEER_FLAG_EXTENDED_OPT_PARAMS);
6777 }
6778
6779 /* enforce-first-as */
6780 DEFUN (neighbor_enforce_first_as,
6781 neighbor_enforce_first_as_cmd,
6782 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6783 NEIGHBOR_STR
6784 NEIGHBOR_ADDR_STR2
6785 "Enforce the first AS for EBGP routes\n")
6786 {
6787 int idx_peer = 1;
6788
6789 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6790 PEER_FLAG_ENFORCE_FIRST_AS);
6791 }
6792
6793 DEFUN (no_neighbor_enforce_first_as,
6794 no_neighbor_enforce_first_as_cmd,
6795 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6796 NO_STR
6797 NEIGHBOR_STR
6798 NEIGHBOR_ADDR_STR2
6799 "Enforce the first AS for EBGP routes\n")
6800 {
6801 int idx_peer = 2;
6802
6803 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6804 PEER_FLAG_ENFORCE_FIRST_AS);
6805 }
6806
6807
6808 DEFUN (neighbor_description,
6809 neighbor_description_cmd,
6810 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6811 NEIGHBOR_STR
6812 NEIGHBOR_ADDR_STR2
6813 "Neighbor specific description\n"
6814 "Up to 80 characters describing this neighbor\n")
6815 {
6816 int idx_peer = 1;
6817 int idx_line = 3;
6818 struct peer *peer;
6819 char *str;
6820
6821 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6822 if (!peer)
6823 return CMD_WARNING_CONFIG_FAILED;
6824
6825 str = argv_concat(argv, argc, idx_line);
6826
6827 peer_description_set(peer, str);
6828
6829 XFREE(MTYPE_TMP, str);
6830
6831 return CMD_SUCCESS;
6832 }
6833
6834 DEFUN (no_neighbor_description,
6835 no_neighbor_description_cmd,
6836 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6837 NO_STR
6838 NEIGHBOR_STR
6839 NEIGHBOR_ADDR_STR2
6840 "Neighbor specific description\n")
6841 {
6842 int idx_peer = 2;
6843 struct peer *peer;
6844
6845 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6846 if (!peer)
6847 return CMD_WARNING_CONFIG_FAILED;
6848
6849 peer_description_unset(peer);
6850
6851 return CMD_SUCCESS;
6852 }
6853
6854 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6855 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6856 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6857 "Neighbor specific description\n"
6858 "Up to 80 characters describing this neighbor\n")
6859
6860 /* Neighbor update-source. */
6861 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6862 const char *source_str)
6863 {
6864 struct peer *peer;
6865 struct prefix p;
6866 union sockunion su;
6867
6868 peer = peer_and_group_lookup_vty(vty, peer_str);
6869 if (!peer)
6870 return CMD_WARNING_CONFIG_FAILED;
6871
6872 if (peer->conf_if)
6873 return CMD_WARNING;
6874
6875 if (source_str) {
6876 if (str2sockunion(source_str, &su) == 0)
6877 peer_update_source_addr_set(peer, &su);
6878 else {
6879 if (str2prefix(source_str, &p)) {
6880 vty_out(vty,
6881 "%% Invalid update-source, remove prefix length \n");
6882 return CMD_WARNING_CONFIG_FAILED;
6883 } else
6884 peer_update_source_if_set(peer, source_str);
6885 }
6886 } else
6887 peer_update_source_unset(peer);
6888
6889 return CMD_SUCCESS;
6890 }
6891
6892 #define BGP_UPDATE_SOURCE_HELP_STR \
6893 "IPv4 address\n" \
6894 "IPv6 address\n" \
6895 "Interface name (requires zebra to be running)\n"
6896
6897 DEFUN (neighbor_update_source,
6898 neighbor_update_source_cmd,
6899 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6900 NEIGHBOR_STR
6901 NEIGHBOR_ADDR_STR2
6902 "Source of routing updates\n"
6903 BGP_UPDATE_SOURCE_HELP_STR)
6904 {
6905 int idx_peer = 1;
6906 int idx_peer_2 = 3;
6907 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6908 argv[idx_peer_2]->arg);
6909 }
6910
6911 DEFUN (no_neighbor_update_source,
6912 no_neighbor_update_source_cmd,
6913 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6914 NO_STR
6915 NEIGHBOR_STR
6916 NEIGHBOR_ADDR_STR2
6917 "Source of routing updates\n"
6918 BGP_UPDATE_SOURCE_HELP_STR)
6919 {
6920 int idx_peer = 2;
6921 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6922 }
6923
6924 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6925 afi_t afi, safi_t safi,
6926 const char *rmap, int set)
6927 {
6928 int ret;
6929 struct peer *peer;
6930 struct route_map *route_map = NULL;
6931
6932 peer = peer_and_group_lookup_vty(vty, peer_str);
6933 if (!peer)
6934 return CMD_WARNING_CONFIG_FAILED;
6935
6936 if (set) {
6937 if (rmap)
6938 route_map = route_map_lookup_warn_noexist(vty, rmap);
6939 ret = peer_default_originate_set(peer, afi, safi,
6940 rmap, route_map);
6941 } else
6942 ret = peer_default_originate_unset(peer, afi, safi);
6943
6944 return bgp_vty_return(vty, ret);
6945 }
6946
6947 /* neighbor default-originate. */
6948 DEFUN (neighbor_default_originate,
6949 neighbor_default_originate_cmd,
6950 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6951 NEIGHBOR_STR
6952 NEIGHBOR_ADDR_STR2
6953 "Originate default route to this neighbor\n")
6954 {
6955 int idx_peer = 1;
6956 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6957 bgp_node_afi(vty),
6958 bgp_node_safi(vty), NULL, 1);
6959 }
6960
6961 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6962 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6963 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6964 "Originate default route to this neighbor\n")
6965
6966 DEFUN (neighbor_default_originate_rmap,
6967 neighbor_default_originate_rmap_cmd,
6968 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6969 NEIGHBOR_STR
6970 NEIGHBOR_ADDR_STR2
6971 "Originate default route to this neighbor\n"
6972 "Route-map to specify criteria to originate default\n"
6973 "route-map name\n")
6974 {
6975 int idx_peer = 1;
6976 int idx_word = 4;
6977 return peer_default_originate_set_vty(
6978 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6979 argv[idx_word]->arg, 1);
6980 }
6981
6982 ALIAS_HIDDEN(
6983 neighbor_default_originate_rmap,
6984 neighbor_default_originate_rmap_hidden_cmd,
6985 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6987 "Originate default route to this neighbor\n"
6988 "Route-map to specify criteria to originate default\n"
6989 "route-map name\n")
6990
6991 DEFUN (no_neighbor_default_originate,
6992 no_neighbor_default_originate_cmd,
6993 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6994 NO_STR
6995 NEIGHBOR_STR
6996 NEIGHBOR_ADDR_STR2
6997 "Originate default route to this neighbor\n"
6998 "Route-map to specify criteria to originate default\n"
6999 "route-map name\n")
7000 {
7001 int idx_peer = 2;
7002 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7003 bgp_node_afi(vty),
7004 bgp_node_safi(vty), NULL, 0);
7005 }
7006
7007 ALIAS_HIDDEN(
7008 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7009 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
7010 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7011 "Originate default route to this neighbor\n"
7012 "Route-map to specify criteria to originate default\n"
7013 "route-map name\n")
7014
7015
7016 /* Set neighbor's BGP port. */
7017 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7018 const char *port_str)
7019 {
7020 struct peer *peer;
7021 uint16_t port;
7022 struct servent *sp;
7023
7024 peer = peer_and_group_lookup_vty(vty, ip_str);
7025 if (!peer)
7026 return CMD_WARNING_CONFIG_FAILED;
7027
7028 if (!port_str) {
7029 sp = getservbyname("bgp", "tcp");
7030 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7031 } else {
7032 port = strtoul(port_str, NULL, 10);
7033 }
7034
7035 peer_port_set(peer, port);
7036
7037 return CMD_SUCCESS;
7038 }
7039
7040 /* Set specified peer's BGP port. */
7041 DEFUN (neighbor_port,
7042 neighbor_port_cmd,
7043 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7044 NEIGHBOR_STR
7045 NEIGHBOR_ADDR_STR2
7046 "Neighbor's BGP port\n"
7047 "TCP port number\n")
7048 {
7049 int idx_ip = 1;
7050 int idx_number = 3;
7051 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7052 argv[idx_number]->arg);
7053 }
7054
7055 DEFUN (no_neighbor_port,
7056 no_neighbor_port_cmd,
7057 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7058 NO_STR
7059 NEIGHBOR_STR
7060 NEIGHBOR_ADDR_STR2
7061 "Neighbor's BGP port\n"
7062 "TCP port number\n")
7063 {
7064 int idx_ip = 2;
7065 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7066 }
7067
7068
7069 /* neighbor weight. */
7070 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7071 safi_t safi, const char *weight_str)
7072 {
7073 int ret;
7074 struct peer *peer;
7075 unsigned long weight;
7076
7077 peer = peer_and_group_lookup_vty(vty, ip_str);
7078 if (!peer)
7079 return CMD_WARNING_CONFIG_FAILED;
7080
7081 weight = strtoul(weight_str, NULL, 10);
7082
7083 ret = peer_weight_set(peer, afi, safi, weight);
7084 return bgp_vty_return(vty, ret);
7085 }
7086
7087 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7088 safi_t safi)
7089 {
7090 int ret;
7091 struct peer *peer;
7092
7093 peer = peer_and_group_lookup_vty(vty, ip_str);
7094 if (!peer)
7095 return CMD_WARNING_CONFIG_FAILED;
7096
7097 ret = peer_weight_unset(peer, afi, safi);
7098 return bgp_vty_return(vty, ret);
7099 }
7100
7101 DEFUN (neighbor_weight,
7102 neighbor_weight_cmd,
7103 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7104 NEIGHBOR_STR
7105 NEIGHBOR_ADDR_STR2
7106 "Set default weight for routes from this neighbor\n"
7107 "default weight\n")
7108 {
7109 int idx_peer = 1;
7110 int idx_number = 3;
7111 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7112 bgp_node_safi(vty), argv[idx_number]->arg);
7113 }
7114
7115 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7116 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7118 "Set default weight for routes from this neighbor\n"
7119 "default weight\n")
7120
7121 DEFUN (no_neighbor_weight,
7122 no_neighbor_weight_cmd,
7123 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7124 NO_STR
7125 NEIGHBOR_STR
7126 NEIGHBOR_ADDR_STR2
7127 "Set default weight for routes from this neighbor\n"
7128 "default weight\n")
7129 {
7130 int idx_peer = 2;
7131 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7132 bgp_node_afi(vty), bgp_node_safi(vty));
7133 }
7134
7135 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7136 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7137 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7138 "Set default weight for routes from this neighbor\n"
7139 "default weight\n")
7140
7141
7142 /* Override capability negotiation. */
7143 DEFUN (neighbor_override_capability,
7144 neighbor_override_capability_cmd,
7145 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7146 NEIGHBOR_STR
7147 NEIGHBOR_ADDR_STR2
7148 "Override capability negotiation result\n")
7149 {
7150 int idx_peer = 1;
7151 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7152 PEER_FLAG_OVERRIDE_CAPABILITY);
7153 }
7154
7155 DEFUN (no_neighbor_override_capability,
7156 no_neighbor_override_capability_cmd,
7157 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7158 NO_STR
7159 NEIGHBOR_STR
7160 NEIGHBOR_ADDR_STR2
7161 "Override capability negotiation result\n")
7162 {
7163 int idx_peer = 2;
7164 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7165 PEER_FLAG_OVERRIDE_CAPABILITY);
7166 }
7167
7168 DEFUN (neighbor_strict_capability,
7169 neighbor_strict_capability_cmd,
7170 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7171 NEIGHBOR_STR
7172 NEIGHBOR_ADDR_STR2
7173 "Strict capability negotiation match\n")
7174 {
7175 int idx_peer = 1;
7176
7177 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7178 PEER_FLAG_STRICT_CAP_MATCH);
7179 }
7180
7181 DEFUN (no_neighbor_strict_capability,
7182 no_neighbor_strict_capability_cmd,
7183 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7184 NO_STR
7185 NEIGHBOR_STR
7186 NEIGHBOR_ADDR_STR2
7187 "Strict capability negotiation match\n")
7188 {
7189 int idx_peer = 2;
7190
7191 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7192 PEER_FLAG_STRICT_CAP_MATCH);
7193 }
7194
7195 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7196 const char *keep_str, const char *hold_str)
7197 {
7198 int ret;
7199 struct peer *peer;
7200 uint32_t keepalive;
7201 uint32_t holdtime;
7202
7203 peer = peer_and_group_lookup_vty(vty, ip_str);
7204 if (!peer)
7205 return CMD_WARNING_CONFIG_FAILED;
7206
7207 keepalive = strtoul(keep_str, NULL, 10);
7208 holdtime = strtoul(hold_str, NULL, 10);
7209
7210 ret = peer_timers_set(peer, keepalive, holdtime);
7211
7212 return bgp_vty_return(vty, ret);
7213 }
7214
7215 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7216 {
7217 int ret;
7218 struct peer *peer;
7219
7220 peer = peer_and_group_lookup_vty(vty, ip_str);
7221 if (!peer)
7222 return CMD_WARNING_CONFIG_FAILED;
7223
7224 ret = peer_timers_unset(peer);
7225
7226 return bgp_vty_return(vty, ret);
7227 }
7228
7229 DEFUN (neighbor_timers,
7230 neighbor_timers_cmd,
7231 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7232 NEIGHBOR_STR
7233 NEIGHBOR_ADDR_STR2
7234 "BGP per neighbor timers\n"
7235 "Keepalive interval\n"
7236 "Holdtime\n")
7237 {
7238 int idx_peer = 1;
7239 int idx_number = 3;
7240 int idx_number_2 = 4;
7241 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7242 argv[idx_number]->arg,
7243 argv[idx_number_2]->arg);
7244 }
7245
7246 DEFUN (no_neighbor_timers,
7247 no_neighbor_timers_cmd,
7248 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7249 NO_STR
7250 NEIGHBOR_STR
7251 NEIGHBOR_ADDR_STR2
7252 "BGP per neighbor timers\n"
7253 "Keepalive interval\n"
7254 "Holdtime\n")
7255 {
7256 int idx_peer = 2;
7257 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7258 }
7259
7260
7261 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7262 const char *time_str)
7263 {
7264 int ret;
7265 struct peer *peer;
7266 uint32_t connect;
7267
7268 peer = peer_and_group_lookup_vty(vty, ip_str);
7269 if (!peer)
7270 return CMD_WARNING_CONFIG_FAILED;
7271
7272 connect = strtoul(time_str, NULL, 10);
7273
7274 ret = peer_timers_connect_set(peer, connect);
7275
7276 return bgp_vty_return(vty, ret);
7277 }
7278
7279 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7280 {
7281 int ret;
7282 struct peer *peer;
7283
7284 peer = peer_and_group_lookup_vty(vty, ip_str);
7285 if (!peer)
7286 return CMD_WARNING_CONFIG_FAILED;
7287
7288 ret = peer_timers_connect_unset(peer);
7289
7290 return bgp_vty_return(vty, ret);
7291 }
7292
7293 DEFUN (neighbor_timers_connect,
7294 neighbor_timers_connect_cmd,
7295 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7296 NEIGHBOR_STR
7297 NEIGHBOR_ADDR_STR2
7298 "BGP per neighbor timers\n"
7299 "BGP connect timer\n"
7300 "Connect timer\n")
7301 {
7302 int idx_peer = 1;
7303 int idx_number = 4;
7304 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7305 argv[idx_number]->arg);
7306 }
7307
7308 DEFUN (no_neighbor_timers_connect,
7309 no_neighbor_timers_connect_cmd,
7310 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7311 NO_STR
7312 NEIGHBOR_STR
7313 NEIGHBOR_ADDR_STR2
7314 "BGP per neighbor timers\n"
7315 "BGP connect timer\n"
7316 "Connect timer\n")
7317 {
7318 int idx_peer = 2;
7319 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7320 }
7321
7322 DEFPY (neighbor_timers_delayopen,
7323 neighbor_timers_delayopen_cmd,
7324 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7325 NEIGHBOR_STR
7326 NEIGHBOR_ADDR_STR2
7327 "BGP per neighbor timers\n"
7328 "RFC 4271 DelayOpenTimer\n"
7329 "DelayOpenTime timer interval\n")
7330 {
7331 struct peer *peer;
7332
7333 peer = peer_and_group_lookup_vty(vty, neighbor);
7334 if (!peer)
7335 return CMD_WARNING_CONFIG_FAILED;
7336
7337 if (!interval) {
7338 if (peer_timers_delayopen_unset(peer))
7339 return CMD_WARNING_CONFIG_FAILED;
7340 } else {
7341 if (peer_timers_delayopen_set(peer, interval))
7342 return CMD_WARNING_CONFIG_FAILED;
7343 }
7344
7345 return CMD_SUCCESS;
7346 }
7347
7348 DEFPY (no_neighbor_timers_delayopen,
7349 no_neighbor_timers_delayopen_cmd,
7350 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7351 NO_STR
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 (peer_timers_delayopen_unset(peer))
7365 return CMD_WARNING_CONFIG_FAILED;
7366
7367 return CMD_SUCCESS;
7368 }
7369
7370 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7371 const char *time_str, int set)
7372 {
7373 int ret;
7374 struct peer *peer;
7375 uint32_t routeadv = 0;
7376
7377 peer = peer_and_group_lookup_vty(vty, ip_str);
7378 if (!peer)
7379 return CMD_WARNING_CONFIG_FAILED;
7380
7381 if (time_str)
7382 routeadv = strtoul(time_str, NULL, 10);
7383
7384 if (set)
7385 ret = peer_advertise_interval_set(peer, routeadv);
7386 else
7387 ret = peer_advertise_interval_unset(peer);
7388
7389 return bgp_vty_return(vty, ret);
7390 }
7391
7392 DEFUN (neighbor_advertise_interval,
7393 neighbor_advertise_interval_cmd,
7394 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7395 NEIGHBOR_STR
7396 NEIGHBOR_ADDR_STR2
7397 "Minimum interval between sending BGP routing updates\n"
7398 "time in seconds\n")
7399 {
7400 int idx_peer = 1;
7401 int idx_number = 3;
7402 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7403 argv[idx_number]->arg, 1);
7404 }
7405
7406 DEFUN (no_neighbor_advertise_interval,
7407 no_neighbor_advertise_interval_cmd,
7408 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7409 NO_STR
7410 NEIGHBOR_STR
7411 NEIGHBOR_ADDR_STR2
7412 "Minimum interval between sending BGP routing updates\n"
7413 "time in seconds\n")
7414 {
7415 int idx_peer = 2;
7416 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7417 }
7418
7419
7420 /* Time to wait before processing route-map updates */
7421 DEFUN (bgp_set_route_map_delay_timer,
7422 bgp_set_route_map_delay_timer_cmd,
7423 "bgp route-map delay-timer (0-600)",
7424 SET_STR
7425 "BGP route-map delay timer\n"
7426 "Time in secs to wait before processing route-map changes\n"
7427 "0 disables the timer, no route updates happen when route-maps change\n")
7428 {
7429 int idx_number = 3;
7430 uint32_t rmap_delay_timer;
7431
7432 if (argv[idx_number]->arg) {
7433 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7434 bm->rmap_update_timer = rmap_delay_timer;
7435
7436 /* if the dynamic update handling is being disabled, and a timer
7437 * is
7438 * running, stop the timer and act as if the timer has already
7439 * fired.
7440 */
7441 if (!rmap_delay_timer && bm->t_rmap_update) {
7442 THREAD_OFF(bm->t_rmap_update);
7443 thread_execute(bm->master, bgp_route_map_update_timer,
7444 NULL, 0);
7445 }
7446 return CMD_SUCCESS;
7447 } else {
7448 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7449 return CMD_WARNING_CONFIG_FAILED;
7450 }
7451 }
7452
7453 DEFUN (no_bgp_set_route_map_delay_timer,
7454 no_bgp_set_route_map_delay_timer_cmd,
7455 "no bgp route-map delay-timer [(0-600)]",
7456 NO_STR
7457 BGP_STR
7458 "Default BGP route-map delay timer\n"
7459 "Reset to default time to wait for processing route-map changes\n"
7460 "0 disables the timer, no route updates happen when route-maps change\n")
7461 {
7462
7463 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7464
7465 return CMD_SUCCESS;
7466 }
7467
7468 /* neighbor interface */
7469 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7470 const char *str)
7471 {
7472 struct peer *peer;
7473
7474 peer = peer_lookup_vty(vty, ip_str);
7475 if (!peer || peer->conf_if) {
7476 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7477 return CMD_WARNING_CONFIG_FAILED;
7478 }
7479
7480 if (str)
7481 peer_interface_set(peer, str);
7482 else
7483 peer_interface_unset(peer);
7484
7485 return CMD_SUCCESS;
7486 }
7487
7488 DEFUN (neighbor_interface,
7489 neighbor_interface_cmd,
7490 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7491 NEIGHBOR_STR
7492 NEIGHBOR_ADDR_STR
7493 "Interface\n"
7494 "Interface name\n")
7495 {
7496 int idx_ip = 1;
7497 int idx_word = 3;
7498
7499 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7500 }
7501
7502 DEFUN (no_neighbor_interface,
7503 no_neighbor_interface_cmd,
7504 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7505 NO_STR
7506 NEIGHBOR_STR
7507 NEIGHBOR_ADDR_STR
7508 "Interface\n"
7509 "Interface name\n")
7510 {
7511 int idx_peer = 2;
7512
7513 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7514 }
7515
7516 DEFUN (neighbor_distribute_list,
7517 neighbor_distribute_list_cmd,
7518 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7519 NEIGHBOR_STR
7520 NEIGHBOR_ADDR_STR2
7521 "Filter updates to/from this neighbor\n"
7522 "IP Access-list name\n"
7523 "Filter incoming updates\n"
7524 "Filter outgoing updates\n")
7525 {
7526 int idx_peer = 1;
7527 int idx_acl = 3;
7528 int direct, ret;
7529 struct peer *peer;
7530
7531 const char *pstr = argv[idx_peer]->arg;
7532 const char *acl = argv[idx_acl]->arg;
7533 const char *inout = argv[argc - 1]->text;
7534
7535 peer = peer_and_group_lookup_vty(vty, pstr);
7536 if (!peer)
7537 return CMD_WARNING_CONFIG_FAILED;
7538
7539 /* Check filter direction. */
7540 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7541 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7542 direct, acl);
7543
7544 return bgp_vty_return(vty, ret);
7545 }
7546
7547 ALIAS_HIDDEN(
7548 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7549 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7551 "Filter updates to/from this neighbor\n"
7552 "IP Access-list name\n"
7553 "Filter incoming updates\n"
7554 "Filter outgoing updates\n")
7555
7556 DEFUN (no_neighbor_distribute_list,
7557 no_neighbor_distribute_list_cmd,
7558 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7559 NO_STR
7560 NEIGHBOR_STR
7561 NEIGHBOR_ADDR_STR2
7562 "Filter updates to/from this neighbor\n"
7563 "IP Access-list name\n"
7564 "Filter incoming updates\n"
7565 "Filter outgoing updates\n")
7566 {
7567 int idx_peer = 2;
7568 int direct, ret;
7569 struct peer *peer;
7570
7571 const char *pstr = argv[idx_peer]->arg;
7572 const char *inout = argv[argc - 1]->text;
7573
7574 peer = peer_and_group_lookup_vty(vty, pstr);
7575 if (!peer)
7576 return CMD_WARNING_CONFIG_FAILED;
7577
7578 /* Check filter direction. */
7579 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7580 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7581 direct);
7582
7583 return bgp_vty_return(vty, ret);
7584 }
7585
7586 ALIAS_HIDDEN(
7587 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7588 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7589 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7590 "Filter updates to/from this neighbor\n"
7591 "IP Access-list name\n"
7592 "Filter incoming updates\n"
7593 "Filter outgoing updates\n")
7594
7595 /* Set prefix list to the peer. */
7596 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7597 afi_t afi, safi_t safi,
7598 const char *name_str,
7599 const char *direct_str)
7600 {
7601 int ret;
7602 int direct = FILTER_IN;
7603 struct peer *peer;
7604
7605 peer = peer_and_group_lookup_vty(vty, ip_str);
7606 if (!peer)
7607 return CMD_WARNING_CONFIG_FAILED;
7608
7609 /* Check filter direction. */
7610 if (strncmp(direct_str, "i", 1) == 0)
7611 direct = FILTER_IN;
7612 else if (strncmp(direct_str, "o", 1) == 0)
7613 direct = FILTER_OUT;
7614
7615 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7616
7617 return bgp_vty_return(vty, ret);
7618 }
7619
7620 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7621 afi_t afi, safi_t safi,
7622 const char *direct_str)
7623 {
7624 int ret;
7625 struct peer *peer;
7626 int direct = FILTER_IN;
7627
7628 peer = peer_and_group_lookup_vty(vty, ip_str);
7629 if (!peer)
7630 return CMD_WARNING_CONFIG_FAILED;
7631
7632 /* Check filter direction. */
7633 if (strncmp(direct_str, "i", 1) == 0)
7634 direct = FILTER_IN;
7635 else if (strncmp(direct_str, "o", 1) == 0)
7636 direct = FILTER_OUT;
7637
7638 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7639
7640 return bgp_vty_return(vty, ret);
7641 }
7642
7643 DEFUN (neighbor_prefix_list,
7644 neighbor_prefix_list_cmd,
7645 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7646 NEIGHBOR_STR
7647 NEIGHBOR_ADDR_STR2
7648 "Filter updates to/from this neighbor\n"
7649 "Name of a prefix list\n"
7650 "Filter incoming updates\n"
7651 "Filter outgoing updates\n")
7652 {
7653 int idx_peer = 1;
7654 int idx_word = 3;
7655 int idx_in_out = 4;
7656 return peer_prefix_list_set_vty(
7657 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7658 argv[idx_word]->arg, argv[idx_in_out]->arg);
7659 }
7660
7661 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7662 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7663 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7664 "Filter updates to/from this neighbor\n"
7665 "Name of a prefix list\n"
7666 "Filter incoming updates\n"
7667 "Filter outgoing updates\n")
7668
7669 DEFUN (no_neighbor_prefix_list,
7670 no_neighbor_prefix_list_cmd,
7671 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7672 NO_STR
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 = 2;
7681 int idx_in_out = 5;
7682 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7683 bgp_node_afi(vty), bgp_node_safi(vty),
7684 argv[idx_in_out]->arg);
7685 }
7686
7687 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7688 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7690 "Filter updates to/from this neighbor\n"
7691 "Name of a prefix list\n"
7692 "Filter incoming updates\n"
7693 "Filter outgoing updates\n")
7694
7695 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7696 safi_t safi, const char *name_str,
7697 const char *direct_str)
7698 {
7699 int ret;
7700 struct peer *peer;
7701 int direct = FILTER_IN;
7702
7703 peer = peer_and_group_lookup_vty(vty, ip_str);
7704 if (!peer)
7705 return CMD_WARNING_CONFIG_FAILED;
7706
7707 /* Check filter direction. */
7708 if (strncmp(direct_str, "i", 1) == 0)
7709 direct = FILTER_IN;
7710 else if (strncmp(direct_str, "o", 1) == 0)
7711 direct = FILTER_OUT;
7712
7713 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7714
7715 return bgp_vty_return(vty, ret);
7716 }
7717
7718 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7719 safi_t safi, const char *direct_str)
7720 {
7721 int ret;
7722 struct peer *peer;
7723 int direct = FILTER_IN;
7724
7725 peer = peer_and_group_lookup_vty(vty, ip_str);
7726 if (!peer)
7727 return CMD_WARNING_CONFIG_FAILED;
7728
7729 /* Check filter direction. */
7730 if (strncmp(direct_str, "i", 1) == 0)
7731 direct = FILTER_IN;
7732 else if (strncmp(direct_str, "o", 1) == 0)
7733 direct = FILTER_OUT;
7734
7735 ret = peer_aslist_unset(peer, afi, safi, direct);
7736
7737 return bgp_vty_return(vty, ret);
7738 }
7739
7740 DEFUN (neighbor_filter_list,
7741 neighbor_filter_list_cmd,
7742 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7743 NEIGHBOR_STR
7744 NEIGHBOR_ADDR_STR2
7745 "Establish BGP filters\n"
7746 "AS path access-list name\n"
7747 "Filter incoming routes\n"
7748 "Filter outgoing routes\n")
7749 {
7750 int idx_peer = 1;
7751 int idx_word = 3;
7752 int idx_in_out = 4;
7753 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7754 bgp_node_safi(vty), argv[idx_word]->arg,
7755 argv[idx_in_out]->arg);
7756 }
7757
7758 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7759 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7761 "Establish BGP filters\n"
7762 "AS path access-list name\n"
7763 "Filter incoming routes\n"
7764 "Filter outgoing routes\n")
7765
7766 DEFUN (no_neighbor_filter_list,
7767 no_neighbor_filter_list_cmd,
7768 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7769 NO_STR
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 = 2;
7778 int idx_in_out = 5;
7779 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7780 bgp_node_afi(vty), bgp_node_safi(vty),
7781 argv[idx_in_out]->arg);
7782 }
7783
7784 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7785 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7786 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7787 "Establish BGP filters\n"
7788 "AS path access-list name\n"
7789 "Filter incoming routes\n"
7790 "Filter outgoing routes\n")
7791
7792 /* Set advertise-map to the peer. */
7793 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7794 afi_t afi, safi_t safi,
7795 const char *advertise_str,
7796 const char *condition_str, bool condition,
7797 bool set)
7798 {
7799 int ret = CMD_WARNING_CONFIG_FAILED;
7800 struct peer *peer;
7801 struct route_map *advertise_map;
7802 struct route_map *condition_map;
7803
7804 peer = peer_and_group_lookup_vty(vty, ip_str);
7805 if (!peer)
7806 return ret;
7807
7808 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7809 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7810
7811 if (set)
7812 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7813 advertise_map, condition_str,
7814 condition_map, condition);
7815 else
7816 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7817 advertise_map, condition_str,
7818 condition_map, condition);
7819
7820 return bgp_vty_return(vty, ret);
7821 }
7822
7823 DEFPY (bgp_condadv_period,
7824 bgp_condadv_period_cmd,
7825 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7826 NO_STR
7827 BGP_STR
7828 "Conditional advertisement settings\n"
7829 "Set period to rescan BGP table to check if condition is met\n"
7830 "Period between BGP table scans, in seconds; default 60\n")
7831 {
7832 VTY_DECLVAR_CONTEXT(bgp, bgp);
7833
7834 bgp->condition_check_period =
7835 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7836
7837 return CMD_SUCCESS;
7838 }
7839
7840 DEFPY (neighbor_advertise_map,
7841 neighbor_advertise_map_cmd,
7842 "[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",
7843 NO_STR
7844 NEIGHBOR_STR
7845 NEIGHBOR_ADDR_STR2
7846 "Route-map to conditionally advertise routes\n"
7847 "Name of advertise map\n"
7848 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7849 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7850 "Name of the exist or non exist map\n")
7851 {
7852 bool condition = CONDITION_EXIST;
7853
7854 if (!strcmp(exist, "non-exist-map"))
7855 condition = CONDITION_NON_EXIST;
7856
7857 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7858 bgp_node_safi(vty), advertise_str,
7859 condition_str, condition, !no);
7860 }
7861
7862 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7863 "[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",
7864 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7865 "Route-map to conditionally advertise routes\n"
7866 "Name of advertise map\n"
7867 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7868 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7869 "Name of the exist or non exist map\n")
7870
7871 /* Set route-map to the peer. */
7872 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7873 afi_t afi, safi_t safi, const char *name_str,
7874 const char *direct_str)
7875 {
7876 int ret;
7877 struct peer *peer;
7878 int direct = RMAP_IN;
7879 struct route_map *route_map;
7880
7881 peer = peer_and_group_lookup_vty(vty, ip_str);
7882 if (!peer)
7883 return CMD_WARNING_CONFIG_FAILED;
7884
7885 /* Check filter direction. */
7886 if (strncmp(direct_str, "in", 2) == 0)
7887 direct = RMAP_IN;
7888 else if (strncmp(direct_str, "o", 1) == 0)
7889 direct = RMAP_OUT;
7890
7891 route_map = route_map_lookup_warn_noexist(vty, name_str);
7892 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7893
7894 return bgp_vty_return(vty, ret);
7895 }
7896
7897 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7898 afi_t afi, safi_t safi,
7899 const char *direct_str)
7900 {
7901 int ret;
7902 struct peer *peer;
7903 int direct = RMAP_IN;
7904
7905 peer = peer_and_group_lookup_vty(vty, ip_str);
7906 if (!peer)
7907 return CMD_WARNING_CONFIG_FAILED;
7908
7909 /* Check filter direction. */
7910 if (strncmp(direct_str, "in", 2) == 0)
7911 direct = RMAP_IN;
7912 else if (strncmp(direct_str, "o", 1) == 0)
7913 direct = RMAP_OUT;
7914
7915 ret = peer_route_map_unset(peer, afi, safi, direct);
7916
7917 return bgp_vty_return(vty, ret);
7918 }
7919
7920 DEFUN (neighbor_route_map,
7921 neighbor_route_map_cmd,
7922 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7923 NEIGHBOR_STR
7924 NEIGHBOR_ADDR_STR2
7925 "Apply route map to neighbor\n"
7926 "Name of route map\n"
7927 "Apply map to incoming routes\n"
7928 "Apply map to outbound routes\n")
7929 {
7930 int idx_peer = 1;
7931 int idx_word = 3;
7932 int idx_in_out = 4;
7933 return peer_route_map_set_vty(
7934 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7935 argv[idx_word]->arg, argv[idx_in_out]->arg);
7936 }
7937
7938 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7939 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7941 "Apply route map to neighbor\n"
7942 "Name of route map\n"
7943 "Apply map to incoming routes\n"
7944 "Apply map to outbound routes\n")
7945
7946 DEFUN (no_neighbor_route_map,
7947 no_neighbor_route_map_cmd,
7948 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7949 NO_STR
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 = 2;
7958 int idx_in_out = 5;
7959 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7960 bgp_node_afi(vty), bgp_node_safi(vty),
7961 argv[idx_in_out]->arg);
7962 }
7963
7964 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7965 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7966 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7967 "Apply route map to neighbor\n"
7968 "Name of route map\n"
7969 "Apply map to incoming routes\n"
7970 "Apply map to outbound routes\n")
7971
7972 /* Set unsuppress-map to the peer. */
7973 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7974 afi_t afi, safi_t safi,
7975 const char *name_str)
7976 {
7977 int ret;
7978 struct peer *peer;
7979 struct route_map *route_map;
7980
7981 peer = peer_and_group_lookup_vty(vty, ip_str);
7982 if (!peer)
7983 return CMD_WARNING_CONFIG_FAILED;
7984
7985 route_map = route_map_lookup_warn_noexist(vty, name_str);
7986 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7987
7988 return bgp_vty_return(vty, ret);
7989 }
7990
7991 /* Unset route-map from the peer. */
7992 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7993 afi_t afi, safi_t safi)
7994 {
7995 int ret;
7996 struct peer *peer;
7997
7998 peer = peer_and_group_lookup_vty(vty, ip_str);
7999 if (!peer)
8000 return CMD_WARNING_CONFIG_FAILED;
8001
8002 ret = peer_unsuppress_map_unset(peer, afi, safi);
8003
8004 return bgp_vty_return(vty, ret);
8005 }
8006
8007 DEFUN (neighbor_unsuppress_map,
8008 neighbor_unsuppress_map_cmd,
8009 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8010 NEIGHBOR_STR
8011 NEIGHBOR_ADDR_STR2
8012 "Route-map to selectively unsuppress suppressed routes\n"
8013 "Name of route map\n")
8014 {
8015 int idx_peer = 1;
8016 int idx_word = 3;
8017 return peer_unsuppress_map_set_vty(
8018 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8019 argv[idx_word]->arg);
8020 }
8021
8022 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8023 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8024 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8025 "Route-map to selectively unsuppress suppressed routes\n"
8026 "Name of route map\n")
8027
8028 DEFUN (no_neighbor_unsuppress_map,
8029 no_neighbor_unsuppress_map_cmd,
8030 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8031 NO_STR
8032 NEIGHBOR_STR
8033 NEIGHBOR_ADDR_STR2
8034 "Route-map to selectively unsuppress suppressed routes\n"
8035 "Name of route map\n")
8036 {
8037 int idx_peer = 2;
8038 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8039 bgp_node_afi(vty),
8040 bgp_node_safi(vty));
8041 }
8042
8043 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8044 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8045 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8046 "Route-map to selectively unsuppress suppressed routes\n"
8047 "Name of route map\n")
8048
8049 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8050 afi_t afi, safi_t safi,
8051 const char *num_str,
8052 const char *threshold_str, int warning,
8053 const char *restart_str,
8054 const char *force_str)
8055 {
8056 int ret;
8057 struct peer *peer;
8058 uint32_t max;
8059 uint8_t threshold;
8060 uint16_t restart;
8061
8062 peer = peer_and_group_lookup_vty(vty, ip_str);
8063 if (!peer)
8064 return CMD_WARNING_CONFIG_FAILED;
8065
8066 max = strtoul(num_str, NULL, 10);
8067 if (threshold_str)
8068 threshold = atoi(threshold_str);
8069 else
8070 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8071
8072 if (restart_str)
8073 restart = atoi(restart_str);
8074 else
8075 restart = 0;
8076
8077 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8078 restart, force_str ? true : false);
8079
8080 return bgp_vty_return(vty, ret);
8081 }
8082
8083 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8084 afi_t afi, safi_t safi)
8085 {
8086 int ret;
8087 struct peer *peer;
8088
8089 peer = peer_and_group_lookup_vty(vty, ip_str);
8090 if (!peer)
8091 return CMD_WARNING_CONFIG_FAILED;
8092
8093 ret = peer_maximum_prefix_unset(peer, afi, safi);
8094
8095 return bgp_vty_return(vty, ret);
8096 }
8097
8098 /* Maximum number of prefix to be sent to the neighbor. */
8099 DEFUN(neighbor_maximum_prefix_out,
8100 neighbor_maximum_prefix_out_cmd,
8101 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8102 NEIGHBOR_STR
8103 NEIGHBOR_ADDR_STR2
8104 "Maximum number of prefixes to be sent to this peer\n"
8105 "Maximum no. of prefix limit\n")
8106 {
8107 int ret;
8108 int idx_peer = 1;
8109 int idx_number = 3;
8110 struct peer *peer;
8111 uint32_t max;
8112 afi_t afi = bgp_node_afi(vty);
8113 safi_t safi = bgp_node_safi(vty);
8114
8115 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8116 if (!peer)
8117 return CMD_WARNING_CONFIG_FAILED;
8118
8119 max = strtoul(argv[idx_number]->arg, NULL, 10);
8120
8121 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8122
8123 return bgp_vty_return(vty, ret);
8124 }
8125
8126 DEFUN(no_neighbor_maximum_prefix_out,
8127 no_neighbor_maximum_prefix_out_cmd,
8128 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8129 NO_STR
8130 NEIGHBOR_STR
8131 NEIGHBOR_ADDR_STR2
8132 "Maximum number of prefixes to be sent to this peer\n"
8133 "Maximum no. of prefix limit\n")
8134 {
8135 int ret;
8136 int idx_peer = 2;
8137 struct peer *peer;
8138 afi_t afi = bgp_node_afi(vty);
8139 safi_t safi = bgp_node_safi(vty);
8140
8141 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8142 if (!peer)
8143 return CMD_WARNING_CONFIG_FAILED;
8144
8145 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8146
8147 return bgp_vty_return(vty, ret);
8148 }
8149
8150 /* Maximum number of prefix configuration. Prefix count is different
8151 for each peer configuration. So this configuration can be set for
8152 each peer configuration. */
8153 DEFUN (neighbor_maximum_prefix,
8154 neighbor_maximum_prefix_cmd,
8155 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8156 NEIGHBOR_STR
8157 NEIGHBOR_ADDR_STR2
8158 "Maximum number of prefix accept from this peer\n"
8159 "maximum no. of prefix limit\n"
8160 "Force checking all received routes not only accepted\n")
8161 {
8162 int idx_peer = 1;
8163 int idx_number = 3;
8164 int idx_force = 0;
8165 char *force = NULL;
8166
8167 if (argv_find(argv, argc, "force", &idx_force))
8168 force = argv[idx_force]->arg;
8169
8170 return peer_maximum_prefix_set_vty(
8171 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8172 argv[idx_number]->arg, NULL, 0, NULL, force);
8173 }
8174
8175 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8176 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8177 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8178 "Maximum number of prefix accept from this peer\n"
8179 "maximum no. of prefix limit\n"
8180 "Force checking all received routes not only accepted\n")
8181
8182 DEFUN (neighbor_maximum_prefix_threshold,
8183 neighbor_maximum_prefix_threshold_cmd,
8184 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8185 NEIGHBOR_STR
8186 NEIGHBOR_ADDR_STR2
8187 "Maximum number of prefix accept from this peer\n"
8188 "maximum no. of prefix limit\n"
8189 "Threshold value (%) at which to generate a warning msg\n"
8190 "Force checking all received routes not only accepted\n")
8191 {
8192 int idx_peer = 1;
8193 int idx_number = 3;
8194 int idx_number_2 = 4;
8195 int idx_force = 0;
8196 char *force = NULL;
8197
8198 if (argv_find(argv, argc, "force", &idx_force))
8199 force = argv[idx_force]->arg;
8200
8201 return peer_maximum_prefix_set_vty(
8202 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8203 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8204 }
8205
8206 ALIAS_HIDDEN(
8207 neighbor_maximum_prefix_threshold,
8208 neighbor_maximum_prefix_threshold_hidden_cmd,
8209 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8210 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8211 "Maximum number of prefix accept from this peer\n"
8212 "maximum no. of prefix limit\n"
8213 "Threshold value (%) at which to generate a warning msg\n"
8214 "Force checking all received routes not only accepted\n")
8215
8216 DEFUN (neighbor_maximum_prefix_warning,
8217 neighbor_maximum_prefix_warning_cmd,
8218 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8219 NEIGHBOR_STR
8220 NEIGHBOR_ADDR_STR2
8221 "Maximum number of prefix accept from this peer\n"
8222 "maximum no. of prefix limit\n"
8223 "Only give warning message when limit is exceeded\n"
8224 "Force checking all received routes not only accepted\n")
8225 {
8226 int idx_peer = 1;
8227 int idx_number = 3;
8228 int idx_force = 0;
8229 char *force = NULL;
8230
8231 if (argv_find(argv, argc, "force", &idx_force))
8232 force = argv[idx_force]->arg;
8233
8234 return peer_maximum_prefix_set_vty(
8235 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8236 argv[idx_number]->arg, NULL, 1, NULL, force);
8237 }
8238
8239 ALIAS_HIDDEN(
8240 neighbor_maximum_prefix_warning,
8241 neighbor_maximum_prefix_warning_hidden_cmd,
8242 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8243 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8244 "Maximum number of prefix accept from this peer\n"
8245 "maximum no. of prefix limit\n"
8246 "Only give warning message when limit is exceeded\n"
8247 "Force checking all received routes not only accepted\n")
8248
8249 DEFUN (neighbor_maximum_prefix_threshold_warning,
8250 neighbor_maximum_prefix_threshold_warning_cmd,
8251 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8252 NEIGHBOR_STR
8253 NEIGHBOR_ADDR_STR2
8254 "Maximum number of prefix accept from this peer\n"
8255 "maximum no. of prefix limit\n"
8256 "Threshold value (%) at which to generate a warning msg\n"
8257 "Only give warning message when limit is exceeded\n"
8258 "Force checking all received routes not only accepted\n")
8259 {
8260 int idx_peer = 1;
8261 int idx_number = 3;
8262 int idx_number_2 = 4;
8263 int idx_force = 0;
8264 char *force = NULL;
8265
8266 if (argv_find(argv, argc, "force", &idx_force))
8267 force = argv[idx_force]->arg;
8268
8269 return peer_maximum_prefix_set_vty(
8270 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8271 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8272 }
8273
8274 ALIAS_HIDDEN(
8275 neighbor_maximum_prefix_threshold_warning,
8276 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8277 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8279 "Maximum number of prefix accept from this peer\n"
8280 "maximum no. of prefix limit\n"
8281 "Threshold value (%) at which to generate a warning msg\n"
8282 "Only give warning message when limit is exceeded\n"
8283 "Force checking all received routes not only accepted\n")
8284
8285 DEFUN (neighbor_maximum_prefix_restart,
8286 neighbor_maximum_prefix_restart_cmd,
8287 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8288 NEIGHBOR_STR
8289 NEIGHBOR_ADDR_STR2
8290 "Maximum number of prefix accept from this peer\n"
8291 "maximum no. of prefix limit\n"
8292 "Restart bgp connection after limit is exceeded\n"
8293 "Restart interval in minutes\n"
8294 "Force checking all received routes not only accepted\n")
8295 {
8296 int idx_peer = 1;
8297 int idx_number = 3;
8298 int idx_number_2 = 5;
8299 int idx_force = 0;
8300 char *force = NULL;
8301
8302 if (argv_find(argv, argc, "force", &idx_force))
8303 force = argv[idx_force]->arg;
8304
8305 return peer_maximum_prefix_set_vty(
8306 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8307 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8308 }
8309
8310 ALIAS_HIDDEN(
8311 neighbor_maximum_prefix_restart,
8312 neighbor_maximum_prefix_restart_hidden_cmd,
8313 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8314 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8315 "Maximum number of prefix accept from this peer\n"
8316 "maximum no. of prefix limit\n"
8317 "Restart bgp connection after limit is exceeded\n"
8318 "Restart interval in minutes\n"
8319 "Force checking all received routes not only accepted\n")
8320
8321 DEFUN (neighbor_maximum_prefix_threshold_restart,
8322 neighbor_maximum_prefix_threshold_restart_cmd,
8323 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8324 NEIGHBOR_STR
8325 NEIGHBOR_ADDR_STR2
8326 "Maximum number of prefixes to accept from this peer\n"
8327 "maximum no. of prefix limit\n"
8328 "Threshold value (%) at which to generate a warning msg\n"
8329 "Restart bgp connection after limit is exceeded\n"
8330 "Restart interval in minutes\n"
8331 "Force checking all received routes not only accepted\n")
8332 {
8333 int idx_peer = 1;
8334 int idx_number = 3;
8335 int idx_number_2 = 4;
8336 int idx_number_3 = 6;
8337 int idx_force = 0;
8338 char *force = NULL;
8339
8340 if (argv_find(argv, argc, "force", &idx_force))
8341 force = argv[idx_force]->arg;
8342
8343 return peer_maximum_prefix_set_vty(
8344 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8345 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8346 argv[idx_number_3]->arg, force);
8347 }
8348
8349 ALIAS_HIDDEN(
8350 neighbor_maximum_prefix_threshold_restart,
8351 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8352 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8354 "Maximum number of prefixes to accept from this peer\n"
8355 "maximum no. of prefix limit\n"
8356 "Threshold value (%) at which to generate a warning msg\n"
8357 "Restart bgp connection after limit is exceeded\n"
8358 "Restart interval in minutes\n"
8359 "Force checking all received routes not only accepted\n")
8360
8361 DEFUN (no_neighbor_maximum_prefix,
8362 no_neighbor_maximum_prefix_cmd,
8363 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8364 NO_STR
8365 NEIGHBOR_STR
8366 NEIGHBOR_ADDR_STR2
8367 "Maximum number of prefixes to accept from this peer\n"
8368 "maximum no. of prefix limit\n"
8369 "Threshold value (%) at which to generate a warning msg\n"
8370 "Restart bgp connection after limit is exceeded\n"
8371 "Restart interval in minutes\n"
8372 "Only give warning message when limit is exceeded\n"
8373 "Force checking all received routes not only accepted\n")
8374 {
8375 int idx_peer = 2;
8376 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8377 bgp_node_afi(vty),
8378 bgp_node_safi(vty));
8379 }
8380
8381 ALIAS_HIDDEN(
8382 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8383 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8384 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8385 "Maximum number of prefixes to accept from this peer\n"
8386 "maximum no. of prefix limit\n"
8387 "Threshold value (%) at which to generate a warning msg\n"
8388 "Restart bgp connection after limit is exceeded\n"
8389 "Restart interval in minutes\n"
8390 "Only give warning message when limit is exceeded\n"
8391 "Force checking all received routes not only accepted\n")
8392
8393 /* "neighbor accept-own" */
8394 DEFPY (neighbor_accept_own,
8395 neighbor_accept_own_cmd,
8396 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8397 NO_STR
8398 NEIGHBOR_STR
8399 NEIGHBOR_ADDR_STR2
8400 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8401 {
8402 struct peer *peer;
8403 afi_t afi = bgp_node_afi(vty);
8404 safi_t safi = bgp_node_safi(vty);
8405 int ret;
8406
8407 peer = peer_and_group_lookup_vty(vty, neighbor);
8408 if (!peer)
8409 return CMD_WARNING_CONFIG_FAILED;
8410
8411 if (no)
8412 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8413 else
8414 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8415
8416 return bgp_vty_return(vty, ret);
8417 }
8418
8419 /* "neighbor soo" */
8420 DEFPY (neighbor_soo,
8421 neighbor_soo_cmd,
8422 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8423 NEIGHBOR_STR
8424 NEIGHBOR_ADDR_STR2
8425 "Set the Site-of-Origin (SoO) extended community\n"
8426 "VPN extended community\n")
8427 {
8428 struct peer *peer;
8429 afi_t afi = bgp_node_afi(vty);
8430 safi_t safi = bgp_node_safi(vty);
8431 struct ecommunity *ecomm_soo;
8432
8433 peer = peer_and_group_lookup_vty(vty, neighbor);
8434 if (!peer)
8435 return CMD_WARNING_CONFIG_FAILED;
8436
8437 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8438 if (!ecomm_soo) {
8439 vty_out(vty, "%% Malformed SoO extended community\n");
8440 return CMD_WARNING;
8441 }
8442 ecommunity_str(ecomm_soo);
8443
8444 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8445 ecommunity_free(&peer->soo[afi][safi]);
8446 peer->soo[afi][safi] = ecomm_soo;
8447 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8448 }
8449
8450 return bgp_vty_return(vty,
8451 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8452 }
8453
8454 DEFPY (no_neighbor_soo,
8455 no_neighbor_soo_cmd,
8456 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8457 NO_STR
8458 NEIGHBOR_STR
8459 NEIGHBOR_ADDR_STR2
8460 "Set the Site-of-Origin (SoO) extended community\n"
8461 "VPN extended community\n")
8462 {
8463 struct peer *peer;
8464 afi_t afi = bgp_node_afi(vty);
8465 safi_t safi = bgp_node_safi(vty);
8466
8467 peer = peer_and_group_lookup_vty(vty, neighbor);
8468 if (!peer)
8469 return CMD_WARNING_CONFIG_FAILED;
8470
8471 ecommunity_free(&peer->soo[afi][safi]);
8472
8473 return bgp_vty_return(
8474 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8475 }
8476
8477 /* "neighbor allowas-in" */
8478 DEFUN (neighbor_allowas_in,
8479 neighbor_allowas_in_cmd,
8480 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8481 NEIGHBOR_STR
8482 NEIGHBOR_ADDR_STR2
8483 "Accept as-path with my AS present in it\n"
8484 "Number of occurrences of AS number\n"
8485 "Only accept my AS in the as-path if the route was originated in my AS\n")
8486 {
8487 int idx_peer = 1;
8488 int idx_number_origin = 3;
8489 int ret;
8490 int origin = 0;
8491 struct peer *peer;
8492 int allow_num = 0;
8493
8494 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8495 if (!peer)
8496 return CMD_WARNING_CONFIG_FAILED;
8497
8498 if (argc <= idx_number_origin)
8499 allow_num = 3;
8500 else {
8501 if (argv[idx_number_origin]->type == WORD_TKN)
8502 origin = 1;
8503 else
8504 allow_num = atoi(argv[idx_number_origin]->arg);
8505 }
8506
8507 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8508 allow_num, origin);
8509
8510 return bgp_vty_return(vty, ret);
8511 }
8512
8513 ALIAS_HIDDEN(
8514 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8515 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8516 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8517 "Accept as-path with my AS present in it\n"
8518 "Number of occurrences of AS number\n"
8519 "Only accept my AS in the as-path if the route was originated in my AS\n")
8520
8521 DEFUN (no_neighbor_allowas_in,
8522 no_neighbor_allowas_in_cmd,
8523 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8524 NO_STR
8525 NEIGHBOR_STR
8526 NEIGHBOR_ADDR_STR2
8527 "allow local ASN appears in aspath attribute\n"
8528 "Number of occurrences of AS number\n"
8529 "Only accept my AS in the as-path if the route was originated in my AS\n")
8530 {
8531 int idx_peer = 2;
8532 int ret;
8533 struct peer *peer;
8534
8535 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8536 if (!peer)
8537 return CMD_WARNING_CONFIG_FAILED;
8538
8539 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8540 bgp_node_safi(vty));
8541
8542 return bgp_vty_return(vty, ret);
8543 }
8544
8545 ALIAS_HIDDEN(
8546 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8547 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8548 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8549 "allow local ASN appears in aspath attribute\n"
8550 "Number of occurrences of AS number\n"
8551 "Only accept my AS in the as-path if the route was originated in my AS\n")
8552
8553 DEFUN (neighbor_ttl_security,
8554 neighbor_ttl_security_cmd,
8555 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8556 NEIGHBOR_STR
8557 NEIGHBOR_ADDR_STR2
8558 "BGP ttl-security parameters\n"
8559 "Specify the maximum number of hops to the BGP peer\n"
8560 "Number of hops to BGP peer\n")
8561 {
8562 int idx_peer = 1;
8563 int idx_number = 4;
8564 struct peer *peer;
8565 int gtsm_hops;
8566
8567 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8568 if (!peer)
8569 return CMD_WARNING_CONFIG_FAILED;
8570
8571 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8572
8573 /*
8574 * If 'neighbor swpX', then this is for directly connected peers,
8575 * we should not accept a ttl-security hops value greater than 1.
8576 */
8577 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8578 vty_out(vty,
8579 "%s is directly connected peer, hops cannot exceed 1\n",
8580 argv[idx_peer]->arg);
8581 return CMD_WARNING_CONFIG_FAILED;
8582 }
8583
8584 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8585 }
8586
8587 DEFUN (no_neighbor_ttl_security,
8588 no_neighbor_ttl_security_cmd,
8589 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8590 NO_STR
8591 NEIGHBOR_STR
8592 NEIGHBOR_ADDR_STR2
8593 "BGP ttl-security parameters\n"
8594 "Specify the maximum number of hops to the BGP peer\n"
8595 "Number of hops to BGP peer\n")
8596 {
8597 int idx_peer = 2;
8598 struct peer *peer;
8599
8600 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8601 if (!peer)
8602 return CMD_WARNING_CONFIG_FAILED;
8603
8604 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8605 }
8606
8607 /* disable-addpath-rx */
8608 DEFUN(neighbor_disable_addpath_rx,
8609 neighbor_disable_addpath_rx_cmd,
8610 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8611 NEIGHBOR_STR
8612 NEIGHBOR_ADDR_STR2
8613 "Do not accept additional paths\n")
8614 {
8615 char *peer_str = argv[1]->arg;
8616 struct peer *peer;
8617 afi_t afi = bgp_node_afi(vty);
8618 safi_t safi = bgp_node_safi(vty);
8619
8620 peer = peer_and_group_lookup_vty(vty, peer_str);
8621 if (!peer)
8622 return CMD_WARNING_CONFIG_FAILED;
8623
8624 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8625 PEER_FLAG_DISABLE_ADDPATH_RX);
8626 }
8627
8628 DEFUN(no_neighbor_disable_addpath_rx,
8629 no_neighbor_disable_addpath_rx_cmd,
8630 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8631 NO_STR
8632 NEIGHBOR_STR
8633 NEIGHBOR_ADDR_STR2
8634 "Do not accept additional paths\n")
8635 {
8636 char *peer_str = argv[2]->arg;
8637 struct peer *peer;
8638 afi_t afi = bgp_node_afi(vty);
8639 safi_t safi = bgp_node_safi(vty);
8640
8641 peer = peer_and_group_lookup_vty(vty, peer_str);
8642 if (!peer)
8643 return CMD_WARNING_CONFIG_FAILED;
8644
8645 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8646 PEER_FLAG_DISABLE_ADDPATH_RX);
8647 }
8648
8649 DEFUN (neighbor_addpath_tx_all_paths,
8650 neighbor_addpath_tx_all_paths_cmd,
8651 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8652 NEIGHBOR_STR
8653 NEIGHBOR_ADDR_STR2
8654 "Use addpath to advertise all paths to a neighbor\n")
8655 {
8656 int idx_peer = 1;
8657 struct peer *peer;
8658
8659 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8660 if (!peer)
8661 return CMD_WARNING_CONFIG_FAILED;
8662
8663 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8664 BGP_ADDPATH_ALL);
8665 return CMD_SUCCESS;
8666 }
8667
8668 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8669 neighbor_addpath_tx_all_paths_hidden_cmd,
8670 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8671 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8672 "Use addpath to advertise all paths to a neighbor\n")
8673
8674 DEFUN (no_neighbor_addpath_tx_all_paths,
8675 no_neighbor_addpath_tx_all_paths_cmd,
8676 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8677 NO_STR
8678 NEIGHBOR_STR
8679 NEIGHBOR_ADDR_STR2
8680 "Use addpath to advertise all paths to a neighbor\n")
8681 {
8682 int idx_peer = 2;
8683 struct peer *peer;
8684
8685 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8686 if (!peer)
8687 return CMD_WARNING_CONFIG_FAILED;
8688
8689 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8690 != BGP_ADDPATH_ALL) {
8691 vty_out(vty,
8692 "%% Peer not currently configured to transmit all paths.");
8693 return CMD_WARNING_CONFIG_FAILED;
8694 }
8695
8696 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8697 BGP_ADDPATH_NONE);
8698
8699 return CMD_SUCCESS;
8700 }
8701
8702 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8703 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8704 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8705 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8706 "Use addpath to advertise all paths to a neighbor\n")
8707
8708 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8709 neighbor_addpath_tx_bestpath_per_as_cmd,
8710 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8711 NEIGHBOR_STR
8712 NEIGHBOR_ADDR_STR2
8713 "Use addpath to advertise the bestpath per each neighboring AS\n")
8714 {
8715 int idx_peer = 1;
8716 struct peer *peer;
8717
8718 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8719 if (!peer)
8720 return CMD_WARNING_CONFIG_FAILED;
8721
8722 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8723 BGP_ADDPATH_BEST_PER_AS);
8724
8725 return CMD_SUCCESS;
8726 }
8727
8728 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8729 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8730 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8731 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8732 "Use addpath to advertise the bestpath per each neighboring AS\n")
8733
8734 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8735 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8736 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8737 NO_STR
8738 NEIGHBOR_STR
8739 NEIGHBOR_ADDR_STR2
8740 "Use addpath to advertise the bestpath per each neighboring AS\n")
8741 {
8742 int idx_peer = 2;
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 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8750 != BGP_ADDPATH_BEST_PER_AS) {
8751 vty_out(vty,
8752 "%% Peer not currently configured to transmit all best path per as.");
8753 return CMD_WARNING_CONFIG_FAILED;
8754 }
8755
8756 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8757 BGP_ADDPATH_NONE);
8758
8759 return CMD_SUCCESS;
8760 }
8761
8762 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8763 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8764 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8765 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8766 "Use addpath to advertise the bestpath per each neighboring AS\n")
8767
8768 DEFPY(
8769 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8770 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8771 NEIGHBOR_STR
8772 NEIGHBOR_ADDR_STR2
8773 "Detect AS loops before sending to neighbor\n")
8774 {
8775 struct peer *peer;
8776
8777 peer = peer_and_group_lookup_vty(vty, neighbor);
8778 if (!peer)
8779 return CMD_WARNING_CONFIG_FAILED;
8780
8781 peer->as_path_loop_detection = true;
8782
8783 return CMD_SUCCESS;
8784 }
8785
8786 DEFPY(
8787 no_neighbor_aspath_loop_detection,
8788 no_neighbor_aspath_loop_detection_cmd,
8789 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8790 NO_STR
8791 NEIGHBOR_STR
8792 NEIGHBOR_ADDR_STR2
8793 "Detect AS loops before sending to neighbor\n")
8794 {
8795 struct peer *peer;
8796
8797 peer = peer_and_group_lookup_vty(vty, neighbor);
8798 if (!peer)
8799 return CMD_WARNING_CONFIG_FAILED;
8800
8801 peer->as_path_loop_detection = false;
8802
8803 return CMD_SUCCESS;
8804 }
8805
8806 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8807 struct ecommunity **list, bool is_rt6)
8808 {
8809 struct ecommunity *ecom = NULL;
8810 struct ecommunity *ecomadd;
8811
8812 for (; argc; --argc, ++argv) {
8813 if (is_rt6)
8814 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8815 ECOMMUNITY_ROUTE_TARGET,
8816 0);
8817 else
8818 ecomadd = ecommunity_str2com(argv[0]->arg,
8819 ECOMMUNITY_ROUTE_TARGET,
8820 0);
8821 if (!ecomadd) {
8822 vty_out(vty, "Malformed community-list value\n");
8823 if (ecom)
8824 ecommunity_free(&ecom);
8825 return CMD_WARNING_CONFIG_FAILED;
8826 }
8827
8828 if (ecom) {
8829 ecommunity_merge(ecom, ecomadd);
8830 ecommunity_free(&ecomadd);
8831 } else {
8832 ecom = ecomadd;
8833 }
8834 }
8835
8836 if (*list) {
8837 ecommunity_free(&*list);
8838 }
8839 *list = ecom;
8840
8841 return CMD_SUCCESS;
8842 }
8843
8844 /*
8845 * v2vimport is true if we are handling a `import vrf ...` command
8846 */
8847 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8848 {
8849 afi_t afi;
8850
8851 switch (vty->node) {
8852 case BGP_IPV4_NODE:
8853 afi = AFI_IP;
8854 break;
8855 case BGP_IPV6_NODE:
8856 afi = AFI_IP6;
8857 break;
8858 default:
8859 vty_out(vty,
8860 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8861 return AFI_MAX;
8862 }
8863
8864 if (!v2vimport) {
8865 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8866 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8867 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8868 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8869 vty_out(vty,
8870 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8871 return AFI_MAX;
8872 }
8873 } else {
8874 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8875 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8876 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8877 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8878 vty_out(vty,
8879 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8880 return AFI_MAX;
8881 }
8882 }
8883 return afi;
8884 }
8885
8886 DEFPY (af_rd_vpn_export,
8887 af_rd_vpn_export_cmd,
8888 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8889 NO_STR
8890 "Specify route distinguisher\n"
8891 "Between current address-family and vpn\n"
8892 "For routes leaked from current address-family to vpn\n"
8893 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8894 {
8895 VTY_DECLVAR_CONTEXT(bgp, bgp);
8896 struct prefix_rd prd;
8897 int ret;
8898 afi_t afi;
8899 int idx = 0;
8900 bool yes = true;
8901
8902 if (argv_find(argv, argc, "no", &idx))
8903 yes = false;
8904
8905 if (yes) {
8906 ret = str2prefix_rd(rd_str, &prd);
8907 if (!ret) {
8908 vty_out(vty, "%% Malformed rd\n");
8909 return CMD_WARNING_CONFIG_FAILED;
8910 }
8911 }
8912
8913 afi = vpn_policy_getafi(vty, bgp, false);
8914 if (afi == AFI_MAX)
8915 return CMD_WARNING_CONFIG_FAILED;
8916
8917 /*
8918 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8919 */
8920 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8921 bgp_get_default(), bgp);
8922
8923 if (yes) {
8924 bgp->vpn_policy[afi].tovpn_rd = prd;
8925 SET_FLAG(bgp->vpn_policy[afi].flags,
8926 BGP_VPN_POLICY_TOVPN_RD_SET);
8927 } else {
8928 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8929 BGP_VPN_POLICY_TOVPN_RD_SET);
8930 }
8931
8932 /* post-change: re-export vpn routes */
8933 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8934 bgp_get_default(), bgp);
8935
8936 return CMD_SUCCESS;
8937 }
8938
8939 ALIAS (af_rd_vpn_export,
8940 af_no_rd_vpn_export_cmd,
8941 "no rd vpn export",
8942 NO_STR
8943 "Specify route distinguisher\n"
8944 "Between current address-family and vpn\n"
8945 "For routes leaked from current address-family to vpn\n")
8946
8947 DEFPY (af_label_vpn_export,
8948 af_label_vpn_export_cmd,
8949 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8950 NO_STR
8951 "label value for VRF\n"
8952 "Between current address-family and vpn\n"
8953 "For routes leaked from current address-family to vpn\n"
8954 "Label Value <0-1048575>\n"
8955 "Automatically assign a label\n")
8956 {
8957 VTY_DECLVAR_CONTEXT(bgp, bgp);
8958 mpls_label_t label = MPLS_LABEL_NONE;
8959 afi_t afi;
8960 int idx = 0;
8961 bool yes = true;
8962
8963 if (argv_find(argv, argc, "no", &idx))
8964 yes = false;
8965
8966 /* If "no ...", squash trailing parameter */
8967 if (!yes)
8968 label_auto = NULL;
8969
8970 if (yes) {
8971 if (!label_auto)
8972 label = label_val; /* parser should force unsigned */
8973 }
8974
8975 afi = vpn_policy_getafi(vty, bgp, false);
8976 if (afi == AFI_MAX)
8977 return CMD_WARNING_CONFIG_FAILED;
8978
8979
8980 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8981 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8982 /* no change */
8983 return CMD_SUCCESS;
8984
8985 /*
8986 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8987 */
8988 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8989 bgp_get_default(), bgp);
8990
8991 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8992 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8993
8994 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8995
8996 /*
8997 * label has previously been automatically
8998 * assigned by labelpool: release it
8999 *
9000 * NB if tovpn_label == MPLS_LABEL_NONE it
9001 * means the automatic assignment is in flight
9002 * and therefore the labelpool callback must
9003 * detect that the auto label is not needed.
9004 */
9005
9006 bgp_lp_release(LP_TYPE_VRF,
9007 &bgp->vpn_policy[afi],
9008 bgp->vpn_policy[afi].tovpn_label);
9009 }
9010 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9011 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9012 }
9013
9014 bgp->vpn_policy[afi].tovpn_label = label;
9015 if (label_auto) {
9016 SET_FLAG(bgp->vpn_policy[afi].flags,
9017 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9018 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9019 vpn_leak_label_callback);
9020 }
9021
9022 /* post-change: re-export vpn routes */
9023 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9024 bgp_get_default(), bgp);
9025
9026 hook_call(bgp_snmp_update_last_changed, bgp);
9027 return CMD_SUCCESS;
9028 }
9029
9030 DEFPY (af_sid_vpn_export,
9031 af_sid_vpn_export_cmd,
9032 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9033 NO_STR
9034 "sid value for VRF\n"
9035 "Between current address-family and vpn\n"
9036 "For routes leaked from current address-family to vpn\n"
9037 "Sid allocation index\n"
9038 "Automatically assign a label\n")
9039 {
9040 VTY_DECLVAR_CONTEXT(bgp, bgp);
9041 afi_t afi;
9042 int debug = 0;
9043 int idx = 0;
9044 bool yes = true;
9045
9046 if (argv_find(argv, argc, "no", &idx))
9047 yes = false;
9048 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9049 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9050
9051 afi = vpn_policy_getafi(vty, bgp, false);
9052 if (afi == AFI_MAX)
9053 return CMD_WARNING_CONFIG_FAILED;
9054
9055 if (!yes) {
9056 /* implement me */
9057 vty_out(vty, "It's not implemented\n");
9058 return CMD_WARNING_CONFIG_FAILED;
9059 }
9060
9061 if (bgp->tovpn_sid_index != 0 ||
9062 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9063 vty_out(vty,
9064 "per-vrf sid and per-af sid are mutually exclusive\n"
9065 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9066 return CMD_WARNING_CONFIG_FAILED;
9067 }
9068
9069 /* skip when it's already configured */
9070 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9071 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9072 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9073 return CMD_SUCCESS;
9074
9075 /*
9076 * mode change between sid_idx and sid_auto isn't supported.
9077 * user must negate sid vpn export when they want to change the mode
9078 */
9079 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9080 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9081 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9082 vty_out(vty, "it's already configured as %s.\n",
9083 sid_auto ? "auto-mode" : "idx-mode");
9084 return CMD_WARNING_CONFIG_FAILED;
9085 }
9086
9087 /* pre-change */
9088 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9089 bgp_get_default(), bgp);
9090
9091 if (sid_auto) {
9092 /* SID allocation auto-mode */
9093 if (debug)
9094 zlog_debug("%s: auto sid alloc.", __func__);
9095 SET_FLAG(bgp->vpn_policy[afi].flags,
9096 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9097 } else {
9098 /* SID allocation index-mode */
9099 if (debug)
9100 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9101 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9102 }
9103
9104 /* post-change */
9105 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9106 bgp_get_default(), bgp);
9107 return CMD_SUCCESS;
9108 }
9109
9110 DEFPY (bgp_sid_vpn_export,
9111 bgp_sid_vpn_export_cmd,
9112 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9113 NO_STR
9114 "sid value for VRF\n"
9115 "Between current vrf and vpn\n"
9116 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9117 "For routes leaked from current vrf to vpn\n"
9118 "Sid allocation index\n"
9119 "Automatically assign a label\n")
9120 {
9121 VTY_DECLVAR_CONTEXT(bgp, bgp);
9122 int debug;
9123
9124 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9125 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9126
9127 if (no) {
9128 /* when per-VRF SID is not set, do nothing */
9129 if (bgp->tovpn_sid_index == 0 &&
9130 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9131 return CMD_SUCCESS;
9132
9133 sid_idx = 0;
9134 sid_auto = false;
9135 bgp->tovpn_sid_index = 0;
9136 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9137 }
9138
9139 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9140 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9141 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9142 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9143 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9144 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9145 vty_out(vty,
9146 "per-vrf sid and per-af sid are mutually exclusive\n"
9147 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9148 return CMD_WARNING_CONFIG_FAILED;
9149 }
9150
9151 /* skip when it's already configured */
9152 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9153 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9154 return CMD_SUCCESS;
9155
9156 /*
9157 * mode change between sid_idx and sid_auto isn't supported.
9158 * user must negate sid vpn export when they want to change the mode
9159 */
9160 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9161 (sid_idx != 0 &&
9162 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9163 vty_out(vty, "it's already configured as %s.\n",
9164 sid_auto ? "auto-mode" : "idx-mode");
9165 return CMD_WARNING_CONFIG_FAILED;
9166 }
9167
9168 /* pre-change */
9169 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9170 bgp);
9171 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9172 bgp);
9173
9174 if (sid_auto) {
9175 /* SID allocation auto-mode */
9176 if (debug)
9177 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9178 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9179 } else if (sid_idx != 0) {
9180 /* SID allocation index-mode */
9181 if (debug)
9182 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9183 sid_idx);
9184 bgp->tovpn_sid_index = sid_idx;
9185 }
9186
9187 /* post-change */
9188 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9189 bgp);
9190 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9191 bgp_get_default(), bgp);
9192
9193 return CMD_SUCCESS;
9194 }
9195
9196 ALIAS (af_label_vpn_export,
9197 af_no_label_vpn_export_cmd,
9198 "no label vpn export",
9199 NO_STR
9200 "label value for VRF\n"
9201 "Between current address-family and vpn\n"
9202 "For routes leaked from current address-family to vpn\n")
9203
9204 ALIAS (bgp_sid_vpn_export,
9205 no_bgp_sid_vpn_export_cmd,
9206 "no$no sid vpn per-vrf export",
9207 NO_STR
9208 "sid value for VRF\n"
9209 "Between current vrf and vpn\n"
9210 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9211 "For routes leaked from current vrf to vpn\n")
9212
9213 DEFPY (af_nexthop_vpn_export,
9214 af_nexthop_vpn_export_cmd,
9215 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9216 NO_STR
9217 "Specify next hop to use for VRF advertised prefixes\n"
9218 "Between current address-family and vpn\n"
9219 "For routes leaked from current address-family to vpn\n"
9220 "IPv4 prefix\n"
9221 "IPv6 prefix\n")
9222 {
9223 VTY_DECLVAR_CONTEXT(bgp, bgp);
9224 afi_t afi;
9225 struct prefix p;
9226
9227 if (!no) {
9228 if (!nexthop_su) {
9229 vty_out(vty, "%% Nexthop required\n");
9230 return CMD_WARNING_CONFIG_FAILED;
9231 }
9232 if (!sockunion2hostprefix(nexthop_su, &p))
9233 return CMD_WARNING_CONFIG_FAILED;
9234 }
9235
9236 afi = vpn_policy_getafi(vty, bgp, false);
9237 if (afi == AFI_MAX)
9238 return CMD_WARNING_CONFIG_FAILED;
9239
9240 /*
9241 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9242 */
9243 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9244 bgp_get_default(), bgp);
9245
9246 if (!no) {
9247 bgp->vpn_policy[afi].tovpn_nexthop = p;
9248 SET_FLAG(bgp->vpn_policy[afi].flags,
9249 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9250 } else {
9251 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9252 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9253 }
9254
9255 /* post-change: re-export vpn routes */
9256 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9257 bgp_get_default(), bgp);
9258
9259 return CMD_SUCCESS;
9260 }
9261
9262 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9263 {
9264 if (!strcmp(dstr, "import")) {
9265 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9266 } else if (!strcmp(dstr, "export")) {
9267 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9268 } else if (!strcmp(dstr, "both")) {
9269 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9270 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9271 } else {
9272 vty_out(vty, "%% direction parse error\n");
9273 return CMD_WARNING_CONFIG_FAILED;
9274 }
9275 return CMD_SUCCESS;
9276 }
9277
9278 DEFPY (af_rt_vpn_imexport,
9279 af_rt_vpn_imexport_cmd,
9280 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9281 NO_STR
9282 "Specify route target list\n"
9283 "Specify route target list\n"
9284 "Between current address-family and vpn\n"
9285 "For routes leaked from vpn to current address-family: match any\n"
9286 "For routes leaked from current address-family to vpn: set\n"
9287 "both import: match any and export: set\n"
9288 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9289 {
9290 VTY_DECLVAR_CONTEXT(bgp, bgp);
9291 int ret;
9292 struct ecommunity *ecom = NULL;
9293 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9294 enum vpn_policy_direction dir;
9295 afi_t afi;
9296 int idx = 0;
9297 bool yes = true;
9298
9299 if (argv_find(argv, argc, "no", &idx))
9300 yes = false;
9301
9302 afi = vpn_policy_getafi(vty, bgp, false);
9303 if (afi == AFI_MAX)
9304 return CMD_WARNING_CONFIG_FAILED;
9305
9306 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9307 if (ret != CMD_SUCCESS)
9308 return ret;
9309
9310 if (yes) {
9311 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9312 vty_out(vty, "%% Missing RTLIST\n");
9313 return CMD_WARNING_CONFIG_FAILED;
9314 }
9315 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9316 if (ret != CMD_SUCCESS) {
9317 return ret;
9318 }
9319 }
9320
9321 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9322 if (!dodir[dir])
9323 continue;
9324
9325 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9326
9327 if (yes) {
9328 if (bgp->vpn_policy[afi].rtlist[dir])
9329 ecommunity_free(
9330 &bgp->vpn_policy[afi].rtlist[dir]);
9331 bgp->vpn_policy[afi].rtlist[dir] =
9332 ecommunity_dup(ecom);
9333 } else {
9334 if (bgp->vpn_policy[afi].rtlist[dir])
9335 ecommunity_free(
9336 &bgp->vpn_policy[afi].rtlist[dir]);
9337 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9338 }
9339
9340 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9341 }
9342
9343 if (ecom)
9344 ecommunity_free(&ecom);
9345
9346 return CMD_SUCCESS;
9347 }
9348
9349 ALIAS (af_rt_vpn_imexport,
9350 af_no_rt_vpn_imexport_cmd,
9351 "no <rt|route-target> vpn <import|export|both>$direction_str",
9352 NO_STR
9353 "Specify route target list\n"
9354 "Specify route target list\n"
9355 "Between current address-family and vpn\n"
9356 "For routes leaked from vpn to current address-family\n"
9357 "For routes leaked from current address-family to vpn\n"
9358 "both import and export\n")
9359
9360 DEFPY (af_route_map_vpn_imexport,
9361 af_route_map_vpn_imexport_cmd,
9362 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9363 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9364 NO_STR
9365 "Specify route map\n"
9366 "Between current address-family and vpn\n"
9367 "For routes leaked from vpn to current address-family\n"
9368 "For routes leaked from current address-family to vpn\n"
9369 "name of route-map\n")
9370 {
9371 VTY_DECLVAR_CONTEXT(bgp, bgp);
9372 int ret;
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 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9391 if (!dodir[dir])
9392 continue;
9393
9394 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9395
9396 if (yes) {
9397 if (bgp->vpn_policy[afi].rmap_name[dir])
9398 XFREE(MTYPE_ROUTE_MAP_NAME,
9399 bgp->vpn_policy[afi].rmap_name[dir]);
9400 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9401 MTYPE_ROUTE_MAP_NAME, rmap_str);
9402 bgp->vpn_policy[afi].rmap[dir] =
9403 route_map_lookup_warn_noexist(vty, rmap_str);
9404 if (!bgp->vpn_policy[afi].rmap[dir])
9405 return CMD_SUCCESS;
9406 } else {
9407 if (bgp->vpn_policy[afi].rmap_name[dir])
9408 XFREE(MTYPE_ROUTE_MAP_NAME,
9409 bgp->vpn_policy[afi].rmap_name[dir]);
9410 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9411 bgp->vpn_policy[afi].rmap[dir] = NULL;
9412 }
9413
9414 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9415 }
9416
9417 return CMD_SUCCESS;
9418 }
9419
9420 ALIAS (af_route_map_vpn_imexport,
9421 af_no_route_map_vpn_imexport_cmd,
9422 "no route-map vpn <import|export>$direction_str",
9423 NO_STR
9424 "Specify route map\n"
9425 "Between current address-family and vpn\n"
9426 "For routes leaked from vpn to current address-family\n"
9427 "For routes leaked from current address-family to vpn\n")
9428
9429 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9430 "import vrf route-map RMAP$rmap_str",
9431 "Import routes from another VRF\n"
9432 "Vrf routes being filtered\n"
9433 "Specify route map\n"
9434 "name of route-map\n")
9435 {
9436 VTY_DECLVAR_CONTEXT(bgp, bgp);
9437 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9438 afi_t afi;
9439 struct bgp *bgp_default;
9440
9441 afi = vpn_policy_getafi(vty, bgp, true);
9442 if (afi == AFI_MAX)
9443 return CMD_WARNING_CONFIG_FAILED;
9444
9445 bgp_default = bgp_get_default();
9446 if (!bgp_default) {
9447 int32_t ret;
9448 as_t as = bgp->as;
9449
9450 /* Auto-create assuming the same AS */
9451 ret = bgp_get_vty(&bgp_default, &as, NULL,
9452 BGP_INSTANCE_TYPE_DEFAULT);
9453
9454 if (ret) {
9455 vty_out(vty,
9456 "VRF default is not configured as a bgp instance\n");
9457 return CMD_WARNING;
9458 }
9459 }
9460
9461 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9462
9463 if (bgp->vpn_policy[afi].rmap_name[dir])
9464 XFREE(MTYPE_ROUTE_MAP_NAME,
9465 bgp->vpn_policy[afi].rmap_name[dir]);
9466 bgp->vpn_policy[afi].rmap_name[dir] =
9467 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9468 bgp->vpn_policy[afi].rmap[dir] =
9469 route_map_lookup_warn_noexist(vty, rmap_str);
9470 if (!bgp->vpn_policy[afi].rmap[dir])
9471 return CMD_SUCCESS;
9472
9473 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9474 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9475
9476 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9477
9478 return CMD_SUCCESS;
9479 }
9480
9481 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9482 "no import vrf route-map [RMAP$rmap_str]",
9483 NO_STR
9484 "Import routes from another VRF\n"
9485 "Vrf routes being filtered\n"
9486 "Specify route map\n"
9487 "name of route-map\n")
9488 {
9489 VTY_DECLVAR_CONTEXT(bgp, bgp);
9490 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9491 afi_t afi;
9492
9493 afi = vpn_policy_getafi(vty, bgp, true);
9494 if (afi == AFI_MAX)
9495 return CMD_WARNING_CONFIG_FAILED;
9496
9497 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9498
9499 if (bgp->vpn_policy[afi].rmap_name[dir])
9500 XFREE(MTYPE_ROUTE_MAP_NAME,
9501 bgp->vpn_policy[afi].rmap_name[dir]);
9502 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9503 bgp->vpn_policy[afi].rmap[dir] = NULL;
9504
9505 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9506 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9507 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9508
9509 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9510
9511 return CMD_SUCCESS;
9512 }
9513
9514 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9515 "[no] import vrf VIEWVRFNAME$import_name",
9516 NO_STR
9517 "Import routes from another VRF\n"
9518 "VRF to import from\n"
9519 "The name of the VRF\n")
9520 {
9521 VTY_DECLVAR_CONTEXT(bgp, bgp);
9522 struct listnode *node;
9523 struct bgp *vrf_bgp, *bgp_default;
9524 int32_t ret = 0;
9525 as_t as = bgp->as;
9526 bool remove = false;
9527 int32_t idx = 0;
9528 char *vname;
9529 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9530 safi_t safi;
9531 afi_t afi;
9532
9533 if (import_name == NULL) {
9534 vty_out(vty, "%% Missing import name\n");
9535 return CMD_WARNING;
9536 }
9537
9538 if (strcmp(import_name, "route-map") == 0) {
9539 vty_out(vty, "%% Must include route-map name\n");
9540 return CMD_WARNING;
9541 }
9542
9543 if (argv_find(argv, argc, "no", &idx))
9544 remove = true;
9545
9546 afi = vpn_policy_getafi(vty, bgp, true);
9547 if (afi == AFI_MAX)
9548 return CMD_WARNING_CONFIG_FAILED;
9549
9550 safi = bgp_node_safi(vty);
9551
9552 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9553 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9554 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9555 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9556 remove ? "unimport" : "import", import_name);
9557 return CMD_WARNING;
9558 }
9559
9560 bgp_default = bgp_get_default();
9561 if (!bgp_default) {
9562 /* Auto-create assuming the same AS */
9563 ret = bgp_get_vty(&bgp_default, &as, NULL,
9564 BGP_INSTANCE_TYPE_DEFAULT);
9565
9566 if (ret) {
9567 vty_out(vty,
9568 "VRF default is not configured as a bgp instance\n");
9569 return CMD_WARNING;
9570 }
9571 }
9572
9573 vrf_bgp = bgp_lookup_by_name(import_name);
9574 if (!vrf_bgp) {
9575 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9576 vrf_bgp = bgp_default;
9577 else
9578 /* Auto-create assuming the same AS */
9579 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9580
9581 if (ret) {
9582 vty_out(vty,
9583 "VRF %s is not configured as a bgp instance\n",
9584 import_name);
9585 return CMD_WARNING;
9586 }
9587 }
9588
9589 if (remove) {
9590 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9591 } else {
9592 /* Already importing from "import_vrf"? */
9593 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9594 vname)) {
9595 if (strcmp(vname, import_name) == 0)
9596 return CMD_WARNING;
9597 }
9598
9599 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9600 }
9601
9602 return CMD_SUCCESS;
9603 }
9604
9605 /* This command is valid only in a bgp vrf instance or the default instance */
9606 DEFPY (bgp_imexport_vpn,
9607 bgp_imexport_vpn_cmd,
9608 "[no] <import|export>$direction_str vpn",
9609 NO_STR
9610 "Import routes to this address-family\n"
9611 "Export routes from this address-family\n"
9612 "to/from default instance VPN RIB\n")
9613 {
9614 VTY_DECLVAR_CONTEXT(bgp, bgp);
9615 int previous_state;
9616 afi_t afi;
9617 safi_t safi;
9618 int idx = 0;
9619 bool yes = true;
9620 int flag;
9621 enum vpn_policy_direction dir;
9622
9623 if (argv_find(argv, argc, "no", &idx))
9624 yes = false;
9625
9626 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9627 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9628
9629 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9630 return CMD_WARNING_CONFIG_FAILED;
9631 }
9632
9633 afi = bgp_node_afi(vty);
9634 safi = bgp_node_safi(vty);
9635 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9636 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9637 return CMD_WARNING_CONFIG_FAILED;
9638 }
9639
9640 if (!strcmp(direction_str, "import")) {
9641 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9642 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9643 } else if (!strcmp(direction_str, "export")) {
9644 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9645 dir = BGP_VPN_POLICY_DIR_TOVPN;
9646 } else {
9647 vty_out(vty, "%% unknown direction %s\n", direction_str);
9648 return CMD_WARNING_CONFIG_FAILED;
9649 }
9650
9651 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9652
9653 if (yes) {
9654 SET_FLAG(bgp->af_flags[afi][safi], flag);
9655 if (!previous_state) {
9656 /* trigger export current vrf */
9657 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9658 }
9659 } else {
9660 if (previous_state) {
9661 /* trigger un-export current vrf */
9662 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9663 }
9664 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9665 }
9666
9667 hook_call(bgp_snmp_init_stats, bgp);
9668
9669 return CMD_SUCCESS;
9670 }
9671
9672 DEFPY (af_routetarget_import,
9673 af_routetarget_import_cmd,
9674 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9675 NO_STR
9676 "Specify route target list\n"
9677 "Specify route target list\n"
9678 "Specify route target list\n"
9679 "Specify route target list\n"
9680 "Flow-spec redirect type route target\n"
9681 "Import routes to this address-family\n"
9682 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9683 {
9684 VTY_DECLVAR_CONTEXT(bgp, bgp);
9685 int ret;
9686 struct ecommunity *ecom = NULL;
9687 afi_t afi;
9688 int idx = 0, idx_unused = 0;
9689 bool yes = true;
9690 bool rt6 = false;
9691
9692 if (argv_find(argv, argc, "no", &idx))
9693 yes = false;
9694
9695 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9696 argv_find(argv, argc, "route-target6", &idx_unused))
9697 rt6 = true;
9698
9699 afi = vpn_policy_getafi(vty, bgp, false);
9700 if (afi == AFI_MAX)
9701 return CMD_WARNING_CONFIG_FAILED;
9702
9703 if (rt6 && afi != AFI_IP6)
9704 return CMD_WARNING_CONFIG_FAILED;
9705
9706 if (yes) {
9707 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9708 vty_out(vty, "%% Missing RTLIST\n");
9709 return CMD_WARNING_CONFIG_FAILED;
9710 }
9711 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9712 if (ret != CMD_SUCCESS)
9713 return ret;
9714 }
9715
9716 if (yes) {
9717 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9718 ecommunity_free(&bgp->vpn_policy[afi]
9719 .import_redirect_rtlist);
9720 bgp->vpn_policy[afi].import_redirect_rtlist =
9721 ecommunity_dup(ecom);
9722 } else {
9723 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9724 ecommunity_free(&bgp->vpn_policy[afi]
9725 .import_redirect_rtlist);
9726 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9727 }
9728
9729 if (ecom)
9730 ecommunity_free(&ecom);
9731
9732 return CMD_SUCCESS;
9733 }
9734
9735 DEFUN_NOSH (address_family_ipv4_safi,
9736 address_family_ipv4_safi_cmd,
9737 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9738 "Enter Address Family command mode\n"
9739 BGP_AF_STR
9740 BGP_SAFI_WITH_LABEL_HELP_STR)
9741 {
9742
9743 if (argc == 3) {
9744 VTY_DECLVAR_CONTEXT(bgp, bgp);
9745 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9746 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9747 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9748 && safi != SAFI_EVPN) {
9749 vty_out(vty,
9750 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9751 return CMD_WARNING_CONFIG_FAILED;
9752 }
9753 vty->node = bgp_node_type(AFI_IP, safi);
9754 } else
9755 vty->node = BGP_IPV4_NODE;
9756
9757 return CMD_SUCCESS;
9758 }
9759
9760 DEFUN_NOSH (address_family_ipv6_safi,
9761 address_family_ipv6_safi_cmd,
9762 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9763 "Enter Address Family command mode\n"
9764 BGP_AF_STR
9765 BGP_SAFI_WITH_LABEL_HELP_STR)
9766 {
9767 if (argc == 3) {
9768 VTY_DECLVAR_CONTEXT(bgp, bgp);
9769 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9770 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9771 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9772 && safi != SAFI_EVPN) {
9773 vty_out(vty,
9774 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9775 return CMD_WARNING_CONFIG_FAILED;
9776 }
9777 vty->node = bgp_node_type(AFI_IP6, safi);
9778 } else
9779 vty->node = BGP_IPV6_NODE;
9780
9781 return CMD_SUCCESS;
9782 }
9783
9784 #ifdef KEEP_OLD_VPN_COMMANDS
9785 DEFUN_NOSH (address_family_vpnv4,
9786 address_family_vpnv4_cmd,
9787 "address-family vpnv4 [unicast]",
9788 "Enter Address Family command mode\n"
9789 BGP_AF_STR
9790 BGP_AF_MODIFIER_STR)
9791 {
9792 vty->node = BGP_VPNV4_NODE;
9793 return CMD_SUCCESS;
9794 }
9795
9796 DEFUN_NOSH (address_family_vpnv6,
9797 address_family_vpnv6_cmd,
9798 "address-family vpnv6 [unicast]",
9799 "Enter Address Family command mode\n"
9800 BGP_AF_STR
9801 BGP_AF_MODIFIER_STR)
9802 {
9803 vty->node = BGP_VPNV6_NODE;
9804 return CMD_SUCCESS;
9805 }
9806 #endif /* KEEP_OLD_VPN_COMMANDS */
9807
9808 DEFUN_NOSH (address_family_evpn,
9809 address_family_evpn_cmd,
9810 "address-family l2vpn evpn",
9811 "Enter Address Family command mode\n"
9812 BGP_AF_STR
9813 BGP_AF_MODIFIER_STR)
9814 {
9815 VTY_DECLVAR_CONTEXT(bgp, bgp);
9816 vty->node = BGP_EVPN_NODE;
9817 return CMD_SUCCESS;
9818 }
9819
9820 DEFUN_NOSH (bgp_segment_routing_srv6,
9821 bgp_segment_routing_srv6_cmd,
9822 "segment-routing srv6",
9823 "Segment-Routing configuration\n"
9824 "Segment-Routing SRv6 configuration\n")
9825 {
9826 VTY_DECLVAR_CONTEXT(bgp, bgp);
9827 bgp->srv6_enabled = true;
9828 vty->node = BGP_SRV6_NODE;
9829 return CMD_SUCCESS;
9830 }
9831
9832 DEFUN (no_bgp_segment_routing_srv6,
9833 no_bgp_segment_routing_srv6_cmd,
9834 "no segment-routing srv6",
9835 NO_STR
9836 "Segment-Routing configuration\n"
9837 "Segment-Routing SRv6 configuration\n")
9838 {
9839 VTY_DECLVAR_CONTEXT(bgp, bgp);
9840
9841 if (strlen(bgp->srv6_locator_name) > 0)
9842 if (bgp_srv6_locator_unset(bgp) < 0)
9843 return CMD_WARNING_CONFIG_FAILED;
9844
9845 bgp->srv6_enabled = false;
9846 return CMD_SUCCESS;
9847 }
9848
9849 DEFPY (bgp_srv6_locator,
9850 bgp_srv6_locator_cmd,
9851 "locator NAME$name",
9852 "Specify SRv6 locator\n"
9853 "Specify SRv6 locator\n")
9854 {
9855 VTY_DECLVAR_CONTEXT(bgp, bgp);
9856 int ret;
9857
9858 if (strlen(bgp->srv6_locator_name) > 0
9859 && strcmp(name, bgp->srv6_locator_name) != 0) {
9860 vty_out(vty, "srv6 locator is already configured\n");
9861 return CMD_WARNING_CONFIG_FAILED;
9862 }
9863
9864 snprintf(bgp->srv6_locator_name,
9865 sizeof(bgp->srv6_locator_name), "%s", name);
9866
9867 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9868 if (ret < 0)
9869 return CMD_WARNING_CONFIG_FAILED;
9870
9871 return CMD_SUCCESS;
9872 }
9873
9874 DEFPY (no_bgp_srv6_locator,
9875 no_bgp_srv6_locator_cmd,
9876 "no locator NAME$name",
9877 NO_STR
9878 "Specify SRv6 locator\n"
9879 "Specify SRv6 locator\n")
9880 {
9881 VTY_DECLVAR_CONTEXT(bgp, bgp);
9882
9883 /* when locator isn't configured, do nothing */
9884 if (strlen(bgp->srv6_locator_name) < 1)
9885 return CMD_SUCCESS;
9886
9887 /* name validation */
9888 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9889 vty_out(vty, "%% No srv6 locator is configured\n");
9890 return CMD_WARNING_CONFIG_FAILED;
9891 }
9892
9893 /* unset locator */
9894 if (bgp_srv6_locator_unset(bgp) < 0)
9895 return CMD_WARNING_CONFIG_FAILED;
9896
9897 return CMD_SUCCESS;
9898 }
9899
9900 DEFPY (show_bgp_srv6,
9901 show_bgp_srv6_cmd,
9902 "show bgp segment-routing srv6",
9903 SHOW_STR
9904 BGP_STR
9905 "BGP Segment Routing\n"
9906 "BGP Segment Routing SRv6\n")
9907 {
9908 struct bgp *bgp;
9909 struct listnode *node;
9910 struct srv6_locator_chunk *chunk;
9911 struct bgp_srv6_function *func;
9912
9913 bgp = bgp_get_default();
9914 if (!bgp)
9915 return CMD_SUCCESS;
9916
9917 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9918 vty_out(vty, "locator_chunks:\n");
9919 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9920 vty_out(vty, "- %pFX\n", &chunk->prefix);
9921 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9922 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9923 vty_out(vty, " func-length: %d\n",
9924 chunk->function_bits_length);
9925 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9926 }
9927
9928 vty_out(vty, "functions:\n");
9929 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9930 vty_out(vty, "- sid: %pI6\n", &func->sid);
9931 vty_out(vty, " locator: %s\n", func->locator_name);
9932 }
9933
9934 vty_out(vty, "bgps:\n");
9935 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9936 vty_out(vty, "- name: %s\n",
9937 bgp->name ? bgp->name : "default");
9938
9939 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9940 bgp->vpn_policy[AFI_IP].tovpn_sid);
9941 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9942 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9943 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
9944 }
9945
9946 return CMD_SUCCESS;
9947 }
9948
9949 DEFUN_NOSH (exit_address_family,
9950 exit_address_family_cmd,
9951 "exit-address-family",
9952 "Exit from Address Family configuration mode\n")
9953 {
9954 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9955 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9956 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9957 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9958 || vty->node == BGP_EVPN_NODE
9959 || vty->node == BGP_FLOWSPECV4_NODE
9960 || vty->node == BGP_FLOWSPECV6_NODE)
9961 vty->node = BGP_NODE;
9962 return CMD_SUCCESS;
9963 }
9964
9965 /* Recalculate bestpath and re-advertise a prefix */
9966 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9967 const char *ip_str, afi_t afi, safi_t safi,
9968 struct prefix_rd *prd)
9969 {
9970 int ret;
9971 struct prefix match;
9972 struct bgp_dest *dest;
9973 struct bgp_dest *rm;
9974 struct bgp *bgp;
9975 struct bgp_table *table;
9976 struct bgp_table *rib;
9977
9978 /* BGP structure lookup. */
9979 if (view_name) {
9980 bgp = bgp_lookup_by_name(view_name);
9981 if (bgp == NULL) {
9982 vty_out(vty, "%% Can't find BGP instance %s\n",
9983 view_name);
9984 return CMD_WARNING;
9985 }
9986 } else {
9987 bgp = bgp_get_default();
9988 if (bgp == NULL) {
9989 vty_out(vty, "%% No BGP process is configured\n");
9990 return CMD_WARNING;
9991 }
9992 }
9993
9994 /* Check IP address argument. */
9995 ret = str2prefix(ip_str, &match);
9996 if (!ret) {
9997 vty_out(vty, "%% address is malformed\n");
9998 return CMD_WARNING;
9999 }
10000
10001 match.family = afi2family(afi);
10002 rib = bgp->rib[afi][safi];
10003
10004 if (safi == SAFI_MPLS_VPN) {
10005 for (dest = bgp_table_top(rib); dest;
10006 dest = bgp_route_next(dest)) {
10007 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10008
10009 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10010 continue;
10011
10012 table = bgp_dest_get_bgp_table_info(dest);
10013 if (table == NULL)
10014 continue;
10015
10016 rm = bgp_node_match(table, &match);
10017 if (rm != NULL) {
10018 const struct prefix *rm_p =
10019 bgp_dest_get_prefix(rm);
10020
10021 if (rm_p->prefixlen == match.prefixlen) {
10022 SET_FLAG(rm->flags,
10023 BGP_NODE_USER_CLEAR);
10024 bgp_process(bgp, rm, afi, safi);
10025 }
10026 bgp_dest_unlock_node(rm);
10027 }
10028 }
10029 } else {
10030 dest = bgp_node_match(rib, &match);
10031 if (dest != NULL) {
10032 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10033
10034 if (dest_p->prefixlen == match.prefixlen) {
10035 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10036 bgp_process(bgp, dest, afi, safi);
10037 }
10038 bgp_dest_unlock_node(dest);
10039 }
10040 }
10041
10042 return CMD_SUCCESS;
10043 }
10044
10045 /* one clear bgp command to rule them all */
10046 DEFUN (clear_ip_bgp_all,
10047 clear_ip_bgp_all_cmd,
10048 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
10049 CLEAR_STR
10050 IP_STR
10051 BGP_STR
10052 BGP_INSTANCE_HELP_STR
10053 BGP_AFI_HELP_STR
10054 BGP_AF_STR
10055 BGP_SAFI_WITH_LABEL_HELP_STR
10056 BGP_AF_MODIFIER_STR
10057 "Clear all peers\n"
10058 "BGP IPv4 neighbor to clear\n"
10059 "BGP IPv6 neighbor to clear\n"
10060 "BGP neighbor on interface to clear\n"
10061 "Clear peers with the AS number\n"
10062 "Clear all external peers\n"
10063 "Clear all members of peer-group\n"
10064 "BGP peer-group name\n"
10065 BGP_SOFT_STR
10066 BGP_SOFT_IN_STR
10067 BGP_SOFT_OUT_STR
10068 BGP_SOFT_IN_STR
10069 "Push out prefix-list ORF and do inbound soft reconfig\n"
10070 BGP_SOFT_OUT_STR
10071 "Reset message statistics\n")
10072 {
10073 char *vrf = NULL;
10074
10075 afi_t afi = AFI_UNSPEC;
10076 safi_t safi = SAFI_UNSPEC;
10077 enum clear_sort clr_sort = clear_peer;
10078 enum bgp_clear_type clr_type;
10079 char *clr_arg = NULL;
10080
10081 int idx = 0;
10082
10083 /* clear [ip] bgp */
10084 if (argv_find(argv, argc, "ip", &idx))
10085 afi = AFI_IP;
10086
10087 /* [<vrf> VIEWVRFNAME] */
10088 if (argv_find(argv, argc, "vrf", &idx)) {
10089 vrf = argv[idx + 1]->arg;
10090 idx += 2;
10091 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10092 vrf = NULL;
10093 } else if (argv_find(argv, argc, "view", &idx)) {
10094 /* [<view> VIEWVRFNAME] */
10095 vrf = argv[idx + 1]->arg;
10096 idx += 2;
10097 }
10098 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10099 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10100 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10101
10102 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10103 if (argv_find(argv, argc, "*", &idx)) {
10104 clr_sort = clear_all;
10105 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10106 clr_sort = clear_peer;
10107 clr_arg = argv[idx]->arg;
10108 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10109 clr_sort = clear_peer;
10110 clr_arg = argv[idx]->arg;
10111 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10112 clr_sort = clear_group;
10113 idx++;
10114 clr_arg = argv[idx]->arg;
10115 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10116 clr_sort = clear_peer;
10117 clr_arg = argv[idx]->arg;
10118 } else if (argv_find(argv, argc, "WORD", &idx)) {
10119 clr_sort = clear_peer;
10120 clr_arg = argv[idx]->arg;
10121 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10122 clr_sort = clear_as;
10123 clr_arg = argv[idx]->arg;
10124 } else if (argv_find(argv, argc, "external", &idx)) {
10125 clr_sort = clear_external;
10126 }
10127
10128 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10129 if (argv_find(argv, argc, "soft", &idx)) {
10130 if (argv_find(argv, argc, "in", &idx)
10131 || argv_find(argv, argc, "out", &idx))
10132 clr_type = strmatch(argv[idx]->text, "in")
10133 ? BGP_CLEAR_SOFT_IN
10134 : BGP_CLEAR_SOFT_OUT;
10135 else
10136 clr_type = BGP_CLEAR_SOFT_BOTH;
10137 } else if (argv_find(argv, argc, "in", &idx)) {
10138 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10139 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10140 : BGP_CLEAR_SOFT_IN;
10141 } else if (argv_find(argv, argc, "out", &idx)) {
10142 clr_type = BGP_CLEAR_SOFT_OUT;
10143 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10144 clr_type = BGP_CLEAR_MESSAGE_STATS;
10145 } else
10146 clr_type = BGP_CLEAR_SOFT_NONE;
10147
10148 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10149 }
10150
10151 DEFUN (clear_ip_bgp_prefix,
10152 clear_ip_bgp_prefix_cmd,
10153 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10154 CLEAR_STR
10155 IP_STR
10156 BGP_STR
10157 BGP_INSTANCE_HELP_STR
10158 "Clear bestpath and re-advertise\n"
10159 "IPv4 prefix\n")
10160 {
10161 char *vrf = NULL;
10162 char *prefix = NULL;
10163
10164 int idx = 0;
10165
10166 /* [<view|vrf> VIEWVRFNAME] */
10167 if (argv_find(argv, argc, "vrf", &idx)) {
10168 vrf = argv[idx + 1]->arg;
10169 idx += 2;
10170 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10171 vrf = NULL;
10172 } else if (argv_find(argv, argc, "view", &idx)) {
10173 /* [<view> VIEWVRFNAME] */
10174 vrf = argv[idx + 1]->arg;
10175 idx += 2;
10176 }
10177
10178 prefix = argv[argc - 1]->arg;
10179
10180 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10181 }
10182
10183 DEFUN (clear_bgp_ipv6_safi_prefix,
10184 clear_bgp_ipv6_safi_prefix_cmd,
10185 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10186 CLEAR_STR
10187 IP_STR
10188 BGP_STR
10189 BGP_AF_STR
10190 BGP_SAFI_HELP_STR
10191 "Clear bestpath and re-advertise\n"
10192 "IPv6 prefix\n")
10193 {
10194 int idx_safi = 0;
10195 int idx_ipv6_prefix = 0;
10196 safi_t safi = SAFI_UNICAST;
10197 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10198 argv[idx_ipv6_prefix]->arg : NULL;
10199
10200 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10201 return bgp_clear_prefix(
10202 vty, NULL, prefix, AFI_IP6,
10203 safi, NULL);
10204 }
10205
10206 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10207 clear_bgp_instance_ipv6_safi_prefix_cmd,
10208 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10209 CLEAR_STR
10210 IP_STR
10211 BGP_STR
10212 BGP_INSTANCE_HELP_STR
10213 BGP_AF_STR
10214 BGP_SAFI_HELP_STR
10215 "Clear bestpath and re-advertise\n"
10216 "IPv6 prefix\n")
10217 {
10218 int idx_safi = 0;
10219 int idx_vrfview = 0;
10220 int idx_ipv6_prefix = 0;
10221 safi_t safi = SAFI_UNICAST;
10222 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10223 argv[idx_ipv6_prefix]->arg : NULL;
10224 char *vrfview = NULL;
10225
10226 /* [<view|vrf> VIEWVRFNAME] */
10227 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10228 vrfview = argv[idx_vrfview + 1]->arg;
10229 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10230 vrfview = NULL;
10231 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10232 /* [<view> VIEWVRFNAME] */
10233 vrfview = argv[idx_vrfview + 1]->arg;
10234 }
10235 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10236
10237 return bgp_clear_prefix(
10238 vty, vrfview, prefix,
10239 AFI_IP6, safi, NULL);
10240 }
10241
10242 DEFUN (show_bgp_views,
10243 show_bgp_views_cmd,
10244 "show [ip] bgp views",
10245 SHOW_STR
10246 IP_STR
10247 BGP_STR
10248 "Show the defined BGP views\n")
10249 {
10250 struct list *inst = bm->bgp;
10251 struct listnode *node;
10252 struct bgp *bgp;
10253
10254 vty_out(vty, "Defined BGP views:\n");
10255 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10256 /* Skip VRFs. */
10257 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10258 continue;
10259 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10260 bgp->as);
10261 }
10262
10263 return CMD_SUCCESS;
10264 }
10265
10266 DEFUN (show_bgp_vrfs,
10267 show_bgp_vrfs_cmd,
10268 "show [ip] bgp vrfs [json]",
10269 SHOW_STR
10270 IP_STR
10271 BGP_STR
10272 "Show BGP VRFs\n"
10273 JSON_STR)
10274 {
10275 char buf[ETHER_ADDR_STRLEN];
10276 struct list *inst = bm->bgp;
10277 struct listnode *node;
10278 struct bgp *bgp;
10279 bool uj = use_json(argc, argv);
10280 json_object *json = NULL;
10281 json_object *json_vrfs = NULL;
10282 int count = 0;
10283
10284 if (uj) {
10285 json = json_object_new_object();
10286 json_vrfs = json_object_new_object();
10287 }
10288
10289 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10290 const char *name, *type;
10291 struct peer *peer;
10292 struct listnode *node2, *nnode2;
10293 int peers_cfg, peers_estb;
10294 json_object *json_vrf = NULL;
10295
10296 /* Skip Views. */
10297 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10298 continue;
10299
10300 count++;
10301 if (!uj && count == 1) {
10302 vty_out(vty,
10303 "%4s %-5s %-16s %9s %10s %-37s\n",
10304 "Type", "Id", "routerId", "#PeersCfg",
10305 "#PeersEstb", "Name");
10306 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10307 "L3-VNI", "RouterMAC", "Interface");
10308 }
10309
10310 peers_cfg = peers_estb = 0;
10311 if (uj)
10312 json_vrf = json_object_new_object();
10313
10314
10315 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10316 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10317 continue;
10318 peers_cfg++;
10319 if (peer_established(peer))
10320 peers_estb++;
10321 }
10322
10323 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10324 name = VRF_DEFAULT_NAME;
10325 type = "DFLT";
10326 } else {
10327 name = bgp->name;
10328 type = "VRF";
10329 }
10330
10331
10332 if (uj) {
10333 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10334 ? -1
10335 : (int64_t)bgp->vrf_id;
10336 char buf[BUFSIZ] = {0};
10337
10338 json_object_string_add(json_vrf, "type", type);
10339 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10340 json_object_string_addf(json_vrf, "routerId", "%pI4",
10341 &bgp->router_id);
10342 json_object_int_add(json_vrf, "numConfiguredPeers",
10343 peers_cfg);
10344 json_object_int_add(json_vrf, "numEstablishedPeers",
10345 peers_estb);
10346
10347 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10348 json_object_string_add(
10349 json_vrf, "rmac",
10350 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10351 json_object_string_add(json_vrf, "interface",
10352 ifindex2ifname(bgp->l3vni_svi_ifindex,
10353 bgp->vrf_id));
10354 json_object_object_add(json_vrfs, name, json_vrf);
10355 } else {
10356 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10357 type,
10358 bgp->vrf_id == VRF_UNKNOWN ? -1
10359 : (int)bgp->vrf_id,
10360 &bgp->router_id, peers_cfg, peers_estb, name);
10361 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10362 bgp->l3vni,
10363 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10364 ifindex2ifname(bgp->l3vni_svi_ifindex,
10365 bgp->vrf_id));
10366 }
10367 }
10368
10369 if (uj) {
10370 json_object_object_add(json, "vrfs", json_vrfs);
10371
10372 json_object_int_add(json, "totalVrfs", count);
10373
10374 vty_json(vty, json);
10375 } else {
10376 if (count)
10377 vty_out(vty,
10378 "\nTotal number of VRFs (including default): %d\n",
10379 count);
10380 }
10381
10382 return CMD_SUCCESS;
10383 }
10384
10385 DEFUN (show_bgp_mac_hash,
10386 show_bgp_mac_hash_cmd,
10387 "show bgp mac hash",
10388 SHOW_STR
10389 BGP_STR
10390 "Mac Address\n"
10391 "Mac Address database\n")
10392 {
10393 bgp_mac_dump_table(vty);
10394
10395 return CMD_SUCCESS;
10396 }
10397
10398 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10399 {
10400 struct vty *vty = (struct vty *)args;
10401 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10402
10403 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10404 }
10405
10406 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10407 {
10408 vty_out(vty, "self nexthop database:\n");
10409 bgp_nexthop_show_address_hash(vty, bgp);
10410
10411 vty_out(vty, "Tunnel-ip database:\n");
10412 hash_iterate(bgp->tip_hash,
10413 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10414 vty);
10415 }
10416
10417 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10418 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10419 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10420 "martian next-hops\n"
10421 "martian next-hop database\n")
10422 {
10423 struct bgp *bgp = NULL;
10424 int idx = 0;
10425 char *name = NULL;
10426
10427 /* [<vrf> VIEWVRFNAME] */
10428 if (argv_find(argv, argc, "vrf", &idx)) {
10429 name = argv[idx + 1]->arg;
10430 if (name && strmatch(name, VRF_DEFAULT_NAME))
10431 name = NULL;
10432 } else if (argv_find(argv, argc, "view", &idx))
10433 /* [<view> VIEWVRFNAME] */
10434 name = argv[idx + 1]->arg;
10435 if (name)
10436 bgp = bgp_lookup_by_name(name);
10437 else
10438 bgp = bgp_get_default();
10439
10440 if (!bgp) {
10441 vty_out(vty, "%% No BGP process is configured\n");
10442 return CMD_WARNING;
10443 }
10444 bgp_show_martian_nexthops(vty, bgp);
10445
10446 return CMD_SUCCESS;
10447 }
10448
10449 DEFUN (show_bgp_memory,
10450 show_bgp_memory_cmd,
10451 "show [ip] bgp memory",
10452 SHOW_STR
10453 IP_STR
10454 BGP_STR
10455 "Global BGP memory statistics\n")
10456 {
10457 char memstrbuf[MTYPE_MEMSTR_LEN];
10458 unsigned long count;
10459
10460 /* RIB related usage stats */
10461 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10462 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10463 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10464 count * sizeof(struct bgp_dest)));
10465
10466 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10467 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10468 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10469 count * sizeof(struct bgp_path_info)));
10470 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10471 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10472 count,
10473 mtype_memstr(
10474 memstrbuf, sizeof(memstrbuf),
10475 count * sizeof(struct bgp_path_info_extra)));
10476
10477 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10478 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10479 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10480 count * sizeof(struct bgp_static)));
10481
10482 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10483 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10484 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10485 count * sizeof(struct bpacket)));
10486
10487 /* Adj-In/Out */
10488 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10489 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10490 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10491 count * sizeof(struct bgp_adj_in)));
10492 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10493 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10495 count * sizeof(struct bgp_adj_out)));
10496
10497 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10498 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10499 count,
10500 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10501 count * sizeof(struct bgp_nexthop_cache)));
10502
10503 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10504 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10505 count,
10506 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10507 count * sizeof(struct bgp_damp_info)));
10508
10509 /* Attributes */
10510 count = attr_count();
10511 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10512 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10513 count * sizeof(struct attr)));
10514
10515 if ((count = attr_unknown_count()))
10516 vty_out(vty, "%ld unknown attributes\n", count);
10517
10518 /* AS_PATH attributes */
10519 count = aspath_count();
10520 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10522 count * sizeof(struct aspath)));
10523
10524 count = mtype_stats_alloc(MTYPE_AS_SEG);
10525 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10526 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10527 count * sizeof(struct assegment)));
10528
10529 /* Other attributes */
10530 if ((count = community_count()))
10531 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10532 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10533 count * sizeof(struct community)));
10534 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10535 vty_out(vty,
10536 "%ld BGP ext-community entries, using %s of memory\n",
10537 count,
10538 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10539 count * sizeof(struct ecommunity)));
10540 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10541 vty_out(vty,
10542 "%ld BGP large-community entries, using %s of memory\n",
10543 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10544 count * sizeof(struct lcommunity)));
10545
10546 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10547 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10548 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10549 count * sizeof(struct cluster_list)));
10550
10551 /* Peer related usage */
10552 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10553 vty_out(vty, "%ld peers, using %s of memory\n", count,
10554 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10555 count * sizeof(struct peer)));
10556
10557 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10558 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10559 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10560 count * sizeof(struct peer_group)));
10561
10562 /* Other */
10563 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10564 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10565 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10566 count * sizeof(regex_t)));
10567 return CMD_SUCCESS;
10568 }
10569
10570 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10571 {
10572 json_object *bestpath = json_object_new_object();
10573
10574 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10575 json_object_string_add(bestpath, "asPath", "ignore");
10576
10577 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10578 json_object_string_add(bestpath, "asPath", "confed");
10579
10580 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10581 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10582 json_object_string_add(bestpath, "multiPathRelax",
10583 "as-set");
10584 else
10585 json_object_string_add(bestpath, "multiPathRelax",
10586 "true");
10587 } else
10588 json_object_string_add(bestpath, "multiPathRelax", "false");
10589
10590 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10591 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10592
10593 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10594 json_object_string_add(bestpath, "compareRouterId", "true");
10595 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10596 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10597 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10598 json_object_string_add(bestpath, "med", "confed");
10599 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10600 json_object_string_add(bestpath, "med",
10601 "missing-as-worst");
10602 else
10603 json_object_string_add(bestpath, "med", "true");
10604 }
10605
10606 json_object_object_add(json, "bestPath", bestpath);
10607 }
10608
10609 /* Print the error code/subcode for why the peer is down */
10610 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10611 json_object *json_peer, bool use_json)
10612 {
10613 const char *code_str;
10614 const char *subcode_str;
10615
10616 if (use_json) {
10617 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10618 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10619 char errorcodesubcode_hexstr[5];
10620 char errorcodesubcode_str[256];
10621
10622 code_str = bgp_notify_code_str(peer->notify.code);
10623 subcode_str = bgp_notify_subcode_str(
10624 peer->notify.code,
10625 peer->notify.subcode);
10626
10627 snprintf(errorcodesubcode_hexstr,
10628 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10629 peer->notify.code, peer->notify.subcode);
10630 json_object_string_add(json_peer,
10631 "lastErrorCodeSubcode",
10632 errorcodesubcode_hexstr);
10633 snprintf(errorcodesubcode_str, 255, "%s%s",
10634 code_str, subcode_str);
10635 json_object_string_add(json_peer,
10636 "lastNotificationReason",
10637 errorcodesubcode_str);
10638 json_object_boolean_add(json_peer,
10639 "lastNotificationHardReset",
10640 peer->notify.hard_reset);
10641 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10642 && peer->notify.code == BGP_NOTIFY_CEASE
10643 && (peer->notify.subcode
10644 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10645 || peer->notify.subcode
10646 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10647 && peer->notify.length) {
10648 char msgbuf[1024];
10649 const char *msg_str;
10650
10651 msg_str = bgp_notify_admin_message(
10652 msgbuf, sizeof(msgbuf),
10653 (uint8_t *)peer->notify.data,
10654 peer->notify.length);
10655 if (msg_str)
10656 json_object_string_add(
10657 json_peer,
10658 "lastShutdownDescription",
10659 msg_str);
10660 }
10661
10662 }
10663 json_object_string_add(json_peer, "lastResetDueTo",
10664 peer_down_str[(int)peer->last_reset]);
10665 json_object_int_add(json_peer, "lastResetCode",
10666 peer->last_reset);
10667 } else {
10668 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10669 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10670 code_str = bgp_notify_code_str(peer->notify.code);
10671 subcode_str =
10672 bgp_notify_subcode_str(peer->notify.code,
10673 peer->notify.subcode);
10674 vty_out(vty, " Notification %s (%s%s%s)\n",
10675 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10676 ? "sent"
10677 : "received",
10678 code_str, subcode_str,
10679 peer->notify.hard_reset
10680 ? bgp_notify_subcode_str(
10681 BGP_NOTIFY_CEASE,
10682 BGP_NOTIFY_CEASE_HARD_RESET)
10683 : "");
10684 } else {
10685 vty_out(vty, " %s\n",
10686 peer_down_str[(int)peer->last_reset]);
10687 }
10688 }
10689 }
10690
10691 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10692 safi_t safi)
10693 {
10694 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10695 }
10696
10697 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10698 struct peer *peer, json_object *json_peer,
10699 int max_neighbor_width, bool use_json)
10700 {
10701 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10702 int len;
10703
10704 if (use_json) {
10705 if (peer_dynamic_neighbor(peer))
10706 json_object_boolean_true_add(json_peer,
10707 "dynamicPeer");
10708 if (peer->hostname)
10709 json_object_string_add(json_peer, "hostname",
10710 peer->hostname);
10711
10712 if (peer->domainname)
10713 json_object_string_add(json_peer, "domainname",
10714 peer->domainname);
10715 json_object_int_add(json_peer, "connectionsEstablished",
10716 peer->established);
10717 json_object_int_add(json_peer, "connectionsDropped",
10718 peer->dropped);
10719 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10720 use_json, json_peer);
10721 if (peer_established(peer))
10722 json_object_string_add(json_peer, "lastResetDueTo",
10723 "AFI/SAFI Not Negotiated");
10724 else
10725 bgp_show_peer_reset(NULL, peer, json_peer, true);
10726 } else {
10727 dn_flag[1] = '\0';
10728 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10729 if (peer->hostname
10730 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10731 len = vty_out(vty, "%s%s(%s)", dn_flag,
10732 peer->hostname, peer->host);
10733 else
10734 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10735
10736 /* pad the neighbor column with spaces */
10737 if (len < max_neighbor_width)
10738 vty_out(vty, "%*s", max_neighbor_width - len,
10739 " ");
10740 vty_out(vty, "%7d %7d %9s", peer->established,
10741 peer->dropped,
10742 peer_uptime(peer->uptime, timebuf,
10743 BGP_UPTIME_LEN, 0, NULL));
10744 if (peer_established(peer))
10745 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10746 else
10747 bgp_show_peer_reset(vty, peer, NULL,
10748 false);
10749 }
10750 }
10751
10752 /* Strip peer's description to the given size. */
10753 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10754 {
10755 static char stripped[BUFSIZ];
10756 uint32_t i = 0;
10757 uint32_t last_space = 0;
10758
10759 while (i < size) {
10760 if (*(desc + i) == 0) {
10761 stripped[i] = '\0';
10762 return stripped;
10763 }
10764 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10765 last_space = i;
10766 stripped[i] = *(desc + i);
10767 i++;
10768 }
10769
10770 if (last_space > size)
10771 stripped[size + 1] = '\0';
10772 else
10773 stripped[last_space] = '\0';
10774
10775 return stripped;
10776 }
10777
10778 /* Determine whether var peer should be filtered out of the summary. */
10779 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10780 struct peer *fpeer, int as_type,
10781 as_t as)
10782 {
10783
10784 /* filter neighbor XXXX */
10785 if (fpeer && fpeer != peer)
10786 return true;
10787
10788 /* filter remote-as (internal|external) */
10789 if (as_type != AS_UNSPECIFIED) {
10790 if (peer->as_type == AS_SPECIFIED) {
10791 if (as_type == AS_INTERNAL) {
10792 if (peer->as != peer->local_as)
10793 return true;
10794 } else if (peer->as == peer->local_as)
10795 return true;
10796 } else if (as_type != peer->as_type)
10797 return true;
10798 } else if (as && as != peer->as) /* filter remote-as XXX */
10799 return true;
10800
10801 return false;
10802 }
10803
10804 /* Show BGP peer's summary information.
10805 *
10806 * Peer's description is stripped according to if `wide` option is given
10807 * or not.
10808 *
10809 * When adding new columns to `show bgp summary` output, please make
10810 * sure `Desc` is the lastest column to show because it can contain
10811 * whitespaces and the whole output will be tricky.
10812 */
10813 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10814 struct peer *fpeer, int as_type, as_t as,
10815 uint16_t show_flags)
10816 {
10817 struct peer *peer;
10818 struct listnode *node, *nnode;
10819 unsigned int count = 0, dn_count = 0;
10820 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10821 char neighbor_buf[VTY_BUFSIZ];
10822 int neighbor_col_default_width = 16;
10823 int len, failed_count = 0;
10824 unsigned int filtered_count = 0;
10825 int max_neighbor_width = 0;
10826 int pfx_rcd_safi;
10827 json_object *json = NULL;
10828 json_object *json_peer = NULL;
10829 json_object *json_peers = NULL;
10830 struct peer_af *paf;
10831 struct bgp_filter *filter;
10832 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10833 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10834 bool show_established =
10835 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10836 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10837 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10838
10839 /* labeled-unicast routes are installed in the unicast table so in order
10840 * to
10841 * display the correct PfxRcd value we must look at SAFI_UNICAST
10842 */
10843
10844 if (safi == SAFI_LABELED_UNICAST)
10845 pfx_rcd_safi = SAFI_UNICAST;
10846 else
10847 pfx_rcd_safi = safi;
10848
10849 if (use_json) {
10850 json = json_object_new_object();
10851 json_peers = json_object_new_object();
10852 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10853 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10854 as_type, as)) {
10855 filtered_count++;
10856 count++;
10857 continue;
10858 }
10859
10860 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10861 continue;
10862
10863 if (peer->afc[afi][safi]) {
10864 /* See if we have at least a single failed peer */
10865 if (bgp_has_peer_failed(peer, afi, safi))
10866 failed_count++;
10867 count++;
10868 }
10869 if (peer_dynamic_neighbor(peer))
10870 dn_count++;
10871 }
10872
10873 } else {
10874 /* Loop over all neighbors that will be displayed to determine
10875 * how many
10876 * characters are needed for the Neighbor column
10877 */
10878 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10879 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10880 as_type, as)) {
10881 filtered_count++;
10882 count++;
10883 continue;
10884 }
10885
10886 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10887 continue;
10888
10889 if (peer->afc[afi][safi]) {
10890 memset(dn_flag, '\0', sizeof(dn_flag));
10891 if (peer_dynamic_neighbor(peer))
10892 dn_flag[0] = '*';
10893
10894 if (peer->hostname
10895 && CHECK_FLAG(bgp->flags,
10896 BGP_FLAG_SHOW_HOSTNAME))
10897 snprintf(neighbor_buf,
10898 sizeof(neighbor_buf),
10899 "%s%s(%s) ", dn_flag,
10900 peer->hostname, peer->host);
10901 else
10902 snprintf(neighbor_buf,
10903 sizeof(neighbor_buf), "%s%s ",
10904 dn_flag, peer->host);
10905
10906 len = strlen(neighbor_buf);
10907
10908 if (len > max_neighbor_width)
10909 max_neighbor_width = len;
10910
10911 /* See if we have at least a single failed peer */
10912 if (bgp_has_peer_failed(peer, afi, safi))
10913 failed_count++;
10914 count++;
10915 }
10916 }
10917
10918 /* Originally we displayed the Neighbor column as 16
10919 * characters wide so make that the default
10920 */
10921 if (max_neighbor_width < neighbor_col_default_width)
10922 max_neighbor_width = neighbor_col_default_width;
10923 }
10924
10925 if (show_failed && !failed_count) {
10926 if (use_json) {
10927 json_object_int_add(json, "failedPeersCount", 0);
10928 json_object_int_add(json, "dynamicPeers", dn_count);
10929 json_object_int_add(json, "totalPeers", count);
10930
10931 vty_json(vty, json);
10932 } else {
10933 vty_out(vty, "%% No failed BGP neighbors found\n");
10934 }
10935 return CMD_SUCCESS;
10936 }
10937
10938 count = 0; /* Reset the value as its used again */
10939 filtered_count = 0;
10940 dn_count = 0;
10941 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10942 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10943 continue;
10944
10945 if (!peer->afc[afi][safi])
10946 continue;
10947
10948 if (!count) {
10949 unsigned long ents;
10950 char memstrbuf[MTYPE_MEMSTR_LEN];
10951 int64_t vrf_id_ui;
10952
10953 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10954 ? -1
10955 : (int64_t)bgp->vrf_id;
10956
10957 /* Usage summary and header */
10958 if (use_json) {
10959 json_object_string_addf(json, "routerId",
10960 "%pI4",
10961 &bgp->router_id);
10962 json_object_int_add(json, "as", bgp->as);
10963 json_object_int_add(json, "vrfId", vrf_id_ui);
10964 json_object_string_add(
10965 json, "vrfName",
10966 (bgp->inst_type
10967 == BGP_INSTANCE_TYPE_DEFAULT)
10968 ? VRF_DEFAULT_NAME
10969 : bgp->name);
10970 } else {
10971 vty_out(vty,
10972 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10973 &bgp->router_id, bgp->as,
10974 bgp->vrf_id == VRF_UNKNOWN
10975 ? -1
10976 : (int)bgp->vrf_id);
10977 vty_out(vty, "\n");
10978 }
10979
10980 if (bgp_update_delay_configured(bgp)) {
10981 if (use_json) {
10982 json_object_int_add(
10983 json, "updateDelayLimit",
10984 bgp->v_update_delay);
10985
10986 if (bgp->v_update_delay
10987 != bgp->v_establish_wait)
10988 json_object_int_add(
10989 json,
10990 "updateDelayEstablishWait",
10991 bgp->v_establish_wait);
10992
10993 if (bgp_update_delay_active(bgp)) {
10994 json_object_string_add(
10995 json,
10996 "updateDelayFirstNeighbor",
10997 bgp->update_delay_begin_time);
10998 json_object_boolean_true_add(
10999 json,
11000 "updateDelayInProgress");
11001 } else {
11002 if (bgp->update_delay_over) {
11003 json_object_string_add(
11004 json,
11005 "updateDelayFirstNeighbor",
11006 bgp->update_delay_begin_time);
11007 json_object_string_add(
11008 json,
11009 "updateDelayBestpathResumed",
11010 bgp->update_delay_end_time);
11011 json_object_string_add(
11012 json,
11013 "updateDelayZebraUpdateResume",
11014 bgp->update_delay_zebra_resume_time);
11015 json_object_string_add(
11016 json,
11017 "updateDelayPeerUpdateResume",
11018 bgp->update_delay_peers_resume_time);
11019 }
11020 }
11021 } else {
11022 vty_out(vty,
11023 "Read-only mode update-delay limit: %d seconds\n",
11024 bgp->v_update_delay);
11025 if (bgp->v_update_delay
11026 != bgp->v_establish_wait)
11027 vty_out(vty,
11028 " Establish wait: %d seconds\n",
11029 bgp->v_establish_wait);
11030
11031 if (bgp_update_delay_active(bgp)) {
11032 vty_out(vty,
11033 " First neighbor established: %s\n",
11034 bgp->update_delay_begin_time);
11035 vty_out(vty,
11036 " Delay in progress\n");
11037 } else {
11038 if (bgp->update_delay_over) {
11039 vty_out(vty,
11040 " First neighbor established: %s\n",
11041 bgp->update_delay_begin_time);
11042 vty_out(vty,
11043 " Best-paths resumed: %s\n",
11044 bgp->update_delay_end_time);
11045 vty_out(vty,
11046 " zebra update resumed: %s\n",
11047 bgp->update_delay_zebra_resume_time);
11048 vty_out(vty,
11049 " peers update resumed: %s\n",
11050 bgp->update_delay_peers_resume_time);
11051 }
11052 }
11053 }
11054 }
11055
11056 if (use_json) {
11057 if (bgp_maxmed_onstartup_configured(bgp)
11058 && bgp->maxmed_active)
11059 json_object_boolean_true_add(
11060 json, "maxMedOnStartup");
11061 if (bgp->v_maxmed_admin)
11062 json_object_boolean_true_add(
11063 json, "maxMedAdministrative");
11064
11065 json_object_int_add(
11066 json, "tableVersion",
11067 bgp_table_version(bgp->rib[afi][safi]));
11068
11069 ents = bgp_table_count(bgp->rib[afi][safi]);
11070 json_object_int_add(json, "ribCount", ents);
11071 json_object_int_add(
11072 json, "ribMemory",
11073 ents * sizeof(struct bgp_dest));
11074
11075 ents = bgp->af_peer_count[afi][safi];
11076 json_object_int_add(json, "peerCount", ents);
11077 json_object_int_add(json, "peerMemory",
11078 ents * sizeof(struct peer));
11079
11080 if ((ents = listcount(bgp->group))) {
11081 json_object_int_add(
11082 json, "peerGroupCount", ents);
11083 json_object_int_add(
11084 json, "peerGroupMemory",
11085 ents * sizeof(struct
11086 peer_group));
11087 }
11088
11089 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11090 BGP_CONFIG_DAMPENING))
11091 json_object_boolean_true_add(
11092 json, "dampeningEnabled");
11093 } else {
11094 if (!show_terse) {
11095 if (bgp_maxmed_onstartup_configured(bgp)
11096 && bgp->maxmed_active)
11097 vty_out(vty,
11098 "Max-med on-startup active\n");
11099 if (bgp->v_maxmed_admin)
11100 vty_out(vty,
11101 "Max-med administrative active\n");
11102
11103 vty_out(vty,
11104 "BGP table version %" PRIu64
11105 "\n",
11106 bgp_table_version(
11107 bgp->rib[afi][safi]));
11108
11109 ents = bgp_table_count(
11110 bgp->rib[afi][safi]);
11111 vty_out(vty,
11112 "RIB entries %ld, using %s of memory\n",
11113 ents,
11114 mtype_memstr(
11115 memstrbuf,
11116 sizeof(memstrbuf),
11117 ents
11118 * sizeof(
11119 struct
11120 bgp_dest)));
11121
11122 /* Peer related usage */
11123 ents = bgp->af_peer_count[afi][safi];
11124 vty_out(vty,
11125 "Peers %ld, using %s of memory\n",
11126 ents,
11127 mtype_memstr(
11128 memstrbuf,
11129 sizeof(memstrbuf),
11130 ents
11131 * sizeof(
11132 struct
11133 peer)));
11134
11135 if ((ents = listcount(bgp->group)))
11136 vty_out(vty,
11137 "Peer groups %ld, using %s of memory\n",
11138 ents,
11139 mtype_memstr(
11140 memstrbuf,
11141 sizeof(memstrbuf),
11142 ents
11143 * sizeof(
11144 struct
11145 peer_group)));
11146
11147 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11148 BGP_CONFIG_DAMPENING))
11149 vty_out(vty,
11150 "Dampening enabled.\n");
11151 }
11152 if (show_failed) {
11153 vty_out(vty, "\n");
11154
11155 /* Subtract 8 here because 'Neighbor' is
11156 * 8 characters */
11157 vty_out(vty, "Neighbor");
11158 vty_out(vty, "%*s",
11159 max_neighbor_width - 8, " ");
11160 vty_out(vty,
11161 BGP_SHOW_SUMMARY_HEADER_FAILED);
11162 }
11163 }
11164 }
11165
11166 paf = peer_af_find(peer, afi, safi);
11167 filter = &peer->filter[afi][safi];
11168
11169 count++;
11170 /* Works for both failed & successful cases */
11171 if (peer_dynamic_neighbor(peer))
11172 dn_count++;
11173
11174 if (use_json) {
11175 json_peer = NULL;
11176 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11177 as_type, as)) {
11178 filtered_count++;
11179 continue;
11180 }
11181 if (show_failed &&
11182 bgp_has_peer_failed(peer, afi, safi)) {
11183 json_peer = json_object_new_object();
11184 bgp_show_failed_summary(vty, bgp, peer,
11185 json_peer, 0, use_json);
11186 } else if (!show_failed) {
11187 if (show_established
11188 && bgp_has_peer_failed(peer, afi, safi)) {
11189 filtered_count++;
11190 continue;
11191 }
11192
11193 json_peer = json_object_new_object();
11194 if (peer_dynamic_neighbor(peer)) {
11195 json_object_boolean_true_add(json_peer,
11196 "dynamicPeer");
11197 }
11198
11199 if (peer->hostname)
11200 json_object_string_add(json_peer, "hostname",
11201 peer->hostname);
11202
11203 if (peer->domainname)
11204 json_object_string_add(json_peer, "domainname",
11205 peer->domainname);
11206
11207 json_object_int_add(json_peer, "remoteAs", peer->as);
11208 json_object_int_add(
11209 json_peer, "localAs",
11210 peer->change_local_as
11211 ? peer->change_local_as
11212 : peer->local_as);
11213 json_object_int_add(json_peer, "version", 4);
11214 json_object_int_add(json_peer, "msgRcvd",
11215 PEER_TOTAL_RX(peer));
11216 json_object_int_add(json_peer, "msgSent",
11217 PEER_TOTAL_TX(peer));
11218
11219 atomic_size_t outq_count, inq_count;
11220 outq_count = atomic_load_explicit(
11221 &peer->obuf->count,
11222 memory_order_relaxed);
11223 inq_count = atomic_load_explicit(
11224 &peer->ibuf->count,
11225 memory_order_relaxed);
11226
11227 json_object_int_add(json_peer, "tableVersion",
11228 peer->version[afi][safi]);
11229 json_object_int_add(json_peer, "outq",
11230 outq_count);
11231 json_object_int_add(json_peer, "inq",
11232 inq_count);
11233 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11234 use_json, json_peer);
11235
11236 json_object_int_add(json_peer, "pfxRcd",
11237 peer->pcount[afi][pfx_rcd_safi]);
11238
11239 if (paf && PAF_SUBGRP(paf))
11240 json_object_int_add(
11241 json_peer, "pfxSnt",
11242 (PAF_SUBGRP(paf))->scount);
11243 else
11244 json_object_int_add(json_peer, "pfxSnt",
11245 0);
11246
11247 /* BGP FSM state */
11248 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11249 || CHECK_FLAG(peer->bgp->flags,
11250 BGP_FLAG_SHUTDOWN))
11251 json_object_string_add(json_peer,
11252 "state",
11253 "Idle (Admin)");
11254 else if (peer->afc_recv[afi][safi])
11255 json_object_string_add(
11256 json_peer, "state",
11257 lookup_msg(bgp_status_msg,
11258 peer->status, NULL));
11259 else if (CHECK_FLAG(
11260 peer->sflags,
11261 PEER_STATUS_PREFIX_OVERFLOW))
11262 json_object_string_add(json_peer,
11263 "state",
11264 "Idle (PfxCt)");
11265 else
11266 json_object_string_add(
11267 json_peer, "state",
11268 lookup_msg(bgp_status_msg,
11269 peer->status, NULL));
11270
11271 /* BGP peer state */
11272 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11273 || CHECK_FLAG(peer->bgp->flags,
11274 BGP_FLAG_SHUTDOWN))
11275 json_object_string_add(json_peer,
11276 "peerState",
11277 "Admin");
11278 else if (CHECK_FLAG(
11279 peer->sflags,
11280 PEER_STATUS_PREFIX_OVERFLOW))
11281 json_object_string_add(json_peer,
11282 "peerState",
11283 "PfxCt");
11284 else if (CHECK_FLAG(peer->flags,
11285 PEER_FLAG_PASSIVE))
11286 json_object_string_add(json_peer,
11287 "peerState",
11288 "Passive");
11289 else if (CHECK_FLAG(peer->sflags,
11290 PEER_STATUS_NSF_WAIT))
11291 json_object_string_add(json_peer,
11292 "peerState",
11293 "NSF passive");
11294 else if (CHECK_FLAG(
11295 peer->bgp->flags,
11296 BGP_FLAG_EBGP_REQUIRES_POLICY)
11297 && (!bgp_inbound_policy_exists(peer,
11298 filter)
11299 || !bgp_outbound_policy_exists(
11300 peer, filter)))
11301 json_object_string_add(json_peer,
11302 "peerState",
11303 "Policy");
11304 else
11305 json_object_string_add(
11306 json_peer, "peerState", "OK");
11307
11308 json_object_int_add(json_peer, "connectionsEstablished",
11309 peer->established);
11310 json_object_int_add(json_peer, "connectionsDropped",
11311 peer->dropped);
11312 if (peer->desc)
11313 json_object_string_add(
11314 json_peer, "desc", peer->desc);
11315 }
11316 /* Avoid creating empty peer dicts in JSON */
11317 if (json_peer == NULL)
11318 continue;
11319
11320 if (peer->conf_if)
11321 json_object_string_add(json_peer, "idType",
11322 "interface");
11323 else if (peer->su.sa.sa_family == AF_INET)
11324 json_object_string_add(json_peer, "idType",
11325 "ipv4");
11326 else if (peer->su.sa.sa_family == AF_INET6)
11327 json_object_string_add(json_peer, "idType",
11328 "ipv6");
11329 json_object_object_add(json_peers, peer->host,
11330 json_peer);
11331 } else {
11332 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11333 as_type, as)) {
11334 filtered_count++;
11335 continue;
11336 }
11337 if (show_failed &&
11338 bgp_has_peer_failed(peer, afi, safi)) {
11339 bgp_show_failed_summary(vty, bgp, peer, NULL,
11340 max_neighbor_width,
11341 use_json);
11342 } else if (!show_failed) {
11343 if (show_established
11344 && bgp_has_peer_failed(peer, afi, safi)) {
11345 filtered_count++;
11346 continue;
11347 }
11348
11349 if ((count - filtered_count) == 1) {
11350 /* display headline before the first
11351 * neighbor line */
11352 vty_out(vty, "\n");
11353
11354 /* Subtract 8 here because 'Neighbor' is
11355 * 8 characters */
11356 vty_out(vty, "Neighbor");
11357 vty_out(vty, "%*s",
11358 max_neighbor_width - 8, " ");
11359 vty_out(vty,
11360 show_wide
11361 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11362 : BGP_SHOW_SUMMARY_HEADER_ALL);
11363 }
11364
11365 memset(dn_flag, '\0', sizeof(dn_flag));
11366 if (peer_dynamic_neighbor(peer)) {
11367 dn_flag[0] = '*';
11368 }
11369
11370 if (peer->hostname
11371 && CHECK_FLAG(bgp->flags,
11372 BGP_FLAG_SHOW_HOSTNAME))
11373 len = vty_out(vty, "%s%s(%s)", dn_flag,
11374 peer->hostname,
11375 peer->host);
11376 else
11377 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11378
11379 /* pad the neighbor column with spaces */
11380 if (len < max_neighbor_width)
11381 vty_out(vty, "%*s", max_neighbor_width - len,
11382 " ");
11383
11384 atomic_size_t outq_count, inq_count;
11385 outq_count = atomic_load_explicit(
11386 &peer->obuf->count,
11387 memory_order_relaxed);
11388 inq_count = atomic_load_explicit(
11389 &peer->ibuf->count,
11390 memory_order_relaxed);
11391
11392 if (show_wide)
11393 vty_out(vty,
11394 "4 %10u %10u %9u %9u %8" PRIu64
11395 " %4zu %4zu %8s",
11396 peer->as,
11397 peer->change_local_as
11398 ? peer->change_local_as
11399 : peer->local_as,
11400 PEER_TOTAL_RX(peer),
11401 PEER_TOTAL_TX(peer),
11402 peer->version[afi][safi],
11403 inq_count, outq_count,
11404 peer_uptime(peer->uptime,
11405 timebuf,
11406 BGP_UPTIME_LEN, 0,
11407 NULL));
11408 else
11409 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11410 " %4zu %4zu %8s",
11411 peer->as, PEER_TOTAL_RX(peer),
11412 PEER_TOTAL_TX(peer),
11413 peer->version[afi][safi],
11414 inq_count, outq_count,
11415 peer_uptime(peer->uptime,
11416 timebuf,
11417 BGP_UPTIME_LEN, 0,
11418 NULL));
11419
11420 if (peer_established(peer)) {
11421 if (peer->afc_recv[afi][safi]) {
11422 if (CHECK_FLAG(
11423 bgp->flags,
11424 BGP_FLAG_EBGP_REQUIRES_POLICY)
11425 && !bgp_inbound_policy_exists(
11426 peer, filter))
11427 vty_out(vty, " %12s",
11428 "(Policy)");
11429 else
11430 vty_out(vty,
11431 " %12u",
11432 peer->pcount
11433 [afi]
11434 [pfx_rcd_safi]);
11435 } else {
11436 vty_out(vty, " NoNeg");
11437 }
11438
11439 if (paf && PAF_SUBGRP(paf)) {
11440 if (CHECK_FLAG(
11441 bgp->flags,
11442 BGP_FLAG_EBGP_REQUIRES_POLICY)
11443 && !bgp_outbound_policy_exists(
11444 peer, filter))
11445 vty_out(vty, " %8s",
11446 "(Policy)");
11447 else
11448 vty_out(vty,
11449 " %8u",
11450 (PAF_SUBGRP(
11451 paf))
11452 ->scount);
11453 } else {
11454 vty_out(vty, " NoNeg");
11455 }
11456 } else {
11457 if (CHECK_FLAG(peer->flags,
11458 PEER_FLAG_SHUTDOWN)
11459 || CHECK_FLAG(peer->bgp->flags,
11460 BGP_FLAG_SHUTDOWN))
11461 vty_out(vty, " Idle (Admin)");
11462 else if (CHECK_FLAG(
11463 peer->sflags,
11464 PEER_STATUS_PREFIX_OVERFLOW))
11465 vty_out(vty, " Idle (PfxCt)");
11466 else
11467 vty_out(vty, " %12s",
11468 lookup_msg(bgp_status_msg,
11469 peer->status, NULL));
11470
11471 vty_out(vty, " %8u", 0);
11472 }
11473 /* Make sure `Desc` column is the lastest in
11474 * the output.
11475 */
11476 if (peer->desc)
11477 vty_out(vty, " %s",
11478 bgp_peer_description_stripped(
11479 peer->desc,
11480 show_wide ? 64 : 20));
11481 else
11482 vty_out(vty, " N/A");
11483 vty_out(vty, "\n");
11484 }
11485
11486 }
11487 }
11488
11489 if (use_json) {
11490 json_object_object_add(json, "peers", json_peers);
11491 json_object_int_add(json, "failedPeers", failed_count);
11492 json_object_int_add(json, "displayedPeers",
11493 count - filtered_count);
11494 json_object_int_add(json, "totalPeers", count);
11495 json_object_int_add(json, "dynamicPeers", dn_count);
11496
11497 if (!show_failed)
11498 bgp_show_bestpath_json(bgp, json);
11499
11500 vty_json(vty, json);
11501 } else {
11502 if (count) {
11503 if (filtered_count == count)
11504 vty_out(vty, "\n%% No matching neighbor\n");
11505 else {
11506 if (show_failed)
11507 vty_out(vty, "\nDisplayed neighbors %d",
11508 failed_count);
11509 else if (as_type != AS_UNSPECIFIED || as
11510 || fpeer || show_established)
11511 vty_out(vty, "\nDisplayed neighbors %d",
11512 count - filtered_count);
11513
11514 vty_out(vty, "\nTotal number of neighbors %d\n",
11515 count);
11516 }
11517 } else {
11518 vty_out(vty, "No %s neighbor is configured\n",
11519 get_afi_safi_str(afi, safi, false));
11520 }
11521
11522 if (dn_count) {
11523 vty_out(vty, "* - dynamic neighbor\n");
11524 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11525 dn_count, bgp->dynamic_neighbors_limit);
11526 }
11527 }
11528
11529 return CMD_SUCCESS;
11530 }
11531
11532 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11533 int safi, struct peer *fpeer, int as_type,
11534 as_t as, uint16_t show_flags)
11535 {
11536 int is_first = 1;
11537 int afi_wildcard = (afi == AFI_MAX);
11538 int safi_wildcard = (safi == SAFI_MAX);
11539 int is_wildcard = (afi_wildcard || safi_wildcard);
11540 bool nbr_output = false;
11541 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11542
11543 if (use_json && is_wildcard)
11544 vty_out(vty, "{\n");
11545 if (afi_wildcard)
11546 afi = 1; /* AFI_IP */
11547 while (afi < AFI_MAX) {
11548 if (safi_wildcard)
11549 safi = 1; /* SAFI_UNICAST */
11550 while (safi < SAFI_MAX) {
11551 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11552 nbr_output = true;
11553
11554 if (is_wildcard) {
11555 /*
11556 * So limit output to those afi/safi
11557 * pairs that
11558 * actualy have something interesting in
11559 * them
11560 */
11561 if (use_json) {
11562 if (!is_first)
11563 vty_out(vty, ",\n");
11564 else
11565 is_first = 0;
11566
11567 vty_out(vty, "\"%s\":",
11568 get_afi_safi_str(afi,
11569 safi,
11570 true));
11571 } else {
11572 vty_out(vty,
11573 "\n%s Summary (%s):\n",
11574 get_afi_safi_str(afi,
11575 safi,
11576 false),
11577 bgp->name_pretty);
11578 }
11579 }
11580 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11581 as_type, as, show_flags);
11582 }
11583 safi++;
11584 if (!safi_wildcard)
11585 safi = SAFI_MAX;
11586 }
11587 afi++;
11588 if (!afi_wildcard)
11589 afi = AFI_MAX;
11590 }
11591
11592 if (use_json && is_wildcard)
11593 vty_out(vty, "}\n");
11594 else if (!nbr_output) {
11595 if (use_json)
11596 vty_out(vty, "{}\n");
11597 else
11598 vty_out(vty, "%% No BGP neighbors found in %s\n",
11599 bgp->name_pretty);
11600 }
11601 }
11602
11603 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11604 safi_t safi,
11605 const char *neighbor,
11606 int as_type, as_t as,
11607 uint16_t show_flags)
11608 {
11609 struct listnode *node, *nnode;
11610 struct bgp *bgp;
11611 struct peer *fpeer = NULL;
11612 int is_first = 1;
11613 bool nbr_output = false;
11614 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11615
11616 if (use_json)
11617 vty_out(vty, "{\n");
11618
11619 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11620 nbr_output = true;
11621 if (use_json) {
11622 if (!is_first)
11623 vty_out(vty, ",\n");
11624 else
11625 is_first = 0;
11626
11627 vty_out(vty, "\"%s\":",
11628 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11629 ? VRF_DEFAULT_NAME
11630 : bgp->name);
11631 }
11632 if (neighbor) {
11633 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11634 use_json);
11635 if (!fpeer)
11636 continue;
11637 }
11638 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11639 as, show_flags);
11640 }
11641
11642 if (use_json)
11643 vty_out(vty, "}\n");
11644 else if (!nbr_output)
11645 vty_out(vty, "%% BGP instance not found\n");
11646 }
11647
11648 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11649 safi_t safi, const char *neighbor, int as_type,
11650 as_t as, uint16_t show_flags)
11651 {
11652 struct bgp *bgp;
11653 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11654 struct peer *fpeer = NULL;
11655
11656 if (name) {
11657 if (strmatch(name, "all")) {
11658 bgp_show_all_instances_summary_vty(vty, afi, safi,
11659 neighbor, as_type,
11660 as, show_flags);
11661 return CMD_SUCCESS;
11662 } else {
11663 bgp = bgp_lookup_by_name(name);
11664
11665 if (!bgp) {
11666 if (use_json)
11667 vty_out(vty, "{}\n");
11668 else
11669 vty_out(vty,
11670 "%% BGP instance not found\n");
11671 return CMD_WARNING;
11672 }
11673
11674 if (neighbor) {
11675 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11676 use_json);
11677 if (!fpeer)
11678 return CMD_WARNING;
11679 }
11680 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11681 as_type, as, show_flags);
11682 return CMD_SUCCESS;
11683 }
11684 }
11685
11686 bgp = bgp_get_default();
11687
11688 if (bgp) {
11689 if (neighbor) {
11690 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11691 use_json);
11692 if (!fpeer)
11693 return CMD_WARNING;
11694 }
11695 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11696 as, show_flags);
11697 } else {
11698 if (use_json)
11699 vty_out(vty, "{}\n");
11700 else
11701 vty_out(vty, "%% BGP instance not found\n");
11702 return CMD_WARNING;
11703 }
11704
11705 return CMD_SUCCESS;
11706 }
11707
11708 /* `show [ip] bgp summary' commands. */
11709 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11710 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11711 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11712 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
11713 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11714 BGP_SAFI_WITH_LABEL_HELP_STR
11715 "Display the entries for all address families\n"
11716 "Summary of BGP neighbor status\n"
11717 "Show only sessions in Established state\n"
11718 "Show only sessions not in Established state\n"
11719 "Show only the specified neighbor session\n"
11720 "Neighbor to display information about\n"
11721 "Neighbor to display information about\n"
11722 "Neighbor on BGP configured interface\n"
11723 "Show only the specified remote AS sessions\n"
11724 "AS number\n"
11725 "Internal (iBGP) AS sessions\n"
11726 "External (eBGP) AS sessions\n"
11727 "Shorten the information on BGP instances\n"
11728 "Increase table width for longer output\n" JSON_STR)
11729 {
11730 char *vrf = NULL;
11731 afi_t afi = AFI_MAX;
11732 safi_t safi = SAFI_MAX;
11733 as_t as = 0; /* 0 means AS filter not set */
11734 int as_type = AS_UNSPECIFIED;
11735 uint16_t show_flags = 0;
11736
11737 int idx = 0;
11738
11739 /* show [ip] bgp */
11740 if (!all && argv_find(argv, argc, "ip", &idx))
11741 afi = AFI_IP;
11742 /* [<vrf> VIEWVRFNAME] */
11743 if (argv_find(argv, argc, "vrf", &idx)) {
11744 vrf = argv[idx + 1]->arg;
11745 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11746 vrf = NULL;
11747 } else if (argv_find(argv, argc, "view", &idx))
11748 /* [<view> VIEWVRFNAME] */
11749 vrf = argv[idx + 1]->arg;
11750 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11751 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11752 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11753 }
11754
11755 if (argv_find(argv, argc, "failed", &idx))
11756 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11757
11758 if (argv_find(argv, argc, "established", &idx))
11759 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11760
11761 if (argv_find(argv, argc, "remote-as", &idx)) {
11762 if (argv[idx + 1]->arg[0] == 'i')
11763 as_type = AS_INTERNAL;
11764 else if (argv[idx + 1]->arg[0] == 'e')
11765 as_type = AS_EXTERNAL;
11766 else
11767 as = (as_t)atoi(argv[idx + 1]->arg);
11768 }
11769
11770 if (argv_find(argv, argc, "terse", &idx))
11771 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11772
11773 if (argv_find(argv, argc, "wide", &idx))
11774 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11775
11776 if (argv_find(argv, argc, "json", &idx))
11777 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11778
11779 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11780 show_flags);
11781 }
11782
11783 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11784 {
11785 if (for_json)
11786 return get_afi_safi_json_str(afi, safi);
11787 else
11788 return get_afi_safi_vty_str(afi, safi);
11789 }
11790
11791
11792 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11793 afi_t afi, safi_t safi,
11794 uint16_t adv_smcap, uint16_t adv_rmcap,
11795 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11796 bool use_json, json_object *json_pref)
11797 {
11798 /* Send-Mode */
11799 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11800 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11801 if (use_json) {
11802 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11803 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11804 json_object_string_add(json_pref, "sendMode",
11805 "advertisedAndReceived");
11806 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11807 json_object_string_add(json_pref, "sendMode",
11808 "advertised");
11809 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11810 json_object_string_add(json_pref, "sendMode",
11811 "received");
11812 } else {
11813 vty_out(vty, " Send-mode: ");
11814 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11815 vty_out(vty, "advertised");
11816 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11817 vty_out(vty, "%sreceived",
11818 CHECK_FLAG(p->af_cap[afi][safi],
11819 adv_smcap)
11820 ? ", "
11821 : "");
11822 vty_out(vty, "\n");
11823 }
11824 }
11825
11826 /* Receive-Mode */
11827 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11828 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11829 if (use_json) {
11830 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11831 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11832 json_object_string_add(json_pref, "recvMode",
11833 "advertisedAndReceived");
11834 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11835 json_object_string_add(json_pref, "recvMode",
11836 "advertised");
11837 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11838 json_object_string_add(json_pref, "recvMode",
11839 "received");
11840 } else {
11841 vty_out(vty, " Receive-mode: ");
11842 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11843 vty_out(vty, "advertised");
11844 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11845 vty_out(vty, "%sreceived",
11846 CHECK_FLAG(p->af_cap[afi][safi],
11847 adv_rmcap)
11848 ? ", "
11849 : "");
11850 vty_out(vty, "\n");
11851 }
11852 }
11853 }
11854
11855 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11856 struct peer *p,
11857 json_object *json)
11858 {
11859 bool rbit = false;
11860 bool nbit = false;
11861
11862 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11863 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11864 && (peer_established(p))) {
11865 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11866 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11867 }
11868
11869 if (json) {
11870 json_object_boolean_add(json, "rBit", rbit);
11871 json_object_boolean_add(json, "nBit", nbit);
11872 } else {
11873 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11874 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11875 }
11876 }
11877
11878 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11879 struct peer *peer,
11880 json_object *json)
11881 {
11882 const char *mode = "NotApplicable";
11883
11884 if (!json)
11885 vty_out(vty, "\n Remote GR Mode: ");
11886
11887 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11888 && (peer_established(peer))) {
11889
11890 if ((peer->nsf_af_count == 0)
11891 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11892
11893 mode = "Disable";
11894
11895 } else if (peer->nsf_af_count == 0
11896 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11897
11898 mode = "Helper";
11899
11900 } else if (peer->nsf_af_count != 0
11901 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11902
11903 mode = "Restart";
11904 }
11905 }
11906
11907 if (json)
11908 json_object_string_add(json, "remoteGrMode", mode);
11909 else
11910 vty_out(vty, mode, "\n");
11911 }
11912
11913 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11914 struct peer *p,
11915 json_object *json)
11916 {
11917 const char *mode = "Invalid";
11918
11919 if (!json)
11920 vty_out(vty, " Local GR Mode: ");
11921
11922 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11923 mode = "Helper";
11924 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11925 mode = "Restart";
11926 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11927 mode = "Disable";
11928 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11929 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11930 mode = "Helper*";
11931 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11932 mode = "Restart*";
11933 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11934 mode = "Disable*";
11935 else
11936 mode = "Invalid*";
11937 }
11938
11939 if (json)
11940 json_object_string_add(json, "localGrMode", mode);
11941 else
11942 vty_out(vty, mode, "\n");
11943 }
11944
11945 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11946 struct vty *vty, struct peer *peer, json_object *json)
11947 {
11948 afi_t afi;
11949 safi_t safi;
11950 json_object *json_afi_safi = NULL;
11951 json_object *json_timer = NULL;
11952 json_object *json_endofrib_status = NULL;
11953 bool eor_flag = false;
11954
11955 FOREACH_AFI_SAFI_NSF (afi, safi) {
11956 if (!peer->afc[afi][safi])
11957 continue;
11958
11959 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11960 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11961 continue;
11962
11963 if (json) {
11964 json_afi_safi = json_object_new_object();
11965 json_endofrib_status = json_object_new_object();
11966 json_timer = json_object_new_object();
11967 }
11968
11969 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11970 eor_flag = true;
11971 else
11972 eor_flag = false;
11973
11974 if (!json) {
11975 vty_out(vty, " %s:\n",
11976 get_afi_safi_str(afi, safi, false));
11977
11978 vty_out(vty, " F bit: ");
11979 }
11980
11981 if (peer->nsf[afi][safi] &&
11982 CHECK_FLAG(peer->af_cap[afi][safi],
11983 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11984
11985 if (json) {
11986 json_object_boolean_true_add(json_afi_safi,
11987 "fBit");
11988 } else
11989 vty_out(vty, "True\n");
11990 } else {
11991 if (json)
11992 json_object_boolean_false_add(json_afi_safi,
11993 "fBit");
11994 else
11995 vty_out(vty, "False\n");
11996 }
11997
11998 if (!json)
11999 vty_out(vty, " End-of-RIB sent: ");
12000
12001 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12002 PEER_STATUS_EOR_SEND)) {
12003 if (json) {
12004 json_object_boolean_true_add(
12005 json_endofrib_status, "endOfRibSend");
12006
12007 PRINT_EOR_JSON(eor_flag);
12008 } else {
12009 vty_out(vty, "Yes\n");
12010 vty_out(vty,
12011 " End-of-RIB sent after update: ");
12012
12013 PRINT_EOR(eor_flag);
12014 }
12015 } else {
12016 if (json) {
12017 json_object_boolean_false_add(
12018 json_endofrib_status, "endOfRibSend");
12019 json_object_boolean_false_add(
12020 json_endofrib_status,
12021 "endOfRibSentAfterUpdate");
12022 } else {
12023 vty_out(vty, "No\n");
12024 vty_out(vty,
12025 " End-of-RIB sent after update: ");
12026 vty_out(vty, "No\n");
12027 }
12028 }
12029
12030 if (!json)
12031 vty_out(vty, " End-of-RIB received: ");
12032
12033 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12034 PEER_STATUS_EOR_RECEIVED)) {
12035 if (json)
12036 json_object_boolean_true_add(
12037 json_endofrib_status, "endOfRibRecv");
12038 else
12039 vty_out(vty, "Yes\n");
12040 } else {
12041 if (json)
12042 json_object_boolean_false_add(
12043 json_endofrib_status, "endOfRibRecv");
12044 else
12045 vty_out(vty, "No\n");
12046 }
12047
12048 if (json) {
12049 json_object_int_add(json_timer, "stalePathTimer",
12050 peer->bgp->stalepath_time);
12051
12052 if (peer->t_gr_stale != NULL) {
12053 json_object_int_add(json_timer,
12054 "stalePathTimerRemaining",
12055 thread_timer_remain_second(
12056 peer->t_gr_stale));
12057 }
12058
12059 /* Display Configured Selection
12060 * Deferral only when when
12061 * Gr mode is enabled.
12062 */
12063 if (CHECK_FLAG(peer->flags,
12064 PEER_FLAG_GRACEFUL_RESTART)) {
12065 json_object_int_add(json_timer,
12066 "selectionDeferralTimer",
12067 peer->bgp->stalepath_time);
12068 }
12069
12070 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12071 NULL) {
12072
12073 json_object_int_add(
12074 json_timer,
12075 "selectionDeferralTimerRemaining",
12076 thread_timer_remain_second(
12077 peer->bgp->gr_info[afi][safi]
12078 .t_select_deferral));
12079 }
12080 } else {
12081 vty_out(vty, " Timers:\n");
12082 vty_out(vty,
12083 " Configured Stale Path Time(sec): %u\n",
12084 peer->bgp->stalepath_time);
12085
12086 if (peer->t_gr_stale != NULL)
12087 vty_out(vty,
12088 " Stale Path Remaining(sec): %ld\n",
12089 thread_timer_remain_second(
12090 peer->t_gr_stale));
12091 /* Display Configured Selection
12092 * Deferral only when when
12093 * Gr mode is enabled.
12094 */
12095 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12096 vty_out(vty,
12097 " Configured Selection Deferral Time(sec): %u\n",
12098 peer->bgp->select_defer_time);
12099
12100 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12101 NULL)
12102 vty_out(vty,
12103 " Selection Deferral Time Remaining(sec): %ld\n",
12104 thread_timer_remain_second(
12105 peer->bgp->gr_info[afi][safi]
12106 .t_select_deferral));
12107 }
12108 if (json) {
12109 json_object_object_add(json_afi_safi, "endOfRibStatus",
12110 json_endofrib_status);
12111 json_object_object_add(json_afi_safi, "timers",
12112 json_timer);
12113 json_object_object_add(
12114 json, get_afi_safi_str(afi, safi, true),
12115 json_afi_safi);
12116 }
12117 }
12118 }
12119
12120 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12121 struct peer *p,
12122 json_object *json)
12123 {
12124 if (json) {
12125 json_object *json_timer = NULL;
12126
12127 json_timer = json_object_new_object();
12128
12129 json_object_int_add(json_timer, "configuredRestartTimer",
12130 p->bgp->restart_time);
12131
12132 json_object_int_add(json_timer, "receivedRestartTimer",
12133 p->v_gr_restart);
12134
12135 if (p->t_gr_restart != NULL)
12136 json_object_int_add(
12137 json_timer, "restartTimerRemaining",
12138 thread_timer_remain_second(p->t_gr_restart));
12139
12140 json_object_object_add(json, "timers", json_timer);
12141 } else {
12142
12143 vty_out(vty, " Timers:\n");
12144 vty_out(vty, " Configured Restart Time(sec): %u\n",
12145 p->bgp->restart_time);
12146
12147 vty_out(vty, " Received Restart Time(sec): %u\n",
12148 p->v_gr_restart);
12149 if (p->t_gr_restart != NULL)
12150 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12151 thread_timer_remain_second(p->t_gr_restart));
12152 if (p->t_gr_restart != NULL) {
12153 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12154 thread_timer_remain_second(p->t_gr_restart));
12155 }
12156 }
12157 }
12158
12159 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12160 json_object *json)
12161 {
12162 char dn_flag[2] = {0};
12163 /* '*' + v6 address of neighbor */
12164 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12165
12166 if (!p->conf_if && peer_dynamic_neighbor(p))
12167 dn_flag[0] = '*';
12168
12169 if (p->conf_if) {
12170 if (json)
12171 json_object_string_addf(json, "neighborAddr", "%pSU",
12172 &p->su);
12173 else
12174 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12175 &p->su);
12176 } else {
12177 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12178 p->host);
12179
12180 if (json)
12181 json_object_string_add(json, "neighborAddr",
12182 neighborAddr);
12183 else
12184 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12185 }
12186
12187 /* more gr info in new format */
12188 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12189 }
12190
12191 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12192 safi_t safi, bool use_json,
12193 json_object *json_neigh)
12194 {
12195 struct bgp_filter *filter;
12196 struct peer_af *paf;
12197 char orf_pfx_name[BUFSIZ];
12198 int orf_pfx_count;
12199 json_object *json_af = NULL;
12200 json_object *json_prefA = NULL;
12201 json_object *json_prefB = NULL;
12202 json_object *json_addr = NULL;
12203 json_object *json_advmap = NULL;
12204
12205 if (use_json) {
12206 json_addr = json_object_new_object();
12207 json_af = json_object_new_object();
12208 filter = &p->filter[afi][safi];
12209
12210 if (peer_group_active(p))
12211 json_object_string_add(json_addr, "peerGroupMember",
12212 p->group->name);
12213
12214 paf = peer_af_find(p, afi, safi);
12215 if (paf && PAF_SUBGRP(paf)) {
12216 json_object_int_add(json_addr, "updateGroupId",
12217 PAF_UPDGRP(paf)->id);
12218 json_object_int_add(json_addr, "subGroupId",
12219 PAF_SUBGRP(paf)->id);
12220 json_object_int_add(json_addr, "packetQueueLength",
12221 bpacket_queue_virtual_length(paf));
12222 }
12223
12224 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12225 || CHECK_FLAG(p->af_cap[afi][safi],
12226 PEER_CAP_ORF_PREFIX_SM_RCV)
12227 || CHECK_FLAG(p->af_cap[afi][safi],
12228 PEER_CAP_ORF_PREFIX_RM_ADV)
12229 || CHECK_FLAG(p->af_cap[afi][safi],
12230 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12231 json_object_int_add(json_af, "orfType",
12232 ORF_TYPE_PREFIX);
12233 json_prefA = json_object_new_object();
12234 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12235 PEER_CAP_ORF_PREFIX_SM_ADV,
12236 PEER_CAP_ORF_PREFIX_RM_ADV,
12237 PEER_CAP_ORF_PREFIX_SM_RCV,
12238 PEER_CAP_ORF_PREFIX_RM_RCV,
12239 use_json, json_prefA);
12240 json_object_object_add(json_af, "orfPrefixList",
12241 json_prefA);
12242 }
12243
12244 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12245 || CHECK_FLAG(p->af_cap[afi][safi],
12246 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12247 || CHECK_FLAG(p->af_cap[afi][safi],
12248 PEER_CAP_ORF_PREFIX_RM_ADV)
12249 || CHECK_FLAG(p->af_cap[afi][safi],
12250 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12251 json_object_int_add(json_af, "orfOldType",
12252 ORF_TYPE_PREFIX_OLD);
12253 json_prefB = json_object_new_object();
12254 bgp_show_peer_afi_orf_cap(
12255 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12256 PEER_CAP_ORF_PREFIX_RM_ADV,
12257 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12258 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12259 json_prefB);
12260 json_object_object_add(json_af, "orfOldPrefixList",
12261 json_prefB);
12262 }
12263
12264 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12265 || CHECK_FLAG(p->af_cap[afi][safi],
12266 PEER_CAP_ORF_PREFIX_SM_RCV)
12267 || CHECK_FLAG(p->af_cap[afi][safi],
12268 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12269 || CHECK_FLAG(p->af_cap[afi][safi],
12270 PEER_CAP_ORF_PREFIX_RM_ADV)
12271 || CHECK_FLAG(p->af_cap[afi][safi],
12272 PEER_CAP_ORF_PREFIX_RM_RCV)
12273 || CHECK_FLAG(p->af_cap[afi][safi],
12274 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12275 json_object_object_add(json_addr, "afDependentCap",
12276 json_af);
12277 else
12278 json_object_free(json_af);
12279
12280 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12281 p->host, afi, safi);
12282 orf_pfx_count = prefix_bgp_show_prefix_list(
12283 NULL, afi, orf_pfx_name, use_json);
12284
12285 if (CHECK_FLAG(p->af_sflags[afi][safi],
12286 PEER_STATUS_ORF_PREFIX_SEND)
12287 || orf_pfx_count) {
12288 if (CHECK_FLAG(p->af_sflags[afi][safi],
12289 PEER_STATUS_ORF_PREFIX_SEND))
12290 json_object_boolean_true_add(json_neigh,
12291 "orfSent");
12292 if (orf_pfx_count)
12293 json_object_int_add(json_addr, "orfRecvCounter",
12294 orf_pfx_count);
12295 }
12296 if (CHECK_FLAG(p->af_sflags[afi][safi],
12297 PEER_STATUS_ORF_WAIT_REFRESH))
12298 json_object_string_add(
12299 json_addr, "orfFirstUpdate",
12300 "deferredUntilORFOrRouteRefreshRecvd");
12301
12302 if (CHECK_FLAG(p->af_flags[afi][safi],
12303 PEER_FLAG_REFLECTOR_CLIENT))
12304 json_object_boolean_true_add(json_addr,
12305 "routeReflectorClient");
12306 if (CHECK_FLAG(p->af_flags[afi][safi],
12307 PEER_FLAG_RSERVER_CLIENT))
12308 json_object_boolean_true_add(json_addr,
12309 "routeServerClient");
12310 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12311 json_object_boolean_true_add(json_addr,
12312 "inboundSoftConfigPermit");
12313
12314 if (CHECK_FLAG(p->af_flags[afi][safi],
12315 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12316 json_object_boolean_true_add(
12317 json_addr,
12318 "privateAsNumsAllReplacedInUpdatesToNbr");
12319 else if (CHECK_FLAG(p->af_flags[afi][safi],
12320 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12321 json_object_boolean_true_add(
12322 json_addr,
12323 "privateAsNumsReplacedInUpdatesToNbr");
12324 else if (CHECK_FLAG(p->af_flags[afi][safi],
12325 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12326 json_object_boolean_true_add(
12327 json_addr,
12328 "privateAsNumsAllRemovedInUpdatesToNbr");
12329 else if (CHECK_FLAG(p->af_flags[afi][safi],
12330 PEER_FLAG_REMOVE_PRIVATE_AS))
12331 json_object_boolean_true_add(
12332 json_addr,
12333 "privateAsNumsRemovedInUpdatesToNbr");
12334
12335 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12336 if (CHECK_FLAG(p->af_flags[afi][safi],
12337 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12338 json_object_boolean_true_add(json_addr,
12339 "allowAsInOrigin");
12340 else
12341 json_object_int_add(json_addr, "allowAsInCount",
12342 p->allowas_in[afi][safi]);
12343 }
12344
12345 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12346 json_object_boolean_true_add(
12347 json_addr,
12348 bgp_addpath_names(p->addpath_type[afi][safi])
12349 ->type_json_name);
12350
12351 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12352 json_object_string_add(json_addr,
12353 "overrideASNsInOutboundUpdates",
12354 "ifAspathEqualRemoteAs");
12355
12356 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12357 || CHECK_FLAG(p->af_flags[afi][safi],
12358 PEER_FLAG_FORCE_NEXTHOP_SELF))
12359 json_object_boolean_true_add(json_addr,
12360 "routerAlwaysNextHop");
12361 if (CHECK_FLAG(p->af_flags[afi][safi],
12362 PEER_FLAG_AS_PATH_UNCHANGED))
12363 json_object_boolean_true_add(
12364 json_addr, "unchangedAsPathPropogatedToNbr");
12365 if (CHECK_FLAG(p->af_flags[afi][safi],
12366 PEER_FLAG_NEXTHOP_UNCHANGED))
12367 json_object_boolean_true_add(
12368 json_addr, "unchangedNextHopPropogatedToNbr");
12369 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12370 json_object_boolean_true_add(
12371 json_addr, "unchangedMedPropogatedToNbr");
12372 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12373 || CHECK_FLAG(p->af_flags[afi][safi],
12374 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12375 if (CHECK_FLAG(p->af_flags[afi][safi],
12376 PEER_FLAG_SEND_COMMUNITY)
12377 && CHECK_FLAG(p->af_flags[afi][safi],
12378 PEER_FLAG_SEND_EXT_COMMUNITY))
12379 json_object_string_add(json_addr,
12380 "commAttriSentToNbr",
12381 "extendedAndStandard");
12382 else if (CHECK_FLAG(p->af_flags[afi][safi],
12383 PEER_FLAG_SEND_EXT_COMMUNITY))
12384 json_object_string_add(json_addr,
12385 "commAttriSentToNbr",
12386 "extended");
12387 else
12388 json_object_string_add(json_addr,
12389 "commAttriSentToNbr",
12390 "standard");
12391 }
12392 if (CHECK_FLAG(p->af_flags[afi][safi],
12393 PEER_FLAG_DEFAULT_ORIGINATE)) {
12394 if (p->default_rmap[afi][safi].name)
12395 json_object_string_add(
12396 json_addr, "defaultRouteMap",
12397 p->default_rmap[afi][safi].name);
12398
12399 if (paf && PAF_SUBGRP(paf)
12400 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12401 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12402 json_object_boolean_true_add(json_addr,
12403 "defaultSent");
12404 else
12405 json_object_boolean_true_add(json_addr,
12406 "defaultNotSent");
12407 }
12408
12409 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12410 if (is_evpn_enabled())
12411 json_object_boolean_true_add(
12412 json_addr, "advertiseAllVnis");
12413 }
12414
12415 if (filter->plist[FILTER_IN].name
12416 || filter->dlist[FILTER_IN].name
12417 || filter->aslist[FILTER_IN].name
12418 || filter->map[RMAP_IN].name)
12419 json_object_boolean_true_add(json_addr,
12420 "inboundPathPolicyConfig");
12421 if (filter->plist[FILTER_OUT].name
12422 || filter->dlist[FILTER_OUT].name
12423 || filter->aslist[FILTER_OUT].name
12424 || filter->map[RMAP_OUT].name || filter->usmap.name)
12425 json_object_boolean_true_add(
12426 json_addr, "outboundPathPolicyConfig");
12427
12428 /* prefix-list */
12429 if (filter->plist[FILTER_IN].name)
12430 json_object_string_add(json_addr,
12431 "incomingUpdatePrefixFilterList",
12432 filter->plist[FILTER_IN].name);
12433 if (filter->plist[FILTER_OUT].name)
12434 json_object_string_add(json_addr,
12435 "outgoingUpdatePrefixFilterList",
12436 filter->plist[FILTER_OUT].name);
12437
12438 /* distribute-list */
12439 if (filter->dlist[FILTER_IN].name)
12440 json_object_string_add(
12441 json_addr, "incomingUpdateNetworkFilterList",
12442 filter->dlist[FILTER_IN].name);
12443 if (filter->dlist[FILTER_OUT].name)
12444 json_object_string_add(
12445 json_addr, "outgoingUpdateNetworkFilterList",
12446 filter->dlist[FILTER_OUT].name);
12447
12448 /* filter-list. */
12449 if (filter->aslist[FILTER_IN].name)
12450 json_object_string_add(json_addr,
12451 "incomingUpdateAsPathFilterList",
12452 filter->aslist[FILTER_IN].name);
12453 if (filter->aslist[FILTER_OUT].name)
12454 json_object_string_add(json_addr,
12455 "outgoingUpdateAsPathFilterList",
12456 filter->aslist[FILTER_OUT].name);
12457
12458 /* route-map. */
12459 if (filter->map[RMAP_IN].name)
12460 json_object_string_add(
12461 json_addr, "routeMapForIncomingAdvertisements",
12462 filter->map[RMAP_IN].name);
12463 if (filter->map[RMAP_OUT].name)
12464 json_object_string_add(
12465 json_addr, "routeMapForOutgoingAdvertisements",
12466 filter->map[RMAP_OUT].name);
12467
12468 /* ebgp-requires-policy (inbound) */
12469 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12470 && !bgp_inbound_policy_exists(p, filter))
12471 json_object_string_add(
12472 json_addr, "inboundEbgpRequiresPolicy",
12473 "Inbound updates discarded due to missing policy");
12474
12475 /* ebgp-requires-policy (outbound) */
12476 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12477 && (!bgp_outbound_policy_exists(p, filter)))
12478 json_object_string_add(
12479 json_addr, "outboundEbgpRequiresPolicy",
12480 "Outbound updates discarded due to missing policy");
12481
12482 /* unsuppress-map */
12483 if (filter->usmap.name)
12484 json_object_string_add(json_addr,
12485 "selectiveUnsuppressRouteMap",
12486 filter->usmap.name);
12487
12488 /* advertise-map */
12489 if (filter->advmap.aname) {
12490 json_advmap = json_object_new_object();
12491 json_object_string_add(json_advmap, "condition",
12492 filter->advmap.condition
12493 ? "EXIST"
12494 : "NON_EXIST");
12495 json_object_string_add(json_advmap, "conditionMap",
12496 filter->advmap.cname);
12497 json_object_string_add(json_advmap, "advertiseMap",
12498 filter->advmap.aname);
12499 json_object_string_add(
12500 json_advmap, "advertiseStatus",
12501 filter->advmap.update_type ==
12502 UPDATE_TYPE_ADVERTISE
12503 ? "Advertise"
12504 : "Withdraw");
12505 json_object_object_add(json_addr, "advertiseMap",
12506 json_advmap);
12507 }
12508
12509 /* Receive prefix count */
12510 json_object_int_add(json_addr, "acceptedPrefixCounter",
12511 p->pcount[afi][safi]);
12512 if (paf && PAF_SUBGRP(paf))
12513 json_object_int_add(json_addr, "sentPrefixCounter",
12514 (PAF_SUBGRP(paf))->scount);
12515
12516 /* Maximum prefix */
12517 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12518 json_object_int_add(json_addr, "prefixOutAllowedMax",
12519 p->pmax_out[afi][safi]);
12520
12521 /* Maximum prefix */
12522 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12523 json_object_int_add(json_addr, "prefixAllowedMax",
12524 p->pmax[afi][safi]);
12525 if (CHECK_FLAG(p->af_flags[afi][safi],
12526 PEER_FLAG_MAX_PREFIX_WARNING))
12527 json_object_boolean_true_add(
12528 json_addr, "prefixAllowedMaxWarning");
12529 json_object_int_add(json_addr,
12530 "prefixAllowedWarningThresh",
12531 p->pmax_threshold[afi][safi]);
12532 if (p->pmax_restart[afi][safi])
12533 json_object_int_add(
12534 json_addr,
12535 "prefixAllowedRestartIntervalMsecs",
12536 p->pmax_restart[afi][safi] * 60000);
12537 }
12538 json_object_object_add(json_neigh,
12539 get_afi_safi_str(afi, safi, true),
12540 json_addr);
12541
12542 } else {
12543 filter = &p->filter[afi][safi];
12544
12545 vty_out(vty, " For address family: %s\n",
12546 get_afi_safi_str(afi, safi, false));
12547
12548 if (peer_group_active(p))
12549 vty_out(vty, " %s peer-group member\n",
12550 p->group->name);
12551
12552 paf = peer_af_find(p, afi, safi);
12553 if (paf && PAF_SUBGRP(paf)) {
12554 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12555 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12556 vty_out(vty, " Packet Queue length %d\n",
12557 bpacket_queue_virtual_length(paf));
12558 } else {
12559 vty_out(vty, " Not part of any update group\n");
12560 }
12561 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12562 || CHECK_FLAG(p->af_cap[afi][safi],
12563 PEER_CAP_ORF_PREFIX_SM_RCV)
12564 || CHECK_FLAG(p->af_cap[afi][safi],
12565 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12566 || CHECK_FLAG(p->af_cap[afi][safi],
12567 PEER_CAP_ORF_PREFIX_RM_ADV)
12568 || CHECK_FLAG(p->af_cap[afi][safi],
12569 PEER_CAP_ORF_PREFIX_RM_RCV)
12570 || CHECK_FLAG(p->af_cap[afi][safi],
12571 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12572 vty_out(vty, " AF-dependant capabilities:\n");
12573
12574 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12575 || CHECK_FLAG(p->af_cap[afi][safi],
12576 PEER_CAP_ORF_PREFIX_SM_RCV)
12577 || CHECK_FLAG(p->af_cap[afi][safi],
12578 PEER_CAP_ORF_PREFIX_RM_ADV)
12579 || CHECK_FLAG(p->af_cap[afi][safi],
12580 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12581 vty_out(vty,
12582 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12583 ORF_TYPE_PREFIX);
12584 bgp_show_peer_afi_orf_cap(
12585 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12586 PEER_CAP_ORF_PREFIX_RM_ADV,
12587 PEER_CAP_ORF_PREFIX_SM_RCV,
12588 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12589 }
12590 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12591 || CHECK_FLAG(p->af_cap[afi][safi],
12592 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12593 || CHECK_FLAG(p->af_cap[afi][safi],
12594 PEER_CAP_ORF_PREFIX_RM_ADV)
12595 || CHECK_FLAG(p->af_cap[afi][safi],
12596 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12597 vty_out(vty,
12598 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12599 ORF_TYPE_PREFIX_OLD);
12600 bgp_show_peer_afi_orf_cap(
12601 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12602 PEER_CAP_ORF_PREFIX_RM_ADV,
12603 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12604 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12605 }
12606
12607 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12608 p->host, afi, safi);
12609 orf_pfx_count = prefix_bgp_show_prefix_list(
12610 NULL, afi, orf_pfx_name, use_json);
12611
12612 if (CHECK_FLAG(p->af_sflags[afi][safi],
12613 PEER_STATUS_ORF_PREFIX_SEND)
12614 || orf_pfx_count) {
12615 vty_out(vty, " Outbound Route Filter (ORF):");
12616 if (CHECK_FLAG(p->af_sflags[afi][safi],
12617 PEER_STATUS_ORF_PREFIX_SEND))
12618 vty_out(vty, " sent;");
12619 if (orf_pfx_count)
12620 vty_out(vty, " received (%d entries)",
12621 orf_pfx_count);
12622 vty_out(vty, "\n");
12623 }
12624 if (CHECK_FLAG(p->af_sflags[afi][safi],
12625 PEER_STATUS_ORF_WAIT_REFRESH))
12626 vty_out(vty,
12627 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12628
12629 if (CHECK_FLAG(p->af_flags[afi][safi],
12630 PEER_FLAG_REFLECTOR_CLIENT))
12631 vty_out(vty, " Route-Reflector Client\n");
12632 if (CHECK_FLAG(p->af_flags[afi][safi],
12633 PEER_FLAG_RSERVER_CLIENT))
12634 vty_out(vty, " Route-Server Client\n");
12635
12636 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12637 vty_out(vty, " ORR group (configured) : %s\n",
12638 p->orr_group_name[afi][safi]);
12639
12640 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12641 vty_out(vty,
12642 " Inbound soft reconfiguration allowed\n");
12643
12644 if (CHECK_FLAG(p->af_flags[afi][safi],
12645 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12646 vty_out(vty,
12647 " Private AS numbers (all) replaced in updates to this neighbor\n");
12648 else if (CHECK_FLAG(p->af_flags[afi][safi],
12649 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12650 vty_out(vty,
12651 " Private AS numbers replaced in updates to this neighbor\n");
12652 else if (CHECK_FLAG(p->af_flags[afi][safi],
12653 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12654 vty_out(vty,
12655 " Private AS numbers (all) removed in updates to this neighbor\n");
12656 else if (CHECK_FLAG(p->af_flags[afi][safi],
12657 PEER_FLAG_REMOVE_PRIVATE_AS))
12658 vty_out(vty,
12659 " Private AS numbers removed in updates to this neighbor\n");
12660
12661 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12662 if (CHECK_FLAG(p->af_flags[afi][safi],
12663 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12664 vty_out(vty,
12665 " Local AS allowed as path origin\n");
12666 else
12667 vty_out(vty,
12668 " Local AS allowed in path, %d occurrences\n",
12669 p->allowas_in[afi][safi]);
12670 }
12671
12672 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12673 vty_out(vty, " %s\n",
12674 bgp_addpath_names(p->addpath_type[afi][safi])
12675 ->human_description);
12676
12677 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12678 vty_out(vty,
12679 " Override ASNs in outbound updates if aspath equals remote-as\n");
12680
12681 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12682 || CHECK_FLAG(p->af_flags[afi][safi],
12683 PEER_FLAG_FORCE_NEXTHOP_SELF))
12684 vty_out(vty, " NEXT_HOP is always this router\n");
12685 if (CHECK_FLAG(p->af_flags[afi][safi],
12686 PEER_FLAG_AS_PATH_UNCHANGED))
12687 vty_out(vty,
12688 " AS_PATH is propagated unchanged to this neighbor\n");
12689 if (CHECK_FLAG(p->af_flags[afi][safi],
12690 PEER_FLAG_NEXTHOP_UNCHANGED))
12691 vty_out(vty,
12692 " NEXT_HOP is propagated unchanged to this neighbor\n");
12693 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12694 vty_out(vty,
12695 " MED is propagated unchanged to this neighbor\n");
12696 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12697 || CHECK_FLAG(p->af_flags[afi][safi],
12698 PEER_FLAG_SEND_EXT_COMMUNITY)
12699 || CHECK_FLAG(p->af_flags[afi][safi],
12700 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12701 vty_out(vty,
12702 " Community attribute sent to this neighbor");
12703 if (CHECK_FLAG(p->af_flags[afi][safi],
12704 PEER_FLAG_SEND_COMMUNITY)
12705 && CHECK_FLAG(p->af_flags[afi][safi],
12706 PEER_FLAG_SEND_EXT_COMMUNITY)
12707 && CHECK_FLAG(p->af_flags[afi][safi],
12708 PEER_FLAG_SEND_LARGE_COMMUNITY))
12709 vty_out(vty, "(all)\n");
12710 else if (CHECK_FLAG(p->af_flags[afi][safi],
12711 PEER_FLAG_SEND_LARGE_COMMUNITY))
12712 vty_out(vty, "(large)\n");
12713 else if (CHECK_FLAG(p->af_flags[afi][safi],
12714 PEER_FLAG_SEND_EXT_COMMUNITY))
12715 vty_out(vty, "(extended)\n");
12716 else
12717 vty_out(vty, "(standard)\n");
12718 }
12719 if (CHECK_FLAG(p->af_flags[afi][safi],
12720 PEER_FLAG_DEFAULT_ORIGINATE)) {
12721 vty_out(vty, " Default information originate,");
12722
12723 if (p->default_rmap[afi][safi].name)
12724 vty_out(vty, " default route-map %s%s,",
12725 p->default_rmap[afi][safi].map ? "*"
12726 : "",
12727 p->default_rmap[afi][safi].name);
12728 if (paf && PAF_SUBGRP(paf)
12729 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12730 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12731 vty_out(vty, " default sent\n");
12732 else
12733 vty_out(vty, " default not sent\n");
12734 }
12735
12736 /* advertise-vni-all */
12737 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12738 if (is_evpn_enabled())
12739 vty_out(vty, " advertise-all-vni\n");
12740 }
12741
12742 if (filter->plist[FILTER_IN].name
12743 || filter->dlist[FILTER_IN].name
12744 || filter->aslist[FILTER_IN].name
12745 || filter->map[RMAP_IN].name)
12746 vty_out(vty, " Inbound path policy configured\n");
12747 if (filter->plist[FILTER_OUT].name
12748 || filter->dlist[FILTER_OUT].name
12749 || filter->aslist[FILTER_OUT].name
12750 || filter->map[RMAP_OUT].name || filter->usmap.name)
12751 vty_out(vty, " Outbound path policy configured\n");
12752
12753 /* prefix-list */
12754 if (filter->plist[FILTER_IN].name)
12755 vty_out(vty,
12756 " Incoming update prefix filter list is %s%s\n",
12757 filter->plist[FILTER_IN].plist ? "*" : "",
12758 filter->plist[FILTER_IN].name);
12759 if (filter->plist[FILTER_OUT].name)
12760 vty_out(vty,
12761 " Outgoing update prefix filter list is %s%s\n",
12762 filter->plist[FILTER_OUT].plist ? "*" : "",
12763 filter->plist[FILTER_OUT].name);
12764
12765 /* distribute-list */
12766 if (filter->dlist[FILTER_IN].name)
12767 vty_out(vty,
12768 " Incoming update network filter list is %s%s\n",
12769 filter->dlist[FILTER_IN].alist ? "*" : "",
12770 filter->dlist[FILTER_IN].name);
12771 if (filter->dlist[FILTER_OUT].name)
12772 vty_out(vty,
12773 " Outgoing update network filter list is %s%s\n",
12774 filter->dlist[FILTER_OUT].alist ? "*" : "",
12775 filter->dlist[FILTER_OUT].name);
12776
12777 /* filter-list. */
12778 if (filter->aslist[FILTER_IN].name)
12779 vty_out(vty,
12780 " Incoming update AS path filter list is %s%s\n",
12781 filter->aslist[FILTER_IN].aslist ? "*" : "",
12782 filter->aslist[FILTER_IN].name);
12783 if (filter->aslist[FILTER_OUT].name)
12784 vty_out(vty,
12785 " Outgoing update AS path filter list is %s%s\n",
12786 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12787 filter->aslist[FILTER_OUT].name);
12788
12789 /* route-map. */
12790 if (filter->map[RMAP_IN].name)
12791 vty_out(vty,
12792 " Route map for incoming advertisements is %s%s\n",
12793 filter->map[RMAP_IN].map ? "*" : "",
12794 filter->map[RMAP_IN].name);
12795 if (filter->map[RMAP_OUT].name)
12796 vty_out(vty,
12797 " Route map for outgoing advertisements is %s%s\n",
12798 filter->map[RMAP_OUT].map ? "*" : "",
12799 filter->map[RMAP_OUT].name);
12800
12801 /* ebgp-requires-policy (inbound) */
12802 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12803 && !bgp_inbound_policy_exists(p, filter))
12804 vty_out(vty,
12805 " Inbound updates discarded due to missing policy\n");
12806
12807 /* ebgp-requires-policy (outbound) */
12808 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12809 && !bgp_outbound_policy_exists(p, filter))
12810 vty_out(vty,
12811 " Outbound updates discarded due to missing policy\n");
12812
12813 /* unsuppress-map */
12814 if (filter->usmap.name)
12815 vty_out(vty,
12816 " Route map for selective unsuppress is %s%s\n",
12817 filter->usmap.map ? "*" : "",
12818 filter->usmap.name);
12819
12820 /* advertise-map */
12821 if (filter->advmap.aname && filter->advmap.cname)
12822 vty_out(vty,
12823 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12824 filter->advmap.condition ? "EXIST"
12825 : "NON_EXIST",
12826 filter->advmap.cmap ? "*" : "",
12827 filter->advmap.cname,
12828 filter->advmap.amap ? "*" : "",
12829 filter->advmap.aname,
12830 filter->advmap.update_type ==
12831 UPDATE_TYPE_ADVERTISE
12832 ? "Advertise"
12833 : "Withdraw");
12834
12835 /* Receive prefix count */
12836 vty_out(vty, " %u accepted prefixes\n",
12837 p->pcount[afi][safi]);
12838
12839 /* maximum-prefix-out */
12840 if (CHECK_FLAG(p->af_flags[afi][safi],
12841 PEER_FLAG_MAX_PREFIX_OUT))
12842 vty_out(vty,
12843 " Maximum allowed prefixes sent %u\n",
12844 p->pmax_out[afi][safi]);
12845
12846 /* Maximum prefix */
12847 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12848 vty_out(vty,
12849 " Maximum prefixes allowed %u%s\n",
12850 p->pmax[afi][safi],
12851 CHECK_FLAG(p->af_flags[afi][safi],
12852 PEER_FLAG_MAX_PREFIX_WARNING)
12853 ? " (warning-only)"
12854 : "");
12855 vty_out(vty, " Threshold for warning message %d%%",
12856 p->pmax_threshold[afi][safi]);
12857 if (p->pmax_restart[afi][safi])
12858 vty_out(vty, ", restart interval %d min",
12859 p->pmax_restart[afi][safi]);
12860 vty_out(vty, "\n");
12861 }
12862
12863 vty_out(vty, "\n");
12864 }
12865 }
12866
12867 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12868 json_object *json)
12869 {
12870 struct bgp *bgp;
12871 char timebuf[BGP_UPTIME_LEN];
12872 char dn_flag[2];
12873 afi_t afi;
12874 safi_t safi;
12875 uint16_t i;
12876 uint8_t *msg;
12877 json_object *json_neigh = NULL;
12878 time_t epoch_tbuf;
12879 uint32_t sync_tcp_mss;
12880
12881 bgp = p->bgp;
12882
12883 if (use_json)
12884 json_neigh = json_object_new_object();
12885
12886 memset(dn_flag, '\0', sizeof(dn_flag));
12887 if (!p->conf_if && peer_dynamic_neighbor(p))
12888 dn_flag[0] = '*';
12889
12890 if (!use_json) {
12891 if (p->conf_if) /* Configured interface name. */
12892 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12893 &p->su);
12894 else /* Configured IP address. */
12895 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12896 p->host);
12897 }
12898
12899 if (use_json) {
12900 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12901 json_object_string_add(json_neigh, "bgpNeighborAddr",
12902 "none");
12903 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12904 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12905 "%pSU", &p->su);
12906
12907 json_object_int_add(json_neigh, "remoteAs", p->as);
12908
12909 if (p->change_local_as)
12910 json_object_int_add(json_neigh, "localAs",
12911 p->change_local_as);
12912 else
12913 json_object_int_add(json_neigh, "localAs", p->local_as);
12914
12915 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12916 json_object_boolean_true_add(json_neigh,
12917 "localAsNoPrepend");
12918
12919 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12920 json_object_boolean_true_add(json_neigh,
12921 "localAsReplaceAs");
12922 } else {
12923 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12924 || (p->as_type == AS_INTERNAL))
12925 vty_out(vty, "remote AS %u, ", p->as);
12926 else
12927 vty_out(vty, "remote AS Unspecified, ");
12928 vty_out(vty, "local AS %u%s%s, ",
12929 p->change_local_as ? p->change_local_as : p->local_as,
12930 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12931 ? " no-prepend"
12932 : "",
12933 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12934 ? " replace-as"
12935 : "");
12936 }
12937 /* peer type internal or confed-internal */
12938 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12939 if (use_json) {
12940 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12941 json_object_boolean_true_add(
12942 json_neigh, "nbrConfedInternalLink");
12943 else
12944 json_object_boolean_true_add(json_neigh,
12945 "nbrInternalLink");
12946 } else {
12947 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12948 vty_out(vty, "confed-internal link\n");
12949 else
12950 vty_out(vty, "internal link\n");
12951 }
12952 /* peer type external or confed-external */
12953 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12954 if (use_json) {
12955 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12956 json_object_boolean_true_add(
12957 json_neigh, "nbrConfedExternalLink");
12958 else
12959 json_object_boolean_true_add(json_neigh,
12960 "nbrExternalLink");
12961 } else {
12962 if (bgp_confederation_peers_check(bgp, p->as))
12963 vty_out(vty, "confed-external link\n");
12964 else
12965 vty_out(vty, "external link\n");
12966 }
12967 } else {
12968 if (use_json)
12969 json_object_boolean_true_add(json_neigh,
12970 "nbrUnspecifiedLink");
12971 else
12972 vty_out(vty, "unspecified link\n");
12973 }
12974
12975 /* Roles */
12976 if (use_json) {
12977 json_object_string_add(json_neigh, "localRole",
12978 bgp_get_name_by_role(p->local_role));
12979 json_object_string_add(json_neigh, "remoteRole",
12980 bgp_get_name_by_role(p->remote_role));
12981 } else {
12982 vty_out(vty, " Local Role: %s\n",
12983 bgp_get_name_by_role(p->local_role));
12984 vty_out(vty, " Remote Role: %s\n",
12985 bgp_get_name_by_role(p->remote_role));
12986 }
12987
12988
12989 /* Description. */
12990 if (p->desc) {
12991 if (use_json)
12992 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12993 else
12994 vty_out(vty, " Description: %s\n", p->desc);
12995 }
12996
12997 if (p->hostname) {
12998 if (use_json) {
12999 json_object_string_add(json_neigh, "hostname",
13000 p->hostname);
13001
13002 if (p->domainname)
13003 json_object_string_add(json_neigh, "domainname",
13004 p->domainname);
13005 } else {
13006 if (p->domainname && (p->domainname[0] != '\0'))
13007 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13008 p->domainname);
13009 else
13010 vty_out(vty, "Hostname: %s\n", p->hostname);
13011 }
13012 } else {
13013 if (use_json)
13014 json_object_string_add(json_neigh, "hostname",
13015 "Unknown");
13016 }
13017
13018 /* Peer-group */
13019 if (p->group) {
13020 if (use_json) {
13021 json_object_string_add(json_neigh, "peerGroup",
13022 p->group->name);
13023
13024 if (dn_flag[0]) {
13025 struct prefix prefix, *range = NULL;
13026
13027 if (sockunion2hostprefix(&(p->su), &prefix))
13028 range = peer_group_lookup_dynamic_neighbor_range(
13029 p->group, &prefix);
13030
13031 if (range) {
13032 json_object_string_addf(
13033 json_neigh,
13034 "peerSubnetRangeGroup", "%pFX",
13035 range);
13036 }
13037 }
13038 } else {
13039 vty_out(vty,
13040 " Member of peer-group %s for session parameters\n",
13041 p->group->name);
13042
13043 if (dn_flag[0]) {
13044 struct prefix prefix, *range = NULL;
13045
13046 if (sockunion2hostprefix(&(p->su), &prefix))
13047 range = peer_group_lookup_dynamic_neighbor_range(
13048 p->group, &prefix);
13049
13050 if (range) {
13051 vty_out(vty,
13052 " Belongs to the subnet range group: %pFX\n",
13053 range);
13054 }
13055 }
13056 }
13057 }
13058
13059 if (use_json) {
13060 /* Administrative shutdown. */
13061 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13062 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13063 json_object_boolean_true_add(json_neigh,
13064 "adminShutDown");
13065
13066 /* BGP Version. */
13067 json_object_int_add(json_neigh, "bgpVersion", 4);
13068 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13069 &p->remote_id);
13070 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13071 &bgp->router_id);
13072
13073 /* Confederation */
13074 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13075 && bgp_confederation_peers_check(bgp, p->as))
13076 json_object_boolean_true_add(json_neigh,
13077 "nbrCommonAdmin");
13078
13079 /* Status. */
13080 json_object_string_add(
13081 json_neigh, "bgpState",
13082 lookup_msg(bgp_status_msg, p->status, NULL));
13083
13084 if (peer_established(p)) {
13085 time_t uptime;
13086
13087 uptime = monotime(NULL);
13088 uptime -= p->uptime;
13089 epoch_tbuf = time(NULL) - uptime;
13090
13091 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13092 uptime * 1000);
13093 json_object_string_add(json_neigh, "bgpTimerUpString",
13094 peer_uptime(p->uptime, timebuf,
13095 BGP_UPTIME_LEN, 0,
13096 NULL));
13097 json_object_int_add(json_neigh,
13098 "bgpTimerUpEstablishedEpoch",
13099 epoch_tbuf);
13100 }
13101
13102 else if (p->status == Active) {
13103 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13104 json_object_string_add(json_neigh, "bgpStateIs",
13105 "passive");
13106 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13107 json_object_string_add(json_neigh, "bgpStateIs",
13108 "passiveNSF");
13109 }
13110
13111 /* read timer */
13112 time_t uptime;
13113 struct tm tm;
13114
13115 uptime = monotime(NULL);
13116 uptime -= p->readtime;
13117 gmtime_r(&uptime, &tm);
13118
13119 json_object_int_add(json_neigh, "bgpTimerLastRead",
13120 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13121 + (tm.tm_hour * 3600000));
13122
13123 uptime = monotime(NULL);
13124 uptime -= p->last_write;
13125 gmtime_r(&uptime, &tm);
13126
13127 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13128 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13129 + (tm.tm_hour * 3600000));
13130
13131 uptime = monotime(NULL);
13132 uptime -= p->update_time;
13133 gmtime_r(&uptime, &tm);
13134
13135 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13136 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13137 + (tm.tm_hour * 3600000));
13138
13139 /* Configured timer values. */
13140 json_object_int_add(json_neigh,
13141 "bgpTimerConfiguredHoldTimeMsecs",
13142 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13143 ? p->holdtime * 1000
13144 : bgp->default_holdtime * 1000);
13145 json_object_int_add(json_neigh,
13146 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13147 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13148 ? p->keepalive * 1000
13149 : bgp->default_keepalive * 1000);
13150 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13151 p->v_holdtime * 1000);
13152 json_object_int_add(json_neigh,
13153 "bgpTimerKeepAliveIntervalMsecs",
13154 p->v_keepalive * 1000);
13155 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13156 json_object_int_add(json_neigh,
13157 "bgpTimerDelayOpenTimeMsecs",
13158 p->v_delayopen * 1000);
13159 }
13160
13161 /* Configured and Synced tcp-mss value for peer */
13162 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13163 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13164 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13165 p->tcp_mss);
13166 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13167 sync_tcp_mss);
13168 }
13169
13170 /* Extended Optional Parameters Length for BGP OPEN Message */
13171 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13172 json_object_boolean_true_add(
13173 json_neigh, "extendedOptionalParametersLength");
13174 else
13175 json_object_boolean_false_add(
13176 json_neigh, "extendedOptionalParametersLength");
13177
13178 /* Conditional advertisements */
13179 json_object_int_add(
13180 json_neigh,
13181 "bgpTimerConfiguredConditionalAdvertisementsSec",
13182 bgp->condition_check_period);
13183 if (thread_is_scheduled(bgp->t_condition_check))
13184 json_object_int_add(
13185 json_neigh,
13186 "bgpTimerUntilConditionalAdvertisementsSec",
13187 thread_timer_remain_second(
13188 bgp->t_condition_check));
13189 } else {
13190 /* Administrative shutdown. */
13191 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13192 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13193 vty_out(vty, " Administratively shut down\n");
13194
13195 /* BGP Version. */
13196 vty_out(vty, " BGP version 4");
13197 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13198 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13199
13200 /* Confederation */
13201 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13202 && bgp_confederation_peers_check(bgp, p->as))
13203 vty_out(vty,
13204 " Neighbor under common administration\n");
13205
13206 /* Status. */
13207 vty_out(vty, " BGP state = %s",
13208 lookup_msg(bgp_status_msg, p->status, NULL));
13209
13210 if (peer_established(p))
13211 vty_out(vty, ", up for %8s",
13212 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13213 0, NULL));
13214
13215 else if (p->status == Active) {
13216 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13217 vty_out(vty, " (passive)");
13218 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13219 vty_out(vty, " (NSF passive)");
13220 }
13221 vty_out(vty, "\n");
13222
13223 /* read timer */
13224 vty_out(vty, " Last read %s",
13225 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13226 NULL));
13227 vty_out(vty, ", Last write %s\n",
13228 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13229 NULL));
13230
13231 /* Configured timer values. */
13232 vty_out(vty,
13233 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13234 p->v_holdtime, p->v_keepalive);
13235 vty_out(vty, " Configured hold time is %d seconds",
13236 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13237 ? p->holdtime
13238 : bgp->default_holdtime);
13239 vty_out(vty, ", keepalive interval is %d seconds\n",
13240 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13241 ? p->keepalive
13242 : bgp->default_keepalive);
13243 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13244 vty_out(vty,
13245 " Configured DelayOpenTime is %d seconds\n",
13246 p->delayopen);
13247
13248 /* Configured and synced tcp-mss value for peer */
13249 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13250 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13251 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13252 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13253 }
13254
13255 /* Extended Optional Parameters Length for BGP OPEN Message */
13256 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13257 vty_out(vty,
13258 " Extended Optional Parameters Length is enabled\n");
13259
13260 /* Conditional advertisements */
13261 vty_out(vty,
13262 " Configured conditional advertisements interval is %d seconds\n",
13263 bgp->condition_check_period);
13264 if (thread_is_scheduled(bgp->t_condition_check))
13265 vty_out(vty,
13266 " Time until conditional advertisements begin is %lu seconds\n",
13267 thread_timer_remain_second(
13268 bgp->t_condition_check));
13269 }
13270 /* Capability. */
13271 if (peer_established(p) &&
13272 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13273 if (use_json) {
13274 json_object *json_cap = NULL;
13275
13276 json_cap = json_object_new_object();
13277
13278 /* AS4 */
13279 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13280 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13281 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13282 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13283 json_object_string_add(
13284 json_cap, "4byteAs",
13285 "advertisedAndReceived");
13286 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13287 json_object_string_add(json_cap,
13288 "4byteAs",
13289 "advertised");
13290 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13291 json_object_string_add(json_cap,
13292 "4byteAs",
13293 "received");
13294 }
13295
13296 /* Extended Message Support */
13297 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13298 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13299 json_object_string_add(json_cap,
13300 "extendedMessage",
13301 "advertisedAndReceived");
13302 else if (CHECK_FLAG(p->cap,
13303 PEER_CAP_EXTENDED_MESSAGE_ADV))
13304 json_object_string_add(json_cap,
13305 "extendedMessage",
13306 "advertised");
13307 else if (CHECK_FLAG(p->cap,
13308 PEER_CAP_EXTENDED_MESSAGE_RCV))
13309 json_object_string_add(json_cap,
13310 "extendedMessage",
13311 "received");
13312
13313 /* AddPath */
13314 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13315 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13316 json_object *json_add = NULL;
13317 const char *print_store;
13318
13319 json_add = json_object_new_object();
13320
13321 FOREACH_AFI_SAFI (afi, safi) {
13322 json_object *json_sub = NULL;
13323 json_sub = json_object_new_object();
13324 print_store = get_afi_safi_str(
13325 afi, safi, true);
13326
13327 if (CHECK_FLAG(
13328 p->af_cap[afi][safi],
13329 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13330 CHECK_FLAG(
13331 p->af_cap[afi][safi],
13332 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13333 if (CHECK_FLAG(
13334 p->af_cap[afi]
13335 [safi],
13336 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13337 CHECK_FLAG(
13338 p->af_cap[afi]
13339 [safi],
13340 PEER_CAP_ADDPATH_AF_TX_RCV))
13341 json_object_boolean_true_add(
13342 json_sub,
13343 "txAdvertisedAndReceived");
13344 else if (
13345 CHECK_FLAG(
13346 p->af_cap[afi]
13347 [safi],
13348 PEER_CAP_ADDPATH_AF_TX_ADV))
13349 json_object_boolean_true_add(
13350 json_sub,
13351 "txAdvertised");
13352 else if (
13353 CHECK_FLAG(
13354 p->af_cap[afi]
13355 [safi],
13356 PEER_CAP_ADDPATH_AF_TX_RCV))
13357 json_object_boolean_true_add(
13358 json_sub,
13359 "txReceived");
13360 }
13361
13362 if (CHECK_FLAG(
13363 p->af_cap[afi][safi],
13364 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13365 CHECK_FLAG(
13366 p->af_cap[afi][safi],
13367 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13368 if (CHECK_FLAG(
13369 p->af_cap[afi]
13370 [safi],
13371 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13372 CHECK_FLAG(
13373 p->af_cap[afi]
13374 [safi],
13375 PEER_CAP_ADDPATH_AF_RX_RCV))
13376 json_object_boolean_true_add(
13377 json_sub,
13378 "rxAdvertisedAndReceived");
13379 else if (
13380 CHECK_FLAG(
13381 p->af_cap[afi]
13382 [safi],
13383 PEER_CAP_ADDPATH_AF_RX_ADV))
13384 json_object_boolean_true_add(
13385 json_sub,
13386 "rxAdvertised");
13387 else if (
13388 CHECK_FLAG(
13389 p->af_cap[afi]
13390 [safi],
13391 PEER_CAP_ADDPATH_AF_RX_RCV))
13392 json_object_boolean_true_add(
13393 json_sub,
13394 "rxReceived");
13395 }
13396
13397 if (CHECK_FLAG(
13398 p->af_cap[afi][safi],
13399 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13400 CHECK_FLAG(
13401 p->af_cap[afi][safi],
13402 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13403 CHECK_FLAG(
13404 p->af_cap[afi][safi],
13405 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13406 CHECK_FLAG(
13407 p->af_cap[afi][safi],
13408 PEER_CAP_ADDPATH_AF_RX_RCV))
13409 json_object_object_add(
13410 json_add, print_store,
13411 json_sub);
13412 else
13413 json_object_free(json_sub);
13414 }
13415
13416 json_object_object_add(json_cap, "addPath",
13417 json_add);
13418 }
13419
13420 /* Dynamic */
13421 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13422 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13423 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13424 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13425 json_object_string_add(
13426 json_cap, "dynamic",
13427 "advertisedAndReceived");
13428 else if (CHECK_FLAG(p->cap,
13429 PEER_CAP_DYNAMIC_ADV))
13430 json_object_string_add(json_cap,
13431 "dynamic",
13432 "advertised");
13433 else if (CHECK_FLAG(p->cap,
13434 PEER_CAP_DYNAMIC_RCV))
13435 json_object_string_add(json_cap,
13436 "dynamic",
13437 "received");
13438 }
13439
13440 /* Role */
13441 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13442 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13443 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13444 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13445 json_object_string_add(
13446 json_cap, "role",
13447 "advertisedAndReceived");
13448 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13449 json_object_string_add(json_cap, "role",
13450 "advertised");
13451 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13452 json_object_string_add(json_cap, "role",
13453 "received");
13454 }
13455
13456 /* Extended nexthop */
13457 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13458 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13459 json_object *json_nxt = NULL;
13460 const char *print_store;
13461
13462
13463 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13464 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13465 json_object_string_add(
13466 json_cap, "extendedNexthop",
13467 "advertisedAndReceived");
13468 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13469 json_object_string_add(
13470 json_cap, "extendedNexthop",
13471 "advertised");
13472 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13473 json_object_string_add(
13474 json_cap, "extendedNexthop",
13475 "received");
13476
13477 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13478 json_nxt = json_object_new_object();
13479
13480 for (safi = SAFI_UNICAST;
13481 safi < SAFI_MAX; safi++) {
13482 if (CHECK_FLAG(
13483 p->af_cap[AFI_IP]
13484 [safi],
13485 PEER_CAP_ENHE_AF_RCV)) {
13486 print_store =
13487 get_afi_safi_str(
13488 AFI_IP,
13489 safi,
13490 true);
13491 json_object_string_add(
13492 json_nxt,
13493 print_store,
13494 "recieved"); /* misspelled for compatibility */
13495 }
13496 }
13497 json_object_object_add(
13498 json_cap,
13499 "extendedNexthopFamililesByPeer",
13500 json_nxt);
13501 }
13502 }
13503
13504 /* Long-lived Graceful Restart */
13505 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13506 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13507 json_object *json_llgr = NULL;
13508 const char *afi_safi_str;
13509
13510 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13511 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13512 json_object_string_add(
13513 json_cap,
13514 "longLivedGracefulRestart",
13515 "advertisedAndReceived");
13516 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13517 json_object_string_add(
13518 json_cap,
13519 "longLivedGracefulRestart",
13520 "advertised");
13521 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13522 json_object_string_add(
13523 json_cap,
13524 "longLivedGracefulRestart",
13525 "received");
13526
13527 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13528 json_llgr = json_object_new_object();
13529
13530 FOREACH_AFI_SAFI (afi, safi) {
13531 if (CHECK_FLAG(
13532 p->af_cap[afi]
13533 [safi],
13534 PEER_CAP_ENHE_AF_RCV)) {
13535 afi_safi_str =
13536 get_afi_safi_str(
13537 afi,
13538 safi,
13539 true);
13540 json_object_string_add(
13541 json_llgr,
13542 afi_safi_str,
13543 "received");
13544 }
13545 }
13546 json_object_object_add(
13547 json_cap,
13548 "longLivedGracefulRestartByPeer",
13549 json_llgr);
13550 }
13551 }
13552
13553 /* Route Refresh */
13554 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13555 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13556 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13557 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13558 (CHECK_FLAG(p->cap,
13559 PEER_CAP_REFRESH_NEW_RCV) ||
13560 CHECK_FLAG(p->cap,
13561 PEER_CAP_REFRESH_OLD_RCV))) {
13562 if (CHECK_FLAG(
13563 p->cap,
13564 PEER_CAP_REFRESH_OLD_RCV) &&
13565 CHECK_FLAG(
13566 p->cap,
13567 PEER_CAP_REFRESH_NEW_RCV))
13568 json_object_string_add(
13569 json_cap,
13570 "routeRefresh",
13571 "advertisedAndReceivedOldNew");
13572 else {
13573 if (CHECK_FLAG(
13574 p->cap,
13575 PEER_CAP_REFRESH_OLD_RCV))
13576 json_object_string_add(
13577 json_cap,
13578 "routeRefresh",
13579 "advertisedAndReceivedOld");
13580 else
13581 json_object_string_add(
13582 json_cap,
13583 "routeRefresh",
13584 "advertisedAndReceivedNew");
13585 }
13586 } else if (CHECK_FLAG(p->cap,
13587 PEER_CAP_REFRESH_ADV))
13588 json_object_string_add(json_cap,
13589 "routeRefresh",
13590 "advertised");
13591 else if (CHECK_FLAG(p->cap,
13592 PEER_CAP_REFRESH_NEW_RCV) ||
13593 CHECK_FLAG(p->cap,
13594 PEER_CAP_REFRESH_OLD_RCV))
13595 json_object_string_add(json_cap,
13596 "routeRefresh",
13597 "received");
13598 }
13599
13600 /* Enhanced Route Refresh */
13601 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13602 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13603 if (CHECK_FLAG(p->cap,
13604 PEER_CAP_ENHANCED_RR_ADV) &&
13605 CHECK_FLAG(p->cap,
13606 PEER_CAP_ENHANCED_RR_RCV))
13607 json_object_string_add(
13608 json_cap,
13609 "enhancedRouteRefresh",
13610 "advertisedAndReceived");
13611 else if (CHECK_FLAG(p->cap,
13612 PEER_CAP_ENHANCED_RR_ADV))
13613 json_object_string_add(
13614 json_cap,
13615 "enhancedRouteRefresh",
13616 "advertised");
13617 else if (CHECK_FLAG(p->cap,
13618 PEER_CAP_ENHANCED_RR_RCV))
13619 json_object_string_add(
13620 json_cap,
13621 "enhancedRouteRefresh",
13622 "received");
13623 }
13624
13625 /* Multiprotocol Extensions */
13626 json_object *json_multi = NULL;
13627
13628 json_multi = json_object_new_object();
13629
13630 FOREACH_AFI_SAFI (afi, safi) {
13631 if (p->afc_adv[afi][safi] ||
13632 p->afc_recv[afi][safi]) {
13633 json_object *json_exten = NULL;
13634 json_exten = json_object_new_object();
13635
13636 if (p->afc_adv[afi][safi] &&
13637 p->afc_recv[afi][safi])
13638 json_object_boolean_true_add(
13639 json_exten,
13640 "advertisedAndReceived");
13641 else if (p->afc_adv[afi][safi])
13642 json_object_boolean_true_add(
13643 json_exten,
13644 "advertised");
13645 else if (p->afc_recv[afi][safi])
13646 json_object_boolean_true_add(
13647 json_exten, "received");
13648
13649 json_object_object_add(
13650 json_multi,
13651 get_afi_safi_str(afi, safi,
13652 true),
13653 json_exten);
13654 }
13655 }
13656 json_object_object_add(json_cap,
13657 "multiprotocolExtensions",
13658 json_multi);
13659
13660 /* Hostname capabilities */
13661 json_object *json_hname = NULL;
13662
13663 json_hname = json_object_new_object();
13664
13665 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13666 json_object_string_add(
13667 json_hname, "advHostName",
13668 bgp->peer_self->hostname
13669 ? bgp->peer_self->hostname
13670 : "n/a");
13671 json_object_string_add(
13672 json_hname, "advDomainName",
13673 bgp->peer_self->domainname
13674 ? bgp->peer_self->domainname
13675 : "n/a");
13676 }
13677
13678
13679 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13680 json_object_string_add(
13681 json_hname, "rcvHostName",
13682 p->hostname ? p->hostname : "n/a");
13683 json_object_string_add(
13684 json_hname, "rcvDomainName",
13685 p->domainname ? p->domainname : "n/a");
13686 }
13687
13688 json_object_object_add(json_cap, "hostName",
13689 json_hname);
13690
13691 /* Graceful Restart */
13692 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13693 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13694 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13695 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13696 json_object_string_add(
13697 json_cap, "gracefulRestart",
13698 "advertisedAndReceived");
13699 else if (CHECK_FLAG(p->cap,
13700 PEER_CAP_RESTART_ADV))
13701 json_object_string_add(
13702 json_cap,
13703 "gracefulRestartCapability",
13704 "advertised");
13705 else if (CHECK_FLAG(p->cap,
13706 PEER_CAP_RESTART_RCV))
13707 json_object_string_add(
13708 json_cap,
13709 "gracefulRestartCapability",
13710 "received");
13711
13712 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13713 int restart_af_count = 0;
13714 json_object *json_restart = NULL;
13715 json_restart = json_object_new_object();
13716
13717 json_object_int_add(
13718 json_cap,
13719 "gracefulRestartRemoteTimerMsecs",
13720 p->v_gr_restart * 1000);
13721
13722 FOREACH_AFI_SAFI (afi, safi) {
13723 if (CHECK_FLAG(
13724 p->af_cap[afi]
13725 [safi],
13726 PEER_CAP_RESTART_AF_RCV)) {
13727 json_object *json_sub =
13728 NULL;
13729 json_sub =
13730 json_object_new_object();
13731
13732 if (CHECK_FLAG(
13733 p->af_cap
13734 [afi]
13735 [safi],
13736 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13737 json_object_boolean_true_add(
13738 json_sub,
13739 "preserved");
13740 restart_af_count++;
13741 json_object_object_add(
13742 json_restart,
13743 get_afi_safi_str(
13744 afi,
13745 safi,
13746 true),
13747 json_sub);
13748 }
13749 }
13750 if (!restart_af_count) {
13751 json_object_string_add(
13752 json_cap,
13753 "addressFamiliesByPeer",
13754 "none");
13755 json_object_free(json_restart);
13756 } else
13757 json_object_object_add(
13758 json_cap,
13759 "addressFamiliesByPeer",
13760 json_restart);
13761 }
13762 }
13763 json_object_object_add(
13764 json_neigh, "neighborCapabilities", json_cap);
13765 } else {
13766 vty_out(vty, " Neighbor capabilities:\n");
13767
13768 /* AS4 */
13769 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13770 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13771 vty_out(vty, " 4 Byte AS:");
13772 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13773 vty_out(vty, " advertised");
13774 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13775 vty_out(vty, " %sreceived",
13776 CHECK_FLAG(p->cap,
13777 PEER_CAP_AS4_ADV)
13778 ? "and "
13779 : "");
13780 vty_out(vty, "\n");
13781 }
13782
13783 /* Extended Message Support */
13784 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13785 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13786 vty_out(vty, " Extended Message:");
13787 if (CHECK_FLAG(p->cap,
13788 PEER_CAP_EXTENDED_MESSAGE_ADV))
13789 vty_out(vty, " advertised");
13790 if (CHECK_FLAG(p->cap,
13791 PEER_CAP_EXTENDED_MESSAGE_RCV))
13792 vty_out(vty, " %sreceived",
13793 CHECK_FLAG(
13794 p->cap,
13795 PEER_CAP_EXTENDED_MESSAGE_ADV)
13796 ? "and "
13797 : "");
13798 vty_out(vty, "\n");
13799 }
13800
13801 /* AddPath */
13802 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13803 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13804 vty_out(vty, " AddPath:\n");
13805
13806 FOREACH_AFI_SAFI (afi, safi) {
13807 if (CHECK_FLAG(
13808 p->af_cap[afi][safi],
13809 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13810 CHECK_FLAG(
13811 p->af_cap[afi][safi],
13812 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13813 vty_out(vty, " %s: TX ",
13814 get_afi_safi_str(
13815 afi, safi,
13816 false));
13817
13818 if (CHECK_FLAG(
13819 p->af_cap[afi]
13820 [safi],
13821 PEER_CAP_ADDPATH_AF_TX_ADV))
13822 vty_out(vty,
13823 "advertised");
13824
13825 if (CHECK_FLAG(
13826 p->af_cap[afi]
13827 [safi],
13828 PEER_CAP_ADDPATH_AF_TX_RCV))
13829 vty_out(vty,
13830 "%sreceived",
13831 CHECK_FLAG(
13832 p->af_cap
13833 [afi]
13834 [safi],
13835 PEER_CAP_ADDPATH_AF_TX_ADV)
13836 ? " and "
13837 : "");
13838
13839 vty_out(vty, "\n");
13840 }
13841
13842 if (CHECK_FLAG(
13843 p->af_cap[afi][safi],
13844 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13845 CHECK_FLAG(
13846 p->af_cap[afi][safi],
13847 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13848 vty_out(vty, " %s: RX ",
13849 get_afi_safi_str(
13850 afi, safi,
13851 false));
13852
13853 if (CHECK_FLAG(
13854 p->af_cap[afi]
13855 [safi],
13856 PEER_CAP_ADDPATH_AF_RX_ADV))
13857 vty_out(vty,
13858 "advertised");
13859
13860 if (CHECK_FLAG(
13861 p->af_cap[afi]
13862 [safi],
13863 PEER_CAP_ADDPATH_AF_RX_RCV))
13864 vty_out(vty,
13865 "%sreceived",
13866 CHECK_FLAG(
13867 p->af_cap
13868 [afi]
13869 [safi],
13870 PEER_CAP_ADDPATH_AF_RX_ADV)
13871 ? " and "
13872 : "");
13873
13874 vty_out(vty, "\n");
13875 }
13876 }
13877 }
13878
13879 /* Dynamic */
13880 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13881 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13882 vty_out(vty, " Dynamic:");
13883 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13884 vty_out(vty, " advertised");
13885 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13886 vty_out(vty, " %sreceived",
13887 CHECK_FLAG(p->cap,
13888 PEER_CAP_DYNAMIC_ADV)
13889 ? "and "
13890 : "");
13891 vty_out(vty, "\n");
13892 }
13893
13894 /* Role */
13895 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13896 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13897 vty_out(vty, " Role:");
13898 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13899 vty_out(vty, " advertised");
13900 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13901 vty_out(vty, " %sreceived",
13902 CHECK_FLAG(p->cap,
13903 PEER_CAP_ROLE_ADV)
13904 ? "and "
13905 : "");
13906 vty_out(vty, "\n");
13907 }
13908
13909 /* Extended nexthop */
13910 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13911 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13912 vty_out(vty, " Extended nexthop:");
13913 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13914 vty_out(vty, " advertised");
13915 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13916 vty_out(vty, " %sreceived",
13917 CHECK_FLAG(p->cap,
13918 PEER_CAP_ENHE_ADV)
13919 ? "and "
13920 : "");
13921 vty_out(vty, "\n");
13922
13923 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13924 vty_out(vty,
13925 " Address families by peer:\n ");
13926 for (safi = SAFI_UNICAST;
13927 safi < SAFI_MAX; safi++)
13928 if (CHECK_FLAG(
13929 p->af_cap[AFI_IP]
13930 [safi],
13931 PEER_CAP_ENHE_AF_RCV))
13932 vty_out(vty,
13933 " %s\n",
13934 get_afi_safi_str(
13935 AFI_IP,
13936 safi,
13937 false));
13938 }
13939 }
13940
13941 /* Long-lived Graceful Restart */
13942 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13943 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13944 vty_out(vty,
13945 " Long-lived Graceful Restart:");
13946 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13947 vty_out(vty, " advertised");
13948 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13949 vty_out(vty, " %sreceived",
13950 CHECK_FLAG(p->cap,
13951 PEER_CAP_LLGR_ADV)
13952 ? "and "
13953 : "");
13954 vty_out(vty, "\n");
13955
13956 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13957 vty_out(vty,
13958 " Address families by peer:\n");
13959 FOREACH_AFI_SAFI (afi, safi)
13960 if (CHECK_FLAG(
13961 p->af_cap[afi]
13962 [safi],
13963 PEER_CAP_LLGR_AF_RCV))
13964 vty_out(vty,
13965 " %s\n",
13966 get_afi_safi_str(
13967 afi,
13968 safi,
13969 false));
13970 }
13971 }
13972
13973 /* Route Refresh */
13974 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13975 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13976 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13977 vty_out(vty, " Route refresh:");
13978 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13979 vty_out(vty, " advertised");
13980 if (CHECK_FLAG(p->cap,
13981 PEER_CAP_REFRESH_NEW_RCV) ||
13982 CHECK_FLAG(p->cap,
13983 PEER_CAP_REFRESH_OLD_RCV))
13984 vty_out(vty, " %sreceived(%s)",
13985 CHECK_FLAG(p->cap,
13986 PEER_CAP_REFRESH_ADV)
13987 ? "and "
13988 : "",
13989 (CHECK_FLAG(
13990 p->cap,
13991 PEER_CAP_REFRESH_OLD_RCV) &&
13992 CHECK_FLAG(
13993 p->cap,
13994 PEER_CAP_REFRESH_NEW_RCV))
13995 ? "old & new"
13996 : CHECK_FLAG(
13997 p->cap,
13998 PEER_CAP_REFRESH_OLD_RCV)
13999 ? "old"
14000 : "new");
14001
14002 vty_out(vty, "\n");
14003 }
14004
14005 /* Enhanced Route Refresh */
14006 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14007 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14008 vty_out(vty, " Enhanced Route Refresh:");
14009 if (CHECK_FLAG(p->cap,
14010 PEER_CAP_ENHANCED_RR_ADV))
14011 vty_out(vty, " advertised");
14012 if (CHECK_FLAG(p->cap,
14013 PEER_CAP_ENHANCED_RR_RCV))
14014 vty_out(vty, " %sreceived",
14015 CHECK_FLAG(p->cap,
14016 PEER_CAP_REFRESH_ADV)
14017 ? "and "
14018 : "");
14019 vty_out(vty, "\n");
14020 }
14021
14022 /* Multiprotocol Extensions */
14023 FOREACH_AFI_SAFI (afi, safi)
14024 if (p->afc_adv[afi][safi] ||
14025 p->afc_recv[afi][safi]) {
14026 vty_out(vty, " Address Family %s:",
14027 get_afi_safi_str(afi, safi,
14028 false));
14029 if (p->afc_adv[afi][safi])
14030 vty_out(vty, " advertised");
14031 if (p->afc_recv[afi][safi])
14032 vty_out(vty, " %sreceived",
14033 p->afc_adv[afi][safi]
14034 ? "and "
14035 : "");
14036 vty_out(vty, "\n");
14037 }
14038
14039 /* Hostname capability */
14040 vty_out(vty, " Hostname Capability:");
14041
14042 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14043 vty_out(vty,
14044 " advertised (name: %s,domain name: %s)",
14045 bgp->peer_self->hostname
14046 ? bgp->peer_self->hostname
14047 : "n/a",
14048 bgp->peer_self->domainname
14049 ? bgp->peer_self->domainname
14050 : "n/a");
14051 } else {
14052 vty_out(vty, " not advertised");
14053 }
14054
14055 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14056 vty_out(vty,
14057 " received (name: %s,domain name: %s)",
14058 p->hostname ? p->hostname : "n/a",
14059 p->domainname ? p->domainname : "n/a");
14060 } else {
14061 vty_out(vty, " not received");
14062 }
14063
14064 vty_out(vty, "\n");
14065
14066 /* Graceful Restart */
14067 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14068 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14069 vty_out(vty,
14070 " Graceful Restart Capability:");
14071 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14072 vty_out(vty, " advertised");
14073 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14074 vty_out(vty, " %sreceived",
14075 CHECK_FLAG(p->cap,
14076 PEER_CAP_RESTART_ADV)
14077 ? "and "
14078 : "");
14079 vty_out(vty, "\n");
14080
14081 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14082 int restart_af_count = 0;
14083
14084 vty_out(vty,
14085 " Remote Restart timer is %d seconds\n",
14086 p->v_gr_restart);
14087 vty_out(vty,
14088 " Address families by peer:\n ");
14089
14090 FOREACH_AFI_SAFI (afi, safi)
14091 if (CHECK_FLAG(
14092 p->af_cap[afi]
14093 [safi],
14094 PEER_CAP_RESTART_AF_RCV)) {
14095 vty_out(vty, "%s%s(%s)",
14096 restart_af_count
14097 ? ", "
14098 : "",
14099 get_afi_safi_str(
14100 afi,
14101 safi,
14102 false),
14103 CHECK_FLAG(
14104 p->af_cap
14105 [afi]
14106 [safi],
14107 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14108 ? "preserved"
14109 : "not preserved");
14110 restart_af_count++;
14111 }
14112 if (!restart_af_count)
14113 vty_out(vty, "none");
14114 vty_out(vty, "\n");
14115 }
14116 } /* Graceful Restart */
14117 }
14118 }
14119
14120 /* graceful restart information */
14121 json_object *json_grace = NULL;
14122 json_object *json_grace_send = NULL;
14123 json_object *json_grace_recv = NULL;
14124 int eor_send_af_count = 0;
14125 int eor_receive_af_count = 0;
14126
14127 if (use_json) {
14128 json_grace = json_object_new_object();
14129 json_grace_send = json_object_new_object();
14130 json_grace_recv = json_object_new_object();
14131
14132 if ((peer_established(p)) &&
14133 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14134 FOREACH_AFI_SAFI (afi, safi) {
14135 if (CHECK_FLAG(p->af_sflags[afi][safi],
14136 PEER_STATUS_EOR_SEND)) {
14137 json_object_boolean_true_add(
14138 json_grace_send,
14139 get_afi_safi_str(afi, safi,
14140 true));
14141 eor_send_af_count++;
14142 }
14143 }
14144 FOREACH_AFI_SAFI (afi, safi) {
14145 if (CHECK_FLAG(p->af_sflags[afi][safi],
14146 PEER_STATUS_EOR_RECEIVED)) {
14147 json_object_boolean_true_add(
14148 json_grace_recv,
14149 get_afi_safi_str(afi, safi,
14150 true));
14151 eor_receive_af_count++;
14152 }
14153 }
14154 }
14155 json_object_object_add(json_grace, "endOfRibSend",
14156 json_grace_send);
14157 json_object_object_add(json_grace, "endOfRibRecv",
14158 json_grace_recv);
14159
14160
14161 if (p->t_gr_restart)
14162 json_object_int_add(
14163 json_grace, "gracefulRestartTimerMsecs",
14164 thread_timer_remain_second(p->t_gr_restart) *
14165 1000);
14166
14167 if (p->t_gr_stale)
14168 json_object_int_add(
14169 json_grace, "gracefulStalepathTimerMsecs",
14170 thread_timer_remain_second(p->t_gr_stale) *
14171 1000);
14172 /* more gr info in new format */
14173 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14174 json_object_object_add(json_neigh, "gracefulRestartInfo",
14175 json_grace);
14176 } else {
14177 vty_out(vty, " Graceful restart information:\n");
14178 if ((peer_established(p)) &&
14179 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14180
14181 vty_out(vty, " End-of-RIB send: ");
14182 FOREACH_AFI_SAFI (afi, safi) {
14183 if (CHECK_FLAG(p->af_sflags[afi][safi],
14184 PEER_STATUS_EOR_SEND)) {
14185 vty_out(vty, "%s%s",
14186 eor_send_af_count ? ", " : "",
14187 get_afi_safi_str(afi, safi,
14188 false));
14189 eor_send_af_count++;
14190 }
14191 }
14192 vty_out(vty, "\n");
14193 vty_out(vty, " End-of-RIB received: ");
14194 FOREACH_AFI_SAFI (afi, safi) {
14195 if (CHECK_FLAG(p->af_sflags[afi][safi],
14196 PEER_STATUS_EOR_RECEIVED)) {
14197 vty_out(vty, "%s%s",
14198 eor_receive_af_count ? ", "
14199 : "",
14200 get_afi_safi_str(afi, safi,
14201 false));
14202 eor_receive_af_count++;
14203 }
14204 }
14205 vty_out(vty, "\n");
14206 }
14207
14208 if (p->t_gr_restart)
14209 vty_out(vty,
14210 " The remaining time of restart timer is %ld\n",
14211 thread_timer_remain_second(p->t_gr_restart));
14212
14213 if (p->t_gr_stale)
14214 vty_out(vty,
14215 " The remaining time of stalepath timer is %ld\n",
14216 thread_timer_remain_second(p->t_gr_stale));
14217
14218 /* more gr info in new format */
14219 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14220 }
14221
14222 if (use_json) {
14223 json_object *json_stat = NULL;
14224 json_stat = json_object_new_object();
14225 /* Packet counts. */
14226
14227 atomic_size_t outq_count, inq_count;
14228 outq_count = atomic_load_explicit(&p->obuf->count,
14229 memory_order_relaxed);
14230 inq_count = atomic_load_explicit(&p->ibuf->count,
14231 memory_order_relaxed);
14232
14233 json_object_int_add(json_stat, "depthInq",
14234 (unsigned long)inq_count);
14235 json_object_int_add(json_stat, "depthOutq",
14236 (unsigned long)outq_count);
14237 json_object_int_add(json_stat, "opensSent",
14238 atomic_load_explicit(&p->open_out,
14239 memory_order_relaxed));
14240 json_object_int_add(json_stat, "opensRecv",
14241 atomic_load_explicit(&p->open_in,
14242 memory_order_relaxed));
14243 json_object_int_add(json_stat, "notificationsSent",
14244 atomic_load_explicit(&p->notify_out,
14245 memory_order_relaxed));
14246 json_object_int_add(json_stat, "notificationsRecv",
14247 atomic_load_explicit(&p->notify_in,
14248 memory_order_relaxed));
14249 json_object_int_add(json_stat, "updatesSent",
14250 atomic_load_explicit(&p->update_out,
14251 memory_order_relaxed));
14252 json_object_int_add(json_stat, "updatesRecv",
14253 atomic_load_explicit(&p->update_in,
14254 memory_order_relaxed));
14255 json_object_int_add(json_stat, "keepalivesSent",
14256 atomic_load_explicit(&p->keepalive_out,
14257 memory_order_relaxed));
14258 json_object_int_add(json_stat, "keepalivesRecv",
14259 atomic_load_explicit(&p->keepalive_in,
14260 memory_order_relaxed));
14261 json_object_int_add(json_stat, "routeRefreshSent",
14262 atomic_load_explicit(&p->refresh_out,
14263 memory_order_relaxed));
14264 json_object_int_add(json_stat, "routeRefreshRecv",
14265 atomic_load_explicit(&p->refresh_in,
14266 memory_order_relaxed));
14267 json_object_int_add(json_stat, "capabilitySent",
14268 atomic_load_explicit(&p->dynamic_cap_out,
14269 memory_order_relaxed));
14270 json_object_int_add(json_stat, "capabilityRecv",
14271 atomic_load_explicit(&p->dynamic_cap_in,
14272 memory_order_relaxed));
14273 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14274 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14275 json_object_object_add(json_neigh, "messageStats", json_stat);
14276 } else {
14277 atomic_size_t outq_count, inq_count, open_out, open_in,
14278 notify_out, notify_in, update_out, update_in,
14279 keepalive_out, keepalive_in, refresh_out, refresh_in,
14280 dynamic_cap_out, dynamic_cap_in;
14281 outq_count = atomic_load_explicit(&p->obuf->count,
14282 memory_order_relaxed);
14283 inq_count = atomic_load_explicit(&p->ibuf->count,
14284 memory_order_relaxed);
14285 open_out = atomic_load_explicit(&p->open_out,
14286 memory_order_relaxed);
14287 open_in =
14288 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14289 notify_out = atomic_load_explicit(&p->notify_out,
14290 memory_order_relaxed);
14291 notify_in = atomic_load_explicit(&p->notify_in,
14292 memory_order_relaxed);
14293 update_out = atomic_load_explicit(&p->update_out,
14294 memory_order_relaxed);
14295 update_in = atomic_load_explicit(&p->update_in,
14296 memory_order_relaxed);
14297 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14298 memory_order_relaxed);
14299 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14300 memory_order_relaxed);
14301 refresh_out = atomic_load_explicit(&p->refresh_out,
14302 memory_order_relaxed);
14303 refresh_in = atomic_load_explicit(&p->refresh_in,
14304 memory_order_relaxed);
14305 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14306 memory_order_relaxed);
14307 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14308 memory_order_relaxed);
14309
14310 /* Packet counts. */
14311 vty_out(vty, " Message statistics:\n");
14312 vty_out(vty, " Inq depth is %zu\n", inq_count);
14313 vty_out(vty, " Outq depth is %zu\n", outq_count);
14314 vty_out(vty, " Sent Rcvd\n");
14315 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14316 open_in);
14317 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14318 notify_in);
14319 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14320 update_in);
14321 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14322 keepalive_in);
14323 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14324 refresh_in);
14325 vty_out(vty, " Capability: %10zu %10zu\n",
14326 dynamic_cap_out, dynamic_cap_in);
14327 vty_out(vty, " Total: %10u %10u\n",
14328 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14329 }
14330
14331 if (use_json) {
14332 /* advertisement-interval */
14333 json_object_int_add(json_neigh,
14334 "minBtwnAdvertisementRunsTimerMsecs",
14335 p->v_routeadv * 1000);
14336
14337 /* Update-source. */
14338 if (p->update_if || p->update_source) {
14339 if (p->update_if)
14340 json_object_string_add(json_neigh,
14341 "updateSource",
14342 p->update_if);
14343 else if (p->update_source)
14344 json_object_string_addf(json_neigh,
14345 "updateSource", "%pSU",
14346 p->update_source);
14347 }
14348 } else {
14349 /* advertisement-interval */
14350 vty_out(vty,
14351 " Minimum time between advertisement runs is %d seconds\n",
14352 p->v_routeadv);
14353
14354 /* Update-source. */
14355 if (p->update_if || p->update_source) {
14356 vty_out(vty, " Update source is ");
14357 if (p->update_if)
14358 vty_out(vty, "%s", p->update_if);
14359 else if (p->update_source)
14360 vty_out(vty, "%pSU", p->update_source);
14361 vty_out(vty, "\n");
14362 }
14363
14364 vty_out(vty, "\n");
14365 }
14366
14367 /* Address Family Information */
14368 json_object *json_hold = NULL;
14369
14370 if (use_json)
14371 json_hold = json_object_new_object();
14372
14373 FOREACH_AFI_SAFI (afi, safi)
14374 if (p->afc[afi][safi])
14375 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14376 json_hold);
14377
14378 if (use_json) {
14379 json_object_object_add(json_neigh, "addressFamilyInfo",
14380 json_hold);
14381 json_object_int_add(json_neigh, "connectionsEstablished",
14382 p->established);
14383 json_object_int_add(json_neigh, "connectionsDropped",
14384 p->dropped);
14385 } else
14386 vty_out(vty, " Connections established %d; dropped %d\n",
14387 p->established, p->dropped);
14388
14389 if (!p->last_reset) {
14390 if (use_json)
14391 json_object_string_add(json_neigh, "lastReset",
14392 "never");
14393 else
14394 vty_out(vty, " Last reset never\n");
14395 } else {
14396 if (use_json) {
14397 time_t uptime;
14398 struct tm tm;
14399
14400 uptime = monotime(NULL);
14401 uptime -= p->resettime;
14402 gmtime_r(&uptime, &tm);
14403
14404 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14405 (tm.tm_sec * 1000)
14406 + (tm.tm_min * 60000)
14407 + (tm.tm_hour * 3600000));
14408 bgp_show_peer_reset(NULL, p, json_neigh, true);
14409 } else {
14410 vty_out(vty, " Last reset %s, ",
14411 peer_uptime(p->resettime, timebuf,
14412 BGP_UPTIME_LEN, 0, NULL));
14413
14414 bgp_show_peer_reset(vty, p, NULL, false);
14415 if (p->last_reset_cause_size) {
14416 msg = p->last_reset_cause;
14417 vty_out(vty,
14418 " Message received that caused BGP to send a NOTIFICATION:\n ");
14419 for (i = 1; i <= p->last_reset_cause_size;
14420 i++) {
14421 vty_out(vty, "%02X", *msg++);
14422
14423 if (i != p->last_reset_cause_size) {
14424 if (i % 16 == 0) {
14425 vty_out(vty, "\n ");
14426 } else if (i % 4 == 0) {
14427 vty_out(vty, " ");
14428 }
14429 }
14430 }
14431 vty_out(vty, "\n");
14432 }
14433 }
14434 }
14435
14436 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14437 if (use_json)
14438 json_object_boolean_true_add(json_neigh,
14439 "prefixesConfigExceedMax");
14440 else
14441 vty_out(vty,
14442 " Peer had exceeded the max. no. of prefixes configured.\n");
14443
14444 if (p->t_pmax_restart) {
14445 if (use_json) {
14446 json_object_boolean_true_add(
14447 json_neigh, "reducePrefixNumFrom");
14448 json_object_int_add(json_neigh,
14449 "restartInTimerMsec",
14450 thread_timer_remain_second(
14451 p->t_pmax_restart)
14452 * 1000);
14453 } else
14454 vty_out(vty,
14455 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14456 p->host, thread_timer_remain_second(
14457 p->t_pmax_restart));
14458 } else {
14459 if (use_json)
14460 json_object_boolean_true_add(
14461 json_neigh,
14462 "reducePrefixNumAndClearIpBgp");
14463 else
14464 vty_out(vty,
14465 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14466 p->host);
14467 }
14468 }
14469
14470 /* EBGP Multihop and GTSM */
14471 if (p->sort != BGP_PEER_IBGP) {
14472 if (use_json) {
14473 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14474 json_object_int_add(json_neigh,
14475 "externalBgpNbrMaxHopsAway",
14476 p->gtsm_hops);
14477 else
14478 json_object_int_add(json_neigh,
14479 "externalBgpNbrMaxHopsAway",
14480 p->ttl);
14481 } else {
14482 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14483 vty_out(vty,
14484 " External BGP neighbor may be up to %d hops away.\n",
14485 p->gtsm_hops);
14486 else
14487 vty_out(vty,
14488 " External BGP neighbor may be up to %d hops away.\n",
14489 p->ttl);
14490 }
14491 } else {
14492 if (use_json) {
14493 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14494 json_object_int_add(json_neigh,
14495 "internalBgpNbrMaxHopsAway",
14496 p->gtsm_hops);
14497 else
14498 json_object_int_add(json_neigh,
14499 "internalBgpNbrMaxHopsAway",
14500 p->ttl);
14501 } else {
14502 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14503 vty_out(vty,
14504 " Internal BGP neighbor may be up to %d hops away.\n",
14505 p->gtsm_hops);
14506 else
14507 vty_out(vty,
14508 " Internal BGP neighbor may be up to %d hops away.\n",
14509 p->ttl);
14510 }
14511 }
14512
14513 /* Local address. */
14514 if (p->su_local) {
14515 if (use_json) {
14516 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14517 p->su_local);
14518 json_object_int_add(json_neigh, "portLocal",
14519 ntohs(p->su_local->sin.sin_port));
14520 } else
14521 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14522 p->su_local, ntohs(p->su_local->sin.sin_port));
14523 } else {
14524 if (use_json) {
14525 json_object_string_add(json_neigh, "hostLocal",
14526 "Unknown");
14527 json_object_int_add(json_neigh, "portLocal", -1);
14528 }
14529 }
14530
14531 /* Remote address. */
14532 if (p->su_remote) {
14533 if (use_json) {
14534 json_object_string_addf(json_neigh, "hostForeign",
14535 "%pSU", p->su_remote);
14536 json_object_int_add(json_neigh, "portForeign",
14537 ntohs(p->su_remote->sin.sin_port));
14538 } else
14539 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14540 p->su_remote,
14541 ntohs(p->su_remote->sin.sin_port));
14542 } else {
14543 if (use_json) {
14544 json_object_string_add(json_neigh, "hostForeign",
14545 "Unknown");
14546 json_object_int_add(json_neigh, "portForeign", -1);
14547 }
14548 }
14549
14550 /* Nexthop display. */
14551 if (p->su_local) {
14552 if (use_json) {
14553 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14554 &p->nexthop.v4);
14555 json_object_string_addf(json_neigh, "nexthopGlobal",
14556 "%pI6", &p->nexthop.v6_global);
14557 json_object_string_addf(json_neigh, "nexthopLocal",
14558 "%pI6", &p->nexthop.v6_local);
14559 if (p->shared_network)
14560 json_object_string_add(json_neigh,
14561 "bgpConnection",
14562 "sharedNetwork");
14563 else
14564 json_object_string_add(json_neigh,
14565 "bgpConnection",
14566 "nonSharedNetwork");
14567 } else {
14568 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14569 vty_out(vty, "Nexthop global: %pI6\n",
14570 &p->nexthop.v6_global);
14571 vty_out(vty, "Nexthop local: %pI6\n",
14572 &p->nexthop.v6_local);
14573 vty_out(vty, "BGP connection: %s\n",
14574 p->shared_network ? "shared network"
14575 : "non shared network");
14576 }
14577 } else {
14578 if (use_json) {
14579 json_object_string_add(json_neigh, "nexthop",
14580 "Unknown");
14581 json_object_string_add(json_neigh, "nexthopGlobal",
14582 "Unknown");
14583 json_object_string_add(json_neigh, "nexthopLocal",
14584 "Unknown");
14585 json_object_string_add(json_neigh, "bgpConnection",
14586 "Unknown");
14587 }
14588 }
14589
14590 /* Timer information. */
14591 if (use_json) {
14592 json_object_int_add(json_neigh, "connectRetryTimer",
14593 p->v_connect);
14594 if (peer_established(p)) {
14595 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14596 p->rtt);
14597 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14598 json_object_int_add(json_neigh,
14599 "shutdownRttInMsecs",
14600 p->rtt_expected);
14601 json_object_int_add(json_neigh,
14602 "shutdownRttAfterCount",
14603 p->rtt_keepalive_rcv);
14604 }
14605 }
14606 if (p->t_start)
14607 json_object_int_add(
14608 json_neigh, "nextStartTimerDueInMsecs",
14609 thread_timer_remain_second(p->t_start) * 1000);
14610 if (p->t_connect)
14611 json_object_int_add(
14612 json_neigh, "nextConnectTimerDueInMsecs",
14613 thread_timer_remain_second(p->t_connect)
14614 * 1000);
14615 if (p->t_routeadv) {
14616 json_object_int_add(json_neigh, "mraiInterval",
14617 p->v_routeadv);
14618 json_object_int_add(
14619 json_neigh, "mraiTimerExpireInMsecs",
14620 thread_timer_remain_second(p->t_routeadv)
14621 * 1000);
14622 }
14623 if (p->password)
14624 json_object_int_add(json_neigh, "authenticationEnabled",
14625 1);
14626
14627 if (p->t_read)
14628 json_object_string_add(json_neigh, "readThread", "on");
14629 else
14630 json_object_string_add(json_neigh, "readThread", "off");
14631
14632 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14633 json_object_string_add(json_neigh, "writeThread", "on");
14634 else
14635 json_object_string_add(json_neigh, "writeThread",
14636 "off");
14637 } else {
14638 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14639 p->v_connect);
14640 if (peer_established(p)) {
14641 vty_out(vty, "Estimated round trip time: %d ms\n",
14642 p->rtt);
14643 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14644 vty_out(vty,
14645 "Shutdown when RTT > %dms, count > %u\n",
14646 p->rtt_expected, p->rtt_keepalive_rcv);
14647 }
14648 if (p->t_start)
14649 vty_out(vty, "Next start timer due in %ld seconds\n",
14650 thread_timer_remain_second(p->t_start));
14651 if (p->t_connect)
14652 vty_out(vty, "Next connect timer due in %ld seconds\n",
14653 thread_timer_remain_second(p->t_connect));
14654 if (p->t_routeadv)
14655 vty_out(vty,
14656 "MRAI (interval %u) timer expires in %ld seconds\n",
14657 p->v_routeadv,
14658 thread_timer_remain_second(p->t_routeadv));
14659 if (p->password)
14660 vty_out(vty, "Peer Authentication Enabled\n");
14661
14662 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14663 p->t_read ? "on" : "off",
14664 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14665 ? "on"
14666 : "off", p->fd);
14667 }
14668
14669 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14670 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14671 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14672
14673 if (!use_json)
14674 vty_out(vty, "\n");
14675
14676 /* BFD information. */
14677 if (p->bfd_config)
14678 bgp_bfd_show_info(vty, p, json_neigh);
14679
14680 if (use_json) {
14681 if (p->conf_if) /* Configured interface name. */
14682 json_object_object_add(json, p->conf_if, json_neigh);
14683 else /* Configured IP address. */
14684 json_object_object_add(json, p->host, json_neigh);
14685 }
14686 }
14687
14688 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14689 enum show_type type,
14690 union sockunion *su,
14691 const char *conf_if, afi_t afi,
14692 json_object *json)
14693 {
14694 struct listnode *node, *nnode;
14695 struct peer *peer;
14696 int find = 0;
14697 safi_t safi = SAFI_UNICAST;
14698 json_object *json_neighbor = NULL;
14699
14700 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14701
14702 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14703 continue;
14704
14705 if ((peer->afc[afi][safi]) == 0)
14706 continue;
14707
14708 if (json)
14709 json_neighbor = json_object_new_object();
14710
14711 if (type == show_all) {
14712 bgp_show_peer_gr_status(vty, peer, json_neighbor);
14713
14714 if (json)
14715 json_object_object_add(json, peer->host,
14716 json_neighbor);
14717
14718 } else if (type == show_peer) {
14719 if (conf_if) {
14720 if ((peer->conf_if
14721 && !strcmp(peer->conf_if, conf_if))
14722 || (peer->hostname
14723 && !strcmp(peer->hostname, conf_if))) {
14724 find = 1;
14725 bgp_show_peer_gr_status(vty, peer,
14726 json_neighbor);
14727 }
14728 } else {
14729 if (sockunion_same(&peer->su, su)) {
14730 find = 1;
14731 bgp_show_peer_gr_status(vty, peer,
14732 json_neighbor);
14733 }
14734 }
14735 if (json && find)
14736 json_object_object_add(json, peer->host,
14737 json_neighbor);
14738 }
14739
14740 if (find)
14741 break;
14742 }
14743
14744 if (type == show_peer && !find) {
14745 if (json)
14746 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14747 else
14748 vty_out(vty, "%% No such neighbor\n");
14749 }
14750
14751 if (!json)
14752 vty_out(vty, "\n");
14753
14754 return CMD_SUCCESS;
14755 }
14756
14757 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14758 enum show_type type, union sockunion *su,
14759 const char *conf_if, bool use_json,
14760 json_object *json)
14761 {
14762 struct listnode *node, *nnode;
14763 struct peer *peer;
14764 int find = 0;
14765 bool nbr_output = false;
14766 afi_t afi = AFI_MAX;
14767 safi_t safi = SAFI_MAX;
14768
14769 if (type == show_ipv4_peer || type == show_ipv4_all) {
14770 afi = AFI_IP;
14771 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14772 afi = AFI_IP6;
14773 }
14774
14775 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14776 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14777 continue;
14778
14779 switch (type) {
14780 case show_all:
14781 bgp_show_peer(vty, peer, use_json, json);
14782 nbr_output = true;
14783 break;
14784 case show_peer:
14785 if (conf_if) {
14786 if ((peer->conf_if
14787 && !strcmp(peer->conf_if, conf_if))
14788 || (peer->hostname
14789 && !strcmp(peer->hostname, conf_if))) {
14790 find = 1;
14791 bgp_show_peer(vty, peer, use_json,
14792 json);
14793 }
14794 } else {
14795 if (sockunion_same(&peer->su, su)) {
14796 find = 1;
14797 bgp_show_peer(vty, peer, use_json,
14798 json);
14799 }
14800 }
14801 break;
14802 case show_ipv4_peer:
14803 case show_ipv6_peer:
14804 FOREACH_SAFI (safi) {
14805 if (peer->afc[afi][safi]) {
14806 if (conf_if) {
14807 if ((peer->conf_if
14808 && !strcmp(peer->conf_if, conf_if))
14809 || (peer->hostname
14810 && !strcmp(peer->hostname, conf_if))) {
14811 find = 1;
14812 bgp_show_peer(vty, peer, use_json,
14813 json);
14814 break;
14815 }
14816 } else {
14817 if (sockunion_same(&peer->su, su)) {
14818 find = 1;
14819 bgp_show_peer(vty, peer, use_json,
14820 json);
14821 break;
14822 }
14823 }
14824 }
14825 }
14826 break;
14827 case show_ipv4_all:
14828 case show_ipv6_all:
14829 FOREACH_SAFI (safi) {
14830 if (peer->afc[afi][safi]) {
14831 bgp_show_peer(vty, peer, use_json, json);
14832 nbr_output = true;
14833 break;
14834 }
14835 }
14836 break;
14837 }
14838 }
14839
14840 if ((type == show_peer || type == show_ipv4_peer ||
14841 type == show_ipv6_peer) && !find) {
14842 if (use_json)
14843 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14844 else
14845 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14846 }
14847
14848 if (type != show_peer && type != show_ipv4_peer &&
14849 type != show_ipv6_peer && !nbr_output && !use_json)
14850 vty_out(vty, "%% No BGP neighbors found\n");
14851
14852 if (use_json) {
14853 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14854 json, JSON_C_TO_STRING_PRETTY));
14855 } else {
14856 vty_out(vty, "\n");
14857 }
14858
14859 return CMD_SUCCESS;
14860 }
14861
14862 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14863 enum show_type type,
14864 const char *ip_str,
14865 afi_t afi, json_object *json)
14866 {
14867
14868 int ret;
14869 struct bgp *bgp;
14870 union sockunion su;
14871
14872 bgp = bgp_get_default();
14873
14874 if (!bgp)
14875 return;
14876
14877 if (!json)
14878 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
14879
14880 if (ip_str) {
14881 ret = str2sockunion(ip_str, &su);
14882 if (ret < 0)
14883 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
14884 ip_str, afi, json);
14885 else
14886 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14887 NULL, afi, json);
14888 } else
14889 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14890 afi, json);
14891 }
14892
14893 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14894 enum show_type type,
14895 const char *ip_str,
14896 bool use_json)
14897 {
14898 struct listnode *node, *nnode;
14899 struct bgp *bgp;
14900 union sockunion su;
14901 json_object *json = NULL;
14902 int ret, is_first = 1;
14903 bool nbr_output = false;
14904
14905 if (use_json)
14906 vty_out(vty, "{\n");
14907
14908 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14909 nbr_output = true;
14910 if (use_json) {
14911 if (!(json = json_object_new_object())) {
14912 flog_err(
14913 EC_BGP_JSON_MEM_ERROR,
14914 "Unable to allocate memory for JSON object");
14915 vty_out(vty,
14916 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14917 return;
14918 }
14919
14920 json_object_int_add(json, "vrfId",
14921 (bgp->vrf_id == VRF_UNKNOWN)
14922 ? -1
14923 : (int64_t)bgp->vrf_id);
14924 json_object_string_add(
14925 json, "vrfName",
14926 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14927 ? VRF_DEFAULT_NAME
14928 : bgp->name);
14929
14930 if (!is_first)
14931 vty_out(vty, ",\n");
14932 else
14933 is_first = 0;
14934
14935 vty_out(vty, "\"%s\":",
14936 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14937 ? VRF_DEFAULT_NAME
14938 : bgp->name);
14939 } else {
14940 vty_out(vty, "\nInstance %s:\n",
14941 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14942 ? VRF_DEFAULT_NAME
14943 : bgp->name);
14944 }
14945
14946 if (type == show_peer || type == show_ipv4_peer ||
14947 type == show_ipv6_peer) {
14948 ret = str2sockunion(ip_str, &su);
14949 if (ret < 0)
14950 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14951 use_json, json);
14952 else
14953 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14954 use_json, json);
14955 } else {
14956 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14957 use_json, json);
14958 }
14959 json_object_free(json);
14960 json = NULL;
14961 }
14962
14963 if (use_json)
14964 vty_out(vty, "}\n");
14965 else if (!nbr_output)
14966 vty_out(vty, "%% BGP instance not found\n");
14967 }
14968
14969 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14970 enum show_type type, const char *ip_str,
14971 bool use_json)
14972 {
14973 int ret;
14974 struct bgp *bgp;
14975 union sockunion su;
14976 json_object *json = NULL;
14977
14978 if (name) {
14979 if (strmatch(name, "all")) {
14980 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14981 use_json);
14982 return CMD_SUCCESS;
14983 } else {
14984 bgp = bgp_lookup_by_name(name);
14985 if (!bgp) {
14986 if (use_json) {
14987 json = json_object_new_object();
14988 vty_json(vty, json);
14989 } else
14990 vty_out(vty,
14991 "%% BGP instance not found\n");
14992
14993 return CMD_WARNING;
14994 }
14995 }
14996 } else {
14997 bgp = bgp_get_default();
14998 }
14999
15000 if (bgp) {
15001 json = json_object_new_object();
15002 if (ip_str) {
15003 ret = str2sockunion(ip_str, &su);
15004 if (ret < 0)
15005 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15006 use_json, json);
15007 else
15008 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15009 use_json, json);
15010 } else {
15011 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15012 json);
15013 }
15014 json_object_free(json);
15015 } else {
15016 if (use_json)
15017 vty_out(vty, "{}\n");
15018 else
15019 vty_out(vty, "%% BGP instance not found\n");
15020 }
15021
15022 return CMD_SUCCESS;
15023 }
15024
15025
15026
15027 /* "show [ip] bgp neighbors graceful-restart" commands. */
15028 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15029 show_ip_bgp_neighbors_graceful_restart_cmd,
15030 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15031 SHOW_STR
15032 BGP_STR
15033 IP_STR
15034 IPV6_STR
15035 NEIGHBOR_STR
15036 "Neighbor to display information about\n"
15037 "Neighbor to display information about\n"
15038 "Neighbor on BGP configured interface\n"
15039 GR_SHOW
15040 JSON_STR)
15041 {
15042 char *sh_arg = NULL;
15043 enum show_type sh_type;
15044 int idx = 0;
15045 afi_t afi = AFI_MAX;
15046 bool uj = use_json(argc, argv);
15047
15048 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15049 afi = AFI_MAX;
15050
15051 idx++;
15052
15053 if (argv_find(argv, argc, "A.B.C.D", &idx)
15054 || argv_find(argv, argc, "X:X::X:X", &idx)
15055 || argv_find(argv, argc, "WORD", &idx)) {
15056 sh_type = show_peer;
15057 sh_arg = argv[idx]->arg;
15058 } else
15059 sh_type = show_all;
15060
15061 if (!argv_find(argv, argc, "graceful-restart", &idx))
15062 return CMD_SUCCESS;
15063
15064
15065 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15066 afi, uj);
15067 }
15068
15069 /* "show [ip] bgp neighbors" commands. */
15070 DEFUN (show_ip_bgp_neighbors,
15071 show_ip_bgp_neighbors_cmd,
15072 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15073 SHOW_STR
15074 IP_STR
15075 BGP_STR
15076 BGP_INSTANCE_HELP_STR
15077 BGP_AF_STR
15078 BGP_AF_STR
15079 "Detailed information on TCP and BGP neighbor connections\n"
15080 "Neighbor to display information about\n"
15081 "Neighbor to display information about\n"
15082 "Neighbor on BGP configured interface\n"
15083 JSON_STR)
15084 {
15085 char *vrf = NULL;
15086 char *sh_arg = NULL;
15087 enum show_type sh_type;
15088 afi_t afi = AFI_MAX;
15089
15090 bool uj = use_json(argc, argv);
15091
15092 int idx = 0;
15093
15094 /* [<vrf> VIEWVRFNAME] */
15095 if (argv_find(argv, argc, "vrf", &idx)) {
15096 vrf = argv[idx + 1]->arg;
15097 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15098 vrf = NULL;
15099 } else if (argv_find(argv, argc, "view", &idx))
15100 /* [<view> VIEWVRFNAME] */
15101 vrf = argv[idx + 1]->arg;
15102
15103 idx++;
15104
15105 if (argv_find(argv, argc, "ipv4", &idx)) {
15106 sh_type = show_ipv4_all;
15107 afi = AFI_IP;
15108 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15109 sh_type = show_ipv6_all;
15110 afi = AFI_IP6;
15111 } else {
15112 sh_type = show_all;
15113 }
15114
15115 if (argv_find(argv, argc, "A.B.C.D", &idx)
15116 || argv_find(argv, argc, "X:X::X:X", &idx)
15117 || argv_find(argv, argc, "WORD", &idx)) {
15118 sh_type = show_peer;
15119 sh_arg = argv[idx]->arg;
15120 }
15121
15122 if (sh_type == show_peer && afi == AFI_IP) {
15123 sh_type = show_ipv4_peer;
15124 } else if (sh_type == show_peer && afi == AFI_IP6) {
15125 sh_type = show_ipv6_peer;
15126 }
15127
15128 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15129 }
15130
15131 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15132 paths' and `show ip mbgp paths'. Those functions results are the
15133 same.*/
15134 DEFUN (show_ip_bgp_paths,
15135 show_ip_bgp_paths_cmd,
15136 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15137 SHOW_STR
15138 IP_STR
15139 BGP_STR
15140 BGP_SAFI_HELP_STR
15141 "Path information\n")
15142 {
15143 vty_out(vty, "Address Refcnt Path\n");
15144 aspath_print_all_vty(vty);
15145 return CMD_SUCCESS;
15146 }
15147
15148 #include "hash.h"
15149
15150 static void community_show_all_iterator(struct hash_bucket *bucket,
15151 struct vty *vty)
15152 {
15153 struct community *com;
15154
15155 com = (struct community *)bucket->data;
15156 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15157 community_str(com, false, false));
15158 }
15159
15160 /* Show BGP's community internal data. */
15161 DEFUN (show_ip_bgp_community_info,
15162 show_ip_bgp_community_info_cmd,
15163 "show [ip] bgp community-info",
15164 SHOW_STR
15165 IP_STR
15166 BGP_STR
15167 "List all bgp community information\n")
15168 {
15169 vty_out(vty, "Address Refcnt Community\n");
15170
15171 hash_iterate(community_hash(),
15172 (void (*)(struct hash_bucket *,
15173 void *))community_show_all_iterator,
15174 vty);
15175
15176 return CMD_SUCCESS;
15177 }
15178
15179 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15180 struct vty *vty)
15181 {
15182 struct lcommunity *lcom;
15183
15184 lcom = (struct lcommunity *)bucket->data;
15185 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15186 lcommunity_str(lcom, false, false));
15187 }
15188
15189 /* Show BGP's community internal data. */
15190 DEFUN (show_ip_bgp_lcommunity_info,
15191 show_ip_bgp_lcommunity_info_cmd,
15192 "show ip bgp large-community-info",
15193 SHOW_STR
15194 IP_STR
15195 BGP_STR
15196 "List all bgp large-community information\n")
15197 {
15198 vty_out(vty, "Address Refcnt Large-community\n");
15199
15200 hash_iterate(lcommunity_hash(),
15201 (void (*)(struct hash_bucket *,
15202 void *))lcommunity_show_all_iterator,
15203 vty);
15204
15205 return CMD_SUCCESS;
15206 }
15207 /* Graceful Restart */
15208
15209 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15210 struct bgp *bgp)
15211 {
15212
15213
15214 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15215
15216 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15217
15218 switch (bgp_global_gr_mode) {
15219
15220 case GLOBAL_HELPER:
15221 vty_out(vty, "Global BGP GR Mode : Helper\n");
15222 break;
15223
15224 case GLOBAL_GR:
15225 vty_out(vty, "Global BGP GR Mode : Restart\n");
15226 break;
15227
15228 case GLOBAL_DISABLE:
15229 vty_out(vty, "Global BGP GR Mode : Disable\n");
15230 break;
15231
15232 case GLOBAL_INVALID:
15233 vty_out(vty,
15234 "Global BGP GR Mode Invalid\n");
15235 break;
15236 }
15237 vty_out(vty, "\n");
15238 }
15239
15240 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15241 enum show_type type,
15242 const char *ip_str,
15243 afi_t afi, bool use_json)
15244 {
15245 json_object *json = NULL;
15246
15247 if (use_json)
15248 json = json_object_new_object();
15249
15250 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15251 afi = AFI_IP;
15252
15253 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15254
15255 bgp_show_neighbor_graceful_restart_vty(
15256 vty, type, ip_str, afi, json);
15257 afi++;
15258 }
15259 } else if (afi != AFI_MAX) {
15260 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15261 json);
15262 } else {
15263 if (json)
15264 json_object_free(json);
15265 return CMD_ERR_INCOMPLETE;
15266 }
15267
15268 if (json)
15269 vty_json(vty, json);
15270
15271 return CMD_SUCCESS;
15272 }
15273 /* Graceful Restart */
15274
15275 DEFUN (show_ip_bgp_attr_info,
15276 show_ip_bgp_attr_info_cmd,
15277 "show [ip] bgp attribute-info",
15278 SHOW_STR
15279 IP_STR
15280 BGP_STR
15281 "List all bgp attribute information\n")
15282 {
15283 attr_show_all(vty);
15284 return CMD_SUCCESS;
15285 }
15286
15287 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15288 afi_t afi, safi_t safi,
15289 bool use_json, json_object *json)
15290 {
15291 struct bgp *bgp;
15292 struct listnode *node;
15293 char *vname;
15294 char *ecom_str;
15295 enum vpn_policy_direction dir;
15296
15297 if (json) {
15298 json_object *json_import_vrfs = NULL;
15299 json_object *json_export_vrfs = NULL;
15300
15301 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15302
15303 if (!bgp) {
15304 vty_json(vty, json);
15305
15306 return CMD_WARNING;
15307 }
15308
15309 /* Provide context for the block */
15310 json_object_string_add(json, "vrf", name ? name : "default");
15311 json_object_string_add(json, "afiSafi",
15312 get_afi_safi_str(afi, safi, true));
15313
15314 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15315 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15316 json_object_string_add(json, "importFromVrfs", "none");
15317 json_object_string_add(json, "importRts", "none");
15318 } else {
15319 json_import_vrfs = json_object_new_array();
15320
15321 for (ALL_LIST_ELEMENTS_RO(
15322 bgp->vpn_policy[afi].import_vrf,
15323 node, vname))
15324 json_object_array_add(json_import_vrfs,
15325 json_object_new_string(vname));
15326
15327 json_object_object_add(json, "importFromVrfs",
15328 json_import_vrfs);
15329 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15330 if (bgp->vpn_policy[afi].rtlist[dir]) {
15331 ecom_str = ecommunity_ecom2str(
15332 bgp->vpn_policy[afi].rtlist[dir],
15333 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15334 json_object_string_add(json, "importRts",
15335 ecom_str);
15336 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15337 } else
15338 json_object_string_add(json, "importRts",
15339 "none");
15340 }
15341
15342 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15343 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15344 json_object_string_add(json, "exportToVrfs", "none");
15345 json_object_string_add(json, "routeDistinguisher",
15346 "none");
15347 json_object_string_add(json, "exportRts", "none");
15348 } else {
15349 json_export_vrfs = json_object_new_array();
15350
15351 for (ALL_LIST_ELEMENTS_RO(
15352 bgp->vpn_policy[afi].export_vrf,
15353 node, vname))
15354 json_object_array_add(json_export_vrfs,
15355 json_object_new_string(vname));
15356 json_object_object_add(json, "exportToVrfs",
15357 json_export_vrfs);
15358 json_object_string_addf(json, "routeDistinguisher",
15359 "%pRD",
15360 &bgp->vpn_policy[afi].tovpn_rd);
15361
15362 dir = BGP_VPN_POLICY_DIR_TOVPN;
15363 if (bgp->vpn_policy[afi].rtlist[dir]) {
15364 ecom_str = ecommunity_ecom2str(
15365 bgp->vpn_policy[afi].rtlist[dir],
15366 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15367 json_object_string_add(json, "exportRts",
15368 ecom_str);
15369 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15370 } else
15371 json_object_string_add(json, "exportRts",
15372 "none");
15373 }
15374
15375 if (use_json) {
15376 vty_json(vty, json);
15377 }
15378 } else {
15379 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15380
15381 if (!bgp) {
15382 vty_out(vty, "%% No such BGP instance exist\n");
15383 return CMD_WARNING;
15384 }
15385
15386 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15387 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15388 vty_out(vty,
15389 "This VRF is not importing %s routes from any other VRF\n",
15390 get_afi_safi_str(afi, safi, false));
15391 else {
15392 vty_out(vty,
15393 "This VRF is importing %s routes from the following VRFs:\n",
15394 get_afi_safi_str(afi, safi, false));
15395
15396 for (ALL_LIST_ELEMENTS_RO(
15397 bgp->vpn_policy[afi].import_vrf,
15398 node, vname))
15399 vty_out(vty, " %s\n", vname);
15400
15401 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15402 ecom_str = NULL;
15403 if (bgp->vpn_policy[afi].rtlist[dir]) {
15404 ecom_str = ecommunity_ecom2str(
15405 bgp->vpn_policy[afi].rtlist[dir],
15406 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15407 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15408
15409 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15410 } else
15411 vty_out(vty, "Import RT(s):\n");
15412 }
15413
15414 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15415 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15416 vty_out(vty,
15417 "This VRF is not exporting %s routes to any other VRF\n",
15418 get_afi_safi_str(afi, safi, false));
15419 else {
15420 vty_out(vty,
15421 "This VRF is exporting %s routes to the following VRFs:\n",
15422 get_afi_safi_str(afi, safi, false));
15423
15424 for (ALL_LIST_ELEMENTS_RO(
15425 bgp->vpn_policy[afi].export_vrf,
15426 node, vname))
15427 vty_out(vty, " %s\n", vname);
15428
15429 vty_out(vty, "RD: %pRD\n",
15430 &bgp->vpn_policy[afi].tovpn_rd);
15431
15432 dir = BGP_VPN_POLICY_DIR_TOVPN;
15433 if (bgp->vpn_policy[afi].rtlist[dir]) {
15434 ecom_str = ecommunity_ecom2str(
15435 bgp->vpn_policy[afi].rtlist[dir],
15436 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15437 vty_out(vty, "Export RT: %s\n", ecom_str);
15438 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15439 } else
15440 vty_out(vty, "Import RT(s):\n");
15441 }
15442 }
15443
15444 return CMD_SUCCESS;
15445 }
15446
15447 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15448 safi_t safi, bool use_json)
15449 {
15450 struct listnode *node, *nnode;
15451 struct bgp *bgp;
15452 char *vrf_name = NULL;
15453 json_object *json = NULL;
15454 json_object *json_vrf = NULL;
15455 json_object *json_vrfs = NULL;
15456
15457 if (use_json) {
15458 json = json_object_new_object();
15459 json_vrfs = json_object_new_object();
15460 }
15461
15462 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15463
15464 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15465 vrf_name = bgp->name;
15466
15467 if (use_json) {
15468 json_vrf = json_object_new_object();
15469 } else {
15470 vty_out(vty, "\nInstance %s:\n",
15471 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15472 ? VRF_DEFAULT_NAME : bgp->name);
15473 }
15474 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15475 if (use_json) {
15476 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15477 json_object_object_add(json_vrfs,
15478 VRF_DEFAULT_NAME, json_vrf);
15479 else
15480 json_object_object_add(json_vrfs, vrf_name,
15481 json_vrf);
15482 }
15483 }
15484
15485 if (use_json) {
15486 json_object_object_add(json, "vrfs", json_vrfs);
15487 vty_json(vty, json);
15488 }
15489
15490 return CMD_SUCCESS;
15491 }
15492
15493 /* "show [ip] bgp route-leak" command. */
15494 DEFUN (show_ip_bgp_route_leak,
15495 show_ip_bgp_route_leak_cmd,
15496 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15497 SHOW_STR
15498 IP_STR
15499 BGP_STR
15500 BGP_INSTANCE_HELP_STR
15501 BGP_AFI_HELP_STR
15502 BGP_SAFI_HELP_STR
15503 "Route leaking information\n"
15504 JSON_STR)
15505 {
15506 char *vrf = NULL;
15507 afi_t afi = AFI_MAX;
15508 safi_t safi = SAFI_MAX;
15509
15510 bool uj = use_json(argc, argv);
15511 int idx = 0;
15512 json_object *json = NULL;
15513
15514 /* show [ip] bgp */
15515 if (argv_find(argv, argc, "ip", &idx)) {
15516 afi = AFI_IP;
15517 safi = SAFI_UNICAST;
15518 }
15519 /* [vrf VIEWVRFNAME] */
15520 if (argv_find(argv, argc, "view", &idx)) {
15521 vty_out(vty,
15522 "%% This command is not applicable to BGP views\n");
15523 return CMD_WARNING;
15524 }
15525
15526 if (argv_find(argv, argc, "vrf", &idx)) {
15527 vrf = argv[idx + 1]->arg;
15528 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15529 vrf = NULL;
15530 }
15531 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15532 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15533 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15534
15535 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15536 vty_out(vty,
15537 "%% This command is applicable only for unicast ipv4|ipv6\n");
15538 return CMD_WARNING;
15539 }
15540
15541 if (vrf && strmatch(vrf, "all"))
15542 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15543
15544 if (uj)
15545 json = json_object_new_object();
15546
15547 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15548 }
15549
15550 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15551 safi_t safi, bool uj)
15552 {
15553 struct listnode *node, *nnode;
15554 struct bgp *bgp;
15555
15556 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15557 if (!uj)
15558 vty_out(vty, "\nInstance %s:\n",
15559 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15560 ? VRF_DEFAULT_NAME
15561 : bgp->name);
15562
15563 update_group_show(bgp, afi, safi, vty, 0, uj);
15564 }
15565 }
15566
15567 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15568 int safi, uint64_t subgrp_id, bool uj)
15569 {
15570 struct bgp *bgp;
15571
15572 if (name) {
15573 if (strmatch(name, "all")) {
15574 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15575 return CMD_SUCCESS;
15576 } else {
15577 bgp = bgp_lookup_by_name(name);
15578 }
15579 } else {
15580 bgp = bgp_get_default();
15581 }
15582
15583 if (bgp)
15584 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15585 return CMD_SUCCESS;
15586 }
15587
15588 DEFUN (show_ip_bgp_updgrps,
15589 show_ip_bgp_updgrps_cmd,
15590 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15591 SHOW_STR
15592 IP_STR
15593 BGP_STR
15594 BGP_INSTANCE_HELP_STR
15595 BGP_AFI_HELP_STR
15596 BGP_SAFI_WITH_LABEL_HELP_STR
15597 "Detailed info about dynamic update groups\n"
15598 "Specific subgroup to display detailed info for\n"
15599 JSON_STR)
15600 {
15601 char *vrf = NULL;
15602 afi_t afi = AFI_IP6;
15603 safi_t safi = SAFI_UNICAST;
15604 uint64_t subgrp_id = 0;
15605
15606 int idx = 0;
15607
15608 bool uj = use_json(argc, argv);
15609
15610 /* show [ip] bgp */
15611 if (argv_find(argv, argc, "ip", &idx))
15612 afi = AFI_IP;
15613 /* [<vrf> VIEWVRFNAME] */
15614 if (argv_find(argv, argc, "vrf", &idx)) {
15615 vrf = argv[idx + 1]->arg;
15616 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15617 vrf = NULL;
15618 } else if (argv_find(argv, argc, "view", &idx))
15619 /* [<view> VIEWVRFNAME] */
15620 vrf = argv[idx + 1]->arg;
15621 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15622 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15623 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15624 }
15625
15626 /* get subgroup id, if provided */
15627 idx = argc - 1;
15628 if (argv[idx]->type == VARIABLE_TKN)
15629 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15630
15631 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15632 }
15633
15634 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15635 show_bgp_instance_all_ipv6_updgrps_cmd,
15636 "show [ip] bgp <view|vrf> all update-groups [json]",
15637 SHOW_STR
15638 IP_STR
15639 BGP_STR
15640 BGP_INSTANCE_ALL_HELP_STR
15641 "Detailed info about dynamic update groups\n"
15642 JSON_STR)
15643 {
15644 bool uj = use_json(argc, argv);
15645
15646 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15647 return CMD_SUCCESS;
15648 }
15649
15650 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15651 show_bgp_l2vpn_evpn_updgrps_cmd,
15652 "show [ip] bgp l2vpn evpn update-groups",
15653 SHOW_STR
15654 IP_STR
15655 BGP_STR
15656 "l2vpn address family\n"
15657 "evpn sub-address family\n"
15658 "Detailed info about dynamic update groups\n")
15659 {
15660 char *vrf = NULL;
15661 uint64_t subgrp_id = 0;
15662
15663 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15664 return CMD_SUCCESS;
15665 }
15666
15667 DEFUN (show_bgp_updgrps_stats,
15668 show_bgp_updgrps_stats_cmd,
15669 "show [ip] bgp update-groups statistics",
15670 SHOW_STR
15671 IP_STR
15672 BGP_STR
15673 "Detailed info about dynamic update groups\n"
15674 "Statistics\n")
15675 {
15676 struct bgp *bgp;
15677
15678 bgp = bgp_get_default();
15679 if (bgp)
15680 update_group_show_stats(bgp, vty);
15681
15682 return CMD_SUCCESS;
15683 }
15684
15685 DEFUN (show_bgp_instance_updgrps_stats,
15686 show_bgp_instance_updgrps_stats_cmd,
15687 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15688 SHOW_STR
15689 IP_STR
15690 BGP_STR
15691 BGP_INSTANCE_HELP_STR
15692 "Detailed info about dynamic update groups\n"
15693 "Statistics\n")
15694 {
15695 int idx_word = 3;
15696 struct bgp *bgp;
15697
15698 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15699 if (bgp)
15700 update_group_show_stats(bgp, vty);
15701
15702 return CMD_SUCCESS;
15703 }
15704
15705 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15706 afi_t afi, safi_t safi,
15707 const char *what, uint64_t subgrp_id)
15708 {
15709 struct bgp *bgp;
15710
15711 if (name)
15712 bgp = bgp_lookup_by_name(name);
15713 else
15714 bgp = bgp_get_default();
15715
15716 if (bgp) {
15717 if (!strcmp(what, "advertise-queue"))
15718 update_group_show_adj_queue(bgp, afi, safi, vty,
15719 subgrp_id);
15720 else if (!strcmp(what, "advertised-routes"))
15721 update_group_show_advertised(bgp, afi, safi, vty,
15722 subgrp_id);
15723 else if (!strcmp(what, "packet-queue"))
15724 update_group_show_packet_queue(bgp, afi, safi, vty,
15725 subgrp_id);
15726 }
15727 }
15728
15729 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15730 show_ip_bgp_instance_updgrps_adj_s_cmd,
15731 "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",
15732 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15733 BGP_SAFI_HELP_STR
15734 "Detailed info about dynamic update groups\n"
15735 "Specific subgroup to display info for\n"
15736 "Advertisement queue\n"
15737 "Announced routes\n"
15738 "Packet queue\n")
15739 {
15740 uint64_t subgrp_id = 0;
15741 afi_t afiz;
15742 safi_t safiz;
15743 if (sgid)
15744 subgrp_id = strtoull(sgid, NULL, 10);
15745
15746 if (!ip && !afi)
15747 afiz = AFI_IP6;
15748 if (!ip && afi)
15749 afiz = bgp_vty_afi_from_str(afi);
15750 if (ip && !afi)
15751 afiz = AFI_IP;
15752 if (ip && afi) {
15753 afiz = bgp_vty_afi_from_str(afi);
15754 if (afiz != AFI_IP)
15755 vty_out(vty,
15756 "%% Cannot specify both 'ip' and 'ipv6'\n");
15757 return CMD_WARNING;
15758 }
15759
15760 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15761
15762 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15763 return CMD_SUCCESS;
15764 }
15765
15766 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15767 json_object *json)
15768 {
15769 struct listnode *node, *nnode;
15770 struct prefix *range;
15771 struct peer *conf;
15772 struct peer *peer;
15773 afi_t afi;
15774 safi_t safi;
15775 const char *peer_status;
15776 int lr_count;
15777 int dynamic;
15778 bool af_cfgd;
15779 json_object *json_peer_group = NULL;
15780 json_object *json_peer_group_afc = NULL;
15781 json_object *json_peer_group_members = NULL;
15782 json_object *json_peer_group_dynamic = NULL;
15783 json_object *json_peer_group_dynamic_af = NULL;
15784 json_object *json_peer_group_ranges = NULL;
15785
15786 conf = group->conf;
15787
15788 if (json) {
15789 json_peer_group = json_object_new_object();
15790 json_peer_group_afc = json_object_new_array();
15791 }
15792
15793 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15794 if (json)
15795 json_object_int_add(json_peer_group, "remoteAs",
15796 conf->as);
15797 else
15798 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15799 group->name, conf->as);
15800 } else if (conf->as_type == AS_INTERNAL) {
15801 if (json)
15802 json_object_int_add(json_peer_group, "remoteAs",
15803 group->bgp->as);
15804 else
15805 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15806 group->name, group->bgp->as);
15807 } else {
15808 if (!json)
15809 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15810 }
15811
15812 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15813 if (json)
15814 json_object_string_add(json_peer_group, "type",
15815 "internal");
15816 else
15817 vty_out(vty, " Peer-group type is internal\n");
15818 } else {
15819 if (json)
15820 json_object_string_add(json_peer_group, "type",
15821 "external");
15822 else
15823 vty_out(vty, " Peer-group type is external\n");
15824 }
15825
15826 /* Display AFs configured. */
15827 if (!json)
15828 vty_out(vty, " Configured address-families:");
15829
15830 FOREACH_AFI_SAFI (afi, safi) {
15831 if (conf->afc[afi][safi]) {
15832 af_cfgd = true;
15833 if (json)
15834 json_object_array_add(
15835 json_peer_group_afc,
15836 json_object_new_string(get_afi_safi_str(
15837 afi, safi, false)));
15838 else
15839 vty_out(vty, " %s;",
15840 get_afi_safi_str(afi, safi, false));
15841 }
15842 }
15843
15844 if (json) {
15845 json_object_object_add(json_peer_group,
15846 "addressFamiliesConfigured",
15847 json_peer_group_afc);
15848 } else {
15849 if (!af_cfgd)
15850 vty_out(vty, " none\n");
15851 else
15852 vty_out(vty, "\n");
15853 }
15854
15855 /* Display listen ranges (for dynamic neighbors), if any */
15856 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15857 lr_count = listcount(group->listen_range[afi]);
15858 if (lr_count) {
15859 if (json) {
15860 if (!json_peer_group_dynamic)
15861 json_peer_group_dynamic =
15862 json_object_new_object();
15863
15864 json_peer_group_dynamic_af =
15865 json_object_new_object();
15866 json_peer_group_ranges =
15867 json_object_new_array();
15868 json_object_int_add(json_peer_group_dynamic_af,
15869 "count", lr_count);
15870 } else {
15871 vty_out(vty, " %d %s listen range(s)\n",
15872 lr_count, afi2str(afi));
15873 }
15874
15875 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15876 nnode, range)) {
15877 if (json) {
15878 char buf[BUFSIZ];
15879
15880 snprintfrr(buf, sizeof(buf), "%pFX",
15881 range);
15882
15883 json_object_array_add(
15884 json_peer_group_ranges,
15885 json_object_new_string(buf));
15886 } else {
15887 vty_out(vty, " %pFX\n", range);
15888 }
15889 }
15890
15891 if (json) {
15892 json_object_object_add(
15893 json_peer_group_dynamic_af, "ranges",
15894 json_peer_group_ranges);
15895
15896 json_object_object_add(
15897 json_peer_group_dynamic, afi2str(afi),
15898 json_peer_group_dynamic_af);
15899 }
15900 }
15901 }
15902
15903 if (json_peer_group_dynamic)
15904 json_object_object_add(json_peer_group, "dynamicRanges",
15905 json_peer_group_dynamic);
15906
15907 /* Display group members and their status */
15908 if (listcount(group->peer)) {
15909 if (json)
15910 json_peer_group_members = json_object_new_object();
15911 else
15912 vty_out(vty, " Peer-group members:\n");
15913 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15914 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15915 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15916 peer_status = "Idle (Admin)";
15917 else if (CHECK_FLAG(peer->sflags,
15918 PEER_STATUS_PREFIX_OVERFLOW))
15919 peer_status = "Idle (PfxCt)";
15920 else
15921 peer_status = lookup_msg(bgp_status_msg,
15922 peer->status, NULL);
15923
15924 dynamic = peer_dynamic_neighbor(peer);
15925
15926 if (json) {
15927 json_object *json_peer_group_member =
15928 json_object_new_object();
15929
15930 json_object_string_add(json_peer_group_member,
15931 "status", peer_status);
15932
15933 if (dynamic)
15934 json_object_boolean_true_add(
15935 json_peer_group_member,
15936 "dynamic");
15937
15938 json_object_object_add(json_peer_group_members,
15939 peer->host,
15940 json_peer_group_member);
15941 } else {
15942 vty_out(vty, " %s %s %s \n", peer->host,
15943 dynamic ? "(dynamic)" : "",
15944 peer_status);
15945 }
15946 }
15947 if (json)
15948 json_object_object_add(json_peer_group, "members",
15949 json_peer_group_members);
15950 }
15951
15952 if (json)
15953 json_object_object_add(json, group->name, json_peer_group);
15954
15955 return CMD_SUCCESS;
15956 }
15957
15958 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15959 const char *group_name, bool uj)
15960 {
15961 struct bgp *bgp;
15962 struct listnode *node, *nnode;
15963 struct peer_group *group;
15964 bool found = false;
15965 json_object *json = NULL;
15966
15967 if (uj)
15968 json = json_object_new_object();
15969
15970 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15971
15972 if (!bgp) {
15973 if (uj)
15974 vty_json(vty, json);
15975 else
15976 vty_out(vty, "%% BGP instance not found\n");
15977
15978 return CMD_WARNING;
15979 }
15980
15981 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15982 if (group_name) {
15983 if (strmatch(group->name, group_name)) {
15984 bgp_show_one_peer_group(vty, group, json);
15985 found = true;
15986 break;
15987 }
15988 } else {
15989 bgp_show_one_peer_group(vty, group, json);
15990 }
15991 }
15992
15993 if (group_name && !found && !uj)
15994 vty_out(vty, "%% No such peer-group\n");
15995
15996 if (uj)
15997 vty_json(vty, json);
15998
15999 return CMD_SUCCESS;
16000 }
16001
16002 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16003 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16004 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16005 "Detailed information on BGP peer groups\n"
16006 "Peer group name\n" JSON_STR)
16007 {
16008 char *vrf, *pg;
16009 int idx = 0;
16010 bool uj = use_json(argc, argv);
16011
16012 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16013 : NULL;
16014 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16015
16016 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16017 }
16018
16019
16020 /* Redistribute VTY commands. */
16021
16022 DEFUN (bgp_redistribute_ipv4,
16023 bgp_redistribute_ipv4_cmd,
16024 "redistribute " FRR_IP_REDIST_STR_BGPD,
16025 "Redistribute information from another routing protocol\n"
16026 FRR_IP_REDIST_HELP_STR_BGPD)
16027 {
16028 VTY_DECLVAR_CONTEXT(bgp, bgp);
16029 int idx_protocol = 1;
16030 int type;
16031
16032 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16033 if (type < 0) {
16034 vty_out(vty, "%% Invalid route type\n");
16035 return CMD_WARNING_CONFIG_FAILED;
16036 }
16037
16038 bgp_redist_add(bgp, AFI_IP, type, 0);
16039 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16040 }
16041
16042 ALIAS_HIDDEN(
16043 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16044 "redistribute " FRR_IP_REDIST_STR_BGPD,
16045 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16046
16047 DEFUN (bgp_redistribute_ipv4_rmap,
16048 bgp_redistribute_ipv4_rmap_cmd,
16049 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16050 "Redistribute information from another routing protocol\n"
16051 FRR_IP_REDIST_HELP_STR_BGPD
16052 "Route map reference\n"
16053 "Pointer to route-map entries\n")
16054 {
16055 VTY_DECLVAR_CONTEXT(bgp, bgp);
16056 int idx_protocol = 1;
16057 int idx_word = 3;
16058 int type;
16059 struct bgp_redist *red;
16060 bool changed;
16061 struct route_map *route_map = route_map_lookup_warn_noexist(
16062 vty, argv[idx_word]->arg);
16063
16064 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16065 if (type < 0) {
16066 vty_out(vty, "%% Invalid route type\n");
16067 return CMD_WARNING_CONFIG_FAILED;
16068 }
16069
16070 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16071 changed =
16072 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16073 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16074 }
16075
16076 ALIAS_HIDDEN(
16077 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16078 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16079 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16080 "Route map reference\n"
16081 "Pointer to route-map entries\n")
16082
16083 DEFUN (bgp_redistribute_ipv4_metric,
16084 bgp_redistribute_ipv4_metric_cmd,
16085 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16086 "Redistribute information from another routing protocol\n"
16087 FRR_IP_REDIST_HELP_STR_BGPD
16088 "Metric for redistributed routes\n"
16089 "Default metric\n")
16090 {
16091 VTY_DECLVAR_CONTEXT(bgp, bgp);
16092 int idx_protocol = 1;
16093 int idx_number = 3;
16094 int type;
16095 uint32_t metric;
16096 struct bgp_redist *red;
16097 bool changed;
16098
16099 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16100 if (type < 0) {
16101 vty_out(vty, "%% Invalid route type\n");
16102 return CMD_WARNING_CONFIG_FAILED;
16103 }
16104 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16105
16106 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16107 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16108 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16109 }
16110
16111 ALIAS_HIDDEN(
16112 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16113 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16114 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16115 "Metric for redistributed routes\n"
16116 "Default metric\n")
16117
16118 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16119 bgp_redistribute_ipv4_rmap_metric_cmd,
16120 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16121 "Redistribute information from another routing protocol\n"
16122 FRR_IP_REDIST_HELP_STR_BGPD
16123 "Route map reference\n"
16124 "Pointer to route-map entries\n"
16125 "Metric for redistributed routes\n"
16126 "Default metric\n")
16127 {
16128 VTY_DECLVAR_CONTEXT(bgp, bgp);
16129 int idx_protocol = 1;
16130 int idx_word = 3;
16131 int idx_number = 5;
16132 int type;
16133 uint32_t metric;
16134 struct bgp_redist *red;
16135 bool changed;
16136 struct route_map *route_map =
16137 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16138
16139 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16140 if (type < 0) {
16141 vty_out(vty, "%% Invalid route type\n");
16142 return CMD_WARNING_CONFIG_FAILED;
16143 }
16144 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16145
16146 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16147 changed =
16148 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16149 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16150 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16151 }
16152
16153 ALIAS_HIDDEN(
16154 bgp_redistribute_ipv4_rmap_metric,
16155 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16156 "redistribute " FRR_IP_REDIST_STR_BGPD
16157 " route-map RMAP_NAME metric (0-4294967295)",
16158 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16159 "Route map reference\n"
16160 "Pointer to route-map entries\n"
16161 "Metric for redistributed routes\n"
16162 "Default metric\n")
16163
16164 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16165 bgp_redistribute_ipv4_metric_rmap_cmd,
16166 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16167 "Redistribute information from another routing protocol\n"
16168 FRR_IP_REDIST_HELP_STR_BGPD
16169 "Metric for redistributed routes\n"
16170 "Default metric\n"
16171 "Route map reference\n"
16172 "Pointer to route-map entries\n")
16173 {
16174 VTY_DECLVAR_CONTEXT(bgp, bgp);
16175 int idx_protocol = 1;
16176 int idx_number = 3;
16177 int idx_word = 5;
16178 int type;
16179 uint32_t metric;
16180 struct bgp_redist *red;
16181 bool changed;
16182 struct route_map *route_map =
16183 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16184
16185 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16186 if (type < 0) {
16187 vty_out(vty, "%% Invalid route type\n");
16188 return CMD_WARNING_CONFIG_FAILED;
16189 }
16190 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16191
16192 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16193 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16194 changed |=
16195 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16196 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16197 }
16198
16199 ALIAS_HIDDEN(
16200 bgp_redistribute_ipv4_metric_rmap,
16201 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16202 "redistribute " FRR_IP_REDIST_STR_BGPD
16203 " metric (0-4294967295) route-map RMAP_NAME",
16204 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16205 "Metric for redistributed routes\n"
16206 "Default metric\n"
16207 "Route map reference\n"
16208 "Pointer to route-map entries\n")
16209
16210 DEFUN (bgp_redistribute_ipv4_ospf,
16211 bgp_redistribute_ipv4_ospf_cmd,
16212 "redistribute <ospf|table> (1-65535)",
16213 "Redistribute information from another routing protocol\n"
16214 "Open Shortest Path First (OSPFv2)\n"
16215 "Non-main Kernel Routing Table\n"
16216 "Instance ID/Table ID\n")
16217 {
16218 VTY_DECLVAR_CONTEXT(bgp, bgp);
16219 int idx_ospf_table = 1;
16220 int idx_number = 2;
16221 unsigned short instance;
16222 unsigned short protocol;
16223
16224 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16225
16226 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16227 protocol = ZEBRA_ROUTE_OSPF;
16228 else
16229 protocol = ZEBRA_ROUTE_TABLE;
16230
16231 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16232 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16233 }
16234
16235 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16236 "redistribute <ospf|table> (1-65535)",
16237 "Redistribute information from another routing protocol\n"
16238 "Open Shortest Path First (OSPFv2)\n"
16239 "Non-main Kernel Routing Table\n"
16240 "Instance ID/Table ID\n")
16241
16242 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16243 bgp_redistribute_ipv4_ospf_rmap_cmd,
16244 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16245 "Redistribute information from another routing protocol\n"
16246 "Open Shortest Path First (OSPFv2)\n"
16247 "Non-main Kernel Routing Table\n"
16248 "Instance ID/Table ID\n"
16249 "Route map reference\n"
16250 "Pointer to route-map entries\n")
16251 {
16252 VTY_DECLVAR_CONTEXT(bgp, bgp);
16253 int idx_ospf_table = 1;
16254 int idx_number = 2;
16255 int idx_word = 4;
16256 struct bgp_redist *red;
16257 unsigned short instance;
16258 int protocol;
16259 bool changed;
16260 struct route_map *route_map =
16261 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16262
16263 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16264 protocol = ZEBRA_ROUTE_OSPF;
16265 else
16266 protocol = ZEBRA_ROUTE_TABLE;
16267
16268 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16269 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16270 changed =
16271 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16272 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16273 }
16274
16275 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16276 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16277 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16278 "Redistribute information from another routing protocol\n"
16279 "Open Shortest Path First (OSPFv2)\n"
16280 "Non-main Kernel Routing Table\n"
16281 "Instance ID/Table ID\n"
16282 "Route map reference\n"
16283 "Pointer to route-map entries\n")
16284
16285 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16286 bgp_redistribute_ipv4_ospf_metric_cmd,
16287 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16288 "Redistribute information from another routing protocol\n"
16289 "Open Shortest Path First (OSPFv2)\n"
16290 "Non-main Kernel Routing Table\n"
16291 "Instance ID/Table ID\n"
16292 "Metric for redistributed routes\n"
16293 "Default metric\n")
16294 {
16295 VTY_DECLVAR_CONTEXT(bgp, bgp);
16296 int idx_ospf_table = 1;
16297 int idx_number = 2;
16298 int idx_number_2 = 4;
16299 uint32_t metric;
16300 struct bgp_redist *red;
16301 unsigned short instance;
16302 int protocol;
16303 bool changed;
16304
16305 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16306 protocol = ZEBRA_ROUTE_OSPF;
16307 else
16308 protocol = ZEBRA_ROUTE_TABLE;
16309
16310 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16311 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16312
16313 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16314 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16315 metric);
16316 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16317 }
16318
16319 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16320 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16321 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16322 "Redistribute information from another routing protocol\n"
16323 "Open Shortest Path First (OSPFv2)\n"
16324 "Non-main Kernel Routing Table\n"
16325 "Instance ID/Table ID\n"
16326 "Metric for redistributed routes\n"
16327 "Default metric\n")
16328
16329 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16330 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16331 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16332 "Redistribute information from another routing protocol\n"
16333 "Open Shortest Path First (OSPFv2)\n"
16334 "Non-main Kernel Routing Table\n"
16335 "Instance ID/Table ID\n"
16336 "Route map reference\n"
16337 "Pointer to route-map entries\n"
16338 "Metric for redistributed routes\n"
16339 "Default metric\n")
16340 {
16341 VTY_DECLVAR_CONTEXT(bgp, bgp);
16342 int idx_ospf_table = 1;
16343 int idx_number = 2;
16344 int idx_word = 4;
16345 int idx_number_2 = 6;
16346 uint32_t metric;
16347 struct bgp_redist *red;
16348 unsigned short instance;
16349 int protocol;
16350 bool changed;
16351 struct route_map *route_map =
16352 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16353
16354 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16355 protocol = ZEBRA_ROUTE_OSPF;
16356 else
16357 protocol = ZEBRA_ROUTE_TABLE;
16358
16359 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16360 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16361
16362 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16363 changed =
16364 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16365 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16366 metric);
16367 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16368 }
16369
16370 ALIAS_HIDDEN(
16371 bgp_redistribute_ipv4_ospf_rmap_metric,
16372 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16373 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
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 "Route map reference\n"
16379 "Pointer to route-map entries\n"
16380 "Metric for redistributed routes\n"
16381 "Default metric\n")
16382
16383 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16384 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16385 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16386 "Redistribute information from another routing protocol\n"
16387 "Open Shortest Path First (OSPFv2)\n"
16388 "Non-main Kernel Routing Table\n"
16389 "Instance ID/Table ID\n"
16390 "Metric for redistributed routes\n"
16391 "Default metric\n"
16392 "Route map reference\n"
16393 "Pointer to route-map entries\n")
16394 {
16395 VTY_DECLVAR_CONTEXT(bgp, bgp);
16396 int idx_ospf_table = 1;
16397 int idx_number = 2;
16398 int idx_number_2 = 4;
16399 int idx_word = 6;
16400 uint32_t metric;
16401 struct bgp_redist *red;
16402 unsigned short instance;
16403 int protocol;
16404 bool changed;
16405 struct route_map *route_map =
16406 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16407
16408 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16409 protocol = ZEBRA_ROUTE_OSPF;
16410 else
16411 protocol = ZEBRA_ROUTE_TABLE;
16412
16413 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16414 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16415
16416 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16417 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16418 metric);
16419 changed |=
16420 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16421 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16422 }
16423
16424 ALIAS_HIDDEN(
16425 bgp_redistribute_ipv4_ospf_metric_rmap,
16426 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16427 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16428 "Redistribute information from another routing protocol\n"
16429 "Open Shortest Path First (OSPFv2)\n"
16430 "Non-main Kernel Routing Table\n"
16431 "Instance ID/Table ID\n"
16432 "Metric for redistributed routes\n"
16433 "Default metric\n"
16434 "Route map reference\n"
16435 "Pointer to route-map entries\n")
16436
16437 DEFUN (no_bgp_redistribute_ipv4_ospf,
16438 no_bgp_redistribute_ipv4_ospf_cmd,
16439 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16440 NO_STR
16441 "Redistribute information from another routing protocol\n"
16442 "Open Shortest Path First (OSPFv2)\n"
16443 "Non-main Kernel Routing Table\n"
16444 "Instance ID/Table ID\n"
16445 "Metric for redistributed routes\n"
16446 "Default metric\n"
16447 "Route map reference\n"
16448 "Pointer to route-map entries\n")
16449 {
16450 VTY_DECLVAR_CONTEXT(bgp, bgp);
16451 int idx_ospf_table = 2;
16452 int idx_number = 3;
16453 unsigned short instance;
16454 int protocol;
16455
16456 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16457 protocol = ZEBRA_ROUTE_OSPF;
16458 else
16459 protocol = ZEBRA_ROUTE_TABLE;
16460
16461 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16462 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16463 }
16464
16465 ALIAS_HIDDEN(
16466 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16467 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16468 NO_STR
16469 "Redistribute information from another routing protocol\n"
16470 "Open Shortest Path First (OSPFv2)\n"
16471 "Non-main Kernel Routing Table\n"
16472 "Instance ID/Table ID\n"
16473 "Metric for redistributed routes\n"
16474 "Default metric\n"
16475 "Route map reference\n"
16476 "Pointer to route-map entries\n")
16477
16478 DEFUN (no_bgp_redistribute_ipv4,
16479 no_bgp_redistribute_ipv4_cmd,
16480 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16481 NO_STR
16482 "Redistribute information from another routing protocol\n"
16483 FRR_IP_REDIST_HELP_STR_BGPD
16484 "Metric for redistributed routes\n"
16485 "Default metric\n"
16486 "Route map reference\n"
16487 "Pointer to route-map entries\n")
16488 {
16489 VTY_DECLVAR_CONTEXT(bgp, bgp);
16490 int idx_protocol = 2;
16491 int type;
16492
16493 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16494 if (type < 0) {
16495 vty_out(vty, "%% Invalid route type\n");
16496 return CMD_WARNING_CONFIG_FAILED;
16497 }
16498 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16499 }
16500
16501 ALIAS_HIDDEN(
16502 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16503 "no redistribute " FRR_IP_REDIST_STR_BGPD
16504 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16505 NO_STR
16506 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16507 "Metric for redistributed routes\n"
16508 "Default metric\n"
16509 "Route map reference\n"
16510 "Pointer to route-map entries\n")
16511
16512 DEFUN (bgp_redistribute_ipv6,
16513 bgp_redistribute_ipv6_cmd,
16514 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16515 "Redistribute information from another routing protocol\n"
16516 FRR_IP6_REDIST_HELP_STR_BGPD)
16517 {
16518 VTY_DECLVAR_CONTEXT(bgp, bgp);
16519 int idx_protocol = 1;
16520 int type;
16521
16522 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16523 if (type < 0) {
16524 vty_out(vty, "%% Invalid route type\n");
16525 return CMD_WARNING_CONFIG_FAILED;
16526 }
16527
16528 bgp_redist_add(bgp, AFI_IP6, type, 0);
16529 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16530 }
16531
16532 DEFUN (bgp_redistribute_ipv6_rmap,
16533 bgp_redistribute_ipv6_rmap_cmd,
16534 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16535 "Redistribute information from another routing protocol\n"
16536 FRR_IP6_REDIST_HELP_STR_BGPD
16537 "Route map reference\n"
16538 "Pointer to route-map entries\n")
16539 {
16540 VTY_DECLVAR_CONTEXT(bgp, bgp);
16541 int idx_protocol = 1;
16542 int idx_word = 3;
16543 int type;
16544 struct bgp_redist *red;
16545 bool changed;
16546 struct route_map *route_map =
16547 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16548
16549 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16550 if (type < 0) {
16551 vty_out(vty, "%% Invalid route type\n");
16552 return CMD_WARNING_CONFIG_FAILED;
16553 }
16554
16555 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16556 changed =
16557 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16558 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16559 }
16560
16561 DEFUN (bgp_redistribute_ipv6_metric,
16562 bgp_redistribute_ipv6_metric_cmd,
16563 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16564 "Redistribute information from another routing protocol\n"
16565 FRR_IP6_REDIST_HELP_STR_BGPD
16566 "Metric for redistributed routes\n"
16567 "Default metric\n")
16568 {
16569 VTY_DECLVAR_CONTEXT(bgp, bgp);
16570 int idx_protocol = 1;
16571 int idx_number = 3;
16572 int type;
16573 uint32_t metric;
16574 struct bgp_redist *red;
16575 bool changed;
16576
16577 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16578 if (type < 0) {
16579 vty_out(vty, "%% Invalid route type\n");
16580 return CMD_WARNING_CONFIG_FAILED;
16581 }
16582 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16583
16584 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16585 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16586 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16587 }
16588
16589 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16590 bgp_redistribute_ipv6_rmap_metric_cmd,
16591 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16592 "Redistribute information from another routing protocol\n"
16593 FRR_IP6_REDIST_HELP_STR_BGPD
16594 "Route map reference\n"
16595 "Pointer to route-map entries\n"
16596 "Metric for redistributed routes\n"
16597 "Default metric\n")
16598 {
16599 VTY_DECLVAR_CONTEXT(bgp, bgp);
16600 int idx_protocol = 1;
16601 int idx_word = 3;
16602 int idx_number = 5;
16603 int type;
16604 uint32_t metric;
16605 struct bgp_redist *red;
16606 bool changed;
16607 struct route_map *route_map =
16608 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16609
16610 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16611 if (type < 0) {
16612 vty_out(vty, "%% Invalid route type\n");
16613 return CMD_WARNING_CONFIG_FAILED;
16614 }
16615 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16616
16617 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16618 changed =
16619 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16620 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16621 metric);
16622 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16623 }
16624
16625 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16626 bgp_redistribute_ipv6_metric_rmap_cmd,
16627 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16628 "Redistribute information from another routing protocol\n"
16629 FRR_IP6_REDIST_HELP_STR_BGPD
16630 "Metric for redistributed routes\n"
16631 "Default metric\n"
16632 "Route map reference\n"
16633 "Pointer to route-map entries\n")
16634 {
16635 VTY_DECLVAR_CONTEXT(bgp, bgp);
16636 int idx_protocol = 1;
16637 int idx_number = 3;
16638 int idx_word = 5;
16639 int type;
16640 uint32_t metric;
16641 struct bgp_redist *red;
16642 bool changed;
16643 struct route_map *route_map =
16644 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16645
16646 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16647 if (type < 0) {
16648 vty_out(vty, "%% Invalid route type\n");
16649 return CMD_WARNING_CONFIG_FAILED;
16650 }
16651 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16652
16653 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16654 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16655 metric);
16656 changed |=
16657 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16658 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16659 }
16660
16661 DEFUN (no_bgp_redistribute_ipv6,
16662 no_bgp_redistribute_ipv6_cmd,
16663 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16664 NO_STR
16665 "Redistribute information from another routing protocol\n"
16666 FRR_IP6_REDIST_HELP_STR_BGPD
16667 "Metric for redistributed routes\n"
16668 "Default metric\n"
16669 "Route map reference\n"
16670 "Pointer to route-map entries\n")
16671 {
16672 VTY_DECLVAR_CONTEXT(bgp, bgp);
16673 int idx_protocol = 2;
16674 int type;
16675
16676 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16677 if (type < 0) {
16678 vty_out(vty, "%% Invalid route type\n");
16679 return CMD_WARNING_CONFIG_FAILED;
16680 }
16681
16682 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16683 }
16684
16685 /* Neighbor update tcp-mss. */
16686 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16687 const char *tcp_mss_str)
16688 {
16689 struct peer *peer;
16690 uint32_t tcp_mss_val = 0;
16691
16692 peer = peer_and_group_lookup_vty(vty, peer_str);
16693 if (!peer)
16694 return CMD_WARNING_CONFIG_FAILED;
16695
16696 if (tcp_mss_str) {
16697 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16698 peer_tcp_mss_set(peer, tcp_mss_val);
16699 } else {
16700 peer_tcp_mss_unset(peer);
16701 }
16702
16703 return CMD_SUCCESS;
16704 }
16705
16706 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16707 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16708 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16709 "TCP max segment size\n"
16710 "TCP MSS value\n")
16711 {
16712 int peer_index = 1;
16713 int mss_index = 3;
16714
16715 vty_out(vty,
16716 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16717 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16718 argv[mss_index]->arg);
16719 }
16720
16721 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16722 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16723 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16724 "TCP max segment size\n"
16725 "TCP MSS value\n")
16726 {
16727 int peer_index = 2;
16728
16729 vty_out(vty,
16730 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16731 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16732 }
16733
16734 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16735 "[no$no] bgp retain route-target all",
16736 NO_STR BGP_STR
16737 "Retain BGP updates\n"
16738 "Retain BGP updates based on route-target values\n"
16739 "Retain all BGP updates\n")
16740 {
16741 bool check;
16742 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16743
16744 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16745 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16746 if (check != !no) {
16747 if (!no)
16748 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16749 [bgp_node_safi(vty)],
16750 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16751 else
16752 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16753 [bgp_node_safi(vty)],
16754 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16755 /* trigger a flush to re-sync with ADJ-RIB-in */
16756 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16757 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16758 }
16759 return CMD_SUCCESS;
16760 }
16761
16762 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16763 afi_t afi, safi_t safi)
16764 {
16765 int i;
16766
16767 /* Unicast redistribution only. */
16768 if (safi != SAFI_UNICAST)
16769 return;
16770
16771 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16772 /* Redistribute BGP does not make sense. */
16773 if (i != ZEBRA_ROUTE_BGP) {
16774 struct list *red_list;
16775 struct listnode *node;
16776 struct bgp_redist *red;
16777
16778 red_list = bgp->redist[afi][i];
16779 if (!red_list)
16780 continue;
16781
16782 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16783 /* "redistribute" configuration. */
16784 vty_out(vty, " redistribute %s",
16785 zebra_route_string(i));
16786 if (red->instance)
16787 vty_out(vty, " %d", red->instance);
16788 if (red->redist_metric_flag)
16789 vty_out(vty, " metric %u",
16790 red->redist_metric);
16791 if (red->rmap.name)
16792 vty_out(vty, " route-map %s",
16793 red->rmap.name);
16794 vty_out(vty, "\n");
16795 }
16796 }
16797 }
16798 }
16799
16800 /* peer-group helpers for config-write */
16801
16802 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16803 {
16804 if (!peer_group_active(peer)) {
16805 if (CHECK_FLAG(peer->flags_invert, flag))
16806 return !CHECK_FLAG(peer->flags, flag);
16807 else
16808 return !!CHECK_FLAG(peer->flags, flag);
16809 }
16810
16811 return !!CHECK_FLAG(peer->flags_override, flag);
16812 }
16813
16814 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16815 uint64_t flag)
16816 {
16817 if (!peer_group_active(peer)) {
16818 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16819 return !peer_af_flag_check(peer, afi, safi, flag);
16820 else
16821 return !!peer_af_flag_check(peer, afi, safi, flag);
16822 }
16823
16824 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16825 }
16826
16827 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16828 uint8_t type, int direct)
16829 {
16830 struct bgp_filter *filter;
16831
16832 if (peer_group_active(peer))
16833 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16834 type);
16835
16836 filter = &peer->filter[afi][safi];
16837 switch (type) {
16838 case PEER_FT_DISTRIBUTE_LIST:
16839 return !!(filter->dlist[direct].name);
16840 case PEER_FT_FILTER_LIST:
16841 return !!(filter->aslist[direct].name);
16842 case PEER_FT_PREFIX_LIST:
16843 return !!(filter->plist[direct].name);
16844 case PEER_FT_ROUTE_MAP:
16845 return !!(filter->map[direct].name);
16846 case PEER_FT_UNSUPPRESS_MAP:
16847 return !!(filter->usmap.name);
16848 case PEER_FT_ADVERTISE_MAP:
16849 return !!(filter->advmap.aname
16850 && ((filter->advmap.condition == direct)
16851 && filter->advmap.cname));
16852 default:
16853 return false;
16854 }
16855 }
16856
16857 /* Return true if the addpath type is set for peer and different from
16858 * peer-group.
16859 */
16860 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16861 safi_t safi)
16862 {
16863 enum bgp_addpath_strat type, g_type;
16864
16865 type = peer->addpath_type[afi][safi];
16866
16867 if (type != BGP_ADDPATH_NONE) {
16868 if (peer_group_active(peer)) {
16869 g_type = peer->group->conf->addpath_type[afi][safi];
16870
16871 if (type != g_type)
16872 return true;
16873 else
16874 return false;
16875 }
16876
16877 return true;
16878 }
16879
16880 return false;
16881 }
16882
16883 /* This is part of the address-family block (unicast only) */
16884 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16885 afi_t afi)
16886 {
16887 int indent = 2;
16888 uint32_t tovpn_sid_index = 0;
16889
16890 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16891 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16892 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16893 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16894 bgp->vpn_policy[afi]
16895 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16896 else
16897 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16898 bgp->vpn_policy[afi]
16899 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16900 }
16901 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16902 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16903 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16904 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16905 return;
16906
16907 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16908 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16909
16910 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16911
16912 } else {
16913 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16914 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16915 bgp->vpn_policy[afi].tovpn_label);
16916 }
16917 }
16918
16919 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16920 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16921 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16922 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16923 } else if (tovpn_sid_index != 0) {
16924 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16925 tovpn_sid_index);
16926 }
16927
16928 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16929 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16930 &bgp->vpn_policy[afi].tovpn_rd);
16931
16932 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16933 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16934
16935 char buf[PREFIX_STRLEN];
16936 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16937 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16938 sizeof(buf))) {
16939
16940 vty_out(vty, "%*snexthop vpn export %s\n",
16941 indent, "", buf);
16942 }
16943 }
16944 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16945 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16946 && ecommunity_cmp(
16947 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16948 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16949
16950 char *b = ecommunity_ecom2str(
16951 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16952 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16953 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16954 XFREE(MTYPE_ECOMMUNITY_STR, b);
16955 } else {
16956 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16957 char *b = ecommunity_ecom2str(
16958 bgp->vpn_policy[afi]
16959 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16960 ECOMMUNITY_FORMAT_ROUTE_MAP,
16961 ECOMMUNITY_ROUTE_TARGET);
16962 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16963 XFREE(MTYPE_ECOMMUNITY_STR, b);
16964 }
16965 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16966 char *b = ecommunity_ecom2str(
16967 bgp->vpn_policy[afi]
16968 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16969 ECOMMUNITY_FORMAT_ROUTE_MAP,
16970 ECOMMUNITY_ROUTE_TARGET);
16971 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16972 XFREE(MTYPE_ECOMMUNITY_STR, b);
16973 }
16974 }
16975
16976 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16977 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16978 bgp->vpn_policy[afi]
16979 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16980
16981 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16982 char *b = ecommunity_ecom2str(
16983 bgp->vpn_policy[afi]
16984 .import_redirect_rtlist,
16985 ECOMMUNITY_FORMAT_ROUTE_MAP,
16986 ECOMMUNITY_ROUTE_TARGET);
16987
16988 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16989 != ECOMMUNITY_SIZE)
16990 vty_out(vty, "%*srt6 redirect import %s\n",
16991 indent, "", b);
16992 else
16993 vty_out(vty, "%*srt redirect import %s\n",
16994 indent, "", b);
16995 XFREE(MTYPE_ECOMMUNITY_STR, b);
16996 }
16997 }
16998
16999 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17000 afi_t afi, safi_t safi)
17001 {
17002 struct bgp_filter *filter;
17003 char *addr;
17004
17005 addr = peer->host;
17006 filter = &peer->filter[afi][safi];
17007
17008 /* distribute-list. */
17009 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17010 FILTER_IN))
17011 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17012 filter->dlist[FILTER_IN].name);
17013
17014 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17015 FILTER_OUT))
17016 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17017 filter->dlist[FILTER_OUT].name);
17018
17019 /* prefix-list. */
17020 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17021 FILTER_IN))
17022 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17023 filter->plist[FILTER_IN].name);
17024
17025 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17026 FILTER_OUT))
17027 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17028 filter->plist[FILTER_OUT].name);
17029
17030 /* route-map. */
17031 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17032 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17033 filter->map[RMAP_IN].name);
17034
17035 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17036 RMAP_OUT))
17037 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17038 filter->map[RMAP_OUT].name);
17039
17040 /* unsuppress-map */
17041 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17042 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17043 filter->usmap.name);
17044
17045 /* advertise-map : always applied in OUT direction*/
17046 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17047 CONDITION_NON_EXIST))
17048 vty_out(vty,
17049 " neighbor %s advertise-map %s non-exist-map %s\n",
17050 addr, filter->advmap.aname, filter->advmap.cname);
17051
17052 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17053 CONDITION_EXIST))
17054 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17055 addr, filter->advmap.aname, filter->advmap.cname);
17056
17057 /* filter-list. */
17058 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17059 FILTER_IN))
17060 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17061 filter->aslist[FILTER_IN].name);
17062
17063 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17064 FILTER_OUT))
17065 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17066 filter->aslist[FILTER_OUT].name);
17067 }
17068
17069 /* BGP peer configuration display function. */
17070 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17071 struct peer *peer)
17072 {
17073 struct peer *g_peer = NULL;
17074 char *addr;
17075 int if_pg_printed = false;
17076 int if_ras_printed = false;
17077
17078 /* Skip dynamic neighbors. */
17079 if (peer_dynamic_neighbor(peer))
17080 return;
17081
17082 if (peer->conf_if)
17083 addr = peer->conf_if;
17084 else
17085 addr = peer->host;
17086
17087 /************************************
17088 ****** Global to the neighbor ******
17089 ************************************/
17090 if (peer->conf_if) {
17091 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17092 vty_out(vty, " neighbor %s interface v6only", addr);
17093 else
17094 vty_out(vty, " neighbor %s interface", addr);
17095
17096 if (peer_group_active(peer)) {
17097 vty_out(vty, " peer-group %s", peer->group->name);
17098 if_pg_printed = true;
17099 } else if (peer->as_type == AS_SPECIFIED) {
17100 vty_out(vty, " remote-as %u", peer->as);
17101 if_ras_printed = true;
17102 } else if (peer->as_type == AS_INTERNAL) {
17103 vty_out(vty, " remote-as internal");
17104 if_ras_printed = true;
17105 } else if (peer->as_type == AS_EXTERNAL) {
17106 vty_out(vty, " remote-as external");
17107 if_ras_printed = true;
17108 }
17109
17110 vty_out(vty, "\n");
17111 }
17112
17113 /* remote-as and peer-group */
17114 /* peer is a member of a peer-group */
17115 if (peer_group_active(peer)) {
17116 g_peer = peer->group->conf;
17117
17118 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17119 if (peer->as_type == AS_SPECIFIED) {
17120 vty_out(vty, " neighbor %s remote-as %u\n",
17121 addr, peer->as);
17122 } else if (peer->as_type == AS_INTERNAL) {
17123 vty_out(vty,
17124 " neighbor %s remote-as internal\n",
17125 addr);
17126 } else if (peer->as_type == AS_EXTERNAL) {
17127 vty_out(vty,
17128 " neighbor %s remote-as external\n",
17129 addr);
17130 }
17131 }
17132
17133 /* For swpX peers we displayed the peer-group
17134 * via 'neighbor swpX interface peer-group PGNAME' */
17135 if (!if_pg_printed)
17136 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17137 peer->group->name);
17138 }
17139
17140 /* peer is NOT a member of a peer-group */
17141 else {
17142 /* peer is a peer-group, declare the peer-group */
17143 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17144 vty_out(vty, " neighbor %s peer-group\n", addr);
17145 }
17146
17147 if (!if_ras_printed) {
17148 if (peer->as_type == AS_SPECIFIED) {
17149 vty_out(vty, " neighbor %s remote-as %u\n",
17150 addr, peer->as);
17151 } else if (peer->as_type == AS_INTERNAL) {
17152 vty_out(vty,
17153 " neighbor %s remote-as internal\n",
17154 addr);
17155 } else if (peer->as_type == AS_EXTERNAL) {
17156 vty_out(vty,
17157 " neighbor %s remote-as external\n",
17158 addr);
17159 }
17160 }
17161 }
17162
17163 /* local-as */
17164 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17165 vty_out(vty, " neighbor %s local-as %u", addr,
17166 peer->change_local_as);
17167 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17168 vty_out(vty, " no-prepend");
17169 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17170 vty_out(vty, " replace-as");
17171 vty_out(vty, "\n");
17172 }
17173
17174 /* description */
17175 if (peer->desc) {
17176 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17177 }
17178
17179 /* shutdown */
17180 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17181 if (peer->tx_shutdown_message)
17182 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17183 peer->tx_shutdown_message);
17184 else
17185 vty_out(vty, " neighbor %s shutdown\n", addr);
17186 }
17187
17188 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17189 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17190 peer->rtt_expected, peer->rtt_keepalive_conf);
17191
17192 /* bfd */
17193 if (peer->bfd_config)
17194 bgp_bfd_peer_config_write(vty, peer, addr);
17195
17196 /* password */
17197 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17198 vty_out(vty, " neighbor %s password %s\n", addr,
17199 peer->password);
17200
17201 /* neighbor solo */
17202 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17203 if (!peer_group_active(peer)) {
17204 vty_out(vty, " neighbor %s solo\n", addr);
17205 }
17206 }
17207
17208 /* BGP port */
17209 if (peer->port != BGP_PORT_DEFAULT) {
17210 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17211 }
17212
17213 /* Local interface name */
17214 if (peer->ifname) {
17215 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17216 }
17217
17218 /* TCP max segment size */
17219 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17220 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17221
17222 /* passive */
17223 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17224 vty_out(vty, " neighbor %s passive\n", addr);
17225
17226 /* ebgp-multihop */
17227 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17228 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17229 && peer->ttl == MAXTTL)) {
17230 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17231 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17232 peer->ttl);
17233 }
17234 }
17235
17236 /* aigp */
17237 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17238 vty_out(vty, " neighbor %s aigp\n", addr);
17239
17240 /* graceful-shutdown */
17241 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17242 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17243
17244 /* role */
17245 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17246 peer->local_role != ROLE_UNDEFINED)
17247 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17248 bgp_get_name_by_role(peer->local_role),
17249 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17250 ? " strict-mode"
17251 : "");
17252
17253 /* ttl-security hops */
17254 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17255 if (!peer_group_active(peer)
17256 || g_peer->gtsm_hops != peer->gtsm_hops) {
17257 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17258 addr, peer->gtsm_hops);
17259 }
17260 }
17261
17262 /* disable-connected-check */
17263 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17264 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17265
17266 /* link-bw-encoding-ieee */
17267 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17268 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17269 addr);
17270
17271 /* extended-optional-parameters */
17272 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17273 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17274 addr);
17275
17276 /* enforce-first-as */
17277 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17278 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17279
17280 /* update-source */
17281 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17282 if (peer->update_source)
17283 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17284 peer->update_source);
17285 else if (peer->update_if)
17286 vty_out(vty, " neighbor %s update-source %s\n", addr,
17287 peer->update_if);
17288 }
17289
17290 /* advertisement-interval */
17291 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17292 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17293 peer->routeadv);
17294
17295 /* timers */
17296 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17297 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17298 peer->keepalive, peer->holdtime);
17299
17300 /* timers connect */
17301 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17302 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17303 peer->connect);
17304 /* need special-case handling for changed default values due to
17305 * config profile / version (because there is no "timers bgp connect"
17306 * command, we need to save this per-peer :/)
17307 */
17308 else if (!peer_group_active(peer) && !peer->connect &&
17309 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17310 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17311 peer->bgp->default_connect_retry);
17312
17313 /* timers delayopen */
17314 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17315 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17316 peer->delayopen);
17317 /* Save config even though flag is not set if default values have been
17318 * changed
17319 */
17320 else if (!peer_group_active(peer) && !peer->delayopen
17321 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17322 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17323 peer->bgp->default_delayopen);
17324
17325 /* capability dynamic */
17326 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17327 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17328
17329 /* capability extended-nexthop */
17330 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17331 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17332 !peer->conf_if)
17333 vty_out(vty,
17334 " no neighbor %s capability extended-nexthop\n",
17335 addr);
17336 else if (!peer->conf_if)
17337 vty_out(vty,
17338 " neighbor %s capability extended-nexthop\n",
17339 addr);
17340 }
17341
17342 /* dont-capability-negotiation */
17343 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17344 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17345
17346 /* override-capability */
17347 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17348 vty_out(vty, " neighbor %s override-capability\n", addr);
17349
17350 /* strict-capability-match */
17351 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17352 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17353
17354 /* Sender side AS path loop detection. */
17355 if (peer->as_path_loop_detection)
17356 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17357 addr);
17358
17359 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17360 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17361
17362 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17363 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17364 vty_out(vty,
17365 " neighbor %s graceful-restart-helper\n", addr);
17366 } else if (CHECK_FLAG(
17367 peer->peer_gr_new_status_flag,
17368 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17369 vty_out(vty,
17370 " neighbor %s graceful-restart\n", addr);
17371 } else if (
17372 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17373 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17374 && !(CHECK_FLAG(
17375 peer->peer_gr_new_status_flag,
17376 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17377 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17378 addr);
17379 }
17380 }
17381 }
17382
17383 /* BGP peer configuration display function. */
17384 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17385 struct peer *peer, afi_t afi, safi_t safi)
17386 {
17387 struct peer *g_peer = NULL;
17388 char *addr;
17389 bool flag_scomm, flag_secomm, flag_slcomm;
17390
17391 /* Skip dynamic neighbors. */
17392 if (peer_dynamic_neighbor(peer))
17393 return;
17394
17395 if (peer->conf_if)
17396 addr = peer->conf_if;
17397 else
17398 addr = peer->host;
17399
17400 /************************************
17401 ****** Per AF to the neighbor ******
17402 ************************************/
17403 if (peer_group_active(peer)) {
17404 g_peer = peer->group->conf;
17405
17406 /* If the peer-group is active but peer is not, print a 'no
17407 * activate' */
17408 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17409 vty_out(vty, " no neighbor %s activate\n", addr);
17410 }
17411
17412 /* If the peer-group is not active but peer is, print an
17413 'activate' */
17414 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17415 vty_out(vty, " neighbor %s activate\n", addr);
17416 }
17417 } else {
17418 if (peer->afc[afi][safi]) {
17419 if (safi == SAFI_ENCAP)
17420 vty_out(vty, " neighbor %s activate\n", addr);
17421 else if (!bgp->default_af[afi][safi])
17422 vty_out(vty, " neighbor %s activate\n", addr);
17423 } else {
17424 if (bgp->default_af[afi][safi])
17425 vty_out(vty, " no neighbor %s activate\n",
17426 addr);
17427 }
17428 }
17429
17430 /* addpath TX knobs */
17431 if (peergroup_af_addpath_check(peer, afi, safi)) {
17432 switch (peer->addpath_type[afi][safi]) {
17433 case BGP_ADDPATH_ALL:
17434 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17435 addr);
17436 break;
17437 case BGP_ADDPATH_BEST_PER_AS:
17438 vty_out(vty,
17439 " neighbor %s addpath-tx-bestpath-per-AS\n",
17440 addr);
17441 break;
17442 case BGP_ADDPATH_MAX:
17443 case BGP_ADDPATH_NONE:
17444 break;
17445 }
17446 }
17447
17448 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17449 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17450
17451 /* ORF capability. */
17452 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17453 || peergroup_af_flag_check(peer, afi, safi,
17454 PEER_FLAG_ORF_PREFIX_RM)) {
17455 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17456
17457 if (peergroup_af_flag_check(peer, afi, safi,
17458 PEER_FLAG_ORF_PREFIX_SM)
17459 && peergroup_af_flag_check(peer, afi, safi,
17460 PEER_FLAG_ORF_PREFIX_RM))
17461 vty_out(vty, " both");
17462 else if (peergroup_af_flag_check(peer, afi, safi,
17463 PEER_FLAG_ORF_PREFIX_SM))
17464 vty_out(vty, " send");
17465 else
17466 vty_out(vty, " receive");
17467 vty_out(vty, "\n");
17468 }
17469
17470 /* Route reflector client. */
17471 if (peergroup_af_flag_check(peer, afi, safi,
17472 PEER_FLAG_REFLECTOR_CLIENT)) {
17473 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17474 }
17475
17476 /* next-hop-self force */
17477 if (peergroup_af_flag_check(peer, afi, safi,
17478 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17479 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17480 }
17481
17482 /* next-hop-self */
17483 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17484 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17485 }
17486
17487 /* remove-private-AS */
17488 if (peergroup_af_flag_check(peer, afi, safi,
17489 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17490 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17491 addr);
17492 }
17493
17494 else if (peergroup_af_flag_check(peer, afi, safi,
17495 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17496 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17497 addr);
17498 }
17499
17500 else if (peergroup_af_flag_check(peer, afi, safi,
17501 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17502 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17503 }
17504
17505 else if (peergroup_af_flag_check(peer, afi, safi,
17506 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17507 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17508 }
17509
17510 /* as-override */
17511 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17512 vty_out(vty, " neighbor %s as-override\n", addr);
17513 }
17514
17515 /* send-community print. */
17516 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17517 PEER_FLAG_SEND_COMMUNITY);
17518 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17519 PEER_FLAG_SEND_EXT_COMMUNITY);
17520 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17521 PEER_FLAG_SEND_LARGE_COMMUNITY);
17522
17523 if (flag_scomm && flag_secomm && flag_slcomm) {
17524 vty_out(vty, " no neighbor %s send-community all\n", addr);
17525 } else {
17526 if (flag_scomm)
17527 vty_out(vty, " no neighbor %s send-community\n", addr);
17528 if (flag_secomm)
17529 vty_out(vty,
17530 " no neighbor %s send-community extended\n",
17531 addr);
17532
17533 if (flag_slcomm)
17534 vty_out(vty, " no neighbor %s send-community large\n",
17535 addr);
17536 }
17537
17538 /* Default information */
17539 if (peergroup_af_flag_check(peer, afi, safi,
17540 PEER_FLAG_DEFAULT_ORIGINATE)) {
17541 vty_out(vty, " neighbor %s default-originate", addr);
17542
17543 if (peer->default_rmap[afi][safi].name)
17544 vty_out(vty, " route-map %s",
17545 peer->default_rmap[afi][safi].name);
17546
17547 vty_out(vty, "\n");
17548 }
17549
17550 /* Soft reconfiguration inbound. */
17551 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17552 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17553 addr);
17554 }
17555
17556 /* maximum-prefix. */
17557 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17558 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17559 peer->pmax[afi][safi]);
17560
17561 if (peer->pmax_threshold[afi][safi]
17562 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17563 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17564 if (peer_af_flag_check(peer, afi, safi,
17565 PEER_FLAG_MAX_PREFIX_WARNING))
17566 vty_out(vty, " warning-only");
17567 if (peer->pmax_restart[afi][safi])
17568 vty_out(vty, " restart %u",
17569 peer->pmax_restart[afi][safi]);
17570 if (peer_af_flag_check(peer, afi, safi,
17571 PEER_FLAG_MAX_PREFIX_FORCE))
17572 vty_out(vty, " force");
17573
17574 vty_out(vty, "\n");
17575 }
17576
17577 /* maximum-prefix-out */
17578 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17579 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17580 addr, peer->pmax_out[afi][safi]);
17581
17582 /* Route server client. */
17583 if (peergroup_af_flag_check(peer, afi, safi,
17584 PEER_FLAG_RSERVER_CLIENT)) {
17585 vty_out(vty, " neighbor %s route-server-client\n", addr);
17586 }
17587
17588 /* Nexthop-local unchanged. */
17589 if (peergroup_af_flag_check(peer, afi, safi,
17590 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17591 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17592 }
17593
17594 /* allowas-in <1-10> */
17595 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17596 if (peer_af_flag_check(peer, afi, safi,
17597 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17598 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17599 } else if (peer->allowas_in[afi][safi] == 3) {
17600 vty_out(vty, " neighbor %s allowas-in\n", addr);
17601 } else {
17602 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17603 peer->allowas_in[afi][safi]);
17604 }
17605 }
17606
17607 /* accept-own */
17608 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17609 vty_out(vty, " neighbor %s accept-own\n", addr);
17610
17611 /* soo */
17612 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17613 char *soo_str = ecommunity_ecom2str(
17614 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17615
17616 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17617 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17618 }
17619
17620 /* weight */
17621 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17622 vty_out(vty, " neighbor %s weight %lu\n", addr,
17623 peer->weight[afi][safi]);
17624
17625 /* Filter. */
17626 bgp_config_write_filter(vty, peer, afi, safi);
17627
17628 /* atribute-unchanged. */
17629 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17630 || (safi != SAFI_EVPN
17631 && peer_af_flag_check(peer, afi, safi,
17632 PEER_FLAG_NEXTHOP_UNCHANGED))
17633 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17634
17635 if (!peer_group_active(peer)
17636 || peergroup_af_flag_check(peer, afi, safi,
17637 PEER_FLAG_AS_PATH_UNCHANGED)
17638 || peergroup_af_flag_check(peer, afi, safi,
17639 PEER_FLAG_NEXTHOP_UNCHANGED)
17640 || peergroup_af_flag_check(peer, afi, safi,
17641 PEER_FLAG_MED_UNCHANGED)) {
17642
17643 vty_out(vty,
17644 " neighbor %s attribute-unchanged%s%s%s\n",
17645 addr,
17646 peer_af_flag_check(peer, afi, safi,
17647 PEER_FLAG_AS_PATH_UNCHANGED)
17648 ? " as-path"
17649 : "",
17650 peer_af_flag_check(peer, afi, safi,
17651 PEER_FLAG_NEXTHOP_UNCHANGED)
17652 ? " next-hop"
17653 : "",
17654 peer_af_flag_check(peer, afi, safi,
17655 PEER_FLAG_MED_UNCHANGED)
17656 ? " med"
17657 : "");
17658 }
17659 }
17660
17661 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_ORR_GROUP))
17662 vty_out(vty, " neighbor %s optimal-route-reflection %s\n",
17663 addr, peer->orr_group_name[afi][safi]);
17664 }
17665
17666 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17667 safi_t safi)
17668 {
17669 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17670 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17671 vty_out(vty, " no bgp retain route-target all\n");
17672 }
17673
17674 /* Address family based peer configuration display. */
17675 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17676 safi_t safi)
17677 {
17678 struct peer *peer;
17679 struct peer_group *group;
17680 struct listnode *node, *nnode;
17681
17682
17683 vty_frame(vty, " !\n address-family ");
17684 if (afi == AFI_IP) {
17685 if (safi == SAFI_UNICAST)
17686 vty_frame(vty, "ipv4 unicast");
17687 else if (safi == SAFI_LABELED_UNICAST)
17688 vty_frame(vty, "ipv4 labeled-unicast");
17689 else if (safi == SAFI_MULTICAST)
17690 vty_frame(vty, "ipv4 multicast");
17691 else if (safi == SAFI_MPLS_VPN)
17692 vty_frame(vty, "ipv4 vpn");
17693 else if (safi == SAFI_ENCAP)
17694 vty_frame(vty, "ipv4 encap");
17695 else if (safi == SAFI_FLOWSPEC)
17696 vty_frame(vty, "ipv4 flowspec");
17697 } else if (afi == AFI_IP6) {
17698 if (safi == SAFI_UNICAST)
17699 vty_frame(vty, "ipv6 unicast");
17700 else if (safi == SAFI_LABELED_UNICAST)
17701 vty_frame(vty, "ipv6 labeled-unicast");
17702 else if (safi == SAFI_MULTICAST)
17703 vty_frame(vty, "ipv6 multicast");
17704 else if (safi == SAFI_MPLS_VPN)
17705 vty_frame(vty, "ipv6 vpn");
17706 else if (safi == SAFI_ENCAP)
17707 vty_frame(vty, "ipv6 encap");
17708 else if (safi == SAFI_FLOWSPEC)
17709 vty_frame(vty, "ipv6 flowspec");
17710 } else if (afi == AFI_L2VPN) {
17711 if (safi == SAFI_EVPN)
17712 vty_frame(vty, "l2vpn evpn");
17713 }
17714 vty_frame(vty, "\n");
17715
17716 bgp_config_write_distance(vty, bgp, afi, safi);
17717
17718 bgp_config_write_network(vty, bgp, afi, safi);
17719
17720 bgp_config_write_redistribute(vty, bgp, afi, safi);
17721
17722 /* BGP flag dampening. */
17723 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17724 bgp_config_write_damp(vty, afi, safi);
17725
17726 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17727 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17728
17729 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17730 /* Do not display doppelganger peers */
17731 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17732 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17733 }
17734
17735 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17736 bgp_config_write_table_map(vty, bgp, afi, safi);
17737
17738 if (safi == SAFI_EVPN)
17739 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17740
17741 if (safi == SAFI_FLOWSPEC)
17742 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17743
17744 if (safi == SAFI_MPLS_VPN)
17745 bgp_vpn_config_write(vty, bgp, afi, safi);
17746
17747 if (safi == SAFI_UNICAST) {
17748 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17749 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17750 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17751
17752 vty_out(vty, " export vpn\n");
17753 }
17754 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17755 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17756
17757 vty_out(vty, " import vpn\n");
17758 }
17759 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17760 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17761 char *name;
17762
17763 for (ALL_LIST_ELEMENTS_RO(
17764 bgp->vpn_policy[afi].import_vrf, node,
17765 name))
17766 vty_out(vty, " import vrf %s\n", name);
17767 }
17768 }
17769
17770 /* Optimal Route Reflection */
17771 bgp_config_write_orr(vty, bgp, afi, safi);
17772
17773 vty_endframe(vty, " exit-address-family\n");
17774 }
17775
17776 int bgp_config_write(struct vty *vty)
17777 {
17778 struct bgp *bgp;
17779 struct peer_group *group;
17780 struct peer *peer;
17781 struct listnode *node, *nnode;
17782 struct listnode *mnode, *mnnode;
17783 afi_t afi;
17784 safi_t safi;
17785 uint32_t tovpn_sid_index = 0;
17786
17787 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17788 vty_out(vty, "bgp route-map delay-timer %u\n",
17789 bm->rmap_update_timer);
17790
17791 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17792 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17793 if (bm->v_update_delay != bm->v_establish_wait)
17794 vty_out(vty, " %d", bm->v_establish_wait);
17795 vty_out(vty, "\n");
17796 }
17797
17798 if (bm->wait_for_fib)
17799 vty_out(vty, "bgp suppress-fib-pending\n");
17800
17801 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17802 vty_out(vty, "bgp graceful-shutdown\n");
17803
17804 /* No-RIB (Zebra) option flag configuration */
17805 if (bgp_option_check(BGP_OPT_NO_FIB))
17806 vty_out(vty, "bgp no-rib\n");
17807
17808 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17809 vty_out(vty, "bgp send-extra-data zebra\n");
17810
17811 /* BGP session DSCP value */
17812 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17813 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17814
17815 /* BGP InQ limit */
17816 if (bm->inq_limit != BM_DEFAULT_INQ_LIMIT)
17817 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17818
17819 /* BGP configuration. */
17820 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17821
17822 /* skip all auto created vrf as they dont have user config */
17823 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17824 continue;
17825
17826 /* Router bgp ASN */
17827 vty_out(vty, "router bgp %u", bgp->as);
17828
17829 if (bgp->name)
17830 vty_out(vty, " %s %s",
17831 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17832 ? "view" : "vrf", bgp->name);
17833 vty_out(vty, "\n");
17834
17835 /* BGP fast-external-failover. */
17836 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17837 vty_out(vty, " no bgp fast-external-failover\n");
17838
17839 /* BGP router ID. */
17840 if (bgp->router_id_static.s_addr != INADDR_ANY)
17841 vty_out(vty, " bgp router-id %pI4\n",
17842 &bgp->router_id_static);
17843
17844 /* Suppress fib pending */
17845 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17846 vty_out(vty, " bgp suppress-fib-pending\n");
17847
17848 /* BGP log-neighbor-changes. */
17849 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17850 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17851 vty_out(vty, " %sbgp log-neighbor-changes\n",
17852 CHECK_FLAG(bgp->flags,
17853 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17854 ? ""
17855 : "no ");
17856
17857 /* BGP configuration. */
17858 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17859 vty_out(vty, " bgp always-compare-med\n");
17860
17861 /* RFC8212 default eBGP policy. */
17862 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17863 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17864 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17865 CHECK_FLAG(bgp->flags,
17866 BGP_FLAG_EBGP_REQUIRES_POLICY)
17867 ? ""
17868 : "no ");
17869
17870 /* draft-ietf-idr-deprecate-as-set-confed-set */
17871 if (bgp->reject_as_sets)
17872 vty_out(vty, " bgp reject-as-sets\n");
17873
17874 /* Suppress duplicate updates if the route actually not changed
17875 */
17876 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17877 != SAVE_BGP_SUPPRESS_DUPLICATES)
17878 vty_out(vty, " %sbgp suppress-duplicates\n",
17879 CHECK_FLAG(bgp->flags,
17880 BGP_FLAG_SUPPRESS_DUPLICATES)
17881 ? ""
17882 : "no ");
17883
17884 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17885 */
17886 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17887 SAVE_BGP_HARD_ADMIN_RESET)
17888 vty_out(vty, " %sbgp hard-administrative-reset\n",
17889 CHECK_FLAG(bgp->flags,
17890 BGP_FLAG_HARD_ADMIN_RESET)
17891 ? ""
17892 : "no ");
17893
17894 /* BGP default <afi>-<safi> */
17895 FOREACH_AFI_SAFI (afi, safi) {
17896 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17897 if (!bgp->default_af[afi][safi])
17898 vty_out(vty, " no bgp default %s\n",
17899 get_bgp_default_af_flag(afi,
17900 safi));
17901 } else if (bgp->default_af[afi][safi])
17902 vty_out(vty, " bgp default %s\n",
17903 get_bgp_default_af_flag(afi, safi));
17904 }
17905
17906 /* BGP default local-preference. */
17907 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17908 vty_out(vty, " bgp default local-preference %u\n",
17909 bgp->default_local_pref);
17910
17911 /* BGP default show-hostname */
17912 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17913 != SAVE_BGP_SHOW_HOSTNAME)
17914 vty_out(vty, " %sbgp default show-hostname\n",
17915 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17916 ? ""
17917 : "no ");
17918
17919 /* BGP default show-nexthop-hostname */
17920 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17921 != SAVE_BGP_SHOW_HOSTNAME)
17922 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17923 CHECK_FLAG(bgp->flags,
17924 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17925 ? ""
17926 : "no ");
17927
17928 /* BGP default subgroup-pkt-queue-max. */
17929 if (bgp->default_subgroup_pkt_queue_max
17930 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17931 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17932 bgp->default_subgroup_pkt_queue_max);
17933
17934 /* BGP client-to-client reflection. */
17935 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17936 vty_out(vty, " no bgp client-to-client reflection\n");
17937
17938 /* BGP cluster ID. */
17939 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17940 vty_out(vty, " bgp cluster-id %pI4\n",
17941 &bgp->cluster_id);
17942
17943 /* Disable ebgp connected nexthop check */
17944 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17945 vty_out(vty,
17946 " bgp disable-ebgp-connected-route-check\n");
17947
17948 /* Confederation identifier*/
17949 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17950 vty_out(vty, " bgp confederation identifier %u\n",
17951 bgp->confed_id);
17952
17953 /* Confederation peer */
17954 if (bgp->confed_peers_cnt > 0) {
17955 int i;
17956
17957 vty_out(vty, " bgp confederation peers");
17958
17959 for (i = 0; i < bgp->confed_peers_cnt; i++)
17960 vty_out(vty, " %u", bgp->confed_peers[i]);
17961
17962 vty_out(vty, "\n");
17963 }
17964
17965 /* BGP deterministic-med. */
17966 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17967 != SAVE_BGP_DETERMINISTIC_MED)
17968 vty_out(vty, " %sbgp deterministic-med\n",
17969 CHECK_FLAG(bgp->flags,
17970 BGP_FLAG_DETERMINISTIC_MED)
17971 ? ""
17972 : "no ");
17973
17974 /* BGP update-delay. */
17975 bgp_config_write_update_delay(vty, bgp);
17976
17977 if (bgp->v_maxmed_onstartup
17978 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17979 vty_out(vty, " bgp max-med on-startup %u",
17980 bgp->v_maxmed_onstartup);
17981 if (bgp->maxmed_onstartup_value
17982 != BGP_MAXMED_VALUE_DEFAULT)
17983 vty_out(vty, " %u",
17984 bgp->maxmed_onstartup_value);
17985 vty_out(vty, "\n");
17986 }
17987 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17988 vty_out(vty, " bgp max-med administrative");
17989 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17990 vty_out(vty, " %u", bgp->maxmed_admin_value);
17991 vty_out(vty, "\n");
17992 }
17993
17994 /* write quanta */
17995 bgp_config_write_wpkt_quanta(vty, bgp);
17996 /* read quanta */
17997 bgp_config_write_rpkt_quanta(vty, bgp);
17998
17999 /* coalesce time */
18000 bgp_config_write_coalesce_time(vty, bgp);
18001
18002 /* BGP per-instance graceful-shutdown */
18003 /* BGP-wide settings and per-instance settings are mutually
18004 * exclusive.
18005 */
18006 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18007 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18008 vty_out(vty, " bgp graceful-shutdown\n");
18009
18010 /* Long-lived Graceful Restart */
18011 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18012 vty_out(vty,
18013 " bgp long-lived-graceful-restart stale-time %u\n",
18014 bgp->llgr_stale_time);
18015
18016 /* BGP graceful-restart. */
18017 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18018 vty_out(vty,
18019 " bgp graceful-restart stalepath-time %u\n",
18020 bgp->stalepath_time);
18021
18022 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18023 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18024 bgp->restart_time);
18025
18026 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18027 SAVE_BGP_GRACEFUL_NOTIFICATION)
18028 vty_out(vty, " %sbgp graceful-restart notification\n",
18029 CHECK_FLAG(bgp->flags,
18030 BGP_FLAG_GRACEFUL_NOTIFICATION)
18031 ? ""
18032 : "no ");
18033
18034 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18035 vty_out(vty,
18036 " bgp graceful-restart select-defer-time %u\n",
18037 bgp->select_defer_time);
18038
18039 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18040 vty_out(vty, " bgp graceful-restart\n");
18041
18042 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18043 vty_out(vty, " bgp graceful-restart-disable\n");
18044
18045 /* BGP graceful-restart Preserve State F bit. */
18046 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18047 vty_out(vty,
18048 " bgp graceful-restart preserve-fw-state\n");
18049
18050 /* BGP TCP keepalive */
18051 bgp_config_tcp_keepalive(vty, bgp);
18052
18053 /* Stale timer for RIB */
18054 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18055 vty_out(vty,
18056 " bgp graceful-restart rib-stale-time %u\n",
18057 bgp->rib_stale_time);
18058
18059 /* BGP bestpath method. */
18060 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18061 vty_out(vty, " bgp bestpath as-path ignore\n");
18062 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18063 vty_out(vty, " bgp bestpath as-path confed\n");
18064
18065 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18066 if (CHECK_FLAG(bgp->flags,
18067 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18068 vty_out(vty,
18069 " bgp bestpath as-path multipath-relax as-set\n");
18070 } else {
18071 vty_out(vty,
18072 " bgp bestpath as-path multipath-relax\n");
18073 }
18074 }
18075
18076 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18077 vty_out(vty,
18078 " bgp route-reflector allow-outbound-policy\n");
18079 }
18080 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18081 vty_out(vty, " bgp bestpath compare-routerid\n");
18082 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18083 vty_out(vty, " bgp bestpath aigp\n");
18084 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18085 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18086 vty_out(vty, " bgp bestpath med");
18087 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18088 vty_out(vty, " confed");
18089 if (CHECK_FLAG(bgp->flags,
18090 BGP_FLAG_MED_MISSING_AS_WORST))
18091 vty_out(vty, " missing-as-worst");
18092 vty_out(vty, "\n");
18093 }
18094
18095 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18096 vty_out(vty,
18097 " bgp bestpath peer-type multipath-relax\n");
18098
18099 /* Link bandwidth handling. */
18100 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18101 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18102 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18103 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18104 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18105 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18106
18107 /* BGP network import check. */
18108 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18109 != SAVE_BGP_IMPORT_CHECK)
18110 vty_out(vty, " %sbgp network import-check\n",
18111 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18112 ? ""
18113 : "no ");
18114
18115 /* BGP timers configuration. */
18116 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18117 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18118 vty_out(vty, " timers bgp %u %u\n",
18119 bgp->default_keepalive, bgp->default_holdtime);
18120
18121 /* BGP minimum holdtime configuration. */
18122 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18123 && bgp->default_min_holdtime != 0)
18124 vty_out(vty, " bgp minimum-holdtime %u\n",
18125 bgp->default_min_holdtime);
18126
18127 /* Conditional advertisement timer configuration */
18128 if (bgp->condition_check_period
18129 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18130 vty_out(vty,
18131 " bgp conditional-advertisement timer %u\n",
18132 bgp->condition_check_period);
18133
18134 /* peer-group */
18135 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18136 bgp_config_write_peer_global(vty, bgp, group->conf);
18137 }
18138
18139 /* Normal neighbor configuration. */
18140 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18141 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18142 bgp_config_write_peer_global(vty, bgp, peer);
18143 }
18144
18145 /* listen range and limit for dynamic BGP neighbors */
18146 bgp_config_write_listen(vty, bgp);
18147
18148 /*
18149 * BGP default autoshutdown neighbors
18150 *
18151 * This must be placed after any peer and peer-group
18152 * configuration, to avoid setting all peers to shutdown after
18153 * a daemon restart, which is undesired behavior. (see #2286)
18154 */
18155 if (bgp->autoshutdown)
18156 vty_out(vty, " bgp default shutdown\n");
18157
18158 /* BGP instance administrative shutdown */
18159 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18160 vty_out(vty, " bgp shutdown\n");
18161
18162 if (bgp->allow_martian)
18163 vty_out(vty, " bgp allow-martian-nexthop\n");
18164
18165 if (bgp->fast_convergence)
18166 vty_out(vty, " bgp fast-convergence\n");
18167
18168 if (bgp->srv6_enabled) {
18169 vty_frame(vty, " !\n segment-routing srv6\n");
18170 if (strlen(bgp->srv6_locator_name))
18171 vty_out(vty, " locator %s\n",
18172 bgp->srv6_locator_name);
18173 vty_endframe(vty, " exit\n");
18174 }
18175
18176 tovpn_sid_index = bgp->tovpn_sid_index;
18177 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18178 vty_out(vty, " sid vpn per-vrf export auto\n");
18179 } else if (tovpn_sid_index != 0) {
18180 vty_out(vty, " sid vpn per-vrf export %d\n",
18181 tovpn_sid_index);
18182 }
18183
18184 /* IPv4 unicast configuration. */
18185 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18186
18187 /* IPv4 multicast configuration. */
18188 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18189
18190 /* IPv4 labeled-unicast configuration. */
18191 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18192
18193 /* IPv4 VPN configuration. */
18194 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18195
18196 /* ENCAPv4 configuration. */
18197 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18198
18199 /* FLOWSPEC v4 configuration. */
18200 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18201
18202 /* IPv6 unicast configuration. */
18203 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18204
18205 /* IPv6 multicast configuration. */
18206 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18207
18208 /* IPv6 labeled-unicast configuration. */
18209 bgp_config_write_family(vty, bgp, AFI_IP6,
18210 SAFI_LABELED_UNICAST);
18211
18212 /* IPv6 VPN configuration. */
18213 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18214
18215 /* ENCAPv6 configuration. */
18216 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18217
18218 /* FLOWSPEC v6 configuration. */
18219 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18220
18221 /* EVPN configuration. */
18222 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18223
18224 hook_call(bgp_inst_config_write, bgp, vty);
18225
18226 #ifdef ENABLE_BGP_VNC
18227 bgp_rfapi_cfg_write(vty, bgp);
18228 #endif
18229
18230 vty_out(vty, "exit\n");
18231 vty_out(vty, "!\n");
18232 }
18233 return 0;
18234 }
18235
18236
18237 /* BGP node structure. */
18238 static struct cmd_node bgp_node = {
18239 .name = "bgp",
18240 .node = BGP_NODE,
18241 .parent_node = CONFIG_NODE,
18242 .prompt = "%s(config-router)# ",
18243 .config_write = bgp_config_write,
18244 };
18245
18246 static struct cmd_node bgp_ipv4_unicast_node = {
18247 .name = "bgp ipv4 unicast",
18248 .node = BGP_IPV4_NODE,
18249 .parent_node = BGP_NODE,
18250 .prompt = "%s(config-router-af)# ",
18251 .no_xpath = true,
18252 };
18253
18254 static struct cmd_node bgp_ipv4_multicast_node = {
18255 .name = "bgp ipv4 multicast",
18256 .node = BGP_IPV4M_NODE,
18257 .parent_node = BGP_NODE,
18258 .prompt = "%s(config-router-af)# ",
18259 .no_xpath = true,
18260 };
18261
18262 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18263 .name = "bgp ipv4 labeled unicast",
18264 .node = BGP_IPV4L_NODE,
18265 .parent_node = BGP_NODE,
18266 .prompt = "%s(config-router-af)# ",
18267 .no_xpath = true,
18268 };
18269
18270 static struct cmd_node bgp_ipv6_unicast_node = {
18271 .name = "bgp ipv6 unicast",
18272 .node = BGP_IPV6_NODE,
18273 .parent_node = BGP_NODE,
18274 .prompt = "%s(config-router-af)# ",
18275 .no_xpath = true,
18276 };
18277
18278 static struct cmd_node bgp_ipv6_multicast_node = {
18279 .name = "bgp ipv6 multicast",
18280 .node = BGP_IPV6M_NODE,
18281 .parent_node = BGP_NODE,
18282 .prompt = "%s(config-router-af)# ",
18283 .no_xpath = true,
18284 };
18285
18286 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18287 .name = "bgp ipv6 labeled unicast",
18288 .node = BGP_IPV6L_NODE,
18289 .parent_node = BGP_NODE,
18290 .prompt = "%s(config-router-af)# ",
18291 .no_xpath = true,
18292 };
18293
18294 static struct cmd_node bgp_vpnv4_node = {
18295 .name = "bgp vpnv4",
18296 .node = BGP_VPNV4_NODE,
18297 .parent_node = BGP_NODE,
18298 .prompt = "%s(config-router-af)# ",
18299 .no_xpath = true,
18300 };
18301
18302 static struct cmd_node bgp_vpnv6_node = {
18303 .name = "bgp vpnv6",
18304 .node = BGP_VPNV6_NODE,
18305 .parent_node = BGP_NODE,
18306 .prompt = "%s(config-router-af-vpnv6)# ",
18307 .no_xpath = true,
18308 };
18309
18310 static struct cmd_node bgp_evpn_node = {
18311 .name = "bgp evpn",
18312 .node = BGP_EVPN_NODE,
18313 .parent_node = BGP_NODE,
18314 .prompt = "%s(config-router-evpn)# ",
18315 .no_xpath = true,
18316 };
18317
18318 static struct cmd_node bgp_evpn_vni_node = {
18319 .name = "bgp evpn vni",
18320 .node = BGP_EVPN_VNI_NODE,
18321 .parent_node = BGP_EVPN_NODE,
18322 .prompt = "%s(config-router-af-vni)# ",
18323 };
18324
18325 static struct cmd_node bgp_flowspecv4_node = {
18326 .name = "bgp ipv4 flowspec",
18327 .node = BGP_FLOWSPECV4_NODE,
18328 .parent_node = BGP_NODE,
18329 .prompt = "%s(config-router-af)# ",
18330 .no_xpath = true,
18331 };
18332
18333 static struct cmd_node bgp_flowspecv6_node = {
18334 .name = "bgp ipv6 flowspec",
18335 .node = BGP_FLOWSPECV6_NODE,
18336 .parent_node = BGP_NODE,
18337 .prompt = "%s(config-router-af-vpnv6)# ",
18338 .no_xpath = true,
18339 };
18340
18341 static struct cmd_node bgp_srv6_node = {
18342 .name = "bgp srv6",
18343 .node = BGP_SRV6_NODE,
18344 .parent_node = BGP_NODE,
18345 .prompt = "%s(config-router-srv6)# ",
18346 };
18347
18348 static void community_list_vty(void);
18349
18350 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18351 {
18352 struct bgp *bgp;
18353 struct peer_group *group;
18354 struct listnode *lnbgp, *lnpeer;
18355
18356 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18357 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18358 vector_set(comps,
18359 XSTRDUP(MTYPE_COMPLETION, group->name));
18360 }
18361 }
18362
18363 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18364 {
18365 struct bgp *bgp;
18366 struct peer *peer;
18367 struct listnode *lnbgp, *lnpeer;
18368
18369 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18370 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18371 /* only provide suggestions on the appropriate input
18372 * token type,
18373 * they'll otherwise show up multiple times */
18374 enum cmd_token_type match_type;
18375 char *name = peer->host;
18376
18377 if (peer->conf_if) {
18378 match_type = VARIABLE_TKN;
18379 name = peer->conf_if;
18380 } else if (strchr(peer->host, ':'))
18381 match_type = IPV6_TKN;
18382 else
18383 match_type = IPV4_TKN;
18384
18385 if (token->type != match_type)
18386 continue;
18387
18388 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18389 }
18390 }
18391 }
18392
18393 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18394 {
18395 bgp_ac_peer(comps, token);
18396
18397 if (token->type == VARIABLE_TKN)
18398 bgp_ac_peergroup(comps, token);
18399 }
18400
18401 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18402 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18403 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18404 {.varname = "peer", .completions = bgp_ac_neighbor},
18405 {.completions = NULL}};
18406
18407 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18408 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18409 {.completions = NULL} };
18410
18411 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18412
18413 static struct thread *t_bgp_cfg;
18414
18415 bool bgp_config_inprocess(void)
18416 {
18417 return thread_is_scheduled(t_bgp_cfg);
18418 }
18419
18420 static void bgp_config_finish(struct thread *t)
18421 {
18422 struct listnode *node;
18423 struct bgp *bgp;
18424
18425 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18426 hook_call(bgp_config_end, bgp);
18427 }
18428
18429 static void bgp_config_start(void)
18430 {
18431 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18432 THREAD_OFF(t_bgp_cfg);
18433 thread_add_timer(bm->master, bgp_config_finish, NULL,
18434 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18435 }
18436
18437 /* When we receive a hook the configuration is read,
18438 * we start a timer to make sure we postpone sending
18439 * EoR before route-maps are processed.
18440 * This is especially valid if using `bgp route-map delay-timer`.
18441 */
18442 static void bgp_config_end(void)
18443 {
18444 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18445 uint32_t bgp_post_config_delay =
18446 thread_is_scheduled(bm->t_rmap_update)
18447 ? thread_timer_remain_second(bm->t_rmap_update)
18448 : BGP_POST_CONFIG_DELAY_SECONDS;
18449
18450 /* If BGP config processing thread isn't running, then
18451 * we can return and rely it's properly handled.
18452 */
18453 if (!bgp_config_inprocess())
18454 return;
18455
18456 THREAD_OFF(t_bgp_cfg);
18457
18458 /* Start a new timer to make sure we don't send EoR
18459 * before route-maps are processed.
18460 */
18461 thread_add_timer(bm->master, bgp_config_finish, NULL,
18462 bgp_post_config_delay, &t_bgp_cfg);
18463 }
18464
18465 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18466 {
18467 int write = 0;
18468 struct interface *ifp;
18469 struct bgp_interface *iifp;
18470
18471 FOR_ALL_INTERFACES (vrf, ifp) {
18472 iifp = ifp->info;
18473 if (!iifp)
18474 continue;
18475
18476 if_vty_config_start(vty, ifp);
18477
18478 if (CHECK_FLAG(iifp->flags,
18479 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18480 vty_out(vty, " mpls bgp forwarding\n");
18481 write++;
18482 }
18483
18484 if_vty_config_end(vty);
18485 }
18486
18487 return write;
18488 }
18489
18490 /* Configuration write function for bgpd. */
18491 static int config_write_interface(struct vty *vty)
18492 {
18493 int write = 0;
18494 struct vrf *vrf = NULL;
18495
18496 /* Display all VRF aware OSPF interface configuration */
18497 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18498 write += config_write_interface_one(vty, vrf);
18499 }
18500
18501 return write;
18502 }
18503
18504 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18505 "[no$no] mpls bgp forwarding",
18506 NO_STR MPLS_STR BGP_STR
18507 "Enable MPLS forwarding for eBGP directly connected peers\n")
18508 {
18509 bool check;
18510 struct bgp_interface *iifp;
18511
18512 VTY_DECLVAR_CONTEXT(interface, ifp);
18513 iifp = ifp->info;
18514 if (!iifp) {
18515 vty_out(vty, "Interface %s not available\n", ifp->name);
18516 return CMD_WARNING_CONFIG_FAILED;
18517 }
18518 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18519 if (check != !no) {
18520 if (no)
18521 UNSET_FLAG(iifp->flags,
18522 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18523 else
18524 SET_FLAG(iifp->flags,
18525 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18526 /* trigger a nht update on eBGP sessions */
18527 if (if_is_operative(ifp))
18528 bgp_nht_ifp_up(ifp);
18529 }
18530 return CMD_SUCCESS;
18531 }
18532
18533 DEFPY (bgp_inq_limit,
18534 bgp_inq_limit_cmd,
18535 "bgp input-queue-limit (1-4294967295)$limit",
18536 BGP_STR
18537 "Set the BGP Input Queue limit for all peers when message parsing\n"
18538 "Input-Queue limit\n")
18539 {
18540 bm->inq_limit = limit;
18541
18542 return CMD_SUCCESS;
18543 }
18544
18545 DEFPY (no_bgp_inq_limit,
18546 no_bgp_inq_limit_cmd,
18547 "no bgp input-queue-limit [(1-4294967295)$limit]",
18548 NO_STR
18549 BGP_STR
18550 "Set the BGP Input Queue limit for all peers when message parsing\n"
18551 "Input-Queue limit\n")
18552 {
18553 bm->inq_limit = BM_DEFAULT_INQ_LIMIT;
18554
18555 return CMD_SUCCESS;
18556 }
18557
18558 /* Initialization of BGP interface. */
18559 static void bgp_vty_if_init(void)
18560 {
18561 /* Install interface node. */
18562 if_cmd_init(config_write_interface);
18563
18564 /* "mpls bgp forwarding" commands. */
18565 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18566 }
18567
18568 void bgp_vty_init(void)
18569 {
18570 cmd_variable_handler_register(bgp_var_neighbor);
18571 cmd_variable_handler_register(bgp_var_peergroup);
18572
18573 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18574
18575 /* Install bgp top node. */
18576 install_node(&bgp_node);
18577 install_node(&bgp_ipv4_unicast_node);
18578 install_node(&bgp_ipv4_multicast_node);
18579 install_node(&bgp_ipv4_labeled_unicast_node);
18580 install_node(&bgp_ipv6_unicast_node);
18581 install_node(&bgp_ipv6_multicast_node);
18582 install_node(&bgp_ipv6_labeled_unicast_node);
18583 install_node(&bgp_vpnv4_node);
18584 install_node(&bgp_vpnv6_node);
18585 install_node(&bgp_evpn_node);
18586 install_node(&bgp_evpn_vni_node);
18587 install_node(&bgp_flowspecv4_node);
18588 install_node(&bgp_flowspecv6_node);
18589 install_node(&bgp_srv6_node);
18590
18591 /* Install default VTY commands to new nodes. */
18592 install_default(BGP_NODE);
18593 install_default(BGP_IPV4_NODE);
18594 install_default(BGP_IPV4M_NODE);
18595 install_default(BGP_IPV4L_NODE);
18596 install_default(BGP_IPV6_NODE);
18597 install_default(BGP_IPV6M_NODE);
18598 install_default(BGP_IPV6L_NODE);
18599 install_default(BGP_VPNV4_NODE);
18600 install_default(BGP_VPNV6_NODE);
18601 install_default(BGP_FLOWSPECV4_NODE);
18602 install_default(BGP_FLOWSPECV6_NODE);
18603 install_default(BGP_EVPN_NODE);
18604 install_default(BGP_EVPN_VNI_NODE);
18605 install_default(BGP_SRV6_NODE);
18606
18607 /* "global bgp inq-limit command */
18608 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18609 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18610
18611 /* "bgp local-mac" hidden commands. */
18612 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18613 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18614
18615 /* "bgp suppress-fib-pending" global */
18616 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18617
18618 /* bgp route-map delay-timer commands. */
18619 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18620 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18621
18622 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18623
18624 /* bgp fast-convergence command */
18625 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18626 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18627
18628 /* global bgp update-delay command */
18629 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18630 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18631
18632 /* global bgp graceful-shutdown command */
18633 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18634 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18635
18636 /* Dummy commands (Currently not supported) */
18637 install_element(BGP_NODE, &no_synchronization_cmd);
18638 install_element(BGP_NODE, &no_auto_summary_cmd);
18639
18640 /* "router bgp" commands. */
18641 install_element(CONFIG_NODE, &router_bgp_cmd);
18642
18643 /* "no router bgp" commands. */
18644 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18645
18646 /* "bgp session-dscp command */
18647 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18648 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18649
18650 /* "bgp router-id" commands. */
18651 install_element(BGP_NODE, &bgp_router_id_cmd);
18652 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18653
18654 /* "bgp suppress-fib-pending" command */
18655 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18656
18657 /* "bgp cluster-id" commands. */
18658 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18659 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18660
18661 /* "bgp no-rib" commands. */
18662 install_element(CONFIG_NODE, &bgp_norib_cmd);
18663 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18664
18665 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18666
18667 /* "bgp confederation" commands. */
18668 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18669 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18670
18671 /* "bgp confederation peers" commands. */
18672 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18673 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18674
18675 /* bgp max-med command */
18676 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18677 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18678 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18679 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18680 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18681
18682 /* "neighbor role" commands. */
18683 install_element(BGP_NODE, &neighbor_role_cmd);
18684 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18685 install_element(BGP_NODE, &no_neighbor_role_cmd);
18686
18687 /* "neighbor aigp" commands. */
18688 install_element(BGP_NODE, &neighbor_aigp_cmd);
18689
18690 /* "neighbor graceful-shutdown" command */
18691 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18692
18693 /* bgp disable-ebgp-connected-nh-check */
18694 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18695 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18696
18697 /* bgp update-delay command */
18698 install_element(BGP_NODE, &bgp_update_delay_cmd);
18699 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18700
18701 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18702 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18703
18704 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18705 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18706
18707 /* "maximum-paths" commands. */
18708 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18709 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18710 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18711 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18712 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18713 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18714 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18715 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18716 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18717 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18718 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18719 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18720 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18721 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18722 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18723
18724 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18725 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18726 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18727 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18728 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18729 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18730 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18731 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18732 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18733 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18734
18735 /* "timers bgp" commands. */
18736 install_element(BGP_NODE, &bgp_timers_cmd);
18737 install_element(BGP_NODE, &no_bgp_timers_cmd);
18738
18739 /* "minimum-holdtime" commands. */
18740 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18741 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18742
18743 /* route-map delay-timer commands - per instance for backwards compat.
18744 */
18745 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18746 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18747
18748 /* "bgp client-to-client reflection" commands */
18749 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18750 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18751
18752 /* "bgp always-compare-med" commands */
18753 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18754 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18755
18756 /* bgp ebgp-requires-policy */
18757 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18758 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18759
18760 /* bgp suppress-duplicates */
18761 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18762 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18763
18764 /* bgp reject-as-sets */
18765 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18766 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18767
18768 /* "bgp deterministic-med" commands */
18769 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18770 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18771
18772 /* "bgp graceful-restart" command */
18773 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18774 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18775
18776 /* "bgp graceful-restart-disable" command */
18777 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18778 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18779
18780 /* "neighbor a:b:c:d graceful-restart" command */
18781 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18782 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18783
18784 /* "neighbor a:b:c:d graceful-restart-disable" command */
18785 install_element(BGP_NODE,
18786 &bgp_neighbor_graceful_restart_disable_set_cmd);
18787 install_element(BGP_NODE,
18788 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18789
18790 /* "neighbor a:b:c:d graceful-restart-helper" command */
18791 install_element(BGP_NODE,
18792 &bgp_neighbor_graceful_restart_helper_set_cmd);
18793 install_element(BGP_NODE,
18794 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18795
18796 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18797 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18798 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18799 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18800 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18801 install_element(BGP_NODE,
18802 &no_bgp_graceful_restart_select_defer_time_cmd);
18803 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18804 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18805 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18806
18807 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18808 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18809 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18810 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18811
18812 /* "bgp inq-limit command */
18813 install_element(BGP_NODE, &bgp_inq_limit_cmd);
18814 install_element(BGP_NODE, &no_bgp_inq_limit_cmd);
18815
18816 /* "bgp graceful-shutdown" commands */
18817 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18818 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18819
18820 /* "bgp hard-administrative-reset" commands */
18821 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18822
18823 /* "bgp long-lived-graceful-restart" commands */
18824 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18825 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18826
18827 /* "bgp fast-external-failover" commands */
18828 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18829 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18830
18831 /* "bgp bestpath aigp" commands */
18832 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
18833
18834 /* "bgp bestpath compare-routerid" commands */
18835 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18836 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18837
18838 /* "bgp bestpath as-path ignore" commands */
18839 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18840 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18841
18842 /* "bgp bestpath as-path confed" commands */
18843 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18844 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18845
18846 /* "bgp bestpath as-path multipath-relax" commands */
18847 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18848 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18849
18850 /* "bgp bestpath peer-type multipath-relax" commands */
18851 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18852 install_element(BGP_NODE,
18853 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18854
18855 /* "bgp log-neighbor-changes" commands */
18856 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18857 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18858
18859 /* "bgp bestpath med" commands */
18860 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18861 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18862
18863 /* "bgp bestpath bandwidth" commands */
18864 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18865 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18866
18867 /* "no bgp default <afi>-<safi>" commands. */
18868 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18869
18870 /* "bgp network import-check" commands. */
18871 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18872 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18873 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18874
18875 /* "bgp default local-preference" commands. */
18876 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18877 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18878
18879 /* bgp default show-hostname */
18880 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18881 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18882
18883 /* bgp default show-nexthop-hostname */
18884 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18885 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18886
18887 /* "bgp default subgroup-pkt-queue-max" commands. */
18888 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18889 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18890
18891 /* bgp ibgp-allow-policy-mods command */
18892 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18893 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18894
18895 /* "bgp listen limit" commands. */
18896 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18897 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18898
18899 /* "bgp listen range" commands. */
18900 install_element(BGP_NODE, &bgp_listen_range_cmd);
18901 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18902
18903 /* "bgp default shutdown" command */
18904 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18905
18906 /* "bgp shutdown" commands */
18907 install_element(BGP_NODE, &bgp_shutdown_cmd);
18908 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18909 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18910 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18911
18912 /* "neighbor remote-as" commands. */
18913 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18914 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18915 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18916 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18917 install_element(BGP_NODE,
18918 &neighbor_interface_v6only_config_remote_as_cmd);
18919 install_element(BGP_NODE, &no_neighbor_cmd);
18920 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18921
18922 /* "neighbor peer-group" commands. */
18923 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18924 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18925 install_element(BGP_NODE,
18926 &no_neighbor_interface_peer_group_remote_as_cmd);
18927
18928 /* "neighbor local-as" commands. */
18929 install_element(BGP_NODE, &neighbor_local_as_cmd);
18930 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18931 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18932 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18933
18934 /* "neighbor solo" commands. */
18935 install_element(BGP_NODE, &neighbor_solo_cmd);
18936 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18937
18938 /* "neighbor password" commands. */
18939 install_element(BGP_NODE, &neighbor_password_cmd);
18940 install_element(BGP_NODE, &no_neighbor_password_cmd);
18941
18942 /* "neighbor activate" commands. */
18943 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18944 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18945 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18946 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18947 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18948 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18949 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18950 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18951 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18952 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18953 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18954 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18955
18956 /* "no neighbor activate" commands. */
18957 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18958 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18959 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18960 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18961 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18962 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18963 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18964 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18965 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18966 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18967 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18968 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18969
18970 /* "neighbor peer-group" set commands. */
18971 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18972 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18973 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18974 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18975 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18976 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18977 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18978 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18979 install_element(BGP_FLOWSPECV4_NODE,
18980 &neighbor_set_peer_group_hidden_cmd);
18981 install_element(BGP_FLOWSPECV6_NODE,
18982 &neighbor_set_peer_group_hidden_cmd);
18983
18984 /* "no neighbor peer-group unset" commands. */
18985 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18986 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18987 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18988 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18989 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18990 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18991 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18992 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18993 install_element(BGP_FLOWSPECV4_NODE,
18994 &no_neighbor_set_peer_group_hidden_cmd);
18995 install_element(BGP_FLOWSPECV6_NODE,
18996 &no_neighbor_set_peer_group_hidden_cmd);
18997
18998 /* "neighbor softreconfiguration inbound" commands.*/
18999 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19000 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19001 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19002 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19003 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19004 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19005 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19006 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19007 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19008 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19009 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19010 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19011 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19012 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19013 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19014 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19015 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19016 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19017 install_element(BGP_FLOWSPECV4_NODE,
19018 &neighbor_soft_reconfiguration_cmd);
19019 install_element(BGP_FLOWSPECV4_NODE,
19020 &no_neighbor_soft_reconfiguration_cmd);
19021 install_element(BGP_FLOWSPECV6_NODE,
19022 &neighbor_soft_reconfiguration_cmd);
19023 install_element(BGP_FLOWSPECV6_NODE,
19024 &no_neighbor_soft_reconfiguration_cmd);
19025 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19026 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19027
19028 /* "neighbor attribute-unchanged" commands. */
19029 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19030 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19031 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19032 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19033 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19034 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19035 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19036 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19037 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19038 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19039 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19040 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19041 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19042 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19043 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19044 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19045 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19046 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19047
19048 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19049 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19050
19051 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19052 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19053 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19054 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19055
19056 /* "nexthop-local unchanged" commands */
19057 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19058 install_element(BGP_IPV6_NODE,
19059 &no_neighbor_nexthop_local_unchanged_cmd);
19060
19061 /* "neighbor next-hop-self" commands. */
19062 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19063 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19064 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19065 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19066 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19067 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19068 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19069 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19070 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19071 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19072 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19073 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19074 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19075 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19076 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19077 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19078 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19079 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19080 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19081 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19082
19083 /* "neighbor next-hop-self force" commands. */
19084 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19085 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19086 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19087 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19088 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19089 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19090 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19091 install_element(BGP_IPV4_NODE,
19092 &no_neighbor_nexthop_self_all_hidden_cmd);
19093 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19094 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19095 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19096 install_element(BGP_IPV4M_NODE,
19097 &no_neighbor_nexthop_self_all_hidden_cmd);
19098 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19099 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19100 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19101 install_element(BGP_IPV4L_NODE,
19102 &no_neighbor_nexthop_self_all_hidden_cmd);
19103 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19104 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19105 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19106 install_element(BGP_IPV6_NODE,
19107 &no_neighbor_nexthop_self_all_hidden_cmd);
19108 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19109 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19110 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19111 install_element(BGP_IPV6M_NODE,
19112 &no_neighbor_nexthop_self_all_hidden_cmd);
19113 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19114 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19115 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19116 install_element(BGP_IPV6L_NODE,
19117 &no_neighbor_nexthop_self_all_hidden_cmd);
19118 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19119 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19120 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19121 install_element(BGP_VPNV4_NODE,
19122 &no_neighbor_nexthop_self_all_hidden_cmd);
19123 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19124 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19125 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19126 install_element(BGP_VPNV6_NODE,
19127 &no_neighbor_nexthop_self_all_hidden_cmd);
19128 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19129 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19130
19131 /* "neighbor as-override" commands. */
19132 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19133 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19134 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19135 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19136 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19137 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19138 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19139 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19140 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19141 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19142 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19143 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19144 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19145 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19146 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19147 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19148 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19149 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19150
19151 /* "neighbor remove-private-AS" commands. */
19152 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19153 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19154 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19155 install_element(BGP_NODE,
19156 &no_neighbor_remove_private_as_all_hidden_cmd);
19157 install_element(BGP_NODE,
19158 &neighbor_remove_private_as_replace_as_hidden_cmd);
19159 install_element(BGP_NODE,
19160 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19161 install_element(BGP_NODE,
19162 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19163 install_element(
19164 BGP_NODE,
19165 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19166 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19167 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19168 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19169 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19170 install_element(BGP_IPV4_NODE,
19171 &neighbor_remove_private_as_replace_as_cmd);
19172 install_element(BGP_IPV4_NODE,
19173 &no_neighbor_remove_private_as_replace_as_cmd);
19174 install_element(BGP_IPV4_NODE,
19175 &neighbor_remove_private_as_all_replace_as_cmd);
19176 install_element(BGP_IPV4_NODE,
19177 &no_neighbor_remove_private_as_all_replace_as_cmd);
19178 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19179 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19180 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19181 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19182 install_element(BGP_IPV4M_NODE,
19183 &neighbor_remove_private_as_replace_as_cmd);
19184 install_element(BGP_IPV4M_NODE,
19185 &no_neighbor_remove_private_as_replace_as_cmd);
19186 install_element(BGP_IPV4M_NODE,
19187 &neighbor_remove_private_as_all_replace_as_cmd);
19188 install_element(BGP_IPV4M_NODE,
19189 &no_neighbor_remove_private_as_all_replace_as_cmd);
19190 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19191 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19192 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19193 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19194 install_element(BGP_IPV4L_NODE,
19195 &neighbor_remove_private_as_replace_as_cmd);
19196 install_element(BGP_IPV4L_NODE,
19197 &no_neighbor_remove_private_as_replace_as_cmd);
19198 install_element(BGP_IPV4L_NODE,
19199 &neighbor_remove_private_as_all_replace_as_cmd);
19200 install_element(BGP_IPV4L_NODE,
19201 &no_neighbor_remove_private_as_all_replace_as_cmd);
19202 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19203 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19204 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19205 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19206 install_element(BGP_IPV6_NODE,
19207 &neighbor_remove_private_as_replace_as_cmd);
19208 install_element(BGP_IPV6_NODE,
19209 &no_neighbor_remove_private_as_replace_as_cmd);
19210 install_element(BGP_IPV6_NODE,
19211 &neighbor_remove_private_as_all_replace_as_cmd);
19212 install_element(BGP_IPV6_NODE,
19213 &no_neighbor_remove_private_as_all_replace_as_cmd);
19214 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19215 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19216 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19217 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19218 install_element(BGP_IPV6M_NODE,
19219 &neighbor_remove_private_as_replace_as_cmd);
19220 install_element(BGP_IPV6M_NODE,
19221 &no_neighbor_remove_private_as_replace_as_cmd);
19222 install_element(BGP_IPV6M_NODE,
19223 &neighbor_remove_private_as_all_replace_as_cmd);
19224 install_element(BGP_IPV6M_NODE,
19225 &no_neighbor_remove_private_as_all_replace_as_cmd);
19226 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19227 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19228 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19229 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19230 install_element(BGP_IPV6L_NODE,
19231 &neighbor_remove_private_as_replace_as_cmd);
19232 install_element(BGP_IPV6L_NODE,
19233 &no_neighbor_remove_private_as_replace_as_cmd);
19234 install_element(BGP_IPV6L_NODE,
19235 &neighbor_remove_private_as_all_replace_as_cmd);
19236 install_element(BGP_IPV6L_NODE,
19237 &no_neighbor_remove_private_as_all_replace_as_cmd);
19238 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19239 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19240 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19241 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19242 install_element(BGP_VPNV4_NODE,
19243 &neighbor_remove_private_as_replace_as_cmd);
19244 install_element(BGP_VPNV4_NODE,
19245 &no_neighbor_remove_private_as_replace_as_cmd);
19246 install_element(BGP_VPNV4_NODE,
19247 &neighbor_remove_private_as_all_replace_as_cmd);
19248 install_element(BGP_VPNV4_NODE,
19249 &no_neighbor_remove_private_as_all_replace_as_cmd);
19250 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19251 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19252 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19253 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19254 install_element(BGP_VPNV6_NODE,
19255 &neighbor_remove_private_as_replace_as_cmd);
19256 install_element(BGP_VPNV6_NODE,
19257 &no_neighbor_remove_private_as_replace_as_cmd);
19258 install_element(BGP_VPNV6_NODE,
19259 &neighbor_remove_private_as_all_replace_as_cmd);
19260 install_element(BGP_VPNV6_NODE,
19261 &no_neighbor_remove_private_as_all_replace_as_cmd);
19262
19263 /* "neighbor send-community" commands.*/
19264 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19265 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19266 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19267 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19268 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19269 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19270 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19271 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19272 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19273 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19274 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19275 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19276 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19277 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19278 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19279 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19280 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19281 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19282 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19283 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19284 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19285 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19286 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19287 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19288 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19289 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19290 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19291 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19292 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19293 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19294 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19295 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19296 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19297 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19298 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19299 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19300
19301 /* "neighbor route-reflector" commands.*/
19302 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19303 install_element(BGP_NODE,
19304 &no_neighbor_route_reflector_client_hidden_cmd);
19305 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19306 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19307 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19308 install_element(BGP_IPV4M_NODE,
19309 &no_neighbor_route_reflector_client_cmd);
19310 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19311 install_element(BGP_IPV4L_NODE,
19312 &no_neighbor_route_reflector_client_cmd);
19313 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19314 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19315 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19316 install_element(BGP_IPV6M_NODE,
19317 &no_neighbor_route_reflector_client_cmd);
19318 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19319 install_element(BGP_IPV6L_NODE,
19320 &no_neighbor_route_reflector_client_cmd);
19321 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19322 install_element(BGP_VPNV4_NODE,
19323 &no_neighbor_route_reflector_client_cmd);
19324 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19325 install_element(BGP_VPNV6_NODE,
19326 &no_neighbor_route_reflector_client_cmd);
19327 install_element(BGP_FLOWSPECV4_NODE,
19328 &neighbor_route_reflector_client_cmd);
19329 install_element(BGP_FLOWSPECV4_NODE,
19330 &no_neighbor_route_reflector_client_cmd);
19331 install_element(BGP_FLOWSPECV6_NODE,
19332 &neighbor_route_reflector_client_cmd);
19333 install_element(BGP_FLOWSPECV6_NODE,
19334 &no_neighbor_route_reflector_client_cmd);
19335 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19336 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19337
19338 /* "optimal-route-reflection" commands */
19339 install_element(BGP_IPV4_NODE, &optimal_route_reflection_cmd);
19340 install_element(BGP_IPV4M_NODE, &optimal_route_reflection_cmd);
19341 install_element(BGP_IPV4L_NODE, &optimal_route_reflection_cmd);
19342 install_element(BGP_IPV6_NODE, &optimal_route_reflection_cmd);
19343 install_element(BGP_IPV6M_NODE, &optimal_route_reflection_cmd);
19344 install_element(BGP_IPV6L_NODE, &optimal_route_reflection_cmd);
19345 install_element(BGP_VPNV4_NODE, &optimal_route_reflection_cmd);
19346 install_element(BGP_VPNV6_NODE, &optimal_route_reflection_cmd);
19347 install_element(BGP_FLOWSPECV4_NODE, &optimal_route_reflection_cmd);
19348 install_element(BGP_FLOWSPECV6_NODE, &optimal_route_reflection_cmd);
19349 install_element(BGP_EVPN_NODE, &optimal_route_reflection_cmd);
19350
19351 /* "neighbor optimal-route-reflection" commands */
19352 install_element(BGP_IPV4_NODE, &neighbor_optimal_route_reflection_cmd);
19353 install_element(BGP_IPV4M_NODE, &neighbor_optimal_route_reflection_cmd);
19354 install_element(BGP_IPV4L_NODE, &neighbor_optimal_route_reflection_cmd);
19355 install_element(BGP_IPV6_NODE, &neighbor_optimal_route_reflection_cmd);
19356 install_element(BGP_IPV6M_NODE, &neighbor_optimal_route_reflection_cmd);
19357 install_element(BGP_IPV6L_NODE, &neighbor_optimal_route_reflection_cmd);
19358 install_element(BGP_VPNV4_NODE, &neighbor_optimal_route_reflection_cmd);
19359 install_element(BGP_VPNV6_NODE, &neighbor_optimal_route_reflection_cmd);
19360 install_element(BGP_FLOWSPECV4_NODE,
19361 &neighbor_optimal_route_reflection_cmd);
19362 install_element(BGP_FLOWSPECV6_NODE,
19363 &neighbor_optimal_route_reflection_cmd);
19364 install_element(BGP_EVPN_NODE, &neighbor_optimal_route_reflection_cmd);
19365
19366 /* "neighbor route-server" commands.*/
19367 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19368 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19369 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19370 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19371 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19372 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19373 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19374 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19375 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19376 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19377 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19378 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19379 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19380 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19381 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19382 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19383 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19384 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19385 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19386 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19387 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19388 install_element(BGP_FLOWSPECV4_NODE,
19389 &no_neighbor_route_server_client_cmd);
19390 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19391 install_element(BGP_FLOWSPECV6_NODE,
19392 &no_neighbor_route_server_client_cmd);
19393
19394 /* "neighbor disable-addpath-rx" commands. */
19395 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19396 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19397 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19398 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19399 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19400 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19401 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19402 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19403 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19404 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19405 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19406 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19407 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19408 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19409 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19410 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19411
19412 /* "neighbor addpath-tx-all-paths" commands.*/
19413 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19414 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19415 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19416 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19417 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19418 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19419 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19420 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19421 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19422 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19423 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19424 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19425 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19426 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19427 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19428 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19429 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19430 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19431
19432 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19433 install_element(BGP_NODE,
19434 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19435 install_element(BGP_NODE,
19436 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19437 install_element(BGP_IPV4_NODE,
19438 &neighbor_addpath_tx_bestpath_per_as_cmd);
19439 install_element(BGP_IPV4_NODE,
19440 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19441 install_element(BGP_IPV4M_NODE,
19442 &neighbor_addpath_tx_bestpath_per_as_cmd);
19443 install_element(BGP_IPV4M_NODE,
19444 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19445 install_element(BGP_IPV4L_NODE,
19446 &neighbor_addpath_tx_bestpath_per_as_cmd);
19447 install_element(BGP_IPV4L_NODE,
19448 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19449 install_element(BGP_IPV6_NODE,
19450 &neighbor_addpath_tx_bestpath_per_as_cmd);
19451 install_element(BGP_IPV6_NODE,
19452 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19453 install_element(BGP_IPV6M_NODE,
19454 &neighbor_addpath_tx_bestpath_per_as_cmd);
19455 install_element(BGP_IPV6M_NODE,
19456 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19457 install_element(BGP_IPV6L_NODE,
19458 &neighbor_addpath_tx_bestpath_per_as_cmd);
19459 install_element(BGP_IPV6L_NODE,
19460 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19461 install_element(BGP_VPNV4_NODE,
19462 &neighbor_addpath_tx_bestpath_per_as_cmd);
19463 install_element(BGP_VPNV4_NODE,
19464 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19465 install_element(BGP_VPNV6_NODE,
19466 &neighbor_addpath_tx_bestpath_per_as_cmd);
19467 install_element(BGP_VPNV6_NODE,
19468 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19469
19470 /* "neighbor sender-as-path-loop-detection" commands. */
19471 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19472 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19473
19474 /* "neighbor passive" commands. */
19475 install_element(BGP_NODE, &neighbor_passive_cmd);
19476 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19477
19478
19479 /* "neighbor shutdown" commands. */
19480 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19481 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19482 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19483 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19484 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19485 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19486
19487 /* "neighbor capability extended-nexthop" commands.*/
19488 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19489 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19490
19491 /* "neighbor capability orf prefix-list" commands.*/
19492 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19493 install_element(BGP_NODE,
19494 &no_neighbor_capability_orf_prefix_hidden_cmd);
19495 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19496 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19497 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19498 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19499 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19500 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19501 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19502 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19503 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19504 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19505 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19506 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19507
19508 /* "neighbor capability dynamic" commands.*/
19509 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19510 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19511
19512 /* "neighbor dont-capability-negotiate" commands. */
19513 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19514 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19515
19516 /* "neighbor ebgp-multihop" commands. */
19517 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19518 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19519 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19520
19521 /* "neighbor disable-connected-check" commands. */
19522 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19523 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19524
19525 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19526 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19527 install_element(BGP_NODE,
19528 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19529
19530 /* "neighbor extended-optional-parameters" commands. */
19531 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19532 install_element(BGP_NODE,
19533 &no_neighbor_extended_optional_parameters_cmd);
19534
19535 /* "neighbor enforce-first-as" commands. */
19536 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19537 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19538
19539 /* "neighbor description" commands. */
19540 install_element(BGP_NODE, &neighbor_description_cmd);
19541 install_element(BGP_NODE, &no_neighbor_description_cmd);
19542 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19543
19544 /* "neighbor update-source" commands. "*/
19545 install_element(BGP_NODE, &neighbor_update_source_cmd);
19546 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19547
19548 /* "neighbor default-originate" commands. */
19549 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19550 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19551 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19552 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19553 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19554 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19555 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19556 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19557 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19558 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19559 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19560 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19561 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19562 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19563 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19564 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19565 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19566 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19567 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19568 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19569 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19570
19571 /* "neighbor port" commands. */
19572 install_element(BGP_NODE, &neighbor_port_cmd);
19573 install_element(BGP_NODE, &no_neighbor_port_cmd);
19574
19575 /* "neighbor weight" commands. */
19576 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19577 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19578
19579 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19580 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19581 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19582 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19583 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19584 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19585 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19586 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19587 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19588 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19589 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19590 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19591 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19592 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19593 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19594 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19595
19596 /* "neighbor override-capability" commands. */
19597 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19598 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19599
19600 /* "neighbor strict-capability-match" commands. */
19601 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19602 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19603
19604 /* "neighbor timers" commands. */
19605 install_element(BGP_NODE, &neighbor_timers_cmd);
19606 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19607
19608 /* "neighbor timers connect" commands. */
19609 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19610 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19611
19612 /* "neighbor timers delayopen" commands. */
19613 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19614 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19615
19616 /* "neighbor advertisement-interval" commands. */
19617 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19618 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19619
19620 /* "neighbor interface" commands. */
19621 install_element(BGP_NODE, &neighbor_interface_cmd);
19622 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19623
19624 /* "neighbor distribute" commands. */
19625 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19626 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19627 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19628 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19629 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19630 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19631 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19632 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19633 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19634 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19635 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19636 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19637 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19638 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19639 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19640 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19641 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19642 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19643
19644 /* "neighbor prefix-list" commands. */
19645 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19646 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19647 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19648 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19649 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19650 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19651 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19652 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19653 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19654 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19655 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19656 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19657 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19658 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19659 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19660 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19661 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19662 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19663 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19664 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19665 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19666 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19667
19668 /* "neighbor filter-list" commands. */
19669 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19670 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19671 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19672 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19673 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19674 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19675 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19676 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19677 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19678 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19679 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19680 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19681 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19682 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19683 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19684 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19685 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19686 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19687 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19688 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19689 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19690 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19691
19692 /* "neighbor route-map" commands. */
19693 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19694 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19695 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19696 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19697 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19698 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19699 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19700 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19701 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19702 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19703 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19704 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19705 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19706 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19707 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19708 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19709 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19710 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19711 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19712 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19713 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19714 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19715 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19716 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19717
19718 /* "neighbor unsuppress-map" commands. */
19719 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19720 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19721 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19722 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19723 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19724 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19725 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19726 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19727 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19728 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19729 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19730 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19731 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19732 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19733 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19734 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19735 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19736 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19737
19738 /* "neighbor advertise-map" commands. */
19739 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19740 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19741 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19742 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19743 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19744 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19745 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19746 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19747 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19748 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19749
19750 /* neighbor maximum-prefix-out commands. */
19751 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19752 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19753 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19754 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19755 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19756 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19757 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19758 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19759 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19760 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19761 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19762 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19763 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19764 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19765 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19766 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19767 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19768 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19769
19770 /* "neighbor maximum-prefix" commands. */
19771 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19772 install_element(BGP_NODE,
19773 &neighbor_maximum_prefix_threshold_hidden_cmd);
19774 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19775 install_element(BGP_NODE,
19776 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19777 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19778 install_element(BGP_NODE,
19779 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19780 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19781 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19782 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19783 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19784 install_element(BGP_IPV4_NODE,
19785 &neighbor_maximum_prefix_threshold_warning_cmd);
19786 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19787 install_element(BGP_IPV4_NODE,
19788 &neighbor_maximum_prefix_threshold_restart_cmd);
19789 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19790 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19791 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19792 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19793 install_element(BGP_IPV4M_NODE,
19794 &neighbor_maximum_prefix_threshold_warning_cmd);
19795 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19796 install_element(BGP_IPV4M_NODE,
19797 &neighbor_maximum_prefix_threshold_restart_cmd);
19798 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19799 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19800 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19801 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19802 install_element(BGP_IPV4L_NODE,
19803 &neighbor_maximum_prefix_threshold_warning_cmd);
19804 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19805 install_element(BGP_IPV4L_NODE,
19806 &neighbor_maximum_prefix_threshold_restart_cmd);
19807 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19808 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19809 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19810 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19811 install_element(BGP_IPV6_NODE,
19812 &neighbor_maximum_prefix_threshold_warning_cmd);
19813 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19814 install_element(BGP_IPV6_NODE,
19815 &neighbor_maximum_prefix_threshold_restart_cmd);
19816 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19817 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19818 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19819 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19820 install_element(BGP_IPV6M_NODE,
19821 &neighbor_maximum_prefix_threshold_warning_cmd);
19822 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19823 install_element(BGP_IPV6M_NODE,
19824 &neighbor_maximum_prefix_threshold_restart_cmd);
19825 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19826 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19827 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19828 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19829 install_element(BGP_IPV6L_NODE,
19830 &neighbor_maximum_prefix_threshold_warning_cmd);
19831 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19832 install_element(BGP_IPV6L_NODE,
19833 &neighbor_maximum_prefix_threshold_restart_cmd);
19834 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19835 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19836 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19837 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19838 install_element(BGP_VPNV4_NODE,
19839 &neighbor_maximum_prefix_threshold_warning_cmd);
19840 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19841 install_element(BGP_VPNV4_NODE,
19842 &neighbor_maximum_prefix_threshold_restart_cmd);
19843 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19844 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19845 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19846 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19847 install_element(BGP_VPNV6_NODE,
19848 &neighbor_maximum_prefix_threshold_warning_cmd);
19849 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19850 install_element(BGP_VPNV6_NODE,
19851 &neighbor_maximum_prefix_threshold_restart_cmd);
19852 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19853
19854 /* "neighbor allowas-in" */
19855 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19856 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19857 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19858 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19859 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19860 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19861 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19862 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19863 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19864 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19865 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19866 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19867 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19868 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19869 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19870 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19871 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19872 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19873 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19874 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19875
19876 /* neighbor accept-own */
19877 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19878 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19879
19880 /* "neighbor soo" */
19881 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19882 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19883 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19884 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19885 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19886 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19887 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19888 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19889 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19890 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19891 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19892 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19893 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19894 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19895 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19896 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19897 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19898 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19899
19900 /* address-family commands. */
19901 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19902 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19903 #ifdef KEEP_OLD_VPN_COMMANDS
19904 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19905 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19906 #endif /* KEEP_OLD_VPN_COMMANDS */
19907
19908 install_element(BGP_NODE, &address_family_evpn_cmd);
19909
19910 /* "exit-address-family" command. */
19911 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19912 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19913 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19914 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19915 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19916 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19917 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19918 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19919 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19920 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19921 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19922
19923 /* BGP retain all route-target */
19924 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19925 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19926
19927 /* "clear ip bgp commands" */
19928 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19929
19930 /* clear ip bgp prefix */
19931 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19932 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19933 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19934
19935 /* "show [ip] bgp summary" commands. */
19936 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19937 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19938 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19939 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19940 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19941 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19942 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19943
19944 /* "show [ip] bgp neighbors" commands. */
19945 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19946
19947 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19948
19949 /* "show [ip] bgp peer-group" commands. */
19950 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19951
19952 /* "show [ip] bgp paths" commands. */
19953 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19954
19955 /* "show [ip] bgp community" commands. */
19956 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19957
19958 /* "show ip bgp large-community" commands. */
19959 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19960 /* "show [ip] bgp attribute-info" commands. */
19961 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19962 /* "show [ip] bgp route-leak" command */
19963 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19964
19965 /* "redistribute" commands. */
19966 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19967 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19968 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19969 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19970 install_element(BGP_NODE,
19971 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19972 install_element(BGP_NODE,
19973 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19974 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19975 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19976 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19977 install_element(BGP_NODE,
19978 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19979 install_element(BGP_NODE,
19980 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19981 install_element(BGP_NODE,
19982 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19983 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19984 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19985 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19986 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19987 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19988 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19989 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19990 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19991 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19992 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19993 install_element(BGP_IPV4_NODE,
19994 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19995 install_element(BGP_IPV4_NODE,
19996 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19997 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19998 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19999 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20000 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20001 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20002 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20003
20004 /* import|export vpn [route-map RMAP_NAME] */
20005 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20006 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20007
20008 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20009 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20010
20011 /* ttl_security commands */
20012 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20013 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20014
20015 /* "bgp tcp-keepalive" commands */
20016 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20017 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20018
20019 /* "show [ip] bgp memory" commands. */
20020 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20021
20022 /* "show bgp martian next-hop" */
20023 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20024
20025 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20026
20027 /* "show [ip] bgp views" commands. */
20028 install_element(VIEW_NODE, &show_bgp_views_cmd);
20029
20030 /* "show [ip] bgp vrfs" commands. */
20031 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20032
20033 /* Community-list. */
20034 community_list_vty();
20035
20036 community_alias_vty();
20037
20038 /* vpn-policy commands */
20039 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20040 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20041 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20042 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20043 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20044 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20045 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20046 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20047 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20048 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20049 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20050 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20051
20052 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20053 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20054
20055 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20056 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20057 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20058 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20059 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20060 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20061 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20062 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20063 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20064 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20065
20066 /* tcp-mss command */
20067 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20068 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20069
20070 /* srv6 commands */
20071 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20072 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20073 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20074 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20075 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20076 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20077 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20078 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20079 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20080
20081 bgp_vty_if_init();
20082 }
20083
20084 #include "memory.h"
20085 #include "bgp_regex.h"
20086 #include "bgp_clist.h"
20087 #include "bgp_ecommunity.h"
20088
20089 /* VTY functions. */
20090
20091 /* Direction value to string conversion. */
20092 static const char *community_direct_str(int direct)
20093 {
20094 switch (direct) {
20095 case COMMUNITY_DENY:
20096 return "deny";
20097 case COMMUNITY_PERMIT:
20098 return "permit";
20099 default:
20100 return "unknown";
20101 }
20102 }
20103
20104 /* Display error string. */
20105 static void community_list_perror(struct vty *vty, int ret)
20106 {
20107 switch (ret) {
20108 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20109 vty_out(vty, "%% Can't find community-list\n");
20110 break;
20111 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20112 vty_out(vty, "%% Malformed community-list value\n");
20113 break;
20114 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20115 vty_out(vty,
20116 "%% Community name conflict, previously defined as standard community\n");
20117 break;
20118 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20119 vty_out(vty,
20120 "%% Community name conflict, previously defined as expanded community\n");
20121 break;
20122 }
20123 }
20124
20125 /* "community-list" keyword help string. */
20126 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20127
20128 /*community-list standard */
20129 DEFUN (community_list_standard,
20130 bgp_community_list_standard_cmd,
20131 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20132 BGP_STR
20133 COMMUNITY_LIST_STR
20134 "Community list number (standard)\n"
20135 "Add an standard community-list entry\n"
20136 "Community list name\n"
20137 "Sequence number of an entry\n"
20138 "Sequence number\n"
20139 "Specify community to reject\n"
20140 "Specify community to accept\n"
20141 COMMUNITY_VAL_STR)
20142 {
20143 char *cl_name_or_number = NULL;
20144 char *seq = NULL;
20145 int direct = 0;
20146 int style = COMMUNITY_LIST_STANDARD;
20147 int idx = 0;
20148
20149 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20150 seq = argv[idx]->arg;
20151
20152 idx = 0;
20153 argv_find(argv, argc, "(1-99)", &idx);
20154 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20155 cl_name_or_number = argv[idx]->arg;
20156 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20157 : COMMUNITY_DENY;
20158 argv_find(argv, argc, "AA:NN", &idx);
20159 char *str = argv_concat(argv, argc, idx);
20160
20161 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20162 direct, style);
20163
20164 XFREE(MTYPE_TMP, str);
20165
20166 if (ret < 0) {
20167 /* Display error string. */
20168 community_list_perror(vty, ret);
20169 return CMD_WARNING_CONFIG_FAILED;
20170 }
20171
20172 return CMD_SUCCESS;
20173 }
20174
20175 DEFUN (no_community_list_standard_all,
20176 no_bgp_community_list_standard_all_cmd,
20177 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20178 NO_STR
20179 BGP_STR
20180 COMMUNITY_LIST_STR
20181 "Community list number (standard)\n"
20182 "Add an standard community-list entry\n"
20183 "Community list name\n"
20184 "Sequence number of an entry\n"
20185 "Sequence number\n"
20186 "Specify community to reject\n"
20187 "Specify community to accept\n"
20188 COMMUNITY_VAL_STR)
20189 {
20190 char *cl_name_or_number = NULL;
20191 char *str = NULL;
20192 int direct = 0;
20193 int style = COMMUNITY_LIST_STANDARD;
20194 char *seq = NULL;
20195 int idx = 0;
20196
20197 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20198 seq = argv[idx]->arg;
20199
20200 idx = 0;
20201 argv_find(argv, argc, "permit", &idx);
20202 argv_find(argv, argc, "deny", &idx);
20203
20204 if (idx) {
20205 direct = argv_find(argv, argc, "permit", &idx)
20206 ? COMMUNITY_PERMIT
20207 : COMMUNITY_DENY;
20208
20209 idx = 0;
20210 argv_find(argv, argc, "AA:NN", &idx);
20211 str = argv_concat(argv, argc, idx);
20212 }
20213
20214 idx = 0;
20215 argv_find(argv, argc, "(1-99)", &idx);
20216 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20217 cl_name_or_number = argv[idx]->arg;
20218
20219 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20220 direct, style);
20221
20222 XFREE(MTYPE_TMP, str);
20223
20224 if (ret < 0) {
20225 community_list_perror(vty, ret);
20226 return CMD_WARNING_CONFIG_FAILED;
20227 }
20228
20229 return CMD_SUCCESS;
20230 }
20231
20232 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20233 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20234 NO_STR BGP_STR COMMUNITY_LIST_STR
20235 "Community list number (standard)\n"
20236 "Add an standard community-list entry\n"
20237 "Community list name\n")
20238
20239 /*community-list expanded */
20240 DEFUN (community_list_expanded_all,
20241 bgp_community_list_expanded_all_cmd,
20242 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20243 BGP_STR
20244 COMMUNITY_LIST_STR
20245 "Community list number (expanded)\n"
20246 "Add an expanded community-list entry\n"
20247 "Community list name\n"
20248 "Sequence number of an entry\n"
20249 "Sequence number\n"
20250 "Specify community to reject\n"
20251 "Specify community to accept\n"
20252 COMMUNITY_VAL_STR)
20253 {
20254 char *cl_name_or_number = NULL;
20255 char *seq = NULL;
20256 int direct = 0;
20257 int style = COMMUNITY_LIST_EXPANDED;
20258 int idx = 0;
20259
20260 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20261 seq = argv[idx]->arg;
20262
20263 idx = 0;
20264
20265 argv_find(argv, argc, "(100-500)", &idx);
20266 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20267 cl_name_or_number = argv[idx]->arg;
20268 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20269 : COMMUNITY_DENY;
20270 argv_find(argv, argc, "AA:NN", &idx);
20271 char *str = argv_concat(argv, argc, idx);
20272
20273 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20274 direct, style);
20275
20276 XFREE(MTYPE_TMP, str);
20277
20278 if (ret < 0) {
20279 /* Display error string. */
20280 community_list_perror(vty, ret);
20281 return CMD_WARNING_CONFIG_FAILED;
20282 }
20283
20284 return CMD_SUCCESS;
20285 }
20286
20287 DEFUN (no_community_list_expanded_all,
20288 no_bgp_community_list_expanded_all_cmd,
20289 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20290 NO_STR
20291 BGP_STR
20292 COMMUNITY_LIST_STR
20293 "Community list number (expanded)\n"
20294 "Add an expanded community-list entry\n"
20295 "Community list name\n"
20296 "Sequence number of an entry\n"
20297 "Sequence number\n"
20298 "Specify community to reject\n"
20299 "Specify community to accept\n"
20300 COMMUNITY_VAL_STR)
20301 {
20302 char *cl_name_or_number = NULL;
20303 char *seq = NULL;
20304 char *str = NULL;
20305 int direct = 0;
20306 int style = COMMUNITY_LIST_EXPANDED;
20307 int idx = 0;
20308
20309 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20310 seq = argv[idx]->arg;
20311
20312 idx = 0;
20313 argv_find(argv, argc, "permit", &idx);
20314 argv_find(argv, argc, "deny", &idx);
20315
20316 if (idx) {
20317 direct = argv_find(argv, argc, "permit", &idx)
20318 ? COMMUNITY_PERMIT
20319 : COMMUNITY_DENY;
20320
20321 idx = 0;
20322 argv_find(argv, argc, "AA:NN", &idx);
20323 str = argv_concat(argv, argc, idx);
20324 }
20325
20326 idx = 0;
20327 argv_find(argv, argc, "(100-500)", &idx);
20328 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20329 cl_name_or_number = argv[idx]->arg;
20330
20331 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20332 direct, style);
20333
20334 XFREE(MTYPE_TMP, str);
20335
20336 if (ret < 0) {
20337 community_list_perror(vty, ret);
20338 return CMD_WARNING_CONFIG_FAILED;
20339 }
20340
20341 return CMD_SUCCESS;
20342 }
20343
20344 ALIAS(no_community_list_expanded_all,
20345 no_bgp_community_list_expanded_all_list_cmd,
20346 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20347 NO_STR BGP_STR COMMUNITY_LIST_STR
20348 "Community list number (expanded)\n"
20349 "Add an expanded community-list entry\n"
20350 "Community list name\n")
20351
20352 /* Return configuration string of community-list entry. */
20353 static const char *community_list_config_str(struct community_entry *entry)
20354 {
20355 const char *str;
20356
20357 if (entry->any)
20358 str = "";
20359 else {
20360 if (entry->style == COMMUNITY_LIST_STANDARD)
20361 str = community_str(entry->u.com, false, false);
20362 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20363 str = lcommunity_str(entry->u.lcom, false, false);
20364 else
20365 str = entry->config;
20366 }
20367 return str;
20368 }
20369
20370 static void community_list_show(struct vty *vty, struct community_list *list)
20371 {
20372 struct community_entry *entry;
20373
20374 for (entry = list->head; entry; entry = entry->next) {
20375 if (entry == list->head) {
20376 if (all_digit(list->name))
20377 vty_out(vty, "Community %s list %s\n",
20378 entry->style == COMMUNITY_LIST_STANDARD
20379 ? "standard"
20380 : "(expanded) access",
20381 list->name);
20382 else
20383 vty_out(vty, "Named Community %s list %s\n",
20384 entry->style == COMMUNITY_LIST_STANDARD
20385 ? "standard"
20386 : "expanded",
20387 list->name);
20388 }
20389 if (entry->any)
20390 vty_out(vty, " %s\n",
20391 community_direct_str(entry->direct));
20392 else
20393 vty_out(vty, " %s %s\n",
20394 community_direct_str(entry->direct),
20395 community_list_config_str(entry));
20396 }
20397 }
20398
20399 DEFUN (show_community_list,
20400 show_bgp_community_list_cmd,
20401 "show bgp community-list",
20402 SHOW_STR
20403 BGP_STR
20404 "List community-list\n")
20405 {
20406 struct community_list *list;
20407 struct community_list_master *cm;
20408
20409 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20410 if (!cm)
20411 return CMD_SUCCESS;
20412
20413 for (list = cm->num.head; list; list = list->next)
20414 community_list_show(vty, list);
20415
20416 for (list = cm->str.head; list; list = list->next)
20417 community_list_show(vty, list);
20418
20419 return CMD_SUCCESS;
20420 }
20421
20422 DEFUN (show_community_list_arg,
20423 show_bgp_community_list_arg_cmd,
20424 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20425 SHOW_STR
20426 BGP_STR
20427 "List community-list\n"
20428 "Community-list number\n"
20429 "Community-list name\n"
20430 "Detailed information on community-list\n")
20431 {
20432 int idx_comm_list = 3;
20433 struct community_list *list;
20434
20435 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20436 COMMUNITY_LIST_MASTER);
20437 if (!list) {
20438 vty_out(vty, "%% Can't find community-list\n");
20439 return CMD_WARNING;
20440 }
20441
20442 community_list_show(vty, list);
20443
20444 return CMD_SUCCESS;
20445 }
20446
20447 /*
20448 * Large Community code.
20449 */
20450 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20451 struct cmd_token **argv, int style,
20452 int reject_all_digit_name)
20453 {
20454 int ret;
20455 int direct;
20456 char *str;
20457 int idx = 0;
20458 char *cl_name;
20459 char *seq = NULL;
20460
20461 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20462 seq = argv[idx]->arg;
20463
20464 idx = 0;
20465 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20466 : COMMUNITY_DENY;
20467
20468 /* All digit name check. */
20469 idx = 0;
20470 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20471 argv_find(argv, argc, "(1-99)", &idx);
20472 argv_find(argv, argc, "(100-500)", &idx);
20473 cl_name = argv[idx]->arg;
20474 if (reject_all_digit_name && all_digit(cl_name)) {
20475 vty_out(vty, "%% Community name cannot have all digits\n");
20476 return CMD_WARNING_CONFIG_FAILED;
20477 }
20478
20479 idx = 0;
20480 argv_find(argv, argc, "AA:BB:CC", &idx);
20481 argv_find(argv, argc, "LINE", &idx);
20482 /* Concat community string argument. */
20483 if (idx)
20484 str = argv_concat(argv, argc, idx);
20485 else
20486 str = NULL;
20487
20488 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20489
20490 /* Free temporary community list string allocated by
20491 argv_concat(). */
20492 XFREE(MTYPE_TMP, str);
20493
20494 if (ret < 0) {
20495 community_list_perror(vty, ret);
20496 return CMD_WARNING_CONFIG_FAILED;
20497 }
20498 return CMD_SUCCESS;
20499 }
20500
20501 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20502 struct cmd_token **argv, int style)
20503 {
20504 int ret;
20505 int direct = 0;
20506 char *str = NULL;
20507 int idx = 0;
20508 char *seq = NULL;
20509
20510 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20511 seq = argv[idx]->arg;
20512
20513 idx = 0;
20514 argv_find(argv, argc, "permit", &idx);
20515 argv_find(argv, argc, "deny", &idx);
20516
20517 if (idx) {
20518 /* Check the list direct. */
20519 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20520 direct = COMMUNITY_PERMIT;
20521 else
20522 direct = COMMUNITY_DENY;
20523
20524 idx = 0;
20525 argv_find(argv, argc, "LINE", &idx);
20526 argv_find(argv, argc, "AA:AA:NN", &idx);
20527 /* Concat community string argument. */
20528 str = argv_concat(argv, argc, idx);
20529 }
20530
20531 idx = 0;
20532 argv_find(argv, argc, "(1-99)", &idx);
20533 argv_find(argv, argc, "(100-500)", &idx);
20534 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20535
20536 /* Unset community list. */
20537 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20538 style);
20539
20540 /* Free temporary community list string allocated by
20541 argv_concat(). */
20542 XFREE(MTYPE_TMP, str);
20543
20544 if (ret < 0) {
20545 community_list_perror(vty, ret);
20546 return CMD_WARNING_CONFIG_FAILED;
20547 }
20548
20549 return CMD_SUCCESS;
20550 }
20551
20552 /* "large-community-list" keyword help string. */
20553 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20554 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20555
20556 DEFUN (lcommunity_list_standard,
20557 bgp_lcommunity_list_standard_cmd,
20558 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20559 BGP_STR
20560 LCOMMUNITY_LIST_STR
20561 "Large Community list number (standard)\n"
20562 "Sequence number of an entry\n"
20563 "Sequence number\n"
20564 "Specify large community to reject\n"
20565 "Specify large community to accept\n"
20566 LCOMMUNITY_VAL_STR)
20567 {
20568 return lcommunity_list_set_vty(vty, argc, argv,
20569 LARGE_COMMUNITY_LIST_STANDARD, 0);
20570 }
20571
20572 DEFUN (lcommunity_list_expanded,
20573 bgp_lcommunity_list_expanded_cmd,
20574 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20575 BGP_STR
20576 LCOMMUNITY_LIST_STR
20577 "Large Community list number (expanded)\n"
20578 "Sequence number of an entry\n"
20579 "Sequence number\n"
20580 "Specify large community to reject\n"
20581 "Specify large community to accept\n"
20582 "An ordered list as a regular-expression\n")
20583 {
20584 return lcommunity_list_set_vty(vty, argc, argv,
20585 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20586 }
20587
20588 DEFUN (lcommunity_list_name_standard,
20589 bgp_lcommunity_list_name_standard_cmd,
20590 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20591 BGP_STR
20592 LCOMMUNITY_LIST_STR
20593 "Specify standard large-community-list\n"
20594 "Large Community list name\n"
20595 "Sequence number of an entry\n"
20596 "Sequence number\n"
20597 "Specify large community to reject\n"
20598 "Specify large community to accept\n"
20599 LCOMMUNITY_VAL_STR)
20600 {
20601 return lcommunity_list_set_vty(vty, argc, argv,
20602 LARGE_COMMUNITY_LIST_STANDARD, 1);
20603 }
20604
20605 DEFUN (lcommunity_list_name_expanded,
20606 bgp_lcommunity_list_name_expanded_cmd,
20607 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20608 BGP_STR
20609 LCOMMUNITY_LIST_STR
20610 "Specify expanded large-community-list\n"
20611 "Large Community list name\n"
20612 "Sequence number of an entry\n"
20613 "Sequence number\n"
20614 "Specify large community to reject\n"
20615 "Specify large community to accept\n"
20616 "An ordered list as a regular-expression\n")
20617 {
20618 return lcommunity_list_set_vty(vty, argc, argv,
20619 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20620 }
20621
20622 DEFUN (no_lcommunity_list_all,
20623 no_bgp_lcommunity_list_all_cmd,
20624 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20625 NO_STR
20626 BGP_STR
20627 LCOMMUNITY_LIST_STR
20628 "Large Community list number (standard)\n"
20629 "Large Community list number (expanded)\n"
20630 "Large Community list name\n")
20631 {
20632 return lcommunity_list_unset_vty(vty, argc, argv,
20633 LARGE_COMMUNITY_LIST_STANDARD);
20634 }
20635
20636 DEFUN (no_lcommunity_list_name_standard_all,
20637 no_bgp_lcommunity_list_name_standard_all_cmd,
20638 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20639 NO_STR
20640 BGP_STR
20641 LCOMMUNITY_LIST_STR
20642 "Specify standard large-community-list\n"
20643 "Large Community list name\n")
20644 {
20645 return lcommunity_list_unset_vty(vty, argc, argv,
20646 LARGE_COMMUNITY_LIST_STANDARD);
20647 }
20648
20649 DEFUN (no_lcommunity_list_name_expanded_all,
20650 no_bgp_lcommunity_list_name_expanded_all_cmd,
20651 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20652 NO_STR
20653 BGP_STR
20654 LCOMMUNITY_LIST_STR
20655 "Specify expanded large-community-list\n"
20656 "Large Community list name\n")
20657 {
20658 return lcommunity_list_unset_vty(vty, argc, argv,
20659 LARGE_COMMUNITY_LIST_EXPANDED);
20660 }
20661
20662 DEFUN (no_lcommunity_list_standard,
20663 no_bgp_lcommunity_list_standard_cmd,
20664 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20665 NO_STR
20666 BGP_STR
20667 LCOMMUNITY_LIST_STR
20668 "Large Community list number (standard)\n"
20669 "Sequence number of an entry\n"
20670 "Sequence number\n"
20671 "Specify large community to reject\n"
20672 "Specify large community to accept\n"
20673 LCOMMUNITY_VAL_STR)
20674 {
20675 return lcommunity_list_unset_vty(vty, argc, argv,
20676 LARGE_COMMUNITY_LIST_STANDARD);
20677 }
20678
20679 DEFUN (no_lcommunity_list_expanded,
20680 no_bgp_lcommunity_list_expanded_cmd,
20681 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20682 NO_STR
20683 BGP_STR
20684 LCOMMUNITY_LIST_STR
20685 "Large Community list number (expanded)\n"
20686 "Sequence number of an entry\n"
20687 "Sequence number\n"
20688 "Specify large community to reject\n"
20689 "Specify large community to accept\n"
20690 "An ordered list as a regular-expression\n")
20691 {
20692 return lcommunity_list_unset_vty(vty, argc, argv,
20693 LARGE_COMMUNITY_LIST_EXPANDED);
20694 }
20695
20696 DEFUN (no_lcommunity_list_name_standard,
20697 no_bgp_lcommunity_list_name_standard_cmd,
20698 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20699 NO_STR
20700 BGP_STR
20701 LCOMMUNITY_LIST_STR
20702 "Specify standard large-community-list\n"
20703 "Large Community list name\n"
20704 "Sequence number of an entry\n"
20705 "Sequence number\n"
20706 "Specify large community to reject\n"
20707 "Specify large community to accept\n"
20708 LCOMMUNITY_VAL_STR)
20709 {
20710 return lcommunity_list_unset_vty(vty, argc, argv,
20711 LARGE_COMMUNITY_LIST_STANDARD);
20712 }
20713
20714 DEFUN (no_lcommunity_list_name_expanded,
20715 no_bgp_lcommunity_list_name_expanded_cmd,
20716 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20717 NO_STR
20718 BGP_STR
20719 LCOMMUNITY_LIST_STR
20720 "Specify expanded large-community-list\n"
20721 "Large community list name\n"
20722 "Sequence number of an entry\n"
20723 "Sequence number\n"
20724 "Specify large community to reject\n"
20725 "Specify large community to accept\n"
20726 "An ordered list as a regular-expression\n")
20727 {
20728 return lcommunity_list_unset_vty(vty, argc, argv,
20729 LARGE_COMMUNITY_LIST_EXPANDED);
20730 }
20731
20732 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20733 {
20734 struct community_entry *entry;
20735
20736 for (entry = list->head; entry; entry = entry->next) {
20737 if (entry == list->head) {
20738 if (all_digit(list->name))
20739 vty_out(vty, "Large community %s list %s\n",
20740 entry->style ==
20741 LARGE_COMMUNITY_LIST_STANDARD
20742 ? "standard"
20743 : "(expanded) access",
20744 list->name);
20745 else
20746 vty_out(vty,
20747 "Named large community %s list %s\n",
20748 entry->style ==
20749 LARGE_COMMUNITY_LIST_STANDARD
20750 ? "standard"
20751 : "expanded",
20752 list->name);
20753 }
20754 if (entry->any)
20755 vty_out(vty, " %s\n",
20756 community_direct_str(entry->direct));
20757 else
20758 vty_out(vty, " %s %s\n",
20759 community_direct_str(entry->direct),
20760 community_list_config_str(entry));
20761 }
20762 }
20763
20764 DEFUN (show_lcommunity_list,
20765 show_bgp_lcommunity_list_cmd,
20766 "show bgp large-community-list",
20767 SHOW_STR
20768 BGP_STR
20769 "List large-community list\n")
20770 {
20771 struct community_list *list;
20772 struct community_list_master *cm;
20773
20774 cm = community_list_master_lookup(bgp_clist,
20775 LARGE_COMMUNITY_LIST_MASTER);
20776 if (!cm)
20777 return CMD_SUCCESS;
20778
20779 for (list = cm->num.head; list; list = list->next)
20780 lcommunity_list_show(vty, list);
20781
20782 for (list = cm->str.head; list; list = list->next)
20783 lcommunity_list_show(vty, list);
20784
20785 return CMD_SUCCESS;
20786 }
20787
20788 DEFUN (show_lcommunity_list_arg,
20789 show_bgp_lcommunity_list_arg_cmd,
20790 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20791 SHOW_STR
20792 BGP_STR
20793 "List large-community list\n"
20794 "Large-community-list number\n"
20795 "Large-community-list name\n"
20796 "Detailed information on large-community-list\n")
20797 {
20798 struct community_list *list;
20799
20800 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20801 LARGE_COMMUNITY_LIST_MASTER);
20802 if (!list) {
20803 vty_out(vty, "%% Can't find large-community-list\n");
20804 return CMD_WARNING;
20805 }
20806
20807 lcommunity_list_show(vty, list);
20808
20809 return CMD_SUCCESS;
20810 }
20811
20812 /* "extcommunity-list" keyword help string. */
20813 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20814 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20815
20816 DEFUN (extcommunity_list_standard,
20817 bgp_extcommunity_list_standard_cmd,
20818 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20819 BGP_STR
20820 EXTCOMMUNITY_LIST_STR
20821 "Extended Community list number (standard)\n"
20822 "Specify standard extcommunity-list\n"
20823 "Community list name\n"
20824 "Sequence number of an entry\n"
20825 "Sequence number\n"
20826 "Specify community to reject\n"
20827 "Specify community to accept\n"
20828 EXTCOMMUNITY_VAL_STR)
20829 {
20830 int style = EXTCOMMUNITY_LIST_STANDARD;
20831 int direct = 0;
20832 char *cl_number_or_name = NULL;
20833 char *seq = NULL;
20834
20835 int idx = 0;
20836
20837 argv_find(argv, argc, "(1-99)", &idx);
20838 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20839 cl_number_or_name = argv[idx]->arg;
20840
20841 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20842 seq = argv[idx]->arg;
20843
20844 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20845 : COMMUNITY_DENY;
20846 argv_find(argv, argc, "AA:NN", &idx);
20847 char *str = argv_concat(argv, argc, idx);
20848
20849 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20850 direct, style);
20851
20852 XFREE(MTYPE_TMP, str);
20853
20854 if (ret < 0) {
20855 community_list_perror(vty, ret);
20856 return CMD_WARNING_CONFIG_FAILED;
20857 }
20858
20859 return CMD_SUCCESS;
20860 }
20861
20862 DEFUN (extcommunity_list_name_expanded,
20863 bgp_extcommunity_list_name_expanded_cmd,
20864 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20865 BGP_STR
20866 EXTCOMMUNITY_LIST_STR
20867 "Extended Community list number (expanded)\n"
20868 "Specify expanded extcommunity-list\n"
20869 "Extended Community list name\n"
20870 "Sequence number of an entry\n"
20871 "Sequence number\n"
20872 "Specify community to reject\n"
20873 "Specify community to accept\n"
20874 "An ordered list as a regular-expression\n")
20875 {
20876 int style = EXTCOMMUNITY_LIST_EXPANDED;
20877 int direct = 0;
20878 char *cl_number_or_name = NULL;
20879 char *seq = NULL;
20880 int idx = 0;
20881
20882 argv_find(argv, argc, "(100-500)", &idx);
20883 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20884 cl_number_or_name = argv[idx]->arg;
20885
20886 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20887 seq = argv[idx]->arg;
20888
20889 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20890 : COMMUNITY_DENY;
20891 argv_find(argv, argc, "LINE", &idx);
20892 char *str = argv_concat(argv, argc, idx);
20893
20894 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20895 direct, style);
20896
20897 XFREE(MTYPE_TMP, str);
20898
20899 if (ret < 0) {
20900 community_list_perror(vty, ret);
20901 return CMD_WARNING_CONFIG_FAILED;
20902 }
20903
20904 return CMD_SUCCESS;
20905 }
20906
20907 DEFUN (no_extcommunity_list_standard_all,
20908 no_bgp_extcommunity_list_standard_all_cmd,
20909 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20910 NO_STR
20911 BGP_STR
20912 EXTCOMMUNITY_LIST_STR
20913 "Extended Community list number (standard)\n"
20914 "Specify standard extcommunity-list\n"
20915 "Community list name\n"
20916 "Sequence number of an entry\n"
20917 "Sequence number\n"
20918 "Specify community to reject\n"
20919 "Specify community to accept\n"
20920 EXTCOMMUNITY_VAL_STR)
20921 {
20922 int style = EXTCOMMUNITY_LIST_STANDARD;
20923 int direct = 0;
20924 char *cl_number_or_name = NULL;
20925 char *str = NULL;
20926 char *seq = NULL;
20927 int idx = 0;
20928
20929 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20930 seq = argv[idx]->arg;
20931
20932 idx = 0;
20933 argv_find(argv, argc, "permit", &idx);
20934 argv_find(argv, argc, "deny", &idx);
20935 if (idx) {
20936 direct = argv_find(argv, argc, "permit", &idx)
20937 ? COMMUNITY_PERMIT
20938 : COMMUNITY_DENY;
20939
20940 idx = 0;
20941 argv_find(argv, argc, "AA:NN", &idx);
20942 str = argv_concat(argv, argc, idx);
20943 }
20944
20945 idx = 0;
20946 argv_find(argv, argc, "(1-99)", &idx);
20947 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20948 cl_number_or_name = argv[idx]->arg;
20949
20950 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20951 seq, direct, style);
20952
20953 XFREE(MTYPE_TMP, str);
20954
20955 if (ret < 0) {
20956 community_list_perror(vty, ret);
20957 return CMD_WARNING_CONFIG_FAILED;
20958 }
20959
20960 return CMD_SUCCESS;
20961 }
20962
20963 ALIAS(no_extcommunity_list_standard_all,
20964 no_bgp_extcommunity_list_standard_all_list_cmd,
20965 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20966 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20967 "Extended Community list number (standard)\n"
20968 "Specify standard extcommunity-list\n"
20969 "Community list name\n")
20970
20971 DEFUN (no_extcommunity_list_expanded_all,
20972 no_bgp_extcommunity_list_expanded_all_cmd,
20973 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20974 NO_STR
20975 BGP_STR
20976 EXTCOMMUNITY_LIST_STR
20977 "Extended Community list number (expanded)\n"
20978 "Specify expanded extcommunity-list\n"
20979 "Extended Community list name\n"
20980 "Sequence number of an entry\n"
20981 "Sequence number\n"
20982 "Specify community to reject\n"
20983 "Specify community to accept\n"
20984 "An ordered list as a regular-expression\n")
20985 {
20986 int style = EXTCOMMUNITY_LIST_EXPANDED;
20987 int direct = 0;
20988 char *cl_number_or_name = NULL;
20989 char *str = NULL;
20990 char *seq = NULL;
20991 int idx = 0;
20992
20993 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20994 seq = argv[idx]->arg;
20995
20996 idx = 0;
20997 argv_find(argv, argc, "permit", &idx);
20998 argv_find(argv, argc, "deny", &idx);
20999
21000 if (idx) {
21001 direct = argv_find(argv, argc, "permit", &idx)
21002 ? COMMUNITY_PERMIT
21003 : COMMUNITY_DENY;
21004
21005 idx = 0;
21006 argv_find(argv, argc, "LINE", &idx);
21007 str = argv_concat(argv, argc, idx);
21008 }
21009
21010 idx = 0;
21011 argv_find(argv, argc, "(100-500)", &idx);
21012 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21013 cl_number_or_name = argv[idx]->arg;
21014
21015 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21016 seq, 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 ALIAS(no_extcommunity_list_expanded_all,
21029 no_bgp_extcommunity_list_expanded_all_list_cmd,
21030 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21031 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21032 "Extended Community list number (expanded)\n"
21033 "Specify expanded extcommunity-list\n"
21034 "Extended Community list name\n")
21035
21036 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21037 {
21038 struct community_entry *entry;
21039
21040 for (entry = list->head; entry; entry = entry->next) {
21041 if (entry == list->head) {
21042 if (all_digit(list->name))
21043 vty_out(vty, "Extended community %s list %s\n",
21044 entry->style == EXTCOMMUNITY_LIST_STANDARD
21045 ? "standard"
21046 : "(expanded) access",
21047 list->name);
21048 else
21049 vty_out(vty,
21050 "Named extended community %s list %s\n",
21051 entry->style == EXTCOMMUNITY_LIST_STANDARD
21052 ? "standard"
21053 : "expanded",
21054 list->name);
21055 }
21056 if (entry->any)
21057 vty_out(vty, " %s\n",
21058 community_direct_str(entry->direct));
21059 else
21060 vty_out(vty, " %s %s\n",
21061 community_direct_str(entry->direct),
21062 community_list_config_str(entry));
21063 }
21064 }
21065
21066 DEFUN (show_extcommunity_list,
21067 show_bgp_extcommunity_list_cmd,
21068 "show bgp extcommunity-list",
21069 SHOW_STR
21070 BGP_STR
21071 "List extended-community list\n")
21072 {
21073 struct community_list *list;
21074 struct community_list_master *cm;
21075
21076 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21077 if (!cm)
21078 return CMD_SUCCESS;
21079
21080 for (list = cm->num.head; list; list = list->next)
21081 extcommunity_list_show(vty, list);
21082
21083 for (list = cm->str.head; list; list = list->next)
21084 extcommunity_list_show(vty, list);
21085
21086 return CMD_SUCCESS;
21087 }
21088
21089 DEFUN (show_extcommunity_list_arg,
21090 show_bgp_extcommunity_list_arg_cmd,
21091 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21092 SHOW_STR
21093 BGP_STR
21094 "List extended-community list\n"
21095 "Extcommunity-list number\n"
21096 "Extcommunity-list name\n"
21097 "Detailed information on extcommunity-list\n")
21098 {
21099 int idx_comm_list = 3;
21100 struct community_list *list;
21101
21102 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21103 EXTCOMMUNITY_LIST_MASTER);
21104 if (!list) {
21105 vty_out(vty, "%% Can't find extcommunity-list\n");
21106 return CMD_WARNING;
21107 }
21108
21109 extcommunity_list_show(vty, list);
21110
21111 return CMD_SUCCESS;
21112 }
21113
21114 /* Display community-list and extcommunity-list configuration. */
21115 static int community_list_config_write(struct vty *vty)
21116 {
21117 struct community_list *list;
21118 struct community_entry *entry;
21119 struct community_list_master *cm;
21120 int write = 0;
21121
21122 /* Community-list. */
21123 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21124
21125 for (list = cm->num.head; list; list = list->next)
21126 for (entry = list->head; entry; entry = entry->next) {
21127 vty_out(vty,
21128 "bgp community-list %s seq %" PRId64 " %s %s\n",
21129 list->name, entry->seq,
21130 community_direct_str(entry->direct),
21131 community_list_config_str(entry));
21132 write++;
21133 }
21134 for (list = cm->str.head; list; list = list->next)
21135 for (entry = list->head; entry; entry = entry->next) {
21136 vty_out(vty,
21137 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21138 entry->style == COMMUNITY_LIST_STANDARD
21139 ? "standard"
21140 : "expanded",
21141 list->name, entry->seq,
21142 community_direct_str(entry->direct),
21143 community_list_config_str(entry));
21144 write++;
21145 }
21146
21147 /* Extcommunity-list. */
21148 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21149
21150 for (list = cm->num.head; list; list = list->next)
21151 for (entry = list->head; entry; entry = entry->next) {
21152 vty_out(vty,
21153 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21154 list->name, entry->seq,
21155 community_direct_str(entry->direct),
21156 community_list_config_str(entry));
21157 write++;
21158 }
21159 for (list = cm->str.head; list; list = list->next)
21160 for (entry = list->head; entry; entry = entry->next) {
21161 vty_out(vty,
21162 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21163 entry->style == EXTCOMMUNITY_LIST_STANDARD
21164 ? "standard"
21165 : "expanded",
21166 list->name, entry->seq,
21167 community_direct_str(entry->direct),
21168 community_list_config_str(entry));
21169 write++;
21170 }
21171
21172
21173 /* lcommunity-list. */
21174 cm = community_list_master_lookup(bgp_clist,
21175 LARGE_COMMUNITY_LIST_MASTER);
21176
21177 for (list = cm->num.head; list; list = list->next)
21178 for (entry = list->head; entry; entry = entry->next) {
21179 vty_out(vty,
21180 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21181 list->name, entry->seq,
21182 community_direct_str(entry->direct),
21183 community_list_config_str(entry));
21184 write++;
21185 }
21186 for (list = cm->str.head; list; list = list->next)
21187 for (entry = list->head; entry; entry = entry->next) {
21188 vty_out(vty,
21189 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21190
21191 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21192 ? "standard"
21193 : "expanded",
21194 list->name, entry->seq, community_direct_str(entry->direct),
21195 community_list_config_str(entry));
21196 write++;
21197 }
21198
21199 return write;
21200 }
21201
21202 static int community_list_config_write(struct vty *vty);
21203 static struct cmd_node community_list_node = {
21204 .name = "community list",
21205 .node = COMMUNITY_LIST_NODE,
21206 .prompt = "",
21207 .config_write = community_list_config_write,
21208 };
21209
21210 static void community_list_vty(void)
21211 {
21212 install_node(&community_list_node);
21213
21214 /* Community-list. */
21215 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21216 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21217 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21218 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21219 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21220 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21221 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21222 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21223
21224 /* Extcommunity-list. */
21225 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21226 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21227 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21228 install_element(CONFIG_NODE,
21229 &no_bgp_extcommunity_list_standard_all_list_cmd);
21230 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21231 install_element(CONFIG_NODE,
21232 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21233 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21234 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21235
21236 /* Large Community List */
21237 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21238 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21239 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21240 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21241 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21242 install_element(CONFIG_NODE,
21243 &no_bgp_lcommunity_list_name_standard_all_cmd);
21244 install_element(CONFIG_NODE,
21245 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21246 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21247 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21248 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21249 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21250 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21251 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21252
21253 bgp_community_list_command_completion_setup();
21254 }
21255
21256 static struct cmd_node community_alias_node = {
21257 .name = "community alias",
21258 .node = COMMUNITY_ALIAS_NODE,
21259 .prompt = "",
21260 .config_write = bgp_community_alias_write,
21261 };
21262
21263 void community_alias_vty(void)
21264 {
21265 install_node(&community_alias_node);
21266
21267 /* Community-list. */
21268 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21269
21270 bgp_community_alias_command_completion_setup();
21271 }