]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12322 from fdumontet6WIND/confed_num
[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 bool use_json,
163 json_object *json);
164
165 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
166 enum show_type type,
167 const char *ip_str,
168 afi_t afi, bool use_json);
169
170 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
171 {
172 switch (afi) {
173 case AFI_IP:
174 switch (safi) {
175 case SAFI_UNICAST:
176 return BGP_IPV4_NODE;
177 case SAFI_MULTICAST:
178 return BGP_IPV4M_NODE;
179 case SAFI_LABELED_UNICAST:
180 return BGP_IPV4L_NODE;
181 case SAFI_MPLS_VPN:
182 return BGP_VPNV4_NODE;
183 case SAFI_FLOWSPEC:
184 return BGP_FLOWSPECV4_NODE;
185 default:
186 /* not expected */
187 return BGP_IPV4_NODE;
188 }
189 case AFI_IP6:
190 switch (safi) {
191 case SAFI_UNICAST:
192 return BGP_IPV6_NODE;
193 case SAFI_MULTICAST:
194 return BGP_IPV6M_NODE;
195 case SAFI_LABELED_UNICAST:
196 return BGP_IPV6L_NODE;
197 case SAFI_MPLS_VPN:
198 return BGP_VPNV6_NODE;
199 case SAFI_FLOWSPEC:
200 return BGP_FLOWSPECV6_NODE;
201 default:
202 /* not expected */
203 return BGP_IPV4_NODE;
204 }
205 case AFI_L2VPN:
206 return BGP_EVPN_NODE;
207 case AFI_UNSPEC:
208 case AFI_MAX:
209 // We should never be here but to clarify the switch statement..
210 return BGP_IPV4_NODE;
211 }
212
213 // Impossible to happen
214 return BGP_IPV4_NODE;
215 }
216
217 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
218 {
219 if (afi == AFI_IP) {
220 if (safi == SAFI_UNICAST)
221 return "IPv4 Unicast";
222 if (safi == SAFI_MULTICAST)
223 return "IPv4 Multicast";
224 if (safi == SAFI_LABELED_UNICAST)
225 return "IPv4 Labeled Unicast";
226 if (safi == SAFI_MPLS_VPN)
227 return "IPv4 VPN";
228 if (safi == SAFI_ENCAP)
229 return "IPv4 Encap";
230 if (safi == SAFI_FLOWSPEC)
231 return "IPv4 Flowspec";
232 } else if (afi == AFI_IP6) {
233 if (safi == SAFI_UNICAST)
234 return "IPv6 Unicast";
235 if (safi == SAFI_MULTICAST)
236 return "IPv6 Multicast";
237 if (safi == SAFI_LABELED_UNICAST)
238 return "IPv6 Labeled Unicast";
239 if (safi == SAFI_MPLS_VPN)
240 return "IPv6 VPN";
241 if (safi == SAFI_ENCAP)
242 return "IPv6 Encap";
243 if (safi == SAFI_FLOWSPEC)
244 return "IPv6 Flowspec";
245 } else if (afi == AFI_L2VPN) {
246 if (safi == SAFI_EVPN)
247 return "L2VPN EVPN";
248 }
249
250 return "Unknown";
251 }
252
253 /*
254 * Please note that we have intentionally camelCased
255 * the return strings here. So if you want
256 * to use this function, please ensure you
257 * are doing this within json output
258 */
259 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
260 {
261 if (afi == AFI_IP) {
262 if (safi == SAFI_UNICAST)
263 return "ipv4Unicast";
264 if (safi == SAFI_MULTICAST)
265 return "ipv4Multicast";
266 if (safi == SAFI_LABELED_UNICAST)
267 return "ipv4LabeledUnicast";
268 if (safi == SAFI_MPLS_VPN)
269 return "ipv4Vpn";
270 if (safi == SAFI_ENCAP)
271 return "ipv4Encap";
272 if (safi == SAFI_FLOWSPEC)
273 return "ipv4Flowspec";
274 } else if (afi == AFI_IP6) {
275 if (safi == SAFI_UNICAST)
276 return "ipv6Unicast";
277 if (safi == SAFI_MULTICAST)
278 return "ipv6Multicast";
279 if (safi == SAFI_LABELED_UNICAST)
280 return "ipv6LabeledUnicast";
281 if (safi == SAFI_MPLS_VPN)
282 return "ipv6Vpn";
283 if (safi == SAFI_ENCAP)
284 return "ipv6Encap";
285 if (safi == SAFI_FLOWSPEC)
286 return "ipv6Flowspec";
287 } else if (afi == AFI_L2VPN) {
288 if (safi == SAFI_EVPN)
289 return "l2VpnEvpn";
290 }
291
292 return "Unknown";
293 }
294
295 /* unset srv6 locator */
296 static int bgp_srv6_locator_unset(struct bgp *bgp)
297 {
298 int ret;
299 struct listnode *node, *nnode;
300 struct srv6_locator_chunk *chunk;
301 struct bgp_srv6_function *func;
302 struct bgp *bgp_vrf;
303
304 /* release chunk notification via ZAPI */
305 ret = bgp_zebra_srv6_manager_release_locator_chunk(
306 bgp->srv6_locator_name);
307 if (ret < 0)
308 return -1;
309
310 /* refresh chunks */
311 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
312 listnode_delete(bgp->srv6_locator_chunks, chunk);
313 srv6_locator_chunk_free(&chunk);
314 }
315
316 /* refresh functions */
317 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
318 listnode_delete(bgp->srv6_functions, func);
319 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
320 }
321
322 /* refresh tovpn_sid */
323 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
324 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
325 continue;
326
327 /* refresh vpnv4 tovpn_sid */
328 XFREE(MTYPE_BGP_SRV6_SID,
329 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
330
331 /* refresh vpnv6 tovpn_sid */
332 XFREE(MTYPE_BGP_SRV6_SID,
333 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
334
335 /* refresh per-vrf tovpn_sid */
336 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
337 }
338
339 /* update vpn bgp processes */
340 vpn_leak_postchange_all();
341
342 /* refresh tovpn_sid_locator */
343 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
344 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
345 continue;
346
347 /* refresh vpnv4 tovpn_sid_locator */
348 srv6_locator_chunk_free(
349 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
350
351 /* refresh vpnv6 tovpn_sid_locator */
352 srv6_locator_chunk_free(
353 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
354
355 /* refresh per-vrf tovpn_sid_locator */
356 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
357 }
358
359 /* clear locator name */
360 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
361
362 return 0;
363 }
364
365 /* Utility function to get address family from current node. */
366 afi_t bgp_node_afi(struct vty *vty)
367 {
368 afi_t afi;
369 switch (vty->node) {
370 case BGP_IPV6_NODE:
371 case BGP_IPV6M_NODE:
372 case BGP_IPV6L_NODE:
373 case BGP_VPNV6_NODE:
374 case BGP_FLOWSPECV6_NODE:
375 afi = AFI_IP6;
376 break;
377 case BGP_EVPN_NODE:
378 afi = AFI_L2VPN;
379 break;
380 default:
381 afi = AFI_IP;
382 break;
383 }
384 return afi;
385 }
386
387 /* Utility function to get subsequent address family from current
388 node. */
389 safi_t bgp_node_safi(struct vty *vty)
390 {
391 safi_t safi;
392 switch (vty->node) {
393 case BGP_VPNV4_NODE:
394 case BGP_VPNV6_NODE:
395 safi = SAFI_MPLS_VPN;
396 break;
397 case BGP_IPV4M_NODE:
398 case BGP_IPV6M_NODE:
399 safi = SAFI_MULTICAST;
400 break;
401 case BGP_EVPN_NODE:
402 safi = SAFI_EVPN;
403 break;
404 case BGP_IPV4L_NODE:
405 case BGP_IPV6L_NODE:
406 safi = SAFI_LABELED_UNICAST;
407 break;
408 case BGP_FLOWSPECV4_NODE:
409 case BGP_FLOWSPECV6_NODE:
410 safi = SAFI_FLOWSPEC;
411 break;
412 default:
413 safi = SAFI_UNICAST;
414 break;
415 }
416 return safi;
417 }
418
419 /**
420 * Converts an AFI in string form to afi_t
421 *
422 * @param afi string, one of
423 * - "ipv4"
424 * - "ipv6"
425 * - "l2vpn"
426 * @return the corresponding afi_t
427 */
428 afi_t bgp_vty_afi_from_str(const char *afi_str)
429 {
430 afi_t afi = AFI_MAX; /* unknown */
431 if (strmatch(afi_str, "ipv4"))
432 afi = AFI_IP;
433 else if (strmatch(afi_str, "ipv6"))
434 afi = AFI_IP6;
435 else if (strmatch(afi_str, "l2vpn"))
436 afi = AFI_L2VPN;
437 return afi;
438 }
439
440 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
441 afi_t *afi)
442 {
443 int ret = 0;
444 if (argv_find(argv, argc, "ipv4", index)) {
445 ret = 1;
446 if (afi)
447 *afi = AFI_IP;
448 } else if (argv_find(argv, argc, "ipv6", index)) {
449 ret = 1;
450 if (afi)
451 *afi = AFI_IP6;
452 } else if (argv_find(argv, argc, "l2vpn", index)) {
453 ret = 1;
454 if (afi)
455 *afi = AFI_L2VPN;
456 }
457 return ret;
458 }
459
460 /* supports <unicast|multicast|vpn|labeled-unicast> */
461 safi_t bgp_vty_safi_from_str(const char *safi_str)
462 {
463 safi_t safi = SAFI_MAX; /* unknown */
464 if (strmatch(safi_str, "multicast"))
465 safi = SAFI_MULTICAST;
466 else if (strmatch(safi_str, "unicast"))
467 safi = SAFI_UNICAST;
468 else if (strmatch(safi_str, "vpn"))
469 safi = SAFI_MPLS_VPN;
470 else if (strmatch(safi_str, "evpn"))
471 safi = SAFI_EVPN;
472 else if (strmatch(safi_str, "labeled-unicast"))
473 safi = SAFI_LABELED_UNICAST;
474 else if (strmatch(safi_str, "flowspec"))
475 safi = SAFI_FLOWSPEC;
476 return safi;
477 }
478
479 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
480 safi_t *safi)
481 {
482 int ret = 0;
483 if (argv_find(argv, argc, "unicast", index)) {
484 ret = 1;
485 if (safi)
486 *safi = SAFI_UNICAST;
487 } else if (argv_find(argv, argc, "multicast", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_MULTICAST;
491 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_LABELED_UNICAST;
495 } else if (argv_find(argv, argc, "vpn", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_MPLS_VPN;
499 } else if (argv_find(argv, argc, "evpn", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_EVPN;
503 } else if (argv_find(argv, argc, "flowspec", index)) {
504 ret = 1;
505 if (safi)
506 *safi = SAFI_FLOWSPEC;
507 }
508 return ret;
509 }
510
511 /*
512 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
513 *
514 * afi
515 * address-family identifier
516 *
517 * safi
518 * subsequent address-family identifier
519 *
520 * Returns:
521 * default_af string corresponding to the supplied afi/safi pair.
522 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
523 * return -1.
524 */
525 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
526 {
527 switch (afi) {
528 case AFI_IP:
529 switch (safi) {
530 case SAFI_UNICAST:
531 return "ipv4-unicast";
532 case SAFI_MULTICAST:
533 return "ipv4-multicast";
534 case SAFI_MPLS_VPN:
535 return "ipv4-vpn";
536 case SAFI_ENCAP:
537 return "ipv4-encap";
538 case SAFI_LABELED_UNICAST:
539 return "ipv4-labeled-unicast";
540 case SAFI_FLOWSPEC:
541 return "ipv4-flowspec";
542 default:
543 return "unknown-afi/safi";
544 }
545 break;
546 case AFI_IP6:
547 switch (safi) {
548 case SAFI_UNICAST:
549 return "ipv6-unicast";
550 case SAFI_MULTICAST:
551 return "ipv6-multicast";
552 case SAFI_MPLS_VPN:
553 return "ipv6-vpn";
554 case SAFI_ENCAP:
555 return "ipv6-encap";
556 case SAFI_LABELED_UNICAST:
557 return "ipv6-labeled-unicast";
558 case SAFI_FLOWSPEC:
559 return "ipv6-flowspec";
560 default:
561 return "unknown-afi/safi";
562 }
563 break;
564 case AFI_L2VPN:
565 switch (safi) {
566 case SAFI_EVPN:
567 return "l2vpn-evpn";
568 default:
569 return "unknown-afi/safi";
570 }
571 case AFI_UNSPEC:
572 case AFI_MAX:
573 return "unknown-afi/safi";
574 }
575 /* all AFIs are accounted for above, so this shouldn't happen */
576 return "unknown-afi/safi";
577 }
578
579 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
580 enum bgp_instance_type inst_type)
581 {
582 int ret = bgp_get(bgp, as, name, inst_type);
583
584 if (ret == BGP_CREATED) {
585 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
586 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
587
588 if (DFLT_BGP_IMPORT_CHECK)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
590 if (DFLT_BGP_SHOW_HOSTNAME)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
592 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
594 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
596 if (DFLT_BGP_DETERMINISTIC_MED)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
598 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
600 if (DFLT_BGP_SUPPRESS_DUPLICATES)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
602 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
604 if (DFLT_BGP_HARD_ADMIN_RESET)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
606
607 ret = BGP_SUCCESS;
608 }
609 return ret;
610 }
611
612 /*
613 * bgp_vty_find_and_parse_afi_safi_bgp
614 *
615 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
616 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
617 * to appropriate values for the calling function. This is to allow the
618 * calling function to make decisions appropriate for the show command
619 * that is being parsed.
620 *
621 * The show commands are generally of the form:
622 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
623 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
624 *
625 * Since we use argv_find if the show command in particular doesn't have:
626 * [ip]
627 * [<view|vrf> VIEWVRFNAME]
628 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
629 * The command parsing should still be ok.
630 *
631 * vty -> The vty for the command so we can output some useful data in
632 * the event of a parse error in the vrf.
633 * argv -> The command tokens
634 * argc -> How many command tokens we have
635 * idx -> The current place in the command, generally should be 0 for this
636 * function
637 * afi -> The parsed afi if it was included in the show command, returned here
638 * safi -> The parsed safi if it was included in the show command, returned here
639 * bgp -> Pointer to the bgp data structure we need to fill in.
640 * use_json -> json is configured or not
641 *
642 * The function returns the correct location in the parse tree for the
643 * last token found.
644 *
645 * Returns 0 for failure to parse correctly, else the idx position of where
646 * it found the last token.
647 */
648 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
649 struct cmd_token **argv, int argc,
650 int *idx, afi_t *afi, safi_t *safi,
651 struct bgp **bgp, bool use_json)
652 {
653 char *vrf_name = NULL;
654
655 assert(afi);
656 assert(safi);
657 assert(bgp);
658
659 if (argv_find(argv, argc, "ip", idx))
660 *afi = AFI_IP;
661
662 if (argv_find(argv, argc, "view", idx))
663 vrf_name = argv[*idx + 1]->arg;
664 else if (argv_find(argv, argc, "vrf", idx)) {
665 vrf_name = argv[*idx + 1]->arg;
666 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
667 vrf_name = NULL;
668 }
669 if (vrf_name) {
670 if (strmatch(vrf_name, "all"))
671 *bgp = NULL;
672 else {
673 *bgp = bgp_lookup_by_name(vrf_name);
674 if (!*bgp) {
675 if (use_json) {
676 json_object *json = NULL;
677 json = json_object_new_object();
678 json_object_string_add(
679 json, "warning",
680 "View/Vrf is unknown");
681 vty_json(vty, json);
682 }
683 else
684 vty_out(vty, "View/Vrf %s is unknown\n",
685 vrf_name);
686 *idx = 0;
687 return 0;
688 }
689 }
690 } else {
691 *bgp = bgp_get_default();
692 if (!*bgp) {
693 if (use_json) {
694 json_object *json = NULL;
695 json = json_object_new_object();
696 json_object_string_add(
697 json, "warning",
698 "Default BGP instance not found");
699 vty_json(vty, json);
700 }
701 else
702 vty_out(vty,
703 "Default BGP instance not found\n");
704 *idx = 0;
705 return 0;
706 }
707 }
708
709 if (argv_find_and_parse_afi(argv, argc, idx, afi))
710 argv_find_and_parse_safi(argv, argc, idx, safi);
711
712 *idx += 1;
713 return *idx;
714 }
715
716 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
717 {
718 struct interface *ifp = NULL;
719 struct listnode *node;
720 struct bgp_listener *listener;
721 union sockunion all_su;
722
723 if (su->sa.sa_family == AF_INET) {
724 (void)str2sockunion("0.0.0.0", &all_su);
725 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
726 } else if (su->sa.sa_family == AF_INET6) {
727 (void)str2sockunion("::", &all_su);
728 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
729 su->sin6.sin6_scope_id,
730 bgp->vrf_id);
731 }
732
733 if (ifp) {
734 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
735 if (sockunion_family(su) !=
736 sockunion_family(&listener->su))
737 continue;
738
739 /* If 0.0.0.0/:: is a listener, then treat as self and
740 * reject.
741 */
742 if (!sockunion_cmp(&listener->su, su) ||
743 !sockunion_cmp(&listener->su, &all_su))
744 return true;
745 }
746 }
747
748 return false;
749 }
750
751 /* Utility function for looking up peer from VTY. */
752 /* This is used only for configuration, so disallow if attempted on
753 * a dynamic neighbor.
754 */
755 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
756 {
757 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
758 int ret;
759 union sockunion su;
760 struct peer *peer;
761
762 if (!bgp) {
763 return NULL;
764 }
765
766 ret = str2sockunion(ip_str, &su);
767 if (ret < 0) {
768 peer = peer_lookup_by_conf_if(bgp, ip_str);
769 if (!peer) {
770 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
771 == NULL) {
772 vty_out(vty,
773 "%% Malformed address or name: %s\n",
774 ip_str);
775 return NULL;
776 }
777 }
778 } else {
779 peer = peer_lookup(bgp, &su);
780 if (!peer) {
781 vty_out(vty,
782 "%% Specify remote-as or peer-group commands first\n");
783 return NULL;
784 }
785 if (peer_dynamic_neighbor(peer)) {
786 vty_out(vty,
787 "%% Operation not allowed on a dynamic neighbor\n");
788 return NULL;
789 }
790 }
791 return peer;
792 }
793
794 /* Utility function for looking up peer or peer group. */
795 /* This is used only for configuration, so disallow if attempted on
796 * a dynamic neighbor.
797 */
798 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
799 {
800 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
801 int ret;
802 union sockunion su;
803 struct peer *peer = NULL;
804 struct peer_group *group = NULL;
805
806 if (!bgp) {
807 return NULL;
808 }
809
810 ret = str2sockunion(peer_str, &su);
811 if (ret == 0) {
812 /* IP address, locate peer. */
813 peer = peer_lookup(bgp, &su);
814 } else {
815 /* Not IP, could match either peer configured on interface or a
816 * group. */
817 peer = peer_lookup_by_conf_if(bgp, peer_str);
818 if (!peer)
819 group = peer_group_lookup(bgp, peer_str);
820 }
821
822 if (peer) {
823 if (peer_dynamic_neighbor(peer)) {
824 vty_out(vty,
825 "%% Operation not allowed on a dynamic neighbor\n");
826 return NULL;
827 }
828
829 return peer;
830 }
831
832 if (group)
833 return group->conf;
834
835 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
836
837 return NULL;
838 }
839
840 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
841 {
842 const char *str = NULL;
843
844 switch (ret) {
845 case BGP_SUCCESS:
846 case BGP_CREATED:
847 case BGP_GR_NO_OPERATION:
848 break;
849 case BGP_ERR_INVALID_VALUE:
850 str = "Invalid value";
851 break;
852 case BGP_ERR_INVALID_FLAG:
853 str = "Invalid flag";
854 break;
855 case BGP_ERR_PEER_GROUP_SHUTDOWN:
856 str = "Peer-group has been shutdown. Activate the peer-group first";
857 break;
858 case BGP_ERR_PEER_FLAG_CONFLICT:
859 str = "Can't set override-capability and strict-capability-match at the same time";
860 break;
861 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
862 str = "Specify remote-as or peer-group remote AS first";
863 break;
864 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
865 str = "Cannot change the peer-group. Deconfigure first";
866 break;
867 case BGP_ERR_PEER_GROUP_MISMATCH:
868 str = "Peer is not a member of this peer-group";
869 break;
870 case BGP_ERR_PEER_FILTER_CONFLICT:
871 str = "Prefix/distribute list can not co-exist";
872 break;
873 case BGP_ERR_NOT_INTERNAL_PEER:
874 str = "Invalid command. Not an internal neighbor";
875 break;
876 case BGP_ERR_REMOVE_PRIVATE_AS:
877 str = "remove-private-AS cannot be configured for IBGP peers";
878 break;
879 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
880 str = "Cannot have local-as same as BGP AS number";
881 break;
882 case BGP_ERR_TCPSIG_FAILED:
883 str = "Error while applying TCP-Sig to session(s)";
884 break;
885 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
886 str = "ebgp-multihop and ttl-security cannot be configured together";
887 break;
888 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
889 str = "ttl-security only allowed for EBGP peers";
890 break;
891 case BGP_ERR_AS_OVERRIDE:
892 str = "as-override cannot be configured for IBGP peers";
893 break;
894 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
895 str = "Invalid limit for number of dynamic neighbors";
896 break;
897 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
898 str = "Dynamic neighbor listen range already exists";
899 break;
900 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
901 str = "Operation not allowed on a dynamic neighbor";
902 break;
903 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
904 str = "Operation not allowed on a directly connected neighbor";
905 break;
906 case BGP_ERR_PEER_SAFI_CONFLICT:
907 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
908 break;
909 case BGP_ERR_GR_INVALID_CMD:
910 str = "The Graceful Restart command used is not valid at this moment.";
911 break;
912 case BGP_ERR_GR_OPERATION_FAILED:
913 str = "The Graceful Restart Operation failed due to an err.";
914 break;
915 case BGP_ERR_PEER_GROUP_MEMBER:
916 str = "Peer-group member cannot override remote-as of peer-group.";
917 break;
918 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
919 str = "Peer-group members must be all internal or all external.";
920 break;
921 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
922 str = "Range specified cannot be deleted because it is not part of current config.";
923 break;
924 case BGP_ERR_INSTANCE_MISMATCH:
925 str = "Instance specified does not match the current instance.";
926 break;
927 case BGP_ERR_NO_INTERFACE_CONFIG:
928 str = "Interface specified is not being used for interface based peer.";
929 break;
930 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
931 str = "No configuration already specified for soft reconfiguration.";
932 break;
933 case BGP_ERR_AS_MISMATCH:
934 str = "BGP is already running.";
935 break;
936 case BGP_ERR_AF_UNCONFIGURED:
937 str = "AFI/SAFI specified is not currently configured.";
938 break;
939 case BGP_ERR_INVALID_AS:
940 str = "Confederation AS specified is the same AS as our AS.";
941 break;
942 case BGP_ERR_INVALID_ROLE_NAME:
943 str = "Invalid role name";
944 break;
945 case BGP_ERR_INVALID_INTERNAL_ROLE:
946 str = "External roles can be set only on eBGP session";
947 break;
948 case BGP_ERR_PEER_ORR_CONFIGURED:
949 str = "Deconfigure optimal-route-reflection on this peer first";
950 break;
951 }
952 if (str) {
953 vty_out(vty, "%% %s\n", str);
954 return CMD_WARNING_CONFIG_FAILED;
955 }
956 return CMD_SUCCESS;
957 }
958
959 /* BGP clear sort. */
960 enum clear_sort {
961 clear_all,
962 clear_peer,
963 clear_group,
964 clear_external,
965 clear_as
966 };
967
968 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
969 safi_t safi, int error)
970 {
971 switch (error) {
972 case BGP_ERR_AF_UNCONFIGURED:
973 if (vty)
974 vty_out(vty,
975 "%% BGP: Enable %s address family for the neighbor %s\n",
976 get_afi_safi_str(afi, safi, false), peer->host);
977 else
978 zlog_warn(
979 "%% BGP: Enable %s address family for the neighbor %s",
980 get_afi_safi_str(afi, safi, false), peer->host);
981 break;
982 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
983 if (vty)
984 vty_out(vty,
985 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
986 peer->host);
987 else
988 zlog_warn(
989 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
990 peer->host);
991 break;
992 default:
993 break;
994 }
995 }
996
997 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
998 struct listnode **nnode, enum bgp_clear_type stype)
999 {
1000 int ret = 0;
1001 struct peer_af *paf;
1002
1003 /* if afi/.safi not specified, spin thru all of them */
1004 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1005 afi_t tmp_afi;
1006 safi_t tmp_safi;
1007 enum bgp_af_index index;
1008
1009 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1010 paf = peer->peer_af_array[index];
1011 if (!paf)
1012 continue;
1013
1014 if (paf && paf->subgroup)
1015 SET_FLAG(paf->subgroup->sflags,
1016 SUBGRP_STATUS_FORCE_UPDATES);
1017
1018 tmp_afi = paf->afi;
1019 tmp_safi = paf->safi;
1020 if (!peer->afc[tmp_afi][tmp_safi])
1021 continue;
1022
1023 if (stype == BGP_CLEAR_SOFT_NONE)
1024 ret = peer_clear(peer, nnode);
1025 else
1026 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1027 stype);
1028 }
1029 /* if afi specified and safi not, spin thru safis on this afi */
1030 } else if (safi == SAFI_UNSPEC) {
1031 safi_t tmp_safi;
1032
1033 for (tmp_safi = SAFI_UNICAST;
1034 tmp_safi < SAFI_MAX; tmp_safi++) {
1035 if (!peer->afc[afi][tmp_safi])
1036 continue;
1037
1038 paf = peer_af_find(peer, afi, tmp_safi);
1039 if (paf && paf->subgroup)
1040 SET_FLAG(paf->subgroup->sflags,
1041 SUBGRP_STATUS_FORCE_UPDATES);
1042
1043 if (stype == BGP_CLEAR_SOFT_NONE)
1044 ret = peer_clear(peer, nnode);
1045 else
1046 ret = peer_clear_soft(peer, afi,
1047 tmp_safi, stype);
1048 }
1049 /* both afi/safi specified, let the caller know if not defined */
1050 } else {
1051 if (!peer->afc[afi][safi])
1052 return 1;
1053
1054 paf = peer_af_find(peer, afi, safi);
1055 if (paf && paf->subgroup)
1056 SET_FLAG(paf->subgroup->sflags,
1057 SUBGRP_STATUS_FORCE_UPDATES);
1058
1059 if (stype == BGP_CLEAR_SOFT_NONE)
1060 ret = peer_clear(peer, nnode);
1061 else
1062 ret = peer_clear_soft(peer, afi, safi, stype);
1063 }
1064
1065 return ret;
1066 }
1067
1068 /* `clear ip bgp' functions. */
1069 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1070 enum clear_sort sort, enum bgp_clear_type stype,
1071 const char *arg)
1072 {
1073 int ret = 0;
1074 bool found = false;
1075 struct peer *peer;
1076
1077 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1078
1079 /* Clear all neighbors. */
1080 /*
1081 * Pass along pointer to next node to peer_clear() when walking all
1082 * nodes on the BGP instance as that may get freed if it is a
1083 * doppelganger
1084 */
1085 if (sort == clear_all) {
1086 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1087
1088 bgp_peer_gr_flags_update(peer);
1089
1090 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1091 gr_router_detected = true;
1092
1093 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1094 stype);
1095
1096 if (ret < 0)
1097 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1098 }
1099
1100 if (gr_router_detected
1101 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1102 bgp_zebra_send_capabilities(bgp, false);
1103 } else if (!gr_router_detected
1104 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1105 bgp_zebra_send_capabilities(bgp, true);
1106 }
1107
1108 /* This is to apply read-only mode on this clear. */
1109 if (stype == BGP_CLEAR_SOFT_NONE)
1110 bgp->update_delay_over = 0;
1111
1112 return CMD_SUCCESS;
1113 }
1114
1115 /* Clear specified neighbor. */
1116 if (sort == clear_peer) {
1117 union sockunion su;
1118
1119 /* Make sockunion for lookup. */
1120 ret = str2sockunion(arg, &su);
1121 if (ret < 0) {
1122 peer = peer_lookup_by_conf_if(bgp, arg);
1123 if (!peer) {
1124 peer = peer_lookup_by_hostname(bgp, arg);
1125 if (!peer) {
1126 vty_out(vty,
1127 "Malformed address or name: %s\n",
1128 arg);
1129 return CMD_WARNING;
1130 }
1131 }
1132 } else {
1133 peer = peer_lookup(bgp, &su);
1134 if (!peer) {
1135 vty_out(vty,
1136 "%% BGP: Unknown neighbor - \"%s\"\n",
1137 arg);
1138 return CMD_WARNING;
1139 }
1140 }
1141
1142 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1143 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1144
1145 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1146
1147 /* if afi/safi not defined for this peer, let caller know */
1148 if (ret == 1)
1149 ret = BGP_ERR_AF_UNCONFIGURED;
1150
1151 if (ret < 0)
1152 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1153
1154 return CMD_SUCCESS;
1155 }
1156
1157 /* Clear all neighbors belonging to a specific peer-group. */
1158 if (sort == clear_group) {
1159 struct peer_group *group;
1160
1161 group = peer_group_lookup(bgp, arg);
1162 if (!group) {
1163 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1164 return CMD_WARNING;
1165 }
1166
1167 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1168 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1169
1170 if (ret < 0)
1171 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1172 else
1173 found = true;
1174 }
1175
1176 if (!found)
1177 vty_out(vty,
1178 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1179 get_afi_safi_str(afi, safi, false), arg);
1180
1181 return CMD_SUCCESS;
1182 }
1183
1184 /* Clear all external (eBGP) neighbors. */
1185 if (sort == clear_external) {
1186 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1187 if (peer->sort == BGP_PEER_IBGP)
1188 continue;
1189
1190 bgp_peer_gr_flags_update(peer);
1191
1192 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1193 gr_router_detected = true;
1194
1195 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1196
1197 if (ret < 0)
1198 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1199 else
1200 found = true;
1201 }
1202
1203 if (gr_router_detected
1204 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1205 bgp_zebra_send_capabilities(bgp, false);
1206 } else if (!gr_router_detected
1207 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1208 bgp_zebra_send_capabilities(bgp, true);
1209 }
1210
1211 if (!found)
1212 vty_out(vty,
1213 "%% BGP: No external %s peer is configured\n",
1214 get_afi_safi_str(afi, safi, false));
1215
1216 return CMD_SUCCESS;
1217 }
1218
1219 /* Clear all neighbors belonging to a specific AS. */
1220 if (sort == clear_as) {
1221 as_t as = strtoul(arg, NULL, 10);
1222
1223 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1224 if (peer->as != as)
1225 continue;
1226
1227 bgp_peer_gr_flags_update(peer);
1228
1229 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1230 gr_router_detected = true;
1231
1232 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1233
1234 if (ret < 0)
1235 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1236 else
1237 found = true;
1238 }
1239
1240 if (gr_router_detected
1241 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1242 bgp_zebra_send_capabilities(bgp, false);
1243 } else if (!gr_router_detected
1244 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1245 bgp_zebra_send_capabilities(bgp, true);
1246 }
1247
1248 if (!found)
1249 vty_out(vty,
1250 "%% BGP: No %s peer is configured with AS %s\n",
1251 get_afi_safi_str(afi, safi, false), arg);
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 return CMD_SUCCESS;
1257 }
1258
1259 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1260 safi_t safi, enum clear_sort sort,
1261 enum bgp_clear_type stype, const char *arg)
1262 {
1263 struct bgp *bgp;
1264
1265 /* BGP structure lookup. */
1266 if (name) {
1267 bgp = bgp_lookup_by_name(name);
1268 if (bgp == NULL) {
1269 vty_out(vty, "Can't find BGP instance %s\n", name);
1270 return CMD_WARNING;
1271 }
1272 } else {
1273 bgp = bgp_get_default();
1274 if (bgp == NULL) {
1275 vty_out(vty, "No BGP process is configured\n");
1276 return CMD_WARNING;
1277 }
1278 }
1279
1280 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1281 }
1282
1283 /* clear soft inbound */
1284 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1285 {
1286 afi_t afi;
1287 safi_t safi;
1288
1289 FOREACH_AFI_SAFI (afi, safi)
1290 bgp_clear_vty(vty, name, afi, safi, clear_all,
1291 BGP_CLEAR_SOFT_IN, NULL);
1292 }
1293
1294 /* clear soft outbound */
1295 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1296 {
1297 afi_t afi;
1298 safi_t safi;
1299
1300 FOREACH_AFI_SAFI (afi, safi)
1301 bgp_clear_vty(vty, name, afi, safi, clear_all,
1302 BGP_CLEAR_SOFT_OUT, NULL);
1303 }
1304
1305
1306 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1307 {
1308 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1309 }
1310
1311 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1312 uint64_t flag, int set)
1313 {
1314 int ret;
1315 struct peer *peer;
1316
1317 peer = peer_and_group_lookup_vty(vty, ip_str);
1318 if (!peer)
1319 return CMD_WARNING_CONFIG_FAILED;
1320
1321 /*
1322 * If 'neighbor <interface>', then this is for directly connected peers,
1323 * we should not accept disable-connected-check.
1324 */
1325 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1326 vty_out(vty,
1327 "%s is directly connected peer, cannot accept disable-connected-check\n",
1328 ip_str);
1329 return CMD_WARNING_CONFIG_FAILED;
1330 }
1331
1332 if (!set && flag == PEER_FLAG_SHUTDOWN)
1333 peer_tx_shutdown_message_unset(peer);
1334
1335 if (set)
1336 ret = peer_flag_set(peer, flag);
1337 else
1338 ret = peer_flag_unset(peer, flag);
1339
1340 return bgp_vty_return(vty, ret);
1341 }
1342
1343 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1344 {
1345 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1346 }
1347
1348 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1349 uint64_t flag)
1350 {
1351 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1352 }
1353
1354 #include "bgpd/bgp_vty_clippy.c"
1355
1356 DEFUN_HIDDEN (bgp_local_mac,
1357 bgp_local_mac_cmd,
1358 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1359 BGP_STR
1360 "Local MAC config\n"
1361 "VxLAN Network Identifier\n"
1362 "VNI number\n"
1363 "local mac\n"
1364 "mac address\n"
1365 "mac-mobility sequence\n"
1366 "seq number\n")
1367 {
1368 int rv;
1369 vni_t vni;
1370 struct ethaddr mac;
1371 struct ipaddr ip;
1372 uint32_t seq;
1373 struct bgp *bgp;
1374
1375 vni = strtoul(argv[3]->arg, NULL, 10);
1376 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1377 vty_out(vty, "%% Malformed MAC address\n");
1378 return CMD_WARNING;
1379 }
1380 memset(&ip, 0, sizeof(ip));
1381 seq = strtoul(argv[7]->arg, NULL, 10);
1382
1383 bgp = bgp_get_default();
1384 if (!bgp) {
1385 vty_out(vty, "Default BGP instance is not there\n");
1386 return CMD_WARNING;
1387 }
1388
1389 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1390 zero_esi);
1391 if (rv < 0) {
1392 vty_out(vty, "Internal error\n");
1393 return CMD_WARNING;
1394 }
1395
1396 return CMD_SUCCESS;
1397 }
1398
1399 DEFUN_HIDDEN (no_bgp_local_mac,
1400 no_bgp_local_mac_cmd,
1401 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1402 NO_STR
1403 BGP_STR
1404 "Local MAC config\n"
1405 "VxLAN Network Identifier\n"
1406 "VNI number\n"
1407 "local mac\n"
1408 "mac address\n")
1409 {
1410 int rv;
1411 vni_t vni;
1412 struct ethaddr mac;
1413 struct ipaddr ip;
1414 struct bgp *bgp;
1415
1416 vni = strtoul(argv[4]->arg, NULL, 10);
1417 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1418 vty_out(vty, "%% Malformed MAC address\n");
1419 return CMD_WARNING;
1420 }
1421 memset(&ip, 0, sizeof(ip));
1422
1423 bgp = bgp_get_default();
1424 if (!bgp) {
1425 vty_out(vty, "Default BGP instance is not there\n");
1426 return CMD_WARNING;
1427 }
1428
1429 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1430 if (rv < 0) {
1431 vty_out(vty, "Internal error\n");
1432 return CMD_WARNING;
1433 }
1434
1435 return CMD_SUCCESS;
1436 }
1437
1438 DEFUN (no_synchronization,
1439 no_synchronization_cmd,
1440 "no synchronization",
1441 NO_STR
1442 "Perform IGP synchronization\n")
1443 {
1444 return CMD_SUCCESS;
1445 }
1446
1447 DEFUN (no_auto_summary,
1448 no_auto_summary_cmd,
1449 "no auto-summary",
1450 NO_STR
1451 "Enable automatic network number summarization\n")
1452 {
1453 return CMD_SUCCESS;
1454 }
1455
1456 /* "router bgp" commands. */
1457 DEFUN_NOSH (router_bgp,
1458 router_bgp_cmd,
1459 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1460 ROUTER_STR
1461 BGP_STR
1462 AS_STR
1463 BGP_INSTANCE_HELP_STR)
1464 {
1465 int idx_asn = 2;
1466 int idx_view_vrf = 3;
1467 int idx_vrf = 4;
1468 int is_new_bgp = 0;
1469 int ret;
1470 as_t as;
1471 struct bgp *bgp;
1472 const char *name = NULL;
1473 enum bgp_instance_type inst_type;
1474
1475 // "router bgp" without an ASN
1476 if (argc == 2) {
1477 // Pending: Make VRF option available for ASN less config
1478 bgp = bgp_get_default();
1479
1480 if (bgp == NULL) {
1481 vty_out(vty, "%% No BGP process is configured\n");
1482 return CMD_WARNING_CONFIG_FAILED;
1483 }
1484
1485 if (listcount(bm->bgp) > 1) {
1486 vty_out(vty, "%% Please specify ASN and VRF\n");
1487 return CMD_WARNING_CONFIG_FAILED;
1488 }
1489 }
1490
1491 // "router bgp X"
1492 else {
1493 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1494
1495 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1496 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1497 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1498
1499 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1500 if (argc > 3) {
1501 name = argv[idx_vrf]->arg;
1502
1503 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1504 if (strmatch(name, VRF_DEFAULT_NAME))
1505 name = NULL;
1506 else
1507 inst_type = BGP_INSTANCE_TYPE_VRF;
1508 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1509 inst_type = BGP_INSTANCE_TYPE_VIEW;
1510 }
1511
1512 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1513 is_new_bgp = (bgp_lookup(as, name) == NULL);
1514
1515 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1516 switch (ret) {
1517 case BGP_ERR_AS_MISMATCH:
1518 vty_out(vty, "BGP is already running; AS is %u\n", as);
1519 return CMD_WARNING_CONFIG_FAILED;
1520 case BGP_ERR_INSTANCE_MISMATCH:
1521 vty_out(vty,
1522 "BGP instance name and AS number mismatch\n");
1523 vty_out(vty,
1524 "BGP instance is already running; AS is %u\n",
1525 as);
1526 return CMD_WARNING_CONFIG_FAILED;
1527 }
1528
1529 /*
1530 * If we just instantiated the default instance, complete
1531 * any pending VRF-VPN leaking that was configured via
1532 * earlier "router bgp X vrf FOO" blocks.
1533 */
1534 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1535 vpn_leak_postchange_all();
1536
1537 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1538 bgp_vpn_leak_export(bgp);
1539 /* Pending: handle when user tries to change a view to vrf n vv.
1540 */
1541 }
1542
1543 /* unset the auto created flag as the user config is now present */
1544 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1545 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1546
1547 return CMD_SUCCESS;
1548 }
1549
1550 /* "no router bgp" commands. */
1551 DEFUN (no_router_bgp,
1552 no_router_bgp_cmd,
1553 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1554 NO_STR
1555 ROUTER_STR
1556 BGP_STR
1557 AS_STR
1558 BGP_INSTANCE_HELP_STR)
1559 {
1560 int idx_asn = 3;
1561 int idx_vrf = 5;
1562 as_t as;
1563 struct bgp *bgp;
1564 const char *name = NULL;
1565
1566 // "no router bgp" without an ASN
1567 if (argc == 3) {
1568 // Pending: Make VRF option available for ASN less config
1569 bgp = bgp_get_default();
1570
1571 if (bgp == NULL) {
1572 vty_out(vty, "%% No BGP process is configured\n");
1573 return CMD_WARNING_CONFIG_FAILED;
1574 }
1575
1576 if (listcount(bm->bgp) > 1) {
1577 vty_out(vty, "%% Please specify ASN and VRF\n");
1578 return CMD_WARNING_CONFIG_FAILED;
1579 }
1580
1581 if (bgp->l3vni) {
1582 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1583 bgp->l3vni);
1584 return CMD_WARNING_CONFIG_FAILED;
1585 }
1586 } else {
1587 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1588
1589 if (argc > 4) {
1590 name = argv[idx_vrf]->arg;
1591 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1592 && strmatch(name, VRF_DEFAULT_NAME))
1593 name = NULL;
1594 }
1595
1596 /* Lookup bgp structure. */
1597 bgp = bgp_lookup(as, name);
1598 if (!bgp) {
1599 vty_out(vty, "%% Can't find BGP instance\n");
1600 return CMD_WARNING_CONFIG_FAILED;
1601 }
1602
1603 if (bgp->l3vni) {
1604 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1605 bgp->l3vni);
1606 return CMD_WARNING_CONFIG_FAILED;
1607 }
1608
1609 /* Cannot delete default instance if vrf instances exist */
1610 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1611 struct listnode *node;
1612 struct bgp *tmp_bgp;
1613
1614 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1615 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1616 continue;
1617 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1618 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1619 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1620 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1621 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1622 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1623 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1624 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1625 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1626 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1627 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1628 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1629 (bgp == bgp_get_evpn() &&
1630 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1631 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1632 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1633 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1634 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1635 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1636 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1637 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1638 (hashcount(tmp_bgp->vnihash))) {
1639 vty_out(vty,
1640 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1641 return CMD_WARNING_CONFIG_FAILED;
1642 }
1643 }
1644 }
1645 }
1646
1647 bgp_delete(bgp);
1648
1649 return CMD_SUCCESS;
1650 }
1651
1652 /* bgp session-dscp */
1653
1654 DEFPY (bgp_session_dscp,
1655 bgp_session_dscp_cmd,
1656 "bgp session-dscp (0-63)$dscp",
1657 BGP_STR
1658 "Override default (C6) bgp TCP session DSCP value\n"
1659 "Manually configured dscp parameter\n")
1660 {
1661 bm->tcp_dscp = dscp << 2;
1662
1663 return CMD_SUCCESS;
1664 }
1665
1666 DEFPY (no_bgp_session_dscp,
1667 no_bgp_session_dscp_cmd,
1668 "no bgp session-dscp [(0-63)]",
1669 NO_STR
1670 BGP_STR
1671 "Override default (C6) bgp TCP session DSCP value\n"
1672 "Manually configured dscp parameter\n")
1673 {
1674 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1675
1676 return CMD_SUCCESS;
1677 }
1678
1679 /* BGP router-id. */
1680
1681 DEFPY (bgp_router_id,
1682 bgp_router_id_cmd,
1683 "bgp router-id A.B.C.D",
1684 BGP_STR
1685 "Override configured router identifier\n"
1686 "Manually configured router identifier\n")
1687 {
1688 VTY_DECLVAR_CONTEXT(bgp, bgp);
1689 bgp_router_id_static_set(bgp, router_id);
1690 return CMD_SUCCESS;
1691 }
1692
1693 DEFPY (no_bgp_router_id,
1694 no_bgp_router_id_cmd,
1695 "no bgp router-id [A.B.C.D]",
1696 NO_STR
1697 BGP_STR
1698 "Override configured router identifier\n"
1699 "Manually configured router identifier\n")
1700 {
1701 VTY_DECLVAR_CONTEXT(bgp, bgp);
1702
1703 if (router_id_str) {
1704 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1705 vty_out(vty, "%% BGP router-id doesn't match\n");
1706 return CMD_WARNING_CONFIG_FAILED;
1707 }
1708 }
1709
1710 router_id.s_addr = 0;
1711 bgp_router_id_static_set(bgp, router_id);
1712
1713 return CMD_SUCCESS;
1714 }
1715
1716 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1717 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1718 NO_STR BGP_STR
1719 "Add community specific parameters\n"
1720 "Create an alias for a community\n"
1721 "Community (AA:BB or AA:BB:CC)\n"
1722 "Alias name\n")
1723 {
1724 struct community_alias ca = {};
1725 struct community_alias *lookup_community;
1726 struct community_alias *lookup_alias;
1727 struct community *comm;
1728 struct lcommunity *lcomm;
1729 uint8_t invalid = 0;
1730
1731 comm = community_str2com(community);
1732 if (!comm)
1733 invalid++;
1734 community_free(&comm);
1735
1736 lcomm = lcommunity_str2com(community);
1737 if (!lcomm)
1738 invalid++;
1739 lcommunity_free(&lcomm);
1740
1741 if (invalid > 1) {
1742 vty_out(vty, "Invalid community format\n");
1743 return CMD_WARNING;
1744 }
1745
1746 strlcpy(ca.community, community, sizeof(ca.community));
1747 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1748
1749 lookup_community = bgp_ca_community_lookup(&ca);
1750 lookup_alias = bgp_ca_alias_lookup(&ca);
1751
1752 if (no) {
1753 bgp_ca_alias_delete(&ca);
1754 bgp_ca_community_delete(&ca);
1755 } else {
1756 if (lookup_alias) {
1757 /* Lookup if community hash table has an item
1758 * with the same alias name.
1759 */
1760 strlcpy(ca.community, lookup_alias->community,
1761 sizeof(ca.community));
1762 if (bgp_ca_community_lookup(&ca)) {
1763 vty_out(vty,
1764 "community (%s) already has this alias (%s)\n",
1765 lookup_alias->community,
1766 lookup_alias->alias);
1767 return CMD_WARNING;
1768 }
1769 bgp_ca_alias_delete(&ca);
1770 }
1771
1772 if (lookup_community) {
1773 /* Lookup if alias hash table has an item
1774 * with the same community.
1775 */
1776 strlcpy(ca.alias, lookup_community->alias,
1777 sizeof(ca.alias));
1778 if (bgp_ca_alias_lookup(&ca)) {
1779 vty_out(vty,
1780 "alias (%s) already has this community (%s)\n",
1781 lookup_community->alias,
1782 lookup_community->community);
1783 return CMD_WARNING;
1784 }
1785 bgp_ca_community_delete(&ca);
1786 }
1787
1788 bgp_ca_alias_insert(&ca);
1789 bgp_ca_community_insert(&ca);
1790 }
1791
1792 return CMD_SUCCESS;
1793 }
1794
1795 DEFPY (bgp_global_suppress_fib_pending,
1796 bgp_global_suppress_fib_pending_cmd,
1797 "[no] bgp suppress-fib-pending",
1798 NO_STR
1799 BGP_STR
1800 "Advertise only routes that are programmed in kernel to peers globally\n")
1801 {
1802 bm_wait_for_fib_set(!no);
1803
1804 return CMD_SUCCESS;
1805 }
1806
1807 DEFPY (bgp_suppress_fib_pending,
1808 bgp_suppress_fib_pending_cmd,
1809 "[no] bgp suppress-fib-pending",
1810 NO_STR
1811 BGP_STR
1812 "Advertise only routes that are programmed in kernel to peers\n")
1813 {
1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
1815
1816 bgp_suppress_fib_pending_set(bgp, !no);
1817 return CMD_SUCCESS;
1818 }
1819
1820
1821 /* BGP Cluster ID. */
1822 DEFUN (bgp_cluster_id,
1823 bgp_cluster_id_cmd,
1824 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1825 BGP_STR
1826 "Configure Route-Reflector Cluster-id\n"
1827 "Route-Reflector Cluster-id in IP address format\n"
1828 "Route-Reflector Cluster-id as 32 bit quantity\n")
1829 {
1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
1831 int idx_ipv4 = 2;
1832 int ret;
1833 struct in_addr cluster;
1834
1835 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1836 if (!ret) {
1837 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1838 return CMD_WARNING_CONFIG_FAILED;
1839 }
1840
1841 bgp_cluster_id_set(bgp, &cluster);
1842 bgp_clear_star_soft_out(vty, bgp->name);
1843
1844 return CMD_SUCCESS;
1845 }
1846
1847 DEFUN (no_bgp_cluster_id,
1848 no_bgp_cluster_id_cmd,
1849 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1850 NO_STR
1851 BGP_STR
1852 "Configure Route-Reflector Cluster-id\n"
1853 "Route-Reflector Cluster-id in IP address format\n"
1854 "Route-Reflector Cluster-id as 32 bit quantity\n")
1855 {
1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 bgp_cluster_id_unset(bgp);
1858 bgp_clear_star_soft_out(vty, bgp->name);
1859
1860 return CMD_SUCCESS;
1861 }
1862
1863 DEFPY (bgp_norib,
1864 bgp_norib_cmd,
1865 "bgp no-rib",
1866 BGP_STR
1867 "Disable BGP route installation to RIB (Zebra)\n")
1868 {
1869 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1870 vty_out(vty,
1871 "%% No-RIB option is already set, nothing to do here.\n");
1872 return CMD_SUCCESS;
1873 }
1874
1875 bgp_option_norib_set_runtime();
1876
1877 return CMD_SUCCESS;
1878 }
1879
1880 DEFPY (no_bgp_norib,
1881 no_bgp_norib_cmd,
1882 "no bgp no-rib",
1883 NO_STR
1884 BGP_STR
1885 "Disable BGP route installation to RIB (Zebra)\n")
1886 {
1887 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1888 vty_out(vty,
1889 "%% No-RIB option is not set, nothing to do here.\n");
1890 return CMD_SUCCESS;
1891 }
1892
1893 bgp_option_norib_unset_runtime();
1894
1895 return CMD_SUCCESS;
1896 }
1897
1898 DEFPY (no_bgp_send_extra_data,
1899 no_bgp_send_extra_data_cmd,
1900 "[no] bgp send-extra-data zebra",
1901 NO_STR
1902 BGP_STR
1903 "Extra data to Zebra for display/use\n"
1904 "To zebra\n")
1905 {
1906 if (no)
1907 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1908 else
1909 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1910
1911 return CMD_SUCCESS;
1912 }
1913
1914 DEFUN (bgp_confederation_identifier,
1915 bgp_confederation_identifier_cmd,
1916 "bgp confederation identifier (1-4294967295)",
1917 BGP_STR
1918 "AS confederation parameters\n"
1919 "AS number\n"
1920 "Set routing domain confederation AS\n")
1921 {
1922 VTY_DECLVAR_CONTEXT(bgp, bgp);
1923 int idx_number = 3;
1924 as_t as;
1925
1926 as = strtoul(argv[idx_number]->arg, NULL, 10);
1927
1928 bgp_confederation_id_set(bgp, as);
1929
1930 return CMD_SUCCESS;
1931 }
1932
1933 DEFUN (no_bgp_confederation_identifier,
1934 no_bgp_confederation_identifier_cmd,
1935 "no bgp confederation identifier [(1-4294967295)]",
1936 NO_STR
1937 BGP_STR
1938 "AS confederation parameters\n"
1939 "AS number\n"
1940 "Set routing domain confederation AS\n")
1941 {
1942 VTY_DECLVAR_CONTEXT(bgp, bgp);
1943 bgp_confederation_id_unset(bgp);
1944
1945 return CMD_SUCCESS;
1946 }
1947
1948 DEFUN (bgp_confederation_peers,
1949 bgp_confederation_peers_cmd,
1950 "bgp confederation peers (1-4294967295)...",
1951 BGP_STR
1952 "AS confederation parameters\n"
1953 "Peer ASs in BGP confederation\n"
1954 AS_STR)
1955 {
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957 int idx_asn = 3;
1958 as_t as;
1959 int i;
1960
1961 for (i = idx_asn; i < argc; i++) {
1962 as = strtoul(argv[i]->arg, NULL, 10);
1963 bgp_confederation_peers_add(bgp, as);
1964 }
1965 return CMD_SUCCESS;
1966 }
1967
1968 DEFUN (no_bgp_confederation_peers,
1969 no_bgp_confederation_peers_cmd,
1970 "no bgp confederation peers (1-4294967295)...",
1971 NO_STR
1972 BGP_STR
1973 "AS confederation parameters\n"
1974 "Peer ASs in BGP confederation\n"
1975 AS_STR)
1976 {
1977 VTY_DECLVAR_CONTEXT(bgp, bgp);
1978 int idx_asn = 4;
1979 as_t as;
1980 int i;
1981
1982 for (i = idx_asn; i < argc; i++) {
1983 as = strtoul(argv[i]->arg, NULL, 10);
1984
1985 bgp_confederation_peers_remove(bgp, as);
1986 }
1987 return CMD_SUCCESS;
1988 }
1989
1990 /**
1991 * Central routine for maximum-paths configuration.
1992 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1993 * @set: 1 for setting values, 0 for removing the max-paths config.
1994 */
1995 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1996 const char *mpaths, uint16_t options,
1997 int set)
1998 {
1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000 uint16_t maxpaths = 0;
2001 int ret;
2002 afi_t afi;
2003 safi_t safi;
2004
2005 afi = bgp_node_afi(vty);
2006 safi = bgp_node_safi(vty);
2007
2008 if (set) {
2009 maxpaths = strtol(mpaths, NULL, 10);
2010 if (maxpaths > multipath_num) {
2011 vty_out(vty,
2012 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2013 maxpaths, multipath_num);
2014 return CMD_WARNING_CONFIG_FAILED;
2015 }
2016 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2017 options);
2018 } else
2019 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2020
2021 if (ret < 0) {
2022 vty_out(vty,
2023 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2024 (set == 1) ? "" : "un",
2025 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2026 maxpaths, afi, safi);
2027 return CMD_WARNING_CONFIG_FAILED;
2028 }
2029
2030 bgp_recalculate_all_bestpaths(bgp);
2031
2032 return CMD_SUCCESS;
2033 }
2034
2035 DEFUN (bgp_maxmed_admin,
2036 bgp_maxmed_admin_cmd,
2037 "bgp max-med administrative ",
2038 BGP_STR
2039 "Advertise routes with max-med\n"
2040 "Administratively applied, for an indefinite period\n")
2041 {
2042 VTY_DECLVAR_CONTEXT(bgp, bgp);
2043
2044 bgp->v_maxmed_admin = 1;
2045 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2046
2047 bgp_maxmed_update(bgp);
2048
2049 return CMD_SUCCESS;
2050 }
2051
2052 DEFUN (bgp_maxmed_admin_medv,
2053 bgp_maxmed_admin_medv_cmd,
2054 "bgp max-med administrative (0-4294967295)",
2055 BGP_STR
2056 "Advertise routes with max-med\n"
2057 "Administratively applied, for an indefinite period\n"
2058 "Max MED value to be used\n")
2059 {
2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
2061 int idx_number = 3;
2062
2063 bgp->v_maxmed_admin = 1;
2064 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2065
2066 bgp_maxmed_update(bgp);
2067
2068 return CMD_SUCCESS;
2069 }
2070
2071 DEFUN (no_bgp_maxmed_admin,
2072 no_bgp_maxmed_admin_cmd,
2073 "no bgp max-med administrative [(0-4294967295)]",
2074 NO_STR
2075 BGP_STR
2076 "Advertise routes with max-med\n"
2077 "Administratively applied, for an indefinite period\n"
2078 "Max MED value to be used\n")
2079 {
2080 VTY_DECLVAR_CONTEXT(bgp, bgp);
2081 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2082 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2083 bgp_maxmed_update(bgp);
2084
2085 return CMD_SUCCESS;
2086 }
2087
2088 DEFUN (bgp_maxmed_onstartup,
2089 bgp_maxmed_onstartup_cmd,
2090 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2091 BGP_STR
2092 "Advertise routes with max-med\n"
2093 "Effective on a startup\n"
2094 "Time (seconds) period for max-med\n"
2095 "Max MED value to be used\n")
2096 {
2097 VTY_DECLVAR_CONTEXT(bgp, bgp);
2098 int idx = 0;
2099
2100 if (argv_find(argv, argc, "(5-86400)", &idx))
2101 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2102 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2103 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2104 else
2105 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2106
2107 bgp_maxmed_update(bgp);
2108
2109 return CMD_SUCCESS;
2110 }
2111
2112 DEFUN (no_bgp_maxmed_onstartup,
2113 no_bgp_maxmed_onstartup_cmd,
2114 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2115 NO_STR
2116 BGP_STR
2117 "Advertise routes with max-med\n"
2118 "Effective on a startup\n"
2119 "Time (seconds) period for max-med\n"
2120 "Max MED value to be used\n")
2121 {
2122 VTY_DECLVAR_CONTEXT(bgp, bgp);
2123
2124 /* Cancel max-med onstartup if its on */
2125 if (bgp->t_maxmed_onstartup) {
2126 THREAD_OFF(bgp->t_maxmed_onstartup);
2127 bgp->maxmed_onstartup_over = 1;
2128 }
2129
2130 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2131 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2132
2133 bgp_maxmed_update(bgp);
2134
2135 return CMD_SUCCESS;
2136 }
2137
2138 static int bgp_global_update_delay_config_vty(struct vty *vty,
2139 uint16_t update_delay,
2140 uint16_t establish_wait)
2141 {
2142 struct listnode *node, *nnode;
2143 struct bgp *bgp;
2144 bool vrf_cfg = false;
2145
2146 /*
2147 * See if update-delay is set per-vrf and warn user to delete it
2148 * Note that we only need to check this if this is the first time
2149 * setting the global config.
2150 */
2151 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2152 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2153 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2154 vty_out(vty,
2155 "%% update-delay configuration found in vrf %s\n",
2156 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2157 ? VRF_DEFAULT_NAME
2158 : bgp->name);
2159 vrf_cfg = true;
2160 }
2161 }
2162 }
2163
2164 if (vrf_cfg) {
2165 vty_out(vty,
2166 "%%Failed: global update-delay config not permitted\n");
2167 return CMD_WARNING;
2168 }
2169
2170 if (!establish_wait) { /* update-delay <delay> */
2171 bm->v_update_delay = update_delay;
2172 bm->v_establish_wait = bm->v_update_delay;
2173 } else {
2174 /* update-delay <delay> <establish-wait> */
2175 if (update_delay < establish_wait) {
2176 vty_out(vty,
2177 "%%Failed: update-delay less than the establish-wait!\n");
2178 return CMD_WARNING_CONFIG_FAILED;
2179 }
2180
2181 bm->v_update_delay = update_delay;
2182 bm->v_establish_wait = establish_wait;
2183 }
2184
2185 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2186 bgp->v_update_delay = bm->v_update_delay;
2187 bgp->v_establish_wait = bm->v_establish_wait;
2188 }
2189
2190 return CMD_SUCCESS;
2191 }
2192
2193 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2194 {
2195 struct listnode *node, *nnode;
2196 struct bgp *bgp;
2197
2198 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2199 bm->v_establish_wait = bm->v_update_delay;
2200
2201 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2202 bgp->v_update_delay = bm->v_update_delay;
2203 bgp->v_establish_wait = bm->v_establish_wait;
2204 }
2205
2206 return CMD_SUCCESS;
2207 }
2208
2209 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2210 uint16_t establish_wait)
2211 {
2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213
2214 /* if configured globally, per-instance config is not allowed */
2215 if (bm->v_update_delay) {
2216 vty_out(vty,
2217 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2218 return CMD_WARNING_CONFIG_FAILED;
2219 }
2220
2221
2222 if (!establish_wait) /* update-delay <delay> */
2223 {
2224 bgp->v_update_delay = update_delay;
2225 bgp->v_establish_wait = bgp->v_update_delay;
2226 return CMD_SUCCESS;
2227 }
2228
2229 /* update-delay <delay> <establish-wait> */
2230 if (update_delay < establish_wait) {
2231 vty_out(vty,
2232 "%%Failed: update-delay less than the establish-wait!\n");
2233 return CMD_WARNING_CONFIG_FAILED;
2234 }
2235
2236 bgp->v_update_delay = update_delay;
2237 bgp->v_establish_wait = establish_wait;
2238
2239 return CMD_SUCCESS;
2240 }
2241
2242 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2243 {
2244 VTY_DECLVAR_CONTEXT(bgp, bgp);
2245
2246 /* If configured globally, cannot remove from one bgp instance */
2247 if (bm->v_update_delay) {
2248 vty_out(vty,
2249 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2250 return CMD_WARNING_CONFIG_FAILED;
2251 }
2252 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2253 bgp->v_establish_wait = bgp->v_update_delay;
2254
2255 return CMD_SUCCESS;
2256 }
2257
2258 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2259 {
2260 /* If configured globally, no need to display per-instance value */
2261 if (bgp->v_update_delay != bm->v_update_delay) {
2262 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2263 if (bgp->v_update_delay != bgp->v_establish_wait)
2264 vty_out(vty, " %d", bgp->v_establish_wait);
2265 vty_out(vty, "\n");
2266 }
2267 }
2268
2269 /* Global update-delay configuration */
2270 DEFPY (bgp_global_update_delay,
2271 bgp_global_update_delay_cmd,
2272 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2273 BGP_STR
2274 "Force initial delay for best-path and updates for all bgp instances\n"
2275 "Max delay in seconds\n"
2276 "Establish wait in seconds\n")
2277 {
2278 return bgp_global_update_delay_config_vty(vty, delay, wait);
2279 }
2280
2281 /* Global update-delay deconfiguration */
2282 DEFPY (no_bgp_global_update_delay,
2283 no_bgp_global_update_delay_cmd,
2284 "no bgp update-delay [(0-3600) [(1-3600)]]",
2285 NO_STR
2286 BGP_STR
2287 "Force initial delay for best-path and updates\n"
2288 "Max delay in seconds\n"
2289 "Establish wait in seconds\n")
2290 {
2291 return bgp_global_update_delay_deconfig_vty(vty);
2292 }
2293
2294 /* Update-delay configuration */
2295
2296 DEFPY (bgp_update_delay,
2297 bgp_update_delay_cmd,
2298 "update-delay (0-3600)$delay [(1-3600)$wait]",
2299 "Force initial delay for best-path and updates\n"
2300 "Max delay in seconds\n"
2301 "Establish wait in seconds\n")
2302 {
2303 return bgp_update_delay_config_vty(vty, delay, wait);
2304 }
2305
2306 /* Update-delay deconfiguration */
2307 DEFPY (no_bgp_update_delay,
2308 no_bgp_update_delay_cmd,
2309 "no update-delay [(0-3600) [(1-3600)]]",
2310 NO_STR
2311 "Force initial delay for best-path and updates\n"
2312 "Max delay in seconds\n"
2313 "Establish wait in seconds\n")
2314 {
2315 return bgp_update_delay_deconfig_vty(vty);
2316 }
2317
2318
2319 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2320 bool set)
2321 {
2322 VTY_DECLVAR_CONTEXT(bgp, bgp);
2323
2324 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2325 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2326
2327 return CMD_SUCCESS;
2328 }
2329
2330 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2331 bool set)
2332 {
2333 VTY_DECLVAR_CONTEXT(bgp, bgp);
2334
2335 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2336 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2337
2338 return CMD_SUCCESS;
2339 }
2340
2341 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2342 {
2343 uint32_t quanta =
2344 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2345 if (quanta != BGP_WRITE_PACKET_MAX)
2346 vty_out(vty, " write-quanta %d\n", quanta);
2347 }
2348
2349 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2350 {
2351 uint32_t quanta =
2352 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2353 if (quanta != BGP_READ_PACKET_MAX)
2354 vty_out(vty, " read-quanta %d\n", quanta);
2355 }
2356
2357 /* Packet quanta configuration
2358 *
2359 * XXX: The value set here controls the size of a stack buffer in the IO
2360 * thread. When changing these limits be careful to prevent stack overflow.
2361 *
2362 * Furthermore, the maximums used here should correspond to
2363 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2364 */
2365 DEFPY (bgp_wpkt_quanta,
2366 bgp_wpkt_quanta_cmd,
2367 "[no] write-quanta (1-64)$quanta",
2368 NO_STR
2369 "How many packets to write to peer socket per run\n"
2370 "Number of packets\n")
2371 {
2372 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2373 }
2374
2375 DEFPY (bgp_rpkt_quanta,
2376 bgp_rpkt_quanta_cmd,
2377 "[no] read-quanta (1-10)$quanta",
2378 NO_STR
2379 "How many packets to read from peer socket per I/O cycle\n"
2380 "Number of packets\n")
2381 {
2382 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2383 }
2384
2385 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2386 {
2387 if (!bgp->heuristic_coalesce)
2388 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2389 }
2390
2391 /* BGP TCP keepalive */
2392 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2393 {
2394 if (bgp->tcp_keepalive_idle) {
2395 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2396 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2397 bgp->tcp_keepalive_probes);
2398 }
2399 }
2400
2401 DEFUN (bgp_coalesce_time,
2402 bgp_coalesce_time_cmd,
2403 "coalesce-time (0-4294967295)",
2404 "Subgroup coalesce timer\n"
2405 "Subgroup coalesce timer value (in ms)\n")
2406 {
2407 VTY_DECLVAR_CONTEXT(bgp, bgp);
2408
2409 int idx = 0;
2410
2411 bgp->heuristic_coalesce = false;
2412
2413 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2414 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2415
2416 return CMD_SUCCESS;
2417 }
2418
2419 DEFUN (no_bgp_coalesce_time,
2420 no_bgp_coalesce_time_cmd,
2421 "no coalesce-time (0-4294967295)",
2422 NO_STR
2423 "Subgroup coalesce timer\n"
2424 "Subgroup coalesce timer value (in ms)\n")
2425 {
2426 VTY_DECLVAR_CONTEXT(bgp, bgp);
2427
2428 bgp->heuristic_coalesce = true;
2429 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2430 return CMD_SUCCESS;
2431 }
2432
2433 /* Maximum-paths configuration */
2434 DEFUN (bgp_maxpaths,
2435 bgp_maxpaths_cmd,
2436 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2437 "Forward packets over multiple paths\n"
2438 "Number of paths\n")
2439 {
2440 int idx_number = 1;
2441 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2442 argv[idx_number]->arg, 0, 1);
2443 }
2444
2445 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2446 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2447 "Forward packets over multiple paths\n"
2448 "Number of paths\n")
2449
2450 DEFUN (bgp_maxpaths_ibgp,
2451 bgp_maxpaths_ibgp_cmd,
2452 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2453 "Forward packets over multiple paths\n"
2454 "iBGP-multipath\n"
2455 "Number of paths\n")
2456 {
2457 int idx_number = 2;
2458 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2459 argv[idx_number]->arg, 0, 1);
2460 }
2461
2462 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2463 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2464 "Forward packets over multiple paths\n"
2465 "iBGP-multipath\n"
2466 "Number of paths\n")
2467
2468 DEFUN (bgp_maxpaths_ibgp_cluster,
2469 bgp_maxpaths_ibgp_cluster_cmd,
2470 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2471 "Forward packets over multiple paths\n"
2472 "iBGP-multipath\n"
2473 "Number of paths\n"
2474 "Match the cluster length\n")
2475 {
2476 int idx_number = 2;
2477 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2478 argv[idx_number]->arg, true, 1);
2479 }
2480
2481 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2482 "maximum-paths ibgp " CMD_RANGE_STR(
2483 1, MULTIPATH_NUM) " equal-cluster-length",
2484 "Forward packets over multiple paths\n"
2485 "iBGP-multipath\n"
2486 "Number of paths\n"
2487 "Match the cluster length\n")
2488
2489 DEFUN (no_bgp_maxpaths,
2490 no_bgp_maxpaths_cmd,
2491 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2492 NO_STR
2493 "Forward packets over multiple paths\n"
2494 "Number of paths\n")
2495 {
2496 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2497 }
2498
2499 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2500 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2501 "Forward packets over multiple paths\n"
2502 "Number of paths\n")
2503
2504 DEFUN (no_bgp_maxpaths_ibgp,
2505 no_bgp_maxpaths_ibgp_cmd,
2506 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2507 NO_STR
2508 "Forward packets over multiple paths\n"
2509 "iBGP-multipath\n"
2510 "Number of paths\n"
2511 "Match the cluster length\n")
2512 {
2513 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2514 }
2515
2516 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2517 "no maximum-paths ibgp [" CMD_RANGE_STR(
2518 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2519 NO_STR
2520 "Forward packets over multiple paths\n"
2521 "iBGP-multipath\n"
2522 "Number of paths\n"
2523 "Match the cluster length\n")
2524
2525 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2526 afi_t afi, safi_t safi)
2527 {
2528 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2529 vty_out(vty, " maximum-paths %d\n",
2530 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2531 }
2532
2533 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2534 vty_out(vty, " maximum-paths ibgp %d",
2535 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2536 if (bgp->maxpaths[afi][safi].same_clusterlen)
2537 vty_out(vty, " equal-cluster-length");
2538 vty_out(vty, "\n");
2539 }
2540 }
2541
2542 /* BGP timers. */
2543
2544 DEFUN (bgp_timers,
2545 bgp_timers_cmd,
2546 "timers bgp (0-65535) (0-65535)",
2547 "Adjust routing timers\n"
2548 "BGP timers\n"
2549 "Keepalive interval\n"
2550 "Holdtime\n")
2551 {
2552 VTY_DECLVAR_CONTEXT(bgp, bgp);
2553 int idx_number = 2;
2554 int idx_number_2 = 3;
2555 unsigned long keepalive = 0;
2556 unsigned long holdtime = 0;
2557
2558 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2559 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2560
2561 /* Holdtime value check. */
2562 if (holdtime < 3 && holdtime != 0) {
2563 vty_out(vty,
2564 "%% hold time value must be either 0 or greater than 3\n");
2565 return CMD_WARNING_CONFIG_FAILED;
2566 }
2567
2568 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2569 BGP_DEFAULT_DELAYOPEN);
2570
2571 return CMD_SUCCESS;
2572 }
2573
2574 DEFUN (no_bgp_timers,
2575 no_bgp_timers_cmd,
2576 "no timers bgp [(0-65535) (0-65535)]",
2577 NO_STR
2578 "Adjust routing timers\n"
2579 "BGP timers\n"
2580 "Keepalive interval\n"
2581 "Holdtime\n")
2582 {
2583 VTY_DECLVAR_CONTEXT(bgp, bgp);
2584 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2585 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2586
2587 return CMD_SUCCESS;
2588 }
2589
2590 /* BGP minimum holdtime. */
2591
2592 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2593 "bgp minimum-holdtime (1-65535)",
2594 "BGP specific commands\n"
2595 "BGP minimum holdtime\n"
2596 "Seconds\n")
2597 {
2598 VTY_DECLVAR_CONTEXT(bgp, bgp);
2599 int idx_number = 2;
2600 unsigned long min_holdtime;
2601
2602 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2603
2604 bgp->default_min_holdtime = min_holdtime;
2605
2606 return CMD_SUCCESS;
2607 }
2608
2609 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2610 "no bgp minimum-holdtime [(1-65535)]",
2611 NO_STR
2612 "BGP specific commands\n"
2613 "BGP minimum holdtime\n"
2614 "Seconds\n")
2615 {
2616 VTY_DECLVAR_CONTEXT(bgp, bgp);
2617
2618 bgp->default_min_holdtime = 0;
2619
2620 return CMD_SUCCESS;
2621 }
2622
2623 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2624 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2625 BGP_STR
2626 "TCP keepalive parameters\n"
2627 "TCP keepalive idle time (seconds)\n"
2628 "TCP keepalive interval (seconds)\n"
2629 "TCP keepalive maximum probes\n")
2630 {
2631 VTY_DECLVAR_CONTEXT(bgp, bgp);
2632
2633 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2634 (uint16_t)probes);
2635
2636 return CMD_SUCCESS;
2637 }
2638
2639 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2640 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2641 NO_STR
2642 BGP_STR
2643 "TCP keepalive parameters\n"
2644 "TCP keepalive idle time (seconds)\n"
2645 "TCP keepalive interval (seconds)\n"
2646 "TCP keepalive maximum probes\n")
2647 {
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
2649
2650 bgp_tcp_keepalive_unset(bgp);
2651
2652 return CMD_SUCCESS;
2653 }
2654
2655 DEFUN (bgp_client_to_client_reflection,
2656 bgp_client_to_client_reflection_cmd,
2657 "bgp client-to-client reflection",
2658 BGP_STR
2659 "Configure client to client route reflection\n"
2660 "reflection of routes allowed\n")
2661 {
2662 VTY_DECLVAR_CONTEXT(bgp, bgp);
2663 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2664 bgp_clear_star_soft_out(vty, bgp->name);
2665
2666 return CMD_SUCCESS;
2667 }
2668
2669 DEFUN (no_bgp_client_to_client_reflection,
2670 no_bgp_client_to_client_reflection_cmd,
2671 "no bgp client-to-client reflection",
2672 NO_STR
2673 BGP_STR
2674 "Configure client to client route reflection\n"
2675 "reflection of routes allowed\n")
2676 {
2677 VTY_DECLVAR_CONTEXT(bgp, bgp);
2678 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2679 bgp_clear_star_soft_out(vty, bgp->name);
2680
2681 return CMD_SUCCESS;
2682 }
2683
2684 /* "bgp always-compare-med" configuration. */
2685 DEFUN (bgp_always_compare_med,
2686 bgp_always_compare_med_cmd,
2687 "bgp always-compare-med",
2688 BGP_STR
2689 "Allow comparing MED from different neighbors\n")
2690 {
2691 VTY_DECLVAR_CONTEXT(bgp, bgp);
2692 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2693 bgp_recalculate_all_bestpaths(bgp);
2694
2695 return CMD_SUCCESS;
2696 }
2697
2698 DEFUN (no_bgp_always_compare_med,
2699 no_bgp_always_compare_med_cmd,
2700 "no bgp always-compare-med",
2701 NO_STR
2702 BGP_STR
2703 "Allow comparing MED from different neighbors\n")
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2707 bgp_recalculate_all_bestpaths(bgp);
2708
2709 return CMD_SUCCESS;
2710 }
2711
2712
2713 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2714 "bgp ebgp-requires-policy",
2715 BGP_STR
2716 "Require in and out policy for eBGP peers (RFC8212)\n")
2717 {
2718 VTY_DECLVAR_CONTEXT(bgp, bgp);
2719 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2720 return CMD_SUCCESS;
2721 }
2722
2723 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2724 "no bgp ebgp-requires-policy",
2725 NO_STR
2726 BGP_STR
2727 "Require in and out policy for eBGP peers (RFC8212)\n")
2728 {
2729 VTY_DECLVAR_CONTEXT(bgp, bgp);
2730 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2731 return CMD_SUCCESS;
2732 }
2733
2734 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2735 "bgp suppress-duplicates",
2736 BGP_STR
2737 "Suppress duplicate updates if the route actually not changed\n")
2738 {
2739 VTY_DECLVAR_CONTEXT(bgp, bgp);
2740 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2741 return CMD_SUCCESS;
2742 }
2743
2744 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2745 "no bgp suppress-duplicates",
2746 NO_STR
2747 BGP_STR
2748 "Suppress duplicate updates if the route actually not changed\n")
2749 {
2750 VTY_DECLVAR_CONTEXT(bgp, bgp);
2751 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2752 return CMD_SUCCESS;
2753 }
2754
2755 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2756 "bgp reject-as-sets",
2757 BGP_STR
2758 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2759 {
2760 VTY_DECLVAR_CONTEXT(bgp, bgp);
2761 struct listnode *node, *nnode;
2762 struct peer *peer;
2763
2764 bgp->reject_as_sets = true;
2765
2766 /* Reset existing BGP sessions to reject routes
2767 * with aspath containing AS_SET or AS_CONFED_SET.
2768 */
2769 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2770 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2771 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2772 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2773 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2774 }
2775 }
2776
2777 return CMD_SUCCESS;
2778 }
2779
2780 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2781 "no bgp reject-as-sets",
2782 NO_STR
2783 BGP_STR
2784 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2785 {
2786 VTY_DECLVAR_CONTEXT(bgp, bgp);
2787 struct listnode *node, *nnode;
2788 struct peer *peer;
2789
2790 bgp->reject_as_sets = false;
2791
2792 /* Reset existing BGP sessions to reject routes
2793 * with aspath containing AS_SET or AS_CONFED_SET.
2794 */
2795 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2796 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2797 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2798 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2799 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2800 }
2801 }
2802
2803 return CMD_SUCCESS;
2804 }
2805
2806 /* "bgp deterministic-med" configuration. */
2807 DEFUN (bgp_deterministic_med,
2808 bgp_deterministic_med_cmd,
2809 "bgp deterministic-med",
2810 BGP_STR
2811 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2812 {
2813 VTY_DECLVAR_CONTEXT(bgp, bgp);
2814
2815 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2816 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2817 bgp_recalculate_all_bestpaths(bgp);
2818 }
2819
2820 return CMD_SUCCESS;
2821 }
2822
2823 DEFUN (no_bgp_deterministic_med,
2824 no_bgp_deterministic_med_cmd,
2825 "no bgp deterministic-med",
2826 NO_STR
2827 BGP_STR
2828 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2829 {
2830 VTY_DECLVAR_CONTEXT(bgp, bgp);
2831 int bestpath_per_as_used;
2832 afi_t afi;
2833 safi_t safi;
2834 struct peer *peer;
2835 struct listnode *node, *nnode;
2836
2837 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2838 bestpath_per_as_used = 0;
2839
2840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2841 FOREACH_AFI_SAFI (afi, safi)
2842 if (bgp_addpath_dmed_required(
2843 peer->addpath_type[afi][safi])) {
2844 bestpath_per_as_used = 1;
2845 break;
2846 }
2847
2848 if (bestpath_per_as_used)
2849 break;
2850 }
2851
2852 if (bestpath_per_as_used) {
2853 vty_out(vty,
2854 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2855 return CMD_WARNING_CONFIG_FAILED;
2856 } else {
2857 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2858 bgp_recalculate_all_bestpaths(bgp);
2859 }
2860 }
2861
2862 return CMD_SUCCESS;
2863 }
2864
2865 /* "bgp graceful-restart mode" configuration. */
2866 DEFUN (bgp_graceful_restart,
2867 bgp_graceful_restart_cmd,
2868 "bgp graceful-restart",
2869 BGP_STR
2870 GR_CMD
2871 )
2872 {
2873 int ret = BGP_GR_FAILURE;
2874
2875 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2876 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2877
2878 VTY_DECLVAR_CONTEXT(bgp, bgp);
2879
2880 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2881
2882 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2883 ret);
2884
2885 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2886 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2887 vty_out(vty,
2888 "Graceful restart configuration changed, reset all peers to take effect\n");
2889 return bgp_vty_return(vty, ret);
2890 }
2891
2892 DEFUN (no_bgp_graceful_restart,
2893 no_bgp_graceful_restart_cmd,
2894 "no bgp graceful-restart",
2895 NO_STR
2896 BGP_STR
2897 NO_GR_CMD
2898 )
2899 {
2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901
2902 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2903 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2904
2905 int ret = BGP_GR_FAILURE;
2906
2907 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2908
2909 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2910 ret);
2911
2912 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2913 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2914 vty_out(vty,
2915 "Graceful restart configuration changed, reset all peers to take effect\n");
2916
2917 return bgp_vty_return(vty, ret);
2918 }
2919
2920 DEFUN (bgp_graceful_restart_stalepath_time,
2921 bgp_graceful_restart_stalepath_time_cmd,
2922 "bgp graceful-restart stalepath-time (1-4095)",
2923 BGP_STR
2924 "Graceful restart capability parameters\n"
2925 "Set the max time to hold onto restarting peer's stale paths\n"
2926 "Delay value (seconds)\n")
2927 {
2928 VTY_DECLVAR_CONTEXT(bgp, bgp);
2929 int idx_number = 3;
2930 uint32_t stalepath;
2931
2932 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2933 bgp->stalepath_time = stalepath;
2934 return CMD_SUCCESS;
2935 }
2936
2937 DEFUN (bgp_graceful_restart_restart_time,
2938 bgp_graceful_restart_restart_time_cmd,
2939 "bgp graceful-restart restart-time (0-4095)",
2940 BGP_STR
2941 "Graceful restart capability parameters\n"
2942 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2943 "Delay value (seconds)\n")
2944 {
2945 VTY_DECLVAR_CONTEXT(bgp, bgp);
2946 int idx_number = 3;
2947 uint32_t restart;
2948
2949 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2950 bgp->restart_time = restart;
2951 return CMD_SUCCESS;
2952 }
2953
2954 DEFUN (bgp_graceful_restart_select_defer_time,
2955 bgp_graceful_restart_select_defer_time_cmd,
2956 "bgp graceful-restart select-defer-time (0-3600)",
2957 BGP_STR
2958 "Graceful restart capability parameters\n"
2959 "Set the time to defer the BGP route selection after restart\n"
2960 "Delay value (seconds, 0 - disable)\n")
2961 {
2962 VTY_DECLVAR_CONTEXT(bgp, bgp);
2963 int idx_number = 3;
2964 uint32_t defer_time;
2965
2966 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2967 bgp->select_defer_time = defer_time;
2968 if (defer_time == 0)
2969 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2970 else
2971 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2972
2973 return CMD_SUCCESS;
2974 }
2975
2976 DEFUN (no_bgp_graceful_restart_stalepath_time,
2977 no_bgp_graceful_restart_stalepath_time_cmd,
2978 "no bgp graceful-restart stalepath-time [(1-4095)]",
2979 NO_STR
2980 BGP_STR
2981 "Graceful restart capability parameters\n"
2982 "Set the max time to hold onto restarting peer's stale paths\n"
2983 "Delay value (seconds)\n")
2984 {
2985 VTY_DECLVAR_CONTEXT(bgp, bgp);
2986
2987 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2988 return CMD_SUCCESS;
2989 }
2990
2991 DEFUN (no_bgp_graceful_restart_restart_time,
2992 no_bgp_graceful_restart_restart_time_cmd,
2993 "no bgp graceful-restart restart-time [(0-4095)]",
2994 NO_STR
2995 BGP_STR
2996 "Graceful restart capability parameters\n"
2997 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2998 "Delay value (seconds)\n")
2999 {
3000 VTY_DECLVAR_CONTEXT(bgp, bgp);
3001
3002 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3003 return CMD_SUCCESS;
3004 }
3005
3006 DEFUN (no_bgp_graceful_restart_select_defer_time,
3007 no_bgp_graceful_restart_select_defer_time_cmd,
3008 "no bgp graceful-restart select-defer-time [(0-3600)]",
3009 NO_STR
3010 BGP_STR
3011 "Graceful restart capability parameters\n"
3012 "Set the time to defer the BGP route selection after restart\n"
3013 "Delay value (seconds)\n")
3014 {
3015 VTY_DECLVAR_CONTEXT(bgp, bgp);
3016
3017 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3018 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3019
3020 return CMD_SUCCESS;
3021 }
3022
3023 DEFUN (bgp_graceful_restart_preserve_fw,
3024 bgp_graceful_restart_preserve_fw_cmd,
3025 "bgp graceful-restart preserve-fw-state",
3026 BGP_STR
3027 "Graceful restart capability parameters\n"
3028 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3029 {
3030 VTY_DECLVAR_CONTEXT(bgp, bgp);
3031 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3032 return CMD_SUCCESS;
3033 }
3034
3035 DEFUN (no_bgp_graceful_restart_preserve_fw,
3036 no_bgp_graceful_restart_preserve_fw_cmd,
3037 "no bgp graceful-restart preserve-fw-state",
3038 NO_STR
3039 BGP_STR
3040 "Graceful restart capability parameters\n"
3041 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3042 {
3043 VTY_DECLVAR_CONTEXT(bgp, bgp);
3044 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3045 return CMD_SUCCESS;
3046 }
3047
3048 DEFPY (bgp_graceful_restart_notification,
3049 bgp_graceful_restart_notification_cmd,
3050 "[no$no] bgp graceful-restart notification",
3051 NO_STR
3052 BGP_STR
3053 "Graceful restart capability parameters\n"
3054 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3055 {
3056 VTY_DECLVAR_CONTEXT(bgp, bgp);
3057
3058 if (no)
3059 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3060 else
3061 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3062
3063 return CMD_SUCCESS;
3064 }
3065
3066 DEFPY (bgp_administrative_reset,
3067 bgp_administrative_reset_cmd,
3068 "[no$no] bgp hard-administrative-reset",
3069 NO_STR
3070 BGP_STR
3071 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3072 {
3073 VTY_DECLVAR_CONTEXT(bgp, bgp);
3074
3075 if (no)
3076 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3077 else
3078 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3079
3080 return CMD_SUCCESS;
3081 }
3082
3083 DEFUN (bgp_graceful_restart_disable,
3084 bgp_graceful_restart_disable_cmd,
3085 "bgp graceful-restart-disable",
3086 BGP_STR
3087 GR_DISABLE)
3088 {
3089 int ret = BGP_GR_FAILURE;
3090
3091 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3092 zlog_debug(
3093 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3094
3095 VTY_DECLVAR_CONTEXT(bgp, bgp);
3096
3097 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3098
3099 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3100 bgp->peer, ret);
3101
3102 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3103 zlog_debug(
3104 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3105 vty_out(vty,
3106 "Graceful restart configuration changed, reset all peers to take effect\n");
3107
3108 return bgp_vty_return(vty, ret);
3109 }
3110
3111 DEFUN (no_bgp_graceful_restart_disable,
3112 no_bgp_graceful_restart_disable_cmd,
3113 "no bgp graceful-restart-disable",
3114 NO_STR
3115 BGP_STR
3116 NO_GR_DISABLE
3117 )
3118 {
3119 VTY_DECLVAR_CONTEXT(bgp, bgp);
3120
3121 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3122 zlog_debug(
3123 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3124
3125 int ret = BGP_GR_FAILURE;
3126
3127 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3128
3129 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3130 ret);
3131
3132 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3133 zlog_debug(
3134 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3135 vty_out(vty,
3136 "Graceful restart configuration changed, reset all peers to take effect\n");
3137
3138 return bgp_vty_return(vty, ret);
3139 }
3140
3141 DEFUN (bgp_neighbor_graceful_restart_set,
3142 bgp_neighbor_graceful_restart_set_cmd,
3143 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3144 NEIGHBOR_STR
3145 NEIGHBOR_ADDR_STR2
3146 GR_NEIGHBOR_CMD
3147 )
3148 {
3149 int idx_peer = 1;
3150 struct peer *peer;
3151 int ret = BGP_GR_FAILURE;
3152
3153 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3154
3155 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3156 zlog_debug(
3157 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3158
3159 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3160 if (!peer)
3161 return CMD_WARNING_CONFIG_FAILED;
3162
3163 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3164
3165 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3166 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3167
3168 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3169 zlog_debug(
3170 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3171 vty_out(vty,
3172 "Graceful restart configuration changed, reset this peer to take effect\n");
3173
3174 return bgp_vty_return(vty, ret);
3175 }
3176
3177 DEFUN (no_bgp_neighbor_graceful_restart,
3178 no_bgp_neighbor_graceful_restart_set_cmd,
3179 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3180 NO_STR
3181 NEIGHBOR_STR
3182 NEIGHBOR_ADDR_STR2
3183 NO_GR_NEIGHBOR_CMD
3184 )
3185 {
3186 int idx_peer = 2;
3187 int ret = BGP_GR_FAILURE;
3188 struct peer *peer;
3189
3190 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3191
3192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3193 if (!peer)
3194 return CMD_WARNING_CONFIG_FAILED;
3195
3196 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3197 zlog_debug(
3198 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3199
3200 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3201
3202 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3203 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3204
3205 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3206 zlog_debug(
3207 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3208 vty_out(vty,
3209 "Graceful restart configuration changed, reset this peer to take effect\n");
3210
3211 return bgp_vty_return(vty, ret);
3212 }
3213
3214 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3215 bgp_neighbor_graceful_restart_helper_set_cmd,
3216 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3217 NEIGHBOR_STR
3218 NEIGHBOR_ADDR_STR2
3219 GR_NEIGHBOR_HELPER_CMD
3220 )
3221 {
3222 int idx_peer = 1;
3223 struct peer *peer;
3224 int ret = BGP_GR_FAILURE;
3225
3226 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3227
3228 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3229 zlog_debug(
3230 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3231
3232 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3233
3234 if (!peer)
3235 return CMD_WARNING_CONFIG_FAILED;
3236
3237
3238 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3239
3240 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3241 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3242
3243 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3244 zlog_debug(
3245 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3246 vty_out(vty,
3247 "Graceful restart configuration changed, reset this peer to take effect\n");
3248
3249 return bgp_vty_return(vty, ret);
3250 }
3251
3252 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3253 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3254 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3255 NO_STR
3256 NEIGHBOR_STR
3257 NEIGHBOR_ADDR_STR2
3258 NO_GR_NEIGHBOR_HELPER_CMD
3259 )
3260 {
3261 int idx_peer = 2;
3262 int ret = BGP_GR_FAILURE;
3263 struct peer *peer;
3264
3265 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3266
3267 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3268 if (!peer)
3269 return CMD_WARNING_CONFIG_FAILED;
3270
3271 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3272 zlog_debug(
3273 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3274
3275 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3276
3277 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3278 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3279
3280 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3281 zlog_debug(
3282 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3283 vty_out(vty,
3284 "Graceful restart configuration changed, reset this peer to take effect\n");
3285
3286 return bgp_vty_return(vty, ret);
3287 }
3288
3289 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3290 bgp_neighbor_graceful_restart_disable_set_cmd,
3291 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3292 NEIGHBOR_STR
3293 NEIGHBOR_ADDR_STR2
3294 GR_NEIGHBOR_DISABLE_CMD
3295 )
3296 {
3297 int idx_peer = 1;
3298 struct peer *peer;
3299 int ret = BGP_GR_FAILURE;
3300
3301 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3302
3303 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3304 zlog_debug(
3305 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3306
3307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3308 if (!peer)
3309 return CMD_WARNING_CONFIG_FAILED;
3310
3311 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3312
3313 if (peer->bgp->t_startup)
3314 bgp_peer_gr_flags_update(peer);
3315
3316 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3317 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3318
3319 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3320 zlog_debug(
3321 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3322 vty_out(vty,
3323 "Graceful restart configuration changed, reset this peer to take effect\n");
3324
3325 return bgp_vty_return(vty, ret);
3326 }
3327
3328 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3329 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3330 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3331 NO_STR
3332 NEIGHBOR_STR
3333 NEIGHBOR_ADDR_STR2
3334 NO_GR_NEIGHBOR_DISABLE_CMD
3335 )
3336 {
3337 int idx_peer = 2;
3338 int ret = BGP_GR_FAILURE;
3339 struct peer *peer;
3340
3341 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3342
3343 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3344 if (!peer)
3345 return CMD_WARNING_CONFIG_FAILED;
3346
3347 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3348 zlog_debug(
3349 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3350
3351 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3352
3353 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3354 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3355
3356 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3357 zlog_debug(
3358 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3359 vty_out(vty,
3360 "Graceful restart configuration changed, reset this peer to take effect\n");
3361
3362 return bgp_vty_return(vty, ret);
3363 }
3364
3365 DEFPY (neighbor_graceful_shutdown,
3366 neighbor_graceful_shutdown_cmd,
3367 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3368 NO_STR
3369 NEIGHBOR_STR
3370 NEIGHBOR_ADDR_STR2
3371 "Graceful shutdown\n")
3372 {
3373 afi_t afi;
3374 safi_t safi;
3375 struct peer *peer;
3376 VTY_DECLVAR_CONTEXT(bgp, bgp);
3377 int ret;
3378
3379 peer = peer_and_group_lookup_vty(vty, neighbor);
3380 if (!peer)
3381 return CMD_WARNING_CONFIG_FAILED;
3382
3383 if (no)
3384 ret = peer_flag_unset_vty(vty, neighbor,
3385 PEER_FLAG_GRACEFUL_SHUTDOWN);
3386 else
3387 ret = peer_flag_set_vty(vty, neighbor,
3388 PEER_FLAG_GRACEFUL_SHUTDOWN);
3389
3390 FOREACH_AFI_SAFI (afi, safi) {
3391 if (!peer->afc[afi][safi])
3392 continue;
3393
3394 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3395 neighbor);
3396 }
3397
3398 return ret;
3399 }
3400
3401 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3402 bgp_graceful_restart_disable_eor_cmd,
3403 "bgp graceful-restart disable-eor",
3404 BGP_STR
3405 "Graceful restart configuration parameters\n"
3406 "Disable EOR Check\n")
3407 {
3408 VTY_DECLVAR_CONTEXT(bgp, bgp);
3409 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3410
3411 return CMD_SUCCESS;
3412 }
3413
3414 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3415 no_bgp_graceful_restart_disable_eor_cmd,
3416 "no bgp graceful-restart disable-eor",
3417 NO_STR
3418 BGP_STR
3419 "Graceful restart configuration parameters\n"
3420 "Disable EOR Check\n")
3421 {
3422 VTY_DECLVAR_CONTEXT(bgp, bgp);
3423 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3424
3425 return CMD_SUCCESS;
3426 }
3427
3428 DEFUN (bgp_graceful_restart_rib_stale_time,
3429 bgp_graceful_restart_rib_stale_time_cmd,
3430 "bgp graceful-restart rib-stale-time (1-3600)",
3431 BGP_STR
3432 "Graceful restart configuration parameters\n"
3433 "Specify the stale route removal timer in rib\n"
3434 "Delay value (seconds)\n")
3435 {
3436 VTY_DECLVAR_CONTEXT(bgp, bgp);
3437 int idx_number = 3;
3438 uint32_t stale_time;
3439
3440 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3441 bgp->rib_stale_time = stale_time;
3442 /* Send the stale timer update message to RIB */
3443 if (bgp_zebra_stale_timer_update(bgp))
3444 return CMD_WARNING;
3445
3446 return CMD_SUCCESS;
3447 }
3448
3449 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3450 no_bgp_graceful_restart_rib_stale_time_cmd,
3451 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3452 NO_STR
3453 BGP_STR
3454 "Graceful restart configuration parameters\n"
3455 "Specify the stale route removal timer in rib\n"
3456 "Delay value (seconds)\n")
3457 {
3458 VTY_DECLVAR_CONTEXT(bgp, bgp);
3459
3460 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3461 /* Send the stale timer update message to RIB */
3462 if (bgp_zebra_stale_timer_update(bgp))
3463 return CMD_WARNING;
3464
3465 return CMD_SUCCESS;
3466 }
3467
3468 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3469 "bgp long-lived-graceful-restart stale-time (1-16777215)",
3470 BGP_STR
3471 "Enable Long-lived Graceful Restart\n"
3472 "Specifies maximum time to wait before purging long-lived stale routes\n"
3473 "Stale time value (seconds)\n")
3474 {
3475 VTY_DECLVAR_CONTEXT(bgp, bgp);
3476
3477 uint32_t llgr_stale_time;
3478
3479 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3480 bgp->llgr_stale_time = llgr_stale_time;
3481
3482 return CMD_SUCCESS;
3483 }
3484
3485 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3486 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3487 NO_STR BGP_STR
3488 "Enable Long-lived Graceful Restart\n"
3489 "Specifies maximum time to wait before purging long-lived stale routes\n"
3490 "Stale time value (seconds)\n")
3491 {
3492 VTY_DECLVAR_CONTEXT(bgp, bgp);
3493
3494 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3495
3496 return CMD_SUCCESS;
3497 }
3498
3499 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3500 struct bgp *bgp)
3501 {
3502 bgp_static_redo_import_check(bgp);
3503 bgp_redistribute_redo(bgp);
3504 bgp_clear_star_soft_out(vty, bgp->name);
3505 bgp_clear_star_soft_in(vty, bgp->name);
3506 }
3507
3508 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3509 {
3510 struct listnode *node, *nnode;
3511 struct bgp *bgp;
3512 bool vrf_cfg = false;
3513
3514 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3515 return CMD_SUCCESS;
3516
3517 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3518 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3519 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3520 vty_out(vty,
3521 "%% graceful-shutdown configuration found in vrf %s\n",
3522 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3523 VRF_DEFAULT_NAME : bgp->name);
3524 vrf_cfg = true;
3525 }
3526 }
3527
3528 if (vrf_cfg) {
3529 vty_out(vty,
3530 "%%Failed: global graceful-shutdown not permitted\n");
3531 return CMD_WARNING;
3532 }
3533
3534 /* Set flag globally */
3535 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3536
3537 /* Initiate processing for all BGP instances. */
3538 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3539 bgp_initiate_graceful_shut_unshut(vty, bgp);
3540
3541 return CMD_SUCCESS;
3542 }
3543
3544 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3545 {
3546 struct listnode *node, *nnode;
3547 struct bgp *bgp;
3548
3549 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3550 return CMD_SUCCESS;
3551
3552 /* Unset flag globally */
3553 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3554
3555 /* Initiate processing for all BGP instances. */
3556 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3557 bgp_initiate_graceful_shut_unshut(vty, bgp);
3558
3559 return CMD_SUCCESS;
3560 }
3561
3562 /* "bgp graceful-shutdown" configuration */
3563 DEFUN (bgp_graceful_shutdown,
3564 bgp_graceful_shutdown_cmd,
3565 "bgp graceful-shutdown",
3566 BGP_STR
3567 "Graceful shutdown parameters\n")
3568 {
3569 if (vty->node == CONFIG_NODE)
3570 return bgp_global_graceful_shutdown_config_vty(vty);
3571
3572 VTY_DECLVAR_CONTEXT(bgp, bgp);
3573
3574 /* if configured globally, per-instance config is not allowed */
3575 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3576 vty_out(vty,
3577 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3578 return CMD_WARNING_CONFIG_FAILED;
3579 }
3580
3581 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3582 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3583 bgp_initiate_graceful_shut_unshut(vty, bgp);
3584 }
3585
3586 return CMD_SUCCESS;
3587 }
3588
3589 DEFUN (no_bgp_graceful_shutdown,
3590 no_bgp_graceful_shutdown_cmd,
3591 "no bgp graceful-shutdown",
3592 NO_STR
3593 BGP_STR
3594 "Graceful shutdown parameters\n")
3595 {
3596 if (vty->node == CONFIG_NODE)
3597 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3598
3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
3600
3601 /* If configured globally, cannot remove from one bgp instance */
3602 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3603 vty_out(vty,
3604 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3605 return CMD_WARNING_CONFIG_FAILED;
3606 }
3607
3608 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3609 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3610 bgp_initiate_graceful_shut_unshut(vty, bgp);
3611 }
3612
3613 return CMD_SUCCESS;
3614 }
3615
3616 /* "bgp fast-external-failover" configuration. */
3617 DEFUN (bgp_fast_external_failover,
3618 bgp_fast_external_failover_cmd,
3619 "bgp fast-external-failover",
3620 BGP_STR
3621 "Immediately reset session if a link to a directly connected external peer goes down\n")
3622 {
3623 VTY_DECLVAR_CONTEXT(bgp, bgp);
3624 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3625 return CMD_SUCCESS;
3626 }
3627
3628 DEFUN (no_bgp_fast_external_failover,
3629 no_bgp_fast_external_failover_cmd,
3630 "no bgp fast-external-failover",
3631 NO_STR
3632 BGP_STR
3633 "Immediately reset session if a link to a directly connected external peer goes down\n")
3634 {
3635 VTY_DECLVAR_CONTEXT(bgp, bgp);
3636 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3637 return CMD_SUCCESS;
3638 }
3639
3640 DEFPY (bgp_bestpath_aigp,
3641 bgp_bestpath_aigp_cmd,
3642 "[no$no] bgp bestpath aigp",
3643 NO_STR
3644 BGP_STR
3645 "Change the default bestpath selection\n"
3646 "Evaluate the AIGP attribute during the best path selection process\n")
3647 {
3648 VTY_DECLVAR_CONTEXT(bgp, bgp);
3649
3650 if (no)
3651 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3652 else
3653 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3654
3655 bgp_recalculate_all_bestpaths(bgp);
3656
3657 return CMD_SUCCESS;
3658 }
3659
3660 /* "bgp bestpath compare-routerid" configuration. */
3661 DEFUN (bgp_bestpath_compare_router_id,
3662 bgp_bestpath_compare_router_id_cmd,
3663 "bgp bestpath compare-routerid",
3664 BGP_STR
3665 "Change the default bestpath selection\n"
3666 "Compare router-id for identical EBGP paths\n")
3667 {
3668 VTY_DECLVAR_CONTEXT(bgp, bgp);
3669 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3670 bgp_recalculate_all_bestpaths(bgp);
3671
3672 return CMD_SUCCESS;
3673 }
3674
3675 DEFUN (no_bgp_bestpath_compare_router_id,
3676 no_bgp_bestpath_compare_router_id_cmd,
3677 "no bgp bestpath compare-routerid",
3678 NO_STR
3679 BGP_STR
3680 "Change the default bestpath selection\n"
3681 "Compare router-id for identical EBGP paths\n")
3682 {
3683 VTY_DECLVAR_CONTEXT(bgp, bgp);
3684 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3685 bgp_recalculate_all_bestpaths(bgp);
3686
3687 return CMD_SUCCESS;
3688 }
3689
3690 /* "bgp bestpath as-path ignore" configuration. */
3691 DEFUN (bgp_bestpath_aspath_ignore,
3692 bgp_bestpath_aspath_ignore_cmd,
3693 "bgp bestpath as-path ignore",
3694 BGP_STR
3695 "Change the default bestpath selection\n"
3696 "AS-path attribute\n"
3697 "Ignore as-path length in selecting a route\n")
3698 {
3699 VTY_DECLVAR_CONTEXT(bgp, bgp);
3700 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3701 bgp_recalculate_all_bestpaths(bgp);
3702
3703 return CMD_SUCCESS;
3704 }
3705
3706 DEFUN (no_bgp_bestpath_aspath_ignore,
3707 no_bgp_bestpath_aspath_ignore_cmd,
3708 "no bgp bestpath as-path ignore",
3709 NO_STR
3710 BGP_STR
3711 "Change the default bestpath selection\n"
3712 "AS-path attribute\n"
3713 "Ignore as-path length in selecting a route\n")
3714 {
3715 VTY_DECLVAR_CONTEXT(bgp, bgp);
3716 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3717 bgp_recalculate_all_bestpaths(bgp);
3718
3719 return CMD_SUCCESS;
3720 }
3721
3722 /* "bgp bestpath as-path confed" configuration. */
3723 DEFUN (bgp_bestpath_aspath_confed,
3724 bgp_bestpath_aspath_confed_cmd,
3725 "bgp bestpath as-path confed",
3726 BGP_STR
3727 "Change the default bestpath selection\n"
3728 "AS-path attribute\n"
3729 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3730 {
3731 VTY_DECLVAR_CONTEXT(bgp, bgp);
3732 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3733 bgp_recalculate_all_bestpaths(bgp);
3734
3735 return CMD_SUCCESS;
3736 }
3737
3738 DEFUN (no_bgp_bestpath_aspath_confed,
3739 no_bgp_bestpath_aspath_confed_cmd,
3740 "no bgp bestpath as-path confed",
3741 NO_STR
3742 BGP_STR
3743 "Change the default bestpath selection\n"
3744 "AS-path attribute\n"
3745 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3746 {
3747 VTY_DECLVAR_CONTEXT(bgp, bgp);
3748 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3749 bgp_recalculate_all_bestpaths(bgp);
3750
3751 return CMD_SUCCESS;
3752 }
3753
3754 /* "bgp bestpath as-path multipath-relax" configuration. */
3755 DEFUN (bgp_bestpath_aspath_multipath_relax,
3756 bgp_bestpath_aspath_multipath_relax_cmd,
3757 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3758 BGP_STR
3759 "Change the default bestpath selection\n"
3760 "AS-path attribute\n"
3761 "Allow load sharing across routes that have different AS paths (but same length)\n"
3762 "Generate an AS_SET\n"
3763 "Do not generate an AS_SET\n")
3764 {
3765 VTY_DECLVAR_CONTEXT(bgp, bgp);
3766 int idx = 0;
3767 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3768
3769 /* no-as-set is now the default behavior so we can silently
3770 * ignore it */
3771 if (argv_find(argv, argc, "as-set", &idx))
3772 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3773 else
3774 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3775
3776 bgp_recalculate_all_bestpaths(bgp);
3777
3778 return CMD_SUCCESS;
3779 }
3780
3781 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3782 no_bgp_bestpath_aspath_multipath_relax_cmd,
3783 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3784 NO_STR
3785 BGP_STR
3786 "Change the default bestpath selection\n"
3787 "AS-path attribute\n"
3788 "Allow load sharing across routes that have different AS paths (but same length)\n"
3789 "Generate an AS_SET\n"
3790 "Do not generate an AS_SET\n")
3791 {
3792 VTY_DECLVAR_CONTEXT(bgp, bgp);
3793 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3794 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3795 bgp_recalculate_all_bestpaths(bgp);
3796
3797 return CMD_SUCCESS;
3798 }
3799
3800 /* "bgp bestpath peer-type multipath-relax" configuration. */
3801 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3802 bgp_bestpath_peer_type_multipath_relax_cmd,
3803 "bgp bestpath peer-type multipath-relax",
3804 BGP_STR
3805 "Change the default bestpath selection\n"
3806 "Peer type\n"
3807 "Allow load sharing across routes learned from different peer types\n")
3808 {
3809 VTY_DECLVAR_CONTEXT(bgp, bgp);
3810 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3811 bgp_recalculate_all_bestpaths(bgp);
3812
3813 return CMD_SUCCESS;
3814 }
3815
3816 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3817 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3818 "no bgp bestpath peer-type multipath-relax",
3819 NO_STR BGP_STR
3820 "Change the default bestpath selection\n"
3821 "Peer type\n"
3822 "Allow load sharing across routes learned from different peer types\n")
3823 {
3824 VTY_DECLVAR_CONTEXT(bgp, bgp);
3825 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3826 bgp_recalculate_all_bestpaths(bgp);
3827
3828 return CMD_SUCCESS;
3829 }
3830
3831 /* "bgp log-neighbor-changes" configuration. */
3832 DEFUN (bgp_log_neighbor_changes,
3833 bgp_log_neighbor_changes_cmd,
3834 "bgp log-neighbor-changes",
3835 BGP_STR
3836 "Log neighbor up/down and reset reason\n")
3837 {
3838 VTY_DECLVAR_CONTEXT(bgp, bgp);
3839 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3840 return CMD_SUCCESS;
3841 }
3842
3843 DEFUN (no_bgp_log_neighbor_changes,
3844 no_bgp_log_neighbor_changes_cmd,
3845 "no bgp log-neighbor-changes",
3846 NO_STR
3847 BGP_STR
3848 "Log neighbor up/down and reset reason\n")
3849 {
3850 VTY_DECLVAR_CONTEXT(bgp, bgp);
3851 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3852 return CMD_SUCCESS;
3853 }
3854
3855 /* "bgp bestpath med" configuration. */
3856 DEFUN (bgp_bestpath_med,
3857 bgp_bestpath_med_cmd,
3858 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3859 BGP_STR
3860 "Change the default bestpath selection\n"
3861 "MED attribute\n"
3862 "Compare MED among confederation paths\n"
3863 "Treat missing MED as the least preferred one\n"
3864 "Treat missing MED as the least preferred one\n"
3865 "Compare MED among confederation paths\n")
3866 {
3867 VTY_DECLVAR_CONTEXT(bgp, bgp);
3868
3869 int idx = 0;
3870 if (argv_find(argv, argc, "confed", &idx))
3871 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3872 idx = 0;
3873 if (argv_find(argv, argc, "missing-as-worst", &idx))
3874 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3875
3876 bgp_recalculate_all_bestpaths(bgp);
3877
3878 return CMD_SUCCESS;
3879 }
3880
3881 DEFUN (no_bgp_bestpath_med,
3882 no_bgp_bestpath_med_cmd,
3883 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3884 NO_STR
3885 BGP_STR
3886 "Change the default bestpath selection\n"
3887 "MED attribute\n"
3888 "Compare MED among confederation paths\n"
3889 "Treat missing MED as the least preferred one\n"
3890 "Treat missing MED as the least preferred one\n"
3891 "Compare MED among confederation paths\n")
3892 {
3893 VTY_DECLVAR_CONTEXT(bgp, bgp);
3894
3895 int idx = 0;
3896 if (argv_find(argv, argc, "confed", &idx))
3897 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3898 idx = 0;
3899 if (argv_find(argv, argc, "missing-as-worst", &idx))
3900 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3901
3902 bgp_recalculate_all_bestpaths(bgp);
3903
3904 return CMD_SUCCESS;
3905 }
3906
3907 /* "bgp bestpath bandwidth" configuration. */
3908 DEFPY (bgp_bestpath_bw,
3909 bgp_bestpath_bw_cmd,
3910 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3911 BGP_STR
3912 "Change the default bestpath selection\n"
3913 "Link Bandwidth attribute\n"
3914 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3915 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3916 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3917 {
3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
3919 afi_t afi;
3920 safi_t safi;
3921
3922 if (!bw_cfg) {
3923 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3924 return CMD_ERR_INCOMPLETE;
3925 }
3926 if (!strcmp(bw_cfg, "ignore"))
3927 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3928 else if (!strcmp(bw_cfg, "skip-missing"))
3929 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3930 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3931 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3932 else
3933 return CMD_ERR_NO_MATCH;
3934
3935 /* This config is used in route install, so redo that. */
3936 FOREACH_AFI_SAFI (afi, safi) {
3937 if (!bgp_fibupd_safi(safi))
3938 continue;
3939 bgp_zebra_announce_table(bgp, afi, safi);
3940 }
3941
3942 return CMD_SUCCESS;
3943 }
3944
3945 DEFPY (no_bgp_bestpath_bw,
3946 no_bgp_bestpath_bw_cmd,
3947 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3948 NO_STR
3949 BGP_STR
3950 "Change the default bestpath selection\n"
3951 "Link Bandwidth attribute\n"
3952 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3953 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3954 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3955 {
3956 VTY_DECLVAR_CONTEXT(bgp, bgp);
3957 afi_t afi;
3958 safi_t safi;
3959
3960 bgp->lb_handling = BGP_LINK_BW_ECMP;
3961
3962 /* This config is used in route install, so redo that. */
3963 FOREACH_AFI_SAFI (afi, safi) {
3964 if (!bgp_fibupd_safi(safi))
3965 continue;
3966 bgp_zebra_announce_table(bgp, afi, safi);
3967 }
3968 return CMD_SUCCESS;
3969 }
3970
3971 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3972 "[no] bgp default <ipv4-unicast|"
3973 "ipv4-multicast|"
3974 "ipv4-vpn|"
3975 "ipv4-labeled-unicast|"
3976 "ipv4-flowspec|"
3977 "ipv6-unicast|"
3978 "ipv6-multicast|"
3979 "ipv6-vpn|"
3980 "ipv6-labeled-unicast|"
3981 "ipv6-flowspec|"
3982 "l2vpn-evpn>$afi_safi",
3983 NO_STR
3984 BGP_STR
3985 "Configure BGP defaults\n"
3986 "Activate ipv4-unicast for a peer by default\n"
3987 "Activate ipv4-multicast for a peer by default\n"
3988 "Activate ipv4-vpn for a peer by default\n"
3989 "Activate ipv4-labeled-unicast for a peer by default\n"
3990 "Activate ipv4-flowspec for a peer by default\n"
3991 "Activate ipv6-unicast for a peer by default\n"
3992 "Activate ipv6-multicast for a peer by default\n"
3993 "Activate ipv6-vpn for a peer by default\n"
3994 "Activate ipv6-labeled-unicast for a peer by default\n"
3995 "Activate ipv6-flowspec for a peer by default\n"
3996 "Activate l2vpn-evpn for a peer by default\n")
3997 {
3998 VTY_DECLVAR_CONTEXT(bgp, bgp);
3999 char afi_safi_str[strlen(afi_safi) + 1];
4000 char *afi_safi_str_tok;
4001
4002 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4003 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4004 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4005 afi_t afi = bgp_vty_afi_from_str(afi_str);
4006 safi_t safi;
4007
4008 /*
4009 * Impossible situation but making coverity happy
4010 */
4011 assert(afi != AFI_MAX);
4012
4013 if (strmatch(safi_str, "labeled"))
4014 safi = bgp_vty_safi_from_str("labeled-unicast");
4015 else
4016 safi = bgp_vty_safi_from_str(safi_str);
4017
4018 assert(safi != SAFI_MAX);
4019 if (no)
4020 bgp->default_af[afi][safi] = false;
4021 else {
4022 if ((safi == SAFI_LABELED_UNICAST
4023 && bgp->default_af[afi][SAFI_UNICAST])
4024 || (safi == SAFI_UNICAST
4025 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4026 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4027 else
4028 bgp->default_af[afi][safi] = true;
4029 }
4030
4031 return CMD_SUCCESS;
4032 }
4033
4034 /* Display hostname in certain command outputs */
4035 DEFUN (bgp_default_show_hostname,
4036 bgp_default_show_hostname_cmd,
4037 "bgp default show-hostname",
4038 BGP_STR
4039 "Configure BGP defaults\n"
4040 "Show hostname in certain command outputs\n")
4041 {
4042 VTY_DECLVAR_CONTEXT(bgp, bgp);
4043 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4044 return CMD_SUCCESS;
4045 }
4046
4047 DEFUN (no_bgp_default_show_hostname,
4048 no_bgp_default_show_hostname_cmd,
4049 "no bgp default show-hostname",
4050 NO_STR
4051 BGP_STR
4052 "Configure BGP defaults\n"
4053 "Show hostname in certain command outputs\n")
4054 {
4055 VTY_DECLVAR_CONTEXT(bgp, bgp);
4056 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4057 return CMD_SUCCESS;
4058 }
4059
4060 /* Display hostname in certain command outputs */
4061 DEFUN (bgp_default_show_nexthop_hostname,
4062 bgp_default_show_nexthop_hostname_cmd,
4063 "bgp default show-nexthop-hostname",
4064 BGP_STR
4065 "Configure BGP defaults\n"
4066 "Show hostname for nexthop in certain command outputs\n")
4067 {
4068 VTY_DECLVAR_CONTEXT(bgp, bgp);
4069 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4070 return CMD_SUCCESS;
4071 }
4072
4073 DEFUN (no_bgp_default_show_nexthop_hostname,
4074 no_bgp_default_show_nexthop_hostname_cmd,
4075 "no bgp default show-nexthop-hostname",
4076 NO_STR
4077 BGP_STR
4078 "Configure BGP defaults\n"
4079 "Show hostname for nexthop in certain command outputs\n")
4080 {
4081 VTY_DECLVAR_CONTEXT(bgp, bgp);
4082 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4083 return CMD_SUCCESS;
4084 }
4085
4086 /* "bgp network import-check" configuration. */
4087 DEFUN (bgp_network_import_check,
4088 bgp_network_import_check_cmd,
4089 "bgp network import-check",
4090 BGP_STR
4091 "BGP network command\n"
4092 "Check BGP network route exists in IGP\n")
4093 {
4094 VTY_DECLVAR_CONTEXT(bgp, bgp);
4095 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4096 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4097 bgp_static_redo_import_check(bgp);
4098 }
4099
4100 return CMD_SUCCESS;
4101 }
4102
4103 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4104 "bgp network import-check exact",
4105 BGP_STR
4106 "BGP network command\n"
4107 "Check BGP network route exists in IGP\n"
4108 "Match route precisely\n")
4109
4110 DEFUN (no_bgp_network_import_check,
4111 no_bgp_network_import_check_cmd,
4112 "no bgp network import-check",
4113 NO_STR
4114 BGP_STR
4115 "BGP network command\n"
4116 "Check BGP network route exists in IGP\n")
4117 {
4118 VTY_DECLVAR_CONTEXT(bgp, bgp);
4119 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4120 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4121 bgp_static_redo_import_check(bgp);
4122 }
4123
4124 return CMD_SUCCESS;
4125 }
4126
4127 DEFUN (bgp_default_local_preference,
4128 bgp_default_local_preference_cmd,
4129 "bgp default local-preference (0-4294967295)",
4130 BGP_STR
4131 "Configure BGP defaults\n"
4132 "local preference (higher=more preferred)\n"
4133 "Configure default local preference value\n")
4134 {
4135 VTY_DECLVAR_CONTEXT(bgp, bgp);
4136 int idx_number = 3;
4137 uint32_t local_pref;
4138
4139 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4140
4141 bgp_default_local_preference_set(bgp, local_pref);
4142 bgp_clear_star_soft_in(vty, bgp->name);
4143
4144 return CMD_SUCCESS;
4145 }
4146
4147 DEFUN (no_bgp_default_local_preference,
4148 no_bgp_default_local_preference_cmd,
4149 "no bgp default local-preference [(0-4294967295)]",
4150 NO_STR
4151 BGP_STR
4152 "Configure BGP defaults\n"
4153 "local preference (higher=more preferred)\n"
4154 "Configure default local preference value\n")
4155 {
4156 VTY_DECLVAR_CONTEXT(bgp, bgp);
4157 bgp_default_local_preference_unset(bgp);
4158 bgp_clear_star_soft_in(vty, bgp->name);
4159
4160 return CMD_SUCCESS;
4161 }
4162
4163
4164 DEFUN (bgp_default_subgroup_pkt_queue_max,
4165 bgp_default_subgroup_pkt_queue_max_cmd,
4166 "bgp default subgroup-pkt-queue-max (20-100)",
4167 BGP_STR
4168 "Configure BGP defaults\n"
4169 "subgroup-pkt-queue-max\n"
4170 "Configure subgroup packet queue max\n")
4171 {
4172 VTY_DECLVAR_CONTEXT(bgp, bgp);
4173 int idx_number = 3;
4174 uint32_t max_size;
4175
4176 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4177
4178 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4179
4180 return CMD_SUCCESS;
4181 }
4182
4183 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4184 no_bgp_default_subgroup_pkt_queue_max_cmd,
4185 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4186 NO_STR
4187 BGP_STR
4188 "Configure BGP defaults\n"
4189 "subgroup-pkt-queue-max\n"
4190 "Configure subgroup packet queue max\n")
4191 {
4192 VTY_DECLVAR_CONTEXT(bgp, bgp);
4193 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4194 return CMD_SUCCESS;
4195 }
4196
4197
4198 DEFUN (bgp_rr_allow_outbound_policy,
4199 bgp_rr_allow_outbound_policy_cmd,
4200 "bgp route-reflector allow-outbound-policy",
4201 BGP_STR
4202 "Allow modifications made by out route-map\n"
4203 "on ibgp neighbors\n")
4204 {
4205 VTY_DECLVAR_CONTEXT(bgp, bgp);
4206
4207 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4208 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4209 update_group_announce_rrclients(bgp);
4210 bgp_clear_star_soft_out(vty, bgp->name);
4211 }
4212
4213 return CMD_SUCCESS;
4214 }
4215
4216 DEFUN (no_bgp_rr_allow_outbound_policy,
4217 no_bgp_rr_allow_outbound_policy_cmd,
4218 "no bgp route-reflector allow-outbound-policy",
4219 NO_STR
4220 BGP_STR
4221 "Allow modifications made by out route-map\n"
4222 "on ibgp neighbors\n")
4223 {
4224 VTY_DECLVAR_CONTEXT(bgp, bgp);
4225
4226 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4227 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4228 update_group_announce_rrclients(bgp);
4229 bgp_clear_star_soft_out(vty, bgp->name);
4230 }
4231
4232 return CMD_SUCCESS;
4233 }
4234
4235 DEFUN (bgp_listen_limit,
4236 bgp_listen_limit_cmd,
4237 "bgp listen limit (1-65535)",
4238 BGP_STR
4239 "BGP Dynamic Neighbors listen commands\n"
4240 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4241 "Configure Dynamic Neighbors listen limit value\n")
4242 {
4243 VTY_DECLVAR_CONTEXT(bgp, bgp);
4244 int idx_number = 3;
4245 int listen_limit;
4246
4247 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4248
4249 bgp_listen_limit_set(bgp, listen_limit);
4250
4251 return CMD_SUCCESS;
4252 }
4253
4254 DEFUN (no_bgp_listen_limit,
4255 no_bgp_listen_limit_cmd,
4256 "no bgp listen limit [(1-65535)]",
4257 NO_STR
4258 BGP_STR
4259 "BGP Dynamic Neighbors listen commands\n"
4260 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4261 "Configure Dynamic Neighbors listen limit value\n")
4262 {
4263 VTY_DECLVAR_CONTEXT(bgp, bgp);
4264 bgp_listen_limit_unset(bgp);
4265 return CMD_SUCCESS;
4266 }
4267
4268
4269 /*
4270 * Check if this listen range is already configured. Check for exact
4271 * match or overlap based on input.
4272 */
4273 static struct peer_group *listen_range_exists(struct bgp *bgp,
4274 struct prefix *range, int exact)
4275 {
4276 struct listnode *node, *nnode;
4277 struct listnode *node1, *nnode1;
4278 struct peer_group *group;
4279 struct prefix *lr;
4280 afi_t afi;
4281 int match;
4282
4283 afi = family2afi(range->family);
4284 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4285 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4286 lr)) {
4287 if (exact)
4288 match = prefix_same(range, lr);
4289 else
4290 match = (prefix_match(range, lr)
4291 || prefix_match(lr, range));
4292 if (match)
4293 return group;
4294 }
4295 }
4296
4297 return NULL;
4298 }
4299
4300 DEFUN (bgp_listen_range,
4301 bgp_listen_range_cmd,
4302 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4303 BGP_STR
4304 "Configure BGP dynamic neighbors listen range\n"
4305 "Configure BGP dynamic neighbors listen range\n"
4306 NEIGHBOR_ADDR_STR
4307 "Member of the peer-group\n"
4308 "Peer-group name\n")
4309 {
4310 VTY_DECLVAR_CONTEXT(bgp, bgp);
4311 struct prefix range;
4312 struct peer_group *group, *existing_group;
4313 afi_t afi;
4314 int ret;
4315 int idx = 0;
4316
4317 argv_find(argv, argc, "A.B.C.D/M", &idx);
4318 argv_find(argv, argc, "X:X::X:X/M", &idx);
4319 char *prefix = argv[idx]->arg;
4320 argv_find(argv, argc, "PGNAME", &idx);
4321 char *peergroup = argv[idx]->arg;
4322
4323 /* Convert IP prefix string to struct prefix. */
4324 ret = str2prefix(prefix, &range);
4325 if (!ret) {
4326 vty_out(vty, "%% Malformed listen range\n");
4327 return CMD_WARNING_CONFIG_FAILED;
4328 }
4329
4330 afi = family2afi(range.family);
4331
4332 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4333 vty_out(vty,
4334 "%% Malformed listen range (link-local address)\n");
4335 return CMD_WARNING_CONFIG_FAILED;
4336 }
4337
4338 apply_mask(&range);
4339
4340 /* Check if same listen range is already configured. */
4341 existing_group = listen_range_exists(bgp, &range, 1);
4342 if (existing_group) {
4343 if (strcmp(existing_group->name, peergroup) == 0)
4344 return CMD_SUCCESS;
4345 else {
4346 vty_out(vty,
4347 "%% Same listen range is attached to peer-group %s\n",
4348 existing_group->name);
4349 return CMD_WARNING_CONFIG_FAILED;
4350 }
4351 }
4352
4353 /* Check if an overlapping listen range exists. */
4354 if (listen_range_exists(bgp, &range, 0)) {
4355 vty_out(vty,
4356 "%% Listen range overlaps with existing listen range\n");
4357 return CMD_WARNING_CONFIG_FAILED;
4358 }
4359
4360 group = peer_group_lookup(bgp, peergroup);
4361 if (!group) {
4362 vty_out(vty, "%% Configure the peer-group first\n");
4363 return CMD_WARNING_CONFIG_FAILED;
4364 }
4365
4366 ret = peer_group_listen_range_add(group, &range);
4367 return bgp_vty_return(vty, ret);
4368 }
4369
4370 DEFUN (no_bgp_listen_range,
4371 no_bgp_listen_range_cmd,
4372 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4373 NO_STR
4374 BGP_STR
4375 "Unconfigure BGP dynamic neighbors listen range\n"
4376 "Unconfigure BGP dynamic neighbors listen range\n"
4377 NEIGHBOR_ADDR_STR
4378 "Member of the peer-group\n"
4379 "Peer-group name\n")
4380 {
4381 VTY_DECLVAR_CONTEXT(bgp, bgp);
4382 struct prefix range;
4383 struct peer_group *group;
4384 afi_t afi;
4385 int ret;
4386 int idx = 0;
4387
4388 argv_find(argv, argc, "A.B.C.D/M", &idx);
4389 argv_find(argv, argc, "X:X::X:X/M", &idx);
4390 char *prefix = argv[idx]->arg;
4391 argv_find(argv, argc, "PGNAME", &idx);
4392 char *peergroup = argv[idx]->arg;
4393
4394 /* Convert IP prefix string to struct prefix. */
4395 ret = str2prefix(prefix, &range);
4396 if (!ret) {
4397 vty_out(vty, "%% Malformed listen range\n");
4398 return CMD_WARNING_CONFIG_FAILED;
4399 }
4400
4401 afi = family2afi(range.family);
4402
4403 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4404 vty_out(vty,
4405 "%% Malformed listen range (link-local address)\n");
4406 return CMD_WARNING_CONFIG_FAILED;
4407 }
4408
4409 apply_mask(&range);
4410
4411 group = peer_group_lookup(bgp, peergroup);
4412 if (!group) {
4413 vty_out(vty, "%% Peer-group does not exist\n");
4414 return CMD_WARNING_CONFIG_FAILED;
4415 }
4416
4417 ret = peer_group_listen_range_del(group, &range);
4418 return bgp_vty_return(vty, ret);
4419 }
4420
4421 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4422 {
4423 struct peer_group *group;
4424 struct listnode *node, *nnode, *rnode, *nrnode;
4425 struct prefix *range;
4426 afi_t afi;
4427
4428 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4429 vty_out(vty, " bgp listen limit %d\n",
4430 bgp->dynamic_neighbors_limit);
4431
4432 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4433 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4434 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4435 nrnode, range)) {
4436 vty_out(vty,
4437 " bgp listen range %pFX peer-group %s\n",
4438 range, group->name);
4439 }
4440 }
4441 }
4442 }
4443
4444
4445 DEFUN (bgp_disable_connected_route_check,
4446 bgp_disable_connected_route_check_cmd,
4447 "bgp disable-ebgp-connected-route-check",
4448 BGP_STR
4449 "Disable checking if nexthop is connected on ebgp sessions\n")
4450 {
4451 VTY_DECLVAR_CONTEXT(bgp, bgp);
4452 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4453 bgp_clear_star_soft_in(vty, bgp->name);
4454
4455 return CMD_SUCCESS;
4456 }
4457
4458 DEFUN (no_bgp_disable_connected_route_check,
4459 no_bgp_disable_connected_route_check_cmd,
4460 "no bgp disable-ebgp-connected-route-check",
4461 NO_STR
4462 BGP_STR
4463 "Disable checking if nexthop is connected on ebgp sessions\n")
4464 {
4465 VTY_DECLVAR_CONTEXT(bgp, bgp);
4466 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4467 bgp_clear_star_soft_in(vty, bgp->name);
4468
4469 return CMD_SUCCESS;
4470 }
4471
4472
4473 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4474 const char *as_str)
4475 {
4476 VTY_DECLVAR_CONTEXT(bgp, bgp);
4477 int ret;
4478 as_t as;
4479 int as_type = AS_SPECIFIED;
4480 union sockunion su;
4481
4482 if (as_str[0] == 'i') {
4483 as = 0;
4484 as_type = AS_INTERNAL;
4485 } else if (as_str[0] == 'e') {
4486 as = 0;
4487 as_type = AS_EXTERNAL;
4488 } else {
4489 /* Get AS number. */
4490 as = strtoul(as_str, NULL, 10);
4491 }
4492
4493 /* If peer is peer group or interface peer, call proper function. */
4494 ret = str2sockunion(peer_str, &su);
4495 if (ret < 0) {
4496 struct peer *peer;
4497
4498 /* Check if existing interface peer */
4499 peer = peer_lookup_by_conf_if(bgp, peer_str);
4500
4501 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4502
4503 /* if not interface peer, check peer-group settings */
4504 if (ret < 0 && !peer) {
4505 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4506 if (ret < 0) {
4507 vty_out(vty,
4508 "%% Create the peer-group or interface first\n");
4509 return CMD_WARNING_CONFIG_FAILED;
4510 }
4511 return CMD_SUCCESS;
4512 }
4513 } else {
4514 if (peer_address_self_check(bgp, &su)) {
4515 vty_out(vty,
4516 "%% Can not configure the local system as neighbor\n");
4517 return CMD_WARNING_CONFIG_FAILED;
4518 }
4519 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4520 }
4521
4522 return bgp_vty_return(vty, ret);
4523 }
4524
4525 DEFUN (bgp_default_shutdown,
4526 bgp_default_shutdown_cmd,
4527 "[no] bgp default shutdown",
4528 NO_STR
4529 BGP_STR
4530 "Configure BGP defaults\n"
4531 "Apply administrative shutdown to newly configured peers\n")
4532 {
4533 VTY_DECLVAR_CONTEXT(bgp, bgp);
4534 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4535 return CMD_SUCCESS;
4536 }
4537
4538 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4539 BGP_STR
4540 "Administrative shutdown of the BGP instance\n"
4541 "Add a shutdown message (RFC 8203)\n"
4542 "Shutdown message\n")
4543 {
4544 char *msgstr = NULL;
4545
4546 VTY_DECLVAR_CONTEXT(bgp, bgp);
4547
4548 if (argc > 3)
4549 msgstr = argv_concat(argv, argc, 3);
4550
4551 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4552 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4553 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4554 return CMD_WARNING_CONFIG_FAILED;
4555 }
4556
4557 bgp_shutdown_enable(bgp, msgstr);
4558 XFREE(MTYPE_TMP, msgstr);
4559
4560 return CMD_SUCCESS;
4561 }
4562
4563 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4564 BGP_STR "Administrative shutdown of the BGP instance\n")
4565 {
4566 VTY_DECLVAR_CONTEXT(bgp, bgp);
4567
4568 bgp_shutdown_enable(bgp, NULL);
4569
4570 return CMD_SUCCESS;
4571 }
4572
4573 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4574 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4575 {
4576 VTY_DECLVAR_CONTEXT(bgp, bgp);
4577
4578 bgp_shutdown_disable(bgp);
4579
4580 return CMD_SUCCESS;
4581 }
4582
4583 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4584 "no bgp shutdown message MSG...", NO_STR BGP_STR
4585 "Administrative shutdown of the BGP instance\n"
4586 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4587
4588 DEFUN (neighbor_remote_as,
4589 neighbor_remote_as_cmd,
4590 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4591 NEIGHBOR_STR
4592 NEIGHBOR_ADDR_STR2
4593 "Specify a BGP neighbor\n"
4594 AS_STR
4595 "Internal BGP peer\n"
4596 "External BGP peer\n")
4597 {
4598 int idx_peer = 1;
4599 int idx_remote_as = 3;
4600 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4601 argv[idx_remote_as]->arg);
4602 }
4603
4604 DEFPY (bgp_allow_martian,
4605 bgp_allow_martian_cmd,
4606 "[no]$no bgp allow-martian-nexthop",
4607 NO_STR
4608 BGP_STR
4609 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4610 {
4611 VTY_DECLVAR_CONTEXT(bgp, bgp);
4612
4613 if (no)
4614 bgp->allow_martian = false;
4615 else
4616 bgp->allow_martian = true;
4617
4618 return CMD_SUCCESS;
4619 }
4620
4621 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4622 * sessions do not wait for hold timer expiry to bring down the sessions
4623 * when nexthop becomes unreachable
4624 */
4625 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4626 BGP_STR "Fast convergence for bgp sessions\n")
4627 {
4628 VTY_DECLVAR_CONTEXT(bgp, bgp);
4629 bgp->fast_convergence = true;
4630
4631 return CMD_SUCCESS;
4632 }
4633
4634 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4635 "no bgp fast-convergence",
4636 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4637 {
4638 VTY_DECLVAR_CONTEXT(bgp, bgp);
4639 bgp->fast_convergence = false;
4640
4641 return CMD_SUCCESS;
4642 }
4643
4644 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4645 int v6only,
4646 const char *peer_group_name,
4647 const char *as_str)
4648 {
4649 VTY_DECLVAR_CONTEXT(bgp, bgp);
4650 as_t as = 0;
4651 int as_type = AS_UNSPECIFIED;
4652 struct peer *peer;
4653 struct peer_group *group;
4654 int ret = 0;
4655
4656 group = peer_group_lookup(bgp, conf_if);
4657
4658 if (group) {
4659 vty_out(vty, "%% Name conflict with peer-group \n");
4660 return CMD_WARNING_CONFIG_FAILED;
4661 }
4662
4663 if (as_str) {
4664 if (as_str[0] == 'i') {
4665 as_type = AS_INTERNAL;
4666 } else if (as_str[0] == 'e') {
4667 as_type = AS_EXTERNAL;
4668 } else {
4669 /* Get AS number. */
4670 as = strtoul(as_str, NULL, 10);
4671 as_type = AS_SPECIFIED;
4672 }
4673 }
4674
4675 peer = peer_lookup_by_conf_if(bgp, conf_if);
4676 if (peer) {
4677 if (as_str)
4678 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4679 } else {
4680 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4681 NULL);
4682
4683 if (!peer) {
4684 vty_out(vty, "%% BGP failed to create peer\n");
4685 return CMD_WARNING_CONFIG_FAILED;
4686 }
4687
4688 if (v6only)
4689 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4690
4691 /* Request zebra to initiate IPv6 RAs on this interface. We do
4692 * this
4693 * any unnumbered peer in order to not worry about run-time
4694 * transitions
4695 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4696 * address
4697 * gets deleted later etc.)
4698 */
4699 if (peer->ifp)
4700 bgp_zebra_initiate_radv(bgp, peer);
4701 }
4702
4703 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4704 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4705 if (v6only)
4706 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4707 else
4708 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4709
4710 /* v6only flag changed. Reset bgp seesion */
4711 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4712 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4713 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4714 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4715 } else
4716 bgp_session_reset(peer);
4717 }
4718
4719 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4720 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4721 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4722 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4723 }
4724
4725 if (peer_group_name) {
4726 group = peer_group_lookup(bgp, peer_group_name);
4727 if (!group) {
4728 vty_out(vty, "%% Configure the peer-group first\n");
4729 return CMD_WARNING_CONFIG_FAILED;
4730 }
4731
4732 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4733 }
4734
4735 return bgp_vty_return(vty, ret);
4736 }
4737
4738 DEFUN (neighbor_interface_config,
4739 neighbor_interface_config_cmd,
4740 "neighbor WORD interface [peer-group PGNAME]",
4741 NEIGHBOR_STR
4742 "Interface name or neighbor tag\n"
4743 "Enable BGP on interface\n"
4744 "Member of the peer-group\n"
4745 "Peer-group name\n")
4746 {
4747 int idx_word = 1;
4748 int idx_peer_group_word = 4;
4749
4750 if (argc > idx_peer_group_word)
4751 return peer_conf_interface_get(
4752 vty, argv[idx_word]->arg, 0,
4753 argv[idx_peer_group_word]->arg, NULL);
4754 else
4755 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4756 NULL, NULL);
4757 }
4758
4759 DEFUN (neighbor_interface_config_v6only,
4760 neighbor_interface_config_v6only_cmd,
4761 "neighbor WORD interface v6only [peer-group PGNAME]",
4762 NEIGHBOR_STR
4763 "Interface name or neighbor tag\n"
4764 "Enable BGP on interface\n"
4765 "Enable BGP with v6 link-local only\n"
4766 "Member of the peer-group\n"
4767 "Peer-group name\n")
4768 {
4769 int idx_word = 1;
4770 int idx_peer_group_word = 5;
4771
4772 if (argc > idx_peer_group_word)
4773 return peer_conf_interface_get(
4774 vty, argv[idx_word]->arg, 1,
4775 argv[idx_peer_group_word]->arg, NULL);
4776
4777 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4778 }
4779
4780
4781 DEFUN (neighbor_interface_config_remote_as,
4782 neighbor_interface_config_remote_as_cmd,
4783 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4784 NEIGHBOR_STR
4785 "Interface name or neighbor tag\n"
4786 "Enable BGP on interface\n"
4787 "Specify a BGP neighbor\n"
4788 AS_STR
4789 "Internal BGP peer\n"
4790 "External BGP peer\n")
4791 {
4792 int idx_word = 1;
4793 int idx_remote_as = 4;
4794 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4795 argv[idx_remote_as]->arg);
4796 }
4797
4798 DEFUN (neighbor_interface_v6only_config_remote_as,
4799 neighbor_interface_v6only_config_remote_as_cmd,
4800 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4801 NEIGHBOR_STR
4802 "Interface name or neighbor tag\n"
4803 "Enable BGP with v6 link-local only\n"
4804 "Enable BGP on interface\n"
4805 "Specify a BGP neighbor\n"
4806 AS_STR
4807 "Internal BGP peer\n"
4808 "External BGP peer\n")
4809 {
4810 int idx_word = 1;
4811 int idx_remote_as = 5;
4812 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4813 argv[idx_remote_as]->arg);
4814 }
4815
4816 DEFUN (neighbor_peer_group,
4817 neighbor_peer_group_cmd,
4818 "neighbor WORD peer-group",
4819 NEIGHBOR_STR
4820 "Interface name or neighbor tag\n"
4821 "Configure peer-group\n")
4822 {
4823 VTY_DECLVAR_CONTEXT(bgp, bgp);
4824 int idx_word = 1;
4825 struct peer *peer;
4826 struct peer_group *group;
4827
4828 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4829 if (peer) {
4830 vty_out(vty, "%% Name conflict with interface: \n");
4831 return CMD_WARNING_CONFIG_FAILED;
4832 }
4833
4834 group = peer_group_get(bgp, argv[idx_word]->arg);
4835 if (!group) {
4836 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4837 return CMD_WARNING_CONFIG_FAILED;
4838 }
4839
4840 return CMD_SUCCESS;
4841 }
4842
4843 DEFUN (no_neighbor,
4844 no_neighbor_cmd,
4845 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4846 NO_STR
4847 NEIGHBOR_STR
4848 NEIGHBOR_ADDR_STR2
4849 "Specify a BGP neighbor\n"
4850 AS_STR
4851 "Internal BGP peer\n"
4852 "External BGP peer\n")
4853 {
4854 VTY_DECLVAR_CONTEXT(bgp, bgp);
4855 int idx_peer = 2;
4856 int ret;
4857 union sockunion su;
4858 struct peer_group *group;
4859 struct peer *peer;
4860 struct peer *other;
4861
4862 ret = str2sockunion(argv[idx_peer]->arg, &su);
4863 if (ret < 0) {
4864 /* look up for neighbor by interface name config. */
4865 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4866 if (peer) {
4867 /* Request zebra to terminate IPv6 RAs on this
4868 * interface. */
4869 if (peer->ifp)
4870 bgp_zebra_terminate_radv(peer->bgp, peer);
4871 peer_notify_unconfig(peer);
4872 peer_delete(peer);
4873 return CMD_SUCCESS;
4874 }
4875
4876 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4877 if (group) {
4878 peer_group_notify_unconfig(group);
4879 peer_group_delete(group);
4880 } else {
4881 vty_out(vty, "%% Create the peer-group first\n");
4882 return CMD_WARNING_CONFIG_FAILED;
4883 }
4884 } else {
4885 peer = peer_lookup(bgp, &su);
4886 if (peer) {
4887 if (peer_dynamic_neighbor(peer)) {
4888 vty_out(vty,
4889 "%% Operation not allowed on a dynamic neighbor\n");
4890 return CMD_WARNING_CONFIG_FAILED;
4891 }
4892
4893 other = peer->doppelganger;
4894
4895 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4896 bgp_zebra_terminate_radv(peer->bgp, peer);
4897
4898 peer_notify_unconfig(peer);
4899 peer_delete(peer);
4900 if (other && other->status != Deleted) {
4901 peer_notify_unconfig(other);
4902 peer_delete(other);
4903 }
4904 }
4905 }
4906
4907 return CMD_SUCCESS;
4908 }
4909
4910 DEFUN (no_neighbor_interface_config,
4911 no_neighbor_interface_config_cmd,
4912 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4913 NO_STR
4914 NEIGHBOR_STR
4915 "Interface name\n"
4916 "Configure BGP on interface\n"
4917 "Enable BGP with v6 link-local only\n"
4918 "Member of the peer-group\n"
4919 "Peer-group name\n"
4920 "Specify a BGP neighbor\n"
4921 AS_STR
4922 "Internal BGP peer\n"
4923 "External BGP peer\n")
4924 {
4925 VTY_DECLVAR_CONTEXT(bgp, bgp);
4926 int idx_word = 2;
4927 struct peer *peer;
4928
4929 /* look up for neighbor by interface name config. */
4930 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4931 if (peer) {
4932 /* Request zebra to terminate IPv6 RAs on this interface. */
4933 if (peer->ifp)
4934 bgp_zebra_terminate_radv(peer->bgp, peer);
4935 peer_notify_unconfig(peer);
4936 peer_delete(peer);
4937 } else {
4938 vty_out(vty, "%% Create the bgp interface first\n");
4939 return CMD_WARNING_CONFIG_FAILED;
4940 }
4941 return CMD_SUCCESS;
4942 }
4943
4944 DEFUN (no_neighbor_peer_group,
4945 no_neighbor_peer_group_cmd,
4946 "no neighbor WORD peer-group",
4947 NO_STR
4948 NEIGHBOR_STR
4949 "Neighbor tag\n"
4950 "Configure peer-group\n")
4951 {
4952 VTY_DECLVAR_CONTEXT(bgp, bgp);
4953 int idx_word = 2;
4954 struct peer_group *group;
4955
4956 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4957 if (group) {
4958 peer_group_notify_unconfig(group);
4959 peer_group_delete(group);
4960 } else {
4961 vty_out(vty, "%% Create the peer-group first\n");
4962 return CMD_WARNING_CONFIG_FAILED;
4963 }
4964 return CMD_SUCCESS;
4965 }
4966
4967 DEFUN (no_neighbor_interface_peer_group_remote_as,
4968 no_neighbor_interface_peer_group_remote_as_cmd,
4969 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4970 NO_STR
4971 NEIGHBOR_STR
4972 "Interface name or neighbor tag\n"
4973 "Specify a BGP neighbor\n"
4974 AS_STR
4975 "Internal BGP peer\n"
4976 "External BGP peer\n")
4977 {
4978 VTY_DECLVAR_CONTEXT(bgp, bgp);
4979 int idx_word = 2;
4980 struct peer_group *group;
4981 struct peer *peer;
4982
4983 /* look up for neighbor by interface name config. */
4984 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4985 if (peer) {
4986 peer_as_change(peer, 0, AS_UNSPECIFIED);
4987 return CMD_SUCCESS;
4988 }
4989
4990 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4991 if (group)
4992 peer_group_remote_as_delete(group);
4993 else {
4994 vty_out(vty, "%% Create the peer-group or interface first\n");
4995 return CMD_WARNING_CONFIG_FAILED;
4996 }
4997 return CMD_SUCCESS;
4998 }
4999
5000 DEFUN (neighbor_local_as,
5001 neighbor_local_as_cmd,
5002 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
5003 NEIGHBOR_STR
5004 NEIGHBOR_ADDR_STR2
5005 "Specify a local-as number\n"
5006 "AS number used as local AS\n")
5007 {
5008 int idx_peer = 1;
5009 int idx_number = 3;
5010 struct peer *peer;
5011 int ret;
5012 as_t as;
5013
5014 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
5017
5018 as = strtoul(argv[idx_number]->arg, NULL, 10);
5019 ret = peer_local_as_set(peer, as, 0, 0);
5020 return bgp_vty_return(vty, ret);
5021 }
5022
5023 DEFUN (neighbor_local_as_no_prepend,
5024 neighbor_local_as_no_prepend_cmd,
5025 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
5026 NEIGHBOR_STR
5027 NEIGHBOR_ADDR_STR2
5028 "Specify a local-as number\n"
5029 "AS number used as local AS\n"
5030 "Do not prepend local-as to updates from ebgp peers\n")
5031 {
5032 int idx_peer = 1;
5033 int idx_number = 3;
5034 struct peer *peer;
5035 int ret;
5036 as_t as;
5037
5038 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5039 if (!peer)
5040 return CMD_WARNING_CONFIG_FAILED;
5041
5042 as = strtoul(argv[idx_number]->arg, NULL, 10);
5043 ret = peer_local_as_set(peer, as, 1, 0);
5044 return bgp_vty_return(vty, ret);
5045 }
5046
5047 DEFUN (neighbor_local_as_no_prepend_replace_as,
5048 neighbor_local_as_no_prepend_replace_as_cmd,
5049 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
5050 NEIGHBOR_STR
5051 NEIGHBOR_ADDR_STR2
5052 "Specify a local-as number\n"
5053 "AS number used as local AS\n"
5054 "Do not prepend local-as to updates from ebgp peers\n"
5055 "Do not prepend local-as to updates from ibgp peers\n")
5056 {
5057 int idx_peer = 1;
5058 int idx_number = 3;
5059 struct peer *peer;
5060 int ret;
5061 as_t as;
5062
5063 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5064 if (!peer)
5065 return CMD_WARNING_CONFIG_FAILED;
5066
5067 as = strtoul(argv[idx_number]->arg, NULL, 10);
5068 ret = peer_local_as_set(peer, as, 1, 1);
5069 return bgp_vty_return(vty, ret);
5070 }
5071
5072 DEFUN (no_neighbor_local_as,
5073 no_neighbor_local_as_cmd,
5074 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5075 NO_STR
5076 NEIGHBOR_STR
5077 NEIGHBOR_ADDR_STR2
5078 "Specify a local-as number\n"
5079 "AS number used as local AS\n"
5080 "Do not prepend local-as to updates from ebgp peers\n"
5081 "Do not prepend local-as to updates from ibgp peers\n")
5082 {
5083 int idx_peer = 2;
5084 struct peer *peer;
5085 int ret;
5086
5087 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5088 if (!peer)
5089 return CMD_WARNING_CONFIG_FAILED;
5090
5091 ret = peer_local_as_unset(peer);
5092 return bgp_vty_return(vty, ret);
5093 }
5094
5095
5096 DEFUN (neighbor_solo,
5097 neighbor_solo_cmd,
5098 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5099 NEIGHBOR_STR
5100 NEIGHBOR_ADDR_STR2
5101 "Solo peer - part of its own update group\n")
5102 {
5103 int idx_peer = 1;
5104 struct peer *peer;
5105 int ret;
5106
5107 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5108 if (!peer)
5109 return CMD_WARNING_CONFIG_FAILED;
5110
5111 ret = update_group_adjust_soloness(peer, 1);
5112 return bgp_vty_return(vty, ret);
5113 }
5114
5115 DEFUN (no_neighbor_solo,
5116 no_neighbor_solo_cmd,
5117 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5118 NO_STR
5119 NEIGHBOR_STR
5120 NEIGHBOR_ADDR_STR2
5121 "Solo peer - part of its own update group\n")
5122 {
5123 int idx_peer = 2;
5124 struct peer *peer;
5125 int ret;
5126
5127 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5128 if (!peer)
5129 return CMD_WARNING_CONFIG_FAILED;
5130
5131 ret = update_group_adjust_soloness(peer, 0);
5132 return bgp_vty_return(vty, ret);
5133 }
5134
5135 DEFUN (neighbor_password,
5136 neighbor_password_cmd,
5137 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5138 NEIGHBOR_STR
5139 NEIGHBOR_ADDR_STR2
5140 "Set a password\n"
5141 "The password\n")
5142 {
5143 int idx_peer = 1;
5144 int idx_line = 3;
5145 struct peer *peer;
5146 int ret;
5147
5148 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5149 if (!peer)
5150 return CMD_WARNING_CONFIG_FAILED;
5151
5152 ret = peer_password_set(peer, argv[idx_line]->arg);
5153 return bgp_vty_return(vty, ret);
5154 }
5155
5156 DEFUN (no_neighbor_password,
5157 no_neighbor_password_cmd,
5158 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5159 NO_STR
5160 NEIGHBOR_STR
5161 NEIGHBOR_ADDR_STR2
5162 "Set a password\n"
5163 "The password\n")
5164 {
5165 int idx_peer = 2;
5166 struct peer *peer;
5167 int ret;
5168
5169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5170 if (!peer)
5171 return CMD_WARNING_CONFIG_FAILED;
5172
5173 ret = peer_password_unset(peer);
5174 return bgp_vty_return(vty, ret);
5175 }
5176
5177 DEFUN (neighbor_activate,
5178 neighbor_activate_cmd,
5179 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5180 NEIGHBOR_STR
5181 NEIGHBOR_ADDR_STR2
5182 "Enable the Address Family for this Neighbor\n")
5183 {
5184 int idx_peer = 1;
5185 int ret;
5186 struct peer *peer;
5187
5188 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5189 if (!peer)
5190 return CMD_WARNING_CONFIG_FAILED;
5191
5192 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5193 return bgp_vty_return(vty, ret);
5194 }
5195
5196 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5197 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5198 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5199 "Enable the Address Family for this Neighbor\n")
5200
5201 DEFUN (no_neighbor_activate,
5202 no_neighbor_activate_cmd,
5203 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5204 NO_STR
5205 NEIGHBOR_STR
5206 NEIGHBOR_ADDR_STR2
5207 "Enable the Address Family for this Neighbor\n")
5208 {
5209 int idx_peer = 2;
5210 int ret;
5211 struct peer *peer;
5212
5213 /* Lookup peer. */
5214 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5215 if (!peer)
5216 return CMD_WARNING_CONFIG_FAILED;
5217
5218 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5219 return bgp_vty_return(vty, ret);
5220 }
5221
5222 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5223 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5224 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5225 "Enable the Address Family for this Neighbor\n")
5226
5227 DEFUN (neighbor_set_peer_group,
5228 neighbor_set_peer_group_cmd,
5229 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5230 NEIGHBOR_STR
5231 NEIGHBOR_ADDR_STR2
5232 "Member of the peer-group\n"
5233 "Peer-group name\n")
5234 {
5235 VTY_DECLVAR_CONTEXT(bgp, bgp);
5236 int idx_peer = 1;
5237 int idx_word = 3;
5238 int ret;
5239 as_t as;
5240 union sockunion su;
5241 struct peer *peer;
5242 struct peer_group *group;
5243
5244 ret = str2sockunion(argv[idx_peer]->arg, &su);
5245 if (ret < 0) {
5246 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5247 if (!peer) {
5248 vty_out(vty, "%% Malformed address or name: %s\n",
5249 argv[idx_peer]->arg);
5250 return CMD_WARNING_CONFIG_FAILED;
5251 }
5252 } else {
5253 if (peer_address_self_check(bgp, &su)) {
5254 vty_out(vty,
5255 "%% Can not configure the local system as neighbor\n");
5256 return CMD_WARNING_CONFIG_FAILED;
5257 }
5258
5259 /* Disallow for dynamic neighbor. */
5260 peer = peer_lookup(bgp, &su);
5261 if (peer && peer_dynamic_neighbor(peer)) {
5262 vty_out(vty,
5263 "%% Operation not allowed on a dynamic neighbor\n");
5264 return CMD_WARNING_CONFIG_FAILED;
5265 }
5266 }
5267
5268 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5269 if (!group) {
5270 vty_out(vty, "%% Configure the peer-group first\n");
5271 return CMD_WARNING_CONFIG_FAILED;
5272 }
5273
5274 ret = peer_group_bind(bgp, &su, peer, group, &as);
5275
5276 return bgp_vty_return(vty, ret);
5277 }
5278
5279 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5280 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5281 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5282 "Member of the peer-group\n"
5283 "Peer-group name\n")
5284
5285 DEFUN (no_neighbor_set_peer_group,
5286 no_neighbor_set_peer_group_cmd,
5287 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5288 NO_STR
5289 NEIGHBOR_STR
5290 NEIGHBOR_ADDR_STR2
5291 "Member of the peer-group\n"
5292 "Peer-group name\n")
5293 {
5294 VTY_DECLVAR_CONTEXT(bgp, bgp);
5295 int idx_peer = 2;
5296 int idx_word = 4;
5297 int ret;
5298 struct peer *peer;
5299 struct peer_group *group;
5300
5301 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5302 if (!peer)
5303 return CMD_WARNING_CONFIG_FAILED;
5304
5305 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5306 if (!group) {
5307 vty_out(vty, "%% Configure the peer-group first\n");
5308 return CMD_WARNING_CONFIG_FAILED;
5309 }
5310
5311 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5312 bgp_zebra_terminate_radv(peer->bgp, peer);
5313
5314 peer_notify_unconfig(peer);
5315 ret = peer_delete(peer);
5316
5317 return bgp_vty_return(vty, ret);
5318 }
5319
5320 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5321 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5322 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5323 "Member of the peer-group\n"
5324 "Peer-group name\n")
5325
5326 /* neighbor passive. */
5327 DEFUN (neighbor_passive,
5328 neighbor_passive_cmd,
5329 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5330 NEIGHBOR_STR
5331 NEIGHBOR_ADDR_STR2
5332 "Don't send open messages to this neighbor\n")
5333 {
5334 int idx_peer = 1;
5335 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5336 }
5337
5338 DEFUN (no_neighbor_passive,
5339 no_neighbor_passive_cmd,
5340 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5341 NO_STR
5342 NEIGHBOR_STR
5343 NEIGHBOR_ADDR_STR2
5344 "Don't send open messages to this neighbor\n")
5345 {
5346 int idx_peer = 2;
5347 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5348 }
5349
5350 /* neighbor shutdown. */
5351 DEFUN (neighbor_shutdown_msg,
5352 neighbor_shutdown_msg_cmd,
5353 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5354 NEIGHBOR_STR
5355 NEIGHBOR_ADDR_STR2
5356 "Administratively shut down this neighbor\n"
5357 "Add a shutdown message (RFC 8203)\n"
5358 "Shutdown message\n")
5359 {
5360 int idx_peer = 1;
5361
5362 if (argc >= 5) {
5363 struct peer *peer =
5364 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5365 char *message;
5366
5367 if (!peer)
5368 return CMD_WARNING_CONFIG_FAILED;
5369 message = argv_concat(argv, argc, 4);
5370 peer_tx_shutdown_message_set(peer, message);
5371 XFREE(MTYPE_TMP, message);
5372 }
5373
5374 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5375 }
5376
5377 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5378 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5379 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5380 "Administratively shut down this neighbor\n")
5381
5382 DEFUN (no_neighbor_shutdown_msg,
5383 no_neighbor_shutdown_msg_cmd,
5384 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5385 NO_STR
5386 NEIGHBOR_STR
5387 NEIGHBOR_ADDR_STR2
5388 "Administratively shut down this neighbor\n"
5389 "Remove a shutdown message (RFC 8203)\n"
5390 "Shutdown message\n")
5391 {
5392 int idx_peer = 2;
5393
5394 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5395 PEER_FLAG_SHUTDOWN);
5396 }
5397
5398 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5399 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5400 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5401 "Administratively shut down this neighbor\n")
5402
5403 DEFUN(neighbor_shutdown_rtt,
5404 neighbor_shutdown_rtt_cmd,
5405 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5406 NEIGHBOR_STR
5407 NEIGHBOR_ADDR_STR2
5408 "Administratively shut down this neighbor\n"
5409 "Shutdown if round-trip-time is higher than expected\n"
5410 "Round-trip-time in milliseconds\n"
5411 "Specify the number of keepalives before shutdown\n"
5412 "The number of keepalives with higher RTT to shutdown\n")
5413 {
5414 int idx_peer = 1;
5415 int idx_rtt = 4;
5416 int idx_count = 0;
5417 struct peer *peer;
5418
5419 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5420
5421 if (!peer)
5422 return CMD_WARNING_CONFIG_FAILED;
5423
5424 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5425
5426 if (argv_find(argv, argc, "count", &idx_count))
5427 peer->rtt_keepalive_conf =
5428 strtol(argv[idx_count + 1]->arg, NULL, 10);
5429
5430 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5431 PEER_FLAG_RTT_SHUTDOWN);
5432 }
5433
5434 DEFUN(no_neighbor_shutdown_rtt,
5435 no_neighbor_shutdown_rtt_cmd,
5436 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5437 NO_STR
5438 NEIGHBOR_STR
5439 NEIGHBOR_ADDR_STR2
5440 "Administratively shut down this neighbor\n"
5441 "Shutdown if round-trip-time is higher than expected\n"
5442 "Round-trip-time in milliseconds\n"
5443 "Specify the number of keepalives before shutdown\n"
5444 "The number of keepalives with higher RTT to shutdown\n")
5445 {
5446 int idx_peer = 2;
5447 struct peer *peer;
5448
5449 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5450
5451 if (!peer)
5452 return CMD_WARNING_CONFIG_FAILED;
5453
5454 peer->rtt_expected = 0;
5455 peer->rtt_keepalive_conf = 1;
5456
5457 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5458 PEER_FLAG_RTT_SHUTDOWN);
5459 }
5460
5461 /* neighbor capability dynamic. */
5462 DEFUN (neighbor_capability_dynamic,
5463 neighbor_capability_dynamic_cmd,
5464 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Advertise capability to the peer\n"
5468 "Advertise dynamic capability to this neighbor\n")
5469 {
5470 int idx_peer = 1;
5471 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5472 PEER_FLAG_DYNAMIC_CAPABILITY);
5473 }
5474
5475 DEFUN (no_neighbor_capability_dynamic,
5476 no_neighbor_capability_dynamic_cmd,
5477 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5478 NO_STR
5479 NEIGHBOR_STR
5480 NEIGHBOR_ADDR_STR2
5481 "Advertise capability to the peer\n"
5482 "Advertise dynamic capability to this neighbor\n")
5483 {
5484 int idx_peer = 2;
5485 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5486 PEER_FLAG_DYNAMIC_CAPABILITY);
5487 }
5488
5489 /* neighbor dont-capability-negotiate */
5490 DEFUN (neighbor_dont_capability_negotiate,
5491 neighbor_dont_capability_negotiate_cmd,
5492 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5493 NEIGHBOR_STR
5494 NEIGHBOR_ADDR_STR2
5495 "Do not perform capability negotiation\n")
5496 {
5497 int idx_peer = 1;
5498 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5499 PEER_FLAG_DONT_CAPABILITY);
5500 }
5501
5502 DEFUN (no_neighbor_dont_capability_negotiate,
5503 no_neighbor_dont_capability_negotiate_cmd,
5504 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5505 NO_STR
5506 NEIGHBOR_STR
5507 NEIGHBOR_ADDR_STR2
5508 "Do not perform capability negotiation\n")
5509 {
5510 int idx_peer = 2;
5511 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5512 PEER_FLAG_DONT_CAPABILITY);
5513 }
5514
5515 /* neighbor capability extended next hop encoding */
5516 DEFUN (neighbor_capability_enhe,
5517 neighbor_capability_enhe_cmd,
5518 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5519 NEIGHBOR_STR
5520 NEIGHBOR_ADDR_STR2
5521 "Advertise capability to the peer\n"
5522 "Advertise extended next-hop capability to the peer\n")
5523 {
5524 int idx_peer = 1;
5525 struct peer *peer;
5526
5527 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5528 if (peer && peer->conf_if)
5529 return CMD_SUCCESS;
5530
5531 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5532 PEER_FLAG_CAPABILITY_ENHE);
5533 }
5534
5535 DEFUN (no_neighbor_capability_enhe,
5536 no_neighbor_capability_enhe_cmd,
5537 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5538 NO_STR
5539 NEIGHBOR_STR
5540 NEIGHBOR_ADDR_STR2
5541 "Advertise capability to the peer\n"
5542 "Advertise extended next-hop capability to the peer\n")
5543 {
5544 int idx_peer = 2;
5545 struct peer *peer;
5546
5547 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5548 if (peer && peer->conf_if) {
5549 vty_out(vty,
5550 "Peer %s cannot have capability extended-nexthop turned off\n",
5551 argv[idx_peer]->arg);
5552 return CMD_WARNING_CONFIG_FAILED;
5553 }
5554
5555 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5556 PEER_FLAG_CAPABILITY_ENHE);
5557 }
5558
5559 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5560 afi_t afi, safi_t safi, uint32_t flag,
5561 int set)
5562 {
5563 int ret;
5564 struct peer *peer;
5565
5566 peer = peer_and_group_lookup_vty(vty, peer_str);
5567 if (!peer)
5568 return CMD_WARNING_CONFIG_FAILED;
5569
5570 if (set)
5571 ret = peer_af_flag_set(peer, afi, safi, flag);
5572 else
5573 ret = peer_af_flag_unset(peer, afi, safi, flag);
5574
5575 return bgp_vty_return(vty, ret);
5576 }
5577
5578 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5579 afi_t afi, safi_t safi, uint32_t flag)
5580 {
5581 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5582 }
5583
5584 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5585 afi_t afi, safi_t safi, uint32_t flag)
5586 {
5587 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5588 }
5589
5590 /* neighbor capability orf prefix-list. */
5591 DEFUN (neighbor_capability_orf_prefix,
5592 neighbor_capability_orf_prefix_cmd,
5593 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5594 NEIGHBOR_STR
5595 NEIGHBOR_ADDR_STR2
5596 "Advertise capability to the peer\n"
5597 "Advertise ORF capability to the peer\n"
5598 "Advertise prefixlist ORF capability to this neighbor\n"
5599 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5600 "Capability to RECEIVE the ORF from this neighbor\n"
5601 "Capability to SEND the ORF to this neighbor\n")
5602 {
5603 int idx_send_recv = 5;
5604 char *peer_str = argv[1]->arg;
5605 struct peer *peer;
5606 afi_t afi = bgp_node_afi(vty);
5607 safi_t safi = bgp_node_safi(vty);
5608
5609 peer = peer_and_group_lookup_vty(vty, peer_str);
5610 if (!peer)
5611 return CMD_WARNING_CONFIG_FAILED;
5612
5613 if (strmatch(argv[idx_send_recv]->text, "send"))
5614 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5615 PEER_FLAG_ORF_PREFIX_SM);
5616
5617 if (strmatch(argv[idx_send_recv]->text, "receive"))
5618 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5619 PEER_FLAG_ORF_PREFIX_RM);
5620
5621 if (strmatch(argv[idx_send_recv]->text, "both"))
5622 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5623 PEER_FLAG_ORF_PREFIX_SM)
5624 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5625 PEER_FLAG_ORF_PREFIX_RM);
5626
5627 return CMD_WARNING_CONFIG_FAILED;
5628 }
5629
5630 ALIAS_HIDDEN(
5631 neighbor_capability_orf_prefix,
5632 neighbor_capability_orf_prefix_hidden_cmd,
5633 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5634 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5635 "Advertise capability to the peer\n"
5636 "Advertise ORF capability to the peer\n"
5637 "Advertise prefixlist ORF capability to this neighbor\n"
5638 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5639 "Capability to RECEIVE the ORF from this neighbor\n"
5640 "Capability to SEND the ORF to this neighbor\n")
5641
5642 DEFUN (no_neighbor_capability_orf_prefix,
5643 no_neighbor_capability_orf_prefix_cmd,
5644 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5645 NO_STR
5646 NEIGHBOR_STR
5647 NEIGHBOR_ADDR_STR2
5648 "Advertise capability to the peer\n"
5649 "Advertise ORF capability to the peer\n"
5650 "Advertise prefixlist ORF capability to this neighbor\n"
5651 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5652 "Capability to RECEIVE the ORF from this neighbor\n"
5653 "Capability to SEND the ORF to this neighbor\n")
5654 {
5655 int idx_send_recv = 6;
5656 char *peer_str = argv[2]->arg;
5657 struct peer *peer;
5658 afi_t afi = bgp_node_afi(vty);
5659 safi_t safi = bgp_node_safi(vty);
5660
5661 peer = peer_and_group_lookup_vty(vty, peer_str);
5662 if (!peer)
5663 return CMD_WARNING_CONFIG_FAILED;
5664
5665 if (strmatch(argv[idx_send_recv]->text, "send"))
5666 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5667 PEER_FLAG_ORF_PREFIX_SM);
5668
5669 if (strmatch(argv[idx_send_recv]->text, "receive"))
5670 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5671 PEER_FLAG_ORF_PREFIX_RM);
5672
5673 if (strmatch(argv[idx_send_recv]->text, "both"))
5674 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5675 PEER_FLAG_ORF_PREFIX_SM)
5676 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5677 PEER_FLAG_ORF_PREFIX_RM);
5678
5679 return CMD_WARNING_CONFIG_FAILED;
5680 }
5681
5682 ALIAS_HIDDEN(
5683 no_neighbor_capability_orf_prefix,
5684 no_neighbor_capability_orf_prefix_hidden_cmd,
5685 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5686 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5687 "Advertise capability to the peer\n"
5688 "Advertise ORF capability to the peer\n"
5689 "Advertise prefixlist ORF capability to this neighbor\n"
5690 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5691 "Capability to RECEIVE the ORF from this neighbor\n"
5692 "Capability to SEND the ORF to this neighbor\n")
5693
5694 /* neighbor next-hop-self. */
5695 DEFUN (neighbor_nexthop_self,
5696 neighbor_nexthop_self_cmd,
5697 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Disable the next hop calculation for this neighbor\n")
5701 {
5702 int idx_peer = 1;
5703 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5704 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5705 }
5706
5707 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5708 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5709 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5710 "Disable the next hop calculation for this neighbor\n")
5711
5712 /* neighbor next-hop-self. */
5713 DEFUN (neighbor_nexthop_self_force,
5714 neighbor_nexthop_self_force_cmd,
5715 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5716 NEIGHBOR_STR
5717 NEIGHBOR_ADDR_STR2
5718 "Disable the next hop calculation for this neighbor\n"
5719 "Set the next hop to self for reflected routes\n")
5720 {
5721 int idx_peer = 1;
5722 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5723 bgp_node_safi(vty),
5724 PEER_FLAG_FORCE_NEXTHOP_SELF);
5725 }
5726
5727 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5728 neighbor_nexthop_self_force_hidden_cmd,
5729 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5730 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5731 "Disable the next hop calculation for this neighbor\n"
5732 "Set the next hop to self for reflected routes\n")
5733
5734 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5735 neighbor_nexthop_self_all_hidden_cmd,
5736 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Disable the next hop calculation for this neighbor\n"
5739 "Set the next hop to self for reflected routes\n")
5740
5741 DEFUN (no_neighbor_nexthop_self,
5742 no_neighbor_nexthop_self_cmd,
5743 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5744 NO_STR
5745 NEIGHBOR_STR
5746 NEIGHBOR_ADDR_STR2
5747 "Disable the next hop calculation for this neighbor\n")
5748 {
5749 int idx_peer = 2;
5750 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5751 bgp_node_afi(vty), bgp_node_safi(vty),
5752 PEER_FLAG_NEXTHOP_SELF);
5753 }
5754
5755 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5756 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5757 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5758 "Disable the next hop calculation for this neighbor\n")
5759
5760 DEFUN (no_neighbor_nexthop_self_force,
5761 no_neighbor_nexthop_self_force_cmd,
5762 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5763 NO_STR
5764 NEIGHBOR_STR
5765 NEIGHBOR_ADDR_STR2
5766 "Disable the next hop calculation for this neighbor\n"
5767 "Set the next hop to self for reflected routes\n")
5768 {
5769 int idx_peer = 2;
5770 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5771 bgp_node_afi(vty), bgp_node_safi(vty),
5772 PEER_FLAG_FORCE_NEXTHOP_SELF);
5773 }
5774
5775 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5776 no_neighbor_nexthop_self_force_hidden_cmd,
5777 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5778 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Disable the next hop calculation for this neighbor\n"
5780 "Set the next hop to self for reflected routes\n")
5781
5782 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5783 no_neighbor_nexthop_self_all_hidden_cmd,
5784 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5785 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5786 "Disable the next hop calculation for this neighbor\n"
5787 "Set the next hop to self for reflected routes\n")
5788
5789 /* neighbor as-override */
5790 DEFUN (neighbor_as_override,
5791 neighbor_as_override_cmd,
5792 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5793 NEIGHBOR_STR
5794 NEIGHBOR_ADDR_STR2
5795 "Override ASNs in outbound updates if aspath equals remote-as\n")
5796 {
5797 int idx_peer = 1;
5798 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5799 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5800 }
5801
5802 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5803 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5805 "Override ASNs in outbound updates if aspath equals remote-as\n")
5806
5807 DEFUN (no_neighbor_as_override,
5808 no_neighbor_as_override_cmd,
5809 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5810 NO_STR
5811 NEIGHBOR_STR
5812 NEIGHBOR_ADDR_STR2
5813 "Override ASNs in outbound updates if aspath equals remote-as\n")
5814 {
5815 int idx_peer = 2;
5816 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5817 bgp_node_afi(vty), bgp_node_safi(vty),
5818 PEER_FLAG_AS_OVERRIDE);
5819 }
5820
5821 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5822 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5823 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 "Override ASNs in outbound updates if aspath equals remote-as\n")
5825
5826 /* neighbor remove-private-AS. */
5827 DEFUN (neighbor_remove_private_as,
5828 neighbor_remove_private_as_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Remove private ASNs in outbound updates\n")
5833 {
5834 int idx_peer = 1;
5835 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5836 bgp_node_safi(vty),
5837 PEER_FLAG_REMOVE_PRIVATE_AS);
5838 }
5839
5840 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Remove private ASNs in outbound updates\n")
5844
5845 DEFUN (neighbor_remove_private_as_all,
5846 neighbor_remove_private_as_all_cmd,
5847 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5848 NEIGHBOR_STR
5849 NEIGHBOR_ADDR_STR2
5850 "Remove private ASNs in outbound updates\n"
5851 "Apply to all AS numbers\n")
5852 {
5853 int idx_peer = 1;
5854 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5855 bgp_node_safi(vty),
5856 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5857 }
5858
5859 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5860 neighbor_remove_private_as_all_hidden_cmd,
5861 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5863 "Remove private ASNs in outbound updates\n"
5864 "Apply to all AS numbers\n")
5865
5866 DEFUN (neighbor_remove_private_as_replace_as,
5867 neighbor_remove_private_as_replace_as_cmd,
5868 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5869 NEIGHBOR_STR
5870 NEIGHBOR_ADDR_STR2
5871 "Remove private ASNs in outbound updates\n"
5872 "Replace private ASNs with our ASN in outbound updates\n")
5873 {
5874 int idx_peer = 1;
5875 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5876 bgp_node_safi(vty),
5877 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5878 }
5879
5880 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5881 neighbor_remove_private_as_replace_as_hidden_cmd,
5882 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5883 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5884 "Remove private ASNs in outbound updates\n"
5885 "Replace private ASNs with our ASN in outbound updates\n")
5886
5887 DEFUN (neighbor_remove_private_as_all_replace_as,
5888 neighbor_remove_private_as_all_replace_as_cmd,
5889 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5890 NEIGHBOR_STR
5891 NEIGHBOR_ADDR_STR2
5892 "Remove private ASNs in outbound updates\n"
5893 "Apply to all AS numbers\n"
5894 "Replace private ASNs with our ASN in outbound updates\n")
5895 {
5896 int idx_peer = 1;
5897 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5898 bgp_node_safi(vty),
5899 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5900 }
5901
5902 ALIAS_HIDDEN(
5903 neighbor_remove_private_as_all_replace_as,
5904 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5905 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5907 "Remove private ASNs in outbound updates\n"
5908 "Apply to all AS numbers\n"
5909 "Replace private ASNs with our ASN in outbound updates\n")
5910
5911 DEFUN (no_neighbor_remove_private_as,
5912 no_neighbor_remove_private_as_cmd,
5913 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5914 NO_STR
5915 NEIGHBOR_STR
5916 NEIGHBOR_ADDR_STR2
5917 "Remove private ASNs in outbound updates\n")
5918 {
5919 int idx_peer = 2;
5920 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5921 bgp_node_afi(vty), bgp_node_safi(vty),
5922 PEER_FLAG_REMOVE_PRIVATE_AS);
5923 }
5924
5925 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5926 no_neighbor_remove_private_as_hidden_cmd,
5927 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5928 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5929 "Remove private ASNs in outbound updates\n")
5930
5931 DEFUN (no_neighbor_remove_private_as_all,
5932 no_neighbor_remove_private_as_all_cmd,
5933 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5934 NO_STR
5935 NEIGHBOR_STR
5936 NEIGHBOR_ADDR_STR2
5937 "Remove private ASNs in outbound updates\n"
5938 "Apply to all AS numbers\n")
5939 {
5940 int idx_peer = 2;
5941 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5942 bgp_node_afi(vty), bgp_node_safi(vty),
5943 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5944 }
5945
5946 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5947 no_neighbor_remove_private_as_all_hidden_cmd,
5948 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5949 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5950 "Remove private ASNs in outbound updates\n"
5951 "Apply to all AS numbers\n")
5952
5953 DEFUN (no_neighbor_remove_private_as_replace_as,
5954 no_neighbor_remove_private_as_replace_as_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5956 NO_STR
5957 NEIGHBOR_STR
5958 NEIGHBOR_ADDR_STR2
5959 "Remove private ASNs in outbound updates\n"
5960 "Replace private ASNs with our ASN in outbound updates\n")
5961 {
5962 int idx_peer = 2;
5963 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5964 bgp_node_afi(vty), bgp_node_safi(vty),
5965 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5966 }
5967
5968 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5969 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5970 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5971 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5972 "Remove private ASNs in outbound updates\n"
5973 "Replace private ASNs with our ASN in outbound updates\n")
5974
5975 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5976 no_neighbor_remove_private_as_all_replace_as_cmd,
5977 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5978 NO_STR
5979 NEIGHBOR_STR
5980 NEIGHBOR_ADDR_STR2
5981 "Remove private ASNs in outbound updates\n"
5982 "Apply to all AS numbers\n"
5983 "Replace private ASNs with our ASN in outbound updates\n")
5984 {
5985 int idx_peer = 2;
5986 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5987 bgp_node_afi(vty), bgp_node_safi(vty),
5988 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5989 }
5990
5991 ALIAS_HIDDEN(
5992 no_neighbor_remove_private_as_all_replace_as,
5993 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5994 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5995 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5996 "Remove private ASNs in outbound updates\n"
5997 "Apply to all AS numbers\n"
5998 "Replace private ASNs with our ASN in outbound updates\n")
5999
6000
6001 /* neighbor send-community. */
6002 DEFUN (neighbor_send_community,
6003 neighbor_send_community_cmd,
6004 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Send Community attribute to this neighbor\n")
6008 {
6009 int idx_peer = 1;
6010
6011 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6012 bgp_node_safi(vty),
6013 PEER_FLAG_SEND_COMMUNITY);
6014 }
6015
6016 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6018 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6019 "Send Community attribute to this neighbor\n")
6020
6021 DEFUN (no_neighbor_send_community,
6022 no_neighbor_send_community_cmd,
6023 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6024 NO_STR
6025 NEIGHBOR_STR
6026 NEIGHBOR_ADDR_STR2
6027 "Send Community attribute to this neighbor\n")
6028 {
6029 int idx_peer = 2;
6030
6031 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6032 bgp_node_afi(vty), bgp_node_safi(vty),
6033 PEER_FLAG_SEND_COMMUNITY);
6034 }
6035
6036 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6037 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6038 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6039 "Send Community attribute to this neighbor\n")
6040
6041 /* neighbor send-community extended. */
6042 DEFUN (neighbor_send_community_type,
6043 neighbor_send_community_type_cmd,
6044 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6045 NEIGHBOR_STR
6046 NEIGHBOR_ADDR_STR2
6047 "Send Community attribute to this neighbor\n"
6048 "Send Standard and Extended Community attributes\n"
6049 "Send Standard, Large and Extended Community attributes\n"
6050 "Send Extended Community attributes\n"
6051 "Send Standard Community attributes\n"
6052 "Send Large Community attributes\n")
6053 {
6054 const char *type = argv[argc - 1]->text;
6055 char *peer_str = argv[1]->arg;
6056 struct peer *peer;
6057 afi_t afi = bgp_node_afi(vty);
6058 safi_t safi = bgp_node_safi(vty);
6059
6060 peer = peer_and_group_lookup_vty(vty, peer_str);
6061 if (!peer)
6062 return CMD_WARNING_CONFIG_FAILED;
6063
6064 if (strmatch(type, "standard"))
6065 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6066 PEER_FLAG_SEND_COMMUNITY);
6067
6068 if (strmatch(type, "extended"))
6069 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6070 PEER_FLAG_SEND_EXT_COMMUNITY);
6071
6072 if (strmatch(type, "large"))
6073 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6074 PEER_FLAG_SEND_LARGE_COMMUNITY);
6075
6076 if (strmatch(type, "both")) {
6077 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6078 PEER_FLAG_SEND_COMMUNITY)
6079 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6080 PEER_FLAG_SEND_EXT_COMMUNITY);
6081 }
6082 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6083 PEER_FLAG_SEND_COMMUNITY)
6084 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6085 PEER_FLAG_SEND_EXT_COMMUNITY)
6086 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6087 PEER_FLAG_SEND_LARGE_COMMUNITY);
6088 }
6089
6090 ALIAS_HIDDEN(
6091 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6092 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6094 "Send Community attribute to this neighbor\n"
6095 "Send Standard and Extended Community attributes\n"
6096 "Send Standard, Large and Extended Community attributes\n"
6097 "Send Extended Community attributes\n"
6098 "Send Standard Community attributes\n"
6099 "Send Large Community attributes\n")
6100
6101 DEFUN (no_neighbor_send_community_type,
6102 no_neighbor_send_community_type_cmd,
6103 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6104 NO_STR
6105 NEIGHBOR_STR
6106 NEIGHBOR_ADDR_STR2
6107 "Send Community attribute to this neighbor\n"
6108 "Send Standard and Extended Community attributes\n"
6109 "Send Standard, Large and Extended Community attributes\n"
6110 "Send Extended Community attributes\n"
6111 "Send Standard Community attributes\n"
6112 "Send Large Community attributes\n")
6113 {
6114 const char *type = argv[argc - 1]->text;
6115 char *peer_str = argv[2]->arg;
6116 struct peer *peer;
6117 afi_t afi = bgp_node_afi(vty);
6118 safi_t safi = bgp_node_safi(vty);
6119
6120 peer = peer_and_group_lookup_vty(vty, peer_str);
6121 if (!peer)
6122 return CMD_WARNING_CONFIG_FAILED;
6123
6124 if (strmatch(type, "standard"))
6125 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6126 PEER_FLAG_SEND_COMMUNITY);
6127
6128 if (strmatch(type, "extended"))
6129 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6130 PEER_FLAG_SEND_EXT_COMMUNITY);
6131
6132 if (strmatch(type, "large"))
6133 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6134 PEER_FLAG_SEND_LARGE_COMMUNITY);
6135
6136 if (strmatch(type, "both")) {
6137
6138 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6139 PEER_FLAG_SEND_COMMUNITY)
6140 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6141 PEER_FLAG_SEND_EXT_COMMUNITY);
6142 }
6143
6144 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6145 PEER_FLAG_SEND_COMMUNITY)
6146 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6147 PEER_FLAG_SEND_EXT_COMMUNITY)
6148 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6149 PEER_FLAG_SEND_LARGE_COMMUNITY);
6150 }
6151
6152 ALIAS_HIDDEN(
6153 no_neighbor_send_community_type,
6154 no_neighbor_send_community_type_hidden_cmd,
6155 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6157 "Send Community attribute to this neighbor\n"
6158 "Send Standard and Extended Community attributes\n"
6159 "Send Standard, Large and Extended Community attributes\n"
6160 "Send Extended Community attributes\n"
6161 "Send Standard Community attributes\n"
6162 "Send Large Community attributes\n")
6163
6164 /* neighbor soft-reconfig. */
6165 DEFUN (neighbor_soft_reconfiguration,
6166 neighbor_soft_reconfiguration_cmd,
6167 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6168 NEIGHBOR_STR
6169 NEIGHBOR_ADDR_STR2
6170 "Per neighbor soft reconfiguration\n"
6171 "Allow inbound soft reconfiguration for this neighbor\n")
6172 {
6173 int idx_peer = 1;
6174 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6175 bgp_node_safi(vty),
6176 PEER_FLAG_SOFT_RECONFIG);
6177 }
6178
6179 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6180 neighbor_soft_reconfiguration_hidden_cmd,
6181 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6183 "Per neighbor soft reconfiguration\n"
6184 "Allow inbound soft reconfiguration for this neighbor\n")
6185
6186 DEFUN (no_neighbor_soft_reconfiguration,
6187 no_neighbor_soft_reconfiguration_cmd,
6188 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6189 NO_STR
6190 NEIGHBOR_STR
6191 NEIGHBOR_ADDR_STR2
6192 "Per neighbor soft reconfiguration\n"
6193 "Allow inbound soft reconfiguration for this neighbor\n")
6194 {
6195 int idx_peer = 2;
6196 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6197 bgp_node_afi(vty), bgp_node_safi(vty),
6198 PEER_FLAG_SOFT_RECONFIG);
6199 }
6200
6201 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6202 no_neighbor_soft_reconfiguration_hidden_cmd,
6203 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6204 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6205 "Per neighbor soft reconfiguration\n"
6206 "Allow inbound soft reconfiguration for this neighbor\n")
6207
6208 DEFUN (neighbor_route_reflector_client,
6209 neighbor_route_reflector_client_cmd,
6210 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6211 NEIGHBOR_STR
6212 NEIGHBOR_ADDR_STR2
6213 "Configure a neighbor as Route Reflector client\n")
6214 {
6215 int idx_peer = 1;
6216 struct peer *peer;
6217
6218
6219 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6220 if (!peer)
6221 return CMD_WARNING_CONFIG_FAILED;
6222
6223 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6224 bgp_node_safi(vty),
6225 PEER_FLAG_REFLECTOR_CLIENT);
6226 }
6227
6228 ALIAS_HIDDEN(neighbor_route_reflector_client,
6229 neighbor_route_reflector_client_hidden_cmd,
6230 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6231 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6232 "Configure a neighbor as Route Reflector client\n")
6233
6234 DEFUN (no_neighbor_route_reflector_client,
6235 no_neighbor_route_reflector_client_cmd,
6236 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6237 NO_STR
6238 NEIGHBOR_STR
6239 NEIGHBOR_ADDR_STR2
6240 "Configure a neighbor as Route Reflector client\n")
6241 {
6242 int idx_peer = 2;
6243 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6244 bgp_node_afi(vty), bgp_node_safi(vty),
6245 PEER_FLAG_REFLECTOR_CLIENT);
6246 }
6247
6248 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6249 no_neighbor_route_reflector_client_hidden_cmd,
6250 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6252 "Configure a neighbor as Route Reflector client\n")
6253
6254 /* optimal-route-reflection Root Routers configuration */
6255 DEFPY (optimal_route_reflection,
6256 optimal_route_reflection_cmd,
6257 "[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]]]",
6258 NO_STR
6259 "Create ORR group and assign root router(s)\n"
6260 "ORR Group name\n"
6261 "Primary Root address\n"
6262 "Primary Root IPv6 address\n"
6263 "Secondary Root address\n"
6264 "Secondary Root IPv6 address\n"
6265 "Tertiary Root address\n"
6266 "Tertiary Root IPv6 address\n")
6267 {
6268 if (!no && !primary) {
6269 vty_out(vty, "%% Specify Primary Root address\n");
6270 return CMD_WARNING_CONFIG_FAILED;
6271 }
6272 return bgp_afi_safi_orr_group_set_vty(
6273 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
6274 primary_str, secondary_str, tertiary_str, !!no);
6275 }
6276
6277 /* neighbor optimal-route-reflection group*/
6278 DEFPY (neighbor_optimal_route_reflection,
6279 neighbor_optimal_route_reflection_cmd,
6280 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6281 NO_STR
6282 NEIGHBOR_STR
6283 NEIGHBOR_ADDR_STR2
6284 "Apply ORR group configuration to the neighbor\n"
6285 "ORR group name\n")
6286 {
6287 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
6288 bgp_node_safi(vty), orr_group, !!no);
6289 }
6290
6291 /* neighbor route-server-client. */
6292 DEFUN (neighbor_route_server_client,
6293 neighbor_route_server_client_cmd,
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6295 NEIGHBOR_STR
6296 NEIGHBOR_ADDR_STR2
6297 "Configure a neighbor as Route Server client\n")
6298 {
6299 int idx_peer = 1;
6300 struct peer *peer;
6301
6302 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6303 if (!peer)
6304 return CMD_WARNING_CONFIG_FAILED;
6305 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6306 bgp_node_safi(vty),
6307 PEER_FLAG_RSERVER_CLIENT);
6308 }
6309
6310 ALIAS_HIDDEN(neighbor_route_server_client,
6311 neighbor_route_server_client_hidden_cmd,
6312 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6313 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6314 "Configure a neighbor as Route Server client\n")
6315
6316 DEFUN (no_neighbor_route_server_client,
6317 no_neighbor_route_server_client_cmd,
6318 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6319 NO_STR
6320 NEIGHBOR_STR
6321 NEIGHBOR_ADDR_STR2
6322 "Configure a neighbor as Route Server client\n")
6323 {
6324 int idx_peer = 2;
6325 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6326 bgp_node_afi(vty), bgp_node_safi(vty),
6327 PEER_FLAG_RSERVER_CLIENT);
6328 }
6329
6330 ALIAS_HIDDEN(no_neighbor_route_server_client,
6331 no_neighbor_route_server_client_hidden_cmd,
6332 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6333 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6334 "Configure a neighbor as Route Server client\n")
6335
6336 DEFUN (neighbor_nexthop_local_unchanged,
6337 neighbor_nexthop_local_unchanged_cmd,
6338 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6339 NEIGHBOR_STR
6340 NEIGHBOR_ADDR_STR2
6341 "Configure treatment of outgoing link-local nexthop attribute\n"
6342 "Leave link-local nexthop unchanged for this peer\n")
6343 {
6344 int idx_peer = 1;
6345 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6346 bgp_node_safi(vty),
6347 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6348 }
6349
6350 DEFUN (no_neighbor_nexthop_local_unchanged,
6351 no_neighbor_nexthop_local_unchanged_cmd,
6352 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6353 NO_STR
6354 NEIGHBOR_STR
6355 NEIGHBOR_ADDR_STR2
6356 "Configure treatment of outgoing link-local-nexthop attribute\n"
6357 "Leave link-local nexthop unchanged for this peer\n")
6358 {
6359 int idx_peer = 2;
6360 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6361 bgp_node_afi(vty), bgp_node_safi(vty),
6362 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6363 }
6364
6365 DEFUN (neighbor_attr_unchanged,
6366 neighbor_attr_unchanged_cmd,
6367 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6368 NEIGHBOR_STR
6369 NEIGHBOR_ADDR_STR2
6370 "BGP attribute is propagated unchanged to this neighbor\n"
6371 "As-path attribute\n"
6372 "Nexthop attribute\n"
6373 "Med attribute\n")
6374 {
6375 int idx = 0;
6376 char *peer_str = argv[1]->arg;
6377 struct peer *peer;
6378 bool aspath = false;
6379 bool nexthop = false;
6380 bool med = false;
6381 afi_t afi = bgp_node_afi(vty);
6382 safi_t safi = bgp_node_safi(vty);
6383 int ret = 0;
6384
6385 peer = peer_and_group_lookup_vty(vty, peer_str);
6386 if (!peer)
6387 return CMD_WARNING_CONFIG_FAILED;
6388
6389 if (argv_find(argv, argc, "as-path", &idx))
6390 aspath = true;
6391
6392 idx = 0;
6393 if (argv_find(argv, argc, "next-hop", &idx))
6394 nexthop = true;
6395
6396 idx = 0;
6397 if (argv_find(argv, argc, "med", &idx))
6398 med = true;
6399
6400 /* no flags means all of them! */
6401 if (!aspath && !nexthop && !med) {
6402 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6403 PEER_FLAG_AS_PATH_UNCHANGED);
6404 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6405 PEER_FLAG_NEXTHOP_UNCHANGED);
6406 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6407 PEER_FLAG_MED_UNCHANGED);
6408 } else {
6409 if (!aspath) {
6410 if (peer_af_flag_check(peer, afi, safi,
6411 PEER_FLAG_AS_PATH_UNCHANGED)) {
6412 ret |= peer_af_flag_unset_vty(
6413 vty, peer_str, afi, safi,
6414 PEER_FLAG_AS_PATH_UNCHANGED);
6415 }
6416 } else
6417 ret |= peer_af_flag_set_vty(
6418 vty, peer_str, afi, safi,
6419 PEER_FLAG_AS_PATH_UNCHANGED);
6420
6421 if (!nexthop) {
6422 if (peer_af_flag_check(peer, afi, safi,
6423 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6424 ret |= peer_af_flag_unset_vty(
6425 vty, peer_str, afi, safi,
6426 PEER_FLAG_NEXTHOP_UNCHANGED);
6427 }
6428 } else
6429 ret |= peer_af_flag_set_vty(
6430 vty, peer_str, afi, safi,
6431 PEER_FLAG_NEXTHOP_UNCHANGED);
6432
6433 if (!med) {
6434 if (peer_af_flag_check(peer, afi, safi,
6435 PEER_FLAG_MED_UNCHANGED)) {
6436 ret |= peer_af_flag_unset_vty(
6437 vty, peer_str, afi, safi,
6438 PEER_FLAG_MED_UNCHANGED);
6439 }
6440 } else
6441 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6442 PEER_FLAG_MED_UNCHANGED);
6443 }
6444
6445 return ret;
6446 }
6447
6448 ALIAS_HIDDEN(
6449 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6450 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6452 "BGP attribute is propagated unchanged to this neighbor\n"
6453 "As-path attribute\n"
6454 "Nexthop attribute\n"
6455 "Med attribute\n")
6456
6457 DEFUN (no_neighbor_attr_unchanged,
6458 no_neighbor_attr_unchanged_cmd,
6459 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6460 NO_STR
6461 NEIGHBOR_STR
6462 NEIGHBOR_ADDR_STR2
6463 "BGP attribute is propagated unchanged to this neighbor\n"
6464 "As-path attribute\n"
6465 "Nexthop attribute\n"
6466 "Med attribute\n")
6467 {
6468 int idx = 0;
6469 char *peer_str = argv[2]->arg;
6470 struct peer *peer;
6471 bool aspath = false;
6472 bool nexthop = false;
6473 bool med = false;
6474 afi_t afi = bgp_node_afi(vty);
6475 safi_t safi = bgp_node_safi(vty);
6476 int ret = 0;
6477
6478 peer = peer_and_group_lookup_vty(vty, peer_str);
6479 if (!peer)
6480 return CMD_WARNING_CONFIG_FAILED;
6481
6482 if (argv_find(argv, argc, "as-path", &idx))
6483 aspath = true;
6484
6485 idx = 0;
6486 if (argv_find(argv, argc, "next-hop", &idx))
6487 nexthop = true;
6488
6489 idx = 0;
6490 if (argv_find(argv, argc, "med", &idx))
6491 med = true;
6492
6493 if (!aspath && !nexthop && !med) // no flags means all of them!
6494 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6495 PEER_FLAG_AS_PATH_UNCHANGED)
6496 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6497 PEER_FLAG_NEXTHOP_UNCHANGED)
6498 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6499 PEER_FLAG_MED_UNCHANGED);
6500
6501 if (aspath)
6502 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6503 PEER_FLAG_AS_PATH_UNCHANGED);
6504
6505 if (nexthop)
6506 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6507 PEER_FLAG_NEXTHOP_UNCHANGED);
6508
6509 if (med)
6510 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6511 PEER_FLAG_MED_UNCHANGED);
6512
6513 return ret;
6514 }
6515
6516 ALIAS_HIDDEN(
6517 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6518 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6519 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6520 "BGP attribute is propagated unchanged to this neighbor\n"
6521 "As-path attribute\n"
6522 "Nexthop attribute\n"
6523 "Med attribute\n")
6524
6525 /* EBGP multihop configuration. */
6526 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6527 const char *ttl_str)
6528 {
6529 struct peer *peer;
6530 unsigned int ttl;
6531
6532 peer = peer_and_group_lookup_vty(vty, ip_str);
6533 if (!peer)
6534 return CMD_WARNING_CONFIG_FAILED;
6535
6536 if (peer->conf_if)
6537 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6538
6539 if (!ttl_str)
6540 ttl = MAXTTL;
6541 else
6542 ttl = strtoul(ttl_str, NULL, 10);
6543
6544 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6545 }
6546
6547 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6548 {
6549 struct peer *peer;
6550
6551 peer = peer_and_group_lookup_vty(vty, ip_str);
6552 if (!peer)
6553 return CMD_WARNING_CONFIG_FAILED;
6554
6555 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6556 }
6557
6558 /* neighbor ebgp-multihop. */
6559 DEFUN (neighbor_ebgp_multihop,
6560 neighbor_ebgp_multihop_cmd,
6561 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6562 NEIGHBOR_STR
6563 NEIGHBOR_ADDR_STR2
6564 "Allow EBGP neighbors not on directly connected networks\n")
6565 {
6566 int idx_peer = 1;
6567 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6568 }
6569
6570 DEFUN (neighbor_ebgp_multihop_ttl,
6571 neighbor_ebgp_multihop_ttl_cmd,
6572 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6573 NEIGHBOR_STR
6574 NEIGHBOR_ADDR_STR2
6575 "Allow EBGP neighbors not on directly connected networks\n"
6576 "maximum hop count\n")
6577 {
6578 int idx_peer = 1;
6579 int idx_number = 3;
6580 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6581 argv[idx_number]->arg);
6582 }
6583
6584 DEFUN (no_neighbor_ebgp_multihop,
6585 no_neighbor_ebgp_multihop_cmd,
6586 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6587 NO_STR
6588 NEIGHBOR_STR
6589 NEIGHBOR_ADDR_STR2
6590 "Allow EBGP neighbors not on directly connected networks\n"
6591 "maximum hop count\n")
6592 {
6593 int idx_peer = 2;
6594 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6595 }
6596
6597 DEFPY (neighbor_aigp,
6598 neighbor_aigp_cmd,
6599 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6600 NO_STR
6601 NEIGHBOR_STR
6602 NEIGHBOR_ADDR_STR2
6603 "Enable send and receive of the AIGP attribute per neighbor\n")
6604 {
6605 struct peer *peer;
6606
6607 peer = peer_and_group_lookup_vty(vty, neighbor);
6608 if (!peer)
6609 return CMD_WARNING_CONFIG_FAILED;
6610
6611 if (no)
6612 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6613 else
6614 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6615 }
6616
6617 static uint8_t get_role_by_name(const char *role_str)
6618 {
6619 if (strncmp(role_str, "peer", 2) == 0)
6620 return ROLE_PEER;
6621 if (strncmp(role_str, "provider", 2) == 0)
6622 return ROLE_PROVIDER;
6623 if (strncmp(role_str, "customer", 2) == 0)
6624 return ROLE_CUSTOMER;
6625 if (strncmp(role_str, "rs-server", 4) == 0)
6626 return ROLE_RS_SERVER;
6627 if (strncmp(role_str, "rs-client", 4) == 0)
6628 return ROLE_RS_CLIENT;
6629 return ROLE_UNDEFINED;
6630 }
6631
6632 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6633 const char *role_str, bool strict_mode)
6634 {
6635 struct peer *peer;
6636
6637 peer = peer_and_group_lookup_vty(vty, ip_str);
6638 if (!peer)
6639 return CMD_WARNING_CONFIG_FAILED;
6640 uint8_t role = get_role_by_name(role_str);
6641
6642 if (role == ROLE_UNDEFINED)
6643 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6644 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6645 }
6646
6647 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6648 {
6649 struct peer *peer;
6650
6651 peer = peer_and_group_lookup_vty(vty, ip_str);
6652 if (!peer)
6653 return CMD_WARNING_CONFIG_FAILED;
6654 return bgp_vty_return(vty, peer_role_unset(peer));
6655 }
6656
6657 DEFPY(neighbor_role,
6658 neighbor_role_cmd,
6659 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6660 NEIGHBOR_STR
6661 NEIGHBOR_ADDR_STR2
6662 "Set session role\n"
6663 ROLE_STR)
6664 {
6665 int idx_peer = 1;
6666 int idx_role = 3;
6667
6668 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6669 false);
6670 }
6671
6672 DEFPY(neighbor_role_strict,
6673 neighbor_role_strict_cmd,
6674 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6675 NEIGHBOR_STR
6676 NEIGHBOR_ADDR_STR2
6677 "Set session role\n"
6678 ROLE_STR
6679 "Use additional restriction on peer\n")
6680 {
6681 int idx_peer = 1;
6682 int idx_role = 3;
6683
6684 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6685 true);
6686 }
6687
6688 DEFPY(no_neighbor_role,
6689 no_neighbor_role_cmd,
6690 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6691 NO_STR
6692 NEIGHBOR_STR
6693 NEIGHBOR_ADDR_STR2
6694 "Set session role\n"
6695 ROLE_STR
6696 "Use additional restriction on peer\n")
6697 {
6698 int idx_peer = 2;
6699
6700 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6701 }
6702
6703 /* disable-connected-check */
6704 DEFUN (neighbor_disable_connected_check,
6705 neighbor_disable_connected_check_cmd,
6706 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6707 NEIGHBOR_STR
6708 NEIGHBOR_ADDR_STR2
6709 "one-hop away EBGP peer using loopback address\n"
6710 "Enforce EBGP neighbors perform multihop\n")
6711 {
6712 int idx_peer = 1;
6713 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6714 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6715 }
6716
6717 DEFUN (no_neighbor_disable_connected_check,
6718 no_neighbor_disable_connected_check_cmd,
6719 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6720 NO_STR
6721 NEIGHBOR_STR
6722 NEIGHBOR_ADDR_STR2
6723 "one-hop away EBGP peer using loopback address\n"
6724 "Enforce EBGP neighbors perform multihop\n")
6725 {
6726 int idx_peer = 2;
6727 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6728 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6729 }
6730
6731 /* disable-link-bw-encoding-ieee */
6732 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6733 neighbor_disable_link_bw_encoding_ieee_cmd,
6734 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6736 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6737 {
6738 int idx_peer = 1;
6739
6740 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6741 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6742 }
6743
6744 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6745 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6746 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6747 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6748 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6749 {
6750 int idx_peer = 2;
6751
6752 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6753 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6754 }
6755
6756 /* extended-optional-parameters */
6757 DEFUN(neighbor_extended_optional_parameters,
6758 neighbor_extended_optional_parameters_cmd,
6759 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6761 "Force the extended optional parameters format for OPEN messages\n")
6762 {
6763 int idx_peer = 1;
6764
6765 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6766 PEER_FLAG_EXTENDED_OPT_PARAMS);
6767 }
6768
6769 DEFUN(no_neighbor_extended_optional_parameters,
6770 no_neighbor_extended_optional_parameters_cmd,
6771 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6773 "Force the extended optional parameters format for OPEN messages\n")
6774 {
6775 int idx_peer = 2;
6776
6777 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6778 PEER_FLAG_EXTENDED_OPT_PARAMS);
6779 }
6780
6781 /* enforce-first-as */
6782 DEFUN (neighbor_enforce_first_as,
6783 neighbor_enforce_first_as_cmd,
6784 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6785 NEIGHBOR_STR
6786 NEIGHBOR_ADDR_STR2
6787 "Enforce the first AS for EBGP routes\n")
6788 {
6789 int idx_peer = 1;
6790
6791 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6792 PEER_FLAG_ENFORCE_FIRST_AS);
6793 }
6794
6795 DEFUN (no_neighbor_enforce_first_as,
6796 no_neighbor_enforce_first_as_cmd,
6797 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6798 NO_STR
6799 NEIGHBOR_STR
6800 NEIGHBOR_ADDR_STR2
6801 "Enforce the first AS for EBGP routes\n")
6802 {
6803 int idx_peer = 2;
6804
6805 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6806 PEER_FLAG_ENFORCE_FIRST_AS);
6807 }
6808
6809
6810 DEFUN (neighbor_description,
6811 neighbor_description_cmd,
6812 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6813 NEIGHBOR_STR
6814 NEIGHBOR_ADDR_STR2
6815 "Neighbor specific description\n"
6816 "Up to 80 characters describing this neighbor\n")
6817 {
6818 int idx_peer = 1;
6819 int idx_line = 3;
6820 struct peer *peer;
6821 char *str;
6822
6823 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6824 if (!peer)
6825 return CMD_WARNING_CONFIG_FAILED;
6826
6827 str = argv_concat(argv, argc, idx_line);
6828
6829 peer_description_set(peer, str);
6830
6831 XFREE(MTYPE_TMP, str);
6832
6833 return CMD_SUCCESS;
6834 }
6835
6836 DEFUN (no_neighbor_description,
6837 no_neighbor_description_cmd,
6838 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6839 NO_STR
6840 NEIGHBOR_STR
6841 NEIGHBOR_ADDR_STR2
6842 "Neighbor specific description\n")
6843 {
6844 int idx_peer = 2;
6845 struct peer *peer;
6846
6847 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6848 if (!peer)
6849 return CMD_WARNING_CONFIG_FAILED;
6850
6851 peer_description_unset(peer);
6852
6853 return CMD_SUCCESS;
6854 }
6855
6856 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6857 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6858 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6859 "Neighbor specific description\n"
6860 "Up to 80 characters describing this neighbor\n")
6861
6862 /* Neighbor update-source. */
6863 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6864 const char *source_str)
6865 {
6866 struct peer *peer;
6867 struct prefix p;
6868 union sockunion su;
6869
6870 peer = peer_and_group_lookup_vty(vty, peer_str);
6871 if (!peer)
6872 return CMD_WARNING_CONFIG_FAILED;
6873
6874 if (peer->conf_if)
6875 return CMD_WARNING;
6876
6877 if (source_str) {
6878 if (str2sockunion(source_str, &su) == 0)
6879 peer_update_source_addr_set(peer, &su);
6880 else {
6881 if (str2prefix(source_str, &p)) {
6882 vty_out(vty,
6883 "%% Invalid update-source, remove prefix length \n");
6884 return CMD_WARNING_CONFIG_FAILED;
6885 } else
6886 peer_update_source_if_set(peer, source_str);
6887 }
6888 } else
6889 peer_update_source_unset(peer);
6890
6891 return CMD_SUCCESS;
6892 }
6893
6894 #define BGP_UPDATE_SOURCE_HELP_STR \
6895 "IPv4 address\n" \
6896 "IPv6 address\n" \
6897 "Interface name (requires zebra to be running)\n"
6898
6899 DEFUN (neighbor_update_source,
6900 neighbor_update_source_cmd,
6901 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6902 NEIGHBOR_STR
6903 NEIGHBOR_ADDR_STR2
6904 "Source of routing updates\n"
6905 BGP_UPDATE_SOURCE_HELP_STR)
6906 {
6907 int idx_peer = 1;
6908 int idx_peer_2 = 3;
6909 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6910 argv[idx_peer_2]->arg);
6911 }
6912
6913 DEFUN (no_neighbor_update_source,
6914 no_neighbor_update_source_cmd,
6915 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6916 NO_STR
6917 NEIGHBOR_STR
6918 NEIGHBOR_ADDR_STR2
6919 "Source of routing updates\n"
6920 BGP_UPDATE_SOURCE_HELP_STR)
6921 {
6922 int idx_peer = 2;
6923 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6924 }
6925
6926 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6927 afi_t afi, safi_t safi,
6928 const char *rmap, int set)
6929 {
6930 int ret;
6931 struct peer *peer;
6932 struct route_map *route_map = NULL;
6933
6934 peer = peer_and_group_lookup_vty(vty, peer_str);
6935 if (!peer)
6936 return CMD_WARNING_CONFIG_FAILED;
6937
6938 if (set) {
6939 if (rmap)
6940 route_map = route_map_lookup_warn_noexist(vty, rmap);
6941 ret = peer_default_originate_set(peer, afi, safi,
6942 rmap, route_map);
6943 } else
6944 ret = peer_default_originate_unset(peer, afi, safi);
6945
6946 return bgp_vty_return(vty, ret);
6947 }
6948
6949 /* neighbor default-originate. */
6950 DEFUN (neighbor_default_originate,
6951 neighbor_default_originate_cmd,
6952 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6953 NEIGHBOR_STR
6954 NEIGHBOR_ADDR_STR2
6955 "Originate default route to this neighbor\n")
6956 {
6957 int idx_peer = 1;
6958 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6959 bgp_node_afi(vty),
6960 bgp_node_safi(vty), NULL, 1);
6961 }
6962
6963 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6964 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6966 "Originate default route to this neighbor\n")
6967
6968 DEFUN (neighbor_default_originate_rmap,
6969 neighbor_default_originate_rmap_cmd,
6970 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6971 NEIGHBOR_STR
6972 NEIGHBOR_ADDR_STR2
6973 "Originate default route to this neighbor\n"
6974 "Route-map to specify criteria to originate default\n"
6975 "route-map name\n")
6976 {
6977 int idx_peer = 1;
6978 int idx_word = 4;
6979 return peer_default_originate_set_vty(
6980 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6981 argv[idx_word]->arg, 1);
6982 }
6983
6984 ALIAS_HIDDEN(
6985 neighbor_default_originate_rmap,
6986 neighbor_default_originate_rmap_hidden_cmd,
6987 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6988 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6989 "Originate default route to this neighbor\n"
6990 "Route-map to specify criteria to originate default\n"
6991 "route-map name\n")
6992
6993 DEFUN (no_neighbor_default_originate,
6994 no_neighbor_default_originate_cmd,
6995 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6996 NO_STR
6997 NEIGHBOR_STR
6998 NEIGHBOR_ADDR_STR2
6999 "Originate default route to this neighbor\n"
7000 "Route-map to specify criteria to originate default\n"
7001 "route-map name\n")
7002 {
7003 int idx_peer = 2;
7004 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7005 bgp_node_afi(vty),
7006 bgp_node_safi(vty), NULL, 0);
7007 }
7008
7009 ALIAS_HIDDEN(
7010 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7011 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
7012 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7013 "Originate default route to this neighbor\n"
7014 "Route-map to specify criteria to originate default\n"
7015 "route-map name\n")
7016
7017
7018 /* Set neighbor's BGP port. */
7019 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7020 const char *port_str)
7021 {
7022 struct peer *peer;
7023 uint16_t port;
7024 struct servent *sp;
7025
7026 peer = peer_and_group_lookup_vty(vty, ip_str);
7027 if (!peer)
7028 return CMD_WARNING_CONFIG_FAILED;
7029
7030 if (!port_str) {
7031 sp = getservbyname("bgp", "tcp");
7032 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7033 } else {
7034 port = strtoul(port_str, NULL, 10);
7035 }
7036
7037 peer_port_set(peer, port);
7038
7039 return CMD_SUCCESS;
7040 }
7041
7042 /* Set specified peer's BGP port. */
7043 DEFUN (neighbor_port,
7044 neighbor_port_cmd,
7045 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7046 NEIGHBOR_STR
7047 NEIGHBOR_ADDR_STR2
7048 "Neighbor's BGP port\n"
7049 "TCP port number\n")
7050 {
7051 int idx_ip = 1;
7052 int idx_number = 3;
7053 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7054 argv[idx_number]->arg);
7055 }
7056
7057 DEFUN (no_neighbor_port,
7058 no_neighbor_port_cmd,
7059 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7060 NO_STR
7061 NEIGHBOR_STR
7062 NEIGHBOR_ADDR_STR2
7063 "Neighbor's BGP port\n"
7064 "TCP port number\n")
7065 {
7066 int idx_ip = 2;
7067 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7068 }
7069
7070
7071 /* neighbor weight. */
7072 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7073 safi_t safi, const char *weight_str)
7074 {
7075 int ret;
7076 struct peer *peer;
7077 unsigned long weight;
7078
7079 peer = peer_and_group_lookup_vty(vty, ip_str);
7080 if (!peer)
7081 return CMD_WARNING_CONFIG_FAILED;
7082
7083 weight = strtoul(weight_str, NULL, 10);
7084
7085 ret = peer_weight_set(peer, afi, safi, weight);
7086 return bgp_vty_return(vty, ret);
7087 }
7088
7089 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7090 safi_t safi)
7091 {
7092 int ret;
7093 struct peer *peer;
7094
7095 peer = peer_and_group_lookup_vty(vty, ip_str);
7096 if (!peer)
7097 return CMD_WARNING_CONFIG_FAILED;
7098
7099 ret = peer_weight_unset(peer, afi, safi);
7100 return bgp_vty_return(vty, ret);
7101 }
7102
7103 DEFUN (neighbor_weight,
7104 neighbor_weight_cmd,
7105 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7106 NEIGHBOR_STR
7107 NEIGHBOR_ADDR_STR2
7108 "Set default weight for routes from this neighbor\n"
7109 "default weight\n")
7110 {
7111 int idx_peer = 1;
7112 int idx_number = 3;
7113 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7114 bgp_node_safi(vty), argv[idx_number]->arg);
7115 }
7116
7117 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7118 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7119 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7120 "Set default weight for routes from this neighbor\n"
7121 "default weight\n")
7122
7123 DEFUN (no_neighbor_weight,
7124 no_neighbor_weight_cmd,
7125 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7126 NO_STR
7127 NEIGHBOR_STR
7128 NEIGHBOR_ADDR_STR2
7129 "Set default weight for routes from this neighbor\n"
7130 "default weight\n")
7131 {
7132 int idx_peer = 2;
7133 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7134 bgp_node_afi(vty), bgp_node_safi(vty));
7135 }
7136
7137 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7138 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7139 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7140 "Set default weight for routes from this neighbor\n"
7141 "default weight\n")
7142
7143
7144 /* Override capability negotiation. */
7145 DEFUN (neighbor_override_capability,
7146 neighbor_override_capability_cmd,
7147 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7148 NEIGHBOR_STR
7149 NEIGHBOR_ADDR_STR2
7150 "Override capability negotiation result\n")
7151 {
7152 int idx_peer = 1;
7153 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7154 PEER_FLAG_OVERRIDE_CAPABILITY);
7155 }
7156
7157 DEFUN (no_neighbor_override_capability,
7158 no_neighbor_override_capability_cmd,
7159 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7160 NO_STR
7161 NEIGHBOR_STR
7162 NEIGHBOR_ADDR_STR2
7163 "Override capability negotiation result\n")
7164 {
7165 int idx_peer = 2;
7166 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7167 PEER_FLAG_OVERRIDE_CAPABILITY);
7168 }
7169
7170 DEFUN (neighbor_strict_capability,
7171 neighbor_strict_capability_cmd,
7172 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7173 NEIGHBOR_STR
7174 NEIGHBOR_ADDR_STR2
7175 "Strict capability negotiation match\n")
7176 {
7177 int idx_peer = 1;
7178
7179 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7180 PEER_FLAG_STRICT_CAP_MATCH);
7181 }
7182
7183 DEFUN (no_neighbor_strict_capability,
7184 no_neighbor_strict_capability_cmd,
7185 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7186 NO_STR
7187 NEIGHBOR_STR
7188 NEIGHBOR_ADDR_STR2
7189 "Strict capability negotiation match\n")
7190 {
7191 int idx_peer = 2;
7192
7193 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7194 PEER_FLAG_STRICT_CAP_MATCH);
7195 }
7196
7197 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7198 const char *keep_str, const char *hold_str)
7199 {
7200 int ret;
7201 struct peer *peer;
7202 uint32_t keepalive;
7203 uint32_t holdtime;
7204
7205 peer = peer_and_group_lookup_vty(vty, ip_str);
7206 if (!peer)
7207 return CMD_WARNING_CONFIG_FAILED;
7208
7209 keepalive = strtoul(keep_str, NULL, 10);
7210 holdtime = strtoul(hold_str, NULL, 10);
7211
7212 ret = peer_timers_set(peer, keepalive, holdtime);
7213
7214 return bgp_vty_return(vty, ret);
7215 }
7216
7217 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7218 {
7219 int ret;
7220 struct peer *peer;
7221
7222 peer = peer_and_group_lookup_vty(vty, ip_str);
7223 if (!peer)
7224 return CMD_WARNING_CONFIG_FAILED;
7225
7226 ret = peer_timers_unset(peer);
7227
7228 return bgp_vty_return(vty, ret);
7229 }
7230
7231 DEFUN (neighbor_timers,
7232 neighbor_timers_cmd,
7233 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7234 NEIGHBOR_STR
7235 NEIGHBOR_ADDR_STR2
7236 "BGP per neighbor timers\n"
7237 "Keepalive interval\n"
7238 "Holdtime\n")
7239 {
7240 int idx_peer = 1;
7241 int idx_number = 3;
7242 int idx_number_2 = 4;
7243 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7244 argv[idx_number]->arg,
7245 argv[idx_number_2]->arg);
7246 }
7247
7248 DEFUN (no_neighbor_timers,
7249 no_neighbor_timers_cmd,
7250 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7251 NO_STR
7252 NEIGHBOR_STR
7253 NEIGHBOR_ADDR_STR2
7254 "BGP per neighbor timers\n"
7255 "Keepalive interval\n"
7256 "Holdtime\n")
7257 {
7258 int idx_peer = 2;
7259 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7260 }
7261
7262
7263 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7264 const char *time_str)
7265 {
7266 int ret;
7267 struct peer *peer;
7268 uint32_t connect;
7269
7270 peer = peer_and_group_lookup_vty(vty, ip_str);
7271 if (!peer)
7272 return CMD_WARNING_CONFIG_FAILED;
7273
7274 connect = strtoul(time_str, NULL, 10);
7275
7276 ret = peer_timers_connect_set(peer, connect);
7277
7278 return bgp_vty_return(vty, ret);
7279 }
7280
7281 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7282 {
7283 int ret;
7284 struct peer *peer;
7285
7286 peer = peer_and_group_lookup_vty(vty, ip_str);
7287 if (!peer)
7288 return CMD_WARNING_CONFIG_FAILED;
7289
7290 ret = peer_timers_connect_unset(peer);
7291
7292 return bgp_vty_return(vty, ret);
7293 }
7294
7295 DEFUN (neighbor_timers_connect,
7296 neighbor_timers_connect_cmd,
7297 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7298 NEIGHBOR_STR
7299 NEIGHBOR_ADDR_STR2
7300 "BGP per neighbor timers\n"
7301 "BGP connect timer\n"
7302 "Connect timer\n")
7303 {
7304 int idx_peer = 1;
7305 int idx_number = 4;
7306 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7307 argv[idx_number]->arg);
7308 }
7309
7310 DEFUN (no_neighbor_timers_connect,
7311 no_neighbor_timers_connect_cmd,
7312 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7313 NO_STR
7314 NEIGHBOR_STR
7315 NEIGHBOR_ADDR_STR2
7316 "BGP per neighbor timers\n"
7317 "BGP connect timer\n"
7318 "Connect timer\n")
7319 {
7320 int idx_peer = 2;
7321 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7322 }
7323
7324 DEFPY (neighbor_timers_delayopen,
7325 neighbor_timers_delayopen_cmd,
7326 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7327 NEIGHBOR_STR
7328 NEIGHBOR_ADDR_STR2
7329 "BGP per neighbor timers\n"
7330 "RFC 4271 DelayOpenTimer\n"
7331 "DelayOpenTime timer interval\n")
7332 {
7333 struct peer *peer;
7334
7335 peer = peer_and_group_lookup_vty(vty, neighbor);
7336 if (!peer)
7337 return CMD_WARNING_CONFIG_FAILED;
7338
7339 if (!interval) {
7340 if (peer_timers_delayopen_unset(peer))
7341 return CMD_WARNING_CONFIG_FAILED;
7342 } else {
7343 if (peer_timers_delayopen_set(peer, interval))
7344 return CMD_WARNING_CONFIG_FAILED;
7345 }
7346
7347 return CMD_SUCCESS;
7348 }
7349
7350 DEFPY (no_neighbor_timers_delayopen,
7351 no_neighbor_timers_delayopen_cmd,
7352 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7353 NO_STR
7354 NEIGHBOR_STR
7355 NEIGHBOR_ADDR_STR2
7356 "BGP per neighbor timers\n"
7357 "RFC 4271 DelayOpenTimer\n"
7358 "DelayOpenTime timer interval\n")
7359 {
7360 struct peer *peer;
7361
7362 peer = peer_and_group_lookup_vty(vty, neighbor);
7363 if (!peer)
7364 return CMD_WARNING_CONFIG_FAILED;
7365
7366 if (peer_timers_delayopen_unset(peer))
7367 return CMD_WARNING_CONFIG_FAILED;
7368
7369 return CMD_SUCCESS;
7370 }
7371
7372 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7373 const char *time_str, int set)
7374 {
7375 int ret;
7376 struct peer *peer;
7377 uint32_t routeadv = 0;
7378
7379 peer = peer_and_group_lookup_vty(vty, ip_str);
7380 if (!peer)
7381 return CMD_WARNING_CONFIG_FAILED;
7382
7383 if (time_str)
7384 routeadv = strtoul(time_str, NULL, 10);
7385
7386 if (set)
7387 ret = peer_advertise_interval_set(peer, routeadv);
7388 else
7389 ret = peer_advertise_interval_unset(peer);
7390
7391 return bgp_vty_return(vty, ret);
7392 }
7393
7394 DEFUN (neighbor_advertise_interval,
7395 neighbor_advertise_interval_cmd,
7396 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7397 NEIGHBOR_STR
7398 NEIGHBOR_ADDR_STR2
7399 "Minimum interval between sending BGP routing updates\n"
7400 "time in seconds\n")
7401 {
7402 int idx_peer = 1;
7403 int idx_number = 3;
7404 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7405 argv[idx_number]->arg, 1);
7406 }
7407
7408 DEFUN (no_neighbor_advertise_interval,
7409 no_neighbor_advertise_interval_cmd,
7410 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7411 NO_STR
7412 NEIGHBOR_STR
7413 NEIGHBOR_ADDR_STR2
7414 "Minimum interval between sending BGP routing updates\n"
7415 "time in seconds\n")
7416 {
7417 int idx_peer = 2;
7418 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7419 }
7420
7421
7422 /* Time to wait before processing route-map updates */
7423 DEFUN (bgp_set_route_map_delay_timer,
7424 bgp_set_route_map_delay_timer_cmd,
7425 "bgp route-map delay-timer (0-600)",
7426 SET_STR
7427 "BGP route-map delay timer\n"
7428 "Time in secs to wait before processing route-map changes\n"
7429 "0 disables the timer, no route updates happen when route-maps change\n")
7430 {
7431 int idx_number = 3;
7432 uint32_t rmap_delay_timer;
7433
7434 if (argv[idx_number]->arg) {
7435 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7436 bm->rmap_update_timer = rmap_delay_timer;
7437
7438 /* if the dynamic update handling is being disabled, and a timer
7439 * is
7440 * running, stop the timer and act as if the timer has already
7441 * fired.
7442 */
7443 if (!rmap_delay_timer && bm->t_rmap_update) {
7444 THREAD_OFF(bm->t_rmap_update);
7445 thread_execute(bm->master, bgp_route_map_update_timer,
7446 NULL, 0);
7447 }
7448 return CMD_SUCCESS;
7449 } else {
7450 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7451 return CMD_WARNING_CONFIG_FAILED;
7452 }
7453 }
7454
7455 DEFUN (no_bgp_set_route_map_delay_timer,
7456 no_bgp_set_route_map_delay_timer_cmd,
7457 "no bgp route-map delay-timer [(0-600)]",
7458 NO_STR
7459 BGP_STR
7460 "Default BGP route-map delay timer\n"
7461 "Reset to default time to wait for processing route-map changes\n"
7462 "0 disables the timer, no route updates happen when route-maps change\n")
7463 {
7464
7465 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7466
7467 return CMD_SUCCESS;
7468 }
7469
7470 /* neighbor interface */
7471 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7472 const char *str)
7473 {
7474 struct peer *peer;
7475
7476 peer = peer_lookup_vty(vty, ip_str);
7477 if (!peer || peer->conf_if) {
7478 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7479 return CMD_WARNING_CONFIG_FAILED;
7480 }
7481
7482 if (str)
7483 peer_interface_set(peer, str);
7484 else
7485 peer_interface_unset(peer);
7486
7487 return CMD_SUCCESS;
7488 }
7489
7490 DEFUN (neighbor_interface,
7491 neighbor_interface_cmd,
7492 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7493 NEIGHBOR_STR
7494 NEIGHBOR_ADDR_STR
7495 "Interface\n"
7496 "Interface name\n")
7497 {
7498 int idx_ip = 1;
7499 int idx_word = 3;
7500
7501 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7502 }
7503
7504 DEFUN (no_neighbor_interface,
7505 no_neighbor_interface_cmd,
7506 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7507 NO_STR
7508 NEIGHBOR_STR
7509 NEIGHBOR_ADDR_STR
7510 "Interface\n"
7511 "Interface name\n")
7512 {
7513 int idx_peer = 2;
7514
7515 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7516 }
7517
7518 DEFUN (neighbor_distribute_list,
7519 neighbor_distribute_list_cmd,
7520 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7521 NEIGHBOR_STR
7522 NEIGHBOR_ADDR_STR2
7523 "Filter updates to/from this neighbor\n"
7524 "IP Access-list name\n"
7525 "Filter incoming updates\n"
7526 "Filter outgoing updates\n")
7527 {
7528 int idx_peer = 1;
7529 int idx_acl = 3;
7530 int direct, ret;
7531 struct peer *peer;
7532
7533 const char *pstr = argv[idx_peer]->arg;
7534 const char *acl = argv[idx_acl]->arg;
7535 const char *inout = argv[argc - 1]->text;
7536
7537 peer = peer_and_group_lookup_vty(vty, pstr);
7538 if (!peer)
7539 return CMD_WARNING_CONFIG_FAILED;
7540
7541 /* Check filter direction. */
7542 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7543 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7544 direct, acl);
7545
7546 return bgp_vty_return(vty, ret);
7547 }
7548
7549 ALIAS_HIDDEN(
7550 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7551 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7552 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7553 "Filter updates to/from this neighbor\n"
7554 "IP Access-list name\n"
7555 "Filter incoming updates\n"
7556 "Filter outgoing updates\n")
7557
7558 DEFUN (no_neighbor_distribute_list,
7559 no_neighbor_distribute_list_cmd,
7560 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7561 NO_STR
7562 NEIGHBOR_STR
7563 NEIGHBOR_ADDR_STR2
7564 "Filter updates to/from this neighbor\n"
7565 "IP Access-list name\n"
7566 "Filter incoming updates\n"
7567 "Filter outgoing updates\n")
7568 {
7569 int idx_peer = 2;
7570 int direct, ret;
7571 struct peer *peer;
7572
7573 const char *pstr = argv[idx_peer]->arg;
7574 const char *inout = argv[argc - 1]->text;
7575
7576 peer = peer_and_group_lookup_vty(vty, pstr);
7577 if (!peer)
7578 return CMD_WARNING_CONFIG_FAILED;
7579
7580 /* Check filter direction. */
7581 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7582 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7583 direct);
7584
7585 return bgp_vty_return(vty, ret);
7586 }
7587
7588 ALIAS_HIDDEN(
7589 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7590 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7591 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7592 "Filter updates to/from this neighbor\n"
7593 "IP Access-list name\n"
7594 "Filter incoming updates\n"
7595 "Filter outgoing updates\n")
7596
7597 /* Set prefix list to the peer. */
7598 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7599 afi_t afi, safi_t safi,
7600 const char *name_str,
7601 const char *direct_str)
7602 {
7603 int ret;
7604 int direct = FILTER_IN;
7605 struct peer *peer;
7606
7607 peer = peer_and_group_lookup_vty(vty, ip_str);
7608 if (!peer)
7609 return CMD_WARNING_CONFIG_FAILED;
7610
7611 /* Check filter direction. */
7612 if (strncmp(direct_str, "i", 1) == 0)
7613 direct = FILTER_IN;
7614 else if (strncmp(direct_str, "o", 1) == 0)
7615 direct = FILTER_OUT;
7616
7617 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7618
7619 return bgp_vty_return(vty, ret);
7620 }
7621
7622 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7623 afi_t afi, safi_t safi,
7624 const char *direct_str)
7625 {
7626 int ret;
7627 struct peer *peer;
7628 int direct = FILTER_IN;
7629
7630 peer = peer_and_group_lookup_vty(vty, ip_str);
7631 if (!peer)
7632 return CMD_WARNING_CONFIG_FAILED;
7633
7634 /* Check filter direction. */
7635 if (strncmp(direct_str, "i", 1) == 0)
7636 direct = FILTER_IN;
7637 else if (strncmp(direct_str, "o", 1) == 0)
7638 direct = FILTER_OUT;
7639
7640 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7641
7642 return bgp_vty_return(vty, ret);
7643 }
7644
7645 DEFUN (neighbor_prefix_list,
7646 neighbor_prefix_list_cmd,
7647 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7648 NEIGHBOR_STR
7649 NEIGHBOR_ADDR_STR2
7650 "Filter updates to/from this neighbor\n"
7651 "Name of a prefix list\n"
7652 "Filter incoming updates\n"
7653 "Filter outgoing updates\n")
7654 {
7655 int idx_peer = 1;
7656 int idx_word = 3;
7657 int idx_in_out = 4;
7658 return peer_prefix_list_set_vty(
7659 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7660 argv[idx_word]->arg, argv[idx_in_out]->arg);
7661 }
7662
7663 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7664 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7665 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7666 "Filter updates to/from this neighbor\n"
7667 "Name of a prefix list\n"
7668 "Filter incoming updates\n"
7669 "Filter outgoing updates\n")
7670
7671 DEFUN (no_neighbor_prefix_list,
7672 no_neighbor_prefix_list_cmd,
7673 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7674 NO_STR
7675 NEIGHBOR_STR
7676 NEIGHBOR_ADDR_STR2
7677 "Filter updates to/from this neighbor\n"
7678 "Name of a prefix list\n"
7679 "Filter incoming updates\n"
7680 "Filter outgoing updates\n")
7681 {
7682 int idx_peer = 2;
7683 int idx_in_out = 5;
7684 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7685 bgp_node_afi(vty), bgp_node_safi(vty),
7686 argv[idx_in_out]->arg);
7687 }
7688
7689 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7690 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7691 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7692 "Filter updates to/from this neighbor\n"
7693 "Name of a prefix list\n"
7694 "Filter incoming updates\n"
7695 "Filter outgoing updates\n")
7696
7697 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7698 safi_t safi, const char *name_str,
7699 const char *direct_str)
7700 {
7701 int ret;
7702 struct peer *peer;
7703 int direct = FILTER_IN;
7704
7705 peer = peer_and_group_lookup_vty(vty, ip_str);
7706 if (!peer)
7707 return CMD_WARNING_CONFIG_FAILED;
7708
7709 /* Check filter direction. */
7710 if (strncmp(direct_str, "i", 1) == 0)
7711 direct = FILTER_IN;
7712 else if (strncmp(direct_str, "o", 1) == 0)
7713 direct = FILTER_OUT;
7714
7715 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7716
7717 return bgp_vty_return(vty, ret);
7718 }
7719
7720 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7721 safi_t safi, const char *direct_str)
7722 {
7723 int ret;
7724 struct peer *peer;
7725 int direct = FILTER_IN;
7726
7727 peer = peer_and_group_lookup_vty(vty, ip_str);
7728 if (!peer)
7729 return CMD_WARNING_CONFIG_FAILED;
7730
7731 /* Check filter direction. */
7732 if (strncmp(direct_str, "i", 1) == 0)
7733 direct = FILTER_IN;
7734 else if (strncmp(direct_str, "o", 1) == 0)
7735 direct = FILTER_OUT;
7736
7737 ret = peer_aslist_unset(peer, afi, safi, direct);
7738
7739 return bgp_vty_return(vty, ret);
7740 }
7741
7742 DEFUN (neighbor_filter_list,
7743 neighbor_filter_list_cmd,
7744 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7745 NEIGHBOR_STR
7746 NEIGHBOR_ADDR_STR2
7747 "Establish BGP filters\n"
7748 "AS path access-list name\n"
7749 "Filter incoming routes\n"
7750 "Filter outgoing routes\n")
7751 {
7752 int idx_peer = 1;
7753 int idx_word = 3;
7754 int idx_in_out = 4;
7755 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7756 bgp_node_safi(vty), argv[idx_word]->arg,
7757 argv[idx_in_out]->arg);
7758 }
7759
7760 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7761 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7762 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7763 "Establish BGP filters\n"
7764 "AS path access-list name\n"
7765 "Filter incoming routes\n"
7766 "Filter outgoing routes\n")
7767
7768 DEFUN (no_neighbor_filter_list,
7769 no_neighbor_filter_list_cmd,
7770 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7771 NO_STR
7772 NEIGHBOR_STR
7773 NEIGHBOR_ADDR_STR2
7774 "Establish BGP filters\n"
7775 "AS path access-list name\n"
7776 "Filter incoming routes\n"
7777 "Filter outgoing routes\n")
7778 {
7779 int idx_peer = 2;
7780 int idx_in_out = 5;
7781 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7782 bgp_node_afi(vty), bgp_node_safi(vty),
7783 argv[idx_in_out]->arg);
7784 }
7785
7786 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7787 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7788 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7789 "Establish BGP filters\n"
7790 "AS path access-list name\n"
7791 "Filter incoming routes\n"
7792 "Filter outgoing routes\n")
7793
7794 /* Set advertise-map to the peer. */
7795 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7796 afi_t afi, safi_t safi,
7797 const char *advertise_str,
7798 const char *condition_str, bool condition,
7799 bool set)
7800 {
7801 int ret = CMD_WARNING_CONFIG_FAILED;
7802 struct peer *peer;
7803 struct route_map *advertise_map;
7804 struct route_map *condition_map;
7805
7806 peer = peer_and_group_lookup_vty(vty, ip_str);
7807 if (!peer)
7808 return ret;
7809
7810 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7811 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7812
7813 if (set)
7814 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7815 advertise_map, condition_str,
7816 condition_map, condition);
7817 else
7818 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7819 advertise_map, condition_str,
7820 condition_map, condition);
7821
7822 return bgp_vty_return(vty, ret);
7823 }
7824
7825 DEFPY (bgp_condadv_period,
7826 bgp_condadv_period_cmd,
7827 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7828 NO_STR
7829 BGP_STR
7830 "Conditional advertisement settings\n"
7831 "Set period to rescan BGP table to check if condition is met\n"
7832 "Period between BGP table scans, in seconds; default 60\n")
7833 {
7834 VTY_DECLVAR_CONTEXT(bgp, bgp);
7835
7836 bgp->condition_check_period =
7837 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7838
7839 return CMD_SUCCESS;
7840 }
7841
7842 DEFPY (neighbor_advertise_map,
7843 neighbor_advertise_map_cmd,
7844 "[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",
7845 NO_STR
7846 NEIGHBOR_STR
7847 NEIGHBOR_ADDR_STR2
7848 "Route-map to conditionally advertise routes\n"
7849 "Name of advertise map\n"
7850 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7851 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7852 "Name of the exist or non exist map\n")
7853 {
7854 bool condition = CONDITION_EXIST;
7855
7856 if (!strcmp(exist, "non-exist-map"))
7857 condition = CONDITION_NON_EXIST;
7858
7859 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7860 bgp_node_safi(vty), advertise_str,
7861 condition_str, condition, !no);
7862 }
7863
7864 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7865 "[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",
7866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7867 "Route-map to conditionally advertise routes\n"
7868 "Name of advertise map\n"
7869 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7870 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7871 "Name of the exist or non exist map\n")
7872
7873 /* Set route-map to the peer. */
7874 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7875 afi_t afi, safi_t safi, const char *name_str,
7876 const char *direct_str)
7877 {
7878 int ret;
7879 struct peer *peer;
7880 int direct = RMAP_IN;
7881 struct route_map *route_map;
7882
7883 peer = peer_and_group_lookup_vty(vty, ip_str);
7884 if (!peer)
7885 return CMD_WARNING_CONFIG_FAILED;
7886
7887 /* Check filter direction. */
7888 if (strncmp(direct_str, "in", 2) == 0)
7889 direct = RMAP_IN;
7890 else if (strncmp(direct_str, "o", 1) == 0)
7891 direct = RMAP_OUT;
7892
7893 route_map = route_map_lookup_warn_noexist(vty, name_str);
7894 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7895
7896 return bgp_vty_return(vty, ret);
7897 }
7898
7899 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7900 afi_t afi, safi_t safi,
7901 const char *direct_str)
7902 {
7903 int ret;
7904 struct peer *peer;
7905 int direct = RMAP_IN;
7906
7907 peer = peer_and_group_lookup_vty(vty, ip_str);
7908 if (!peer)
7909 return CMD_WARNING_CONFIG_FAILED;
7910
7911 /* Check filter direction. */
7912 if (strncmp(direct_str, "in", 2) == 0)
7913 direct = RMAP_IN;
7914 else if (strncmp(direct_str, "o", 1) == 0)
7915 direct = RMAP_OUT;
7916
7917 ret = peer_route_map_unset(peer, afi, safi, direct);
7918
7919 return bgp_vty_return(vty, ret);
7920 }
7921
7922 DEFUN (neighbor_route_map,
7923 neighbor_route_map_cmd,
7924 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7925 NEIGHBOR_STR
7926 NEIGHBOR_ADDR_STR2
7927 "Apply route map to neighbor\n"
7928 "Name of route map\n"
7929 "Apply map to incoming routes\n"
7930 "Apply map to outbound routes\n")
7931 {
7932 int idx_peer = 1;
7933 int idx_word = 3;
7934 int idx_in_out = 4;
7935 return peer_route_map_set_vty(
7936 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7937 argv[idx_word]->arg, argv[idx_in_out]->arg);
7938 }
7939
7940 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7941 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7943 "Apply route map to neighbor\n"
7944 "Name of route map\n"
7945 "Apply map to incoming routes\n"
7946 "Apply map to outbound routes\n")
7947
7948 DEFUN (no_neighbor_route_map,
7949 no_neighbor_route_map_cmd,
7950 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7951 NO_STR
7952 NEIGHBOR_STR
7953 NEIGHBOR_ADDR_STR2
7954 "Apply route map to neighbor\n"
7955 "Name of route map\n"
7956 "Apply map to incoming routes\n"
7957 "Apply map to outbound routes\n")
7958 {
7959 int idx_peer = 2;
7960 int idx_in_out = 5;
7961 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7962 bgp_node_afi(vty), bgp_node_safi(vty),
7963 argv[idx_in_out]->arg);
7964 }
7965
7966 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7967 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7969 "Apply route map to neighbor\n"
7970 "Name of route map\n"
7971 "Apply map to incoming routes\n"
7972 "Apply map to outbound routes\n")
7973
7974 /* Set unsuppress-map to the peer. */
7975 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7976 afi_t afi, safi_t safi,
7977 const char *name_str)
7978 {
7979 int ret;
7980 struct peer *peer;
7981 struct route_map *route_map;
7982
7983 peer = peer_and_group_lookup_vty(vty, ip_str);
7984 if (!peer)
7985 return CMD_WARNING_CONFIG_FAILED;
7986
7987 route_map = route_map_lookup_warn_noexist(vty, name_str);
7988 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7989
7990 return bgp_vty_return(vty, ret);
7991 }
7992
7993 /* Unset route-map from the peer. */
7994 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7995 afi_t afi, safi_t safi)
7996 {
7997 int ret;
7998 struct peer *peer;
7999
8000 peer = peer_and_group_lookup_vty(vty, ip_str);
8001 if (!peer)
8002 return CMD_WARNING_CONFIG_FAILED;
8003
8004 ret = peer_unsuppress_map_unset(peer, afi, safi);
8005
8006 return bgp_vty_return(vty, ret);
8007 }
8008
8009 DEFUN (neighbor_unsuppress_map,
8010 neighbor_unsuppress_map_cmd,
8011 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8012 NEIGHBOR_STR
8013 NEIGHBOR_ADDR_STR2
8014 "Route-map to selectively unsuppress suppressed routes\n"
8015 "Name of route map\n")
8016 {
8017 int idx_peer = 1;
8018 int idx_word = 3;
8019 return peer_unsuppress_map_set_vty(
8020 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8021 argv[idx_word]->arg);
8022 }
8023
8024 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8025 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8026 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8027 "Route-map to selectively unsuppress suppressed routes\n"
8028 "Name of route map\n")
8029
8030 DEFUN (no_neighbor_unsuppress_map,
8031 no_neighbor_unsuppress_map_cmd,
8032 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8033 NO_STR
8034 NEIGHBOR_STR
8035 NEIGHBOR_ADDR_STR2
8036 "Route-map to selectively unsuppress suppressed routes\n"
8037 "Name of route map\n")
8038 {
8039 int idx_peer = 2;
8040 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8041 bgp_node_afi(vty),
8042 bgp_node_safi(vty));
8043 }
8044
8045 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8046 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8047 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8048 "Route-map to selectively unsuppress suppressed routes\n"
8049 "Name of route map\n")
8050
8051 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8052 afi_t afi, safi_t safi,
8053 const char *num_str,
8054 const char *threshold_str, int warning,
8055 const char *restart_str,
8056 const char *force_str)
8057 {
8058 int ret;
8059 struct peer *peer;
8060 uint32_t max;
8061 uint8_t threshold;
8062 uint16_t restart;
8063
8064 peer = peer_and_group_lookup_vty(vty, ip_str);
8065 if (!peer)
8066 return CMD_WARNING_CONFIG_FAILED;
8067
8068 max = strtoul(num_str, NULL, 10);
8069 if (threshold_str)
8070 threshold = atoi(threshold_str);
8071 else
8072 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8073
8074 if (restart_str)
8075 restart = atoi(restart_str);
8076 else
8077 restart = 0;
8078
8079 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8080 restart, force_str ? true : false);
8081
8082 return bgp_vty_return(vty, ret);
8083 }
8084
8085 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8086 afi_t afi, safi_t safi)
8087 {
8088 int ret;
8089 struct peer *peer;
8090
8091 peer = peer_and_group_lookup_vty(vty, ip_str);
8092 if (!peer)
8093 return CMD_WARNING_CONFIG_FAILED;
8094
8095 ret = peer_maximum_prefix_unset(peer, afi, safi);
8096
8097 return bgp_vty_return(vty, ret);
8098 }
8099
8100 /* Maximum number of prefix to be sent to the neighbor. */
8101 DEFUN(neighbor_maximum_prefix_out,
8102 neighbor_maximum_prefix_out_cmd,
8103 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8104 NEIGHBOR_STR
8105 NEIGHBOR_ADDR_STR2
8106 "Maximum number of prefixes to be sent to this peer\n"
8107 "Maximum no. of prefix limit\n")
8108 {
8109 int ret;
8110 int idx_peer = 1;
8111 int idx_number = 3;
8112 struct peer *peer;
8113 uint32_t max;
8114 afi_t afi = bgp_node_afi(vty);
8115 safi_t safi = bgp_node_safi(vty);
8116
8117 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8118 if (!peer)
8119 return CMD_WARNING_CONFIG_FAILED;
8120
8121 max = strtoul(argv[idx_number]->arg, NULL, 10);
8122
8123 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8124
8125 return bgp_vty_return(vty, ret);
8126 }
8127
8128 DEFUN(no_neighbor_maximum_prefix_out,
8129 no_neighbor_maximum_prefix_out_cmd,
8130 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8131 NO_STR
8132 NEIGHBOR_STR
8133 NEIGHBOR_ADDR_STR2
8134 "Maximum number of prefixes to be sent to this peer\n"
8135 "Maximum no. of prefix limit\n")
8136 {
8137 int ret;
8138 int idx_peer = 2;
8139 struct peer *peer;
8140 afi_t afi = bgp_node_afi(vty);
8141 safi_t safi = bgp_node_safi(vty);
8142
8143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8144 if (!peer)
8145 return CMD_WARNING_CONFIG_FAILED;
8146
8147 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8148
8149 return bgp_vty_return(vty, ret);
8150 }
8151
8152 /* Maximum number of prefix configuration. Prefix count is different
8153 for each peer configuration. So this configuration can be set for
8154 each peer configuration. */
8155 DEFUN (neighbor_maximum_prefix,
8156 neighbor_maximum_prefix_cmd,
8157 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8158 NEIGHBOR_STR
8159 NEIGHBOR_ADDR_STR2
8160 "Maximum number of prefix accept from this peer\n"
8161 "maximum no. of prefix limit\n"
8162 "Force checking all received routes not only accepted\n")
8163 {
8164 int idx_peer = 1;
8165 int idx_number = 3;
8166 int idx_force = 0;
8167 char *force = NULL;
8168
8169 if (argv_find(argv, argc, "force", &idx_force))
8170 force = argv[idx_force]->arg;
8171
8172 return peer_maximum_prefix_set_vty(
8173 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8174 argv[idx_number]->arg, NULL, 0, NULL, force);
8175 }
8176
8177 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8178 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8179 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8180 "Maximum number of prefix accept from this peer\n"
8181 "maximum no. of prefix limit\n"
8182 "Force checking all received routes not only accepted\n")
8183
8184 DEFUN (neighbor_maximum_prefix_threshold,
8185 neighbor_maximum_prefix_threshold_cmd,
8186 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8187 NEIGHBOR_STR
8188 NEIGHBOR_ADDR_STR2
8189 "Maximum number of prefix accept from this peer\n"
8190 "maximum no. of prefix limit\n"
8191 "Threshold value (%) at which to generate a warning msg\n"
8192 "Force checking all received routes not only accepted\n")
8193 {
8194 int idx_peer = 1;
8195 int idx_number = 3;
8196 int idx_number_2 = 4;
8197 int idx_force = 0;
8198 char *force = NULL;
8199
8200 if (argv_find(argv, argc, "force", &idx_force))
8201 force = argv[idx_force]->arg;
8202
8203 return peer_maximum_prefix_set_vty(
8204 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8205 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8206 }
8207
8208 ALIAS_HIDDEN(
8209 neighbor_maximum_prefix_threshold,
8210 neighbor_maximum_prefix_threshold_hidden_cmd,
8211 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8212 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8213 "Maximum number of prefix accept from this peer\n"
8214 "maximum no. of prefix limit\n"
8215 "Threshold value (%) at which to generate a warning msg\n"
8216 "Force checking all received routes not only accepted\n")
8217
8218 DEFUN (neighbor_maximum_prefix_warning,
8219 neighbor_maximum_prefix_warning_cmd,
8220 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8221 NEIGHBOR_STR
8222 NEIGHBOR_ADDR_STR2
8223 "Maximum number of prefix accept from this peer\n"
8224 "maximum no. of prefix limit\n"
8225 "Only give warning message when limit is exceeded\n"
8226 "Force checking all received routes not only accepted\n")
8227 {
8228 int idx_peer = 1;
8229 int idx_number = 3;
8230 int idx_force = 0;
8231 char *force = NULL;
8232
8233 if (argv_find(argv, argc, "force", &idx_force))
8234 force = argv[idx_force]->arg;
8235
8236 return peer_maximum_prefix_set_vty(
8237 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8238 argv[idx_number]->arg, NULL, 1, NULL, force);
8239 }
8240
8241 ALIAS_HIDDEN(
8242 neighbor_maximum_prefix_warning,
8243 neighbor_maximum_prefix_warning_hidden_cmd,
8244 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8246 "Maximum number of prefix accept from this peer\n"
8247 "maximum no. of prefix limit\n"
8248 "Only give warning message when limit is exceeded\n"
8249 "Force checking all received routes not only accepted\n")
8250
8251 DEFUN (neighbor_maximum_prefix_threshold_warning,
8252 neighbor_maximum_prefix_threshold_warning_cmd,
8253 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8254 NEIGHBOR_STR
8255 NEIGHBOR_ADDR_STR2
8256 "Maximum number of prefix accept from this peer\n"
8257 "maximum no. of prefix limit\n"
8258 "Threshold value (%) at which to generate a warning msg\n"
8259 "Only give warning message when limit is exceeded\n"
8260 "Force checking all received routes not only accepted\n")
8261 {
8262 int idx_peer = 1;
8263 int idx_number = 3;
8264 int idx_number_2 = 4;
8265 int idx_force = 0;
8266 char *force = NULL;
8267
8268 if (argv_find(argv, argc, "force", &idx_force))
8269 force = argv[idx_force]->arg;
8270
8271 return peer_maximum_prefix_set_vty(
8272 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8273 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8274 }
8275
8276 ALIAS_HIDDEN(
8277 neighbor_maximum_prefix_threshold_warning,
8278 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8279 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8280 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8281 "Maximum number of prefix accept from this peer\n"
8282 "maximum no. of prefix limit\n"
8283 "Threshold value (%) at which to generate a warning msg\n"
8284 "Only give warning message when limit is exceeded\n"
8285 "Force checking all received routes not only accepted\n")
8286
8287 DEFUN (neighbor_maximum_prefix_restart,
8288 neighbor_maximum_prefix_restart_cmd,
8289 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8290 NEIGHBOR_STR
8291 NEIGHBOR_ADDR_STR2
8292 "Maximum number of prefix accept from this peer\n"
8293 "maximum no. of prefix limit\n"
8294 "Restart bgp connection after limit is exceeded\n"
8295 "Restart interval in minutes\n"
8296 "Force checking all received routes not only accepted\n")
8297 {
8298 int idx_peer = 1;
8299 int idx_number = 3;
8300 int idx_number_2 = 5;
8301 int idx_force = 0;
8302 char *force = NULL;
8303
8304 if (argv_find(argv, argc, "force", &idx_force))
8305 force = argv[idx_force]->arg;
8306
8307 return peer_maximum_prefix_set_vty(
8308 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8309 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8310 }
8311
8312 ALIAS_HIDDEN(
8313 neighbor_maximum_prefix_restart,
8314 neighbor_maximum_prefix_restart_hidden_cmd,
8315 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8316 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8317 "Maximum number of prefix accept from this peer\n"
8318 "maximum no. of prefix limit\n"
8319 "Restart bgp connection after limit is exceeded\n"
8320 "Restart interval in minutes\n"
8321 "Force checking all received routes not only accepted\n")
8322
8323 DEFUN (neighbor_maximum_prefix_threshold_restart,
8324 neighbor_maximum_prefix_threshold_restart_cmd,
8325 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8326 NEIGHBOR_STR
8327 NEIGHBOR_ADDR_STR2
8328 "Maximum number of prefixes to accept from this peer\n"
8329 "maximum no. of prefix limit\n"
8330 "Threshold value (%) at which to generate a warning msg\n"
8331 "Restart bgp connection after limit is exceeded\n"
8332 "Restart interval in minutes\n"
8333 "Force checking all received routes not only accepted\n")
8334 {
8335 int idx_peer = 1;
8336 int idx_number = 3;
8337 int idx_number_2 = 4;
8338 int idx_number_3 = 6;
8339 int idx_force = 0;
8340 char *force = NULL;
8341
8342 if (argv_find(argv, argc, "force", &idx_force))
8343 force = argv[idx_force]->arg;
8344
8345 return peer_maximum_prefix_set_vty(
8346 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8347 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8348 argv[idx_number_3]->arg, force);
8349 }
8350
8351 ALIAS_HIDDEN(
8352 neighbor_maximum_prefix_threshold_restart,
8353 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8354 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8356 "Maximum number of prefixes to accept from this peer\n"
8357 "maximum no. of prefix limit\n"
8358 "Threshold value (%) at which to generate a warning msg\n"
8359 "Restart bgp connection after limit is exceeded\n"
8360 "Restart interval in minutes\n"
8361 "Force checking all received routes not only accepted\n")
8362
8363 DEFUN (no_neighbor_maximum_prefix,
8364 no_neighbor_maximum_prefix_cmd,
8365 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8366 NO_STR
8367 NEIGHBOR_STR
8368 NEIGHBOR_ADDR_STR2
8369 "Maximum number of prefixes to accept from this peer\n"
8370 "maximum no. of prefix limit\n"
8371 "Threshold value (%) at which to generate a warning msg\n"
8372 "Restart bgp connection after limit is exceeded\n"
8373 "Restart interval in minutes\n"
8374 "Only give warning message when limit is exceeded\n"
8375 "Force checking all received routes not only accepted\n")
8376 {
8377 int idx_peer = 2;
8378 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8379 bgp_node_afi(vty),
8380 bgp_node_safi(vty));
8381 }
8382
8383 ALIAS_HIDDEN(
8384 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8385 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8386 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8387 "Maximum number of prefixes to accept from this peer\n"
8388 "maximum no. of prefix limit\n"
8389 "Threshold value (%) at which to generate a warning msg\n"
8390 "Restart bgp connection after limit is exceeded\n"
8391 "Restart interval in minutes\n"
8392 "Only give warning message when limit is exceeded\n"
8393 "Force checking all received routes not only accepted\n")
8394
8395 /* "neighbor accept-own" */
8396 DEFPY (neighbor_accept_own,
8397 neighbor_accept_own_cmd,
8398 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8399 NO_STR
8400 NEIGHBOR_STR
8401 NEIGHBOR_ADDR_STR2
8402 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8403 {
8404 struct peer *peer;
8405 afi_t afi = bgp_node_afi(vty);
8406 safi_t safi = bgp_node_safi(vty);
8407 int ret;
8408
8409 peer = peer_and_group_lookup_vty(vty, neighbor);
8410 if (!peer)
8411 return CMD_WARNING_CONFIG_FAILED;
8412
8413 if (no)
8414 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8415 else
8416 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8417
8418 return bgp_vty_return(vty, ret);
8419 }
8420
8421 /* "neighbor soo" */
8422 DEFPY (neighbor_soo,
8423 neighbor_soo_cmd,
8424 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8425 NEIGHBOR_STR
8426 NEIGHBOR_ADDR_STR2
8427 "Set the Site-of-Origin (SoO) extended community\n"
8428 "VPN extended community\n")
8429 {
8430 struct peer *peer;
8431 afi_t afi = bgp_node_afi(vty);
8432 safi_t safi = bgp_node_safi(vty);
8433 struct ecommunity *ecomm_soo;
8434
8435 peer = peer_and_group_lookup_vty(vty, neighbor);
8436 if (!peer)
8437 return CMD_WARNING_CONFIG_FAILED;
8438
8439 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8440 if (!ecomm_soo) {
8441 vty_out(vty, "%% Malformed SoO extended community\n");
8442 return CMD_WARNING;
8443 }
8444 ecommunity_str(ecomm_soo);
8445
8446 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8447 ecommunity_free(&peer->soo[afi][safi]);
8448 peer->soo[afi][safi] = ecomm_soo;
8449 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8450 }
8451
8452 return bgp_vty_return(vty,
8453 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8454 }
8455
8456 DEFPY (no_neighbor_soo,
8457 no_neighbor_soo_cmd,
8458 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8459 NO_STR
8460 NEIGHBOR_STR
8461 NEIGHBOR_ADDR_STR2
8462 "Set the Site-of-Origin (SoO) extended community\n"
8463 "VPN extended community\n")
8464 {
8465 struct peer *peer;
8466 afi_t afi = bgp_node_afi(vty);
8467 safi_t safi = bgp_node_safi(vty);
8468
8469 peer = peer_and_group_lookup_vty(vty, neighbor);
8470 if (!peer)
8471 return CMD_WARNING_CONFIG_FAILED;
8472
8473 ecommunity_free(&peer->soo[afi][safi]);
8474
8475 return bgp_vty_return(
8476 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8477 }
8478
8479 /* "neighbor allowas-in" */
8480 DEFUN (neighbor_allowas_in,
8481 neighbor_allowas_in_cmd,
8482 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8483 NEIGHBOR_STR
8484 NEIGHBOR_ADDR_STR2
8485 "Accept as-path with my AS present in it\n"
8486 "Number of occurrences of AS number\n"
8487 "Only accept my AS in the as-path if the route was originated in my AS\n")
8488 {
8489 int idx_peer = 1;
8490 int idx_number_origin = 3;
8491 int ret;
8492 int origin = 0;
8493 struct peer *peer;
8494 int allow_num = 0;
8495
8496 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8497 if (!peer)
8498 return CMD_WARNING_CONFIG_FAILED;
8499
8500 if (argc <= idx_number_origin)
8501 allow_num = 3;
8502 else {
8503 if (argv[idx_number_origin]->type == WORD_TKN)
8504 origin = 1;
8505 else
8506 allow_num = atoi(argv[idx_number_origin]->arg);
8507 }
8508
8509 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8510 allow_num, origin);
8511
8512 return bgp_vty_return(vty, ret);
8513 }
8514
8515 ALIAS_HIDDEN(
8516 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8517 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8518 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8519 "Accept as-path with my AS present in it\n"
8520 "Number of occurrences of AS number\n"
8521 "Only accept my AS in the as-path if the route was originated in my AS\n")
8522
8523 DEFUN (no_neighbor_allowas_in,
8524 no_neighbor_allowas_in_cmd,
8525 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8526 NO_STR
8527 NEIGHBOR_STR
8528 NEIGHBOR_ADDR_STR2
8529 "allow local ASN appears in aspath attribute\n"
8530 "Number of occurrences of AS number\n"
8531 "Only accept my AS in the as-path if the route was originated in my AS\n")
8532 {
8533 int idx_peer = 2;
8534 int ret;
8535 struct peer *peer;
8536
8537 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8538 if (!peer)
8539 return CMD_WARNING_CONFIG_FAILED;
8540
8541 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8542 bgp_node_safi(vty));
8543
8544 return bgp_vty_return(vty, ret);
8545 }
8546
8547 ALIAS_HIDDEN(
8548 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8549 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8550 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8551 "allow local ASN appears in aspath attribute\n"
8552 "Number of occurrences of AS number\n"
8553 "Only accept my AS in the as-path if the route was originated in my AS\n")
8554
8555 DEFUN (neighbor_ttl_security,
8556 neighbor_ttl_security_cmd,
8557 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8558 NEIGHBOR_STR
8559 NEIGHBOR_ADDR_STR2
8560 "BGP ttl-security parameters\n"
8561 "Specify the maximum number of hops to the BGP peer\n"
8562 "Number of hops to BGP peer\n")
8563 {
8564 int idx_peer = 1;
8565 int idx_number = 4;
8566 struct peer *peer;
8567 int gtsm_hops;
8568
8569 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8570 if (!peer)
8571 return CMD_WARNING_CONFIG_FAILED;
8572
8573 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8574
8575 /*
8576 * If 'neighbor swpX', then this is for directly connected peers,
8577 * we should not accept a ttl-security hops value greater than 1.
8578 */
8579 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8580 vty_out(vty,
8581 "%s is directly connected peer, hops cannot exceed 1\n",
8582 argv[idx_peer]->arg);
8583 return CMD_WARNING_CONFIG_FAILED;
8584 }
8585
8586 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8587 }
8588
8589 DEFUN (no_neighbor_ttl_security,
8590 no_neighbor_ttl_security_cmd,
8591 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8592 NO_STR
8593 NEIGHBOR_STR
8594 NEIGHBOR_ADDR_STR2
8595 "BGP ttl-security parameters\n"
8596 "Specify the maximum number of hops to the BGP peer\n"
8597 "Number of hops to BGP peer\n")
8598 {
8599 int idx_peer = 2;
8600 struct peer *peer;
8601
8602 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8603 if (!peer)
8604 return CMD_WARNING_CONFIG_FAILED;
8605
8606 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8607 }
8608
8609 /* disable-addpath-rx */
8610 DEFUN(neighbor_disable_addpath_rx,
8611 neighbor_disable_addpath_rx_cmd,
8612 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8613 NEIGHBOR_STR
8614 NEIGHBOR_ADDR_STR2
8615 "Do not accept additional paths\n")
8616 {
8617 char *peer_str = argv[1]->arg;
8618 struct peer *peer;
8619 afi_t afi = bgp_node_afi(vty);
8620 safi_t safi = bgp_node_safi(vty);
8621
8622 peer = peer_and_group_lookup_vty(vty, peer_str);
8623 if (!peer)
8624 return CMD_WARNING_CONFIG_FAILED;
8625
8626 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8627 PEER_FLAG_DISABLE_ADDPATH_RX);
8628 }
8629
8630 DEFUN(no_neighbor_disable_addpath_rx,
8631 no_neighbor_disable_addpath_rx_cmd,
8632 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8633 NO_STR
8634 NEIGHBOR_STR
8635 NEIGHBOR_ADDR_STR2
8636 "Do not accept additional paths\n")
8637 {
8638 char *peer_str = argv[2]->arg;
8639 struct peer *peer;
8640 afi_t afi = bgp_node_afi(vty);
8641 safi_t safi = bgp_node_safi(vty);
8642
8643 peer = peer_and_group_lookup_vty(vty, peer_str);
8644 if (!peer)
8645 return CMD_WARNING_CONFIG_FAILED;
8646
8647 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8648 PEER_FLAG_DISABLE_ADDPATH_RX);
8649 }
8650
8651 DEFUN (neighbor_addpath_tx_all_paths,
8652 neighbor_addpath_tx_all_paths_cmd,
8653 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8654 NEIGHBOR_STR
8655 NEIGHBOR_ADDR_STR2
8656 "Use addpath to advertise all paths to a neighbor\n")
8657 {
8658 int idx_peer = 1;
8659 struct peer *peer;
8660
8661 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8662 if (!peer)
8663 return CMD_WARNING_CONFIG_FAILED;
8664
8665 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8666 BGP_ADDPATH_ALL);
8667 return CMD_SUCCESS;
8668 }
8669
8670 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8671 neighbor_addpath_tx_all_paths_hidden_cmd,
8672 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8673 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8674 "Use addpath to advertise all paths to a neighbor\n")
8675
8676 DEFUN (no_neighbor_addpath_tx_all_paths,
8677 no_neighbor_addpath_tx_all_paths_cmd,
8678 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8679 NO_STR
8680 NEIGHBOR_STR
8681 NEIGHBOR_ADDR_STR2
8682 "Use addpath to advertise all paths to a neighbor\n")
8683 {
8684 int idx_peer = 2;
8685 struct peer *peer;
8686
8687 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8688 if (!peer)
8689 return CMD_WARNING_CONFIG_FAILED;
8690
8691 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8692 != BGP_ADDPATH_ALL) {
8693 vty_out(vty,
8694 "%% Peer not currently configured to transmit all paths.");
8695 return CMD_WARNING_CONFIG_FAILED;
8696 }
8697
8698 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8699 BGP_ADDPATH_NONE);
8700
8701 return CMD_SUCCESS;
8702 }
8703
8704 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8705 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8706 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8707 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8708 "Use addpath to advertise all paths to a neighbor\n")
8709
8710 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8711 neighbor_addpath_tx_bestpath_per_as_cmd,
8712 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8713 NEIGHBOR_STR
8714 NEIGHBOR_ADDR_STR2
8715 "Use addpath to advertise the bestpath per each neighboring AS\n")
8716 {
8717 int idx_peer = 1;
8718 struct peer *peer;
8719
8720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8721 if (!peer)
8722 return CMD_WARNING_CONFIG_FAILED;
8723
8724 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8725 BGP_ADDPATH_BEST_PER_AS);
8726
8727 return CMD_SUCCESS;
8728 }
8729
8730 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8731 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8732 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8734 "Use addpath to advertise the bestpath per each neighboring AS\n")
8735
8736 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8737 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8738 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8739 NO_STR
8740 NEIGHBOR_STR
8741 NEIGHBOR_ADDR_STR2
8742 "Use addpath to advertise the bestpath per each neighboring AS\n")
8743 {
8744 int idx_peer = 2;
8745 struct peer *peer;
8746
8747 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8748 if (!peer)
8749 return CMD_WARNING_CONFIG_FAILED;
8750
8751 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8752 != BGP_ADDPATH_BEST_PER_AS) {
8753 vty_out(vty,
8754 "%% Peer not currently configured to transmit all best path per as.");
8755 return CMD_WARNING_CONFIG_FAILED;
8756 }
8757
8758 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8759 BGP_ADDPATH_NONE);
8760
8761 return CMD_SUCCESS;
8762 }
8763
8764 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8765 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8766 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8767 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8768 "Use addpath to advertise the bestpath per each neighboring AS\n")
8769
8770 DEFPY(
8771 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8772 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8773 NEIGHBOR_STR
8774 NEIGHBOR_ADDR_STR2
8775 "Detect AS loops before sending to neighbor\n")
8776 {
8777 struct peer *peer;
8778
8779 peer = peer_and_group_lookup_vty(vty, neighbor);
8780 if (!peer)
8781 return CMD_WARNING_CONFIG_FAILED;
8782
8783 peer->as_path_loop_detection = true;
8784
8785 return CMD_SUCCESS;
8786 }
8787
8788 DEFPY(
8789 no_neighbor_aspath_loop_detection,
8790 no_neighbor_aspath_loop_detection_cmd,
8791 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8792 NO_STR
8793 NEIGHBOR_STR
8794 NEIGHBOR_ADDR_STR2
8795 "Detect AS loops before sending to neighbor\n")
8796 {
8797 struct peer *peer;
8798
8799 peer = peer_and_group_lookup_vty(vty, neighbor);
8800 if (!peer)
8801 return CMD_WARNING_CONFIG_FAILED;
8802
8803 peer->as_path_loop_detection = false;
8804
8805 return CMD_SUCCESS;
8806 }
8807
8808 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8809 struct ecommunity **list, bool is_rt6)
8810 {
8811 struct ecommunity *ecom = NULL;
8812 struct ecommunity *ecomadd;
8813
8814 for (; argc; --argc, ++argv) {
8815 if (is_rt6)
8816 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8817 ECOMMUNITY_ROUTE_TARGET,
8818 0);
8819 else
8820 ecomadd = ecommunity_str2com(argv[0]->arg,
8821 ECOMMUNITY_ROUTE_TARGET,
8822 0);
8823 if (!ecomadd) {
8824 vty_out(vty, "Malformed community-list value\n");
8825 if (ecom)
8826 ecommunity_free(&ecom);
8827 return CMD_WARNING_CONFIG_FAILED;
8828 }
8829
8830 if (ecom) {
8831 ecommunity_merge(ecom, ecomadd);
8832 ecommunity_free(&ecomadd);
8833 } else {
8834 ecom = ecomadd;
8835 }
8836 }
8837
8838 if (*list) {
8839 ecommunity_free(&*list);
8840 }
8841 *list = ecom;
8842
8843 return CMD_SUCCESS;
8844 }
8845
8846 /*
8847 * v2vimport is true if we are handling a `import vrf ...` command
8848 */
8849 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8850 {
8851 afi_t afi;
8852
8853 switch (vty->node) {
8854 case BGP_IPV4_NODE:
8855 afi = AFI_IP;
8856 break;
8857 case BGP_IPV6_NODE:
8858 afi = AFI_IP6;
8859 break;
8860 default:
8861 vty_out(vty,
8862 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8863 return AFI_MAX;
8864 }
8865
8866 if (!v2vimport) {
8867 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8868 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8869 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8870 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8871 vty_out(vty,
8872 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8873 return AFI_MAX;
8874 }
8875 } else {
8876 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8877 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8878 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8879 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8880 vty_out(vty,
8881 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8882 return AFI_MAX;
8883 }
8884 }
8885 return afi;
8886 }
8887
8888 DEFPY (af_rd_vpn_export,
8889 af_rd_vpn_export_cmd,
8890 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8891 NO_STR
8892 "Specify route distinguisher\n"
8893 "Between current address-family and vpn\n"
8894 "For routes leaked from current address-family to vpn\n"
8895 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8896 {
8897 VTY_DECLVAR_CONTEXT(bgp, bgp);
8898 struct prefix_rd prd;
8899 int ret;
8900 afi_t afi;
8901 int idx = 0;
8902 bool yes = true;
8903
8904 if (argv_find(argv, argc, "no", &idx))
8905 yes = false;
8906
8907 if (yes) {
8908 ret = str2prefix_rd(rd_str, &prd);
8909 if (!ret) {
8910 vty_out(vty, "%% Malformed rd\n");
8911 return CMD_WARNING_CONFIG_FAILED;
8912 }
8913 }
8914
8915 afi = vpn_policy_getafi(vty, bgp, false);
8916 if (afi == AFI_MAX)
8917 return CMD_WARNING_CONFIG_FAILED;
8918
8919 /*
8920 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8921 */
8922 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8923 bgp_get_default(), bgp);
8924
8925 if (yes) {
8926 bgp->vpn_policy[afi].tovpn_rd = prd;
8927 SET_FLAG(bgp->vpn_policy[afi].flags,
8928 BGP_VPN_POLICY_TOVPN_RD_SET);
8929 } else {
8930 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8931 BGP_VPN_POLICY_TOVPN_RD_SET);
8932 }
8933
8934 /* post-change: re-export vpn routes */
8935 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8936 bgp_get_default(), bgp);
8937
8938 return CMD_SUCCESS;
8939 }
8940
8941 ALIAS (af_rd_vpn_export,
8942 af_no_rd_vpn_export_cmd,
8943 "no rd vpn export",
8944 NO_STR
8945 "Specify route distinguisher\n"
8946 "Between current address-family and vpn\n"
8947 "For routes leaked from current address-family to vpn\n")
8948
8949 DEFPY (af_label_vpn_export,
8950 af_label_vpn_export_cmd,
8951 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8952 NO_STR
8953 "label value for VRF\n"
8954 "Between current address-family and vpn\n"
8955 "For routes leaked from current address-family to vpn\n"
8956 "Label Value <0-1048575>\n"
8957 "Automatically assign a label\n")
8958 {
8959 VTY_DECLVAR_CONTEXT(bgp, bgp);
8960 mpls_label_t label = MPLS_LABEL_NONE;
8961 afi_t afi;
8962 int idx = 0;
8963 bool yes = true;
8964
8965 if (argv_find(argv, argc, "no", &idx))
8966 yes = false;
8967
8968 /* If "no ...", squash trailing parameter */
8969 if (!yes)
8970 label_auto = NULL;
8971
8972 if (yes) {
8973 if (!label_auto)
8974 label = label_val; /* parser should force unsigned */
8975 }
8976
8977 afi = vpn_policy_getafi(vty, bgp, false);
8978 if (afi == AFI_MAX)
8979 return CMD_WARNING_CONFIG_FAILED;
8980
8981
8982 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8983 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8984 /* no change */
8985 return CMD_SUCCESS;
8986
8987 /*
8988 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8989 */
8990 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8991 bgp_get_default(), bgp);
8992
8993 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8994 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8995
8996 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8997
8998 /*
8999 * label has previously been automatically
9000 * assigned by labelpool: release it
9001 *
9002 * NB if tovpn_label == MPLS_LABEL_NONE it
9003 * means the automatic assignment is in flight
9004 * and therefore the labelpool callback must
9005 * detect that the auto label is not needed.
9006 */
9007
9008 bgp_lp_release(LP_TYPE_VRF,
9009 &bgp->vpn_policy[afi],
9010 bgp->vpn_policy[afi].tovpn_label);
9011 }
9012 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9013 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9014 }
9015
9016 bgp->vpn_policy[afi].tovpn_label = label;
9017 if (label_auto) {
9018 SET_FLAG(bgp->vpn_policy[afi].flags,
9019 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9020 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9021 vpn_leak_label_callback);
9022 }
9023
9024 /* post-change: re-export vpn routes */
9025 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9026 bgp_get_default(), bgp);
9027
9028 hook_call(bgp_snmp_update_last_changed, bgp);
9029 return CMD_SUCCESS;
9030 }
9031
9032 DEFPY (af_sid_vpn_export,
9033 af_sid_vpn_export_cmd,
9034 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9035 NO_STR
9036 "sid value for VRF\n"
9037 "Between current address-family and vpn\n"
9038 "For routes leaked from current address-family to vpn\n"
9039 "Sid allocation index\n"
9040 "Automatically assign a label\n")
9041 {
9042 VTY_DECLVAR_CONTEXT(bgp, bgp);
9043 afi_t afi;
9044 int debug = 0;
9045 int idx = 0;
9046 bool yes = true;
9047
9048 if (argv_find(argv, argc, "no", &idx))
9049 yes = false;
9050 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9051 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9052
9053 afi = vpn_policy_getafi(vty, bgp, false);
9054 if (afi == AFI_MAX)
9055 return CMD_WARNING_CONFIG_FAILED;
9056
9057 if (!yes) {
9058 /* implement me */
9059 vty_out(vty, "It's not implemented\n");
9060 return CMD_WARNING_CONFIG_FAILED;
9061 }
9062
9063 if (bgp->tovpn_sid_index != 0 ||
9064 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9065 vty_out(vty,
9066 "per-vrf sid and per-af sid are mutually exclusive\n"
9067 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9068 return CMD_WARNING_CONFIG_FAILED;
9069 }
9070
9071 /* skip when it's already configured */
9072 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9073 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9074 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9075 return CMD_SUCCESS;
9076
9077 /*
9078 * mode change between sid_idx and sid_auto isn't supported.
9079 * user must negate sid vpn export when they want to change the mode
9080 */
9081 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9082 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9083 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9084 vty_out(vty, "it's already configured as %s.\n",
9085 sid_auto ? "auto-mode" : "idx-mode");
9086 return CMD_WARNING_CONFIG_FAILED;
9087 }
9088
9089 /* pre-change */
9090 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9091 bgp_get_default(), bgp);
9092
9093 if (sid_auto) {
9094 /* SID allocation auto-mode */
9095 if (debug)
9096 zlog_debug("%s: auto sid alloc.", __func__);
9097 SET_FLAG(bgp->vpn_policy[afi].flags,
9098 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9099 } else {
9100 /* SID allocation index-mode */
9101 if (debug)
9102 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9103 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9104 }
9105
9106 /* post-change */
9107 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9108 bgp_get_default(), bgp);
9109 return CMD_SUCCESS;
9110 }
9111
9112 DEFPY (bgp_sid_vpn_export,
9113 bgp_sid_vpn_export_cmd,
9114 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9115 NO_STR
9116 "sid value for VRF\n"
9117 "Between current vrf and vpn\n"
9118 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9119 "For routes leaked from current vrf to vpn\n"
9120 "Sid allocation index\n"
9121 "Automatically assign a label\n")
9122 {
9123 VTY_DECLVAR_CONTEXT(bgp, bgp);
9124 int debug;
9125
9126 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9127 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9128
9129 if (no) {
9130 /* when per-VRF SID is not set, do nothing */
9131 if (bgp->tovpn_sid_index == 0 &&
9132 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9133 return CMD_SUCCESS;
9134
9135 sid_idx = 0;
9136 sid_auto = false;
9137 bgp->tovpn_sid_index = 0;
9138 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9139 }
9140
9141 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9142 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9143 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9144 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9145 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9146 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9147 vty_out(vty,
9148 "per-vrf sid and per-af sid are mutually exclusive\n"
9149 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9150 return CMD_WARNING_CONFIG_FAILED;
9151 }
9152
9153 /* skip when it's already configured */
9154 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9155 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9156 return CMD_SUCCESS;
9157
9158 /*
9159 * mode change between sid_idx and sid_auto isn't supported.
9160 * user must negate sid vpn export when they want to change the mode
9161 */
9162 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9163 (sid_idx != 0 &&
9164 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9165 vty_out(vty, "it's already configured as %s.\n",
9166 sid_auto ? "auto-mode" : "idx-mode");
9167 return CMD_WARNING_CONFIG_FAILED;
9168 }
9169
9170 /* pre-change */
9171 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9172 bgp);
9173 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9174 bgp);
9175
9176 if (sid_auto) {
9177 /* SID allocation auto-mode */
9178 if (debug)
9179 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9180 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9181 } else if (sid_idx != 0) {
9182 /* SID allocation index-mode */
9183 if (debug)
9184 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9185 sid_idx);
9186 bgp->tovpn_sid_index = sid_idx;
9187 }
9188
9189 /* post-change */
9190 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9191 bgp);
9192 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9193 bgp_get_default(), bgp);
9194
9195 return CMD_SUCCESS;
9196 }
9197
9198 ALIAS (af_label_vpn_export,
9199 af_no_label_vpn_export_cmd,
9200 "no label vpn export",
9201 NO_STR
9202 "label value for VRF\n"
9203 "Between current address-family and vpn\n"
9204 "For routes leaked from current address-family to vpn\n")
9205
9206 ALIAS (bgp_sid_vpn_export,
9207 no_bgp_sid_vpn_export_cmd,
9208 "no$no sid vpn per-vrf export",
9209 NO_STR
9210 "sid value for VRF\n"
9211 "Between current vrf and vpn\n"
9212 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9213 "For routes leaked from current vrf to vpn\n")
9214
9215 DEFPY (af_nexthop_vpn_export,
9216 af_nexthop_vpn_export_cmd,
9217 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9218 NO_STR
9219 "Specify next hop to use for VRF advertised prefixes\n"
9220 "Between current address-family and vpn\n"
9221 "For routes leaked from current address-family to vpn\n"
9222 "IPv4 prefix\n"
9223 "IPv6 prefix\n")
9224 {
9225 VTY_DECLVAR_CONTEXT(bgp, bgp);
9226 afi_t afi;
9227 struct prefix p;
9228
9229 if (!no) {
9230 if (!nexthop_su) {
9231 vty_out(vty, "%% Nexthop required\n");
9232 return CMD_WARNING_CONFIG_FAILED;
9233 }
9234 if (!sockunion2hostprefix(nexthop_su, &p))
9235 return CMD_WARNING_CONFIG_FAILED;
9236 }
9237
9238 afi = vpn_policy_getafi(vty, bgp, false);
9239 if (afi == AFI_MAX)
9240 return CMD_WARNING_CONFIG_FAILED;
9241
9242 /*
9243 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9244 */
9245 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9246 bgp_get_default(), bgp);
9247
9248 if (!no) {
9249 bgp->vpn_policy[afi].tovpn_nexthop = p;
9250 SET_FLAG(bgp->vpn_policy[afi].flags,
9251 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9252 } else {
9253 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9254 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9255 }
9256
9257 /* post-change: re-export vpn routes */
9258 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9259 bgp_get_default(), bgp);
9260
9261 return CMD_SUCCESS;
9262 }
9263
9264 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9265 {
9266 if (!strcmp(dstr, "import")) {
9267 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9268 } else if (!strcmp(dstr, "export")) {
9269 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9270 } else if (!strcmp(dstr, "both")) {
9271 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9272 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9273 } else {
9274 vty_out(vty, "%% direction parse error\n");
9275 return CMD_WARNING_CONFIG_FAILED;
9276 }
9277 return CMD_SUCCESS;
9278 }
9279
9280 DEFPY (af_rt_vpn_imexport,
9281 af_rt_vpn_imexport_cmd,
9282 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9283 NO_STR
9284 "Specify route target list\n"
9285 "Specify route target list\n"
9286 "Between current address-family and vpn\n"
9287 "For routes leaked from vpn to current address-family: match any\n"
9288 "For routes leaked from current address-family to vpn: set\n"
9289 "both import: match any and export: set\n"
9290 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9291 {
9292 VTY_DECLVAR_CONTEXT(bgp, bgp);
9293 int ret;
9294 struct ecommunity *ecom = NULL;
9295 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9296 enum vpn_policy_direction dir;
9297 afi_t afi;
9298 int idx = 0;
9299 bool yes = true;
9300
9301 if (argv_find(argv, argc, "no", &idx))
9302 yes = false;
9303
9304 afi = vpn_policy_getafi(vty, bgp, false);
9305 if (afi == AFI_MAX)
9306 return CMD_WARNING_CONFIG_FAILED;
9307
9308 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9309 if (ret != CMD_SUCCESS)
9310 return ret;
9311
9312 if (yes) {
9313 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9314 vty_out(vty, "%% Missing RTLIST\n");
9315 return CMD_WARNING_CONFIG_FAILED;
9316 }
9317 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9318 if (ret != CMD_SUCCESS) {
9319 return ret;
9320 }
9321 }
9322
9323 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9324 if (!dodir[dir])
9325 continue;
9326
9327 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9328
9329 if (yes) {
9330 if (bgp->vpn_policy[afi].rtlist[dir])
9331 ecommunity_free(
9332 &bgp->vpn_policy[afi].rtlist[dir]);
9333 bgp->vpn_policy[afi].rtlist[dir] =
9334 ecommunity_dup(ecom);
9335 } else {
9336 if (bgp->vpn_policy[afi].rtlist[dir])
9337 ecommunity_free(
9338 &bgp->vpn_policy[afi].rtlist[dir]);
9339 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9340 }
9341
9342 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9343 }
9344
9345 if (ecom)
9346 ecommunity_free(&ecom);
9347
9348 return CMD_SUCCESS;
9349 }
9350
9351 ALIAS (af_rt_vpn_imexport,
9352 af_no_rt_vpn_imexport_cmd,
9353 "no <rt|route-target> vpn <import|export|both>$direction_str",
9354 NO_STR
9355 "Specify route target list\n"
9356 "Specify route target list\n"
9357 "Between current address-family and vpn\n"
9358 "For routes leaked from vpn to current address-family\n"
9359 "For routes leaked from current address-family to vpn\n"
9360 "both import and export\n")
9361
9362 DEFPY (af_route_map_vpn_imexport,
9363 af_route_map_vpn_imexport_cmd,
9364 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9365 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9366 NO_STR
9367 "Specify route map\n"
9368 "Between current address-family and vpn\n"
9369 "For routes leaked from vpn to current address-family\n"
9370 "For routes leaked from current address-family to vpn\n"
9371 "name of route-map\n")
9372 {
9373 VTY_DECLVAR_CONTEXT(bgp, bgp);
9374 int ret;
9375 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9376 enum vpn_policy_direction dir;
9377 afi_t afi;
9378 int idx = 0;
9379 bool yes = true;
9380
9381 if (argv_find(argv, argc, "no", &idx))
9382 yes = false;
9383
9384 afi = vpn_policy_getafi(vty, bgp, false);
9385 if (afi == AFI_MAX)
9386 return CMD_WARNING_CONFIG_FAILED;
9387
9388 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9389 if (ret != CMD_SUCCESS)
9390 return ret;
9391
9392 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9393 if (!dodir[dir])
9394 continue;
9395
9396 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9397
9398 if (yes) {
9399 if (bgp->vpn_policy[afi].rmap_name[dir])
9400 XFREE(MTYPE_ROUTE_MAP_NAME,
9401 bgp->vpn_policy[afi].rmap_name[dir]);
9402 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9403 MTYPE_ROUTE_MAP_NAME, rmap_str);
9404 bgp->vpn_policy[afi].rmap[dir] =
9405 route_map_lookup_warn_noexist(vty, rmap_str);
9406 if (!bgp->vpn_policy[afi].rmap[dir])
9407 return CMD_SUCCESS;
9408 } else {
9409 if (bgp->vpn_policy[afi].rmap_name[dir])
9410 XFREE(MTYPE_ROUTE_MAP_NAME,
9411 bgp->vpn_policy[afi].rmap_name[dir]);
9412 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9413 bgp->vpn_policy[afi].rmap[dir] = NULL;
9414 }
9415
9416 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9417 }
9418
9419 return CMD_SUCCESS;
9420 }
9421
9422 ALIAS (af_route_map_vpn_imexport,
9423 af_no_route_map_vpn_imexport_cmd,
9424 "no route-map vpn <import|export>$direction_str",
9425 NO_STR
9426 "Specify route map\n"
9427 "Between current address-family and vpn\n"
9428 "For routes leaked from vpn to current address-family\n"
9429 "For routes leaked from current address-family to vpn\n")
9430
9431 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9432 "import vrf route-map RMAP$rmap_str",
9433 "Import routes from another VRF\n"
9434 "Vrf routes being filtered\n"
9435 "Specify route map\n"
9436 "name of route-map\n")
9437 {
9438 VTY_DECLVAR_CONTEXT(bgp, bgp);
9439 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9440 afi_t afi;
9441 struct bgp *bgp_default;
9442
9443 afi = vpn_policy_getafi(vty, bgp, true);
9444 if (afi == AFI_MAX)
9445 return CMD_WARNING_CONFIG_FAILED;
9446
9447 bgp_default = bgp_get_default();
9448 if (!bgp_default) {
9449 int32_t ret;
9450 as_t as = bgp->as;
9451
9452 /* Auto-create assuming the same AS */
9453 ret = bgp_get_vty(&bgp_default, &as, NULL,
9454 BGP_INSTANCE_TYPE_DEFAULT);
9455
9456 if (ret) {
9457 vty_out(vty,
9458 "VRF default is not configured as a bgp instance\n");
9459 return CMD_WARNING;
9460 }
9461 }
9462
9463 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9464
9465 if (bgp->vpn_policy[afi].rmap_name[dir])
9466 XFREE(MTYPE_ROUTE_MAP_NAME,
9467 bgp->vpn_policy[afi].rmap_name[dir]);
9468 bgp->vpn_policy[afi].rmap_name[dir] =
9469 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9470 bgp->vpn_policy[afi].rmap[dir] =
9471 route_map_lookup_warn_noexist(vty, rmap_str);
9472 if (!bgp->vpn_policy[afi].rmap[dir])
9473 return CMD_SUCCESS;
9474
9475 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9476 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9477
9478 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9479
9480 return CMD_SUCCESS;
9481 }
9482
9483 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9484 "no import vrf route-map [RMAP$rmap_str]",
9485 NO_STR
9486 "Import routes from another VRF\n"
9487 "Vrf routes being filtered\n"
9488 "Specify route map\n"
9489 "name of route-map\n")
9490 {
9491 VTY_DECLVAR_CONTEXT(bgp, bgp);
9492 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9493 afi_t afi;
9494
9495 afi = vpn_policy_getafi(vty, bgp, true);
9496 if (afi == AFI_MAX)
9497 return CMD_WARNING_CONFIG_FAILED;
9498
9499 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9500
9501 if (bgp->vpn_policy[afi].rmap_name[dir])
9502 XFREE(MTYPE_ROUTE_MAP_NAME,
9503 bgp->vpn_policy[afi].rmap_name[dir]);
9504 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9505 bgp->vpn_policy[afi].rmap[dir] = NULL;
9506
9507 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9508 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9509 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9510
9511 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9512
9513 return CMD_SUCCESS;
9514 }
9515
9516 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9517 "[no] import vrf VIEWVRFNAME$import_name",
9518 NO_STR
9519 "Import routes from another VRF\n"
9520 "VRF to import from\n"
9521 "The name of the VRF\n")
9522 {
9523 VTY_DECLVAR_CONTEXT(bgp, bgp);
9524 struct listnode *node;
9525 struct bgp *vrf_bgp, *bgp_default;
9526 int32_t ret = 0;
9527 as_t as = bgp->as;
9528 bool remove = false;
9529 int32_t idx = 0;
9530 char *vname;
9531 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9532 safi_t safi;
9533 afi_t afi;
9534
9535 if (import_name == NULL) {
9536 vty_out(vty, "%% Missing import name\n");
9537 return CMD_WARNING;
9538 }
9539
9540 if (strcmp(import_name, "route-map") == 0) {
9541 vty_out(vty, "%% Must include route-map name\n");
9542 return CMD_WARNING;
9543 }
9544
9545 if (argv_find(argv, argc, "no", &idx))
9546 remove = true;
9547
9548 afi = vpn_policy_getafi(vty, bgp, true);
9549 if (afi == AFI_MAX)
9550 return CMD_WARNING_CONFIG_FAILED;
9551
9552 safi = bgp_node_safi(vty);
9553
9554 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9555 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9556 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9557 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9558 remove ? "unimport" : "import", import_name);
9559 return CMD_WARNING;
9560 }
9561
9562 bgp_default = bgp_get_default();
9563 if (!bgp_default) {
9564 /* Auto-create assuming the same AS */
9565 ret = bgp_get_vty(&bgp_default, &as, NULL,
9566 BGP_INSTANCE_TYPE_DEFAULT);
9567
9568 if (ret) {
9569 vty_out(vty,
9570 "VRF default is not configured as a bgp instance\n");
9571 return CMD_WARNING;
9572 }
9573 }
9574
9575 vrf_bgp = bgp_lookup_by_name(import_name);
9576 if (!vrf_bgp) {
9577 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9578 vrf_bgp = bgp_default;
9579 else
9580 /* Auto-create assuming the same AS */
9581 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9582
9583 if (ret) {
9584 vty_out(vty,
9585 "VRF %s is not configured as a bgp instance\n",
9586 import_name);
9587 return CMD_WARNING;
9588 }
9589 }
9590
9591 if (remove) {
9592 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9593 } else {
9594 /* Already importing from "import_vrf"? */
9595 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9596 vname)) {
9597 if (strcmp(vname, import_name) == 0)
9598 return CMD_WARNING;
9599 }
9600
9601 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9602 }
9603
9604 return CMD_SUCCESS;
9605 }
9606
9607 /* This command is valid only in a bgp vrf instance or the default instance */
9608 DEFPY (bgp_imexport_vpn,
9609 bgp_imexport_vpn_cmd,
9610 "[no] <import|export>$direction_str vpn",
9611 NO_STR
9612 "Import routes to this address-family\n"
9613 "Export routes from this address-family\n"
9614 "to/from default instance VPN RIB\n")
9615 {
9616 VTY_DECLVAR_CONTEXT(bgp, bgp);
9617 int previous_state;
9618 afi_t afi;
9619 safi_t safi;
9620 int idx = 0;
9621 bool yes = true;
9622 int flag;
9623 enum vpn_policy_direction dir;
9624
9625 if (argv_find(argv, argc, "no", &idx))
9626 yes = false;
9627
9628 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9629 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9630
9631 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9632 return CMD_WARNING_CONFIG_FAILED;
9633 }
9634
9635 afi = bgp_node_afi(vty);
9636 safi = bgp_node_safi(vty);
9637 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9638 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9639 return CMD_WARNING_CONFIG_FAILED;
9640 }
9641
9642 if (!strcmp(direction_str, "import")) {
9643 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9644 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9645 } else if (!strcmp(direction_str, "export")) {
9646 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9647 dir = BGP_VPN_POLICY_DIR_TOVPN;
9648 } else {
9649 vty_out(vty, "%% unknown direction %s\n", direction_str);
9650 return CMD_WARNING_CONFIG_FAILED;
9651 }
9652
9653 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9654
9655 if (yes) {
9656 SET_FLAG(bgp->af_flags[afi][safi], flag);
9657 if (!previous_state) {
9658 /* trigger export current vrf */
9659 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9660 }
9661 } else {
9662 if (previous_state) {
9663 /* trigger un-export current vrf */
9664 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9665 }
9666 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9667 }
9668
9669 hook_call(bgp_snmp_init_stats, bgp);
9670
9671 return CMD_SUCCESS;
9672 }
9673
9674 DEFPY (af_routetarget_import,
9675 af_routetarget_import_cmd,
9676 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9677 NO_STR
9678 "Specify route target list\n"
9679 "Specify route target list\n"
9680 "Specify route target list\n"
9681 "Specify route target list\n"
9682 "Flow-spec redirect type route target\n"
9683 "Import routes to this address-family\n"
9684 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9685 {
9686 VTY_DECLVAR_CONTEXT(bgp, bgp);
9687 int ret;
9688 struct ecommunity *ecom = NULL;
9689 afi_t afi;
9690 int idx = 0, idx_unused = 0;
9691 bool yes = true;
9692 bool rt6 = false;
9693
9694 if (argv_find(argv, argc, "no", &idx))
9695 yes = false;
9696
9697 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9698 argv_find(argv, argc, "route-target6", &idx_unused))
9699 rt6 = true;
9700
9701 afi = vpn_policy_getafi(vty, bgp, false);
9702 if (afi == AFI_MAX)
9703 return CMD_WARNING_CONFIG_FAILED;
9704
9705 if (rt6 && afi != AFI_IP6)
9706 return CMD_WARNING_CONFIG_FAILED;
9707
9708 if (yes) {
9709 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9710 vty_out(vty, "%% Missing RTLIST\n");
9711 return CMD_WARNING_CONFIG_FAILED;
9712 }
9713 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9714 if (ret != CMD_SUCCESS)
9715 return ret;
9716 }
9717
9718 if (yes) {
9719 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9720 ecommunity_free(&bgp->vpn_policy[afi]
9721 .import_redirect_rtlist);
9722 bgp->vpn_policy[afi].import_redirect_rtlist =
9723 ecommunity_dup(ecom);
9724 } else {
9725 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9726 ecommunity_free(&bgp->vpn_policy[afi]
9727 .import_redirect_rtlist);
9728 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9729 }
9730
9731 if (ecom)
9732 ecommunity_free(&ecom);
9733
9734 return CMD_SUCCESS;
9735 }
9736
9737 DEFUN_NOSH (address_family_ipv4_safi,
9738 address_family_ipv4_safi_cmd,
9739 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9740 "Enter Address Family command mode\n"
9741 BGP_AF_STR
9742 BGP_SAFI_WITH_LABEL_HELP_STR)
9743 {
9744
9745 if (argc == 3) {
9746 VTY_DECLVAR_CONTEXT(bgp, bgp);
9747 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9748 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9749 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9750 && safi != SAFI_EVPN) {
9751 vty_out(vty,
9752 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9753 return CMD_WARNING_CONFIG_FAILED;
9754 }
9755 vty->node = bgp_node_type(AFI_IP, safi);
9756 } else
9757 vty->node = BGP_IPV4_NODE;
9758
9759 return CMD_SUCCESS;
9760 }
9761
9762 DEFUN_NOSH (address_family_ipv6_safi,
9763 address_family_ipv6_safi_cmd,
9764 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9765 "Enter Address Family command mode\n"
9766 BGP_AF_STR
9767 BGP_SAFI_WITH_LABEL_HELP_STR)
9768 {
9769 if (argc == 3) {
9770 VTY_DECLVAR_CONTEXT(bgp, bgp);
9771 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9772 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9773 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9774 && safi != SAFI_EVPN) {
9775 vty_out(vty,
9776 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9777 return CMD_WARNING_CONFIG_FAILED;
9778 }
9779 vty->node = bgp_node_type(AFI_IP6, safi);
9780 } else
9781 vty->node = BGP_IPV6_NODE;
9782
9783 return CMD_SUCCESS;
9784 }
9785
9786 #ifdef KEEP_OLD_VPN_COMMANDS
9787 DEFUN_NOSH (address_family_vpnv4,
9788 address_family_vpnv4_cmd,
9789 "address-family vpnv4 [unicast]",
9790 "Enter Address Family command mode\n"
9791 BGP_AF_STR
9792 BGP_AF_MODIFIER_STR)
9793 {
9794 vty->node = BGP_VPNV4_NODE;
9795 return CMD_SUCCESS;
9796 }
9797
9798 DEFUN_NOSH (address_family_vpnv6,
9799 address_family_vpnv6_cmd,
9800 "address-family vpnv6 [unicast]",
9801 "Enter Address Family command mode\n"
9802 BGP_AF_STR
9803 BGP_AF_MODIFIER_STR)
9804 {
9805 vty->node = BGP_VPNV6_NODE;
9806 return CMD_SUCCESS;
9807 }
9808 #endif /* KEEP_OLD_VPN_COMMANDS */
9809
9810 DEFUN_NOSH (address_family_evpn,
9811 address_family_evpn_cmd,
9812 "address-family l2vpn evpn",
9813 "Enter Address Family command mode\n"
9814 BGP_AF_STR
9815 BGP_AF_MODIFIER_STR)
9816 {
9817 VTY_DECLVAR_CONTEXT(bgp, bgp);
9818 vty->node = BGP_EVPN_NODE;
9819 return CMD_SUCCESS;
9820 }
9821
9822 DEFUN_NOSH (bgp_segment_routing_srv6,
9823 bgp_segment_routing_srv6_cmd,
9824 "segment-routing srv6",
9825 "Segment-Routing configuration\n"
9826 "Segment-Routing SRv6 configuration\n")
9827 {
9828 VTY_DECLVAR_CONTEXT(bgp, bgp);
9829 bgp->srv6_enabled = true;
9830 vty->node = BGP_SRV6_NODE;
9831 return CMD_SUCCESS;
9832 }
9833
9834 DEFUN (no_bgp_segment_routing_srv6,
9835 no_bgp_segment_routing_srv6_cmd,
9836 "no segment-routing srv6",
9837 NO_STR
9838 "Segment-Routing configuration\n"
9839 "Segment-Routing SRv6 configuration\n")
9840 {
9841 VTY_DECLVAR_CONTEXT(bgp, bgp);
9842
9843 if (strlen(bgp->srv6_locator_name) > 0)
9844 if (bgp_srv6_locator_unset(bgp) < 0)
9845 return CMD_WARNING_CONFIG_FAILED;
9846
9847 bgp->srv6_enabled = false;
9848 return CMD_SUCCESS;
9849 }
9850
9851 DEFPY (bgp_srv6_locator,
9852 bgp_srv6_locator_cmd,
9853 "locator NAME$name",
9854 "Specify SRv6 locator\n"
9855 "Specify SRv6 locator\n")
9856 {
9857 VTY_DECLVAR_CONTEXT(bgp, bgp);
9858 int ret;
9859
9860 if (strlen(bgp->srv6_locator_name) > 0
9861 && strcmp(name, bgp->srv6_locator_name) != 0) {
9862 vty_out(vty, "srv6 locator is already configured\n");
9863 return CMD_WARNING_CONFIG_FAILED;
9864 }
9865
9866 snprintf(bgp->srv6_locator_name,
9867 sizeof(bgp->srv6_locator_name), "%s", name);
9868
9869 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9870 if (ret < 0)
9871 return CMD_WARNING_CONFIG_FAILED;
9872
9873 return CMD_SUCCESS;
9874 }
9875
9876 DEFPY (no_bgp_srv6_locator,
9877 no_bgp_srv6_locator_cmd,
9878 "no locator NAME$name",
9879 NO_STR
9880 "Specify SRv6 locator\n"
9881 "Specify SRv6 locator\n")
9882 {
9883 VTY_DECLVAR_CONTEXT(bgp, bgp);
9884
9885 /* when locator isn't configured, do nothing */
9886 if (strlen(bgp->srv6_locator_name) < 1)
9887 return CMD_SUCCESS;
9888
9889 /* name validation */
9890 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9891 vty_out(vty, "%% No srv6 locator is configured\n");
9892 return CMD_WARNING_CONFIG_FAILED;
9893 }
9894
9895 /* unset locator */
9896 if (bgp_srv6_locator_unset(bgp) < 0)
9897 return CMD_WARNING_CONFIG_FAILED;
9898
9899 return CMD_SUCCESS;
9900 }
9901
9902 DEFPY (show_bgp_srv6,
9903 show_bgp_srv6_cmd,
9904 "show bgp segment-routing srv6",
9905 SHOW_STR
9906 BGP_STR
9907 "BGP Segment Routing\n"
9908 "BGP Segment Routing SRv6\n")
9909 {
9910 struct bgp *bgp;
9911 struct listnode *node;
9912 struct srv6_locator_chunk *chunk;
9913 struct bgp_srv6_function *func;
9914
9915 bgp = bgp_get_default();
9916 if (!bgp)
9917 return CMD_SUCCESS;
9918
9919 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9920 vty_out(vty, "locator_chunks:\n");
9921 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9922 vty_out(vty, "- %pFX\n", &chunk->prefix);
9923 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9924 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9925 vty_out(vty, " func-length: %d\n",
9926 chunk->function_bits_length);
9927 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9928 }
9929
9930 vty_out(vty, "functions:\n");
9931 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9932 vty_out(vty, "- sid: %pI6\n", &func->sid);
9933 vty_out(vty, " locator: %s\n", func->locator_name);
9934 }
9935
9936 vty_out(vty, "bgps:\n");
9937 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9938 vty_out(vty, "- name: %s\n",
9939 bgp->name ? bgp->name : "default");
9940
9941 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9942 bgp->vpn_policy[AFI_IP].tovpn_sid);
9943 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9944 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9945 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
9946 }
9947
9948 return CMD_SUCCESS;
9949 }
9950
9951 DEFUN_NOSH (exit_address_family,
9952 exit_address_family_cmd,
9953 "exit-address-family",
9954 "Exit from Address Family configuration mode\n")
9955 {
9956 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9957 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9958 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9959 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9960 || vty->node == BGP_EVPN_NODE
9961 || vty->node == BGP_FLOWSPECV4_NODE
9962 || vty->node == BGP_FLOWSPECV6_NODE)
9963 vty->node = BGP_NODE;
9964 return CMD_SUCCESS;
9965 }
9966
9967 /* Recalculate bestpath and re-advertise a prefix */
9968 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9969 const char *ip_str, afi_t afi, safi_t safi,
9970 struct prefix_rd *prd)
9971 {
9972 int ret;
9973 struct prefix match;
9974 struct bgp_dest *dest;
9975 struct bgp_dest *rm;
9976 struct bgp *bgp;
9977 struct bgp_table *table;
9978 struct bgp_table *rib;
9979
9980 /* BGP structure lookup. */
9981 if (view_name) {
9982 bgp = bgp_lookup_by_name(view_name);
9983 if (bgp == NULL) {
9984 vty_out(vty, "%% Can't find BGP instance %s\n",
9985 view_name);
9986 return CMD_WARNING;
9987 }
9988 } else {
9989 bgp = bgp_get_default();
9990 if (bgp == NULL) {
9991 vty_out(vty, "%% No BGP process is configured\n");
9992 return CMD_WARNING;
9993 }
9994 }
9995
9996 /* Check IP address argument. */
9997 ret = str2prefix(ip_str, &match);
9998 if (!ret) {
9999 vty_out(vty, "%% address is malformed\n");
10000 return CMD_WARNING;
10001 }
10002
10003 match.family = afi2family(afi);
10004 rib = bgp->rib[afi][safi];
10005
10006 if (safi == SAFI_MPLS_VPN) {
10007 for (dest = bgp_table_top(rib); dest;
10008 dest = bgp_route_next(dest)) {
10009 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10010
10011 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10012 continue;
10013
10014 table = bgp_dest_get_bgp_table_info(dest);
10015 if (table == NULL)
10016 continue;
10017
10018 rm = bgp_node_match(table, &match);
10019 if (rm != NULL) {
10020 const struct prefix *rm_p =
10021 bgp_dest_get_prefix(rm);
10022
10023 if (rm_p->prefixlen == match.prefixlen) {
10024 SET_FLAG(rm->flags,
10025 BGP_NODE_USER_CLEAR);
10026 bgp_process(bgp, rm, afi, safi);
10027 }
10028 bgp_dest_unlock_node(rm);
10029 }
10030 }
10031 } else {
10032 dest = bgp_node_match(rib, &match);
10033 if (dest != NULL) {
10034 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10035
10036 if (dest_p->prefixlen == match.prefixlen) {
10037 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10038 bgp_process(bgp, dest, afi, safi);
10039 }
10040 bgp_dest_unlock_node(dest);
10041 }
10042 }
10043
10044 return CMD_SUCCESS;
10045 }
10046
10047 /* one clear bgp command to rule them all */
10048 DEFUN (clear_ip_bgp_all,
10049 clear_ip_bgp_all_cmd,
10050 "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>]",
10051 CLEAR_STR
10052 IP_STR
10053 BGP_STR
10054 BGP_INSTANCE_HELP_STR
10055 BGP_AFI_HELP_STR
10056 BGP_AF_STR
10057 BGP_SAFI_WITH_LABEL_HELP_STR
10058 BGP_AF_MODIFIER_STR
10059 "Clear all peers\n"
10060 "BGP IPv4 neighbor to clear\n"
10061 "BGP IPv6 neighbor to clear\n"
10062 "BGP neighbor on interface to clear\n"
10063 "Clear peers with the AS number\n"
10064 "Clear all external peers\n"
10065 "Clear all members of peer-group\n"
10066 "BGP peer-group name\n"
10067 BGP_SOFT_STR
10068 BGP_SOFT_IN_STR
10069 BGP_SOFT_OUT_STR
10070 BGP_SOFT_IN_STR
10071 "Push out prefix-list ORF and do inbound soft reconfig\n"
10072 BGP_SOFT_OUT_STR
10073 "Reset message statistics\n")
10074 {
10075 char *vrf = NULL;
10076
10077 afi_t afi = AFI_UNSPEC;
10078 safi_t safi = SAFI_UNSPEC;
10079 enum clear_sort clr_sort = clear_peer;
10080 enum bgp_clear_type clr_type;
10081 char *clr_arg = NULL;
10082
10083 int idx = 0;
10084
10085 /* clear [ip] bgp */
10086 if (argv_find(argv, argc, "ip", &idx))
10087 afi = AFI_IP;
10088
10089 /* [<vrf> VIEWVRFNAME] */
10090 if (argv_find(argv, argc, "vrf", &idx)) {
10091 vrf = argv[idx + 1]->arg;
10092 idx += 2;
10093 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10094 vrf = NULL;
10095 } else if (argv_find(argv, argc, "view", &idx)) {
10096 /* [<view> VIEWVRFNAME] */
10097 vrf = argv[idx + 1]->arg;
10098 idx += 2;
10099 }
10100 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10101 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10102 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10103
10104 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10105 if (argv_find(argv, argc, "*", &idx)) {
10106 clr_sort = clear_all;
10107 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10108 clr_sort = clear_peer;
10109 clr_arg = argv[idx]->arg;
10110 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10111 clr_sort = clear_peer;
10112 clr_arg = argv[idx]->arg;
10113 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10114 clr_sort = clear_group;
10115 idx++;
10116 clr_arg = argv[idx]->arg;
10117 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10118 clr_sort = clear_peer;
10119 clr_arg = argv[idx]->arg;
10120 } else if (argv_find(argv, argc, "WORD", &idx)) {
10121 clr_sort = clear_peer;
10122 clr_arg = argv[idx]->arg;
10123 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10124 clr_sort = clear_as;
10125 clr_arg = argv[idx]->arg;
10126 } else if (argv_find(argv, argc, "external", &idx)) {
10127 clr_sort = clear_external;
10128 }
10129
10130 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10131 if (argv_find(argv, argc, "soft", &idx)) {
10132 if (argv_find(argv, argc, "in", &idx)
10133 || argv_find(argv, argc, "out", &idx))
10134 clr_type = strmatch(argv[idx]->text, "in")
10135 ? BGP_CLEAR_SOFT_IN
10136 : BGP_CLEAR_SOFT_OUT;
10137 else
10138 clr_type = BGP_CLEAR_SOFT_BOTH;
10139 } else if (argv_find(argv, argc, "in", &idx)) {
10140 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10141 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10142 : BGP_CLEAR_SOFT_IN;
10143 } else if (argv_find(argv, argc, "out", &idx)) {
10144 clr_type = BGP_CLEAR_SOFT_OUT;
10145 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10146 clr_type = BGP_CLEAR_MESSAGE_STATS;
10147 } else
10148 clr_type = BGP_CLEAR_SOFT_NONE;
10149
10150 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10151 }
10152
10153 DEFUN (clear_ip_bgp_prefix,
10154 clear_ip_bgp_prefix_cmd,
10155 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10156 CLEAR_STR
10157 IP_STR
10158 BGP_STR
10159 BGP_INSTANCE_HELP_STR
10160 "Clear bestpath and re-advertise\n"
10161 "IPv4 prefix\n")
10162 {
10163 char *vrf = NULL;
10164 char *prefix = NULL;
10165
10166 int idx = 0;
10167
10168 /* [<view|vrf> VIEWVRFNAME] */
10169 if (argv_find(argv, argc, "vrf", &idx)) {
10170 vrf = argv[idx + 1]->arg;
10171 idx += 2;
10172 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10173 vrf = NULL;
10174 } else if (argv_find(argv, argc, "view", &idx)) {
10175 /* [<view> VIEWVRFNAME] */
10176 vrf = argv[idx + 1]->arg;
10177 idx += 2;
10178 }
10179
10180 prefix = argv[argc - 1]->arg;
10181
10182 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10183 }
10184
10185 DEFUN (clear_bgp_ipv6_safi_prefix,
10186 clear_bgp_ipv6_safi_prefix_cmd,
10187 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10188 CLEAR_STR
10189 IP_STR
10190 BGP_STR
10191 BGP_AF_STR
10192 BGP_SAFI_HELP_STR
10193 "Clear bestpath and re-advertise\n"
10194 "IPv6 prefix\n")
10195 {
10196 int idx_safi = 0;
10197 int idx_ipv6_prefix = 0;
10198 safi_t safi = SAFI_UNICAST;
10199 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10200 argv[idx_ipv6_prefix]->arg : NULL;
10201
10202 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10203 return bgp_clear_prefix(
10204 vty, NULL, prefix, AFI_IP6,
10205 safi, NULL);
10206 }
10207
10208 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10209 clear_bgp_instance_ipv6_safi_prefix_cmd,
10210 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10211 CLEAR_STR
10212 IP_STR
10213 BGP_STR
10214 BGP_INSTANCE_HELP_STR
10215 BGP_AF_STR
10216 BGP_SAFI_HELP_STR
10217 "Clear bestpath and re-advertise\n"
10218 "IPv6 prefix\n")
10219 {
10220 int idx_safi = 0;
10221 int idx_vrfview = 0;
10222 int idx_ipv6_prefix = 0;
10223 safi_t safi = SAFI_UNICAST;
10224 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10225 argv[idx_ipv6_prefix]->arg : NULL;
10226 char *vrfview = NULL;
10227
10228 /* [<view|vrf> VIEWVRFNAME] */
10229 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10230 vrfview = argv[idx_vrfview + 1]->arg;
10231 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10232 vrfview = NULL;
10233 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10234 /* [<view> VIEWVRFNAME] */
10235 vrfview = argv[idx_vrfview + 1]->arg;
10236 }
10237 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10238
10239 return bgp_clear_prefix(
10240 vty, vrfview, prefix,
10241 AFI_IP6, safi, NULL);
10242 }
10243
10244 DEFUN (show_bgp_views,
10245 show_bgp_views_cmd,
10246 "show [ip] bgp views",
10247 SHOW_STR
10248 IP_STR
10249 BGP_STR
10250 "Show the defined BGP views\n")
10251 {
10252 struct list *inst = bm->bgp;
10253 struct listnode *node;
10254 struct bgp *bgp;
10255
10256 vty_out(vty, "Defined BGP views:\n");
10257 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10258 /* Skip VRFs. */
10259 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10260 continue;
10261 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10262 bgp->as);
10263 }
10264
10265 return CMD_SUCCESS;
10266 }
10267
10268 DEFUN (show_bgp_vrfs,
10269 show_bgp_vrfs_cmd,
10270 "show [ip] bgp vrfs [json]",
10271 SHOW_STR
10272 IP_STR
10273 BGP_STR
10274 "Show BGP VRFs\n"
10275 JSON_STR)
10276 {
10277 char buf[ETHER_ADDR_STRLEN];
10278 struct list *inst = bm->bgp;
10279 struct listnode *node;
10280 struct bgp *bgp;
10281 bool uj = use_json(argc, argv);
10282 json_object *json = NULL;
10283 json_object *json_vrfs = NULL;
10284 int count = 0;
10285
10286 if (uj) {
10287 json = json_object_new_object();
10288 json_vrfs = json_object_new_object();
10289 }
10290
10291 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10292 const char *name, *type;
10293 struct peer *peer;
10294 struct listnode *node2, *nnode2;
10295 int peers_cfg, peers_estb;
10296 json_object *json_vrf = NULL;
10297
10298 /* Skip Views. */
10299 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10300 continue;
10301
10302 count++;
10303 if (!uj && count == 1) {
10304 vty_out(vty,
10305 "%4s %-5s %-16s %9s %10s %-37s\n",
10306 "Type", "Id", "routerId", "#PeersCfg",
10307 "#PeersEstb", "Name");
10308 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10309 "L3-VNI", "RouterMAC", "Interface");
10310 }
10311
10312 peers_cfg = peers_estb = 0;
10313 if (uj)
10314 json_vrf = json_object_new_object();
10315
10316
10317 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10318 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10319 continue;
10320 peers_cfg++;
10321 if (peer_established(peer))
10322 peers_estb++;
10323 }
10324
10325 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10326 name = VRF_DEFAULT_NAME;
10327 type = "DFLT";
10328 } else {
10329 name = bgp->name;
10330 type = "VRF";
10331 }
10332
10333
10334 if (uj) {
10335 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10336 ? -1
10337 : (int64_t)bgp->vrf_id;
10338 char buf[BUFSIZ] = {0};
10339
10340 json_object_string_add(json_vrf, "type", type);
10341 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10342 json_object_string_addf(json_vrf, "routerId", "%pI4",
10343 &bgp->router_id);
10344 json_object_int_add(json_vrf, "numConfiguredPeers",
10345 peers_cfg);
10346 json_object_int_add(json_vrf, "numEstablishedPeers",
10347 peers_estb);
10348
10349 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10350 json_object_string_add(
10351 json_vrf, "rmac",
10352 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10353 json_object_string_add(json_vrf, "interface",
10354 ifindex2ifname(bgp->l3vni_svi_ifindex,
10355 bgp->vrf_id));
10356 json_object_object_add(json_vrfs, name, json_vrf);
10357 } else {
10358 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10359 type,
10360 bgp->vrf_id == VRF_UNKNOWN ? -1
10361 : (int)bgp->vrf_id,
10362 &bgp->router_id, peers_cfg, peers_estb, name);
10363 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10364 bgp->l3vni,
10365 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10366 ifindex2ifname(bgp->l3vni_svi_ifindex,
10367 bgp->vrf_id));
10368 }
10369 }
10370
10371 if (uj) {
10372 json_object_object_add(json, "vrfs", json_vrfs);
10373
10374 json_object_int_add(json, "totalVrfs", count);
10375
10376 vty_json(vty, json);
10377 } else {
10378 if (count)
10379 vty_out(vty,
10380 "\nTotal number of VRFs (including default): %d\n",
10381 count);
10382 }
10383
10384 return CMD_SUCCESS;
10385 }
10386
10387 DEFUN (show_bgp_mac_hash,
10388 show_bgp_mac_hash_cmd,
10389 "show bgp mac hash",
10390 SHOW_STR
10391 BGP_STR
10392 "Mac Address\n"
10393 "Mac Address database\n")
10394 {
10395 bgp_mac_dump_table(vty);
10396
10397 return CMD_SUCCESS;
10398 }
10399
10400 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10401 {
10402 struct vty *vty = (struct vty *)args;
10403 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10404
10405 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10406 }
10407
10408 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10409 {
10410 vty_out(vty, "self nexthop database:\n");
10411 bgp_nexthop_show_address_hash(vty, bgp);
10412
10413 vty_out(vty, "Tunnel-ip database:\n");
10414 hash_iterate(bgp->tip_hash,
10415 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10416 vty);
10417 }
10418
10419 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10420 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10421 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10422 "martian next-hops\n"
10423 "martian next-hop database\n")
10424 {
10425 struct bgp *bgp = NULL;
10426 int idx = 0;
10427 char *name = NULL;
10428
10429 /* [<vrf> VIEWVRFNAME] */
10430 if (argv_find(argv, argc, "vrf", &idx)) {
10431 name = argv[idx + 1]->arg;
10432 if (name && strmatch(name, VRF_DEFAULT_NAME))
10433 name = NULL;
10434 } else if (argv_find(argv, argc, "view", &idx))
10435 /* [<view> VIEWVRFNAME] */
10436 name = argv[idx + 1]->arg;
10437 if (name)
10438 bgp = bgp_lookup_by_name(name);
10439 else
10440 bgp = bgp_get_default();
10441
10442 if (!bgp) {
10443 vty_out(vty, "%% No BGP process is configured\n");
10444 return CMD_WARNING;
10445 }
10446 bgp_show_martian_nexthops(vty, bgp);
10447
10448 return CMD_SUCCESS;
10449 }
10450
10451 DEFUN (show_bgp_memory,
10452 show_bgp_memory_cmd,
10453 "show [ip] bgp memory",
10454 SHOW_STR
10455 IP_STR
10456 BGP_STR
10457 "Global BGP memory statistics\n")
10458 {
10459 char memstrbuf[MTYPE_MEMSTR_LEN];
10460 unsigned long count;
10461
10462 /* RIB related usage stats */
10463 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10464 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10465 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10466 count * sizeof(struct bgp_dest)));
10467
10468 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10469 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10470 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10471 count * sizeof(struct bgp_path_info)));
10472 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10473 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10474 count,
10475 mtype_memstr(
10476 memstrbuf, sizeof(memstrbuf),
10477 count * sizeof(struct bgp_path_info_extra)));
10478
10479 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10480 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10481 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10482 count * sizeof(struct bgp_static)));
10483
10484 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10485 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10486 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10487 count * sizeof(struct bpacket)));
10488
10489 /* Adj-In/Out */
10490 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10491 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10492 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10493 count * sizeof(struct bgp_adj_in)));
10494 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10495 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10497 count * sizeof(struct bgp_adj_out)));
10498
10499 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10500 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10501 count,
10502 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10503 count * sizeof(struct bgp_nexthop_cache)));
10504
10505 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10506 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10507 count,
10508 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10509 count * sizeof(struct bgp_damp_info)));
10510
10511 /* Attributes */
10512 count = attr_count();
10513 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10514 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10515 count * sizeof(struct attr)));
10516
10517 if ((count = attr_unknown_count()))
10518 vty_out(vty, "%ld unknown attributes\n", count);
10519
10520 /* AS_PATH attributes */
10521 count = aspath_count();
10522 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10523 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10524 count * sizeof(struct aspath)));
10525
10526 count = mtype_stats_alloc(MTYPE_AS_SEG);
10527 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10528 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10529 count * sizeof(struct assegment)));
10530
10531 /* Other attributes */
10532 if ((count = community_count()))
10533 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10534 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10535 count * sizeof(struct community)));
10536 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10537 vty_out(vty,
10538 "%ld BGP ext-community entries, using %s of memory\n",
10539 count,
10540 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10541 count * sizeof(struct ecommunity)));
10542 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10543 vty_out(vty,
10544 "%ld BGP large-community entries, using %s of memory\n",
10545 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10546 count * sizeof(struct lcommunity)));
10547
10548 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10549 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10550 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10551 count * sizeof(struct cluster_list)));
10552
10553 /* Peer related usage */
10554 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10555 vty_out(vty, "%ld peers, using %s of memory\n", count,
10556 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10557 count * sizeof(struct peer)));
10558
10559 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10560 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10561 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10562 count * sizeof(struct peer_group)));
10563
10564 /* Other */
10565 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10566 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10567 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10568 count * sizeof(regex_t)));
10569 return CMD_SUCCESS;
10570 }
10571
10572 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10573 {
10574 json_object *bestpath = json_object_new_object();
10575
10576 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10577 json_object_string_add(bestpath, "asPath", "ignore");
10578
10579 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10580 json_object_string_add(bestpath, "asPath", "confed");
10581
10582 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10583 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10584 json_object_string_add(bestpath, "multiPathRelax",
10585 "as-set");
10586 else
10587 json_object_string_add(bestpath, "multiPathRelax",
10588 "true");
10589 } else
10590 json_object_string_add(bestpath, "multiPathRelax", "false");
10591
10592 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10593 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10594
10595 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10596 json_object_string_add(bestpath, "compareRouterId", "true");
10597 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10598 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10599 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10600 json_object_string_add(bestpath, "med", "confed");
10601 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10602 json_object_string_add(bestpath, "med",
10603 "missing-as-worst");
10604 else
10605 json_object_string_add(bestpath, "med", "true");
10606 }
10607
10608 json_object_object_add(json, "bestPath", bestpath);
10609 }
10610
10611 /* Print the error code/subcode for why the peer is down */
10612 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10613 json_object *json_peer, bool use_json)
10614 {
10615 const char *code_str;
10616 const char *subcode_str;
10617
10618 if (use_json) {
10619 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10620 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10621 char errorcodesubcode_hexstr[5];
10622 char errorcodesubcode_str[256];
10623
10624 code_str = bgp_notify_code_str(peer->notify.code);
10625 subcode_str = bgp_notify_subcode_str(
10626 peer->notify.code,
10627 peer->notify.subcode);
10628
10629 snprintf(errorcodesubcode_hexstr,
10630 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10631 peer->notify.code, peer->notify.subcode);
10632 json_object_string_add(json_peer,
10633 "lastErrorCodeSubcode",
10634 errorcodesubcode_hexstr);
10635 snprintf(errorcodesubcode_str, 255, "%s%s",
10636 code_str, subcode_str);
10637 json_object_string_add(json_peer,
10638 "lastNotificationReason",
10639 errorcodesubcode_str);
10640 json_object_boolean_add(json_peer,
10641 "lastNotificationHardReset",
10642 peer->notify.hard_reset);
10643 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10644 && peer->notify.code == BGP_NOTIFY_CEASE
10645 && (peer->notify.subcode
10646 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10647 || peer->notify.subcode
10648 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10649 && peer->notify.length) {
10650 char msgbuf[1024];
10651 const char *msg_str;
10652
10653 msg_str = bgp_notify_admin_message(
10654 msgbuf, sizeof(msgbuf),
10655 (uint8_t *)peer->notify.data,
10656 peer->notify.length);
10657 if (msg_str)
10658 json_object_string_add(
10659 json_peer,
10660 "lastShutdownDescription",
10661 msg_str);
10662 }
10663
10664 }
10665 json_object_string_add(json_peer, "lastResetDueTo",
10666 peer_down_str[(int)peer->last_reset]);
10667 json_object_int_add(json_peer, "lastResetCode",
10668 peer->last_reset);
10669 } else {
10670 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10671 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10672 code_str = bgp_notify_code_str(peer->notify.code);
10673 subcode_str =
10674 bgp_notify_subcode_str(peer->notify.code,
10675 peer->notify.subcode);
10676 vty_out(vty, " Notification %s (%s%s%s)\n",
10677 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10678 ? "sent"
10679 : "received",
10680 code_str, subcode_str,
10681 peer->notify.hard_reset
10682 ? bgp_notify_subcode_str(
10683 BGP_NOTIFY_CEASE,
10684 BGP_NOTIFY_CEASE_HARD_RESET)
10685 : "");
10686 } else {
10687 vty_out(vty, " %s\n",
10688 peer_down_str[(int)peer->last_reset]);
10689 }
10690 }
10691 }
10692
10693 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10694 safi_t safi)
10695 {
10696 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10697 }
10698
10699 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10700 struct peer *peer, json_object *json_peer,
10701 int max_neighbor_width, bool use_json)
10702 {
10703 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10704 int len;
10705
10706 if (use_json) {
10707 if (peer_dynamic_neighbor(peer))
10708 json_object_boolean_true_add(json_peer,
10709 "dynamicPeer");
10710 if (peer->hostname)
10711 json_object_string_add(json_peer, "hostname",
10712 peer->hostname);
10713
10714 if (peer->domainname)
10715 json_object_string_add(json_peer, "domainname",
10716 peer->domainname);
10717 json_object_int_add(json_peer, "connectionsEstablished",
10718 peer->established);
10719 json_object_int_add(json_peer, "connectionsDropped",
10720 peer->dropped);
10721 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10722 use_json, json_peer);
10723 if (peer_established(peer))
10724 json_object_string_add(json_peer, "lastResetDueTo",
10725 "AFI/SAFI Not Negotiated");
10726 else
10727 bgp_show_peer_reset(NULL, peer, json_peer, true);
10728 } else {
10729 dn_flag[1] = '\0';
10730 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10731 if (peer->hostname
10732 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10733 len = vty_out(vty, "%s%s(%s)", dn_flag,
10734 peer->hostname, peer->host);
10735 else
10736 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10737
10738 /* pad the neighbor column with spaces */
10739 if (len < max_neighbor_width)
10740 vty_out(vty, "%*s", max_neighbor_width - len,
10741 " ");
10742 vty_out(vty, "%7d %7d %9s", peer->established,
10743 peer->dropped,
10744 peer_uptime(peer->uptime, timebuf,
10745 BGP_UPTIME_LEN, 0, NULL));
10746 if (peer_established(peer))
10747 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10748 else
10749 bgp_show_peer_reset(vty, peer, NULL,
10750 false);
10751 }
10752 }
10753
10754 /* Strip peer's description to the given size. */
10755 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10756 {
10757 static char stripped[BUFSIZ];
10758 uint32_t i = 0;
10759 uint32_t last_space = 0;
10760
10761 while (i < size) {
10762 if (*(desc + i) == 0) {
10763 stripped[i] = '\0';
10764 return stripped;
10765 }
10766 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10767 last_space = i;
10768 stripped[i] = *(desc + i);
10769 i++;
10770 }
10771
10772 if (last_space > size)
10773 stripped[size + 1] = '\0';
10774 else
10775 stripped[last_space] = '\0';
10776
10777 return stripped;
10778 }
10779
10780 /* Determine whether var peer should be filtered out of the summary. */
10781 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10782 struct peer *fpeer, int as_type,
10783 as_t as)
10784 {
10785
10786 /* filter neighbor XXXX */
10787 if (fpeer && fpeer != peer)
10788 return true;
10789
10790 /* filter remote-as (internal|external) */
10791 if (as_type != AS_UNSPECIFIED) {
10792 if (peer->as_type == AS_SPECIFIED) {
10793 if (as_type == AS_INTERNAL) {
10794 if (peer->as != peer->local_as)
10795 return true;
10796 } else if (peer->as == peer->local_as)
10797 return true;
10798 } else if (as_type != peer->as_type)
10799 return true;
10800 } else if (as && as != peer->as) /* filter remote-as XXX */
10801 return true;
10802
10803 return false;
10804 }
10805
10806 /* Show BGP peer's summary information.
10807 *
10808 * Peer's description is stripped according to if `wide` option is given
10809 * or not.
10810 *
10811 * When adding new columns to `show bgp summary` output, please make
10812 * sure `Desc` is the lastest column to show because it can contain
10813 * whitespaces and the whole output will be tricky.
10814 */
10815 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10816 struct peer *fpeer, int as_type, as_t as,
10817 uint16_t show_flags)
10818 {
10819 struct peer *peer;
10820 struct listnode *node, *nnode;
10821 unsigned int count = 0, dn_count = 0;
10822 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10823 char neighbor_buf[VTY_BUFSIZ];
10824 int neighbor_col_default_width = 16;
10825 int len, failed_count = 0;
10826 unsigned int filtered_count = 0;
10827 int max_neighbor_width = 0;
10828 int pfx_rcd_safi;
10829 json_object *json = NULL;
10830 json_object *json_peer = NULL;
10831 json_object *json_peers = NULL;
10832 struct peer_af *paf;
10833 struct bgp_filter *filter;
10834 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10835 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10836 bool show_established =
10837 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10838 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10839 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10840
10841 /* labeled-unicast routes are installed in the unicast table so in order
10842 * to
10843 * display the correct PfxRcd value we must look at SAFI_UNICAST
10844 */
10845
10846 if (safi == SAFI_LABELED_UNICAST)
10847 pfx_rcd_safi = SAFI_UNICAST;
10848 else
10849 pfx_rcd_safi = safi;
10850
10851 if (use_json) {
10852 json = json_object_new_object();
10853 json_peers = json_object_new_object();
10854 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10855 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10856 as_type, as)) {
10857 filtered_count++;
10858 count++;
10859 continue;
10860 }
10861
10862 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10863 continue;
10864
10865 if (peer->afc[afi][safi]) {
10866 /* See if we have at least a single failed peer */
10867 if (bgp_has_peer_failed(peer, afi, safi))
10868 failed_count++;
10869 count++;
10870 }
10871 if (peer_dynamic_neighbor(peer))
10872 dn_count++;
10873 }
10874
10875 } else {
10876 /* Loop over all neighbors that will be displayed to determine
10877 * how many
10878 * characters are needed for the Neighbor column
10879 */
10880 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10881 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10882 as_type, as)) {
10883 filtered_count++;
10884 count++;
10885 continue;
10886 }
10887
10888 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10889 continue;
10890
10891 if (peer->afc[afi][safi]) {
10892 memset(dn_flag, '\0', sizeof(dn_flag));
10893 if (peer_dynamic_neighbor(peer))
10894 dn_flag[0] = '*';
10895
10896 if (peer->hostname
10897 && CHECK_FLAG(bgp->flags,
10898 BGP_FLAG_SHOW_HOSTNAME))
10899 snprintf(neighbor_buf,
10900 sizeof(neighbor_buf),
10901 "%s%s(%s) ", dn_flag,
10902 peer->hostname, peer->host);
10903 else
10904 snprintf(neighbor_buf,
10905 sizeof(neighbor_buf), "%s%s ",
10906 dn_flag, peer->host);
10907
10908 len = strlen(neighbor_buf);
10909
10910 if (len > max_neighbor_width)
10911 max_neighbor_width = len;
10912
10913 /* See if we have at least a single failed peer */
10914 if (bgp_has_peer_failed(peer, afi, safi))
10915 failed_count++;
10916 count++;
10917 }
10918 }
10919
10920 /* Originally we displayed the Neighbor column as 16
10921 * characters wide so make that the default
10922 */
10923 if (max_neighbor_width < neighbor_col_default_width)
10924 max_neighbor_width = neighbor_col_default_width;
10925 }
10926
10927 if (show_failed && !failed_count) {
10928 if (use_json) {
10929 json_object_int_add(json, "failedPeersCount", 0);
10930 json_object_int_add(json, "dynamicPeers", dn_count);
10931 json_object_int_add(json, "totalPeers", count);
10932
10933 vty_json(vty, json);
10934 } else {
10935 vty_out(vty, "%% No failed BGP neighbors found\n");
10936 }
10937 return CMD_SUCCESS;
10938 }
10939
10940 count = 0; /* Reset the value as its used again */
10941 filtered_count = 0;
10942 dn_count = 0;
10943 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10944 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10945 continue;
10946
10947 if (!peer->afc[afi][safi])
10948 continue;
10949
10950 if (!count) {
10951 unsigned long ents;
10952 char memstrbuf[MTYPE_MEMSTR_LEN];
10953 int64_t vrf_id_ui;
10954
10955 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10956 ? -1
10957 : (int64_t)bgp->vrf_id;
10958
10959 /* Usage summary and header */
10960 if (use_json) {
10961 json_object_string_addf(json, "routerId",
10962 "%pI4",
10963 &bgp->router_id);
10964 json_object_int_add(json, "as", bgp->as);
10965 json_object_int_add(json, "vrfId", vrf_id_ui);
10966 json_object_string_add(
10967 json, "vrfName",
10968 (bgp->inst_type
10969 == BGP_INSTANCE_TYPE_DEFAULT)
10970 ? VRF_DEFAULT_NAME
10971 : bgp->name);
10972 } else {
10973 vty_out(vty,
10974 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10975 &bgp->router_id, bgp->as,
10976 bgp->vrf_id == VRF_UNKNOWN
10977 ? -1
10978 : (int)bgp->vrf_id);
10979 vty_out(vty, "\n");
10980 }
10981
10982 if (bgp_update_delay_configured(bgp)) {
10983 if (use_json) {
10984 json_object_int_add(
10985 json, "updateDelayLimit",
10986 bgp->v_update_delay);
10987
10988 if (bgp->v_update_delay
10989 != bgp->v_establish_wait)
10990 json_object_int_add(
10991 json,
10992 "updateDelayEstablishWait",
10993 bgp->v_establish_wait);
10994
10995 if (bgp_update_delay_active(bgp)) {
10996 json_object_string_add(
10997 json,
10998 "updateDelayFirstNeighbor",
10999 bgp->update_delay_begin_time);
11000 json_object_boolean_true_add(
11001 json,
11002 "updateDelayInProgress");
11003 } else {
11004 if (bgp->update_delay_over) {
11005 json_object_string_add(
11006 json,
11007 "updateDelayFirstNeighbor",
11008 bgp->update_delay_begin_time);
11009 json_object_string_add(
11010 json,
11011 "updateDelayBestpathResumed",
11012 bgp->update_delay_end_time);
11013 json_object_string_add(
11014 json,
11015 "updateDelayZebraUpdateResume",
11016 bgp->update_delay_zebra_resume_time);
11017 json_object_string_add(
11018 json,
11019 "updateDelayPeerUpdateResume",
11020 bgp->update_delay_peers_resume_time);
11021 }
11022 }
11023 } else {
11024 vty_out(vty,
11025 "Read-only mode update-delay limit: %d seconds\n",
11026 bgp->v_update_delay);
11027 if (bgp->v_update_delay
11028 != bgp->v_establish_wait)
11029 vty_out(vty,
11030 " Establish wait: %d seconds\n",
11031 bgp->v_establish_wait);
11032
11033 if (bgp_update_delay_active(bgp)) {
11034 vty_out(vty,
11035 " First neighbor established: %s\n",
11036 bgp->update_delay_begin_time);
11037 vty_out(vty,
11038 " Delay in progress\n");
11039 } else {
11040 if (bgp->update_delay_over) {
11041 vty_out(vty,
11042 " First neighbor established: %s\n",
11043 bgp->update_delay_begin_time);
11044 vty_out(vty,
11045 " Best-paths resumed: %s\n",
11046 bgp->update_delay_end_time);
11047 vty_out(vty,
11048 " zebra update resumed: %s\n",
11049 bgp->update_delay_zebra_resume_time);
11050 vty_out(vty,
11051 " peers update resumed: %s\n",
11052 bgp->update_delay_peers_resume_time);
11053 }
11054 }
11055 }
11056 }
11057
11058 if (use_json) {
11059 if (bgp_maxmed_onstartup_configured(bgp)
11060 && bgp->maxmed_active)
11061 json_object_boolean_true_add(
11062 json, "maxMedOnStartup");
11063 if (bgp->v_maxmed_admin)
11064 json_object_boolean_true_add(
11065 json, "maxMedAdministrative");
11066
11067 json_object_int_add(
11068 json, "tableVersion",
11069 bgp_table_version(bgp->rib[afi][safi]));
11070
11071 ents = bgp_table_count(bgp->rib[afi][safi]);
11072 json_object_int_add(json, "ribCount", ents);
11073 json_object_int_add(
11074 json, "ribMemory",
11075 ents * sizeof(struct bgp_dest));
11076
11077 ents = bgp->af_peer_count[afi][safi];
11078 json_object_int_add(json, "peerCount", ents);
11079 json_object_int_add(json, "peerMemory",
11080 ents * sizeof(struct peer));
11081
11082 if ((ents = listcount(bgp->group))) {
11083 json_object_int_add(
11084 json, "peerGroupCount", ents);
11085 json_object_int_add(
11086 json, "peerGroupMemory",
11087 ents * sizeof(struct
11088 peer_group));
11089 }
11090
11091 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11092 BGP_CONFIG_DAMPENING))
11093 json_object_boolean_true_add(
11094 json, "dampeningEnabled");
11095 } else {
11096 if (!show_terse) {
11097 if (bgp_maxmed_onstartup_configured(bgp)
11098 && bgp->maxmed_active)
11099 vty_out(vty,
11100 "Max-med on-startup active\n");
11101 if (bgp->v_maxmed_admin)
11102 vty_out(vty,
11103 "Max-med administrative active\n");
11104
11105 vty_out(vty,
11106 "BGP table version %" PRIu64
11107 "\n",
11108 bgp_table_version(
11109 bgp->rib[afi][safi]));
11110
11111 ents = bgp_table_count(
11112 bgp->rib[afi][safi]);
11113 vty_out(vty,
11114 "RIB entries %ld, using %s of memory\n",
11115 ents,
11116 mtype_memstr(
11117 memstrbuf,
11118 sizeof(memstrbuf),
11119 ents
11120 * sizeof(
11121 struct
11122 bgp_dest)));
11123
11124 /* Peer related usage */
11125 ents = bgp->af_peer_count[afi][safi];
11126 vty_out(vty,
11127 "Peers %ld, using %s of memory\n",
11128 ents,
11129 mtype_memstr(
11130 memstrbuf,
11131 sizeof(memstrbuf),
11132 ents
11133 * sizeof(
11134 struct
11135 peer)));
11136
11137 if ((ents = listcount(bgp->group)))
11138 vty_out(vty,
11139 "Peer groups %ld, using %s of memory\n",
11140 ents,
11141 mtype_memstr(
11142 memstrbuf,
11143 sizeof(memstrbuf),
11144 ents
11145 * sizeof(
11146 struct
11147 peer_group)));
11148
11149 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11150 BGP_CONFIG_DAMPENING))
11151 vty_out(vty,
11152 "Dampening enabled.\n");
11153 }
11154 if (show_failed) {
11155 vty_out(vty, "\n");
11156
11157 /* Subtract 8 here because 'Neighbor' is
11158 * 8 characters */
11159 vty_out(vty, "Neighbor");
11160 vty_out(vty, "%*s",
11161 max_neighbor_width - 8, " ");
11162 vty_out(vty,
11163 BGP_SHOW_SUMMARY_HEADER_FAILED);
11164 }
11165 }
11166 }
11167
11168 paf = peer_af_find(peer, afi, safi);
11169 filter = &peer->filter[afi][safi];
11170
11171 count++;
11172 /* Works for both failed & successful cases */
11173 if (peer_dynamic_neighbor(peer))
11174 dn_count++;
11175
11176 if (use_json) {
11177 json_peer = NULL;
11178 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11179 as_type, as)) {
11180 filtered_count++;
11181 continue;
11182 }
11183 if (show_failed &&
11184 bgp_has_peer_failed(peer, afi, safi)) {
11185 json_peer = json_object_new_object();
11186 bgp_show_failed_summary(vty, bgp, peer,
11187 json_peer, 0, use_json);
11188 } else if (!show_failed) {
11189 if (show_established
11190 && bgp_has_peer_failed(peer, afi, safi)) {
11191 filtered_count++;
11192 continue;
11193 }
11194
11195 json_peer = json_object_new_object();
11196 if (peer_dynamic_neighbor(peer)) {
11197 json_object_boolean_true_add(json_peer,
11198 "dynamicPeer");
11199 }
11200
11201 if (peer->hostname)
11202 json_object_string_add(json_peer, "hostname",
11203 peer->hostname);
11204
11205 if (peer->domainname)
11206 json_object_string_add(json_peer, "domainname",
11207 peer->domainname);
11208
11209 json_object_int_add(json_peer, "remoteAs", peer->as);
11210 json_object_int_add(
11211 json_peer, "localAs",
11212 peer->change_local_as
11213 ? peer->change_local_as
11214 : peer->local_as);
11215 json_object_int_add(json_peer, "version", 4);
11216 json_object_int_add(json_peer, "msgRcvd",
11217 PEER_TOTAL_RX(peer));
11218 json_object_int_add(json_peer, "msgSent",
11219 PEER_TOTAL_TX(peer));
11220
11221 atomic_size_t outq_count, inq_count;
11222 outq_count = atomic_load_explicit(
11223 &peer->obuf->count,
11224 memory_order_relaxed);
11225 inq_count = atomic_load_explicit(
11226 &peer->ibuf->count,
11227 memory_order_relaxed);
11228
11229 json_object_int_add(json_peer, "tableVersion",
11230 peer->version[afi][safi]);
11231 json_object_int_add(json_peer, "outq",
11232 outq_count);
11233 json_object_int_add(json_peer, "inq",
11234 inq_count);
11235 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11236 use_json, json_peer);
11237
11238 json_object_int_add(json_peer, "pfxRcd",
11239 peer->pcount[afi][pfx_rcd_safi]);
11240
11241 if (paf && PAF_SUBGRP(paf))
11242 json_object_int_add(
11243 json_peer, "pfxSnt",
11244 (PAF_SUBGRP(paf))->scount);
11245 else
11246 json_object_int_add(json_peer, "pfxSnt",
11247 0);
11248
11249 /* BGP FSM state */
11250 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11251 || CHECK_FLAG(peer->bgp->flags,
11252 BGP_FLAG_SHUTDOWN))
11253 json_object_string_add(json_peer,
11254 "state",
11255 "Idle (Admin)");
11256 else if (peer->afc_recv[afi][safi])
11257 json_object_string_add(
11258 json_peer, "state",
11259 lookup_msg(bgp_status_msg,
11260 peer->status, NULL));
11261 else if (CHECK_FLAG(
11262 peer->sflags,
11263 PEER_STATUS_PREFIX_OVERFLOW))
11264 json_object_string_add(json_peer,
11265 "state",
11266 "Idle (PfxCt)");
11267 else
11268 json_object_string_add(
11269 json_peer, "state",
11270 lookup_msg(bgp_status_msg,
11271 peer->status, NULL));
11272
11273 /* BGP peer state */
11274 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11275 || CHECK_FLAG(peer->bgp->flags,
11276 BGP_FLAG_SHUTDOWN))
11277 json_object_string_add(json_peer,
11278 "peerState",
11279 "Admin");
11280 else if (CHECK_FLAG(
11281 peer->sflags,
11282 PEER_STATUS_PREFIX_OVERFLOW))
11283 json_object_string_add(json_peer,
11284 "peerState",
11285 "PfxCt");
11286 else if (CHECK_FLAG(peer->flags,
11287 PEER_FLAG_PASSIVE))
11288 json_object_string_add(json_peer,
11289 "peerState",
11290 "Passive");
11291 else if (CHECK_FLAG(peer->sflags,
11292 PEER_STATUS_NSF_WAIT))
11293 json_object_string_add(json_peer,
11294 "peerState",
11295 "NSF passive");
11296 else if (CHECK_FLAG(
11297 peer->bgp->flags,
11298 BGP_FLAG_EBGP_REQUIRES_POLICY)
11299 && (!bgp_inbound_policy_exists(peer,
11300 filter)
11301 || !bgp_outbound_policy_exists(
11302 peer, filter)))
11303 json_object_string_add(json_peer,
11304 "peerState",
11305 "Policy");
11306 else
11307 json_object_string_add(
11308 json_peer, "peerState", "OK");
11309
11310 json_object_int_add(json_peer, "connectionsEstablished",
11311 peer->established);
11312 json_object_int_add(json_peer, "connectionsDropped",
11313 peer->dropped);
11314 if (peer->desc)
11315 json_object_string_add(
11316 json_peer, "desc", peer->desc);
11317 }
11318 /* Avoid creating empty peer dicts in JSON */
11319 if (json_peer == NULL)
11320 continue;
11321
11322 if (peer->conf_if)
11323 json_object_string_add(json_peer, "idType",
11324 "interface");
11325 else if (peer->su.sa.sa_family == AF_INET)
11326 json_object_string_add(json_peer, "idType",
11327 "ipv4");
11328 else if (peer->su.sa.sa_family == AF_INET6)
11329 json_object_string_add(json_peer, "idType",
11330 "ipv6");
11331 json_object_object_add(json_peers, peer->host,
11332 json_peer);
11333 } else {
11334 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11335 as_type, as)) {
11336 filtered_count++;
11337 continue;
11338 }
11339 if (show_failed &&
11340 bgp_has_peer_failed(peer, afi, safi)) {
11341 bgp_show_failed_summary(vty, bgp, peer, NULL,
11342 max_neighbor_width,
11343 use_json);
11344 } else if (!show_failed) {
11345 if (show_established
11346 && bgp_has_peer_failed(peer, afi, safi)) {
11347 filtered_count++;
11348 continue;
11349 }
11350
11351 if ((count - filtered_count) == 1) {
11352 /* display headline before the first
11353 * neighbor line */
11354 vty_out(vty, "\n");
11355
11356 /* Subtract 8 here because 'Neighbor' is
11357 * 8 characters */
11358 vty_out(vty, "Neighbor");
11359 vty_out(vty, "%*s",
11360 max_neighbor_width - 8, " ");
11361 vty_out(vty,
11362 show_wide
11363 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11364 : BGP_SHOW_SUMMARY_HEADER_ALL);
11365 }
11366
11367 memset(dn_flag, '\0', sizeof(dn_flag));
11368 if (peer_dynamic_neighbor(peer)) {
11369 dn_flag[0] = '*';
11370 }
11371
11372 if (peer->hostname
11373 && CHECK_FLAG(bgp->flags,
11374 BGP_FLAG_SHOW_HOSTNAME))
11375 len = vty_out(vty, "%s%s(%s)", dn_flag,
11376 peer->hostname,
11377 peer->host);
11378 else
11379 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11380
11381 /* pad the neighbor column with spaces */
11382 if (len < max_neighbor_width)
11383 vty_out(vty, "%*s", max_neighbor_width - len,
11384 " ");
11385
11386 atomic_size_t outq_count, inq_count;
11387 outq_count = atomic_load_explicit(
11388 &peer->obuf->count,
11389 memory_order_relaxed);
11390 inq_count = atomic_load_explicit(
11391 &peer->ibuf->count,
11392 memory_order_relaxed);
11393
11394 if (show_wide)
11395 vty_out(vty,
11396 "4 %10u %10u %9u %9u %8" PRIu64
11397 " %4zu %4zu %8s",
11398 peer->as,
11399 peer->change_local_as
11400 ? peer->change_local_as
11401 : peer->local_as,
11402 PEER_TOTAL_RX(peer),
11403 PEER_TOTAL_TX(peer),
11404 peer->version[afi][safi],
11405 inq_count, outq_count,
11406 peer_uptime(peer->uptime,
11407 timebuf,
11408 BGP_UPTIME_LEN, 0,
11409 NULL));
11410 else
11411 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11412 " %4zu %4zu %8s",
11413 peer->as, PEER_TOTAL_RX(peer),
11414 PEER_TOTAL_TX(peer),
11415 peer->version[afi][safi],
11416 inq_count, outq_count,
11417 peer_uptime(peer->uptime,
11418 timebuf,
11419 BGP_UPTIME_LEN, 0,
11420 NULL));
11421
11422 if (peer_established(peer)) {
11423 if (peer->afc_recv[afi][safi]) {
11424 if (CHECK_FLAG(
11425 bgp->flags,
11426 BGP_FLAG_EBGP_REQUIRES_POLICY)
11427 && !bgp_inbound_policy_exists(
11428 peer, filter))
11429 vty_out(vty, " %12s",
11430 "(Policy)");
11431 else
11432 vty_out(vty,
11433 " %12u",
11434 peer->pcount
11435 [afi]
11436 [pfx_rcd_safi]);
11437 } else {
11438 vty_out(vty, " NoNeg");
11439 }
11440
11441 if (paf && PAF_SUBGRP(paf)) {
11442 if (CHECK_FLAG(
11443 bgp->flags,
11444 BGP_FLAG_EBGP_REQUIRES_POLICY)
11445 && !bgp_outbound_policy_exists(
11446 peer, filter))
11447 vty_out(vty, " %8s",
11448 "(Policy)");
11449 else
11450 vty_out(vty,
11451 " %8u",
11452 (PAF_SUBGRP(
11453 paf))
11454 ->scount);
11455 } else {
11456 vty_out(vty, " NoNeg");
11457 }
11458 } else {
11459 if (CHECK_FLAG(peer->flags,
11460 PEER_FLAG_SHUTDOWN)
11461 || CHECK_FLAG(peer->bgp->flags,
11462 BGP_FLAG_SHUTDOWN))
11463 vty_out(vty, " Idle (Admin)");
11464 else if (CHECK_FLAG(
11465 peer->sflags,
11466 PEER_STATUS_PREFIX_OVERFLOW))
11467 vty_out(vty, " Idle (PfxCt)");
11468 else
11469 vty_out(vty, " %12s",
11470 lookup_msg(bgp_status_msg,
11471 peer->status, NULL));
11472
11473 vty_out(vty, " %8u", 0);
11474 }
11475 /* Make sure `Desc` column is the lastest in
11476 * the output.
11477 */
11478 if (peer->desc)
11479 vty_out(vty, " %s",
11480 bgp_peer_description_stripped(
11481 peer->desc,
11482 show_wide ? 64 : 20));
11483 else
11484 vty_out(vty, " N/A");
11485 vty_out(vty, "\n");
11486 }
11487
11488 }
11489 }
11490
11491 if (use_json) {
11492 json_object_object_add(json, "peers", json_peers);
11493 json_object_int_add(json, "failedPeers", failed_count);
11494 json_object_int_add(json, "displayedPeers",
11495 count - filtered_count);
11496 json_object_int_add(json, "totalPeers", count);
11497 json_object_int_add(json, "dynamicPeers", dn_count);
11498
11499 if (!show_failed)
11500 bgp_show_bestpath_json(bgp, json);
11501
11502 vty_json(vty, json);
11503 } else {
11504 if (count) {
11505 if (filtered_count == count)
11506 vty_out(vty, "\n%% No matching neighbor\n");
11507 else {
11508 if (show_failed)
11509 vty_out(vty, "\nDisplayed neighbors %d",
11510 failed_count);
11511 else if (as_type != AS_UNSPECIFIED || as
11512 || fpeer || show_established)
11513 vty_out(vty, "\nDisplayed neighbors %d",
11514 count - filtered_count);
11515
11516 vty_out(vty, "\nTotal number of neighbors %d\n",
11517 count);
11518 }
11519 } else {
11520 vty_out(vty, "No %s neighbor is configured\n",
11521 get_afi_safi_str(afi, safi, false));
11522 }
11523
11524 if (dn_count) {
11525 vty_out(vty, "* - dynamic neighbor\n");
11526 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11527 dn_count, bgp->dynamic_neighbors_limit);
11528 }
11529 }
11530
11531 return CMD_SUCCESS;
11532 }
11533
11534 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11535 int safi, struct peer *fpeer, int as_type,
11536 as_t as, uint16_t show_flags)
11537 {
11538 int is_first = 1;
11539 int afi_wildcard = (afi == AFI_MAX);
11540 int safi_wildcard = (safi == SAFI_MAX);
11541 int is_wildcard = (afi_wildcard || safi_wildcard);
11542 bool nbr_output = false;
11543 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11544
11545 if (use_json && is_wildcard)
11546 vty_out(vty, "{\n");
11547 if (afi_wildcard)
11548 afi = 1; /* AFI_IP */
11549 while (afi < AFI_MAX) {
11550 if (safi_wildcard)
11551 safi = 1; /* SAFI_UNICAST */
11552 while (safi < SAFI_MAX) {
11553 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11554 nbr_output = true;
11555
11556 if (is_wildcard) {
11557 /*
11558 * So limit output to those afi/safi
11559 * pairs that
11560 * actualy have something interesting in
11561 * them
11562 */
11563 if (use_json) {
11564 if (!is_first)
11565 vty_out(vty, ",\n");
11566 else
11567 is_first = 0;
11568
11569 vty_out(vty, "\"%s\":",
11570 get_afi_safi_str(afi,
11571 safi,
11572 true));
11573 } else {
11574 vty_out(vty,
11575 "\n%s Summary (%s):\n",
11576 get_afi_safi_str(afi,
11577 safi,
11578 false),
11579 bgp->name_pretty);
11580 }
11581 }
11582 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11583 as_type, as, show_flags);
11584 }
11585 safi++;
11586 if (!safi_wildcard)
11587 safi = SAFI_MAX;
11588 }
11589 afi++;
11590 if (!afi_wildcard)
11591 afi = AFI_MAX;
11592 }
11593
11594 if (use_json && is_wildcard)
11595 vty_out(vty, "}\n");
11596 else if (!nbr_output) {
11597 if (use_json)
11598 vty_out(vty, "{}\n");
11599 else
11600 vty_out(vty, "%% No BGP neighbors found in %s\n",
11601 bgp->name_pretty);
11602 }
11603 }
11604
11605 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11606 safi_t safi,
11607 const char *neighbor,
11608 int as_type, as_t as,
11609 uint16_t show_flags)
11610 {
11611 struct listnode *node, *nnode;
11612 struct bgp *bgp;
11613 struct peer *fpeer = NULL;
11614 int is_first = 1;
11615 bool nbr_output = false;
11616 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11617
11618 if (use_json)
11619 vty_out(vty, "{\n");
11620
11621 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11622 nbr_output = true;
11623 if (use_json) {
11624 if (!is_first)
11625 vty_out(vty, ",\n");
11626 else
11627 is_first = 0;
11628
11629 vty_out(vty, "\"%s\":",
11630 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11631 ? VRF_DEFAULT_NAME
11632 : bgp->name);
11633 }
11634 if (neighbor) {
11635 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11636 use_json);
11637 if (!fpeer)
11638 continue;
11639 }
11640 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11641 as, show_flags);
11642 }
11643
11644 if (use_json)
11645 vty_out(vty, "}\n");
11646 else if (!nbr_output)
11647 vty_out(vty, "%% BGP instance not found\n");
11648 }
11649
11650 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11651 safi_t safi, const char *neighbor, int as_type,
11652 as_t as, uint16_t show_flags)
11653 {
11654 struct bgp *bgp;
11655 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11656 struct peer *fpeer = NULL;
11657
11658 if (name) {
11659 if (strmatch(name, "all")) {
11660 bgp_show_all_instances_summary_vty(vty, afi, safi,
11661 neighbor, as_type,
11662 as, show_flags);
11663 return CMD_SUCCESS;
11664 } else {
11665 bgp = bgp_lookup_by_name(name);
11666
11667 if (!bgp) {
11668 if (use_json)
11669 vty_out(vty, "{}\n");
11670 else
11671 vty_out(vty,
11672 "%% BGP instance not found\n");
11673 return CMD_WARNING;
11674 }
11675
11676 if (neighbor) {
11677 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11678 use_json);
11679 if (!fpeer)
11680 return CMD_WARNING;
11681 }
11682 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11683 as_type, as, show_flags);
11684 return CMD_SUCCESS;
11685 }
11686 }
11687
11688 bgp = bgp_get_default();
11689
11690 if (bgp) {
11691 if (neighbor) {
11692 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11693 use_json);
11694 if (!fpeer)
11695 return CMD_WARNING;
11696 }
11697 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11698 as, show_flags);
11699 } else {
11700 if (use_json)
11701 vty_out(vty, "{}\n");
11702 else
11703 vty_out(vty, "%% BGP instance not found\n");
11704 return CMD_WARNING;
11705 }
11706
11707 return CMD_SUCCESS;
11708 }
11709
11710 /* `show [ip] bgp summary' commands. */
11711 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11712 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11713 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11714 "]] [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]",
11715 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11716 BGP_SAFI_WITH_LABEL_HELP_STR
11717 "Display the entries for all address families\n"
11718 "Summary of BGP neighbor status\n"
11719 "Show only sessions in Established state\n"
11720 "Show only sessions not in Established state\n"
11721 "Show only the specified neighbor session\n"
11722 "Neighbor to display information about\n"
11723 "Neighbor to display information about\n"
11724 "Neighbor on BGP configured interface\n"
11725 "Show only the specified remote AS sessions\n"
11726 "AS number\n"
11727 "Internal (iBGP) AS sessions\n"
11728 "External (eBGP) AS sessions\n"
11729 "Shorten the information on BGP instances\n"
11730 "Increase table width for longer output\n" JSON_STR)
11731 {
11732 char *vrf = NULL;
11733 afi_t afi = AFI_MAX;
11734 safi_t safi = SAFI_MAX;
11735 as_t as = 0; /* 0 means AS filter not set */
11736 int as_type = AS_UNSPECIFIED;
11737 uint16_t show_flags = 0;
11738
11739 int idx = 0;
11740
11741 /* show [ip] bgp */
11742 if (!all && argv_find(argv, argc, "ip", &idx))
11743 afi = AFI_IP;
11744 /* [<vrf> VIEWVRFNAME] */
11745 if (argv_find(argv, argc, "vrf", &idx)) {
11746 vrf = argv[idx + 1]->arg;
11747 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11748 vrf = NULL;
11749 } else if (argv_find(argv, argc, "view", &idx))
11750 /* [<view> VIEWVRFNAME] */
11751 vrf = argv[idx + 1]->arg;
11752 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11753 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11754 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11755 }
11756
11757 if (argv_find(argv, argc, "failed", &idx))
11758 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11759
11760 if (argv_find(argv, argc, "established", &idx))
11761 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11762
11763 if (argv_find(argv, argc, "remote-as", &idx)) {
11764 if (argv[idx + 1]->arg[0] == 'i')
11765 as_type = AS_INTERNAL;
11766 else if (argv[idx + 1]->arg[0] == 'e')
11767 as_type = AS_EXTERNAL;
11768 else
11769 as = (as_t)atoi(argv[idx + 1]->arg);
11770 }
11771
11772 if (argv_find(argv, argc, "terse", &idx))
11773 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11774
11775 if (argv_find(argv, argc, "wide", &idx))
11776 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11777
11778 if (argv_find(argv, argc, "json", &idx))
11779 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11780
11781 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11782 show_flags);
11783 }
11784
11785 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11786 {
11787 if (for_json)
11788 return get_afi_safi_json_str(afi, safi);
11789 else
11790 return get_afi_safi_vty_str(afi, safi);
11791 }
11792
11793
11794 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11795 afi_t afi, safi_t safi,
11796 uint16_t adv_smcap, uint16_t adv_rmcap,
11797 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11798 bool use_json, json_object *json_pref)
11799 {
11800 /* Send-Mode */
11801 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11802 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11803 if (use_json) {
11804 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11805 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11806 json_object_string_add(json_pref, "sendMode",
11807 "advertisedAndReceived");
11808 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11809 json_object_string_add(json_pref, "sendMode",
11810 "advertised");
11811 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11812 json_object_string_add(json_pref, "sendMode",
11813 "received");
11814 } else {
11815 vty_out(vty, " Send-mode: ");
11816 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11817 vty_out(vty, "advertised");
11818 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11819 vty_out(vty, "%sreceived",
11820 CHECK_FLAG(p->af_cap[afi][safi],
11821 adv_smcap)
11822 ? ", "
11823 : "");
11824 vty_out(vty, "\n");
11825 }
11826 }
11827
11828 /* Receive-Mode */
11829 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11830 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11831 if (use_json) {
11832 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11833 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11834 json_object_string_add(json_pref, "recvMode",
11835 "advertisedAndReceived");
11836 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11837 json_object_string_add(json_pref, "recvMode",
11838 "advertised");
11839 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11840 json_object_string_add(json_pref, "recvMode",
11841 "received");
11842 } else {
11843 vty_out(vty, " Receive-mode: ");
11844 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11845 vty_out(vty, "advertised");
11846 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11847 vty_out(vty, "%sreceived",
11848 CHECK_FLAG(p->af_cap[afi][safi],
11849 adv_rmcap)
11850 ? ", "
11851 : "");
11852 vty_out(vty, "\n");
11853 }
11854 }
11855 }
11856
11857 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11858 struct peer *p,
11859 bool use_json,
11860 json_object *json)
11861 {
11862 bool rbit = false;
11863 bool nbit = false;
11864
11865 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11866 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11867 && (peer_established(p))) {
11868 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11869 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11870 }
11871
11872 if (use_json) {
11873 json_object_boolean_add(json, "rBit", rbit);
11874 json_object_boolean_add(json, "nBit", nbit);
11875 } else {
11876 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11877 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11878 }
11879 }
11880
11881 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11882 struct peer *peer,
11883 bool use_json,
11884 json_object *json)
11885 {
11886 const char *mode = "NotApplicable";
11887
11888 if (!use_json)
11889 vty_out(vty, "\n Remote GR Mode: ");
11890
11891 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11892 && (peer_established(peer))) {
11893
11894 if ((peer->nsf_af_count == 0)
11895 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11896
11897 mode = "Disable";
11898
11899 } else if (peer->nsf_af_count == 0
11900 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11901
11902 mode = "Helper";
11903
11904 } else if (peer->nsf_af_count != 0
11905 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11906
11907 mode = "Restart";
11908 }
11909 }
11910
11911 if (use_json) {
11912 json_object_string_add(json, "remoteGrMode", mode);
11913 } else
11914 vty_out(vty, mode, "\n");
11915 }
11916
11917 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11918 struct peer *p,
11919 bool use_json,
11920 json_object *json)
11921 {
11922 const char *mode = "Invalid";
11923
11924 if (!use_json)
11925 vty_out(vty, " Local GR Mode: ");
11926
11927 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11928 mode = "Helper";
11929 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11930 mode = "Restart";
11931 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11932 mode = "Disable";
11933 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11934 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11935 mode = "Helper*";
11936 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11937 mode = "Restart*";
11938 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11939 mode = "Disable*";
11940 else
11941 mode = "Invalid*";
11942 }
11943
11944 if (use_json) {
11945 json_object_string_add(json, "localGrMode", mode);
11946 } else {
11947 vty_out(vty, mode, "\n");
11948 }
11949 }
11950
11951 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11952 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11953 {
11954 afi_t afi;
11955 safi_t safi;
11956 json_object *json_afi_safi = NULL;
11957 json_object *json_timer = NULL;
11958 json_object *json_endofrib_status = NULL;
11959 bool eor_flag = false;
11960
11961 FOREACH_AFI_SAFI_NSF (afi, safi) {
11962 if (!peer->afc[afi][safi])
11963 continue;
11964
11965 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11966 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11967 continue;
11968
11969 if (use_json) {
11970 json_afi_safi = json_object_new_object();
11971 json_endofrib_status = json_object_new_object();
11972 json_timer = json_object_new_object();
11973 }
11974
11975 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11976 eor_flag = true;
11977 else
11978 eor_flag = false;
11979
11980 if (!use_json) {
11981 vty_out(vty, " %s:\n",
11982 get_afi_safi_str(afi, safi, false));
11983
11984 vty_out(vty, " F bit: ");
11985 }
11986
11987 if (peer->nsf[afi][safi] &&
11988 CHECK_FLAG(peer->af_cap[afi][safi],
11989 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11990
11991 if (use_json) {
11992 json_object_boolean_true_add(json_afi_safi,
11993 "fBit");
11994 } else
11995 vty_out(vty, "True\n");
11996 } else {
11997 if (use_json)
11998 json_object_boolean_false_add(json_afi_safi,
11999 "fBit");
12000 else
12001 vty_out(vty, "False\n");
12002 }
12003
12004 if (!use_json)
12005 vty_out(vty, " End-of-RIB sent: ");
12006
12007 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12008 PEER_STATUS_EOR_SEND)) {
12009 if (use_json) {
12010 json_object_boolean_true_add(
12011 json_endofrib_status, "endOfRibSend");
12012
12013 PRINT_EOR_JSON(eor_flag);
12014 } else {
12015 vty_out(vty, "Yes\n");
12016 vty_out(vty,
12017 " End-of-RIB sent after update: ");
12018
12019 PRINT_EOR(eor_flag);
12020 }
12021 } else {
12022 if (use_json) {
12023 json_object_boolean_false_add(
12024 json_endofrib_status, "endOfRibSend");
12025 json_object_boolean_false_add(
12026 json_endofrib_status,
12027 "endOfRibSentAfterUpdate");
12028 } else {
12029 vty_out(vty, "No\n");
12030 vty_out(vty,
12031 " End-of-RIB sent after update: ");
12032 vty_out(vty, "No\n");
12033 }
12034 }
12035
12036 if (!use_json)
12037 vty_out(vty, " End-of-RIB received: ");
12038
12039 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12040 PEER_STATUS_EOR_RECEIVED)) {
12041 if (use_json)
12042 json_object_boolean_true_add(
12043 json_endofrib_status, "endOfRibRecv");
12044 else
12045 vty_out(vty, "Yes\n");
12046 } else {
12047 if (use_json)
12048 json_object_boolean_false_add(
12049 json_endofrib_status, "endOfRibRecv");
12050 else
12051 vty_out(vty, "No\n");
12052 }
12053
12054 if (use_json) {
12055 json_object_int_add(json_timer, "stalePathTimer",
12056 peer->bgp->stalepath_time);
12057
12058 if (peer->t_gr_stale != NULL) {
12059 json_object_int_add(json_timer,
12060 "stalePathTimerRemaining",
12061 thread_timer_remain_second(
12062 peer->t_gr_stale));
12063 }
12064
12065 /* Display Configured Selection
12066 * Deferral only when when
12067 * Gr mode is enabled.
12068 */
12069 if (CHECK_FLAG(peer->flags,
12070 PEER_FLAG_GRACEFUL_RESTART)) {
12071 json_object_int_add(json_timer,
12072 "selectionDeferralTimer",
12073 peer->bgp->stalepath_time);
12074 }
12075
12076 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12077 NULL) {
12078
12079 json_object_int_add(
12080 json_timer,
12081 "selectionDeferralTimerRemaining",
12082 thread_timer_remain_second(
12083 peer->bgp->gr_info[afi][safi]
12084 .t_select_deferral));
12085 }
12086 } else {
12087 vty_out(vty, " Timers:\n");
12088 vty_out(vty,
12089 " Configured Stale Path Time(sec): %u\n",
12090 peer->bgp->stalepath_time);
12091
12092 if (peer->t_gr_stale != NULL)
12093 vty_out(vty,
12094 " Stale Path Remaining(sec): %ld\n",
12095 thread_timer_remain_second(
12096 peer->t_gr_stale));
12097 /* Display Configured Selection
12098 * Deferral only when when
12099 * Gr mode is enabled.
12100 */
12101 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12102 vty_out(vty,
12103 " Configured Selection Deferral Time(sec): %u\n",
12104 peer->bgp->select_defer_time);
12105
12106 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12107 NULL)
12108 vty_out(vty,
12109 " Selection Deferral Time Remaining(sec): %ld\n",
12110 thread_timer_remain_second(
12111 peer->bgp->gr_info[afi][safi]
12112 .t_select_deferral));
12113 }
12114 if (use_json) {
12115 json_object_object_add(json_afi_safi, "endOfRibStatus",
12116 json_endofrib_status);
12117 json_object_object_add(json_afi_safi, "timers",
12118 json_timer);
12119 json_object_object_add(
12120 json, get_afi_safi_str(afi, safi, true),
12121 json_afi_safi);
12122 }
12123 }
12124 }
12125
12126 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12127 struct peer *p,
12128 bool use_json,
12129 json_object *json)
12130 {
12131 if (use_json) {
12132 json_object *json_timer = NULL;
12133
12134 json_timer = json_object_new_object();
12135
12136 json_object_int_add(json_timer, "configuredRestartTimer",
12137 p->bgp->restart_time);
12138
12139 json_object_int_add(json_timer, "receivedRestartTimer",
12140 p->v_gr_restart);
12141
12142 if (p->t_gr_restart != NULL)
12143 json_object_int_add(
12144 json_timer, "restartTimerRemaining",
12145 thread_timer_remain_second(p->t_gr_restart));
12146
12147 json_object_object_add(json, "timers", json_timer);
12148 } else {
12149
12150 vty_out(vty, " Timers:\n");
12151 vty_out(vty, " Configured Restart Time(sec): %u\n",
12152 p->bgp->restart_time);
12153
12154 vty_out(vty, " Received Restart Time(sec): %u\n",
12155 p->v_gr_restart);
12156 if (p->t_gr_restart != NULL)
12157 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12158 thread_timer_remain_second(p->t_gr_restart));
12159 if (p->t_gr_restart != NULL) {
12160 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12161 thread_timer_remain_second(p->t_gr_restart));
12162 }
12163 }
12164 }
12165
12166 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12167 bool use_json, json_object *json)
12168 {
12169 char dn_flag[2] = {0};
12170 /* '*' + v6 address of neighbor */
12171 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12172
12173 if (!p->conf_if && peer_dynamic_neighbor(p))
12174 dn_flag[0] = '*';
12175
12176 if (p->conf_if) {
12177 if (use_json)
12178 json_object_string_addf(json, "neighborAddr", "%pSU",
12179 &p->su);
12180 else
12181 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12182 &p->su);
12183 } else {
12184 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12185 p->host);
12186
12187 if (use_json)
12188 json_object_string_add(json, "neighborAddr",
12189 neighborAddr);
12190 else
12191 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12192 }
12193
12194 /* more gr info in new format */
12195 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12196 }
12197
12198 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12199 safi_t safi, bool use_json,
12200 json_object *json_neigh)
12201 {
12202 struct bgp_filter *filter;
12203 struct peer_af *paf;
12204 char orf_pfx_name[BUFSIZ];
12205 int orf_pfx_count;
12206 json_object *json_af = NULL;
12207 json_object *json_prefA = NULL;
12208 json_object *json_prefB = NULL;
12209 json_object *json_addr = NULL;
12210 json_object *json_advmap = NULL;
12211
12212 if (use_json) {
12213 json_addr = json_object_new_object();
12214 json_af = json_object_new_object();
12215 filter = &p->filter[afi][safi];
12216
12217 if (peer_group_active(p))
12218 json_object_string_add(json_addr, "peerGroupMember",
12219 p->group->name);
12220
12221 paf = peer_af_find(p, afi, safi);
12222 if (paf && PAF_SUBGRP(paf)) {
12223 json_object_int_add(json_addr, "updateGroupId",
12224 PAF_UPDGRP(paf)->id);
12225 json_object_int_add(json_addr, "subGroupId",
12226 PAF_SUBGRP(paf)->id);
12227 json_object_int_add(json_addr, "packetQueueLength",
12228 bpacket_queue_virtual_length(paf));
12229 }
12230
12231 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12232 || CHECK_FLAG(p->af_cap[afi][safi],
12233 PEER_CAP_ORF_PREFIX_SM_RCV)
12234 || CHECK_FLAG(p->af_cap[afi][safi],
12235 PEER_CAP_ORF_PREFIX_RM_ADV)
12236 || CHECK_FLAG(p->af_cap[afi][safi],
12237 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12238 json_object_int_add(json_af, "orfType",
12239 ORF_TYPE_PREFIX);
12240 json_prefA = json_object_new_object();
12241 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12242 PEER_CAP_ORF_PREFIX_SM_ADV,
12243 PEER_CAP_ORF_PREFIX_RM_ADV,
12244 PEER_CAP_ORF_PREFIX_SM_RCV,
12245 PEER_CAP_ORF_PREFIX_RM_RCV,
12246 use_json, json_prefA);
12247 json_object_object_add(json_af, "orfPrefixList",
12248 json_prefA);
12249 }
12250
12251 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12252 || CHECK_FLAG(p->af_cap[afi][safi],
12253 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12254 || CHECK_FLAG(p->af_cap[afi][safi],
12255 PEER_CAP_ORF_PREFIX_RM_ADV)
12256 || CHECK_FLAG(p->af_cap[afi][safi],
12257 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12258 json_object_int_add(json_af, "orfOldType",
12259 ORF_TYPE_PREFIX_OLD);
12260 json_prefB = json_object_new_object();
12261 bgp_show_peer_afi_orf_cap(
12262 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12263 PEER_CAP_ORF_PREFIX_RM_ADV,
12264 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12265 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12266 json_prefB);
12267 json_object_object_add(json_af, "orfOldPrefixList",
12268 json_prefB);
12269 }
12270
12271 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12272 || CHECK_FLAG(p->af_cap[afi][safi],
12273 PEER_CAP_ORF_PREFIX_SM_RCV)
12274 || CHECK_FLAG(p->af_cap[afi][safi],
12275 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12276 || CHECK_FLAG(p->af_cap[afi][safi],
12277 PEER_CAP_ORF_PREFIX_RM_ADV)
12278 || CHECK_FLAG(p->af_cap[afi][safi],
12279 PEER_CAP_ORF_PREFIX_RM_RCV)
12280 || CHECK_FLAG(p->af_cap[afi][safi],
12281 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12282 json_object_object_add(json_addr, "afDependentCap",
12283 json_af);
12284 else
12285 json_object_free(json_af);
12286
12287 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12288 p->host, afi, safi);
12289 orf_pfx_count = prefix_bgp_show_prefix_list(
12290 NULL, afi, orf_pfx_name, use_json);
12291
12292 if (CHECK_FLAG(p->af_sflags[afi][safi],
12293 PEER_STATUS_ORF_PREFIX_SEND)
12294 || orf_pfx_count) {
12295 if (CHECK_FLAG(p->af_sflags[afi][safi],
12296 PEER_STATUS_ORF_PREFIX_SEND))
12297 json_object_boolean_true_add(json_neigh,
12298 "orfSent");
12299 if (orf_pfx_count)
12300 json_object_int_add(json_addr, "orfRecvCounter",
12301 orf_pfx_count);
12302 }
12303 if (CHECK_FLAG(p->af_sflags[afi][safi],
12304 PEER_STATUS_ORF_WAIT_REFRESH))
12305 json_object_string_add(
12306 json_addr, "orfFirstUpdate",
12307 "deferredUntilORFOrRouteRefreshRecvd");
12308
12309 if (CHECK_FLAG(p->af_flags[afi][safi],
12310 PEER_FLAG_REFLECTOR_CLIENT))
12311 json_object_boolean_true_add(json_addr,
12312 "routeReflectorClient");
12313 if (CHECK_FLAG(p->af_flags[afi][safi],
12314 PEER_FLAG_RSERVER_CLIENT))
12315 json_object_boolean_true_add(json_addr,
12316 "routeServerClient");
12317 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12318 json_object_boolean_true_add(json_addr,
12319 "inboundSoftConfigPermit");
12320
12321 if (CHECK_FLAG(p->af_flags[afi][safi],
12322 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12323 json_object_boolean_true_add(
12324 json_addr,
12325 "privateAsNumsAllReplacedInUpdatesToNbr");
12326 else if (CHECK_FLAG(p->af_flags[afi][safi],
12327 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12328 json_object_boolean_true_add(
12329 json_addr,
12330 "privateAsNumsReplacedInUpdatesToNbr");
12331 else if (CHECK_FLAG(p->af_flags[afi][safi],
12332 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12333 json_object_boolean_true_add(
12334 json_addr,
12335 "privateAsNumsAllRemovedInUpdatesToNbr");
12336 else if (CHECK_FLAG(p->af_flags[afi][safi],
12337 PEER_FLAG_REMOVE_PRIVATE_AS))
12338 json_object_boolean_true_add(
12339 json_addr,
12340 "privateAsNumsRemovedInUpdatesToNbr");
12341
12342 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12343 if (CHECK_FLAG(p->af_flags[afi][safi],
12344 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12345 json_object_boolean_true_add(json_addr,
12346 "allowAsInOrigin");
12347 else
12348 json_object_int_add(json_addr, "allowAsInCount",
12349 p->allowas_in[afi][safi]);
12350 }
12351
12352 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12353 json_object_boolean_true_add(
12354 json_addr,
12355 bgp_addpath_names(p->addpath_type[afi][safi])
12356 ->type_json_name);
12357
12358 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12359 json_object_string_add(json_addr,
12360 "overrideASNsInOutboundUpdates",
12361 "ifAspathEqualRemoteAs");
12362
12363 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12364 || CHECK_FLAG(p->af_flags[afi][safi],
12365 PEER_FLAG_FORCE_NEXTHOP_SELF))
12366 json_object_boolean_true_add(json_addr,
12367 "routerAlwaysNextHop");
12368 if (CHECK_FLAG(p->af_flags[afi][safi],
12369 PEER_FLAG_AS_PATH_UNCHANGED))
12370 json_object_boolean_true_add(
12371 json_addr, "unchangedAsPathPropogatedToNbr");
12372 if (CHECK_FLAG(p->af_flags[afi][safi],
12373 PEER_FLAG_NEXTHOP_UNCHANGED))
12374 json_object_boolean_true_add(
12375 json_addr, "unchangedNextHopPropogatedToNbr");
12376 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12377 json_object_boolean_true_add(
12378 json_addr, "unchangedMedPropogatedToNbr");
12379 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12380 || CHECK_FLAG(p->af_flags[afi][safi],
12381 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12382 if (CHECK_FLAG(p->af_flags[afi][safi],
12383 PEER_FLAG_SEND_COMMUNITY)
12384 && CHECK_FLAG(p->af_flags[afi][safi],
12385 PEER_FLAG_SEND_EXT_COMMUNITY))
12386 json_object_string_add(json_addr,
12387 "commAttriSentToNbr",
12388 "extendedAndStandard");
12389 else if (CHECK_FLAG(p->af_flags[afi][safi],
12390 PEER_FLAG_SEND_EXT_COMMUNITY))
12391 json_object_string_add(json_addr,
12392 "commAttriSentToNbr",
12393 "extended");
12394 else
12395 json_object_string_add(json_addr,
12396 "commAttriSentToNbr",
12397 "standard");
12398 }
12399 if (CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_DEFAULT_ORIGINATE)) {
12401 if (p->default_rmap[afi][safi].name)
12402 json_object_string_add(
12403 json_addr, "defaultRouteMap",
12404 p->default_rmap[afi][safi].name);
12405
12406 if (paf && PAF_SUBGRP(paf)
12407 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12408 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12409 json_object_boolean_true_add(json_addr,
12410 "defaultSent");
12411 else
12412 json_object_boolean_true_add(json_addr,
12413 "defaultNotSent");
12414 }
12415
12416 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12417 if (is_evpn_enabled())
12418 json_object_boolean_true_add(
12419 json_addr, "advertiseAllVnis");
12420 }
12421
12422 if (filter->plist[FILTER_IN].name
12423 || filter->dlist[FILTER_IN].name
12424 || filter->aslist[FILTER_IN].name
12425 || filter->map[RMAP_IN].name)
12426 json_object_boolean_true_add(json_addr,
12427 "inboundPathPolicyConfig");
12428 if (filter->plist[FILTER_OUT].name
12429 || filter->dlist[FILTER_OUT].name
12430 || filter->aslist[FILTER_OUT].name
12431 || filter->map[RMAP_OUT].name || filter->usmap.name)
12432 json_object_boolean_true_add(
12433 json_addr, "outboundPathPolicyConfig");
12434
12435 /* prefix-list */
12436 if (filter->plist[FILTER_IN].name)
12437 json_object_string_add(json_addr,
12438 "incomingUpdatePrefixFilterList",
12439 filter->plist[FILTER_IN].name);
12440 if (filter->plist[FILTER_OUT].name)
12441 json_object_string_add(json_addr,
12442 "outgoingUpdatePrefixFilterList",
12443 filter->plist[FILTER_OUT].name);
12444
12445 /* distribute-list */
12446 if (filter->dlist[FILTER_IN].name)
12447 json_object_string_add(
12448 json_addr, "incomingUpdateNetworkFilterList",
12449 filter->dlist[FILTER_IN].name);
12450 if (filter->dlist[FILTER_OUT].name)
12451 json_object_string_add(
12452 json_addr, "outgoingUpdateNetworkFilterList",
12453 filter->dlist[FILTER_OUT].name);
12454
12455 /* filter-list. */
12456 if (filter->aslist[FILTER_IN].name)
12457 json_object_string_add(json_addr,
12458 "incomingUpdateAsPathFilterList",
12459 filter->aslist[FILTER_IN].name);
12460 if (filter->aslist[FILTER_OUT].name)
12461 json_object_string_add(json_addr,
12462 "outgoingUpdateAsPathFilterList",
12463 filter->aslist[FILTER_OUT].name);
12464
12465 /* route-map. */
12466 if (filter->map[RMAP_IN].name)
12467 json_object_string_add(
12468 json_addr, "routeMapForIncomingAdvertisements",
12469 filter->map[RMAP_IN].name);
12470 if (filter->map[RMAP_OUT].name)
12471 json_object_string_add(
12472 json_addr, "routeMapForOutgoingAdvertisements",
12473 filter->map[RMAP_OUT].name);
12474
12475 /* ebgp-requires-policy (inbound) */
12476 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12477 && !bgp_inbound_policy_exists(p, filter))
12478 json_object_string_add(
12479 json_addr, "inboundEbgpRequiresPolicy",
12480 "Inbound updates discarded due to missing policy");
12481
12482 /* ebgp-requires-policy (outbound) */
12483 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12484 && (!bgp_outbound_policy_exists(p, filter)))
12485 json_object_string_add(
12486 json_addr, "outboundEbgpRequiresPolicy",
12487 "Outbound updates discarded due to missing policy");
12488
12489 /* unsuppress-map */
12490 if (filter->usmap.name)
12491 json_object_string_add(json_addr,
12492 "selectiveUnsuppressRouteMap",
12493 filter->usmap.name);
12494
12495 /* advertise-map */
12496 if (filter->advmap.aname) {
12497 json_advmap = json_object_new_object();
12498 json_object_string_add(json_advmap, "condition",
12499 filter->advmap.condition
12500 ? "EXIST"
12501 : "NON_EXIST");
12502 json_object_string_add(json_advmap, "conditionMap",
12503 filter->advmap.cname);
12504 json_object_string_add(json_advmap, "advertiseMap",
12505 filter->advmap.aname);
12506 json_object_string_add(
12507 json_advmap, "advertiseStatus",
12508 filter->advmap.update_type ==
12509 UPDATE_TYPE_ADVERTISE
12510 ? "Advertise"
12511 : "Withdraw");
12512 json_object_object_add(json_addr, "advertiseMap",
12513 json_advmap);
12514 }
12515
12516 /* Receive prefix count */
12517 json_object_int_add(json_addr, "acceptedPrefixCounter",
12518 p->pcount[afi][safi]);
12519 if (paf && PAF_SUBGRP(paf))
12520 json_object_int_add(json_addr, "sentPrefixCounter",
12521 (PAF_SUBGRP(paf))->scount);
12522
12523 /* Maximum prefix */
12524 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12525 json_object_int_add(json_addr, "prefixOutAllowedMax",
12526 p->pmax_out[afi][safi]);
12527
12528 /* Maximum prefix */
12529 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12530 json_object_int_add(json_addr, "prefixAllowedMax",
12531 p->pmax[afi][safi]);
12532 if (CHECK_FLAG(p->af_flags[afi][safi],
12533 PEER_FLAG_MAX_PREFIX_WARNING))
12534 json_object_boolean_true_add(
12535 json_addr, "prefixAllowedMaxWarning");
12536 json_object_int_add(json_addr,
12537 "prefixAllowedWarningThresh",
12538 p->pmax_threshold[afi][safi]);
12539 if (p->pmax_restart[afi][safi])
12540 json_object_int_add(
12541 json_addr,
12542 "prefixAllowedRestartIntervalMsecs",
12543 p->pmax_restart[afi][safi] * 60000);
12544 }
12545 json_object_object_add(json_neigh,
12546 get_afi_safi_str(afi, safi, true),
12547 json_addr);
12548
12549 } else {
12550 filter = &p->filter[afi][safi];
12551
12552 vty_out(vty, " For address family: %s\n",
12553 get_afi_safi_str(afi, safi, false));
12554
12555 if (peer_group_active(p))
12556 vty_out(vty, " %s peer-group member\n",
12557 p->group->name);
12558
12559 paf = peer_af_find(p, afi, safi);
12560 if (paf && PAF_SUBGRP(paf)) {
12561 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12562 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12563 vty_out(vty, " Packet Queue length %d\n",
12564 bpacket_queue_virtual_length(paf));
12565 } else {
12566 vty_out(vty, " Not part of any update group\n");
12567 }
12568 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12569 || CHECK_FLAG(p->af_cap[afi][safi],
12570 PEER_CAP_ORF_PREFIX_SM_RCV)
12571 || CHECK_FLAG(p->af_cap[afi][safi],
12572 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12573 || CHECK_FLAG(p->af_cap[afi][safi],
12574 PEER_CAP_ORF_PREFIX_RM_ADV)
12575 || CHECK_FLAG(p->af_cap[afi][safi],
12576 PEER_CAP_ORF_PREFIX_RM_RCV)
12577 || CHECK_FLAG(p->af_cap[afi][safi],
12578 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12579 vty_out(vty, " AF-dependant capabilities:\n");
12580
12581 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12582 || CHECK_FLAG(p->af_cap[afi][safi],
12583 PEER_CAP_ORF_PREFIX_SM_RCV)
12584 || CHECK_FLAG(p->af_cap[afi][safi],
12585 PEER_CAP_ORF_PREFIX_RM_ADV)
12586 || CHECK_FLAG(p->af_cap[afi][safi],
12587 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12588 vty_out(vty,
12589 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12590 ORF_TYPE_PREFIX);
12591 bgp_show_peer_afi_orf_cap(
12592 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12593 PEER_CAP_ORF_PREFIX_RM_ADV,
12594 PEER_CAP_ORF_PREFIX_SM_RCV,
12595 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12596 }
12597 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12598 || CHECK_FLAG(p->af_cap[afi][safi],
12599 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12600 || CHECK_FLAG(p->af_cap[afi][safi],
12601 PEER_CAP_ORF_PREFIX_RM_ADV)
12602 || CHECK_FLAG(p->af_cap[afi][safi],
12603 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12604 vty_out(vty,
12605 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12606 ORF_TYPE_PREFIX_OLD);
12607 bgp_show_peer_afi_orf_cap(
12608 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12609 PEER_CAP_ORF_PREFIX_RM_ADV,
12610 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12611 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12612 }
12613
12614 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12615 p->host, afi, safi);
12616 orf_pfx_count = prefix_bgp_show_prefix_list(
12617 NULL, afi, orf_pfx_name, use_json);
12618
12619 if (CHECK_FLAG(p->af_sflags[afi][safi],
12620 PEER_STATUS_ORF_PREFIX_SEND)
12621 || orf_pfx_count) {
12622 vty_out(vty, " Outbound Route Filter (ORF):");
12623 if (CHECK_FLAG(p->af_sflags[afi][safi],
12624 PEER_STATUS_ORF_PREFIX_SEND))
12625 vty_out(vty, " sent;");
12626 if (orf_pfx_count)
12627 vty_out(vty, " received (%d entries)",
12628 orf_pfx_count);
12629 vty_out(vty, "\n");
12630 }
12631 if (CHECK_FLAG(p->af_sflags[afi][safi],
12632 PEER_STATUS_ORF_WAIT_REFRESH))
12633 vty_out(vty,
12634 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12635
12636 if (CHECK_FLAG(p->af_flags[afi][safi],
12637 PEER_FLAG_REFLECTOR_CLIENT))
12638 vty_out(vty, " Route-Reflector Client\n");
12639 if (CHECK_FLAG(p->af_flags[afi][safi],
12640 PEER_FLAG_RSERVER_CLIENT))
12641 vty_out(vty, " Route-Server Client\n");
12642
12643 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12644 vty_out(vty, " ORR group (configured) : %s\n",
12645 p->orr_group_name[afi][safi]);
12646
12647 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12648 vty_out(vty,
12649 " Inbound soft reconfiguration allowed\n");
12650
12651 if (CHECK_FLAG(p->af_flags[afi][safi],
12652 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12653 vty_out(vty,
12654 " Private AS numbers (all) replaced in updates to this neighbor\n");
12655 else if (CHECK_FLAG(p->af_flags[afi][safi],
12656 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12657 vty_out(vty,
12658 " Private AS numbers replaced in updates to this neighbor\n");
12659 else if (CHECK_FLAG(p->af_flags[afi][safi],
12660 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12661 vty_out(vty,
12662 " Private AS numbers (all) removed in updates to this neighbor\n");
12663 else if (CHECK_FLAG(p->af_flags[afi][safi],
12664 PEER_FLAG_REMOVE_PRIVATE_AS))
12665 vty_out(vty,
12666 " Private AS numbers removed in updates to this neighbor\n");
12667
12668 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12669 if (CHECK_FLAG(p->af_flags[afi][safi],
12670 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12671 vty_out(vty,
12672 " Local AS allowed as path origin\n");
12673 else
12674 vty_out(vty,
12675 " Local AS allowed in path, %d occurrences\n",
12676 p->allowas_in[afi][safi]);
12677 }
12678
12679 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12680 vty_out(vty, " %s\n",
12681 bgp_addpath_names(p->addpath_type[afi][safi])
12682 ->human_description);
12683
12684 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12685 vty_out(vty,
12686 " Override ASNs in outbound updates if aspath equals remote-as\n");
12687
12688 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12689 || CHECK_FLAG(p->af_flags[afi][safi],
12690 PEER_FLAG_FORCE_NEXTHOP_SELF))
12691 vty_out(vty, " NEXT_HOP is always this router\n");
12692 if (CHECK_FLAG(p->af_flags[afi][safi],
12693 PEER_FLAG_AS_PATH_UNCHANGED))
12694 vty_out(vty,
12695 " AS_PATH is propagated unchanged to this neighbor\n");
12696 if (CHECK_FLAG(p->af_flags[afi][safi],
12697 PEER_FLAG_NEXTHOP_UNCHANGED))
12698 vty_out(vty,
12699 " NEXT_HOP is propagated unchanged to this neighbor\n");
12700 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12701 vty_out(vty,
12702 " MED is propagated unchanged to this neighbor\n");
12703 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12704 || CHECK_FLAG(p->af_flags[afi][safi],
12705 PEER_FLAG_SEND_EXT_COMMUNITY)
12706 || CHECK_FLAG(p->af_flags[afi][safi],
12707 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12708 vty_out(vty,
12709 " Community attribute sent to this neighbor");
12710 if (CHECK_FLAG(p->af_flags[afi][safi],
12711 PEER_FLAG_SEND_COMMUNITY)
12712 && CHECK_FLAG(p->af_flags[afi][safi],
12713 PEER_FLAG_SEND_EXT_COMMUNITY)
12714 && CHECK_FLAG(p->af_flags[afi][safi],
12715 PEER_FLAG_SEND_LARGE_COMMUNITY))
12716 vty_out(vty, "(all)\n");
12717 else if (CHECK_FLAG(p->af_flags[afi][safi],
12718 PEER_FLAG_SEND_LARGE_COMMUNITY))
12719 vty_out(vty, "(large)\n");
12720 else if (CHECK_FLAG(p->af_flags[afi][safi],
12721 PEER_FLAG_SEND_EXT_COMMUNITY))
12722 vty_out(vty, "(extended)\n");
12723 else
12724 vty_out(vty, "(standard)\n");
12725 }
12726 if (CHECK_FLAG(p->af_flags[afi][safi],
12727 PEER_FLAG_DEFAULT_ORIGINATE)) {
12728 vty_out(vty, " Default information originate,");
12729
12730 if (p->default_rmap[afi][safi].name)
12731 vty_out(vty, " default route-map %s%s,",
12732 p->default_rmap[afi][safi].map ? "*"
12733 : "",
12734 p->default_rmap[afi][safi].name);
12735 if (paf && PAF_SUBGRP(paf)
12736 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12737 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12738 vty_out(vty, " default sent\n");
12739 else
12740 vty_out(vty, " default not sent\n");
12741 }
12742
12743 /* advertise-vni-all */
12744 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12745 if (is_evpn_enabled())
12746 vty_out(vty, " advertise-all-vni\n");
12747 }
12748
12749 if (filter->plist[FILTER_IN].name
12750 || filter->dlist[FILTER_IN].name
12751 || filter->aslist[FILTER_IN].name
12752 || filter->map[RMAP_IN].name)
12753 vty_out(vty, " Inbound path policy configured\n");
12754 if (filter->plist[FILTER_OUT].name
12755 || filter->dlist[FILTER_OUT].name
12756 || filter->aslist[FILTER_OUT].name
12757 || filter->map[RMAP_OUT].name || filter->usmap.name)
12758 vty_out(vty, " Outbound path policy configured\n");
12759
12760 /* prefix-list */
12761 if (filter->plist[FILTER_IN].name)
12762 vty_out(vty,
12763 " Incoming update prefix filter list is %s%s\n",
12764 filter->plist[FILTER_IN].plist ? "*" : "",
12765 filter->plist[FILTER_IN].name);
12766 if (filter->plist[FILTER_OUT].name)
12767 vty_out(vty,
12768 " Outgoing update prefix filter list is %s%s\n",
12769 filter->plist[FILTER_OUT].plist ? "*" : "",
12770 filter->plist[FILTER_OUT].name);
12771
12772 /* distribute-list */
12773 if (filter->dlist[FILTER_IN].name)
12774 vty_out(vty,
12775 " Incoming update network filter list is %s%s\n",
12776 filter->dlist[FILTER_IN].alist ? "*" : "",
12777 filter->dlist[FILTER_IN].name);
12778 if (filter->dlist[FILTER_OUT].name)
12779 vty_out(vty,
12780 " Outgoing update network filter list is %s%s\n",
12781 filter->dlist[FILTER_OUT].alist ? "*" : "",
12782 filter->dlist[FILTER_OUT].name);
12783
12784 /* filter-list. */
12785 if (filter->aslist[FILTER_IN].name)
12786 vty_out(vty,
12787 " Incoming update AS path filter list is %s%s\n",
12788 filter->aslist[FILTER_IN].aslist ? "*" : "",
12789 filter->aslist[FILTER_IN].name);
12790 if (filter->aslist[FILTER_OUT].name)
12791 vty_out(vty,
12792 " Outgoing update AS path filter list is %s%s\n",
12793 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12794 filter->aslist[FILTER_OUT].name);
12795
12796 /* route-map. */
12797 if (filter->map[RMAP_IN].name)
12798 vty_out(vty,
12799 " Route map for incoming advertisements is %s%s\n",
12800 filter->map[RMAP_IN].map ? "*" : "",
12801 filter->map[RMAP_IN].name);
12802 if (filter->map[RMAP_OUT].name)
12803 vty_out(vty,
12804 " Route map for outgoing advertisements is %s%s\n",
12805 filter->map[RMAP_OUT].map ? "*" : "",
12806 filter->map[RMAP_OUT].name);
12807
12808 /* ebgp-requires-policy (inbound) */
12809 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12810 && !bgp_inbound_policy_exists(p, filter))
12811 vty_out(vty,
12812 " Inbound updates discarded due to missing policy\n");
12813
12814 /* ebgp-requires-policy (outbound) */
12815 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12816 && !bgp_outbound_policy_exists(p, filter))
12817 vty_out(vty,
12818 " Outbound updates discarded due to missing policy\n");
12819
12820 /* unsuppress-map */
12821 if (filter->usmap.name)
12822 vty_out(vty,
12823 " Route map for selective unsuppress is %s%s\n",
12824 filter->usmap.map ? "*" : "",
12825 filter->usmap.name);
12826
12827 /* advertise-map */
12828 if (filter->advmap.aname && filter->advmap.cname)
12829 vty_out(vty,
12830 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12831 filter->advmap.condition ? "EXIST"
12832 : "NON_EXIST",
12833 filter->advmap.cmap ? "*" : "",
12834 filter->advmap.cname,
12835 filter->advmap.amap ? "*" : "",
12836 filter->advmap.aname,
12837 filter->advmap.update_type ==
12838 UPDATE_TYPE_ADVERTISE
12839 ? "Advertise"
12840 : "Withdraw");
12841
12842 /* Receive prefix count */
12843 vty_out(vty, " %u accepted prefixes\n",
12844 p->pcount[afi][safi]);
12845
12846 /* maximum-prefix-out */
12847 if (CHECK_FLAG(p->af_flags[afi][safi],
12848 PEER_FLAG_MAX_PREFIX_OUT))
12849 vty_out(vty,
12850 " Maximum allowed prefixes sent %u\n",
12851 p->pmax_out[afi][safi]);
12852
12853 /* Maximum prefix */
12854 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12855 vty_out(vty,
12856 " Maximum prefixes allowed %u%s\n",
12857 p->pmax[afi][safi],
12858 CHECK_FLAG(p->af_flags[afi][safi],
12859 PEER_FLAG_MAX_PREFIX_WARNING)
12860 ? " (warning-only)"
12861 : "");
12862 vty_out(vty, " Threshold for warning message %d%%",
12863 p->pmax_threshold[afi][safi]);
12864 if (p->pmax_restart[afi][safi])
12865 vty_out(vty, ", restart interval %d min",
12866 p->pmax_restart[afi][safi]);
12867 vty_out(vty, "\n");
12868 }
12869
12870 vty_out(vty, "\n");
12871 }
12872 }
12873
12874 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12875 json_object *json)
12876 {
12877 struct bgp *bgp;
12878 char timebuf[BGP_UPTIME_LEN];
12879 char dn_flag[2];
12880 afi_t afi;
12881 safi_t safi;
12882 uint16_t i;
12883 uint8_t *msg;
12884 json_object *json_neigh = NULL;
12885 time_t epoch_tbuf;
12886 uint32_t sync_tcp_mss;
12887
12888 bgp = p->bgp;
12889
12890 if (use_json)
12891 json_neigh = json_object_new_object();
12892
12893 memset(dn_flag, '\0', sizeof(dn_flag));
12894 if (!p->conf_if && peer_dynamic_neighbor(p))
12895 dn_flag[0] = '*';
12896
12897 if (!use_json) {
12898 if (p->conf_if) /* Configured interface name. */
12899 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12900 &p->su);
12901 else /* Configured IP address. */
12902 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12903 p->host);
12904 }
12905
12906 if (use_json) {
12907 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12908 json_object_string_add(json_neigh, "bgpNeighborAddr",
12909 "none");
12910 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12911 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12912 "%pSU", &p->su);
12913
12914 json_object_int_add(json_neigh, "remoteAs", p->as);
12915
12916 if (p->change_local_as)
12917 json_object_int_add(json_neigh, "localAs",
12918 p->change_local_as);
12919 else
12920 json_object_int_add(json_neigh, "localAs", p->local_as);
12921
12922 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12923 json_object_boolean_true_add(json_neigh,
12924 "localAsNoPrepend");
12925
12926 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12927 json_object_boolean_true_add(json_neigh,
12928 "localAsReplaceAs");
12929 } else {
12930 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12931 || (p->as_type == AS_INTERNAL))
12932 vty_out(vty, "remote AS %u, ", p->as);
12933 else
12934 vty_out(vty, "remote AS Unspecified, ");
12935 vty_out(vty, "local AS %u%s%s, ",
12936 p->change_local_as ? p->change_local_as : p->local_as,
12937 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12938 ? " no-prepend"
12939 : "",
12940 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12941 ? " replace-as"
12942 : "");
12943 }
12944 /* peer type internal or confed-internal */
12945 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12946 if (use_json) {
12947 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12948 json_object_boolean_true_add(
12949 json_neigh, "nbrConfedInternalLink");
12950 else
12951 json_object_boolean_true_add(json_neigh,
12952 "nbrInternalLink");
12953 } else {
12954 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12955 vty_out(vty, "confed-internal link\n");
12956 else
12957 vty_out(vty, "internal link\n");
12958 }
12959 /* peer type external or confed-external */
12960 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12961 if (use_json) {
12962 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12963 json_object_boolean_true_add(
12964 json_neigh, "nbrConfedExternalLink");
12965 else
12966 json_object_boolean_true_add(json_neigh,
12967 "nbrExternalLink");
12968 } else {
12969 if (bgp_confederation_peers_check(bgp, p->as))
12970 vty_out(vty, "confed-external link\n");
12971 else
12972 vty_out(vty, "external link\n");
12973 }
12974 } else {
12975 if (use_json)
12976 json_object_boolean_true_add(json_neigh,
12977 "nbrUnspecifiedLink");
12978 else
12979 vty_out(vty, "unspecified link\n");
12980 }
12981
12982 /* Roles */
12983 if (use_json) {
12984 json_object_string_add(json_neigh, "localRole",
12985 bgp_get_name_by_role(p->local_role));
12986 json_object_string_add(json_neigh, "remoteRole",
12987 bgp_get_name_by_role(p->remote_role));
12988 } else {
12989 vty_out(vty, " Local Role: %s\n",
12990 bgp_get_name_by_role(p->local_role));
12991 vty_out(vty, " Remote Role: %s\n",
12992 bgp_get_name_by_role(p->remote_role));
12993 }
12994
12995
12996 /* Description. */
12997 if (p->desc) {
12998 if (use_json)
12999 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13000 else
13001 vty_out(vty, " Description: %s\n", p->desc);
13002 }
13003
13004 if (p->hostname) {
13005 if (use_json) {
13006 if (p->hostname)
13007 json_object_string_add(json_neigh, "hostname",
13008 p->hostname);
13009
13010 if (p->domainname)
13011 json_object_string_add(json_neigh, "domainname",
13012 p->domainname);
13013 } else {
13014 if (p->domainname && (p->domainname[0] != '\0'))
13015 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13016 p->domainname);
13017 else
13018 vty_out(vty, "Hostname: %s\n", p->hostname);
13019 }
13020 }
13021
13022 /* Peer-group */
13023 if (p->group) {
13024 if (use_json) {
13025 json_object_string_add(json_neigh, "peerGroup",
13026 p->group->name);
13027
13028 if (dn_flag[0]) {
13029 struct prefix prefix, *range = NULL;
13030
13031 if (sockunion2hostprefix(&(p->su), &prefix))
13032 range = peer_group_lookup_dynamic_neighbor_range(
13033 p->group, &prefix);
13034
13035 if (range) {
13036 json_object_string_addf(
13037 json_neigh,
13038 "peerSubnetRangeGroup", "%pFX",
13039 range);
13040 }
13041 }
13042 } else {
13043 vty_out(vty,
13044 " Member of peer-group %s for session parameters\n",
13045 p->group->name);
13046
13047 if (dn_flag[0]) {
13048 struct prefix prefix, *range = NULL;
13049
13050 if (sockunion2hostprefix(&(p->su), &prefix))
13051 range = peer_group_lookup_dynamic_neighbor_range(
13052 p->group, &prefix);
13053
13054 if (range) {
13055 vty_out(vty,
13056 " Belongs to the subnet range group: %pFX\n",
13057 range);
13058 }
13059 }
13060 }
13061 }
13062
13063 if (use_json) {
13064 /* Administrative shutdown. */
13065 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13066 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13067 json_object_boolean_true_add(json_neigh,
13068 "adminShutDown");
13069
13070 /* BGP Version. */
13071 json_object_int_add(json_neigh, "bgpVersion", 4);
13072 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13073 &p->remote_id);
13074 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13075 &bgp->router_id);
13076
13077 /* Confederation */
13078 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13079 && bgp_confederation_peers_check(bgp, p->as))
13080 json_object_boolean_true_add(json_neigh,
13081 "nbrCommonAdmin");
13082
13083 /* Status. */
13084 json_object_string_add(
13085 json_neigh, "bgpState",
13086 lookup_msg(bgp_status_msg, p->status, NULL));
13087
13088 if (peer_established(p)) {
13089 time_t uptime;
13090
13091 uptime = monotime(NULL);
13092 uptime -= p->uptime;
13093 epoch_tbuf = time(NULL) - uptime;
13094
13095 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13096 uptime * 1000);
13097 json_object_string_add(json_neigh, "bgpTimerUpString",
13098 peer_uptime(p->uptime, timebuf,
13099 BGP_UPTIME_LEN, 0,
13100 NULL));
13101 json_object_int_add(json_neigh,
13102 "bgpTimerUpEstablishedEpoch",
13103 epoch_tbuf);
13104 }
13105
13106 else if (p->status == Active) {
13107 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13108 json_object_string_add(json_neigh, "bgpStateIs",
13109 "passive");
13110 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13111 json_object_string_add(json_neigh, "bgpStateIs",
13112 "passiveNSF");
13113 }
13114
13115 /* read timer */
13116 time_t uptime;
13117 struct tm tm;
13118
13119 uptime = monotime(NULL);
13120 uptime -= p->readtime;
13121 gmtime_r(&uptime, &tm);
13122
13123 json_object_int_add(json_neigh, "bgpTimerLastRead",
13124 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13125 + (tm.tm_hour * 3600000));
13126
13127 uptime = monotime(NULL);
13128 uptime -= p->last_write;
13129 gmtime_r(&uptime, &tm);
13130
13131 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13132 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13133 + (tm.tm_hour * 3600000));
13134
13135 uptime = monotime(NULL);
13136 uptime -= p->update_time;
13137 gmtime_r(&uptime, &tm);
13138
13139 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13140 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13141 + (tm.tm_hour * 3600000));
13142
13143 /* Configured timer values. */
13144 json_object_int_add(json_neigh,
13145 "bgpTimerConfiguredHoldTimeMsecs",
13146 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13147 ? p->holdtime * 1000
13148 : bgp->default_holdtime * 1000);
13149 json_object_int_add(json_neigh,
13150 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13151 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13152 ? p->keepalive * 1000
13153 : bgp->default_keepalive * 1000);
13154 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13155 p->v_holdtime * 1000);
13156 json_object_int_add(json_neigh,
13157 "bgpTimerKeepAliveIntervalMsecs",
13158 p->v_keepalive * 1000);
13159 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13160 json_object_int_add(json_neigh,
13161 "bgpTimerDelayOpenTimeMsecs",
13162 p->v_delayopen * 1000);
13163 }
13164
13165 /* Configured and Synced tcp-mss value for peer */
13166 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13167 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13168 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13169 p->tcp_mss);
13170 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13171 sync_tcp_mss);
13172 }
13173
13174 /* Extended Optional Parameters Length for BGP OPEN Message */
13175 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13176 json_object_boolean_true_add(
13177 json_neigh, "extendedOptionalParametersLength");
13178 else
13179 json_object_boolean_false_add(
13180 json_neigh, "extendedOptionalParametersLength");
13181
13182 /* Conditional advertisements */
13183 json_object_int_add(
13184 json_neigh,
13185 "bgpTimerConfiguredConditionalAdvertisementsSec",
13186 bgp->condition_check_period);
13187 if (thread_is_scheduled(bgp->t_condition_check))
13188 json_object_int_add(
13189 json_neigh,
13190 "bgpTimerUntilConditionalAdvertisementsSec",
13191 thread_timer_remain_second(
13192 bgp->t_condition_check));
13193 } else {
13194 /* Administrative shutdown. */
13195 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13196 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13197 vty_out(vty, " Administratively shut down\n");
13198
13199 /* BGP Version. */
13200 vty_out(vty, " BGP version 4");
13201 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13202 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13203
13204 /* Confederation */
13205 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13206 && bgp_confederation_peers_check(bgp, p->as))
13207 vty_out(vty,
13208 " Neighbor under common administration\n");
13209
13210 /* Status. */
13211 vty_out(vty, " BGP state = %s",
13212 lookup_msg(bgp_status_msg, p->status, NULL));
13213
13214 if (peer_established(p))
13215 vty_out(vty, ", up for %8s",
13216 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13217 0, NULL));
13218
13219 else if (p->status == Active) {
13220 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13221 vty_out(vty, " (passive)");
13222 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13223 vty_out(vty, " (NSF passive)");
13224 }
13225 vty_out(vty, "\n");
13226
13227 /* read timer */
13228 vty_out(vty, " Last read %s",
13229 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13230 NULL));
13231 vty_out(vty, ", Last write %s\n",
13232 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13233 NULL));
13234
13235 /* Configured timer values. */
13236 vty_out(vty,
13237 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13238 p->v_holdtime, p->v_keepalive);
13239 vty_out(vty, " Configured hold time is %d seconds",
13240 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13241 ? p->holdtime
13242 : bgp->default_holdtime);
13243 vty_out(vty, ", keepalive interval is %d seconds\n",
13244 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13245 ? p->keepalive
13246 : bgp->default_keepalive);
13247 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13248 vty_out(vty,
13249 " Configured DelayOpenTime is %d seconds\n",
13250 p->delayopen);
13251
13252 /* Configured and synced tcp-mss value for peer */
13253 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13254 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13255 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13256 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13257 }
13258
13259 /* Extended Optional Parameters Length for BGP OPEN Message */
13260 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13261 vty_out(vty,
13262 " Extended Optional Parameters Length is enabled\n");
13263
13264 /* Conditional advertisements */
13265 vty_out(vty,
13266 " Configured conditional advertisements interval is %d seconds\n",
13267 bgp->condition_check_period);
13268 if (thread_is_scheduled(bgp->t_condition_check))
13269 vty_out(vty,
13270 " Time until conditional advertisements begin is %lu seconds\n",
13271 thread_timer_remain_second(
13272 bgp->t_condition_check));
13273 }
13274 /* Capability. */
13275 if (peer_established(p) &&
13276 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13277 if (use_json) {
13278 json_object *json_cap = NULL;
13279
13280 json_cap = json_object_new_object();
13281
13282 /* AS4 */
13283 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13284 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13285 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13286 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13287 json_object_string_add(
13288 json_cap, "4byteAs",
13289 "advertisedAndReceived");
13290 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13291 json_object_string_add(json_cap,
13292 "4byteAs",
13293 "advertised");
13294 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13295 json_object_string_add(json_cap,
13296 "4byteAs",
13297 "received");
13298 }
13299
13300 /* Extended Message Support */
13301 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13302 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13303 json_object_string_add(json_cap,
13304 "extendedMessage",
13305 "advertisedAndReceived");
13306 else if (CHECK_FLAG(p->cap,
13307 PEER_CAP_EXTENDED_MESSAGE_ADV))
13308 json_object_string_add(json_cap,
13309 "extendedMessage",
13310 "advertised");
13311 else if (CHECK_FLAG(p->cap,
13312 PEER_CAP_EXTENDED_MESSAGE_RCV))
13313 json_object_string_add(json_cap,
13314 "extendedMessage",
13315 "received");
13316
13317 /* AddPath */
13318 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13319 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13320 json_object *json_add = NULL;
13321 const char *print_store;
13322
13323 json_add = json_object_new_object();
13324
13325 FOREACH_AFI_SAFI (afi, safi) {
13326 json_object *json_sub = NULL;
13327 json_sub = json_object_new_object();
13328 print_store = get_afi_safi_str(
13329 afi, safi, true);
13330
13331 if (CHECK_FLAG(
13332 p->af_cap[afi][safi],
13333 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13334 CHECK_FLAG(
13335 p->af_cap[afi][safi],
13336 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13337 if (CHECK_FLAG(
13338 p->af_cap[afi]
13339 [safi],
13340 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13341 CHECK_FLAG(
13342 p->af_cap[afi]
13343 [safi],
13344 PEER_CAP_ADDPATH_AF_TX_RCV))
13345 json_object_boolean_true_add(
13346 json_sub,
13347 "txAdvertisedAndReceived");
13348 else if (
13349 CHECK_FLAG(
13350 p->af_cap[afi]
13351 [safi],
13352 PEER_CAP_ADDPATH_AF_TX_ADV))
13353 json_object_boolean_true_add(
13354 json_sub,
13355 "txAdvertised");
13356 else if (
13357 CHECK_FLAG(
13358 p->af_cap[afi]
13359 [safi],
13360 PEER_CAP_ADDPATH_AF_TX_RCV))
13361 json_object_boolean_true_add(
13362 json_sub,
13363 "txReceived");
13364 }
13365
13366 if (CHECK_FLAG(
13367 p->af_cap[afi][safi],
13368 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13369 CHECK_FLAG(
13370 p->af_cap[afi][safi],
13371 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13372 if (CHECK_FLAG(
13373 p->af_cap[afi]
13374 [safi],
13375 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13376 CHECK_FLAG(
13377 p->af_cap[afi]
13378 [safi],
13379 PEER_CAP_ADDPATH_AF_RX_RCV))
13380 json_object_boolean_true_add(
13381 json_sub,
13382 "rxAdvertisedAndReceived");
13383 else if (
13384 CHECK_FLAG(
13385 p->af_cap[afi]
13386 [safi],
13387 PEER_CAP_ADDPATH_AF_RX_ADV))
13388 json_object_boolean_true_add(
13389 json_sub,
13390 "rxAdvertised");
13391 else if (
13392 CHECK_FLAG(
13393 p->af_cap[afi]
13394 [safi],
13395 PEER_CAP_ADDPATH_AF_RX_RCV))
13396 json_object_boolean_true_add(
13397 json_sub,
13398 "rxReceived");
13399 }
13400
13401 if (CHECK_FLAG(
13402 p->af_cap[afi][safi],
13403 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13404 CHECK_FLAG(
13405 p->af_cap[afi][safi],
13406 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13407 CHECK_FLAG(
13408 p->af_cap[afi][safi],
13409 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13410 CHECK_FLAG(
13411 p->af_cap[afi][safi],
13412 PEER_CAP_ADDPATH_AF_RX_RCV))
13413 json_object_object_add(
13414 json_add, print_store,
13415 json_sub);
13416 else
13417 json_object_free(json_sub);
13418 }
13419
13420 json_object_object_add(json_cap, "addPath",
13421 json_add);
13422 }
13423
13424 /* Dynamic */
13425 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13426 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13427 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13428 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13429 json_object_string_add(
13430 json_cap, "dynamic",
13431 "advertisedAndReceived");
13432 else if (CHECK_FLAG(p->cap,
13433 PEER_CAP_DYNAMIC_ADV))
13434 json_object_string_add(json_cap,
13435 "dynamic",
13436 "advertised");
13437 else if (CHECK_FLAG(p->cap,
13438 PEER_CAP_DYNAMIC_RCV))
13439 json_object_string_add(json_cap,
13440 "dynamic",
13441 "received");
13442 }
13443
13444 /* Role */
13445 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13446 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13447 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13448 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13449 json_object_string_add(
13450 json_cap, "role",
13451 "advertisedAndReceived");
13452 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13453 json_object_string_add(json_cap, "role",
13454 "advertised");
13455 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13456 json_object_string_add(json_cap, "role",
13457 "received");
13458 }
13459
13460 /* Extended nexthop */
13461 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13462 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13463 json_object *json_nxt = NULL;
13464 const char *print_store;
13465
13466
13467 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13468 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13469 json_object_string_add(
13470 json_cap, "extendedNexthop",
13471 "advertisedAndReceived");
13472 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13473 json_object_string_add(
13474 json_cap, "extendedNexthop",
13475 "advertised");
13476 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13477 json_object_string_add(
13478 json_cap, "extendedNexthop",
13479 "received");
13480
13481 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13482 json_nxt = json_object_new_object();
13483
13484 for (safi = SAFI_UNICAST;
13485 safi < SAFI_MAX; safi++) {
13486 if (CHECK_FLAG(
13487 p->af_cap[AFI_IP]
13488 [safi],
13489 PEER_CAP_ENHE_AF_RCV)) {
13490 print_store =
13491 get_afi_safi_str(
13492 AFI_IP,
13493 safi,
13494 true);
13495 json_object_string_add(
13496 json_nxt,
13497 print_store,
13498 "recieved"); /* misspelled for compatibility */
13499 }
13500 }
13501 json_object_object_add(
13502 json_cap,
13503 "extendedNexthopFamililesByPeer",
13504 json_nxt);
13505 }
13506 }
13507
13508 /* Long-lived Graceful Restart */
13509 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13510 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13511 json_object *json_llgr = NULL;
13512 const char *afi_safi_str;
13513
13514 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13515 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13516 json_object_string_add(
13517 json_cap,
13518 "longLivedGracefulRestart",
13519 "advertisedAndReceived");
13520 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13521 json_object_string_add(
13522 json_cap,
13523 "longLivedGracefulRestart",
13524 "advertised");
13525 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13526 json_object_string_add(
13527 json_cap,
13528 "longLivedGracefulRestart",
13529 "received");
13530
13531 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13532 json_llgr = json_object_new_object();
13533
13534 FOREACH_AFI_SAFI (afi, safi) {
13535 if (CHECK_FLAG(
13536 p->af_cap[afi]
13537 [safi],
13538 PEER_CAP_ENHE_AF_RCV)) {
13539 afi_safi_str =
13540 get_afi_safi_str(
13541 afi,
13542 safi,
13543 true);
13544 json_object_string_add(
13545 json_llgr,
13546 afi_safi_str,
13547 "received");
13548 }
13549 }
13550 json_object_object_add(
13551 json_cap,
13552 "longLivedGracefulRestartByPeer",
13553 json_llgr);
13554 }
13555 }
13556
13557 /* Route Refresh */
13558 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13559 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13560 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13561 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13562 (CHECK_FLAG(p->cap,
13563 PEER_CAP_REFRESH_NEW_RCV) ||
13564 CHECK_FLAG(p->cap,
13565 PEER_CAP_REFRESH_OLD_RCV))) {
13566 if (CHECK_FLAG(
13567 p->cap,
13568 PEER_CAP_REFRESH_OLD_RCV) &&
13569 CHECK_FLAG(
13570 p->cap,
13571 PEER_CAP_REFRESH_NEW_RCV))
13572 json_object_string_add(
13573 json_cap,
13574 "routeRefresh",
13575 "advertisedAndReceivedOldNew");
13576 else {
13577 if (CHECK_FLAG(
13578 p->cap,
13579 PEER_CAP_REFRESH_OLD_RCV))
13580 json_object_string_add(
13581 json_cap,
13582 "routeRefresh",
13583 "advertisedAndReceivedOld");
13584 else
13585 json_object_string_add(
13586 json_cap,
13587 "routeRefresh",
13588 "advertisedAndReceivedNew");
13589 }
13590 } else if (CHECK_FLAG(p->cap,
13591 PEER_CAP_REFRESH_ADV))
13592 json_object_string_add(json_cap,
13593 "routeRefresh",
13594 "advertised");
13595 else if (CHECK_FLAG(p->cap,
13596 PEER_CAP_REFRESH_NEW_RCV) ||
13597 CHECK_FLAG(p->cap,
13598 PEER_CAP_REFRESH_OLD_RCV))
13599 json_object_string_add(json_cap,
13600 "routeRefresh",
13601 "received");
13602 }
13603
13604 /* Enhanced Route Refresh */
13605 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13606 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13607 if (CHECK_FLAG(p->cap,
13608 PEER_CAP_ENHANCED_RR_ADV) &&
13609 CHECK_FLAG(p->cap,
13610 PEER_CAP_ENHANCED_RR_RCV))
13611 json_object_string_add(
13612 json_cap,
13613 "enhancedRouteRefresh",
13614 "advertisedAndReceived");
13615 else if (CHECK_FLAG(p->cap,
13616 PEER_CAP_ENHANCED_RR_ADV))
13617 json_object_string_add(
13618 json_cap,
13619 "enhancedRouteRefresh",
13620 "advertised");
13621 else if (CHECK_FLAG(p->cap,
13622 PEER_CAP_ENHANCED_RR_RCV))
13623 json_object_string_add(
13624 json_cap,
13625 "enhancedRouteRefresh",
13626 "received");
13627 }
13628
13629 /* Multiprotocol Extensions */
13630 json_object *json_multi = NULL;
13631
13632 json_multi = json_object_new_object();
13633
13634 FOREACH_AFI_SAFI (afi, safi) {
13635 if (p->afc_adv[afi][safi] ||
13636 p->afc_recv[afi][safi]) {
13637 json_object *json_exten = NULL;
13638 json_exten = json_object_new_object();
13639
13640 if (p->afc_adv[afi][safi] &&
13641 p->afc_recv[afi][safi])
13642 json_object_boolean_true_add(
13643 json_exten,
13644 "advertisedAndReceived");
13645 else if (p->afc_adv[afi][safi])
13646 json_object_boolean_true_add(
13647 json_exten,
13648 "advertised");
13649 else if (p->afc_recv[afi][safi])
13650 json_object_boolean_true_add(
13651 json_exten, "received");
13652
13653 json_object_object_add(
13654 json_multi,
13655 get_afi_safi_str(afi, safi,
13656 true),
13657 json_exten);
13658 }
13659 }
13660 json_object_object_add(json_cap,
13661 "multiprotocolExtensions",
13662 json_multi);
13663
13664 /* Hostname capabilities */
13665 json_object *json_hname = NULL;
13666
13667 json_hname = json_object_new_object();
13668
13669 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13670 json_object_string_add(
13671 json_hname, "advHostName",
13672 bgp->peer_self->hostname
13673 ? bgp->peer_self->hostname
13674 : "n/a");
13675 json_object_string_add(
13676 json_hname, "advDomainName",
13677 bgp->peer_self->domainname
13678 ? bgp->peer_self->domainname
13679 : "n/a");
13680 }
13681
13682
13683 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13684 json_object_string_add(
13685 json_hname, "rcvHostName",
13686 p->hostname ? p->hostname : "n/a");
13687 json_object_string_add(
13688 json_hname, "rcvDomainName",
13689 p->domainname ? p->domainname : "n/a");
13690 }
13691
13692 json_object_object_add(json_cap, "hostName",
13693 json_hname);
13694
13695 /* Graceful Restart */
13696 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13697 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13698 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13699 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13700 json_object_string_add(
13701 json_cap, "gracefulRestart",
13702 "advertisedAndReceived");
13703 else if (CHECK_FLAG(p->cap,
13704 PEER_CAP_RESTART_ADV))
13705 json_object_string_add(
13706 json_cap,
13707 "gracefulRestartCapability",
13708 "advertised");
13709 else if (CHECK_FLAG(p->cap,
13710 PEER_CAP_RESTART_RCV))
13711 json_object_string_add(
13712 json_cap,
13713 "gracefulRestartCapability",
13714 "received");
13715
13716 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13717 int restart_af_count = 0;
13718 json_object *json_restart = NULL;
13719 json_restart = json_object_new_object();
13720
13721 json_object_int_add(
13722 json_cap,
13723 "gracefulRestartRemoteTimerMsecs",
13724 p->v_gr_restart * 1000);
13725
13726 FOREACH_AFI_SAFI (afi, safi) {
13727 if (CHECK_FLAG(
13728 p->af_cap[afi]
13729 [safi],
13730 PEER_CAP_RESTART_AF_RCV)) {
13731 json_object *json_sub =
13732 NULL;
13733 json_sub =
13734 json_object_new_object();
13735
13736 if (CHECK_FLAG(
13737 p->af_cap
13738 [afi]
13739 [safi],
13740 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13741 json_object_boolean_true_add(
13742 json_sub,
13743 "preserved");
13744 restart_af_count++;
13745 json_object_object_add(
13746 json_restart,
13747 get_afi_safi_str(
13748 afi,
13749 safi,
13750 true),
13751 json_sub);
13752 }
13753 }
13754 if (!restart_af_count) {
13755 json_object_string_add(
13756 json_cap,
13757 "addressFamiliesByPeer",
13758 "none");
13759 json_object_free(json_restart);
13760 } else
13761 json_object_object_add(
13762 json_cap,
13763 "addressFamiliesByPeer",
13764 json_restart);
13765 }
13766 }
13767 json_object_object_add(
13768 json_neigh, "neighborCapabilities", json_cap);
13769 } else {
13770 vty_out(vty, " Neighbor capabilities:\n");
13771
13772 /* AS4 */
13773 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13774 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13775 vty_out(vty, " 4 Byte AS:");
13776 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13777 vty_out(vty, " advertised");
13778 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13779 vty_out(vty, " %sreceived",
13780 CHECK_FLAG(p->cap,
13781 PEER_CAP_AS4_ADV)
13782 ? "and "
13783 : "");
13784 vty_out(vty, "\n");
13785 }
13786
13787 /* Extended Message Support */
13788 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13789 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13790 vty_out(vty, " Extended Message:");
13791 if (CHECK_FLAG(p->cap,
13792 PEER_CAP_EXTENDED_MESSAGE_ADV))
13793 vty_out(vty, " advertised");
13794 if (CHECK_FLAG(p->cap,
13795 PEER_CAP_EXTENDED_MESSAGE_RCV))
13796 vty_out(vty, " %sreceived",
13797 CHECK_FLAG(
13798 p->cap,
13799 PEER_CAP_EXTENDED_MESSAGE_ADV)
13800 ? "and "
13801 : "");
13802 vty_out(vty, "\n");
13803 }
13804
13805 /* AddPath */
13806 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13807 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13808 vty_out(vty, " AddPath:\n");
13809
13810 FOREACH_AFI_SAFI (afi, safi) {
13811 if (CHECK_FLAG(
13812 p->af_cap[afi][safi],
13813 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13814 CHECK_FLAG(
13815 p->af_cap[afi][safi],
13816 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13817 vty_out(vty, " %s: TX ",
13818 get_afi_safi_str(
13819 afi, safi,
13820 false));
13821
13822 if (CHECK_FLAG(
13823 p->af_cap[afi]
13824 [safi],
13825 PEER_CAP_ADDPATH_AF_TX_ADV))
13826 vty_out(vty,
13827 "advertised");
13828
13829 if (CHECK_FLAG(
13830 p->af_cap[afi]
13831 [safi],
13832 PEER_CAP_ADDPATH_AF_TX_RCV))
13833 vty_out(vty,
13834 "%sreceived",
13835 CHECK_FLAG(
13836 p->af_cap
13837 [afi]
13838 [safi],
13839 PEER_CAP_ADDPATH_AF_TX_ADV)
13840 ? " and "
13841 : "");
13842
13843 vty_out(vty, "\n");
13844 }
13845
13846 if (CHECK_FLAG(
13847 p->af_cap[afi][safi],
13848 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13849 CHECK_FLAG(
13850 p->af_cap[afi][safi],
13851 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13852 vty_out(vty, " %s: RX ",
13853 get_afi_safi_str(
13854 afi, safi,
13855 false));
13856
13857 if (CHECK_FLAG(
13858 p->af_cap[afi]
13859 [safi],
13860 PEER_CAP_ADDPATH_AF_RX_ADV))
13861 vty_out(vty,
13862 "advertised");
13863
13864 if (CHECK_FLAG(
13865 p->af_cap[afi]
13866 [safi],
13867 PEER_CAP_ADDPATH_AF_RX_RCV))
13868 vty_out(vty,
13869 "%sreceived",
13870 CHECK_FLAG(
13871 p->af_cap
13872 [afi]
13873 [safi],
13874 PEER_CAP_ADDPATH_AF_RX_ADV)
13875 ? " and "
13876 : "");
13877
13878 vty_out(vty, "\n");
13879 }
13880 }
13881 }
13882
13883 /* Dynamic */
13884 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13885 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13886 vty_out(vty, " Dynamic:");
13887 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13888 vty_out(vty, " advertised");
13889 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13890 vty_out(vty, " %sreceived",
13891 CHECK_FLAG(p->cap,
13892 PEER_CAP_DYNAMIC_ADV)
13893 ? "and "
13894 : "");
13895 vty_out(vty, "\n");
13896 }
13897
13898 /* Role */
13899 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13900 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13901 vty_out(vty, " Role:");
13902 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13903 vty_out(vty, " advertised");
13904 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13905 vty_out(vty, " %sreceived",
13906 CHECK_FLAG(p->cap,
13907 PEER_CAP_ROLE_ADV)
13908 ? "and "
13909 : "");
13910 vty_out(vty, "\n");
13911 }
13912
13913 /* Extended nexthop */
13914 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13915 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13916 vty_out(vty, " Extended nexthop:");
13917 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13918 vty_out(vty, " advertised");
13919 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13920 vty_out(vty, " %sreceived",
13921 CHECK_FLAG(p->cap,
13922 PEER_CAP_ENHE_ADV)
13923 ? "and "
13924 : "");
13925 vty_out(vty, "\n");
13926
13927 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13928 vty_out(vty,
13929 " Address families by peer:\n ");
13930 for (safi = SAFI_UNICAST;
13931 safi < SAFI_MAX; safi++)
13932 if (CHECK_FLAG(
13933 p->af_cap[AFI_IP]
13934 [safi],
13935 PEER_CAP_ENHE_AF_RCV))
13936 vty_out(vty,
13937 " %s\n",
13938 get_afi_safi_str(
13939 AFI_IP,
13940 safi,
13941 false));
13942 }
13943 }
13944
13945 /* Long-lived Graceful Restart */
13946 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13947 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13948 vty_out(vty,
13949 " Long-lived Graceful Restart:");
13950 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13951 vty_out(vty, " advertised");
13952 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13953 vty_out(vty, " %sreceived",
13954 CHECK_FLAG(p->cap,
13955 PEER_CAP_LLGR_ADV)
13956 ? "and "
13957 : "");
13958 vty_out(vty, "\n");
13959
13960 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13961 vty_out(vty,
13962 " Address families by peer:\n");
13963 FOREACH_AFI_SAFI (afi, safi)
13964 if (CHECK_FLAG(
13965 p->af_cap[afi]
13966 [safi],
13967 PEER_CAP_LLGR_AF_RCV))
13968 vty_out(vty,
13969 " %s\n",
13970 get_afi_safi_str(
13971 afi,
13972 safi,
13973 false));
13974 }
13975 }
13976
13977 /* Route Refresh */
13978 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13979 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13980 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13981 vty_out(vty, " Route refresh:");
13982 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13983 vty_out(vty, " advertised");
13984 if (CHECK_FLAG(p->cap,
13985 PEER_CAP_REFRESH_NEW_RCV) ||
13986 CHECK_FLAG(p->cap,
13987 PEER_CAP_REFRESH_OLD_RCV))
13988 vty_out(vty, " %sreceived(%s)",
13989 CHECK_FLAG(p->cap,
13990 PEER_CAP_REFRESH_ADV)
13991 ? "and "
13992 : "",
13993 (CHECK_FLAG(
13994 p->cap,
13995 PEER_CAP_REFRESH_OLD_RCV) &&
13996 CHECK_FLAG(
13997 p->cap,
13998 PEER_CAP_REFRESH_NEW_RCV))
13999 ? "old & new"
14000 : CHECK_FLAG(
14001 p->cap,
14002 PEER_CAP_REFRESH_OLD_RCV)
14003 ? "old"
14004 : "new");
14005
14006 vty_out(vty, "\n");
14007 }
14008
14009 /* Enhanced Route Refresh */
14010 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14011 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14012 vty_out(vty, " Enhanced Route Refresh:");
14013 if (CHECK_FLAG(p->cap,
14014 PEER_CAP_ENHANCED_RR_ADV))
14015 vty_out(vty, " advertised");
14016 if (CHECK_FLAG(p->cap,
14017 PEER_CAP_ENHANCED_RR_RCV))
14018 vty_out(vty, " %sreceived",
14019 CHECK_FLAG(p->cap,
14020 PEER_CAP_REFRESH_ADV)
14021 ? "and "
14022 : "");
14023 vty_out(vty, "\n");
14024 }
14025
14026 /* Multiprotocol Extensions */
14027 FOREACH_AFI_SAFI (afi, safi)
14028 if (p->afc_adv[afi][safi] ||
14029 p->afc_recv[afi][safi]) {
14030 vty_out(vty, " Address Family %s:",
14031 get_afi_safi_str(afi, safi,
14032 false));
14033 if (p->afc_adv[afi][safi])
14034 vty_out(vty, " advertised");
14035 if (p->afc_recv[afi][safi])
14036 vty_out(vty, " %sreceived",
14037 p->afc_adv[afi][safi]
14038 ? "and "
14039 : "");
14040 vty_out(vty, "\n");
14041 }
14042
14043 /* Hostname capability */
14044 vty_out(vty, " Hostname Capability:");
14045
14046 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14047 vty_out(vty,
14048 " advertised (name: %s,domain name: %s)",
14049 bgp->peer_self->hostname
14050 ? bgp->peer_self->hostname
14051 : "n/a",
14052 bgp->peer_self->domainname
14053 ? bgp->peer_self->domainname
14054 : "n/a");
14055 } else {
14056 vty_out(vty, " not advertised");
14057 }
14058
14059 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14060 vty_out(vty,
14061 " received (name: %s,domain name: %s)",
14062 p->hostname ? p->hostname : "n/a",
14063 p->domainname ? p->domainname : "n/a");
14064 } else {
14065 vty_out(vty, " not received");
14066 }
14067
14068 vty_out(vty, "\n");
14069
14070 /* Graceful Restart */
14071 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14072 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14073 vty_out(vty,
14074 " Graceful Restart Capability:");
14075 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14076 vty_out(vty, " advertised");
14077 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14078 vty_out(vty, " %sreceived",
14079 CHECK_FLAG(p->cap,
14080 PEER_CAP_RESTART_ADV)
14081 ? "and "
14082 : "");
14083 vty_out(vty, "\n");
14084
14085 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14086 int restart_af_count = 0;
14087
14088 vty_out(vty,
14089 " Remote Restart timer is %d seconds\n",
14090 p->v_gr_restart);
14091 vty_out(vty,
14092 " Address families by peer:\n ");
14093
14094 FOREACH_AFI_SAFI (afi, safi)
14095 if (CHECK_FLAG(
14096 p->af_cap[afi]
14097 [safi],
14098 PEER_CAP_RESTART_AF_RCV)) {
14099 vty_out(vty, "%s%s(%s)",
14100 restart_af_count
14101 ? ", "
14102 : "",
14103 get_afi_safi_str(
14104 afi,
14105 safi,
14106 false),
14107 CHECK_FLAG(
14108 p->af_cap
14109 [afi]
14110 [safi],
14111 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14112 ? "preserved"
14113 : "not preserved");
14114 restart_af_count++;
14115 }
14116 if (!restart_af_count)
14117 vty_out(vty, "none");
14118 vty_out(vty, "\n");
14119 }
14120 } /* Graceful Restart */
14121 }
14122 }
14123
14124 /* graceful restart information */
14125 json_object *json_grace = NULL;
14126 json_object *json_grace_send = NULL;
14127 json_object *json_grace_recv = NULL;
14128 int eor_send_af_count = 0;
14129 int eor_receive_af_count = 0;
14130
14131 if (use_json) {
14132 json_grace = json_object_new_object();
14133 json_grace_send = json_object_new_object();
14134 json_grace_recv = json_object_new_object();
14135
14136 if ((peer_established(p)) &&
14137 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14138 FOREACH_AFI_SAFI (afi, safi) {
14139 if (CHECK_FLAG(p->af_sflags[afi][safi],
14140 PEER_STATUS_EOR_SEND)) {
14141 json_object_boolean_true_add(
14142 json_grace_send,
14143 get_afi_safi_str(afi, safi,
14144 true));
14145 eor_send_af_count++;
14146 }
14147 }
14148 FOREACH_AFI_SAFI (afi, safi) {
14149 if (CHECK_FLAG(p->af_sflags[afi][safi],
14150 PEER_STATUS_EOR_RECEIVED)) {
14151 json_object_boolean_true_add(
14152 json_grace_recv,
14153 get_afi_safi_str(afi, safi,
14154 true));
14155 eor_receive_af_count++;
14156 }
14157 }
14158 }
14159 json_object_object_add(json_grace, "endOfRibSend",
14160 json_grace_send);
14161 json_object_object_add(json_grace, "endOfRibRecv",
14162 json_grace_recv);
14163
14164
14165 if (p->t_gr_restart)
14166 json_object_int_add(
14167 json_grace, "gracefulRestartTimerMsecs",
14168 thread_timer_remain_second(p->t_gr_restart) *
14169 1000);
14170
14171 if (p->t_gr_stale)
14172 json_object_int_add(
14173 json_grace, "gracefulStalepathTimerMsecs",
14174 thread_timer_remain_second(p->t_gr_stale) *
14175 1000);
14176 /* more gr info in new format */
14177 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
14178 json_object_object_add(json_neigh, "gracefulRestartInfo",
14179 json_grace);
14180 } else {
14181 vty_out(vty, " Graceful restart information:\n");
14182 if ((peer_established(p)) &&
14183 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14184
14185 vty_out(vty, " End-of-RIB send: ");
14186 FOREACH_AFI_SAFI (afi, safi) {
14187 if (CHECK_FLAG(p->af_sflags[afi][safi],
14188 PEER_STATUS_EOR_SEND)) {
14189 vty_out(vty, "%s%s",
14190 eor_send_af_count ? ", " : "",
14191 get_afi_safi_str(afi, safi,
14192 false));
14193 eor_send_af_count++;
14194 }
14195 }
14196 vty_out(vty, "\n");
14197 vty_out(vty, " End-of-RIB received: ");
14198 FOREACH_AFI_SAFI (afi, safi) {
14199 if (CHECK_FLAG(p->af_sflags[afi][safi],
14200 PEER_STATUS_EOR_RECEIVED)) {
14201 vty_out(vty, "%s%s",
14202 eor_receive_af_count ? ", "
14203 : "",
14204 get_afi_safi_str(afi, safi,
14205 false));
14206 eor_receive_af_count++;
14207 }
14208 }
14209 vty_out(vty, "\n");
14210 }
14211
14212 if (p->t_gr_restart)
14213 vty_out(vty,
14214 " The remaining time of restart timer is %ld\n",
14215 thread_timer_remain_second(p->t_gr_restart));
14216
14217 if (p->t_gr_stale)
14218 vty_out(vty,
14219 " The remaining time of stalepath timer is %ld\n",
14220 thread_timer_remain_second(p->t_gr_stale));
14221
14222 /* more gr info in new format */
14223 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14224 }
14225
14226 if (use_json) {
14227 json_object *json_stat = NULL;
14228 json_stat = json_object_new_object();
14229 /* Packet counts. */
14230
14231 atomic_size_t outq_count, inq_count;
14232 outq_count = atomic_load_explicit(&p->obuf->count,
14233 memory_order_relaxed);
14234 inq_count = atomic_load_explicit(&p->ibuf->count,
14235 memory_order_relaxed);
14236
14237 json_object_int_add(json_stat, "depthInq",
14238 (unsigned long)inq_count);
14239 json_object_int_add(json_stat, "depthOutq",
14240 (unsigned long)outq_count);
14241 json_object_int_add(json_stat, "opensSent",
14242 atomic_load_explicit(&p->open_out,
14243 memory_order_relaxed));
14244 json_object_int_add(json_stat, "opensRecv",
14245 atomic_load_explicit(&p->open_in,
14246 memory_order_relaxed));
14247 json_object_int_add(json_stat, "notificationsSent",
14248 atomic_load_explicit(&p->notify_out,
14249 memory_order_relaxed));
14250 json_object_int_add(json_stat, "notificationsRecv",
14251 atomic_load_explicit(&p->notify_in,
14252 memory_order_relaxed));
14253 json_object_int_add(json_stat, "updatesSent",
14254 atomic_load_explicit(&p->update_out,
14255 memory_order_relaxed));
14256 json_object_int_add(json_stat, "updatesRecv",
14257 atomic_load_explicit(&p->update_in,
14258 memory_order_relaxed));
14259 json_object_int_add(json_stat, "keepalivesSent",
14260 atomic_load_explicit(&p->keepalive_out,
14261 memory_order_relaxed));
14262 json_object_int_add(json_stat, "keepalivesRecv",
14263 atomic_load_explicit(&p->keepalive_in,
14264 memory_order_relaxed));
14265 json_object_int_add(json_stat, "routeRefreshSent",
14266 atomic_load_explicit(&p->refresh_out,
14267 memory_order_relaxed));
14268 json_object_int_add(json_stat, "routeRefreshRecv",
14269 atomic_load_explicit(&p->refresh_in,
14270 memory_order_relaxed));
14271 json_object_int_add(json_stat, "capabilitySent",
14272 atomic_load_explicit(&p->dynamic_cap_out,
14273 memory_order_relaxed));
14274 json_object_int_add(json_stat, "capabilityRecv",
14275 atomic_load_explicit(&p->dynamic_cap_in,
14276 memory_order_relaxed));
14277 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14278 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14279 json_object_object_add(json_neigh, "messageStats", json_stat);
14280 } else {
14281 atomic_size_t outq_count, inq_count, open_out, open_in,
14282 notify_out, notify_in, update_out, update_in,
14283 keepalive_out, keepalive_in, refresh_out, refresh_in,
14284 dynamic_cap_out, dynamic_cap_in;
14285 outq_count = atomic_load_explicit(&p->obuf->count,
14286 memory_order_relaxed);
14287 inq_count = atomic_load_explicit(&p->ibuf->count,
14288 memory_order_relaxed);
14289 open_out = atomic_load_explicit(&p->open_out,
14290 memory_order_relaxed);
14291 open_in =
14292 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14293 notify_out = atomic_load_explicit(&p->notify_out,
14294 memory_order_relaxed);
14295 notify_in = atomic_load_explicit(&p->notify_in,
14296 memory_order_relaxed);
14297 update_out = atomic_load_explicit(&p->update_out,
14298 memory_order_relaxed);
14299 update_in = atomic_load_explicit(&p->update_in,
14300 memory_order_relaxed);
14301 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14302 memory_order_relaxed);
14303 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14304 memory_order_relaxed);
14305 refresh_out = atomic_load_explicit(&p->refresh_out,
14306 memory_order_relaxed);
14307 refresh_in = atomic_load_explicit(&p->refresh_in,
14308 memory_order_relaxed);
14309 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14310 memory_order_relaxed);
14311 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14312 memory_order_relaxed);
14313
14314 /* Packet counts. */
14315 vty_out(vty, " Message statistics:\n");
14316 vty_out(vty, " Inq depth is %zu\n", inq_count);
14317 vty_out(vty, " Outq depth is %zu\n", outq_count);
14318 vty_out(vty, " Sent Rcvd\n");
14319 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14320 open_in);
14321 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14322 notify_in);
14323 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14324 update_in);
14325 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14326 keepalive_in);
14327 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14328 refresh_in);
14329 vty_out(vty, " Capability: %10zu %10zu\n",
14330 dynamic_cap_out, dynamic_cap_in);
14331 vty_out(vty, " Total: %10u %10u\n",
14332 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14333 }
14334
14335 if (use_json) {
14336 /* advertisement-interval */
14337 json_object_int_add(json_neigh,
14338 "minBtwnAdvertisementRunsTimerMsecs",
14339 p->v_routeadv * 1000);
14340
14341 /* Update-source. */
14342 if (p->update_if || p->update_source) {
14343 if (p->update_if)
14344 json_object_string_add(json_neigh,
14345 "updateSource",
14346 p->update_if);
14347 else if (p->update_source)
14348 json_object_string_addf(json_neigh,
14349 "updateSource", "%pSU",
14350 p->update_source);
14351 }
14352 } else {
14353 /* advertisement-interval */
14354 vty_out(vty,
14355 " Minimum time between advertisement runs is %d seconds\n",
14356 p->v_routeadv);
14357
14358 /* Update-source. */
14359 if (p->update_if || p->update_source) {
14360 vty_out(vty, " Update source is ");
14361 if (p->update_if)
14362 vty_out(vty, "%s", p->update_if);
14363 else if (p->update_source)
14364 vty_out(vty, "%pSU", p->update_source);
14365 vty_out(vty, "\n");
14366 }
14367
14368 vty_out(vty, "\n");
14369 }
14370
14371 /* Address Family Information */
14372 json_object *json_hold = NULL;
14373
14374 if (use_json)
14375 json_hold = json_object_new_object();
14376
14377 FOREACH_AFI_SAFI (afi, safi)
14378 if (p->afc[afi][safi])
14379 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14380 json_hold);
14381
14382 if (use_json) {
14383 json_object_object_add(json_neigh, "addressFamilyInfo",
14384 json_hold);
14385 json_object_int_add(json_neigh, "connectionsEstablished",
14386 p->established);
14387 json_object_int_add(json_neigh, "connectionsDropped",
14388 p->dropped);
14389 } else
14390 vty_out(vty, " Connections established %d; dropped %d\n",
14391 p->established, p->dropped);
14392
14393 if (!p->last_reset) {
14394 if (use_json)
14395 json_object_string_add(json_neigh, "lastReset",
14396 "never");
14397 else
14398 vty_out(vty, " Last reset never\n");
14399 } else {
14400 if (use_json) {
14401 time_t uptime;
14402 struct tm tm;
14403
14404 uptime = monotime(NULL);
14405 uptime -= p->resettime;
14406 gmtime_r(&uptime, &tm);
14407
14408 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14409 (tm.tm_sec * 1000)
14410 + (tm.tm_min * 60000)
14411 + (tm.tm_hour * 3600000));
14412 bgp_show_peer_reset(NULL, p, json_neigh, true);
14413 } else {
14414 vty_out(vty, " Last reset %s, ",
14415 peer_uptime(p->resettime, timebuf,
14416 BGP_UPTIME_LEN, 0, NULL));
14417
14418 bgp_show_peer_reset(vty, p, NULL, false);
14419 if (p->last_reset_cause_size) {
14420 msg = p->last_reset_cause;
14421 vty_out(vty,
14422 " Message received that caused BGP to send a NOTIFICATION:\n ");
14423 for (i = 1; i <= p->last_reset_cause_size;
14424 i++) {
14425 vty_out(vty, "%02X", *msg++);
14426
14427 if (i != p->last_reset_cause_size) {
14428 if (i % 16 == 0) {
14429 vty_out(vty, "\n ");
14430 } else if (i % 4 == 0) {
14431 vty_out(vty, " ");
14432 }
14433 }
14434 }
14435 vty_out(vty, "\n");
14436 }
14437 }
14438 }
14439
14440 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14441 if (use_json)
14442 json_object_boolean_true_add(json_neigh,
14443 "prefixesConfigExceedMax");
14444 else
14445 vty_out(vty,
14446 " Peer had exceeded the max. no. of prefixes configured.\n");
14447
14448 if (p->t_pmax_restart) {
14449 if (use_json) {
14450 json_object_boolean_true_add(
14451 json_neigh, "reducePrefixNumFrom");
14452 json_object_int_add(json_neigh,
14453 "restartInTimerMsec",
14454 thread_timer_remain_second(
14455 p->t_pmax_restart)
14456 * 1000);
14457 } else
14458 vty_out(vty,
14459 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14460 p->host, thread_timer_remain_second(
14461 p->t_pmax_restart));
14462 } else {
14463 if (use_json)
14464 json_object_boolean_true_add(
14465 json_neigh,
14466 "reducePrefixNumAndClearIpBgp");
14467 else
14468 vty_out(vty,
14469 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14470 p->host);
14471 }
14472 }
14473
14474 /* EBGP Multihop and GTSM */
14475 if (p->sort != BGP_PEER_IBGP) {
14476 if (use_json) {
14477 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14478 json_object_int_add(json_neigh,
14479 "externalBgpNbrMaxHopsAway",
14480 p->gtsm_hops);
14481 else
14482 json_object_int_add(json_neigh,
14483 "externalBgpNbrMaxHopsAway",
14484 p->ttl);
14485 } else {
14486 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14487 vty_out(vty,
14488 " External BGP neighbor may be up to %d hops away.\n",
14489 p->gtsm_hops);
14490 else
14491 vty_out(vty,
14492 " External BGP neighbor may be up to %d hops away.\n",
14493 p->ttl);
14494 }
14495 } else {
14496 if (use_json) {
14497 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14498 json_object_int_add(json_neigh,
14499 "internalBgpNbrMaxHopsAway",
14500 p->gtsm_hops);
14501 else
14502 json_object_int_add(json_neigh,
14503 "internalBgpNbrMaxHopsAway",
14504 p->ttl);
14505 } else {
14506 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14507 vty_out(vty,
14508 " Internal BGP neighbor may be up to %d hops away.\n",
14509 p->gtsm_hops);
14510 else
14511 vty_out(vty,
14512 " Internal BGP neighbor may be up to %d hops away.\n",
14513 p->ttl);
14514 }
14515 }
14516
14517 /* Local address. */
14518 if (p->su_local) {
14519 if (use_json) {
14520 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14521 p->su_local);
14522 json_object_int_add(json_neigh, "portLocal",
14523 ntohs(p->su_local->sin.sin_port));
14524 } else
14525 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14526 p->su_local, ntohs(p->su_local->sin.sin_port));
14527 } else {
14528 if (use_json) {
14529 json_object_string_add(json_neigh, "hostLocal",
14530 "Unknown");
14531 json_object_int_add(json_neigh, "portLocal", -1);
14532 }
14533 }
14534
14535 /* Remote address. */
14536 if (p->su_remote) {
14537 if (use_json) {
14538 json_object_string_addf(json_neigh, "hostForeign",
14539 "%pSU", p->su_remote);
14540 json_object_int_add(json_neigh, "portForeign",
14541 ntohs(p->su_remote->sin.sin_port));
14542 } else
14543 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14544 p->su_remote,
14545 ntohs(p->su_remote->sin.sin_port));
14546 } else {
14547 if (use_json) {
14548 json_object_string_add(json_neigh, "hostForeign",
14549 "Unknown");
14550 json_object_int_add(json_neigh, "portForeign", -1);
14551 }
14552 }
14553
14554 /* Nexthop display. */
14555 if (p->su_local) {
14556 if (use_json) {
14557 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14558 &p->nexthop.v4);
14559 json_object_string_addf(json_neigh, "nexthopGlobal",
14560 "%pI6", &p->nexthop.v6_global);
14561 json_object_string_addf(json_neigh, "nexthopLocal",
14562 "%pI6", &p->nexthop.v6_local);
14563 if (p->shared_network)
14564 json_object_string_add(json_neigh,
14565 "bgpConnection",
14566 "sharedNetwork");
14567 else
14568 json_object_string_add(json_neigh,
14569 "bgpConnection",
14570 "nonSharedNetwork");
14571 } else {
14572 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14573 vty_out(vty, "Nexthop global: %pI6\n",
14574 &p->nexthop.v6_global);
14575 vty_out(vty, "Nexthop local: %pI6\n",
14576 &p->nexthop.v6_local);
14577 vty_out(vty, "BGP connection: %s\n",
14578 p->shared_network ? "shared network"
14579 : "non shared network");
14580 }
14581 }
14582
14583 /* Timer information. */
14584 if (use_json) {
14585 json_object_int_add(json_neigh, "connectRetryTimer",
14586 p->v_connect);
14587 if (peer_established(p)) {
14588 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14589 p->rtt);
14590 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14591 json_object_int_add(json_neigh,
14592 "shutdownRttInMsecs",
14593 p->rtt_expected);
14594 json_object_int_add(json_neigh,
14595 "shutdownRttAfterCount",
14596 p->rtt_keepalive_rcv);
14597 }
14598 }
14599 if (p->t_start)
14600 json_object_int_add(
14601 json_neigh, "nextStartTimerDueInMsecs",
14602 thread_timer_remain_second(p->t_start) * 1000);
14603 if (p->t_connect)
14604 json_object_int_add(
14605 json_neigh, "nextConnectTimerDueInMsecs",
14606 thread_timer_remain_second(p->t_connect)
14607 * 1000);
14608 if (p->t_routeadv) {
14609 json_object_int_add(json_neigh, "mraiInterval",
14610 p->v_routeadv);
14611 json_object_int_add(
14612 json_neigh, "mraiTimerExpireInMsecs",
14613 thread_timer_remain_second(p->t_routeadv)
14614 * 1000);
14615 }
14616 if (p->password)
14617 json_object_int_add(json_neigh, "authenticationEnabled",
14618 1);
14619
14620 if (p->t_read)
14621 json_object_string_add(json_neigh, "readThread", "on");
14622 else
14623 json_object_string_add(json_neigh, "readThread", "off");
14624
14625 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14626 json_object_string_add(json_neigh, "writeThread", "on");
14627 else
14628 json_object_string_add(json_neigh, "writeThread",
14629 "off");
14630 } else {
14631 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14632 p->v_connect);
14633 if (peer_established(p)) {
14634 vty_out(vty, "Estimated round trip time: %d ms\n",
14635 p->rtt);
14636 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14637 vty_out(vty,
14638 "Shutdown when RTT > %dms, count > %u\n",
14639 p->rtt_expected, p->rtt_keepalive_rcv);
14640 }
14641 if (p->t_start)
14642 vty_out(vty, "Next start timer due in %ld seconds\n",
14643 thread_timer_remain_second(p->t_start));
14644 if (p->t_connect)
14645 vty_out(vty, "Next connect timer due in %ld seconds\n",
14646 thread_timer_remain_second(p->t_connect));
14647 if (p->t_routeadv)
14648 vty_out(vty,
14649 "MRAI (interval %u) timer expires in %ld seconds\n",
14650 p->v_routeadv,
14651 thread_timer_remain_second(p->t_routeadv));
14652 if (p->password)
14653 vty_out(vty, "Peer Authentication Enabled\n");
14654
14655 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14656 p->t_read ? "on" : "off",
14657 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14658 ? "on"
14659 : "off", p->fd);
14660 }
14661
14662 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14663 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14664 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14665
14666 if (!use_json)
14667 vty_out(vty, "\n");
14668
14669 /* BFD information. */
14670 if (p->bfd_config)
14671 bgp_bfd_show_info(vty, p, json_neigh);
14672
14673 if (use_json) {
14674 if (p->conf_if) /* Configured interface name. */
14675 json_object_object_add(json, p->conf_if, json_neigh);
14676 else /* Configured IP address. */
14677 json_object_object_add(json, p->host, json_neigh);
14678 }
14679 }
14680
14681 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14682 enum show_type type,
14683 union sockunion *su,
14684 const char *conf_if, afi_t afi,
14685 bool use_json)
14686 {
14687 struct listnode *node, *nnode;
14688 struct peer *peer;
14689 int find = 0;
14690 safi_t safi = SAFI_UNICAST;
14691 json_object *json = NULL;
14692 json_object *json_neighbor = NULL;
14693
14694 if (use_json) {
14695 json = json_object_new_object();
14696 json_neighbor = json_object_new_object();
14697 }
14698
14699 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14700
14701 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14702 continue;
14703
14704 if ((peer->afc[afi][safi]) == 0)
14705 continue;
14706
14707 if (type == show_all) {
14708 bgp_show_peer_gr_status(vty, peer, use_json,
14709 json_neighbor);
14710
14711 if (use_json) {
14712 json_object_object_add(json, peer->host,
14713 json_neighbor);
14714 json_neighbor = NULL;
14715 }
14716
14717 } else if (type == show_peer) {
14718 if (conf_if) {
14719 if ((peer->conf_if
14720 && !strcmp(peer->conf_if, conf_if))
14721 || (peer->hostname
14722 && !strcmp(peer->hostname, conf_if))) {
14723 find = 1;
14724 bgp_show_peer_gr_status(vty, peer,
14725 use_json,
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 use_json,
14733 json_neighbor);
14734 }
14735 }
14736 if (use_json && find)
14737 json_object_object_add(json, peer->host,
14738 json_neighbor);
14739 }
14740
14741 if (find) {
14742 json_neighbor = NULL;
14743 break;
14744 }
14745 }
14746
14747 if (type == show_peer && !find) {
14748 if (use_json)
14749 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14750 else
14751 vty_out(vty, "%% No such neighbor\n");
14752 }
14753 if (use_json) {
14754 if (json_neighbor)
14755 json_object_free(json_neighbor);
14756 vty_json(vty, json);
14757 } else {
14758 vty_out(vty, "\n");
14759 }
14760
14761 return CMD_SUCCESS;
14762 }
14763
14764 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14765 enum show_type type, union sockunion *su,
14766 const char *conf_if, bool use_json,
14767 json_object *json)
14768 {
14769 struct listnode *node, *nnode;
14770 struct peer *peer;
14771 int find = 0;
14772 bool nbr_output = false;
14773 afi_t afi = AFI_MAX;
14774 safi_t safi = SAFI_MAX;
14775
14776 if (type == show_ipv4_peer || type == show_ipv4_all) {
14777 afi = AFI_IP;
14778 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14779 afi = AFI_IP6;
14780 }
14781
14782 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14783 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14784 continue;
14785
14786 switch (type) {
14787 case show_all:
14788 bgp_show_peer(vty, peer, use_json, json);
14789 nbr_output = true;
14790 break;
14791 case show_peer:
14792 if (conf_if) {
14793 if ((peer->conf_if
14794 && !strcmp(peer->conf_if, conf_if))
14795 || (peer->hostname
14796 && !strcmp(peer->hostname, conf_if))) {
14797 find = 1;
14798 bgp_show_peer(vty, peer, use_json,
14799 json);
14800 }
14801 } else {
14802 if (sockunion_same(&peer->su, su)) {
14803 find = 1;
14804 bgp_show_peer(vty, peer, use_json,
14805 json);
14806 }
14807 }
14808 break;
14809 case show_ipv4_peer:
14810 case show_ipv6_peer:
14811 FOREACH_SAFI (safi) {
14812 if (peer->afc[afi][safi]) {
14813 if (conf_if) {
14814 if ((peer->conf_if
14815 && !strcmp(peer->conf_if, conf_if))
14816 || (peer->hostname
14817 && !strcmp(peer->hostname, conf_if))) {
14818 find = 1;
14819 bgp_show_peer(vty, peer, use_json,
14820 json);
14821 break;
14822 }
14823 } else {
14824 if (sockunion_same(&peer->su, su)) {
14825 find = 1;
14826 bgp_show_peer(vty, peer, use_json,
14827 json);
14828 break;
14829 }
14830 }
14831 }
14832 }
14833 break;
14834 case show_ipv4_all:
14835 case show_ipv6_all:
14836 FOREACH_SAFI (safi) {
14837 if (peer->afc[afi][safi]) {
14838 bgp_show_peer(vty, peer, use_json, json);
14839 nbr_output = true;
14840 break;
14841 }
14842 }
14843 break;
14844 }
14845 }
14846
14847 if ((type == show_peer || type == show_ipv4_peer ||
14848 type == show_ipv6_peer) && !find) {
14849 if (use_json)
14850 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14851 else
14852 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14853 }
14854
14855 if (type != show_peer && type != show_ipv4_peer &&
14856 type != show_ipv6_peer && !nbr_output && !use_json)
14857 vty_out(vty, "%% No BGP neighbors found\n");
14858
14859 if (use_json) {
14860 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14861 json, JSON_C_TO_STRING_PRETTY));
14862 } else {
14863 vty_out(vty, "\n");
14864 }
14865
14866 return CMD_SUCCESS;
14867 }
14868
14869 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14870 enum show_type type,
14871 const char *ip_str,
14872 afi_t afi, bool use_json)
14873 {
14874
14875 int ret;
14876 struct bgp *bgp;
14877 union sockunion su;
14878
14879 bgp = bgp_get_default();
14880
14881 if (!bgp)
14882 return;
14883
14884 if (!use_json)
14885 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14886 NULL);
14887
14888 if (ip_str) {
14889 ret = str2sockunion(ip_str, &su);
14890 if (ret < 0)
14891 bgp_show_neighbor_graceful_restart(
14892 vty, bgp, type, NULL, ip_str, afi, use_json);
14893 else
14894 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14895 NULL, afi, use_json);
14896 } else
14897 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14898 afi, use_json);
14899 }
14900
14901 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14902 enum show_type type,
14903 const char *ip_str,
14904 bool use_json)
14905 {
14906 struct listnode *node, *nnode;
14907 struct bgp *bgp;
14908 union sockunion su;
14909 json_object *json = NULL;
14910 int ret, is_first = 1;
14911 bool nbr_output = false;
14912
14913 if (use_json)
14914 vty_out(vty, "{\n");
14915
14916 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14917 nbr_output = true;
14918 if (use_json) {
14919 if (!(json = json_object_new_object())) {
14920 flog_err(
14921 EC_BGP_JSON_MEM_ERROR,
14922 "Unable to allocate memory for JSON object");
14923 vty_out(vty,
14924 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14925 return;
14926 }
14927
14928 json_object_int_add(json, "vrfId",
14929 (bgp->vrf_id == VRF_UNKNOWN)
14930 ? -1
14931 : (int64_t)bgp->vrf_id);
14932 json_object_string_add(
14933 json, "vrfName",
14934 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14935 ? VRF_DEFAULT_NAME
14936 : bgp->name);
14937
14938 if (!is_first)
14939 vty_out(vty, ",\n");
14940 else
14941 is_first = 0;
14942
14943 vty_out(vty, "\"%s\":",
14944 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14945 ? VRF_DEFAULT_NAME
14946 : bgp->name);
14947 } else {
14948 vty_out(vty, "\nInstance %s:\n",
14949 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14950 ? VRF_DEFAULT_NAME
14951 : bgp->name);
14952 }
14953
14954 if (type == show_peer || type == show_ipv4_peer ||
14955 type == show_ipv6_peer) {
14956 ret = str2sockunion(ip_str, &su);
14957 if (ret < 0)
14958 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14959 use_json, json);
14960 else
14961 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14962 use_json, json);
14963 } else {
14964 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14965 use_json, json);
14966 }
14967 json_object_free(json);
14968 json = NULL;
14969 }
14970
14971 if (use_json)
14972 vty_out(vty, "}\n");
14973 else if (!nbr_output)
14974 vty_out(vty, "%% BGP instance not found\n");
14975 }
14976
14977 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14978 enum show_type type, const char *ip_str,
14979 bool use_json)
14980 {
14981 int ret;
14982 struct bgp *bgp;
14983 union sockunion su;
14984 json_object *json = NULL;
14985
14986 if (name) {
14987 if (strmatch(name, "all")) {
14988 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14989 use_json);
14990 return CMD_SUCCESS;
14991 } else {
14992 bgp = bgp_lookup_by_name(name);
14993 if (!bgp) {
14994 if (use_json) {
14995 json = json_object_new_object();
14996 vty_json(vty, json);
14997 } else
14998 vty_out(vty,
14999 "%% BGP instance not found\n");
15000
15001 return CMD_WARNING;
15002 }
15003 }
15004 } else {
15005 bgp = bgp_get_default();
15006 }
15007
15008 if (bgp) {
15009 json = json_object_new_object();
15010 if (ip_str) {
15011 ret = str2sockunion(ip_str, &su);
15012 if (ret < 0)
15013 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15014 use_json, json);
15015 else
15016 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15017 use_json, json);
15018 } else {
15019 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15020 json);
15021 }
15022 json_object_free(json);
15023 } else {
15024 if (use_json)
15025 vty_out(vty, "{}\n");
15026 else
15027 vty_out(vty, "%% BGP instance not found\n");
15028 }
15029
15030 return CMD_SUCCESS;
15031 }
15032
15033
15034
15035 /* "show [ip] bgp neighbors graceful-restart" commands. */
15036 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15037 show_ip_bgp_neighbors_graceful_restart_cmd,
15038 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15039 SHOW_STR
15040 BGP_STR
15041 IP_STR
15042 IPV6_STR
15043 NEIGHBOR_STR
15044 "Neighbor to display information about\n"
15045 "Neighbor to display information about\n"
15046 "Neighbor on BGP configured interface\n"
15047 GR_SHOW
15048 JSON_STR)
15049 {
15050 char *sh_arg = NULL;
15051 enum show_type sh_type;
15052 int idx = 0;
15053 afi_t afi = AFI_MAX;
15054 bool uj = use_json(argc, argv);
15055
15056 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15057 afi = AFI_MAX;
15058
15059 idx++;
15060
15061 if (argv_find(argv, argc, "A.B.C.D", &idx)
15062 || argv_find(argv, argc, "X:X::X:X", &idx)
15063 || argv_find(argv, argc, "WORD", &idx)) {
15064 sh_type = show_peer;
15065 sh_arg = argv[idx]->arg;
15066 } else
15067 sh_type = show_all;
15068
15069 if (!argv_find(argv, argc, "graceful-restart", &idx))
15070 return CMD_SUCCESS;
15071
15072
15073 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15074 afi, uj);
15075 }
15076
15077 /* "show [ip] bgp neighbors" commands. */
15078 DEFUN (show_ip_bgp_neighbors,
15079 show_ip_bgp_neighbors_cmd,
15080 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15081 SHOW_STR
15082 IP_STR
15083 BGP_STR
15084 BGP_INSTANCE_HELP_STR
15085 BGP_AF_STR
15086 BGP_AF_STR
15087 "Detailed information on TCP and BGP neighbor connections\n"
15088 "Neighbor to display information about\n"
15089 "Neighbor to display information about\n"
15090 "Neighbor on BGP configured interface\n"
15091 JSON_STR)
15092 {
15093 char *vrf = NULL;
15094 char *sh_arg = NULL;
15095 enum show_type sh_type;
15096 afi_t afi = AFI_MAX;
15097
15098 bool uj = use_json(argc, argv);
15099
15100 int idx = 0;
15101
15102 /* [<vrf> VIEWVRFNAME] */
15103 if (argv_find(argv, argc, "vrf", &idx)) {
15104 vrf = argv[idx + 1]->arg;
15105 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15106 vrf = NULL;
15107 } else if (argv_find(argv, argc, "view", &idx))
15108 /* [<view> VIEWVRFNAME] */
15109 vrf = argv[idx + 1]->arg;
15110
15111 idx++;
15112
15113 if (argv_find(argv, argc, "ipv4", &idx)) {
15114 sh_type = show_ipv4_all;
15115 afi = AFI_IP;
15116 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15117 sh_type = show_ipv6_all;
15118 afi = AFI_IP6;
15119 } else {
15120 sh_type = show_all;
15121 }
15122
15123 if (argv_find(argv, argc, "A.B.C.D", &idx)
15124 || argv_find(argv, argc, "X:X::X:X", &idx)
15125 || argv_find(argv, argc, "WORD", &idx)) {
15126 sh_type = show_peer;
15127 sh_arg = argv[idx]->arg;
15128 }
15129
15130 if (sh_type == show_peer && afi == AFI_IP) {
15131 sh_type = show_ipv4_peer;
15132 } else if (sh_type == show_peer && afi == AFI_IP6) {
15133 sh_type = show_ipv6_peer;
15134 }
15135
15136 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15137 }
15138
15139 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15140 paths' and `show ip mbgp paths'. Those functions results are the
15141 same.*/
15142 DEFUN (show_ip_bgp_paths,
15143 show_ip_bgp_paths_cmd,
15144 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15145 SHOW_STR
15146 IP_STR
15147 BGP_STR
15148 BGP_SAFI_HELP_STR
15149 "Path information\n")
15150 {
15151 vty_out(vty, "Address Refcnt Path\n");
15152 aspath_print_all_vty(vty);
15153 return CMD_SUCCESS;
15154 }
15155
15156 #include "hash.h"
15157
15158 static void community_show_all_iterator(struct hash_bucket *bucket,
15159 struct vty *vty)
15160 {
15161 struct community *com;
15162
15163 com = (struct community *)bucket->data;
15164 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15165 community_str(com, false, false));
15166 }
15167
15168 /* Show BGP's community internal data. */
15169 DEFUN (show_ip_bgp_community_info,
15170 show_ip_bgp_community_info_cmd,
15171 "show [ip] bgp community-info",
15172 SHOW_STR
15173 IP_STR
15174 BGP_STR
15175 "List all bgp community information\n")
15176 {
15177 vty_out(vty, "Address Refcnt Community\n");
15178
15179 hash_iterate(community_hash(),
15180 (void (*)(struct hash_bucket *,
15181 void *))community_show_all_iterator,
15182 vty);
15183
15184 return CMD_SUCCESS;
15185 }
15186
15187 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15188 struct vty *vty)
15189 {
15190 struct lcommunity *lcom;
15191
15192 lcom = (struct lcommunity *)bucket->data;
15193 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15194 lcommunity_str(lcom, false, false));
15195 }
15196
15197 /* Show BGP's community internal data. */
15198 DEFUN (show_ip_bgp_lcommunity_info,
15199 show_ip_bgp_lcommunity_info_cmd,
15200 "show ip bgp large-community-info",
15201 SHOW_STR
15202 IP_STR
15203 BGP_STR
15204 "List all bgp large-community information\n")
15205 {
15206 vty_out(vty, "Address Refcnt Large-community\n");
15207
15208 hash_iterate(lcommunity_hash(),
15209 (void (*)(struct hash_bucket *,
15210 void *))lcommunity_show_all_iterator,
15211 vty);
15212
15213 return CMD_SUCCESS;
15214 }
15215 /* Graceful Restart */
15216
15217 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15218 struct bgp *bgp,
15219 bool use_json,
15220 json_object *json)
15221 {
15222
15223
15224 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15225
15226 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15227
15228 switch (bgp_global_gr_mode) {
15229
15230 case GLOBAL_HELPER:
15231 vty_out(vty, "Global BGP GR Mode : Helper\n");
15232 break;
15233
15234 case GLOBAL_GR:
15235 vty_out(vty, "Global BGP GR Mode : Restart\n");
15236 break;
15237
15238 case GLOBAL_DISABLE:
15239 vty_out(vty, "Global BGP GR Mode : Disable\n");
15240 break;
15241
15242 case GLOBAL_INVALID:
15243 vty_out(vty,
15244 "Global BGP GR Mode Invalid\n");
15245 break;
15246 }
15247 vty_out(vty, "\n");
15248 }
15249
15250 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15251 enum show_type type,
15252 const char *ip_str,
15253 afi_t afi, bool use_json)
15254 {
15255 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15256 afi = AFI_IP;
15257
15258 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15259
15260 bgp_show_neighbor_graceful_restart_vty(
15261 vty, type, ip_str, afi, use_json);
15262 afi++;
15263 }
15264 } else if (afi != AFI_MAX) {
15265 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15266 use_json);
15267 } else {
15268 return CMD_ERR_INCOMPLETE;
15269 }
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 }