]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12684 from chiragshah6/fdev2
[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
82 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
83 {
84 .val_bool = false,
85 .match_profile = "traditional",
86 .match_version = "< 7.4",
87 },
88 { .val_bool = true },
89 );
90 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
91 { .val_bool = true, .match_profile = "datacenter", },
92 { .val_bool = false },
93 );
94 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
95 { .val_bool = true, .match_profile = "datacenter", },
96 { .val_bool = false },
97 );
98 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
99 { .val_bool = true, .match_profile = "datacenter", },
100 { .val_bool = false },
101 );
102 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
103 { .val_bool = true, .match_profile = "datacenter", },
104 { .val_bool = false },
105 );
106 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
107 { .val_ulong = 10, .match_profile = "datacenter", },
108 { .val_ulong = 120 },
109 );
110 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
111 { .val_ulong = 9, .match_profile = "datacenter", },
112 { .val_ulong = 180 },
113 );
114 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
115 { .val_ulong = 3, .match_profile = "datacenter", },
116 { .val_ulong = 60 },
117 );
118 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
119 { .val_bool = false, .match_profile = "datacenter", },
120 { .val_bool = false, .match_version = "< 7.4", },
121 { .val_bool = true },
122 );
123 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
124 { .val_bool = false, .match_version = "< 7.6", },
125 { .val_bool = true },
126 );
127 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
128 { .val_bool = false, .match_version = "< 8.3", },
129 { .val_bool = true },
130 );
131 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
132 { .val_bool = false, .match_version = "< 8.3", },
133 { .val_bool = true },
134 );
135
136 DEFINE_HOOK(bgp_inst_config_write,
137 (struct bgp *bgp, struct vty *vty),
138 (bgp, vty));
139 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
140 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
141
142 static struct peer_group *listen_range_exists(struct bgp *bgp,
143 struct prefix *range, int exact);
144
145 /* Show BGP peer's information. */
146 enum show_type {
147 show_all,
148 show_peer,
149 show_ipv4_all,
150 show_ipv6_all,
151 show_ipv4_peer,
152 show_ipv6_peer
153 };
154
155 static struct peer_group *listen_range_exists(struct bgp *bgp,
156 struct prefix *range, int exact);
157
158 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
159 struct bgp *bgp);
160
161 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
162 enum show_type type,
163 const char *ip_str,
164 afi_t afi, bool use_json);
165
166 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
167 {
168 switch (afi) {
169 case AFI_IP:
170 switch (safi) {
171 case SAFI_UNICAST:
172 return BGP_IPV4_NODE;
173 case SAFI_MULTICAST:
174 return BGP_IPV4M_NODE;
175 case SAFI_LABELED_UNICAST:
176 return BGP_IPV4L_NODE;
177 case SAFI_MPLS_VPN:
178 return BGP_VPNV4_NODE;
179 case SAFI_FLOWSPEC:
180 return BGP_FLOWSPECV4_NODE;
181 default:
182 /* not expected */
183 return BGP_IPV4_NODE;
184 }
185 case AFI_IP6:
186 switch (safi) {
187 case SAFI_UNICAST:
188 return BGP_IPV6_NODE;
189 case SAFI_MULTICAST:
190 return BGP_IPV6M_NODE;
191 case SAFI_LABELED_UNICAST:
192 return BGP_IPV6L_NODE;
193 case SAFI_MPLS_VPN:
194 return BGP_VPNV6_NODE;
195 case SAFI_FLOWSPEC:
196 return BGP_FLOWSPECV6_NODE;
197 default:
198 /* not expected */
199 return BGP_IPV4_NODE;
200 }
201 case AFI_L2VPN:
202 return BGP_EVPN_NODE;
203 case AFI_UNSPEC:
204 case AFI_MAX:
205 // We should never be here but to clarify the switch statement..
206 return BGP_IPV4_NODE;
207 }
208
209 // Impossible to happen
210 return BGP_IPV4_NODE;
211 }
212
213 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
214 {
215 if (afi == AFI_IP) {
216 if (safi == SAFI_UNICAST)
217 return "IPv4 Unicast";
218 if (safi == SAFI_MULTICAST)
219 return "IPv4 Multicast";
220 if (safi == SAFI_LABELED_UNICAST)
221 return "IPv4 Labeled Unicast";
222 if (safi == SAFI_MPLS_VPN)
223 return "IPv4 VPN";
224 if (safi == SAFI_ENCAP)
225 return "IPv4 Encap";
226 if (safi == SAFI_FLOWSPEC)
227 return "IPv4 Flowspec";
228 } else if (afi == AFI_IP6) {
229 if (safi == SAFI_UNICAST)
230 return "IPv6 Unicast";
231 if (safi == SAFI_MULTICAST)
232 return "IPv6 Multicast";
233 if (safi == SAFI_LABELED_UNICAST)
234 return "IPv6 Labeled Unicast";
235 if (safi == SAFI_MPLS_VPN)
236 return "IPv6 VPN";
237 if (safi == SAFI_ENCAP)
238 return "IPv6 Encap";
239 if (safi == SAFI_FLOWSPEC)
240 return "IPv6 Flowspec";
241 } else if (afi == AFI_L2VPN) {
242 if (safi == SAFI_EVPN)
243 return "L2VPN EVPN";
244 }
245
246 return "Unknown";
247 }
248
249 /*
250 * Please note that we have intentionally camelCased
251 * the return strings here. So if you want
252 * to use this function, please ensure you
253 * are doing this within json output
254 */
255 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
256 {
257 if (afi == AFI_IP) {
258 if (safi == SAFI_UNICAST)
259 return "ipv4Unicast";
260 if (safi == SAFI_MULTICAST)
261 return "ipv4Multicast";
262 if (safi == SAFI_LABELED_UNICAST)
263 return "ipv4LabeledUnicast";
264 if (safi == SAFI_MPLS_VPN)
265 return "ipv4Vpn";
266 if (safi == SAFI_ENCAP)
267 return "ipv4Encap";
268 if (safi == SAFI_FLOWSPEC)
269 return "ipv4Flowspec";
270 } else if (afi == AFI_IP6) {
271 if (safi == SAFI_UNICAST)
272 return "ipv6Unicast";
273 if (safi == SAFI_MULTICAST)
274 return "ipv6Multicast";
275 if (safi == SAFI_LABELED_UNICAST)
276 return "ipv6LabeledUnicast";
277 if (safi == SAFI_MPLS_VPN)
278 return "ipv6Vpn";
279 if (safi == SAFI_ENCAP)
280 return "ipv6Encap";
281 if (safi == SAFI_FLOWSPEC)
282 return "ipv6Flowspec";
283 } else if (afi == AFI_L2VPN) {
284 if (safi == SAFI_EVPN)
285 return "l2VpnEvpn";
286 }
287
288 return "Unknown";
289 }
290
291 /* unset srv6 locator */
292 static int bgp_srv6_locator_unset(struct bgp *bgp)
293 {
294 int ret;
295 struct listnode *node, *nnode;
296 struct srv6_locator_chunk *chunk;
297 struct bgp_srv6_function *func;
298 struct bgp *bgp_vrf;
299
300 /* release chunk notification via ZAPI */
301 ret = bgp_zebra_srv6_manager_release_locator_chunk(
302 bgp->srv6_locator_name);
303 if (ret < 0)
304 return -1;
305
306 /* refresh chunks */
307 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
308 listnode_delete(bgp->srv6_locator_chunks, chunk);
309 srv6_locator_chunk_free(&chunk);
310 }
311
312 /* refresh functions */
313 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
314 listnode_delete(bgp->srv6_functions, func);
315 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
316 }
317
318 /* refresh tovpn_sid */
319 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
320 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
321 continue;
322
323 /* refresh vpnv4 tovpn_sid */
324 XFREE(MTYPE_BGP_SRV6_SID,
325 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
326
327 /* refresh vpnv6 tovpn_sid */
328 XFREE(MTYPE_BGP_SRV6_SID,
329 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
330
331 /* refresh per-vrf tovpn_sid */
332 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
333 }
334
335 /* update vpn bgp processes */
336 vpn_leak_postchange_all();
337
338 /* refresh tovpn_sid_locator */
339 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
340 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
341 continue;
342
343 /* refresh vpnv4 tovpn_sid_locator */
344 srv6_locator_chunk_free(
345 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
346
347 /* refresh vpnv6 tovpn_sid_locator */
348 srv6_locator_chunk_free(
349 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
350
351 /* refresh per-vrf tovpn_sid_locator */
352 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
353 }
354
355 /* clear locator name */
356 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
357
358 return 0;
359 }
360
361 /* Utility function to get address family from current node. */
362 afi_t bgp_node_afi(struct vty *vty)
363 {
364 afi_t afi;
365 switch (vty->node) {
366 case BGP_IPV6_NODE:
367 case BGP_IPV6M_NODE:
368 case BGP_IPV6L_NODE:
369 case BGP_VPNV6_NODE:
370 case BGP_FLOWSPECV6_NODE:
371 afi = AFI_IP6;
372 break;
373 case BGP_EVPN_NODE:
374 afi = AFI_L2VPN;
375 break;
376 default:
377 afi = AFI_IP;
378 break;
379 }
380 return afi;
381 }
382
383 /* Utility function to get subsequent address family from current
384 node. */
385 safi_t bgp_node_safi(struct vty *vty)
386 {
387 safi_t safi;
388 switch (vty->node) {
389 case BGP_VPNV4_NODE:
390 case BGP_VPNV6_NODE:
391 safi = SAFI_MPLS_VPN;
392 break;
393 case BGP_IPV4M_NODE:
394 case BGP_IPV6M_NODE:
395 safi = SAFI_MULTICAST;
396 break;
397 case BGP_EVPN_NODE:
398 safi = SAFI_EVPN;
399 break;
400 case BGP_IPV4L_NODE:
401 case BGP_IPV6L_NODE:
402 safi = SAFI_LABELED_UNICAST;
403 break;
404 case BGP_FLOWSPECV4_NODE:
405 case BGP_FLOWSPECV6_NODE:
406 safi = SAFI_FLOWSPEC;
407 break;
408 default:
409 safi = SAFI_UNICAST;
410 break;
411 }
412 return safi;
413 }
414
415 /**
416 * Converts an AFI in string form to afi_t
417 *
418 * @param afi string, one of
419 * - "ipv4"
420 * - "ipv6"
421 * - "l2vpn"
422 * @return the corresponding afi_t
423 */
424 afi_t bgp_vty_afi_from_str(const char *afi_str)
425 {
426 afi_t afi = AFI_MAX; /* unknown */
427 if (strmatch(afi_str, "ipv4"))
428 afi = AFI_IP;
429 else if (strmatch(afi_str, "ipv6"))
430 afi = AFI_IP6;
431 else if (strmatch(afi_str, "l2vpn"))
432 afi = AFI_L2VPN;
433 return afi;
434 }
435
436 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
437 afi_t *afi)
438 {
439 int ret = 0;
440 if (argv_find(argv, argc, "ipv4", index)) {
441 ret = 1;
442 if (afi)
443 *afi = AFI_IP;
444 } else if (argv_find(argv, argc, "ipv6", index)) {
445 ret = 1;
446 if (afi)
447 *afi = AFI_IP6;
448 } else if (argv_find(argv, argc, "l2vpn", index)) {
449 ret = 1;
450 if (afi)
451 *afi = AFI_L2VPN;
452 }
453 return ret;
454 }
455
456 /* supports <unicast|multicast|vpn|labeled-unicast> */
457 safi_t bgp_vty_safi_from_str(const char *safi_str)
458 {
459 safi_t safi = SAFI_MAX; /* unknown */
460 if (strmatch(safi_str, "multicast"))
461 safi = SAFI_MULTICAST;
462 else if (strmatch(safi_str, "unicast"))
463 safi = SAFI_UNICAST;
464 else if (strmatch(safi_str, "vpn"))
465 safi = SAFI_MPLS_VPN;
466 else if (strmatch(safi_str, "evpn"))
467 safi = SAFI_EVPN;
468 else if (strmatch(safi_str, "labeled-unicast"))
469 safi = SAFI_LABELED_UNICAST;
470 else if (strmatch(safi_str, "flowspec"))
471 safi = SAFI_FLOWSPEC;
472 return safi;
473 }
474
475 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
476 safi_t *safi)
477 {
478 int ret = 0;
479 if (argv_find(argv, argc, "unicast", index)) {
480 ret = 1;
481 if (safi)
482 *safi = SAFI_UNICAST;
483 } else if (argv_find(argv, argc, "multicast", index)) {
484 ret = 1;
485 if (safi)
486 *safi = SAFI_MULTICAST;
487 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_LABELED_UNICAST;
491 } else if (argv_find(argv, argc, "vpn", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_MPLS_VPN;
495 } else if (argv_find(argv, argc, "evpn", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_EVPN;
499 } else if (argv_find(argv, argc, "flowspec", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_FLOWSPEC;
503 }
504 return ret;
505 }
506
507 /*
508 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
509 *
510 * afi
511 * address-family identifier
512 *
513 * safi
514 * subsequent address-family identifier
515 *
516 * Returns:
517 * default_af string corresponding to the supplied afi/safi pair.
518 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
519 * return -1.
520 */
521 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
522 {
523 switch (afi) {
524 case AFI_IP:
525 switch (safi) {
526 case SAFI_UNICAST:
527 return "ipv4-unicast";
528 case SAFI_MULTICAST:
529 return "ipv4-multicast";
530 case SAFI_MPLS_VPN:
531 return "ipv4-vpn";
532 case SAFI_ENCAP:
533 return "ipv4-encap";
534 case SAFI_LABELED_UNICAST:
535 return "ipv4-labeled-unicast";
536 case SAFI_FLOWSPEC:
537 return "ipv4-flowspec";
538 default:
539 return "unknown-afi/safi";
540 }
541 break;
542 case AFI_IP6:
543 switch (safi) {
544 case SAFI_UNICAST:
545 return "ipv6-unicast";
546 case SAFI_MULTICAST:
547 return "ipv6-multicast";
548 case SAFI_MPLS_VPN:
549 return "ipv6-vpn";
550 case SAFI_ENCAP:
551 return "ipv6-encap";
552 case SAFI_LABELED_UNICAST:
553 return "ipv6-labeled-unicast";
554 case SAFI_FLOWSPEC:
555 return "ipv6-flowspec";
556 default:
557 return "unknown-afi/safi";
558 }
559 break;
560 case AFI_L2VPN:
561 switch (safi) {
562 case SAFI_EVPN:
563 return "l2vpn-evpn";
564 default:
565 return "unknown-afi/safi";
566 }
567 case AFI_UNSPEC:
568 case AFI_MAX:
569 return "unknown-afi/safi";
570 }
571 /* all AFIs are accounted for above, so this shouldn't happen */
572 return "unknown-afi/safi";
573 }
574
575 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
576 enum bgp_instance_type inst_type)
577 {
578 int ret = bgp_get(bgp, as, name, inst_type);
579
580 if (ret == BGP_CREATED) {
581 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
582 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
583
584 if (DFLT_BGP_IMPORT_CHECK)
585 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
586 if (DFLT_BGP_SHOW_HOSTNAME)
587 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
588 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
590 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
592 if (DFLT_BGP_DETERMINISTIC_MED)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
594 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
596 if (DFLT_BGP_SUPPRESS_DUPLICATES)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
598 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
600 if (DFLT_BGP_HARD_ADMIN_RESET)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
602
603 ret = BGP_SUCCESS;
604 }
605 return ret;
606 }
607
608 /*
609 * bgp_vty_find_and_parse_afi_safi_bgp
610 *
611 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
612 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
613 * to appropriate values for the calling function. This is to allow the
614 * calling function to make decisions appropriate for the show command
615 * that is being parsed.
616 *
617 * The show commands are generally of the form:
618 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
619 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
620 *
621 * Since we use argv_find if the show command in particular doesn't have:
622 * [ip]
623 * [<view|vrf> VIEWVRFNAME]
624 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
625 * The command parsing should still be ok.
626 *
627 * vty -> The vty for the command so we can output some useful data in
628 * the event of a parse error in the vrf.
629 * argv -> The command tokens
630 * argc -> How many command tokens we have
631 * idx -> The current place in the command, generally should be 0 for this
632 * function
633 * afi -> The parsed afi if it was included in the show command, returned here
634 * safi -> The parsed safi if it was included in the show command, returned here
635 * bgp -> Pointer to the bgp data structure we need to fill in.
636 * use_json -> json is configured or not
637 *
638 * The function returns the correct location in the parse tree for the
639 * last token found.
640 *
641 * Returns 0 for failure to parse correctly, else the idx position of where
642 * it found the last token.
643 */
644 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
645 struct cmd_token **argv, int argc,
646 int *idx, afi_t *afi, safi_t *safi,
647 struct bgp **bgp, bool use_json)
648 {
649 char *vrf_name = NULL;
650
651 assert(afi);
652 assert(safi);
653 assert(bgp);
654
655 if (argv_find(argv, argc, "ip", idx))
656 *afi = AFI_IP;
657
658 if (argv_find(argv, argc, "view", idx))
659 vrf_name = argv[*idx + 1]->arg;
660 else if (argv_find(argv, argc, "vrf", idx)) {
661 vrf_name = argv[*idx + 1]->arg;
662 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
663 vrf_name = NULL;
664 }
665 if (vrf_name) {
666 if (strmatch(vrf_name, "all"))
667 *bgp = NULL;
668 else {
669 *bgp = bgp_lookup_by_name(vrf_name);
670 if (!*bgp) {
671 if (use_json) {
672 json_object *json = NULL;
673 json = json_object_new_object();
674 json_object_string_add(
675 json, "warning",
676 "View/Vrf is unknown");
677 vty_json(vty, json);
678 }
679 else
680 vty_out(vty, "View/Vrf %s is unknown\n",
681 vrf_name);
682 *idx = 0;
683 return 0;
684 }
685 }
686 } else {
687 *bgp = bgp_get_default();
688 if (!*bgp) {
689 if (use_json) {
690 json_object *json = NULL;
691 json = json_object_new_object();
692 json_object_string_add(
693 json, "warning",
694 "Default BGP instance not found");
695 vty_json(vty, json);
696 }
697 else
698 vty_out(vty,
699 "Default BGP instance not found\n");
700 *idx = 0;
701 return 0;
702 }
703 }
704
705 if (argv_find_and_parse_afi(argv, argc, idx, afi))
706 argv_find_and_parse_safi(argv, argc, idx, safi);
707
708 *idx += 1;
709 return *idx;
710 }
711
712 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
713 {
714 struct interface *ifp = NULL;
715 struct listnode *node;
716 struct bgp_listener *listener;
717 union sockunion all_su;
718
719 if (su->sa.sa_family == AF_INET) {
720 (void)str2sockunion("0.0.0.0", &all_su);
721 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
722 } else if (su->sa.sa_family == AF_INET6) {
723 (void)str2sockunion("::", &all_su);
724 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
725 su->sin6.sin6_scope_id,
726 bgp->vrf_id);
727 }
728
729 if (ifp) {
730 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
731 if (sockunion_family(su) !=
732 sockunion_family(&listener->su))
733 continue;
734
735 /* If 0.0.0.0/:: is a listener, then treat as self and
736 * reject.
737 */
738 if (!sockunion_cmp(&listener->su, su) ||
739 !sockunion_cmp(&listener->su, &all_su))
740 return true;
741 }
742 }
743
744 return false;
745 }
746
747 /* Utility function for looking up peer from VTY. */
748 /* This is used only for configuration, so disallow if attempted on
749 * a dynamic neighbor.
750 */
751 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
752 {
753 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
754 int ret;
755 union sockunion su;
756 struct peer *peer;
757
758 if (!bgp) {
759 return NULL;
760 }
761
762 ret = str2sockunion(ip_str, &su);
763 if (ret < 0) {
764 peer = peer_lookup_by_conf_if(bgp, ip_str);
765 if (!peer) {
766 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
767 == NULL) {
768 vty_out(vty,
769 "%% Malformed address or name: %s\n",
770 ip_str);
771 return NULL;
772 }
773 }
774 } else {
775 peer = peer_lookup(bgp, &su);
776 if (!peer) {
777 vty_out(vty,
778 "%% Specify remote-as or peer-group commands first\n");
779 return NULL;
780 }
781 if (peer_dynamic_neighbor(peer)) {
782 vty_out(vty,
783 "%% Operation not allowed on a dynamic neighbor\n");
784 return NULL;
785 }
786 }
787 return peer;
788 }
789
790 /* Utility function for looking up peer or peer group. */
791 /* This is used only for configuration, so disallow if attempted on
792 * a dynamic neighbor.
793 */
794 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
795 {
796 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
797 int ret;
798 union sockunion su;
799 struct peer *peer = NULL;
800 struct peer_group *group = NULL;
801
802 if (!bgp) {
803 return NULL;
804 }
805
806 ret = str2sockunion(peer_str, &su);
807 if (ret == 0) {
808 /* IP address, locate peer. */
809 peer = peer_lookup(bgp, &su);
810 } else {
811 /* Not IP, could match either peer configured on interface or a
812 * group. */
813 peer = peer_lookup_by_conf_if(bgp, peer_str);
814 if (!peer)
815 group = peer_group_lookup(bgp, peer_str);
816 }
817
818 if (peer) {
819 if (peer_dynamic_neighbor(peer)) {
820 zlog_warn(
821 "%pBP: Operation not allowed on a dynamic neighbor",
822 peer);
823 vty_out(vty,
824 "%% Operation not allowed on a dynamic neighbor\n");
825 return NULL;
826 }
827
828 return peer;
829 }
830
831 if (group)
832 return group->conf;
833
834 zlog_warn("Specify remote-as or peer-group commands first before: %s",
835 vty->buf);
836 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
837
838 return NULL;
839 }
840
841 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
842 {
843 const char *str = NULL;
844
845 switch (ret) {
846 case BGP_SUCCESS:
847 case BGP_CREATED:
848 case BGP_GR_NO_OPERATION:
849 break;
850 case BGP_ERR_INVALID_VALUE:
851 str = "Invalid value";
852 break;
853 case BGP_ERR_INVALID_FLAG:
854 str = "Invalid flag";
855 break;
856 case BGP_ERR_PEER_GROUP_SHUTDOWN:
857 str = "Peer-group has been shutdown. Activate the peer-group first";
858 break;
859 case BGP_ERR_PEER_FLAG_CONFLICT:
860 str = "Can't set override-capability and strict-capability-match at the same time";
861 break;
862 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
863 str = "Specify remote-as or peer-group remote AS first";
864 break;
865 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
866 str = "Cannot change the peer-group. Deconfigure first";
867 break;
868 case BGP_ERR_PEER_GROUP_MISMATCH:
869 str = "Peer is not a member of this peer-group";
870 break;
871 case BGP_ERR_PEER_FILTER_CONFLICT:
872 str = "Prefix/distribute list can not co-exist";
873 break;
874 case BGP_ERR_NOT_INTERNAL_PEER:
875 str = "Invalid command. Not an internal neighbor";
876 break;
877 case BGP_ERR_REMOVE_PRIVATE_AS:
878 str = "remove-private-AS cannot be configured for IBGP peers";
879 break;
880 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
881 str = "Cannot have local-as same as BGP AS number";
882 break;
883 case BGP_ERR_TCPSIG_FAILED:
884 str = "Error while applying TCP-Sig to session(s)";
885 break;
886 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
887 str = "ebgp-multihop and ttl-security cannot be configured together";
888 break;
889 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
890 str = "ttl-security only allowed for EBGP peers";
891 break;
892 case BGP_ERR_AS_OVERRIDE:
893 str = "as-override cannot be configured for IBGP peers";
894 break;
895 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
896 str = "Invalid limit for number of dynamic neighbors";
897 break;
898 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
899 str = "Dynamic neighbor listen range already exists";
900 break;
901 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
902 str = "Operation not allowed on a dynamic neighbor";
903 break;
904 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
905 str = "Operation not allowed on a directly connected neighbor";
906 break;
907 case BGP_ERR_PEER_SAFI_CONFLICT:
908 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
909 break;
910 case BGP_ERR_GR_INVALID_CMD:
911 str = "The Graceful Restart command used is not valid at this moment.";
912 break;
913 case BGP_ERR_GR_OPERATION_FAILED:
914 str = "The Graceful Restart Operation failed due to an err.";
915 break;
916 case BGP_ERR_PEER_GROUP_MEMBER:
917 str = "Peer-group member cannot override remote-as of peer-group.";
918 break;
919 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
920 str = "Peer-group members must be all internal or all external.";
921 break;
922 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
923 str = "Range specified cannot be deleted because it is not part of current config.";
924 break;
925 case BGP_ERR_INSTANCE_MISMATCH:
926 str = "Instance specified does not match the current instance.";
927 break;
928 case BGP_ERR_NO_INTERFACE_CONFIG:
929 str = "Interface specified is not being used for interface based peer.";
930 break;
931 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
932 str = "No configuration already specified for soft reconfiguration.";
933 break;
934 case BGP_ERR_AS_MISMATCH:
935 str = "BGP is already running.";
936 break;
937 case BGP_ERR_AF_UNCONFIGURED:
938 str = "AFI/SAFI specified is not currently configured.";
939 break;
940 case BGP_ERR_INVALID_AS:
941 str = "Confederation AS specified is the same AS as our AS.";
942 break;
943 case BGP_ERR_INVALID_ROLE_NAME:
944 str = "Invalid role name";
945 break;
946 case BGP_ERR_INVALID_INTERNAL_ROLE:
947 str = "External roles can be set only on eBGP session";
948 break;
949 }
950 if (str) {
951 vty_out(vty, "%% %s\n", str);
952 return CMD_WARNING_CONFIG_FAILED;
953 }
954 return CMD_SUCCESS;
955 }
956
957 /* BGP clear sort. */
958 enum clear_sort {
959 clear_all,
960 clear_peer,
961 clear_group,
962 clear_external,
963 clear_as
964 };
965
966 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
967 safi_t safi, int error)
968 {
969 switch (error) {
970 case BGP_ERR_AF_UNCONFIGURED:
971 if (vty)
972 vty_out(vty,
973 "%% BGP: Enable %s address family for the neighbor %s\n",
974 get_afi_safi_str(afi, safi, false), peer->host);
975 else
976 zlog_warn(
977 "%% BGP: Enable %s address family for the neighbor %s",
978 get_afi_safi_str(afi, safi, false), peer->host);
979 break;
980 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
981 if (vty)
982 vty_out(vty,
983 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
984 peer->host);
985 else
986 zlog_warn(
987 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
988 peer->host);
989 break;
990 default:
991 break;
992 }
993 }
994
995 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
996 struct listnode **nnode, enum bgp_clear_type stype)
997 {
998 int ret = 0;
999 struct peer_af *paf;
1000
1001 /* if afi/.safi not specified, spin thru all of them */
1002 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1003 afi_t tmp_afi;
1004 safi_t tmp_safi;
1005 enum bgp_af_index index;
1006
1007 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1008 paf = peer->peer_af_array[index];
1009 if (!paf)
1010 continue;
1011
1012 if (paf && paf->subgroup)
1013 SET_FLAG(paf->subgroup->sflags,
1014 SUBGRP_STATUS_FORCE_UPDATES);
1015
1016 tmp_afi = paf->afi;
1017 tmp_safi = paf->safi;
1018 if (!peer->afc[tmp_afi][tmp_safi])
1019 continue;
1020
1021 if (stype == BGP_CLEAR_SOFT_NONE)
1022 ret = peer_clear(peer, nnode);
1023 else
1024 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1025 stype);
1026 }
1027 /* if afi specified and safi not, spin thru safis on this afi */
1028 } else if (safi == SAFI_UNSPEC) {
1029 safi_t tmp_safi;
1030
1031 for (tmp_safi = SAFI_UNICAST;
1032 tmp_safi < SAFI_MAX; tmp_safi++) {
1033 if (!peer->afc[afi][tmp_safi])
1034 continue;
1035
1036 paf = peer_af_find(peer, afi, tmp_safi);
1037 if (paf && paf->subgroup)
1038 SET_FLAG(paf->subgroup->sflags,
1039 SUBGRP_STATUS_FORCE_UPDATES);
1040
1041 if (stype == BGP_CLEAR_SOFT_NONE)
1042 ret = peer_clear(peer, nnode);
1043 else
1044 ret = peer_clear_soft(peer, afi,
1045 tmp_safi, stype);
1046 }
1047 /* both afi/safi specified, let the caller know if not defined */
1048 } else {
1049 if (!peer->afc[afi][safi])
1050 return 1;
1051
1052 paf = peer_af_find(peer, afi, safi);
1053 if (paf && paf->subgroup)
1054 SET_FLAG(paf->subgroup->sflags,
1055 SUBGRP_STATUS_FORCE_UPDATES);
1056
1057 if (stype == BGP_CLEAR_SOFT_NONE)
1058 ret = peer_clear(peer, nnode);
1059 else
1060 ret = peer_clear_soft(peer, afi, safi, stype);
1061 }
1062
1063 return ret;
1064 }
1065
1066 /* `clear ip bgp' functions. */
1067 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1068 enum clear_sort sort, enum bgp_clear_type stype,
1069 const char *arg)
1070 {
1071 int ret = 0;
1072 bool found = false;
1073 struct peer *peer;
1074
1075 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1076
1077 /* Clear all neighbors. */
1078 /*
1079 * Pass along pointer to next node to peer_clear() when walking all
1080 * nodes on the BGP instance as that may get freed if it is a
1081 * doppelganger
1082 */
1083 if (sort == clear_all) {
1084 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1085
1086 bgp_peer_gr_flags_update(peer);
1087
1088 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1089 gr_router_detected = true;
1090
1091 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1092 stype);
1093
1094 if (ret < 0)
1095 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1096 }
1097
1098 if (gr_router_detected
1099 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1100 bgp_zebra_send_capabilities(bgp, false);
1101 } else if (!gr_router_detected
1102 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1103 bgp_zebra_send_capabilities(bgp, true);
1104 }
1105
1106 /* This is to apply read-only mode on this clear. */
1107 if (stype == BGP_CLEAR_SOFT_NONE)
1108 bgp->update_delay_over = 0;
1109
1110 return CMD_SUCCESS;
1111 }
1112
1113 /* Clear specified neighbor. */
1114 if (sort == clear_peer) {
1115 union sockunion su;
1116
1117 /* Make sockunion for lookup. */
1118 ret = str2sockunion(arg, &su);
1119 if (ret < 0) {
1120 peer = peer_lookup_by_conf_if(bgp, arg);
1121 if (!peer) {
1122 peer = peer_lookup_by_hostname(bgp, arg);
1123 if (!peer) {
1124 vty_out(vty,
1125 "Malformed address or name: %s\n",
1126 arg);
1127 return CMD_WARNING;
1128 }
1129 }
1130 } else {
1131 peer = peer_lookup(bgp, &su);
1132 if (!peer) {
1133 vty_out(vty,
1134 "%% BGP: Unknown neighbor - \"%s\"\n",
1135 arg);
1136 return CMD_WARNING;
1137 }
1138 }
1139
1140 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1141 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1142
1143 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1144
1145 /* if afi/safi not defined for this peer, let caller know */
1146 if (ret == 1)
1147 ret = BGP_ERR_AF_UNCONFIGURED;
1148
1149 if (ret < 0)
1150 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1151
1152 return CMD_SUCCESS;
1153 }
1154
1155 /* Clear all neighbors belonging to a specific peer-group. */
1156 if (sort == clear_group) {
1157 struct peer_group *group;
1158
1159 group = peer_group_lookup(bgp, arg);
1160 if (!group) {
1161 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1162 return CMD_WARNING;
1163 }
1164
1165 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1166 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1167
1168 if (ret < 0)
1169 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1170 else
1171 found = true;
1172 }
1173
1174 if (!found)
1175 vty_out(vty,
1176 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1177 get_afi_safi_str(afi, safi, false), arg);
1178
1179 return CMD_SUCCESS;
1180 }
1181
1182 /* Clear all external (eBGP) neighbors. */
1183 if (sort == clear_external) {
1184 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1185 if (peer->sort == BGP_PEER_IBGP)
1186 continue;
1187
1188 bgp_peer_gr_flags_update(peer);
1189
1190 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1191 gr_router_detected = true;
1192
1193 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1194
1195 if (ret < 0)
1196 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1197 else
1198 found = true;
1199 }
1200
1201 if (gr_router_detected
1202 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1203 bgp_zebra_send_capabilities(bgp, false);
1204 } else if (!gr_router_detected
1205 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1206 bgp_zebra_send_capabilities(bgp, true);
1207 }
1208
1209 if (!found)
1210 vty_out(vty,
1211 "%% BGP: No external %s peer is configured\n",
1212 get_afi_safi_str(afi, safi, false));
1213
1214 return CMD_SUCCESS;
1215 }
1216
1217 /* Clear all neighbors belonging to a specific AS. */
1218 if (sort == clear_as) {
1219 as_t as = strtoul(arg, NULL, 10);
1220
1221 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1222 if (peer->as != as)
1223 continue;
1224
1225 bgp_peer_gr_flags_update(peer);
1226
1227 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1228 gr_router_detected = true;
1229
1230 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1231
1232 if (ret < 0)
1233 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1234 else
1235 found = true;
1236 }
1237
1238 if (gr_router_detected
1239 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1240 bgp_zebra_send_capabilities(bgp, false);
1241 } else if (!gr_router_detected
1242 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1243 bgp_zebra_send_capabilities(bgp, true);
1244 }
1245
1246 if (!found)
1247 vty_out(vty,
1248 "%% BGP: No %s peer is configured with AS %s\n",
1249 get_afi_safi_str(afi, safi, false), arg);
1250
1251 return CMD_SUCCESS;
1252 }
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1258 safi_t safi, enum clear_sort sort,
1259 enum bgp_clear_type stype, const char *arg)
1260 {
1261 struct bgp *bgp;
1262
1263 /* BGP structure lookup. */
1264 if (name) {
1265 bgp = bgp_lookup_by_name(name);
1266 if (bgp == NULL) {
1267 vty_out(vty, "Can't find BGP instance %s\n", name);
1268 return CMD_WARNING;
1269 }
1270 } else {
1271 bgp = bgp_get_default();
1272 if (bgp == NULL) {
1273 vty_out(vty, "No BGP process is configured\n");
1274 return CMD_WARNING;
1275 }
1276 }
1277
1278 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1279 }
1280
1281 /* clear soft inbound */
1282 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1283 {
1284 afi_t afi;
1285 safi_t safi;
1286
1287 FOREACH_AFI_SAFI (afi, safi)
1288 bgp_clear_vty(vty, name, afi, safi, clear_all,
1289 BGP_CLEAR_SOFT_IN, NULL);
1290 }
1291
1292 /* clear soft outbound */
1293 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1294 {
1295 afi_t afi;
1296 safi_t safi;
1297
1298 FOREACH_AFI_SAFI (afi, safi)
1299 bgp_clear_vty(vty, name, afi, safi, clear_all,
1300 BGP_CLEAR_SOFT_OUT, NULL);
1301 }
1302
1303
1304 void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1305 {
1306 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1307 }
1308
1309 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1310 uint64_t flag, int set)
1311 {
1312 int ret;
1313 struct peer *peer;
1314
1315 peer = peer_and_group_lookup_vty(vty, ip_str);
1316 if (!peer)
1317 return CMD_WARNING_CONFIG_FAILED;
1318
1319 /*
1320 * If 'neighbor <interface>', then this is for directly connected peers,
1321 * we should not accept disable-connected-check.
1322 */
1323 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1324 vty_out(vty,
1325 "%s is directly connected peer, cannot accept disable-connected-check\n",
1326 ip_str);
1327 return CMD_WARNING_CONFIG_FAILED;
1328 }
1329
1330 if (!set && flag == PEER_FLAG_SHUTDOWN)
1331 peer_tx_shutdown_message_unset(peer);
1332
1333 if (set)
1334 ret = peer_flag_set(peer, flag);
1335 else
1336 ret = peer_flag_unset(peer, flag);
1337
1338 return bgp_vty_return(vty, ret);
1339 }
1340
1341 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1342 {
1343 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1344 }
1345
1346 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1347 uint64_t flag)
1348 {
1349 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1350 }
1351
1352 #include "bgpd/bgp_vty_clippy.c"
1353
1354 DEFUN_HIDDEN (bgp_local_mac,
1355 bgp_local_mac_cmd,
1356 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1357 BGP_STR
1358 "Local MAC config\n"
1359 "VxLAN Network Identifier\n"
1360 "VNI number\n"
1361 "local mac\n"
1362 "mac address\n"
1363 "mac-mobility sequence\n"
1364 "seq number\n")
1365 {
1366 int rv;
1367 vni_t vni;
1368 struct ethaddr mac;
1369 struct ipaddr ip;
1370 uint32_t seq;
1371 struct bgp *bgp;
1372
1373 vni = strtoul(argv[3]->arg, NULL, 10);
1374 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1375 vty_out(vty, "%% Malformed MAC address\n");
1376 return CMD_WARNING;
1377 }
1378 memset(&ip, 0, sizeof(ip));
1379 seq = strtoul(argv[7]->arg, NULL, 10);
1380
1381 bgp = bgp_get_default();
1382 if (!bgp) {
1383 vty_out(vty, "Default BGP instance is not there\n");
1384 return CMD_WARNING;
1385 }
1386
1387 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1388 zero_esi);
1389 if (rv < 0) {
1390 vty_out(vty, "Internal error\n");
1391 return CMD_WARNING;
1392 }
1393
1394 return CMD_SUCCESS;
1395 }
1396
1397 DEFUN_HIDDEN (no_bgp_local_mac,
1398 no_bgp_local_mac_cmd,
1399 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1400 NO_STR
1401 BGP_STR
1402 "Local MAC config\n"
1403 "VxLAN Network Identifier\n"
1404 "VNI number\n"
1405 "local mac\n"
1406 "mac address\n")
1407 {
1408 int rv;
1409 vni_t vni;
1410 struct ethaddr mac;
1411 struct ipaddr ip;
1412 struct bgp *bgp;
1413
1414 vni = strtoul(argv[4]->arg, NULL, 10);
1415 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1416 vty_out(vty, "%% Malformed MAC address\n");
1417 return CMD_WARNING;
1418 }
1419 memset(&ip, 0, sizeof(ip));
1420
1421 bgp = bgp_get_default();
1422 if (!bgp) {
1423 vty_out(vty, "Default BGP instance is not there\n");
1424 return CMD_WARNING;
1425 }
1426
1427 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1428 if (rv < 0) {
1429 vty_out(vty, "Internal error\n");
1430 return CMD_WARNING;
1431 }
1432
1433 return CMD_SUCCESS;
1434 }
1435
1436 DEFUN (no_synchronization,
1437 no_synchronization_cmd,
1438 "no synchronization",
1439 NO_STR
1440 "Perform IGP synchronization\n")
1441 {
1442 return CMD_SUCCESS;
1443 }
1444
1445 DEFUN (no_auto_summary,
1446 no_auto_summary_cmd,
1447 "no auto-summary",
1448 NO_STR
1449 "Enable automatic network number summarization\n")
1450 {
1451 return CMD_SUCCESS;
1452 }
1453
1454 /* "router bgp" commands. */
1455 DEFUN_NOSH (router_bgp,
1456 router_bgp_cmd,
1457 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1458 ROUTER_STR
1459 BGP_STR
1460 AS_STR
1461 BGP_INSTANCE_HELP_STR)
1462 {
1463 int idx_asn = 2;
1464 int idx_view_vrf = 3;
1465 int idx_vrf = 4;
1466 int is_new_bgp = 0;
1467 int ret;
1468 as_t as;
1469 struct bgp *bgp;
1470 const char *name = NULL;
1471 enum bgp_instance_type inst_type;
1472
1473 // "router bgp" without an ASN
1474 if (argc == 2) {
1475 // Pending: Make VRF option available for ASN less config
1476 bgp = bgp_get_default();
1477
1478 if (bgp == NULL) {
1479 vty_out(vty, "%% No BGP process is configured\n");
1480 return CMD_WARNING_CONFIG_FAILED;
1481 }
1482
1483 if (listcount(bm->bgp) > 1) {
1484 vty_out(vty, "%% Please specify ASN and VRF\n");
1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
1487 }
1488
1489 // "router bgp X"
1490 else {
1491 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1492
1493 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1494 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1495 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1496
1497 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1498 if (argc > 3) {
1499 name = argv[idx_vrf]->arg;
1500
1501 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1502 if (strmatch(name, VRF_DEFAULT_NAME))
1503 name = NULL;
1504 else
1505 inst_type = BGP_INSTANCE_TYPE_VRF;
1506 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1507 inst_type = BGP_INSTANCE_TYPE_VIEW;
1508 }
1509
1510 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1511 is_new_bgp = (bgp_lookup(as, name) == NULL);
1512
1513 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1514 switch (ret) {
1515 case BGP_ERR_AS_MISMATCH:
1516 vty_out(vty, "BGP is already running; AS is %u\n", as);
1517 return CMD_WARNING_CONFIG_FAILED;
1518 case BGP_ERR_INSTANCE_MISMATCH:
1519 vty_out(vty,
1520 "BGP instance name and AS number mismatch\n");
1521 vty_out(vty,
1522 "BGP instance is already running; AS is %u\n",
1523 as);
1524 return CMD_WARNING_CONFIG_FAILED;
1525 }
1526
1527 /*
1528 * If we just instantiated the default instance, complete
1529 * any pending VRF-VPN leaking that was configured via
1530 * earlier "router bgp X vrf FOO" blocks.
1531 */
1532 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1533 vpn_leak_postchange_all();
1534
1535 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1536 bgp_vpn_leak_export(bgp);
1537 /* Pending: handle when user tries to change a view to vrf n vv.
1538 */
1539 }
1540
1541 /* unset the auto created flag as the user config is now present */
1542 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1543 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1544
1545 return CMD_SUCCESS;
1546 }
1547
1548 /* "no router bgp" commands. */
1549 DEFUN (no_router_bgp,
1550 no_router_bgp_cmd,
1551 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1552 NO_STR
1553 ROUTER_STR
1554 BGP_STR
1555 AS_STR
1556 BGP_INSTANCE_HELP_STR)
1557 {
1558 int idx_asn = 3;
1559 int idx_vrf = 5;
1560 as_t as;
1561 struct bgp *bgp;
1562 const char *name = NULL;
1563
1564 // "no router bgp" without an ASN
1565 if (argc == 3) {
1566 // Pending: Make VRF option available for ASN less config
1567 bgp = bgp_get_default();
1568
1569 if (bgp == NULL) {
1570 vty_out(vty, "%% No BGP process is configured\n");
1571 return CMD_WARNING_CONFIG_FAILED;
1572 }
1573
1574 if (listcount(bm->bgp) > 1) {
1575 vty_out(vty, "%% Please specify ASN and VRF\n");
1576 return CMD_WARNING_CONFIG_FAILED;
1577 }
1578
1579 if (bgp->l3vni) {
1580 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1581 bgp->l3vni);
1582 return CMD_WARNING_CONFIG_FAILED;
1583 }
1584 } else {
1585 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1586
1587 if (argc > 4) {
1588 name = argv[idx_vrf]->arg;
1589 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1590 && strmatch(name, VRF_DEFAULT_NAME))
1591 name = NULL;
1592 }
1593
1594 /* Lookup bgp structure. */
1595 bgp = bgp_lookup(as, name);
1596 if (!bgp) {
1597 vty_out(vty, "%% Can't find BGP instance\n");
1598 return CMD_WARNING_CONFIG_FAILED;
1599 }
1600
1601 if (bgp->l3vni) {
1602 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1603 bgp->l3vni);
1604 return CMD_WARNING_CONFIG_FAILED;
1605 }
1606
1607 /* Cannot delete default instance if vrf instances exist */
1608 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1609 struct listnode *node;
1610 struct bgp *tmp_bgp;
1611
1612 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1613 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1614 continue;
1615 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1616 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1617 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1618 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1619 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1620 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1621 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1622 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1623 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1624 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1625 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1626 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1627 (bgp == bgp_get_evpn() &&
1628 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1629 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1630 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1631 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1632 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1633 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1634 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1635 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1636 (hashcount(tmp_bgp->vnihash))) {
1637 vty_out(vty,
1638 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1639 return CMD_WARNING_CONFIG_FAILED;
1640 }
1641 }
1642 }
1643 }
1644
1645 bgp_delete(bgp);
1646
1647 return CMD_SUCCESS;
1648 }
1649
1650 /* bgp session-dscp */
1651
1652 DEFPY (bgp_session_dscp,
1653 bgp_session_dscp_cmd,
1654 "bgp session-dscp (0-63)$dscp",
1655 BGP_STR
1656 "Override default (C6) bgp TCP session DSCP value\n"
1657 "Manually configured dscp parameter\n")
1658 {
1659 bm->tcp_dscp = dscp << 2;
1660
1661 return CMD_SUCCESS;
1662 }
1663
1664 DEFPY (no_bgp_session_dscp,
1665 no_bgp_session_dscp_cmd,
1666 "no bgp session-dscp [(0-63)]",
1667 NO_STR
1668 BGP_STR
1669 "Override default (C6) bgp TCP session DSCP value\n"
1670 "Manually configured dscp parameter\n")
1671 {
1672 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1673
1674 return CMD_SUCCESS;
1675 }
1676
1677 /* BGP router-id. */
1678
1679 DEFPY (bgp_router_id,
1680 bgp_router_id_cmd,
1681 "bgp router-id A.B.C.D",
1682 BGP_STR
1683 "Override configured router identifier\n"
1684 "Manually configured router identifier\n")
1685 {
1686 VTY_DECLVAR_CONTEXT(bgp, bgp);
1687 bgp_router_id_static_set(bgp, router_id);
1688 return CMD_SUCCESS;
1689 }
1690
1691 DEFPY (no_bgp_router_id,
1692 no_bgp_router_id_cmd,
1693 "no bgp router-id [A.B.C.D]",
1694 NO_STR
1695 BGP_STR
1696 "Override configured router identifier\n"
1697 "Manually configured router identifier\n")
1698 {
1699 VTY_DECLVAR_CONTEXT(bgp, bgp);
1700
1701 if (router_id_str) {
1702 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1703 vty_out(vty, "%% BGP router-id doesn't match\n");
1704 return CMD_WARNING_CONFIG_FAILED;
1705 }
1706 }
1707
1708 router_id.s_addr = 0;
1709 bgp_router_id_static_set(bgp, router_id);
1710
1711 return CMD_SUCCESS;
1712 }
1713
1714 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1715 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1716 NO_STR BGP_STR
1717 "Add community specific parameters\n"
1718 "Create an alias for a community\n"
1719 "Community (AA:BB or AA:BB:CC)\n"
1720 "Alias name\n")
1721 {
1722 struct community_alias ca = {};
1723 struct community_alias *lookup_community;
1724 struct community_alias *lookup_alias;
1725 struct community *comm;
1726 struct lcommunity *lcomm;
1727 uint8_t invalid = 0;
1728
1729 comm = community_str2com(community);
1730 if (!comm)
1731 invalid++;
1732 community_free(&comm);
1733
1734 lcomm = lcommunity_str2com(community);
1735 if (!lcomm)
1736 invalid++;
1737 lcommunity_free(&lcomm);
1738
1739 if (invalid > 1) {
1740 vty_out(vty, "Invalid community format\n");
1741 return CMD_WARNING;
1742 }
1743
1744 strlcpy(ca.community, community, sizeof(ca.community));
1745 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1746
1747 lookup_community = bgp_ca_community_lookup(&ca);
1748 lookup_alias = bgp_ca_alias_lookup(&ca);
1749
1750 if (no) {
1751 bgp_ca_alias_delete(&ca);
1752 bgp_ca_community_delete(&ca);
1753 } else {
1754 if (lookup_alias) {
1755 /* Lookup if community hash table has an item
1756 * with the same alias name.
1757 */
1758 strlcpy(ca.community, lookup_alias->community,
1759 sizeof(ca.community));
1760 if (bgp_ca_community_lookup(&ca)) {
1761 vty_out(vty,
1762 "community (%s) already has this alias (%s)\n",
1763 lookup_alias->community,
1764 lookup_alias->alias);
1765 return CMD_WARNING;
1766 }
1767 bgp_ca_alias_delete(&ca);
1768 }
1769
1770 if (lookup_community) {
1771 /* Lookup if alias hash table has an item
1772 * with the same community.
1773 */
1774 strlcpy(ca.alias, lookup_community->alias,
1775 sizeof(ca.alias));
1776 if (bgp_ca_alias_lookup(&ca)) {
1777 vty_out(vty,
1778 "alias (%s) already has this community (%s)\n",
1779 lookup_community->alias,
1780 lookup_community->community);
1781 return CMD_WARNING;
1782 }
1783 bgp_ca_community_delete(&ca);
1784 }
1785
1786 bgp_ca_alias_insert(&ca);
1787 bgp_ca_community_insert(&ca);
1788 }
1789
1790 return CMD_SUCCESS;
1791 }
1792
1793 DEFPY (bgp_global_suppress_fib_pending,
1794 bgp_global_suppress_fib_pending_cmd,
1795 "[no] bgp suppress-fib-pending",
1796 NO_STR
1797 BGP_STR
1798 "Advertise only routes that are programmed in kernel to peers globally\n")
1799 {
1800 bm_wait_for_fib_set(!no);
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805 DEFPY (bgp_suppress_fib_pending,
1806 bgp_suppress_fib_pending_cmd,
1807 "[no] bgp suppress-fib-pending",
1808 NO_STR
1809 BGP_STR
1810 "Advertise only routes that are programmed in kernel to peers\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813
1814 bgp_suppress_fib_pending_set(bgp, !no);
1815 return CMD_SUCCESS;
1816 }
1817
1818
1819 /* BGP Cluster ID. */
1820 DEFUN (bgp_cluster_id,
1821 bgp_cluster_id_cmd,
1822 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1823 BGP_STR
1824 "Configure Route-Reflector Cluster-id\n"
1825 "Route-Reflector Cluster-id in IP address format\n"
1826 "Route-Reflector Cluster-id as 32 bit quantity\n")
1827 {
1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 int idx_ipv4 = 2;
1830 int ret;
1831 struct in_addr cluster;
1832
1833 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1834 if (!ret) {
1835 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1836 return CMD_WARNING_CONFIG_FAILED;
1837 }
1838
1839 bgp_cluster_id_set(bgp, &cluster);
1840 bgp_clear_star_soft_out(vty, bgp->name);
1841
1842 return CMD_SUCCESS;
1843 }
1844
1845 DEFUN (no_bgp_cluster_id,
1846 no_bgp_cluster_id_cmd,
1847 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1848 NO_STR
1849 BGP_STR
1850 "Configure Route-Reflector Cluster-id\n"
1851 "Route-Reflector Cluster-id in IP address format\n"
1852 "Route-Reflector Cluster-id as 32 bit quantity\n")
1853 {
1854 VTY_DECLVAR_CONTEXT(bgp, bgp);
1855 bgp_cluster_id_unset(bgp);
1856 bgp_clear_star_soft_out(vty, bgp->name);
1857
1858 return CMD_SUCCESS;
1859 }
1860
1861 DEFPY (bgp_norib,
1862 bgp_norib_cmd,
1863 "bgp no-rib",
1864 BGP_STR
1865 "Disable BGP route installation to RIB (Zebra)\n")
1866 {
1867 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1868 vty_out(vty,
1869 "%% No-RIB option is already set, nothing to do here.\n");
1870 return CMD_SUCCESS;
1871 }
1872
1873 bgp_option_norib_set_runtime();
1874
1875 return CMD_SUCCESS;
1876 }
1877
1878 DEFPY (no_bgp_norib,
1879 no_bgp_norib_cmd,
1880 "no bgp no-rib",
1881 NO_STR
1882 BGP_STR
1883 "Disable BGP route installation to RIB (Zebra)\n")
1884 {
1885 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1886 vty_out(vty,
1887 "%% No-RIB option is not set, nothing to do here.\n");
1888 return CMD_SUCCESS;
1889 }
1890
1891 bgp_option_norib_unset_runtime();
1892
1893 return CMD_SUCCESS;
1894 }
1895
1896 DEFPY (no_bgp_send_extra_data,
1897 no_bgp_send_extra_data_cmd,
1898 "[no] bgp send-extra-data zebra",
1899 NO_STR
1900 BGP_STR
1901 "Extra data to Zebra for display/use\n"
1902 "To zebra\n")
1903 {
1904 if (no)
1905 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1906 else
1907 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1908
1909 return CMD_SUCCESS;
1910 }
1911
1912 DEFUN (bgp_confederation_identifier,
1913 bgp_confederation_identifier_cmd,
1914 "bgp confederation identifier (1-4294967295)",
1915 BGP_STR
1916 "AS confederation parameters\n"
1917 "AS number\n"
1918 "Set routing domain confederation AS\n")
1919 {
1920 VTY_DECLVAR_CONTEXT(bgp, bgp);
1921 int idx_number = 3;
1922 as_t as;
1923
1924 as = strtoul(argv[idx_number]->arg, NULL, 10);
1925
1926 bgp_confederation_id_set(bgp, as);
1927
1928 return CMD_SUCCESS;
1929 }
1930
1931 DEFUN (no_bgp_confederation_identifier,
1932 no_bgp_confederation_identifier_cmd,
1933 "no bgp confederation identifier [(1-4294967295)]",
1934 NO_STR
1935 BGP_STR
1936 "AS confederation parameters\n"
1937 "AS number\n"
1938 "Set routing domain confederation AS\n")
1939 {
1940 VTY_DECLVAR_CONTEXT(bgp, bgp);
1941 bgp_confederation_id_unset(bgp);
1942
1943 return CMD_SUCCESS;
1944 }
1945
1946 DEFUN (bgp_confederation_peers,
1947 bgp_confederation_peers_cmd,
1948 "bgp confederation peers (1-4294967295)...",
1949 BGP_STR
1950 "AS confederation parameters\n"
1951 "Peer ASs in BGP confederation\n"
1952 AS_STR)
1953 {
1954 VTY_DECLVAR_CONTEXT(bgp, bgp);
1955 int idx_asn = 3;
1956 as_t as;
1957 int i;
1958
1959 for (i = idx_asn; i < argc; i++) {
1960 as = strtoul(argv[i]->arg, NULL, 10);
1961 bgp_confederation_peers_add(bgp, as);
1962 }
1963 return CMD_SUCCESS;
1964 }
1965
1966 DEFUN (no_bgp_confederation_peers,
1967 no_bgp_confederation_peers_cmd,
1968 "no bgp confederation peers (1-4294967295)...",
1969 NO_STR
1970 BGP_STR
1971 "AS confederation parameters\n"
1972 "Peer ASs in BGP confederation\n"
1973 AS_STR)
1974 {
1975 VTY_DECLVAR_CONTEXT(bgp, bgp);
1976 int idx_asn = 4;
1977 as_t as;
1978 int i;
1979
1980 for (i = idx_asn; i < argc; i++) {
1981 as = strtoul(argv[i]->arg, NULL, 10);
1982
1983 bgp_confederation_peers_remove(bgp, as);
1984 }
1985 return CMD_SUCCESS;
1986 }
1987
1988 /**
1989 * Central routine for maximum-paths configuration.
1990 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1991 * @set: 1 for setting values, 0 for removing the max-paths config.
1992 */
1993 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1994 const char *mpaths, uint16_t options,
1995 int set)
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998 uint16_t maxpaths = 0;
1999 int ret;
2000 afi_t afi;
2001 safi_t safi;
2002
2003 afi = bgp_node_afi(vty);
2004 safi = bgp_node_safi(vty);
2005
2006 if (set) {
2007 maxpaths = strtol(mpaths, NULL, 10);
2008 if (maxpaths > multipath_num) {
2009 vty_out(vty,
2010 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2011 maxpaths, multipath_num);
2012 return CMD_WARNING_CONFIG_FAILED;
2013 }
2014 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2015 options);
2016 } else
2017 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2018
2019 if (ret < 0) {
2020 vty_out(vty,
2021 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2022 (set == 1) ? "" : "un",
2023 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2024 maxpaths, afi, safi);
2025 return CMD_WARNING_CONFIG_FAILED;
2026 }
2027
2028 bgp_recalculate_all_bestpaths(bgp);
2029
2030 return CMD_SUCCESS;
2031 }
2032
2033 DEFUN (bgp_maxmed_admin,
2034 bgp_maxmed_admin_cmd,
2035 "bgp max-med administrative ",
2036 BGP_STR
2037 "Advertise routes with max-med\n"
2038 "Administratively applied, for an indefinite period\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041
2042 bgp->v_maxmed_admin = 1;
2043 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2044
2045 bgp_maxmed_update(bgp);
2046
2047 return CMD_SUCCESS;
2048 }
2049
2050 DEFUN (bgp_maxmed_admin_medv,
2051 bgp_maxmed_admin_medv_cmd,
2052 "bgp max-med administrative (0-4294967295)",
2053 BGP_STR
2054 "Advertise routes with max-med\n"
2055 "Administratively applied, for an indefinite period\n"
2056 "Max MED value to be used\n")
2057 {
2058 VTY_DECLVAR_CONTEXT(bgp, bgp);
2059 int idx_number = 3;
2060
2061 bgp->v_maxmed_admin = 1;
2062 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2063
2064 bgp_maxmed_update(bgp);
2065
2066 return CMD_SUCCESS;
2067 }
2068
2069 DEFUN (no_bgp_maxmed_admin,
2070 no_bgp_maxmed_admin_cmd,
2071 "no bgp max-med administrative [(0-4294967295)]",
2072 NO_STR
2073 BGP_STR
2074 "Advertise routes with max-med\n"
2075 "Administratively applied, for an indefinite period\n"
2076 "Max MED value to be used\n")
2077 {
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2080 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2081 bgp_maxmed_update(bgp);
2082
2083 return CMD_SUCCESS;
2084 }
2085
2086 DEFUN (bgp_maxmed_onstartup,
2087 bgp_maxmed_onstartup_cmd,
2088 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2089 BGP_STR
2090 "Advertise routes with max-med\n"
2091 "Effective on a startup\n"
2092 "Time (seconds) period for max-med\n"
2093 "Max MED value to be used\n")
2094 {
2095 VTY_DECLVAR_CONTEXT(bgp, bgp);
2096 int idx = 0;
2097
2098 if (argv_find(argv, argc, "(5-86400)", &idx))
2099 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2100 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2101 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2102 else
2103 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2104
2105 bgp_maxmed_update(bgp);
2106
2107 return CMD_SUCCESS;
2108 }
2109
2110 DEFUN (no_bgp_maxmed_onstartup,
2111 no_bgp_maxmed_onstartup_cmd,
2112 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2113 NO_STR
2114 BGP_STR
2115 "Advertise routes with max-med\n"
2116 "Effective on a startup\n"
2117 "Time (seconds) period for max-med\n"
2118 "Max MED value to be used\n")
2119 {
2120 VTY_DECLVAR_CONTEXT(bgp, bgp);
2121
2122 /* Cancel max-med onstartup if its on */
2123 if (bgp->t_maxmed_onstartup) {
2124 THREAD_OFF(bgp->t_maxmed_onstartup);
2125 bgp->maxmed_onstartup_over = 1;
2126 }
2127
2128 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2129 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2130
2131 bgp_maxmed_update(bgp);
2132
2133 return CMD_SUCCESS;
2134 }
2135
2136 static int bgp_global_update_delay_config_vty(struct vty *vty,
2137 uint16_t update_delay,
2138 uint16_t establish_wait)
2139 {
2140 struct listnode *node, *nnode;
2141 struct bgp *bgp;
2142 bool vrf_cfg = false;
2143
2144 /*
2145 * See if update-delay is set per-vrf and warn user to delete it
2146 * Note that we only need to check this if this is the first time
2147 * setting the global config.
2148 */
2149 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2150 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2151 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2152 vty_out(vty,
2153 "%% update-delay configuration found in vrf %s\n",
2154 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2155 ? VRF_DEFAULT_NAME
2156 : bgp->name);
2157 vrf_cfg = true;
2158 }
2159 }
2160 }
2161
2162 if (vrf_cfg) {
2163 vty_out(vty,
2164 "%%Failed: global update-delay config not permitted\n");
2165 return CMD_WARNING;
2166 }
2167
2168 if (!establish_wait) { /* update-delay <delay> */
2169 bm->v_update_delay = update_delay;
2170 bm->v_establish_wait = bm->v_update_delay;
2171 } else {
2172 /* update-delay <delay> <establish-wait> */
2173 if (update_delay < establish_wait) {
2174 vty_out(vty,
2175 "%%Failed: update-delay less than the establish-wait!\n");
2176 return CMD_WARNING_CONFIG_FAILED;
2177 }
2178
2179 bm->v_update_delay = update_delay;
2180 bm->v_establish_wait = establish_wait;
2181 }
2182
2183 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2184 bgp->v_update_delay = bm->v_update_delay;
2185 bgp->v_establish_wait = bm->v_establish_wait;
2186 }
2187
2188 return CMD_SUCCESS;
2189 }
2190
2191 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2192 {
2193 struct listnode *node, *nnode;
2194 struct bgp *bgp;
2195
2196 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2197 bm->v_establish_wait = bm->v_update_delay;
2198
2199 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2200 bgp->v_update_delay = bm->v_update_delay;
2201 bgp->v_establish_wait = bm->v_establish_wait;
2202 }
2203
2204 return CMD_SUCCESS;
2205 }
2206
2207 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2208 uint16_t establish_wait)
2209 {
2210 VTY_DECLVAR_CONTEXT(bgp, bgp);
2211
2212 /* if configured globally, per-instance config is not allowed */
2213 if (bm->v_update_delay) {
2214 vty_out(vty,
2215 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2216 return CMD_WARNING_CONFIG_FAILED;
2217 }
2218
2219
2220 if (!establish_wait) /* update-delay <delay> */
2221 {
2222 bgp->v_update_delay = update_delay;
2223 bgp->v_establish_wait = bgp->v_update_delay;
2224 return CMD_SUCCESS;
2225 }
2226
2227 /* update-delay <delay> <establish-wait> */
2228 if (update_delay < establish_wait) {
2229 vty_out(vty,
2230 "%%Failed: update-delay less than the establish-wait!\n");
2231 return CMD_WARNING_CONFIG_FAILED;
2232 }
2233
2234 bgp->v_update_delay = update_delay;
2235 bgp->v_establish_wait = establish_wait;
2236
2237 return CMD_SUCCESS;
2238 }
2239
2240 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2241 {
2242 VTY_DECLVAR_CONTEXT(bgp, bgp);
2243
2244 /* If configured globally, cannot remove from one bgp instance */
2245 if (bm->v_update_delay) {
2246 vty_out(vty,
2247 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2248 return CMD_WARNING_CONFIG_FAILED;
2249 }
2250 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2251 bgp->v_establish_wait = bgp->v_update_delay;
2252
2253 return CMD_SUCCESS;
2254 }
2255
2256 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2257 {
2258 /* If configured globally, no need to display per-instance value */
2259 if (bgp->v_update_delay != bm->v_update_delay) {
2260 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2261 if (bgp->v_update_delay != bgp->v_establish_wait)
2262 vty_out(vty, " %d", bgp->v_establish_wait);
2263 vty_out(vty, "\n");
2264 }
2265 }
2266
2267 /* Global update-delay configuration */
2268 DEFPY (bgp_global_update_delay,
2269 bgp_global_update_delay_cmd,
2270 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2271 BGP_STR
2272 "Force initial delay for best-path and updates for all bgp instances\n"
2273 "Max delay in seconds\n"
2274 "Establish wait in seconds\n")
2275 {
2276 return bgp_global_update_delay_config_vty(vty, delay, wait);
2277 }
2278
2279 /* Global update-delay deconfiguration */
2280 DEFPY (no_bgp_global_update_delay,
2281 no_bgp_global_update_delay_cmd,
2282 "no bgp update-delay [(0-3600) [(1-3600)]]",
2283 NO_STR
2284 BGP_STR
2285 "Force initial delay for best-path and updates\n"
2286 "Max delay in seconds\n"
2287 "Establish wait in seconds\n")
2288 {
2289 return bgp_global_update_delay_deconfig_vty(vty);
2290 }
2291
2292 /* Update-delay configuration */
2293
2294 DEFPY (bgp_update_delay,
2295 bgp_update_delay_cmd,
2296 "update-delay (0-3600)$delay [(1-3600)$wait]",
2297 "Force initial delay for best-path and updates\n"
2298 "Max delay in seconds\n"
2299 "Establish wait in seconds\n")
2300 {
2301 return bgp_update_delay_config_vty(vty, delay, wait);
2302 }
2303
2304 /* Update-delay deconfiguration */
2305 DEFPY (no_bgp_update_delay,
2306 no_bgp_update_delay_cmd,
2307 "no update-delay [(0-3600) [(1-3600)]]",
2308 NO_STR
2309 "Force initial delay for best-path and updates\n"
2310 "Max delay in seconds\n"
2311 "Establish wait in seconds\n")
2312 {
2313 return bgp_update_delay_deconfig_vty(vty);
2314 }
2315
2316
2317 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2318 bool set)
2319 {
2320 VTY_DECLVAR_CONTEXT(bgp, bgp);
2321
2322 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2323 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2324
2325 return CMD_SUCCESS;
2326 }
2327
2328 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2329 bool set)
2330 {
2331 VTY_DECLVAR_CONTEXT(bgp, bgp);
2332
2333 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2334 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2335
2336 return CMD_SUCCESS;
2337 }
2338
2339 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2340 {
2341 uint32_t quanta =
2342 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2343 if (quanta != BGP_WRITE_PACKET_MAX)
2344 vty_out(vty, " write-quanta %d\n", quanta);
2345 }
2346
2347 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2348 {
2349 uint32_t quanta =
2350 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2351 if (quanta != BGP_READ_PACKET_MAX)
2352 vty_out(vty, " read-quanta %d\n", quanta);
2353 }
2354
2355 /* Packet quanta configuration
2356 *
2357 * XXX: The value set here controls the size of a stack buffer in the IO
2358 * thread. When changing these limits be careful to prevent stack overflow.
2359 *
2360 * Furthermore, the maximums used here should correspond to
2361 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2362 */
2363 DEFPY (bgp_wpkt_quanta,
2364 bgp_wpkt_quanta_cmd,
2365 "[no] write-quanta (1-64)$quanta",
2366 NO_STR
2367 "How many packets to write to peer socket per run\n"
2368 "Number of packets\n")
2369 {
2370 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2371 }
2372
2373 DEFPY (bgp_rpkt_quanta,
2374 bgp_rpkt_quanta_cmd,
2375 "[no] read-quanta (1-10)$quanta",
2376 NO_STR
2377 "How many packets to read from peer socket per I/O cycle\n"
2378 "Number of packets\n")
2379 {
2380 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2381 }
2382
2383 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2384 {
2385 if (!bgp->heuristic_coalesce)
2386 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2387 }
2388
2389 /* BGP TCP keepalive */
2390 static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2391 {
2392 if (bgp->tcp_keepalive_idle) {
2393 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2394 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2395 bgp->tcp_keepalive_probes);
2396 }
2397 }
2398
2399 DEFUN (bgp_coalesce_time,
2400 bgp_coalesce_time_cmd,
2401 "coalesce-time (0-4294967295)",
2402 "Subgroup coalesce timer\n"
2403 "Subgroup coalesce timer value (in ms)\n")
2404 {
2405 VTY_DECLVAR_CONTEXT(bgp, bgp);
2406
2407 int idx = 0;
2408
2409 bgp->heuristic_coalesce = false;
2410
2411 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2412 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2413
2414 return CMD_SUCCESS;
2415 }
2416
2417 DEFUN (no_bgp_coalesce_time,
2418 no_bgp_coalesce_time_cmd,
2419 "no coalesce-time (0-4294967295)",
2420 NO_STR
2421 "Subgroup coalesce timer\n"
2422 "Subgroup coalesce timer value (in ms)\n")
2423 {
2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425
2426 bgp->heuristic_coalesce = true;
2427 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2428 return CMD_SUCCESS;
2429 }
2430
2431 /* Maximum-paths configuration */
2432 DEFUN (bgp_maxpaths,
2433 bgp_maxpaths_cmd,
2434 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2435 "Forward packets over multiple paths\n"
2436 "Number of paths\n")
2437 {
2438 int idx_number = 1;
2439 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2440 argv[idx_number]->arg, 0, 1);
2441 }
2442
2443 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2444 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2445 "Forward packets over multiple paths\n"
2446 "Number of paths\n")
2447
2448 DEFUN (bgp_maxpaths_ibgp,
2449 bgp_maxpaths_ibgp_cmd,
2450 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2451 "Forward packets over multiple paths\n"
2452 "iBGP-multipath\n"
2453 "Number of paths\n")
2454 {
2455 int idx_number = 2;
2456 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2457 argv[idx_number]->arg, 0, 1);
2458 }
2459
2460 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2461 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2462 "Forward packets over multiple paths\n"
2463 "iBGP-multipath\n"
2464 "Number of paths\n")
2465
2466 DEFUN (bgp_maxpaths_ibgp_cluster,
2467 bgp_maxpaths_ibgp_cluster_cmd,
2468 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2469 "Forward packets over multiple paths\n"
2470 "iBGP-multipath\n"
2471 "Number of paths\n"
2472 "Match the cluster length\n")
2473 {
2474 int idx_number = 2;
2475 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2476 argv[idx_number]->arg, true, 1);
2477 }
2478
2479 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2480 "maximum-paths ibgp " CMD_RANGE_STR(
2481 1, MULTIPATH_NUM) " equal-cluster-length",
2482 "Forward packets over multiple paths\n"
2483 "iBGP-multipath\n"
2484 "Number of paths\n"
2485 "Match the cluster length\n")
2486
2487 DEFUN (no_bgp_maxpaths,
2488 no_bgp_maxpaths_cmd,
2489 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2490 NO_STR
2491 "Forward packets over multiple paths\n"
2492 "Number of paths\n")
2493 {
2494 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2495 }
2496
2497 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2498 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2499 "Forward packets over multiple paths\n"
2500 "Number of paths\n")
2501
2502 DEFUN (no_bgp_maxpaths_ibgp,
2503 no_bgp_maxpaths_ibgp_cmd,
2504 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2505 NO_STR
2506 "Forward packets over multiple paths\n"
2507 "iBGP-multipath\n"
2508 "Number of paths\n"
2509 "Match the cluster length\n")
2510 {
2511 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2512 }
2513
2514 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2515 "no maximum-paths ibgp [" CMD_RANGE_STR(
2516 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2517 NO_STR
2518 "Forward packets over multiple paths\n"
2519 "iBGP-multipath\n"
2520 "Number of paths\n"
2521 "Match the cluster length\n")
2522
2523 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2524 afi_t afi, safi_t safi)
2525 {
2526 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2527 vty_out(vty, " maximum-paths %d\n",
2528 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2529 }
2530
2531 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2532 vty_out(vty, " maximum-paths ibgp %d",
2533 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2534 if (bgp->maxpaths[afi][safi].same_clusterlen)
2535 vty_out(vty, " equal-cluster-length");
2536 vty_out(vty, "\n");
2537 }
2538 }
2539
2540 /* BGP timers. */
2541
2542 DEFUN (bgp_timers,
2543 bgp_timers_cmd,
2544 "timers bgp (0-65535) (0-65535)",
2545 "Adjust routing timers\n"
2546 "BGP timers\n"
2547 "Keepalive interval\n"
2548 "Holdtime\n")
2549 {
2550 VTY_DECLVAR_CONTEXT(bgp, bgp);
2551 int idx_number = 2;
2552 int idx_number_2 = 3;
2553 unsigned long keepalive = 0;
2554 unsigned long holdtime = 0;
2555
2556 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2557 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2558
2559 /* Holdtime value check. */
2560 if (holdtime < 3 && holdtime != 0) {
2561 vty_out(vty,
2562 "%% hold time value must be either 0 or greater than 3\n");
2563 return CMD_WARNING_CONFIG_FAILED;
2564 }
2565
2566 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2567 BGP_DEFAULT_DELAYOPEN);
2568
2569 return CMD_SUCCESS;
2570 }
2571
2572 DEFUN (no_bgp_timers,
2573 no_bgp_timers_cmd,
2574 "no timers bgp [(0-65535) (0-65535)]",
2575 NO_STR
2576 "Adjust routing timers\n"
2577 "BGP timers\n"
2578 "Keepalive interval\n"
2579 "Holdtime\n")
2580 {
2581 VTY_DECLVAR_CONTEXT(bgp, bgp);
2582 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2583 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2584
2585 return CMD_SUCCESS;
2586 }
2587
2588 /* BGP minimum holdtime. */
2589
2590 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2591 "bgp minimum-holdtime (1-65535)",
2592 "BGP specific commands\n"
2593 "BGP minimum holdtime\n"
2594 "Seconds\n")
2595 {
2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
2597 int idx_number = 2;
2598 unsigned long min_holdtime;
2599
2600 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2601
2602 bgp->default_min_holdtime = min_holdtime;
2603
2604 return CMD_SUCCESS;
2605 }
2606
2607 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2608 "no bgp minimum-holdtime [(1-65535)]",
2609 NO_STR
2610 "BGP specific commands\n"
2611 "BGP minimum holdtime\n"
2612 "Seconds\n")
2613 {
2614 VTY_DECLVAR_CONTEXT(bgp, bgp);
2615
2616 bgp->default_min_holdtime = 0;
2617
2618 return CMD_SUCCESS;
2619 }
2620
2621 DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2622 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2623 BGP_STR
2624 "TCP keepalive parameters\n"
2625 "TCP keepalive idle time (seconds)\n"
2626 "TCP keepalive interval (seconds)\n"
2627 "TCP keepalive maximum probes\n")
2628 {
2629 VTY_DECLVAR_CONTEXT(bgp, bgp);
2630
2631 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2632 (uint16_t)probes);
2633
2634 return CMD_SUCCESS;
2635 }
2636
2637 DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2638 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2639 NO_STR
2640 BGP_STR
2641 "TCP keepalive parameters\n"
2642 "TCP keepalive idle time (seconds)\n"
2643 "TCP keepalive interval (seconds)\n"
2644 "TCP keepalive maximum probes\n")
2645 {
2646 VTY_DECLVAR_CONTEXT(bgp, bgp);
2647
2648 bgp_tcp_keepalive_unset(bgp);
2649
2650 return CMD_SUCCESS;
2651 }
2652
2653 DEFUN (bgp_client_to_client_reflection,
2654 bgp_client_to_client_reflection_cmd,
2655 "bgp client-to-client reflection",
2656 BGP_STR
2657 "Configure client to client route reflection\n"
2658 "reflection of routes allowed\n")
2659 {
2660 VTY_DECLVAR_CONTEXT(bgp, bgp);
2661 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2662 bgp_clear_star_soft_out(vty, bgp->name);
2663
2664 return CMD_SUCCESS;
2665 }
2666
2667 DEFUN (no_bgp_client_to_client_reflection,
2668 no_bgp_client_to_client_reflection_cmd,
2669 "no bgp client-to-client reflection",
2670 NO_STR
2671 BGP_STR
2672 "Configure client to client route reflection\n"
2673 "reflection of routes allowed\n")
2674 {
2675 VTY_DECLVAR_CONTEXT(bgp, bgp);
2676 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2677 bgp_clear_star_soft_out(vty, bgp->name);
2678
2679 return CMD_SUCCESS;
2680 }
2681
2682 /* "bgp always-compare-med" configuration. */
2683 DEFUN (bgp_always_compare_med,
2684 bgp_always_compare_med_cmd,
2685 "bgp always-compare-med",
2686 BGP_STR
2687 "Allow comparing MED from different neighbors\n")
2688 {
2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
2690 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2691 bgp_recalculate_all_bestpaths(bgp);
2692
2693 return CMD_SUCCESS;
2694 }
2695
2696 DEFUN (no_bgp_always_compare_med,
2697 no_bgp_always_compare_med_cmd,
2698 "no bgp always-compare-med",
2699 NO_STR
2700 BGP_STR
2701 "Allow comparing MED from different neighbors\n")
2702 {
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2705 bgp_recalculate_all_bestpaths(bgp);
2706
2707 return CMD_SUCCESS;
2708 }
2709
2710
2711 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2712 "bgp ebgp-requires-policy",
2713 BGP_STR
2714 "Require in and out policy for eBGP peers (RFC8212)\n")
2715 {
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2718 return CMD_SUCCESS;
2719 }
2720
2721 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2722 "no bgp ebgp-requires-policy",
2723 NO_STR
2724 BGP_STR
2725 "Require in and out policy for eBGP peers (RFC8212)\n")
2726 {
2727 VTY_DECLVAR_CONTEXT(bgp, bgp);
2728 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2729 return CMD_SUCCESS;
2730 }
2731
2732 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2733 "bgp suppress-duplicates",
2734 BGP_STR
2735 "Suppress duplicate updates if the route actually not changed\n")
2736 {
2737 VTY_DECLVAR_CONTEXT(bgp, bgp);
2738 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2739 return CMD_SUCCESS;
2740 }
2741
2742 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2743 "no bgp suppress-duplicates",
2744 NO_STR
2745 BGP_STR
2746 "Suppress duplicate updates if the route actually not changed\n")
2747 {
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2750 return CMD_SUCCESS;
2751 }
2752
2753 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2754 "bgp reject-as-sets",
2755 BGP_STR
2756 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2757 {
2758 VTY_DECLVAR_CONTEXT(bgp, bgp);
2759 struct listnode *node, *nnode;
2760 struct peer *peer;
2761
2762 bgp->reject_as_sets = true;
2763
2764 /* Reset existing BGP sessions to reject routes
2765 * with aspath containing AS_SET or AS_CONFED_SET.
2766 */
2767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2768 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2769 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2770 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2771 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2772 }
2773 }
2774
2775 return CMD_SUCCESS;
2776 }
2777
2778 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2779 "no bgp reject-as-sets",
2780 NO_STR
2781 BGP_STR
2782 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2783 {
2784 VTY_DECLVAR_CONTEXT(bgp, bgp);
2785 struct listnode *node, *nnode;
2786 struct peer *peer;
2787
2788 bgp->reject_as_sets = false;
2789
2790 /* Reset existing BGP sessions to reject routes
2791 * with aspath containing AS_SET or AS_CONFED_SET.
2792 */
2793 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2794 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2795 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2796 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2797 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2798 }
2799 }
2800
2801 return CMD_SUCCESS;
2802 }
2803
2804 /* "bgp deterministic-med" configuration. */
2805 DEFUN (bgp_deterministic_med,
2806 bgp_deterministic_med_cmd,
2807 "bgp deterministic-med",
2808 BGP_STR
2809 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2810 {
2811 VTY_DECLVAR_CONTEXT(bgp, bgp);
2812
2813 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2814 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2815 bgp_recalculate_all_bestpaths(bgp);
2816 }
2817
2818 return CMD_SUCCESS;
2819 }
2820
2821 DEFUN (no_bgp_deterministic_med,
2822 no_bgp_deterministic_med_cmd,
2823 "no bgp deterministic-med",
2824 NO_STR
2825 BGP_STR
2826 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2827 {
2828 VTY_DECLVAR_CONTEXT(bgp, bgp);
2829 int bestpath_per_as_used;
2830 afi_t afi;
2831 safi_t safi;
2832 struct peer *peer;
2833 struct listnode *node, *nnode;
2834
2835 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2836 bestpath_per_as_used = 0;
2837
2838 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2839 FOREACH_AFI_SAFI (afi, safi)
2840 if (bgp_addpath_dmed_required(
2841 peer->addpath_type[afi][safi])) {
2842 bestpath_per_as_used = 1;
2843 break;
2844 }
2845
2846 if (bestpath_per_as_used)
2847 break;
2848 }
2849
2850 if (bestpath_per_as_used) {
2851 vty_out(vty,
2852 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2853 return CMD_WARNING_CONFIG_FAILED;
2854 } else {
2855 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2856 bgp_recalculate_all_bestpaths(bgp);
2857 }
2858 }
2859
2860 return CMD_SUCCESS;
2861 }
2862
2863 /* "bgp graceful-restart mode" configuration. */
2864 DEFUN (bgp_graceful_restart,
2865 bgp_graceful_restart_cmd,
2866 "bgp graceful-restart",
2867 BGP_STR
2868 GR_CMD
2869 )
2870 {
2871 int ret = BGP_GR_FAILURE;
2872
2873 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2874 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2875
2876 VTY_DECLVAR_CONTEXT(bgp, bgp);
2877
2878 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2879
2880 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2881 ret);
2882
2883 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2884 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2885 vty_out(vty,
2886 "Graceful restart configuration changed, reset all peers to take effect\n");
2887 return bgp_vty_return(vty, ret);
2888 }
2889
2890 DEFUN (no_bgp_graceful_restart,
2891 no_bgp_graceful_restart_cmd,
2892 "no bgp graceful-restart",
2893 NO_STR
2894 BGP_STR
2895 NO_GR_CMD
2896 )
2897 {
2898 VTY_DECLVAR_CONTEXT(bgp, bgp);
2899
2900 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2901 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2902
2903 int ret = BGP_GR_FAILURE;
2904
2905 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2906
2907 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2908 ret);
2909
2910 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2911 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2912 vty_out(vty,
2913 "Graceful restart configuration changed, reset all peers to take effect\n");
2914
2915 return bgp_vty_return(vty, ret);
2916 }
2917
2918 DEFUN (bgp_graceful_restart_stalepath_time,
2919 bgp_graceful_restart_stalepath_time_cmd,
2920 "bgp graceful-restart stalepath-time (1-4095)",
2921 BGP_STR
2922 "Graceful restart capability parameters\n"
2923 "Set the max time to hold onto restarting peer's stale paths\n"
2924 "Delay value (seconds)\n")
2925 {
2926 VTY_DECLVAR_CONTEXT(bgp, bgp);
2927 int idx_number = 3;
2928 uint32_t stalepath;
2929
2930 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2931 bgp->stalepath_time = stalepath;
2932 return CMD_SUCCESS;
2933 }
2934
2935 DEFUN (bgp_graceful_restart_restart_time,
2936 bgp_graceful_restart_restart_time_cmd,
2937 "bgp graceful-restart restart-time (0-4095)",
2938 BGP_STR
2939 "Graceful restart capability parameters\n"
2940 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2941 "Delay value (seconds)\n")
2942 {
2943 VTY_DECLVAR_CONTEXT(bgp, bgp);
2944 int idx_number = 3;
2945 uint32_t restart;
2946
2947 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2948 bgp->restart_time = restart;
2949 return CMD_SUCCESS;
2950 }
2951
2952 DEFUN (bgp_graceful_restart_select_defer_time,
2953 bgp_graceful_restart_select_defer_time_cmd,
2954 "bgp graceful-restart select-defer-time (0-3600)",
2955 BGP_STR
2956 "Graceful restart capability parameters\n"
2957 "Set the time to defer the BGP route selection after restart\n"
2958 "Delay value (seconds, 0 - disable)\n")
2959 {
2960 VTY_DECLVAR_CONTEXT(bgp, bgp);
2961 int idx_number = 3;
2962 uint32_t defer_time;
2963
2964 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2965 bgp->select_defer_time = defer_time;
2966 if (defer_time == 0)
2967 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2968 else
2969 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2970
2971 return CMD_SUCCESS;
2972 }
2973
2974 DEFUN (no_bgp_graceful_restart_stalepath_time,
2975 no_bgp_graceful_restart_stalepath_time_cmd,
2976 "no bgp graceful-restart stalepath-time [(1-4095)]",
2977 NO_STR
2978 BGP_STR
2979 "Graceful restart capability parameters\n"
2980 "Set the max time to hold onto restarting peer's stale paths\n"
2981 "Delay value (seconds)\n")
2982 {
2983 VTY_DECLVAR_CONTEXT(bgp, bgp);
2984
2985 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2986 return CMD_SUCCESS;
2987 }
2988
2989 DEFUN (no_bgp_graceful_restart_restart_time,
2990 no_bgp_graceful_restart_restart_time_cmd,
2991 "no bgp graceful-restart restart-time [(0-4095)]",
2992 NO_STR
2993 BGP_STR
2994 "Graceful restart capability parameters\n"
2995 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2996 "Delay value (seconds)\n")
2997 {
2998 VTY_DECLVAR_CONTEXT(bgp, bgp);
2999
3000 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3001 return CMD_SUCCESS;
3002 }
3003
3004 DEFUN (no_bgp_graceful_restart_select_defer_time,
3005 no_bgp_graceful_restart_select_defer_time_cmd,
3006 "no bgp graceful-restart select-defer-time [(0-3600)]",
3007 NO_STR
3008 BGP_STR
3009 "Graceful restart capability parameters\n"
3010 "Set the time to defer the BGP route selection after restart\n"
3011 "Delay value (seconds)\n")
3012 {
3013 VTY_DECLVAR_CONTEXT(bgp, bgp);
3014
3015 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3016 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3017
3018 return CMD_SUCCESS;
3019 }
3020
3021 DEFUN (bgp_graceful_restart_preserve_fw,
3022 bgp_graceful_restart_preserve_fw_cmd,
3023 "bgp graceful-restart preserve-fw-state",
3024 BGP_STR
3025 "Graceful restart capability parameters\n"
3026 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3027 {
3028 VTY_DECLVAR_CONTEXT(bgp, bgp);
3029 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3030 return CMD_SUCCESS;
3031 }
3032
3033 DEFUN (no_bgp_graceful_restart_preserve_fw,
3034 no_bgp_graceful_restart_preserve_fw_cmd,
3035 "no bgp graceful-restart preserve-fw-state",
3036 NO_STR
3037 BGP_STR
3038 "Graceful restart capability parameters\n"
3039 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3040 {
3041 VTY_DECLVAR_CONTEXT(bgp, bgp);
3042 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3043 return CMD_SUCCESS;
3044 }
3045
3046 DEFPY (bgp_graceful_restart_notification,
3047 bgp_graceful_restart_notification_cmd,
3048 "[no$no] bgp graceful-restart notification",
3049 NO_STR
3050 BGP_STR
3051 "Graceful restart capability parameters\n"
3052 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3053 {
3054 VTY_DECLVAR_CONTEXT(bgp, bgp);
3055
3056 if (no)
3057 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3058 else
3059 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3060
3061 return CMD_SUCCESS;
3062 }
3063
3064 DEFPY (bgp_administrative_reset,
3065 bgp_administrative_reset_cmd,
3066 "[no$no] bgp hard-administrative-reset",
3067 NO_STR
3068 BGP_STR
3069 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3070 {
3071 VTY_DECLVAR_CONTEXT(bgp, bgp);
3072
3073 if (no)
3074 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3075 else
3076 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3077
3078 return CMD_SUCCESS;
3079 }
3080
3081 DEFUN (bgp_graceful_restart_disable,
3082 bgp_graceful_restart_disable_cmd,
3083 "bgp graceful-restart-disable",
3084 BGP_STR
3085 GR_DISABLE)
3086 {
3087 int ret = BGP_GR_FAILURE;
3088
3089 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3090 zlog_debug(
3091 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3092
3093 VTY_DECLVAR_CONTEXT(bgp, bgp);
3094
3095 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3096
3097 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3098 bgp->peer, ret);
3099
3100 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3101 zlog_debug(
3102 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3103 vty_out(vty,
3104 "Graceful restart configuration changed, reset all peers to take effect\n");
3105
3106 return bgp_vty_return(vty, ret);
3107 }
3108
3109 DEFUN (no_bgp_graceful_restart_disable,
3110 no_bgp_graceful_restart_disable_cmd,
3111 "no bgp graceful-restart-disable",
3112 NO_STR
3113 BGP_STR
3114 NO_GR_DISABLE
3115 )
3116 {
3117 VTY_DECLVAR_CONTEXT(bgp, bgp);
3118
3119 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3120 zlog_debug(
3121 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3122
3123 int ret = BGP_GR_FAILURE;
3124
3125 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3126
3127 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3128 ret);
3129
3130 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3131 zlog_debug(
3132 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3133 vty_out(vty,
3134 "Graceful restart configuration changed, reset all peers to take effect\n");
3135
3136 return bgp_vty_return(vty, ret);
3137 }
3138
3139 DEFUN (bgp_neighbor_graceful_restart_set,
3140 bgp_neighbor_graceful_restart_set_cmd,
3141 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3142 NEIGHBOR_STR
3143 NEIGHBOR_ADDR_STR2
3144 GR_NEIGHBOR_CMD
3145 )
3146 {
3147 int idx_peer = 1;
3148 struct peer *peer;
3149 int ret = BGP_GR_FAILURE;
3150
3151 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3152
3153 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3154 zlog_debug(
3155 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3156
3157 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3158 if (!peer)
3159 return CMD_WARNING_CONFIG_FAILED;
3160
3161 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3162
3163 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3164 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3165
3166 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3167 zlog_debug(
3168 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3169 vty_out(vty,
3170 "Graceful restart configuration changed, reset this peer to take effect\n");
3171
3172 return bgp_vty_return(vty, ret);
3173 }
3174
3175 DEFUN (no_bgp_neighbor_graceful_restart,
3176 no_bgp_neighbor_graceful_restart_set_cmd,
3177 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3178 NO_STR
3179 NEIGHBOR_STR
3180 NEIGHBOR_ADDR_STR2
3181 NO_GR_NEIGHBOR_CMD
3182 )
3183 {
3184 int idx_peer = 2;
3185 int ret = BGP_GR_FAILURE;
3186 struct peer *peer;
3187
3188 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3189
3190 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3191 if (!peer)
3192 return CMD_WARNING_CONFIG_FAILED;
3193
3194 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3195 zlog_debug(
3196 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3197
3198 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3199
3200 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3201 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3202
3203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3204 zlog_debug(
3205 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3206 vty_out(vty,
3207 "Graceful restart configuration changed, reset this peer to take effect\n");
3208
3209 return bgp_vty_return(vty, ret);
3210 }
3211
3212 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3213 bgp_neighbor_graceful_restart_helper_set_cmd,
3214 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
3217 GR_NEIGHBOR_HELPER_CMD
3218 )
3219 {
3220 int idx_peer = 1;
3221 struct peer *peer;
3222 int ret = BGP_GR_FAILURE;
3223
3224 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3225
3226 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3227 zlog_debug(
3228 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3229
3230 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3231
3232 if (!peer)
3233 return CMD_WARNING_CONFIG_FAILED;
3234
3235
3236 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3237
3238 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3239 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3240
3241 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3242 zlog_debug(
3243 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3244 vty_out(vty,
3245 "Graceful restart configuration changed, reset this peer to take effect\n");
3246
3247 return bgp_vty_return(vty, ret);
3248 }
3249
3250 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3251 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3252 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3253 NO_STR
3254 NEIGHBOR_STR
3255 NEIGHBOR_ADDR_STR2
3256 NO_GR_NEIGHBOR_HELPER_CMD
3257 )
3258 {
3259 int idx_peer = 2;
3260 int ret = BGP_GR_FAILURE;
3261 struct peer *peer;
3262
3263 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3264
3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3268
3269 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3270 zlog_debug(
3271 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3272
3273 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3274
3275 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3276 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3277
3278 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3279 zlog_debug(
3280 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3281 vty_out(vty,
3282 "Graceful restart configuration changed, reset this peer to take effect\n");
3283
3284 return bgp_vty_return(vty, ret);
3285 }
3286
3287 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3288 bgp_neighbor_graceful_restart_disable_set_cmd,
3289 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3290 NEIGHBOR_STR
3291 NEIGHBOR_ADDR_STR2
3292 GR_NEIGHBOR_DISABLE_CMD
3293 )
3294 {
3295 int idx_peer = 1;
3296 struct peer *peer;
3297 int ret = BGP_GR_FAILURE;
3298
3299 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3300
3301 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3302 zlog_debug(
3303 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3304
3305 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3306 if (!peer)
3307 return CMD_WARNING_CONFIG_FAILED;
3308
3309 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3310
3311 if (peer->bgp->t_startup)
3312 bgp_peer_gr_flags_update(peer);
3313
3314 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3315 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3316
3317 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3318 zlog_debug(
3319 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3320 vty_out(vty,
3321 "Graceful restart configuration changed, reset this peer to take effect\n");
3322
3323 return bgp_vty_return(vty, ret);
3324 }
3325
3326 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3327 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3328 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3329 NO_STR
3330 NEIGHBOR_STR
3331 NEIGHBOR_ADDR_STR2
3332 NO_GR_NEIGHBOR_DISABLE_CMD
3333 )
3334 {
3335 int idx_peer = 2;
3336 int ret = BGP_GR_FAILURE;
3337 struct peer *peer;
3338
3339 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3340
3341 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3342 if (!peer)
3343 return CMD_WARNING_CONFIG_FAILED;
3344
3345 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3346 zlog_debug(
3347 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3348
3349 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3350
3351 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3352 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3353
3354 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3355 zlog_debug(
3356 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3357 vty_out(vty,
3358 "Graceful restart configuration changed, reset this peer to take effect\n");
3359
3360 return bgp_vty_return(vty, ret);
3361 }
3362
3363 DEFPY (neighbor_graceful_shutdown,
3364 neighbor_graceful_shutdown_cmd,
3365 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3366 NO_STR
3367 NEIGHBOR_STR
3368 NEIGHBOR_ADDR_STR2
3369 "Graceful shutdown\n")
3370 {
3371 afi_t afi;
3372 safi_t safi;
3373 struct peer *peer;
3374 VTY_DECLVAR_CONTEXT(bgp, bgp);
3375 int ret;
3376
3377 peer = peer_and_group_lookup_vty(vty, neighbor);
3378 if (!peer)
3379 return CMD_WARNING_CONFIG_FAILED;
3380
3381 if (no)
3382 ret = peer_flag_unset_vty(vty, neighbor,
3383 PEER_FLAG_GRACEFUL_SHUTDOWN);
3384 else
3385 ret = peer_flag_set_vty(vty, neighbor,
3386 PEER_FLAG_GRACEFUL_SHUTDOWN);
3387
3388 FOREACH_AFI_SAFI (afi, safi) {
3389 if (!peer->afc[afi][safi])
3390 continue;
3391
3392 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3393 neighbor);
3394 }
3395
3396 return ret;
3397 }
3398
3399 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3400 bgp_graceful_restart_disable_eor_cmd,
3401 "bgp graceful-restart disable-eor",
3402 BGP_STR
3403 "Graceful restart configuration parameters\n"
3404 "Disable EOR Check\n")
3405 {
3406 VTY_DECLVAR_CONTEXT(bgp, bgp);
3407 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3408
3409 return CMD_SUCCESS;
3410 }
3411
3412 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3413 no_bgp_graceful_restart_disable_eor_cmd,
3414 "no bgp graceful-restart disable-eor",
3415 NO_STR
3416 BGP_STR
3417 "Graceful restart configuration parameters\n"
3418 "Disable EOR Check\n")
3419 {
3420 VTY_DECLVAR_CONTEXT(bgp, bgp);
3421 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3422
3423 return CMD_SUCCESS;
3424 }
3425
3426 DEFUN (bgp_graceful_restart_rib_stale_time,
3427 bgp_graceful_restart_rib_stale_time_cmd,
3428 "bgp graceful-restart rib-stale-time (1-3600)",
3429 BGP_STR
3430 "Graceful restart configuration parameters\n"
3431 "Specify the stale route removal timer in rib\n"
3432 "Delay value (seconds)\n")
3433 {
3434 VTY_DECLVAR_CONTEXT(bgp, bgp);
3435 int idx_number = 3;
3436 uint32_t stale_time;
3437
3438 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3439 bgp->rib_stale_time = stale_time;
3440 /* Send the stale timer update message to RIB */
3441 if (bgp_zebra_stale_timer_update(bgp))
3442 return CMD_WARNING;
3443
3444 return CMD_SUCCESS;
3445 }
3446
3447 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3448 no_bgp_graceful_restart_rib_stale_time_cmd,
3449 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3450 NO_STR
3451 BGP_STR
3452 "Graceful restart configuration parameters\n"
3453 "Specify the stale route removal timer in rib\n"
3454 "Delay value (seconds)\n")
3455 {
3456 VTY_DECLVAR_CONTEXT(bgp, bgp);
3457
3458 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3459 /* Send the stale timer update message to RIB */
3460 if (bgp_zebra_stale_timer_update(bgp))
3461 return CMD_WARNING;
3462
3463 return CMD_SUCCESS;
3464 }
3465
3466 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3467 "bgp long-lived-graceful-restart stale-time (1-16777215)",
3468 BGP_STR
3469 "Enable Long-lived Graceful Restart\n"
3470 "Specifies maximum time to wait before purging long-lived stale routes\n"
3471 "Stale time value (seconds)\n")
3472 {
3473 VTY_DECLVAR_CONTEXT(bgp, bgp);
3474
3475 uint32_t llgr_stale_time;
3476
3477 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3478 bgp->llgr_stale_time = llgr_stale_time;
3479
3480 return CMD_SUCCESS;
3481 }
3482
3483 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3484 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3485 NO_STR BGP_STR
3486 "Enable Long-lived Graceful Restart\n"
3487 "Specifies maximum time to wait before purging long-lived stale routes\n"
3488 "Stale time value (seconds)\n")
3489 {
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491
3492 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3493
3494 return CMD_SUCCESS;
3495 }
3496
3497 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3498 struct bgp *bgp)
3499 {
3500 bgp_static_redo_import_check(bgp);
3501 bgp_redistribute_redo(bgp);
3502 bgp_clear_star_soft_out(vty, bgp->name);
3503 bgp_clear_star_soft_in(vty, bgp->name);
3504 }
3505
3506 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3507 {
3508 struct listnode *node, *nnode;
3509 struct bgp *bgp;
3510 bool vrf_cfg = false;
3511
3512 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3513 return CMD_SUCCESS;
3514
3515 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3516 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3517 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3518 vty_out(vty,
3519 "%% graceful-shutdown configuration found in vrf %s\n",
3520 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3521 VRF_DEFAULT_NAME : bgp->name);
3522 vrf_cfg = true;
3523 }
3524 }
3525
3526 if (vrf_cfg) {
3527 vty_out(vty,
3528 "%%Failed: global graceful-shutdown not permitted\n");
3529 return CMD_WARNING;
3530 }
3531
3532 /* Set flag globally */
3533 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3534
3535 /* Initiate processing for all BGP instances. */
3536 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3537 bgp_initiate_graceful_shut_unshut(vty, bgp);
3538
3539 return CMD_SUCCESS;
3540 }
3541
3542 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3543 {
3544 struct listnode *node, *nnode;
3545 struct bgp *bgp;
3546
3547 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3548 return CMD_SUCCESS;
3549
3550 /* Unset flag globally */
3551 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3552
3553 /* Initiate processing for all BGP instances. */
3554 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3555 bgp_initiate_graceful_shut_unshut(vty, bgp);
3556
3557 return CMD_SUCCESS;
3558 }
3559
3560 /* "bgp graceful-shutdown" configuration */
3561 DEFUN (bgp_graceful_shutdown,
3562 bgp_graceful_shutdown_cmd,
3563 "bgp graceful-shutdown",
3564 BGP_STR
3565 "Graceful shutdown parameters\n")
3566 {
3567 if (vty->node == CONFIG_NODE)
3568 return bgp_global_graceful_shutdown_config_vty(vty);
3569
3570 VTY_DECLVAR_CONTEXT(bgp, bgp);
3571
3572 /* if configured globally, per-instance config is not allowed */
3573 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3574 vty_out(vty,
3575 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3576 return CMD_WARNING_CONFIG_FAILED;
3577 }
3578
3579 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3580 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3581 bgp_initiate_graceful_shut_unshut(vty, bgp);
3582 }
3583
3584 return CMD_SUCCESS;
3585 }
3586
3587 DEFUN (no_bgp_graceful_shutdown,
3588 no_bgp_graceful_shutdown_cmd,
3589 "no bgp graceful-shutdown",
3590 NO_STR
3591 BGP_STR
3592 "Graceful shutdown parameters\n")
3593 {
3594 if (vty->node == CONFIG_NODE)
3595 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3596
3597 VTY_DECLVAR_CONTEXT(bgp, bgp);
3598
3599 /* If configured globally, cannot remove from one bgp instance */
3600 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3601 vty_out(vty,
3602 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3603 return CMD_WARNING_CONFIG_FAILED;
3604 }
3605
3606 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3607 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3608 bgp_initiate_graceful_shut_unshut(vty, bgp);
3609 }
3610
3611 return CMD_SUCCESS;
3612 }
3613
3614 /* "bgp fast-external-failover" configuration. */
3615 DEFUN (bgp_fast_external_failover,
3616 bgp_fast_external_failover_cmd,
3617 "bgp fast-external-failover",
3618 BGP_STR
3619 "Immediately reset session if a link to a directly connected external peer goes down\n")
3620 {
3621 VTY_DECLVAR_CONTEXT(bgp, bgp);
3622 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3623 return CMD_SUCCESS;
3624 }
3625
3626 DEFUN (no_bgp_fast_external_failover,
3627 no_bgp_fast_external_failover_cmd,
3628 "no bgp fast-external-failover",
3629 NO_STR
3630 BGP_STR
3631 "Immediately reset session if a link to a directly connected external peer goes down\n")
3632 {
3633 VTY_DECLVAR_CONTEXT(bgp, bgp);
3634 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3635 return CMD_SUCCESS;
3636 }
3637
3638 DEFPY (bgp_bestpath_aigp,
3639 bgp_bestpath_aigp_cmd,
3640 "[no$no] bgp bestpath aigp",
3641 NO_STR
3642 BGP_STR
3643 "Change the default bestpath selection\n"
3644 "Evaluate the AIGP attribute during the best path selection process\n")
3645 {
3646 VTY_DECLVAR_CONTEXT(bgp, bgp);
3647
3648 if (no)
3649 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3650 else
3651 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3652
3653 bgp_recalculate_all_bestpaths(bgp);
3654
3655 return CMD_SUCCESS;
3656 }
3657
3658 /* "bgp bestpath compare-routerid" configuration. */
3659 DEFUN (bgp_bestpath_compare_router_id,
3660 bgp_bestpath_compare_router_id_cmd,
3661 "bgp bestpath compare-routerid",
3662 BGP_STR
3663 "Change the default bestpath selection\n"
3664 "Compare router-id for identical EBGP paths\n")
3665 {
3666 VTY_DECLVAR_CONTEXT(bgp, bgp);
3667 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3668 bgp_recalculate_all_bestpaths(bgp);
3669
3670 return CMD_SUCCESS;
3671 }
3672
3673 DEFUN (no_bgp_bestpath_compare_router_id,
3674 no_bgp_bestpath_compare_router_id_cmd,
3675 "no bgp bestpath compare-routerid",
3676 NO_STR
3677 BGP_STR
3678 "Change the default bestpath selection\n"
3679 "Compare router-id for identical EBGP paths\n")
3680 {
3681 VTY_DECLVAR_CONTEXT(bgp, bgp);
3682 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3683 bgp_recalculate_all_bestpaths(bgp);
3684
3685 return CMD_SUCCESS;
3686 }
3687
3688 /* "bgp bestpath as-path ignore" configuration. */
3689 DEFUN (bgp_bestpath_aspath_ignore,
3690 bgp_bestpath_aspath_ignore_cmd,
3691 "bgp bestpath as-path ignore",
3692 BGP_STR
3693 "Change the default bestpath selection\n"
3694 "AS-path attribute\n"
3695 "Ignore as-path length in selecting a route\n")
3696 {
3697 VTY_DECLVAR_CONTEXT(bgp, bgp);
3698 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3699 bgp_recalculate_all_bestpaths(bgp);
3700
3701 return CMD_SUCCESS;
3702 }
3703
3704 DEFUN (no_bgp_bestpath_aspath_ignore,
3705 no_bgp_bestpath_aspath_ignore_cmd,
3706 "no bgp bestpath as-path ignore",
3707 NO_STR
3708 BGP_STR
3709 "Change the default bestpath selection\n"
3710 "AS-path attribute\n"
3711 "Ignore as-path length in selecting a route\n")
3712 {
3713 VTY_DECLVAR_CONTEXT(bgp, bgp);
3714 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3715 bgp_recalculate_all_bestpaths(bgp);
3716
3717 return CMD_SUCCESS;
3718 }
3719
3720 /* "bgp bestpath as-path confed" configuration. */
3721 DEFUN (bgp_bestpath_aspath_confed,
3722 bgp_bestpath_aspath_confed_cmd,
3723 "bgp bestpath as-path confed",
3724 BGP_STR
3725 "Change the default bestpath selection\n"
3726 "AS-path attribute\n"
3727 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3728 {
3729 VTY_DECLVAR_CONTEXT(bgp, bgp);
3730 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3731 bgp_recalculate_all_bestpaths(bgp);
3732
3733 return CMD_SUCCESS;
3734 }
3735
3736 DEFUN (no_bgp_bestpath_aspath_confed,
3737 no_bgp_bestpath_aspath_confed_cmd,
3738 "no bgp bestpath as-path confed",
3739 NO_STR
3740 BGP_STR
3741 "Change the default bestpath selection\n"
3742 "AS-path attribute\n"
3743 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3744 {
3745 VTY_DECLVAR_CONTEXT(bgp, bgp);
3746 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3747 bgp_recalculate_all_bestpaths(bgp);
3748
3749 return CMD_SUCCESS;
3750 }
3751
3752 /* "bgp bestpath as-path multipath-relax" configuration. */
3753 DEFUN (bgp_bestpath_aspath_multipath_relax,
3754 bgp_bestpath_aspath_multipath_relax_cmd,
3755 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3756 BGP_STR
3757 "Change the default bestpath selection\n"
3758 "AS-path attribute\n"
3759 "Allow load sharing across routes that have different AS paths (but same length)\n"
3760 "Generate an AS_SET\n"
3761 "Do not generate an AS_SET\n")
3762 {
3763 VTY_DECLVAR_CONTEXT(bgp, bgp);
3764 int idx = 0;
3765 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3766
3767 /* no-as-set is now the default behavior so we can silently
3768 * ignore it */
3769 if (argv_find(argv, argc, "as-set", &idx))
3770 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3771 else
3772 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3773
3774 bgp_recalculate_all_bestpaths(bgp);
3775
3776 return CMD_SUCCESS;
3777 }
3778
3779 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3780 no_bgp_bestpath_aspath_multipath_relax_cmd,
3781 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3782 NO_STR
3783 BGP_STR
3784 "Change the default bestpath selection\n"
3785 "AS-path attribute\n"
3786 "Allow load sharing across routes that have different AS paths (but same length)\n"
3787 "Generate an AS_SET\n"
3788 "Do not generate an AS_SET\n")
3789 {
3790 VTY_DECLVAR_CONTEXT(bgp, bgp);
3791 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3792 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3793 bgp_recalculate_all_bestpaths(bgp);
3794
3795 return CMD_SUCCESS;
3796 }
3797
3798 /* "bgp bestpath peer-type multipath-relax" configuration. */
3799 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3800 bgp_bestpath_peer_type_multipath_relax_cmd,
3801 "bgp bestpath peer-type multipath-relax",
3802 BGP_STR
3803 "Change the default bestpath selection\n"
3804 "Peer type\n"
3805 "Allow load sharing across routes learned from different peer types\n")
3806 {
3807 VTY_DECLVAR_CONTEXT(bgp, bgp);
3808 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3809 bgp_recalculate_all_bestpaths(bgp);
3810
3811 return CMD_SUCCESS;
3812 }
3813
3814 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3815 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3816 "no bgp bestpath peer-type multipath-relax",
3817 NO_STR BGP_STR
3818 "Change the default bestpath selection\n"
3819 "Peer type\n"
3820 "Allow load sharing across routes learned from different peer types\n")
3821 {
3822 VTY_DECLVAR_CONTEXT(bgp, bgp);
3823 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3824 bgp_recalculate_all_bestpaths(bgp);
3825
3826 return CMD_SUCCESS;
3827 }
3828
3829 /* "bgp log-neighbor-changes" configuration. */
3830 DEFUN (bgp_log_neighbor_changes,
3831 bgp_log_neighbor_changes_cmd,
3832 "bgp log-neighbor-changes",
3833 BGP_STR
3834 "Log neighbor up/down and reset reason\n")
3835 {
3836 VTY_DECLVAR_CONTEXT(bgp, bgp);
3837 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3838 return CMD_SUCCESS;
3839 }
3840
3841 DEFUN (no_bgp_log_neighbor_changes,
3842 no_bgp_log_neighbor_changes_cmd,
3843 "no bgp log-neighbor-changes",
3844 NO_STR
3845 BGP_STR
3846 "Log neighbor up/down and reset reason\n")
3847 {
3848 VTY_DECLVAR_CONTEXT(bgp, bgp);
3849 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3850 return CMD_SUCCESS;
3851 }
3852
3853 /* "bgp bestpath med" configuration. */
3854 DEFUN (bgp_bestpath_med,
3855 bgp_bestpath_med_cmd,
3856 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3857 BGP_STR
3858 "Change the default bestpath selection\n"
3859 "MED attribute\n"
3860 "Compare MED among confederation paths\n"
3861 "Treat missing MED as the least preferred one\n"
3862 "Treat missing MED as the least preferred one\n"
3863 "Compare MED among confederation paths\n")
3864 {
3865 VTY_DECLVAR_CONTEXT(bgp, bgp);
3866
3867 int idx = 0;
3868 if (argv_find(argv, argc, "confed", &idx))
3869 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3870 idx = 0;
3871 if (argv_find(argv, argc, "missing-as-worst", &idx))
3872 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3873
3874 bgp_recalculate_all_bestpaths(bgp);
3875
3876 return CMD_SUCCESS;
3877 }
3878
3879 DEFUN (no_bgp_bestpath_med,
3880 no_bgp_bestpath_med_cmd,
3881 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3882 NO_STR
3883 BGP_STR
3884 "Change the default bestpath selection\n"
3885 "MED attribute\n"
3886 "Compare MED among confederation paths\n"
3887 "Treat missing MED as the least preferred one\n"
3888 "Treat missing MED as the least preferred one\n"
3889 "Compare MED among confederation paths\n")
3890 {
3891 VTY_DECLVAR_CONTEXT(bgp, bgp);
3892
3893 int idx = 0;
3894 if (argv_find(argv, argc, "confed", &idx))
3895 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3896 idx = 0;
3897 if (argv_find(argv, argc, "missing-as-worst", &idx))
3898 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3899
3900 bgp_recalculate_all_bestpaths(bgp);
3901
3902 return CMD_SUCCESS;
3903 }
3904
3905 /* "bgp bestpath bandwidth" configuration. */
3906 DEFPY (bgp_bestpath_bw,
3907 bgp_bestpath_bw_cmd,
3908 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3909 BGP_STR
3910 "Change the default bestpath selection\n"
3911 "Link Bandwidth attribute\n"
3912 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3913 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3914 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3915 {
3916 VTY_DECLVAR_CONTEXT(bgp, bgp);
3917 afi_t afi;
3918 safi_t safi;
3919
3920 if (!bw_cfg) {
3921 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3922 return CMD_ERR_INCOMPLETE;
3923 }
3924 if (!strcmp(bw_cfg, "ignore"))
3925 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3926 else if (!strcmp(bw_cfg, "skip-missing"))
3927 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3928 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3929 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3930 else
3931 return CMD_ERR_NO_MATCH;
3932
3933 /* This config is used in route install, so redo that. */
3934 FOREACH_AFI_SAFI (afi, safi) {
3935 if (!bgp_fibupd_safi(safi))
3936 continue;
3937 bgp_zebra_announce_table(bgp, afi, safi);
3938 }
3939
3940 return CMD_SUCCESS;
3941 }
3942
3943 DEFPY (no_bgp_bestpath_bw,
3944 no_bgp_bestpath_bw_cmd,
3945 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3946 NO_STR
3947 BGP_STR
3948 "Change the default bestpath selection\n"
3949 "Link Bandwidth attribute\n"
3950 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3951 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3952 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3953 {
3954 VTY_DECLVAR_CONTEXT(bgp, bgp);
3955 afi_t afi;
3956 safi_t safi;
3957
3958 bgp->lb_handling = BGP_LINK_BW_ECMP;
3959
3960 /* This config is used in route install, so redo that. */
3961 FOREACH_AFI_SAFI (afi, safi) {
3962 if (!bgp_fibupd_safi(safi))
3963 continue;
3964 bgp_zebra_announce_table(bgp, afi, safi);
3965 }
3966 return CMD_SUCCESS;
3967 }
3968
3969 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3970 "[no] bgp default <ipv4-unicast|"
3971 "ipv4-multicast|"
3972 "ipv4-vpn|"
3973 "ipv4-labeled-unicast|"
3974 "ipv4-flowspec|"
3975 "ipv6-unicast|"
3976 "ipv6-multicast|"
3977 "ipv6-vpn|"
3978 "ipv6-labeled-unicast|"
3979 "ipv6-flowspec|"
3980 "l2vpn-evpn>$afi_safi",
3981 NO_STR
3982 BGP_STR
3983 "Configure BGP defaults\n"
3984 "Activate ipv4-unicast for a peer by default\n"
3985 "Activate ipv4-multicast for a peer by default\n"
3986 "Activate ipv4-vpn for a peer by default\n"
3987 "Activate ipv4-labeled-unicast for a peer by default\n"
3988 "Activate ipv4-flowspec for a peer by default\n"
3989 "Activate ipv6-unicast for a peer by default\n"
3990 "Activate ipv6-multicast for a peer by default\n"
3991 "Activate ipv6-vpn for a peer by default\n"
3992 "Activate ipv6-labeled-unicast for a peer by default\n"
3993 "Activate ipv6-flowspec for a peer by default\n"
3994 "Activate l2vpn-evpn for a peer by default\n")
3995 {
3996 VTY_DECLVAR_CONTEXT(bgp, bgp);
3997 char afi_safi_str[strlen(afi_safi) + 1];
3998 char *afi_safi_str_tok;
3999
4000 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4001 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4002 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4003 afi_t afi = bgp_vty_afi_from_str(afi_str);
4004 safi_t safi;
4005
4006 /*
4007 * Impossible situation but making coverity happy
4008 */
4009 assert(afi != AFI_MAX);
4010
4011 if (strmatch(safi_str, "labeled"))
4012 safi = bgp_vty_safi_from_str("labeled-unicast");
4013 else
4014 safi = bgp_vty_safi_from_str(safi_str);
4015
4016 assert(safi != SAFI_MAX);
4017 if (no)
4018 bgp->default_af[afi][safi] = false;
4019 else {
4020 if ((safi == SAFI_LABELED_UNICAST
4021 && bgp->default_af[afi][SAFI_UNICAST])
4022 || (safi == SAFI_UNICAST
4023 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4024 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4025 else
4026 bgp->default_af[afi][safi] = true;
4027 }
4028
4029 return CMD_SUCCESS;
4030 }
4031
4032 /* Display hostname in certain command outputs */
4033 DEFUN (bgp_default_show_hostname,
4034 bgp_default_show_hostname_cmd,
4035 "bgp default show-hostname",
4036 BGP_STR
4037 "Configure BGP defaults\n"
4038 "Show hostname in certain command outputs\n")
4039 {
4040 VTY_DECLVAR_CONTEXT(bgp, bgp);
4041 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4042 return CMD_SUCCESS;
4043 }
4044
4045 DEFUN (no_bgp_default_show_hostname,
4046 no_bgp_default_show_hostname_cmd,
4047 "no bgp default show-hostname",
4048 NO_STR
4049 BGP_STR
4050 "Configure BGP defaults\n"
4051 "Show hostname in certain command outputs\n")
4052 {
4053 VTY_DECLVAR_CONTEXT(bgp, bgp);
4054 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4055 return CMD_SUCCESS;
4056 }
4057
4058 /* Display hostname in certain command outputs */
4059 DEFUN (bgp_default_show_nexthop_hostname,
4060 bgp_default_show_nexthop_hostname_cmd,
4061 "bgp default show-nexthop-hostname",
4062 BGP_STR
4063 "Configure BGP defaults\n"
4064 "Show hostname for nexthop in certain command outputs\n")
4065 {
4066 VTY_DECLVAR_CONTEXT(bgp, bgp);
4067 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4068 return CMD_SUCCESS;
4069 }
4070
4071 DEFUN (no_bgp_default_show_nexthop_hostname,
4072 no_bgp_default_show_nexthop_hostname_cmd,
4073 "no bgp default show-nexthop-hostname",
4074 NO_STR
4075 BGP_STR
4076 "Configure BGP defaults\n"
4077 "Show hostname for nexthop in certain command outputs\n")
4078 {
4079 VTY_DECLVAR_CONTEXT(bgp, bgp);
4080 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4081 return CMD_SUCCESS;
4082 }
4083
4084 /* "bgp network import-check" configuration. */
4085 DEFUN (bgp_network_import_check,
4086 bgp_network_import_check_cmd,
4087 "bgp network import-check",
4088 BGP_STR
4089 "BGP network command\n"
4090 "Check BGP network route exists in IGP\n")
4091 {
4092 VTY_DECLVAR_CONTEXT(bgp, bgp);
4093 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4094 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4095 bgp_static_redo_import_check(bgp);
4096 }
4097
4098 return CMD_SUCCESS;
4099 }
4100
4101 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4102 "bgp network import-check exact",
4103 BGP_STR
4104 "BGP network command\n"
4105 "Check BGP network route exists in IGP\n"
4106 "Match route precisely\n")
4107
4108 DEFUN (no_bgp_network_import_check,
4109 no_bgp_network_import_check_cmd,
4110 "no bgp network import-check",
4111 NO_STR
4112 BGP_STR
4113 "BGP network command\n"
4114 "Check BGP network route exists in IGP\n")
4115 {
4116 VTY_DECLVAR_CONTEXT(bgp, bgp);
4117 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4118 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4119 bgp_static_redo_import_check(bgp);
4120 }
4121
4122 return CMD_SUCCESS;
4123 }
4124
4125 DEFUN (bgp_default_local_preference,
4126 bgp_default_local_preference_cmd,
4127 "bgp default local-preference (0-4294967295)",
4128 BGP_STR
4129 "Configure BGP defaults\n"
4130 "local preference (higher=more preferred)\n"
4131 "Configure default local preference value\n")
4132 {
4133 VTY_DECLVAR_CONTEXT(bgp, bgp);
4134 int idx_number = 3;
4135 uint32_t local_pref;
4136
4137 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4138
4139 bgp_default_local_preference_set(bgp, local_pref);
4140 bgp_clear_star_soft_in(vty, bgp->name);
4141
4142 return CMD_SUCCESS;
4143 }
4144
4145 DEFUN (no_bgp_default_local_preference,
4146 no_bgp_default_local_preference_cmd,
4147 "no bgp default local-preference [(0-4294967295)]",
4148 NO_STR
4149 BGP_STR
4150 "Configure BGP defaults\n"
4151 "local preference (higher=more preferred)\n"
4152 "Configure default local preference value\n")
4153 {
4154 VTY_DECLVAR_CONTEXT(bgp, bgp);
4155 bgp_default_local_preference_unset(bgp);
4156 bgp_clear_star_soft_in(vty, bgp->name);
4157
4158 return CMD_SUCCESS;
4159 }
4160
4161
4162 DEFUN (bgp_default_subgroup_pkt_queue_max,
4163 bgp_default_subgroup_pkt_queue_max_cmd,
4164 "bgp default subgroup-pkt-queue-max (20-100)",
4165 BGP_STR
4166 "Configure BGP defaults\n"
4167 "subgroup-pkt-queue-max\n"
4168 "Configure subgroup packet queue max\n")
4169 {
4170 VTY_DECLVAR_CONTEXT(bgp, bgp);
4171 int idx_number = 3;
4172 uint32_t max_size;
4173
4174 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4175
4176 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4177
4178 return CMD_SUCCESS;
4179 }
4180
4181 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4182 no_bgp_default_subgroup_pkt_queue_max_cmd,
4183 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4184 NO_STR
4185 BGP_STR
4186 "Configure BGP defaults\n"
4187 "subgroup-pkt-queue-max\n"
4188 "Configure subgroup packet queue max\n")
4189 {
4190 VTY_DECLVAR_CONTEXT(bgp, bgp);
4191 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4192 return CMD_SUCCESS;
4193 }
4194
4195
4196 DEFUN (bgp_rr_allow_outbound_policy,
4197 bgp_rr_allow_outbound_policy_cmd,
4198 "bgp route-reflector allow-outbound-policy",
4199 BGP_STR
4200 "Allow modifications made by out route-map\n"
4201 "on ibgp neighbors\n")
4202 {
4203 VTY_DECLVAR_CONTEXT(bgp, bgp);
4204
4205 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4206 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4207 update_group_announce_rrclients(bgp);
4208 bgp_clear_star_soft_out(vty, bgp->name);
4209 }
4210
4211 return CMD_SUCCESS;
4212 }
4213
4214 DEFUN (no_bgp_rr_allow_outbound_policy,
4215 no_bgp_rr_allow_outbound_policy_cmd,
4216 "no bgp route-reflector allow-outbound-policy",
4217 NO_STR
4218 BGP_STR
4219 "Allow modifications made by out route-map\n"
4220 "on ibgp neighbors\n")
4221 {
4222 VTY_DECLVAR_CONTEXT(bgp, bgp);
4223
4224 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4225 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4226 update_group_announce_rrclients(bgp);
4227 bgp_clear_star_soft_out(vty, bgp->name);
4228 }
4229
4230 return CMD_SUCCESS;
4231 }
4232
4233 DEFUN (bgp_listen_limit,
4234 bgp_listen_limit_cmd,
4235 "bgp listen limit (1-65535)",
4236 BGP_STR
4237 "BGP Dynamic Neighbors listen commands\n"
4238 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4239 "Configure Dynamic Neighbors listen limit value\n")
4240 {
4241 VTY_DECLVAR_CONTEXT(bgp, bgp);
4242 int idx_number = 3;
4243 int listen_limit;
4244
4245 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4246
4247 bgp_listen_limit_set(bgp, listen_limit);
4248
4249 return CMD_SUCCESS;
4250 }
4251
4252 DEFUN (no_bgp_listen_limit,
4253 no_bgp_listen_limit_cmd,
4254 "no bgp listen limit [(1-65535)]",
4255 NO_STR
4256 BGP_STR
4257 "BGP Dynamic Neighbors listen commands\n"
4258 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4259 "Configure Dynamic Neighbors listen limit value\n")
4260 {
4261 VTY_DECLVAR_CONTEXT(bgp, bgp);
4262 bgp_listen_limit_unset(bgp);
4263 return CMD_SUCCESS;
4264 }
4265
4266
4267 /*
4268 * Check if this listen range is already configured. Check for exact
4269 * match or overlap based on input.
4270 */
4271 static struct peer_group *listen_range_exists(struct bgp *bgp,
4272 struct prefix *range, int exact)
4273 {
4274 struct listnode *node, *nnode;
4275 struct listnode *node1, *nnode1;
4276 struct peer_group *group;
4277 struct prefix *lr;
4278 afi_t afi;
4279 int match;
4280
4281 afi = family2afi(range->family);
4282 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4283 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4284 lr)) {
4285 if (exact)
4286 match = prefix_same(range, lr);
4287 else
4288 match = (prefix_match(range, lr)
4289 || prefix_match(lr, range));
4290 if (match)
4291 return group;
4292 }
4293 }
4294
4295 return NULL;
4296 }
4297
4298 DEFUN (bgp_listen_range,
4299 bgp_listen_range_cmd,
4300 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4301 BGP_STR
4302 "Configure BGP dynamic neighbors listen range\n"
4303 "Configure BGP dynamic neighbors listen range\n"
4304 NEIGHBOR_ADDR_STR
4305 "Member of the peer-group\n"
4306 "Peer-group name\n")
4307 {
4308 VTY_DECLVAR_CONTEXT(bgp, bgp);
4309 struct prefix range;
4310 struct peer_group *group, *existing_group;
4311 afi_t afi;
4312 int ret;
4313 int idx = 0;
4314
4315 argv_find(argv, argc, "A.B.C.D/M", &idx);
4316 argv_find(argv, argc, "X:X::X:X/M", &idx);
4317 char *prefix = argv[idx]->arg;
4318 argv_find(argv, argc, "PGNAME", &idx);
4319 char *peergroup = argv[idx]->arg;
4320
4321 /* Convert IP prefix string to struct prefix. */
4322 ret = str2prefix(prefix, &range);
4323 if (!ret) {
4324 vty_out(vty, "%% Malformed listen range\n");
4325 return CMD_WARNING_CONFIG_FAILED;
4326 }
4327
4328 afi = family2afi(range.family);
4329
4330 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4331 vty_out(vty,
4332 "%% Malformed listen range (link-local address)\n");
4333 return CMD_WARNING_CONFIG_FAILED;
4334 }
4335
4336 apply_mask(&range);
4337
4338 /* Check if same listen range is already configured. */
4339 existing_group = listen_range_exists(bgp, &range, 1);
4340 if (existing_group) {
4341 if (strcmp(existing_group->name, peergroup) == 0)
4342 return CMD_SUCCESS;
4343 else {
4344 vty_out(vty,
4345 "%% Same listen range is attached to peer-group %s\n",
4346 existing_group->name);
4347 return CMD_WARNING_CONFIG_FAILED;
4348 }
4349 }
4350
4351 /* Check if an overlapping listen range exists. */
4352 if (listen_range_exists(bgp, &range, 0)) {
4353 vty_out(vty,
4354 "%% Listen range overlaps with existing listen range\n");
4355 return CMD_WARNING_CONFIG_FAILED;
4356 }
4357
4358 group = peer_group_lookup(bgp, peergroup);
4359 if (!group) {
4360 vty_out(vty, "%% Configure the peer-group first\n");
4361 return CMD_WARNING_CONFIG_FAILED;
4362 }
4363
4364 ret = peer_group_listen_range_add(group, &range);
4365 return bgp_vty_return(vty, ret);
4366 }
4367
4368 DEFUN (no_bgp_listen_range,
4369 no_bgp_listen_range_cmd,
4370 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4371 NO_STR
4372 BGP_STR
4373 "Unconfigure BGP dynamic neighbors listen range\n"
4374 "Unconfigure BGP dynamic neighbors listen range\n"
4375 NEIGHBOR_ADDR_STR
4376 "Member of the peer-group\n"
4377 "Peer-group name\n")
4378 {
4379 VTY_DECLVAR_CONTEXT(bgp, bgp);
4380 struct prefix range;
4381 struct peer_group *group;
4382 afi_t afi;
4383 int ret;
4384 int idx = 0;
4385
4386 argv_find(argv, argc, "A.B.C.D/M", &idx);
4387 argv_find(argv, argc, "X:X::X:X/M", &idx);
4388 char *prefix = argv[idx]->arg;
4389 argv_find(argv, argc, "PGNAME", &idx);
4390 char *peergroup = argv[idx]->arg;
4391
4392 /* Convert IP prefix string to struct prefix. */
4393 ret = str2prefix(prefix, &range);
4394 if (!ret) {
4395 vty_out(vty, "%% Malformed listen range\n");
4396 return CMD_WARNING_CONFIG_FAILED;
4397 }
4398
4399 afi = family2afi(range.family);
4400
4401 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4402 vty_out(vty,
4403 "%% Malformed listen range (link-local address)\n");
4404 return CMD_WARNING_CONFIG_FAILED;
4405 }
4406
4407 apply_mask(&range);
4408
4409 group = peer_group_lookup(bgp, peergroup);
4410 if (!group) {
4411 vty_out(vty, "%% Peer-group does not exist\n");
4412 return CMD_WARNING_CONFIG_FAILED;
4413 }
4414
4415 ret = peer_group_listen_range_del(group, &range);
4416 return bgp_vty_return(vty, ret);
4417 }
4418
4419 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4420 {
4421 struct peer_group *group;
4422 struct listnode *node, *nnode, *rnode, *nrnode;
4423 struct prefix *range;
4424 afi_t afi;
4425
4426 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4427 vty_out(vty, " bgp listen limit %d\n",
4428 bgp->dynamic_neighbors_limit);
4429
4430 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4431 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4432 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4433 nrnode, range)) {
4434 vty_out(vty,
4435 " bgp listen range %pFX peer-group %s\n",
4436 range, group->name);
4437 }
4438 }
4439 }
4440 }
4441
4442
4443 DEFUN (bgp_disable_connected_route_check,
4444 bgp_disable_connected_route_check_cmd,
4445 "bgp disable-ebgp-connected-route-check",
4446 BGP_STR
4447 "Disable checking if nexthop is connected on ebgp sessions\n")
4448 {
4449 VTY_DECLVAR_CONTEXT(bgp, bgp);
4450 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4451 bgp_clear_star_soft_in(vty, bgp->name);
4452
4453 return CMD_SUCCESS;
4454 }
4455
4456 DEFUN (no_bgp_disable_connected_route_check,
4457 no_bgp_disable_connected_route_check_cmd,
4458 "no bgp disable-ebgp-connected-route-check",
4459 NO_STR
4460 BGP_STR
4461 "Disable checking if nexthop is connected on ebgp sessions\n")
4462 {
4463 VTY_DECLVAR_CONTEXT(bgp, bgp);
4464 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4465 bgp_clear_star_soft_in(vty, bgp->name);
4466
4467 return CMD_SUCCESS;
4468 }
4469
4470
4471 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4472 const char *as_str)
4473 {
4474 VTY_DECLVAR_CONTEXT(bgp, bgp);
4475 int ret;
4476 as_t as;
4477 int as_type = AS_SPECIFIED;
4478 union sockunion su;
4479
4480 if (as_str[0] == 'i') {
4481 as = 0;
4482 as_type = AS_INTERNAL;
4483 } else if (as_str[0] == 'e') {
4484 as = 0;
4485 as_type = AS_EXTERNAL;
4486 } else {
4487 /* Get AS number. */
4488 as = strtoul(as_str, NULL, 10);
4489 }
4490
4491 /* If peer is peer group or interface peer, call proper function. */
4492 ret = str2sockunion(peer_str, &su);
4493 if (ret < 0) {
4494 struct peer *peer;
4495
4496 /* Check if existing interface peer */
4497 peer = peer_lookup_by_conf_if(bgp, peer_str);
4498
4499 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4500
4501 /* if not interface peer, check peer-group settings */
4502 if (ret < 0 && !peer) {
4503 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4504 if (ret < 0) {
4505 vty_out(vty,
4506 "%% Create the peer-group or interface first\n");
4507 return CMD_WARNING_CONFIG_FAILED;
4508 }
4509 return CMD_SUCCESS;
4510 }
4511 } else {
4512 if (peer_address_self_check(bgp, &su)) {
4513 vty_out(vty,
4514 "%% Can not configure the local system as neighbor\n");
4515 return CMD_WARNING_CONFIG_FAILED;
4516 }
4517 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4518 }
4519
4520 return bgp_vty_return(vty, ret);
4521 }
4522
4523 DEFUN (bgp_default_shutdown,
4524 bgp_default_shutdown_cmd,
4525 "[no] bgp default shutdown",
4526 NO_STR
4527 BGP_STR
4528 "Configure BGP defaults\n"
4529 "Apply administrative shutdown to newly configured peers\n")
4530 {
4531 VTY_DECLVAR_CONTEXT(bgp, bgp);
4532 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4533 return CMD_SUCCESS;
4534 }
4535
4536 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4537 BGP_STR
4538 "Administrative shutdown of the BGP instance\n"
4539 "Add a shutdown message (RFC 8203)\n"
4540 "Shutdown message\n")
4541 {
4542 char *msgstr = NULL;
4543
4544 VTY_DECLVAR_CONTEXT(bgp, bgp);
4545
4546 if (argc > 3)
4547 msgstr = argv_concat(argv, argc, 3);
4548
4549 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4550 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4551 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4552 return CMD_WARNING_CONFIG_FAILED;
4553 }
4554
4555 bgp_shutdown_enable(bgp, msgstr);
4556 XFREE(MTYPE_TMP, msgstr);
4557
4558 return CMD_SUCCESS;
4559 }
4560
4561 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4562 BGP_STR "Administrative shutdown of the BGP instance\n")
4563 {
4564 VTY_DECLVAR_CONTEXT(bgp, bgp);
4565
4566 bgp_shutdown_enable(bgp, NULL);
4567
4568 return CMD_SUCCESS;
4569 }
4570
4571 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4572 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4573 {
4574 VTY_DECLVAR_CONTEXT(bgp, bgp);
4575
4576 bgp_shutdown_disable(bgp);
4577
4578 return CMD_SUCCESS;
4579 }
4580
4581 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4582 "no bgp shutdown message MSG...", NO_STR BGP_STR
4583 "Administrative shutdown of the BGP instance\n"
4584 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4585
4586 DEFUN (neighbor_remote_as,
4587 neighbor_remote_as_cmd,
4588 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4589 NEIGHBOR_STR
4590 NEIGHBOR_ADDR_STR2
4591 "Specify a BGP neighbor\n"
4592 AS_STR
4593 "Internal BGP peer\n"
4594 "External BGP peer\n")
4595 {
4596 int idx_peer = 1;
4597 int idx_remote_as = 3;
4598 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4599 argv[idx_remote_as]->arg);
4600 }
4601
4602 DEFPY (bgp_allow_martian,
4603 bgp_allow_martian_cmd,
4604 "[no]$no bgp allow-martian-nexthop",
4605 NO_STR
4606 BGP_STR
4607 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4608 {
4609 VTY_DECLVAR_CONTEXT(bgp, bgp);
4610
4611 if (no)
4612 bgp->allow_martian = false;
4613 else
4614 bgp->allow_martian = true;
4615
4616 return CMD_SUCCESS;
4617 }
4618
4619 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4620 * sessions do not wait for hold timer expiry to bring down the sessions
4621 * when nexthop becomes unreachable
4622 */
4623 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4624 BGP_STR "Fast convergence for bgp sessions\n")
4625 {
4626 VTY_DECLVAR_CONTEXT(bgp, bgp);
4627 bgp->fast_convergence = true;
4628
4629 return CMD_SUCCESS;
4630 }
4631
4632 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4633 "no bgp fast-convergence",
4634 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4635 {
4636 VTY_DECLVAR_CONTEXT(bgp, bgp);
4637 bgp->fast_convergence = false;
4638
4639 return CMD_SUCCESS;
4640 }
4641
4642 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4643 int v6only,
4644 const char *peer_group_name,
4645 const char *as_str)
4646 {
4647 VTY_DECLVAR_CONTEXT(bgp, bgp);
4648 as_t as = 0;
4649 int as_type = AS_UNSPECIFIED;
4650 struct peer *peer;
4651 struct peer_group *group;
4652 int ret = 0;
4653
4654 group = peer_group_lookup(bgp, conf_if);
4655
4656 if (group) {
4657 vty_out(vty, "%% Name conflict with peer-group \n");
4658 return CMD_WARNING_CONFIG_FAILED;
4659 }
4660
4661 if (as_str) {
4662 if (as_str[0] == 'i') {
4663 as_type = AS_INTERNAL;
4664 } else if (as_str[0] == 'e') {
4665 as_type = AS_EXTERNAL;
4666 } else {
4667 /* Get AS number. */
4668 as = strtoul(as_str, NULL, 10);
4669 as_type = AS_SPECIFIED;
4670 }
4671 }
4672
4673 peer = peer_lookup_by_conf_if(bgp, conf_if);
4674 if (peer) {
4675 if (as_str)
4676 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4677 } else {
4678 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4679 NULL, true);
4680
4681 if (!peer) {
4682 vty_out(vty, "%% BGP failed to create peer\n");
4683 return CMD_WARNING_CONFIG_FAILED;
4684 }
4685
4686 if (v6only)
4687 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4688
4689 /* Request zebra to initiate IPv6 RAs on this interface. We do
4690 * this
4691 * any unnumbered peer in order to not worry about run-time
4692 * transitions
4693 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4694 * address
4695 * gets deleted later etc.)
4696 */
4697 if (peer->ifp)
4698 bgp_zebra_initiate_radv(bgp, peer);
4699 }
4700
4701 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4702 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4703 if (v6only)
4704 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4705 else
4706 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4707
4708 /* v6only flag changed. Reset bgp seesion */
4709 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4710 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4711 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4712 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4713 } else
4714 bgp_session_reset(peer);
4715 }
4716
4717 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4718 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4719 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4720 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4721 }
4722
4723 if (peer_group_name) {
4724 group = peer_group_lookup(bgp, peer_group_name);
4725 if (!group) {
4726 vty_out(vty, "%% Configure the peer-group first\n");
4727 return CMD_WARNING_CONFIG_FAILED;
4728 }
4729
4730 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4731 }
4732
4733 return bgp_vty_return(vty, ret);
4734 }
4735
4736 DEFUN (neighbor_interface_config,
4737 neighbor_interface_config_cmd,
4738 "neighbor WORD interface [peer-group PGNAME]",
4739 NEIGHBOR_STR
4740 "Interface name or neighbor tag\n"
4741 "Enable BGP on interface\n"
4742 "Member of the peer-group\n"
4743 "Peer-group name\n")
4744 {
4745 int idx_word = 1;
4746 int idx_peer_group_word = 4;
4747
4748 if (argc > idx_peer_group_word)
4749 return peer_conf_interface_get(
4750 vty, argv[idx_word]->arg, 0,
4751 argv[idx_peer_group_word]->arg, NULL);
4752 else
4753 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4754 NULL, NULL);
4755 }
4756
4757 DEFUN (neighbor_interface_config_v6only,
4758 neighbor_interface_config_v6only_cmd,
4759 "neighbor WORD interface v6only [peer-group PGNAME]",
4760 NEIGHBOR_STR
4761 "Interface name or neighbor tag\n"
4762 "Enable BGP on interface\n"
4763 "Enable BGP with v6 link-local only\n"
4764 "Member of the peer-group\n"
4765 "Peer-group name\n")
4766 {
4767 int idx_word = 1;
4768 int idx_peer_group_word = 5;
4769
4770 if (argc > idx_peer_group_word)
4771 return peer_conf_interface_get(
4772 vty, argv[idx_word]->arg, 1,
4773 argv[idx_peer_group_word]->arg, NULL);
4774
4775 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4776 }
4777
4778
4779 DEFUN (neighbor_interface_config_remote_as,
4780 neighbor_interface_config_remote_as_cmd,
4781 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4782 NEIGHBOR_STR
4783 "Interface name or neighbor tag\n"
4784 "Enable BGP on interface\n"
4785 "Specify a BGP neighbor\n"
4786 AS_STR
4787 "Internal BGP peer\n"
4788 "External BGP peer\n")
4789 {
4790 int idx_word = 1;
4791 int idx_remote_as = 4;
4792 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4793 argv[idx_remote_as]->arg);
4794 }
4795
4796 DEFUN (neighbor_interface_v6only_config_remote_as,
4797 neighbor_interface_v6only_config_remote_as_cmd,
4798 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4799 NEIGHBOR_STR
4800 "Interface name or neighbor tag\n"
4801 "Enable BGP with v6 link-local only\n"
4802 "Enable BGP on interface\n"
4803 "Specify a BGP neighbor\n"
4804 AS_STR
4805 "Internal BGP peer\n"
4806 "External BGP peer\n")
4807 {
4808 int idx_word = 1;
4809 int idx_remote_as = 5;
4810 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4811 argv[idx_remote_as]->arg);
4812 }
4813
4814 DEFUN (neighbor_peer_group,
4815 neighbor_peer_group_cmd,
4816 "neighbor WORD peer-group",
4817 NEIGHBOR_STR
4818 "Interface name or neighbor tag\n"
4819 "Configure peer-group\n")
4820 {
4821 VTY_DECLVAR_CONTEXT(bgp, bgp);
4822 int idx_word = 1;
4823 struct peer *peer;
4824 struct peer_group *group;
4825
4826 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4827 if (peer) {
4828 vty_out(vty, "%% Name conflict with interface: \n");
4829 return CMD_WARNING_CONFIG_FAILED;
4830 }
4831
4832 group = peer_group_get(bgp, argv[idx_word]->arg);
4833 if (!group) {
4834 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4835 return CMD_WARNING_CONFIG_FAILED;
4836 }
4837
4838 return CMD_SUCCESS;
4839 }
4840
4841 DEFUN (no_neighbor,
4842 no_neighbor_cmd,
4843 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4844 NO_STR
4845 NEIGHBOR_STR
4846 NEIGHBOR_ADDR_STR2
4847 "Specify a BGP neighbor\n"
4848 AS_STR
4849 "Internal BGP peer\n"
4850 "External BGP peer\n")
4851 {
4852 VTY_DECLVAR_CONTEXT(bgp, bgp);
4853 int idx_peer = 2;
4854 int ret;
4855 union sockunion su;
4856 struct peer_group *group;
4857 struct peer *peer;
4858 struct peer *other;
4859
4860 ret = str2sockunion(argv[idx_peer]->arg, &su);
4861 if (ret < 0) {
4862 /* look up for neighbor by interface name config. */
4863 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4864 if (peer) {
4865 /* Request zebra to terminate IPv6 RAs on this
4866 * interface. */
4867 if (peer->ifp)
4868 bgp_zebra_terminate_radv(peer->bgp, peer);
4869 peer_notify_unconfig(peer);
4870 peer_delete(peer);
4871 return CMD_SUCCESS;
4872 }
4873
4874 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4875 if (group) {
4876 peer_group_notify_unconfig(group);
4877 peer_group_delete(group);
4878 } else {
4879 vty_out(vty, "%% Create the peer-group first\n");
4880 return CMD_WARNING_CONFIG_FAILED;
4881 }
4882 } else {
4883 peer = peer_lookup(bgp, &su);
4884 if (peer) {
4885 if (peer_dynamic_neighbor(peer)) {
4886 vty_out(vty,
4887 "%% Operation not allowed on a dynamic neighbor\n");
4888 return CMD_WARNING_CONFIG_FAILED;
4889 }
4890
4891 other = peer->doppelganger;
4892
4893 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4894 bgp_zebra_terminate_radv(peer->bgp, peer);
4895
4896 peer_notify_unconfig(peer);
4897 peer_delete(peer);
4898 if (other && other->status != Deleted) {
4899 peer_notify_unconfig(other);
4900 peer_delete(other);
4901 }
4902 }
4903 }
4904
4905 return CMD_SUCCESS;
4906 }
4907
4908 DEFUN (no_neighbor_interface_config,
4909 no_neighbor_interface_config_cmd,
4910 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4911 NO_STR
4912 NEIGHBOR_STR
4913 "Interface name\n"
4914 "Configure BGP on interface\n"
4915 "Enable BGP with v6 link-local only\n"
4916 "Member of the peer-group\n"
4917 "Peer-group name\n"
4918 "Specify a BGP neighbor\n"
4919 AS_STR
4920 "Internal BGP peer\n"
4921 "External BGP peer\n")
4922 {
4923 VTY_DECLVAR_CONTEXT(bgp, bgp);
4924 int idx_word = 2;
4925 struct peer *peer;
4926
4927 /* look up for neighbor by interface name config. */
4928 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4929 if (peer) {
4930 /* Request zebra to terminate IPv6 RAs on this interface. */
4931 if (peer->ifp)
4932 bgp_zebra_terminate_radv(peer->bgp, peer);
4933 peer_notify_unconfig(peer);
4934 peer_delete(peer);
4935 } else {
4936 vty_out(vty, "%% Create the bgp interface first\n");
4937 return CMD_WARNING_CONFIG_FAILED;
4938 }
4939 return CMD_SUCCESS;
4940 }
4941
4942 DEFUN (no_neighbor_peer_group,
4943 no_neighbor_peer_group_cmd,
4944 "no neighbor WORD peer-group",
4945 NO_STR
4946 NEIGHBOR_STR
4947 "Neighbor tag\n"
4948 "Configure peer-group\n")
4949 {
4950 VTY_DECLVAR_CONTEXT(bgp, bgp);
4951 int idx_word = 2;
4952 struct peer_group *group;
4953
4954 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4955 if (group) {
4956 peer_group_notify_unconfig(group);
4957 peer_group_delete(group);
4958 } else {
4959 vty_out(vty, "%% Create the peer-group first\n");
4960 return CMD_WARNING_CONFIG_FAILED;
4961 }
4962 return CMD_SUCCESS;
4963 }
4964
4965 DEFUN (no_neighbor_interface_peer_group_remote_as,
4966 no_neighbor_interface_peer_group_remote_as_cmd,
4967 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4968 NO_STR
4969 NEIGHBOR_STR
4970 "Interface name or neighbor tag\n"
4971 "Specify a BGP neighbor\n"
4972 AS_STR
4973 "Internal BGP peer\n"
4974 "External BGP peer\n")
4975 {
4976 VTY_DECLVAR_CONTEXT(bgp, bgp);
4977 int idx_word = 2;
4978 struct peer_group *group;
4979 struct peer *peer;
4980
4981 /* look up for neighbor by interface name config. */
4982 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4983 if (peer) {
4984 peer_as_change(peer, 0, AS_UNSPECIFIED);
4985 return CMD_SUCCESS;
4986 }
4987
4988 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4989 if (group)
4990 peer_group_remote_as_delete(group);
4991 else {
4992 vty_out(vty, "%% Create the peer-group or interface first\n");
4993 return CMD_WARNING_CONFIG_FAILED;
4994 }
4995 return CMD_SUCCESS;
4996 }
4997
4998 DEFUN (neighbor_local_as,
4999 neighbor_local_as_cmd,
5000 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
5001 NEIGHBOR_STR
5002 NEIGHBOR_ADDR_STR2
5003 "Specify a local-as number\n"
5004 "AS number used as local AS\n")
5005 {
5006 int idx_peer = 1;
5007 int idx_number = 3;
5008 struct peer *peer;
5009 int ret;
5010 as_t as;
5011
5012 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5013 if (!peer)
5014 return CMD_WARNING_CONFIG_FAILED;
5015
5016 as = strtoul(argv[idx_number]->arg, NULL, 10);
5017 ret = peer_local_as_set(peer, as, 0, 0);
5018 return bgp_vty_return(vty, ret);
5019 }
5020
5021 DEFUN (neighbor_local_as_no_prepend,
5022 neighbor_local_as_no_prepend_cmd,
5023 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
5024 NEIGHBOR_STR
5025 NEIGHBOR_ADDR_STR2
5026 "Specify a local-as number\n"
5027 "AS number used as local AS\n"
5028 "Do not prepend local-as to updates from ebgp peers\n")
5029 {
5030 int idx_peer = 1;
5031 int idx_number = 3;
5032 struct peer *peer;
5033 int ret;
5034 as_t as;
5035
5036 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5037 if (!peer)
5038 return CMD_WARNING_CONFIG_FAILED;
5039
5040 as = strtoul(argv[idx_number]->arg, NULL, 10);
5041 ret = peer_local_as_set(peer, as, 1, 0);
5042 return bgp_vty_return(vty, ret);
5043 }
5044
5045 DEFUN (neighbor_local_as_no_prepend_replace_as,
5046 neighbor_local_as_no_prepend_replace_as_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
5048 NEIGHBOR_STR
5049 NEIGHBOR_ADDR_STR2
5050 "Specify a local-as number\n"
5051 "AS number used as local AS\n"
5052 "Do not prepend local-as to updates from ebgp peers\n"
5053 "Do not prepend local-as to updates from ibgp peers\n")
5054 {
5055 int idx_peer = 1;
5056 int idx_number = 3;
5057 struct peer *peer;
5058 int ret;
5059 as_t as;
5060
5061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5062 if (!peer)
5063 return CMD_WARNING_CONFIG_FAILED;
5064
5065 as = strtoul(argv[idx_number]->arg, NULL, 10);
5066 ret = peer_local_as_set(peer, as, 1, 1);
5067 return bgp_vty_return(vty, ret);
5068 }
5069
5070 DEFUN (no_neighbor_local_as,
5071 no_neighbor_local_as_cmd,
5072 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5073 NO_STR
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR2
5076 "Specify a local-as number\n"
5077 "AS number used as local AS\n"
5078 "Do not prepend local-as to updates from ebgp peers\n"
5079 "Do not prepend local-as to updates from ibgp peers\n")
5080 {
5081 int idx_peer = 2;
5082 struct peer *peer;
5083 int ret;
5084
5085 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5086 if (!peer)
5087 return CMD_WARNING_CONFIG_FAILED;
5088
5089 ret = peer_local_as_unset(peer);
5090 return bgp_vty_return(vty, ret);
5091 }
5092
5093
5094 DEFUN (neighbor_solo,
5095 neighbor_solo_cmd,
5096 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5097 NEIGHBOR_STR
5098 NEIGHBOR_ADDR_STR2
5099 "Solo peer - part of its own update group\n")
5100 {
5101 int idx_peer = 1;
5102 struct peer *peer;
5103 int ret;
5104
5105 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5106 if (!peer)
5107 return CMD_WARNING_CONFIG_FAILED;
5108
5109 ret = update_group_adjust_soloness(peer, 1);
5110 return bgp_vty_return(vty, ret);
5111 }
5112
5113 DEFUN (no_neighbor_solo,
5114 no_neighbor_solo_cmd,
5115 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5116 NO_STR
5117 NEIGHBOR_STR
5118 NEIGHBOR_ADDR_STR2
5119 "Solo peer - part of its own update group\n")
5120 {
5121 int idx_peer = 2;
5122 struct peer *peer;
5123 int ret;
5124
5125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5126 if (!peer)
5127 return CMD_WARNING_CONFIG_FAILED;
5128
5129 ret = update_group_adjust_soloness(peer, 0);
5130 return bgp_vty_return(vty, ret);
5131 }
5132
5133 DEFUN (neighbor_password,
5134 neighbor_password_cmd,
5135 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5136 NEIGHBOR_STR
5137 NEIGHBOR_ADDR_STR2
5138 "Set a password\n"
5139 "The password\n")
5140 {
5141 int idx_peer = 1;
5142 int idx_line = 3;
5143 struct peer *peer;
5144 int ret;
5145
5146 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5147 if (!peer)
5148 return CMD_WARNING_CONFIG_FAILED;
5149
5150 ret = peer_password_set(peer, argv[idx_line]->arg);
5151 return bgp_vty_return(vty, ret);
5152 }
5153
5154 DEFUN (no_neighbor_password,
5155 no_neighbor_password_cmd,
5156 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5157 NO_STR
5158 NEIGHBOR_STR
5159 NEIGHBOR_ADDR_STR2
5160 "Set a password\n"
5161 "The password\n")
5162 {
5163 int idx_peer = 2;
5164 struct peer *peer;
5165 int ret;
5166
5167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5168 if (!peer)
5169 return CMD_WARNING_CONFIG_FAILED;
5170
5171 ret = peer_password_unset(peer);
5172 return bgp_vty_return(vty, ret);
5173 }
5174
5175 DEFUN (neighbor_activate,
5176 neighbor_activate_cmd,
5177 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5178 NEIGHBOR_STR
5179 NEIGHBOR_ADDR_STR2
5180 "Enable the Address Family for this Neighbor\n")
5181 {
5182 int idx_peer = 1;
5183 int ret;
5184 struct peer *peer;
5185
5186 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5187 if (!peer)
5188 return CMD_WARNING_CONFIG_FAILED;
5189
5190 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5191 return bgp_vty_return(vty, ret);
5192 }
5193
5194 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5195 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5196 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5197 "Enable the Address Family for this Neighbor\n")
5198
5199 DEFUN (no_neighbor_activate,
5200 no_neighbor_activate_cmd,
5201 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5202 NO_STR
5203 NEIGHBOR_STR
5204 NEIGHBOR_ADDR_STR2
5205 "Enable the Address Family for this Neighbor\n")
5206 {
5207 int idx_peer = 2;
5208 int ret;
5209 struct peer *peer;
5210
5211 /* Lookup peer. */
5212 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5213 if (!peer)
5214 return CMD_WARNING_CONFIG_FAILED;
5215
5216 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5217 return bgp_vty_return(vty, ret);
5218 }
5219
5220 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5221 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5223 "Enable the Address Family for this Neighbor\n")
5224
5225 DEFUN (neighbor_set_peer_group,
5226 neighbor_set_peer_group_cmd,
5227 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Member of the peer-group\n"
5231 "Peer-group name\n")
5232 {
5233 VTY_DECLVAR_CONTEXT(bgp, bgp);
5234 int idx_peer = 1;
5235 int idx_word = 3;
5236 int ret;
5237 as_t as;
5238 union sockunion su;
5239 struct peer *peer;
5240 struct peer_group *group;
5241
5242 ret = str2sockunion(argv[idx_peer]->arg, &su);
5243 if (ret < 0) {
5244 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5245 if (!peer) {
5246 vty_out(vty, "%% Malformed address or name: %s\n",
5247 argv[idx_peer]->arg);
5248 return CMD_WARNING_CONFIG_FAILED;
5249 }
5250 } else {
5251 if (peer_address_self_check(bgp, &su)) {
5252 vty_out(vty,
5253 "%% Can not configure the local system as neighbor\n");
5254 return CMD_WARNING_CONFIG_FAILED;
5255 }
5256
5257 /* Disallow for dynamic neighbor. */
5258 peer = peer_lookup(bgp, &su);
5259 if (peer && peer_dynamic_neighbor(peer)) {
5260 vty_out(vty,
5261 "%% Operation not allowed on a dynamic neighbor\n");
5262 return CMD_WARNING_CONFIG_FAILED;
5263 }
5264 }
5265
5266 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5267 if (!group) {
5268 vty_out(vty, "%% Configure the peer-group first\n");
5269 return CMD_WARNING_CONFIG_FAILED;
5270 }
5271
5272 ret = peer_group_bind(bgp, &su, peer, group, &as);
5273
5274 return bgp_vty_return(vty, ret);
5275 }
5276
5277 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5278 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5279 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5280 "Member of the peer-group\n"
5281 "Peer-group name\n")
5282
5283 DEFUN (no_neighbor_set_peer_group,
5284 no_neighbor_set_peer_group_cmd,
5285 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5286 NO_STR
5287 NEIGHBOR_STR
5288 NEIGHBOR_ADDR_STR2
5289 "Member of the peer-group\n"
5290 "Peer-group name\n")
5291 {
5292 VTY_DECLVAR_CONTEXT(bgp, bgp);
5293 int idx_peer = 2;
5294 int idx_word = 4;
5295 int ret;
5296 struct peer *peer;
5297 struct peer_group *group;
5298
5299 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5300 if (!peer)
5301 return CMD_WARNING_CONFIG_FAILED;
5302
5303 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5304 if (!group) {
5305 vty_out(vty, "%% Configure the peer-group first\n");
5306 return CMD_WARNING_CONFIG_FAILED;
5307 }
5308
5309 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5310 bgp_zebra_terminate_radv(peer->bgp, peer);
5311
5312 peer_notify_unconfig(peer);
5313 ret = peer_delete(peer);
5314
5315 return bgp_vty_return(vty, ret);
5316 }
5317
5318 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5319 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5320 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5321 "Member of the peer-group\n"
5322 "Peer-group name\n")
5323
5324 /* neighbor passive. */
5325 DEFUN (neighbor_passive,
5326 neighbor_passive_cmd,
5327 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5328 NEIGHBOR_STR
5329 NEIGHBOR_ADDR_STR2
5330 "Don't send open messages to this neighbor\n")
5331 {
5332 int idx_peer = 1;
5333 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5334 }
5335
5336 DEFUN (no_neighbor_passive,
5337 no_neighbor_passive_cmd,
5338 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5339 NO_STR
5340 NEIGHBOR_STR
5341 NEIGHBOR_ADDR_STR2
5342 "Don't send open messages to this neighbor\n")
5343 {
5344 int idx_peer = 2;
5345 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5346 }
5347
5348 /* neighbor shutdown. */
5349 DEFUN (neighbor_shutdown_msg,
5350 neighbor_shutdown_msg_cmd,
5351 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5352 NEIGHBOR_STR
5353 NEIGHBOR_ADDR_STR2
5354 "Administratively shut down this neighbor\n"
5355 "Add a shutdown message (RFC 8203)\n"
5356 "Shutdown message\n")
5357 {
5358 int idx_peer = 1;
5359
5360 if (argc >= 5) {
5361 struct peer *peer =
5362 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5363 char *message;
5364
5365 if (!peer)
5366 return CMD_WARNING_CONFIG_FAILED;
5367 message = argv_concat(argv, argc, 4);
5368 peer_tx_shutdown_message_set(peer, message);
5369 XFREE(MTYPE_TMP, message);
5370 }
5371
5372 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5373 }
5374
5375 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5376 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5377 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5378 "Administratively shut down this neighbor\n")
5379
5380 DEFUN (no_neighbor_shutdown_msg,
5381 no_neighbor_shutdown_msg_cmd,
5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5383 NO_STR
5384 NEIGHBOR_STR
5385 NEIGHBOR_ADDR_STR2
5386 "Administratively shut down this neighbor\n"
5387 "Remove a shutdown message (RFC 8203)\n"
5388 "Shutdown message\n")
5389 {
5390 int idx_peer = 2;
5391
5392 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5393 PEER_FLAG_SHUTDOWN);
5394 }
5395
5396 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5397 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5398 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5399 "Administratively shut down this neighbor\n")
5400
5401 DEFUN(neighbor_shutdown_rtt,
5402 neighbor_shutdown_rtt_cmd,
5403 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5404 NEIGHBOR_STR
5405 NEIGHBOR_ADDR_STR2
5406 "Administratively shut down this neighbor\n"
5407 "Shutdown if round-trip-time is higher than expected\n"
5408 "Round-trip-time in milliseconds\n"
5409 "Specify the number of keepalives before shutdown\n"
5410 "The number of keepalives with higher RTT to shutdown\n")
5411 {
5412 int idx_peer = 1;
5413 int idx_rtt = 4;
5414 int idx_count = 0;
5415 struct peer *peer;
5416
5417 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5418
5419 if (!peer)
5420 return CMD_WARNING_CONFIG_FAILED;
5421
5422 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5423
5424 if (argv_find(argv, argc, "count", &idx_count))
5425 peer->rtt_keepalive_conf =
5426 strtol(argv[idx_count + 1]->arg, NULL, 10);
5427
5428 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5429 PEER_FLAG_RTT_SHUTDOWN);
5430 }
5431
5432 DEFUN(no_neighbor_shutdown_rtt,
5433 no_neighbor_shutdown_rtt_cmd,
5434 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5435 NO_STR
5436 NEIGHBOR_STR
5437 NEIGHBOR_ADDR_STR2
5438 "Administratively shut down this neighbor\n"
5439 "Shutdown if round-trip-time is higher than expected\n"
5440 "Round-trip-time in milliseconds\n"
5441 "Specify the number of keepalives before shutdown\n"
5442 "The number of keepalives with higher RTT to shutdown\n")
5443 {
5444 int idx_peer = 2;
5445 struct peer *peer;
5446
5447 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5448
5449 if (!peer)
5450 return CMD_WARNING_CONFIG_FAILED;
5451
5452 peer->rtt_expected = 0;
5453 peer->rtt_keepalive_conf = 1;
5454
5455 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5456 PEER_FLAG_RTT_SHUTDOWN);
5457 }
5458
5459 /* neighbor capability dynamic. */
5460 DEFUN (neighbor_capability_dynamic,
5461 neighbor_capability_dynamic_cmd,
5462 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5463 NEIGHBOR_STR
5464 NEIGHBOR_ADDR_STR2
5465 "Advertise capability to the peer\n"
5466 "Advertise dynamic capability to this neighbor\n")
5467 {
5468 int idx_peer = 1;
5469 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5470 PEER_FLAG_DYNAMIC_CAPABILITY);
5471 }
5472
5473 DEFUN (no_neighbor_capability_dynamic,
5474 no_neighbor_capability_dynamic_cmd,
5475 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5476 NO_STR
5477 NEIGHBOR_STR
5478 NEIGHBOR_ADDR_STR2
5479 "Advertise capability to the peer\n"
5480 "Advertise dynamic capability to this neighbor\n")
5481 {
5482 int idx_peer = 2;
5483 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5484 PEER_FLAG_DYNAMIC_CAPABILITY);
5485 }
5486
5487 /* neighbor dont-capability-negotiate */
5488 DEFUN (neighbor_dont_capability_negotiate,
5489 neighbor_dont_capability_negotiate_cmd,
5490 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5491 NEIGHBOR_STR
5492 NEIGHBOR_ADDR_STR2
5493 "Do not perform capability negotiation\n")
5494 {
5495 int idx_peer = 1;
5496 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5497 PEER_FLAG_DONT_CAPABILITY);
5498 }
5499
5500 DEFUN (no_neighbor_dont_capability_negotiate,
5501 no_neighbor_dont_capability_negotiate_cmd,
5502 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5503 NO_STR
5504 NEIGHBOR_STR
5505 NEIGHBOR_ADDR_STR2
5506 "Do not perform capability negotiation\n")
5507 {
5508 int idx_peer = 2;
5509 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5510 PEER_FLAG_DONT_CAPABILITY);
5511 }
5512
5513 /* neighbor capability extended next hop encoding */
5514 DEFUN (neighbor_capability_enhe,
5515 neighbor_capability_enhe_cmd,
5516 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5517 NEIGHBOR_STR
5518 NEIGHBOR_ADDR_STR2
5519 "Advertise capability to the peer\n"
5520 "Advertise extended next-hop capability to the peer\n")
5521 {
5522 int idx_peer = 1;
5523 struct peer *peer;
5524
5525 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5526 if (peer && peer->conf_if)
5527 return CMD_SUCCESS;
5528
5529 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5530 PEER_FLAG_CAPABILITY_ENHE);
5531 }
5532
5533 DEFUN (no_neighbor_capability_enhe,
5534 no_neighbor_capability_enhe_cmd,
5535 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5536 NO_STR
5537 NEIGHBOR_STR
5538 NEIGHBOR_ADDR_STR2
5539 "Advertise capability to the peer\n"
5540 "Advertise extended next-hop capability to the peer\n")
5541 {
5542 int idx_peer = 2;
5543 struct peer *peer;
5544
5545 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5546 if (peer && peer->conf_if) {
5547 vty_out(vty,
5548 "Peer %s cannot have capability extended-nexthop turned off\n",
5549 argv[idx_peer]->arg);
5550 return CMD_WARNING_CONFIG_FAILED;
5551 }
5552
5553 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5554 PEER_FLAG_CAPABILITY_ENHE);
5555 }
5556
5557 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5558 afi_t afi, safi_t safi, uint32_t flag,
5559 int set)
5560 {
5561 int ret;
5562 struct peer *peer;
5563
5564 peer = peer_and_group_lookup_vty(vty, peer_str);
5565 if (!peer)
5566 return CMD_WARNING_CONFIG_FAILED;
5567
5568 if (set)
5569 ret = peer_af_flag_set(peer, afi, safi, flag);
5570 else
5571 ret = peer_af_flag_unset(peer, afi, safi, flag);
5572
5573 return bgp_vty_return(vty, ret);
5574 }
5575
5576 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5577 afi_t afi, safi_t safi, uint32_t flag)
5578 {
5579 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5580 }
5581
5582 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5583 afi_t afi, safi_t safi, uint32_t flag)
5584 {
5585 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5586 }
5587
5588 /* neighbor capability orf prefix-list. */
5589 DEFUN (neighbor_capability_orf_prefix,
5590 neighbor_capability_orf_prefix_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5592 NEIGHBOR_STR
5593 NEIGHBOR_ADDR_STR2
5594 "Advertise capability to the peer\n"
5595 "Advertise ORF capability to the peer\n"
5596 "Advertise prefixlist ORF capability to this neighbor\n"
5597 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5598 "Capability to RECEIVE the ORF from this neighbor\n"
5599 "Capability to SEND the ORF to this neighbor\n")
5600 {
5601 int idx_send_recv = 5;
5602 char *peer_str = argv[1]->arg;
5603 struct peer *peer;
5604 afi_t afi = bgp_node_afi(vty);
5605 safi_t safi = bgp_node_safi(vty);
5606
5607 peer = peer_and_group_lookup_vty(vty, peer_str);
5608 if (!peer)
5609 return CMD_WARNING_CONFIG_FAILED;
5610
5611 if (strmatch(argv[idx_send_recv]->text, "send"))
5612 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5613 PEER_FLAG_ORF_PREFIX_SM);
5614
5615 if (strmatch(argv[idx_send_recv]->text, "receive"))
5616 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5617 PEER_FLAG_ORF_PREFIX_RM);
5618
5619 if (strmatch(argv[idx_send_recv]->text, "both"))
5620 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5621 PEER_FLAG_ORF_PREFIX_SM)
5622 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5623 PEER_FLAG_ORF_PREFIX_RM);
5624
5625 return CMD_WARNING_CONFIG_FAILED;
5626 }
5627
5628 ALIAS_HIDDEN(
5629 neighbor_capability_orf_prefix,
5630 neighbor_capability_orf_prefix_hidden_cmd,
5631 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5632 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5633 "Advertise capability to the peer\n"
5634 "Advertise ORF capability to the peer\n"
5635 "Advertise prefixlist ORF capability to this neighbor\n"
5636 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5637 "Capability to RECEIVE the ORF from this neighbor\n"
5638 "Capability to SEND the ORF to this neighbor\n")
5639
5640 DEFUN (no_neighbor_capability_orf_prefix,
5641 no_neighbor_capability_orf_prefix_cmd,
5642 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5643 NO_STR
5644 NEIGHBOR_STR
5645 NEIGHBOR_ADDR_STR2
5646 "Advertise capability to the peer\n"
5647 "Advertise ORF capability to the peer\n"
5648 "Advertise prefixlist ORF capability to this neighbor\n"
5649 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5650 "Capability to RECEIVE the ORF from this neighbor\n"
5651 "Capability to SEND the ORF to this neighbor\n")
5652 {
5653 int idx_send_recv = 6;
5654 char *peer_str = argv[2]->arg;
5655 struct peer *peer;
5656 afi_t afi = bgp_node_afi(vty);
5657 safi_t safi = bgp_node_safi(vty);
5658
5659 peer = peer_and_group_lookup_vty(vty, peer_str);
5660 if (!peer)
5661 return CMD_WARNING_CONFIG_FAILED;
5662
5663 if (strmatch(argv[idx_send_recv]->text, "send"))
5664 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5665 PEER_FLAG_ORF_PREFIX_SM);
5666
5667 if (strmatch(argv[idx_send_recv]->text, "receive"))
5668 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5669 PEER_FLAG_ORF_PREFIX_RM);
5670
5671 if (strmatch(argv[idx_send_recv]->text, "both"))
5672 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5673 PEER_FLAG_ORF_PREFIX_SM)
5674 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5675 PEER_FLAG_ORF_PREFIX_RM);
5676
5677 return CMD_WARNING_CONFIG_FAILED;
5678 }
5679
5680 ALIAS_HIDDEN(
5681 no_neighbor_capability_orf_prefix,
5682 no_neighbor_capability_orf_prefix_hidden_cmd,
5683 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5684 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5685 "Advertise capability to the peer\n"
5686 "Advertise ORF capability to the peer\n"
5687 "Advertise prefixlist ORF capability to this neighbor\n"
5688 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5689 "Capability to RECEIVE the ORF from this neighbor\n"
5690 "Capability to SEND the ORF to this neighbor\n")
5691
5692 /* neighbor next-hop-self. */
5693 DEFUN (neighbor_nexthop_self,
5694 neighbor_nexthop_self_cmd,
5695 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5696 NEIGHBOR_STR
5697 NEIGHBOR_ADDR_STR2
5698 "Disable the next hop calculation for this neighbor\n")
5699 {
5700 int idx_peer = 1;
5701 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5702 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5703 }
5704
5705 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5706 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5707 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5708 "Disable the next hop calculation for this neighbor\n")
5709
5710 /* neighbor next-hop-self. */
5711 DEFUN (neighbor_nexthop_self_force,
5712 neighbor_nexthop_self_force_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5714 NEIGHBOR_STR
5715 NEIGHBOR_ADDR_STR2
5716 "Disable the next hop calculation for this neighbor\n"
5717 "Set the next hop to self for reflected routes\n")
5718 {
5719 int idx_peer = 1;
5720 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5721 bgp_node_safi(vty),
5722 PEER_FLAG_FORCE_NEXTHOP_SELF);
5723 }
5724
5725 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5726 neighbor_nexthop_self_force_hidden_cmd,
5727 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 "Disable the next hop calculation for this neighbor\n"
5730 "Set the next hop to self for reflected routes\n")
5731
5732 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5733 neighbor_nexthop_self_all_hidden_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Disable the next hop calculation for this neighbor\n"
5737 "Set the next hop to self for reflected routes\n")
5738
5739 DEFUN (no_neighbor_nexthop_self,
5740 no_neighbor_nexthop_self_cmd,
5741 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5742 NO_STR
5743 NEIGHBOR_STR
5744 NEIGHBOR_ADDR_STR2
5745 "Disable the next hop calculation for this neighbor\n")
5746 {
5747 int idx_peer = 2;
5748 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5749 bgp_node_afi(vty), bgp_node_safi(vty),
5750 PEER_FLAG_NEXTHOP_SELF);
5751 }
5752
5753 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5754 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5755 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5756 "Disable the next hop calculation for this neighbor\n")
5757
5758 DEFUN (no_neighbor_nexthop_self_force,
5759 no_neighbor_nexthop_self_force_cmd,
5760 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5761 NO_STR
5762 NEIGHBOR_STR
5763 NEIGHBOR_ADDR_STR2
5764 "Disable the next hop calculation for this neighbor\n"
5765 "Set the next hop to self for reflected routes\n")
5766 {
5767 int idx_peer = 2;
5768 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5769 bgp_node_afi(vty), bgp_node_safi(vty),
5770 PEER_FLAG_FORCE_NEXTHOP_SELF);
5771 }
5772
5773 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5774 no_neighbor_nexthop_self_force_hidden_cmd,
5775 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 "Disable the next hop calculation for this neighbor\n"
5778 "Set the next hop to self for reflected routes\n")
5779
5780 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5781 no_neighbor_nexthop_self_all_hidden_cmd,
5782 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5784 "Disable the next hop calculation for this neighbor\n"
5785 "Set the next hop to self for reflected routes\n")
5786
5787 /* neighbor as-override */
5788 DEFUN (neighbor_as_override,
5789 neighbor_as_override_cmd,
5790 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5791 NEIGHBOR_STR
5792 NEIGHBOR_ADDR_STR2
5793 "Override ASNs in outbound updates if aspath equals remote-as\n")
5794 {
5795 int idx_peer = 1;
5796 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5797 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5798 }
5799
5800 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5801 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5803 "Override ASNs in outbound updates if aspath equals remote-as\n")
5804
5805 DEFUN (no_neighbor_as_override,
5806 no_neighbor_as_override_cmd,
5807 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5808 NO_STR
5809 NEIGHBOR_STR
5810 NEIGHBOR_ADDR_STR2
5811 "Override ASNs in outbound updates if aspath equals remote-as\n")
5812 {
5813 int idx_peer = 2;
5814 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5815 bgp_node_afi(vty), bgp_node_safi(vty),
5816 PEER_FLAG_AS_OVERRIDE);
5817 }
5818
5819 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5820 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5822 "Override ASNs in outbound updates if aspath equals remote-as\n")
5823
5824 /* neighbor remove-private-AS. */
5825 DEFUN (neighbor_remove_private_as,
5826 neighbor_remove_private_as_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5828 NEIGHBOR_STR
5829 NEIGHBOR_ADDR_STR2
5830 "Remove private ASNs in outbound updates\n")
5831 {
5832 int idx_peer = 1;
5833 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5834 bgp_node_safi(vty),
5835 PEER_FLAG_REMOVE_PRIVATE_AS);
5836 }
5837
5838 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5840 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5841 "Remove private ASNs in outbound updates\n")
5842
5843 DEFUN (neighbor_remove_private_as_all,
5844 neighbor_remove_private_as_all_cmd,
5845 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5846 NEIGHBOR_STR
5847 NEIGHBOR_ADDR_STR2
5848 "Remove private ASNs in outbound updates\n"
5849 "Apply to all AS numbers\n")
5850 {
5851 int idx_peer = 1;
5852 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5853 bgp_node_safi(vty),
5854 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5855 }
5856
5857 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5858 neighbor_remove_private_as_all_hidden_cmd,
5859 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5861 "Remove private ASNs in outbound updates\n"
5862 "Apply to all AS numbers\n")
5863
5864 DEFUN (neighbor_remove_private_as_replace_as,
5865 neighbor_remove_private_as_replace_as_cmd,
5866 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
5869 "Remove private ASNs in outbound updates\n"
5870 "Replace private ASNs with our ASN in outbound updates\n")
5871 {
5872 int idx_peer = 1;
5873 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5874 bgp_node_safi(vty),
5875 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5876 }
5877
5878 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5879 neighbor_remove_private_as_replace_as_hidden_cmd,
5880 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5882 "Remove private ASNs in outbound updates\n"
5883 "Replace private ASNs with our ASN in outbound updates\n")
5884
5885 DEFUN (neighbor_remove_private_as_all_replace_as,
5886 neighbor_remove_private_as_all_replace_as_cmd,
5887 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5888 NEIGHBOR_STR
5889 NEIGHBOR_ADDR_STR2
5890 "Remove private ASNs in outbound updates\n"
5891 "Apply to all AS numbers\n"
5892 "Replace private ASNs with our ASN in outbound updates\n")
5893 {
5894 int idx_peer = 1;
5895 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5896 bgp_node_safi(vty),
5897 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5898 }
5899
5900 ALIAS_HIDDEN(
5901 neighbor_remove_private_as_all_replace_as,
5902 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5903 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5904 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5905 "Remove private ASNs in outbound updates\n"
5906 "Apply to all AS numbers\n"
5907 "Replace private ASNs with our ASN in outbound updates\n")
5908
5909 DEFUN (no_neighbor_remove_private_as,
5910 no_neighbor_remove_private_as_cmd,
5911 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5912 NO_STR
5913 NEIGHBOR_STR
5914 NEIGHBOR_ADDR_STR2
5915 "Remove private ASNs in outbound updates\n")
5916 {
5917 int idx_peer = 2;
5918 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5919 bgp_node_afi(vty), bgp_node_safi(vty),
5920 PEER_FLAG_REMOVE_PRIVATE_AS);
5921 }
5922
5923 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5924 no_neighbor_remove_private_as_hidden_cmd,
5925 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5926 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5927 "Remove private ASNs in outbound updates\n")
5928
5929 DEFUN (no_neighbor_remove_private_as_all,
5930 no_neighbor_remove_private_as_all_cmd,
5931 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5932 NO_STR
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
5935 "Remove private ASNs in outbound updates\n"
5936 "Apply to all AS numbers\n")
5937 {
5938 int idx_peer = 2;
5939 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5940 bgp_node_afi(vty), bgp_node_safi(vty),
5941 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5942 }
5943
5944 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5945 no_neighbor_remove_private_as_all_hidden_cmd,
5946 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5947 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Remove private ASNs in outbound updates\n"
5949 "Apply to all AS numbers\n")
5950
5951 DEFUN (no_neighbor_remove_private_as_replace_as,
5952 no_neighbor_remove_private_as_replace_as_cmd,
5953 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5954 NO_STR
5955 NEIGHBOR_STR
5956 NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n"
5958 "Replace private ASNs with our ASN in outbound updates\n")
5959 {
5960 int idx_peer = 2;
5961 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5962 bgp_node_afi(vty), bgp_node_safi(vty),
5963 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5964 }
5965
5966 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5967 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5968 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5970 "Remove private ASNs in outbound updates\n"
5971 "Replace private ASNs with our ASN in outbound updates\n")
5972
5973 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5974 no_neighbor_remove_private_as_all_replace_as_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5976 NO_STR
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Remove private ASNs in outbound updates\n"
5980 "Apply to all AS numbers\n"
5981 "Replace private ASNs with our ASN in outbound updates\n")
5982 {
5983 int idx_peer = 2;
5984 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5985 bgp_node_afi(vty), bgp_node_safi(vty),
5986 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5987 }
5988
5989 ALIAS_HIDDEN(
5990 no_neighbor_remove_private_as_all_replace_as,
5991 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5992 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5993 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5994 "Remove private ASNs in outbound updates\n"
5995 "Apply to all AS numbers\n"
5996 "Replace private ASNs with our ASN in outbound updates\n")
5997
5998
5999 /* neighbor send-community. */
6000 DEFUN (neighbor_send_community,
6001 neighbor_send_community_cmd,
6002 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6003 NEIGHBOR_STR
6004 NEIGHBOR_ADDR_STR2
6005 "Send Community attribute to this neighbor\n")
6006 {
6007 int idx_peer = 1;
6008
6009 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6010 bgp_node_safi(vty),
6011 PEER_FLAG_SEND_COMMUNITY);
6012 }
6013
6014 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6015 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6017 "Send Community attribute to this neighbor\n")
6018
6019 DEFUN (no_neighbor_send_community,
6020 no_neighbor_send_community_cmd,
6021 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6022 NO_STR
6023 NEIGHBOR_STR
6024 NEIGHBOR_ADDR_STR2
6025 "Send Community attribute to this neighbor\n")
6026 {
6027 int idx_peer = 2;
6028
6029 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6030 bgp_node_afi(vty), bgp_node_safi(vty),
6031 PEER_FLAG_SEND_COMMUNITY);
6032 }
6033
6034 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6035 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6036 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6037 "Send Community attribute to this neighbor\n")
6038
6039 /* neighbor send-community extended. */
6040 DEFUN (neighbor_send_community_type,
6041 neighbor_send_community_type_cmd,
6042 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6043 NEIGHBOR_STR
6044 NEIGHBOR_ADDR_STR2
6045 "Send Community attribute to this neighbor\n"
6046 "Send Standard and Extended Community attributes\n"
6047 "Send Standard, Large and Extended Community attributes\n"
6048 "Send Extended Community attributes\n"
6049 "Send Standard Community attributes\n"
6050 "Send Large Community attributes\n")
6051 {
6052 const char *type = argv[argc - 1]->text;
6053 char *peer_str = argv[1]->arg;
6054 struct peer *peer;
6055 afi_t afi = bgp_node_afi(vty);
6056 safi_t safi = bgp_node_safi(vty);
6057
6058 peer = peer_and_group_lookup_vty(vty, peer_str);
6059 if (!peer)
6060 return CMD_WARNING_CONFIG_FAILED;
6061
6062 if (strmatch(type, "standard"))
6063 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6064 PEER_FLAG_SEND_COMMUNITY);
6065
6066 if (strmatch(type, "extended"))
6067 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6068 PEER_FLAG_SEND_EXT_COMMUNITY);
6069
6070 if (strmatch(type, "large"))
6071 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6072 PEER_FLAG_SEND_LARGE_COMMUNITY);
6073
6074 if (strmatch(type, "both")) {
6075 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6076 PEER_FLAG_SEND_COMMUNITY)
6077 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6078 PEER_FLAG_SEND_EXT_COMMUNITY);
6079 }
6080 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6081 PEER_FLAG_SEND_COMMUNITY)
6082 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6083 PEER_FLAG_SEND_EXT_COMMUNITY)
6084 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6085 PEER_FLAG_SEND_LARGE_COMMUNITY);
6086 }
6087
6088 ALIAS_HIDDEN(
6089 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6090 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6091 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6092 "Send Community attribute to this neighbor\n"
6093 "Send Standard and Extended Community attributes\n"
6094 "Send Standard, Large and Extended Community attributes\n"
6095 "Send Extended Community attributes\n"
6096 "Send Standard Community attributes\n"
6097 "Send Large Community attributes\n")
6098
6099 DEFUN (no_neighbor_send_community_type,
6100 no_neighbor_send_community_type_cmd,
6101 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6102 NO_STR
6103 NEIGHBOR_STR
6104 NEIGHBOR_ADDR_STR2
6105 "Send Community attribute to this neighbor\n"
6106 "Send Standard and Extended Community attributes\n"
6107 "Send Standard, Large and Extended Community attributes\n"
6108 "Send Extended Community attributes\n"
6109 "Send Standard Community attributes\n"
6110 "Send Large Community attributes\n")
6111 {
6112 const char *type = argv[argc - 1]->text;
6113 char *peer_str = argv[2]->arg;
6114 struct peer *peer;
6115 afi_t afi = bgp_node_afi(vty);
6116 safi_t safi = bgp_node_safi(vty);
6117
6118 peer = peer_and_group_lookup_vty(vty, peer_str);
6119 if (!peer)
6120 return CMD_WARNING_CONFIG_FAILED;
6121
6122 if (strmatch(type, "standard"))
6123 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6124 PEER_FLAG_SEND_COMMUNITY);
6125
6126 if (strmatch(type, "extended"))
6127 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6128 PEER_FLAG_SEND_EXT_COMMUNITY);
6129
6130 if (strmatch(type, "large"))
6131 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6132 PEER_FLAG_SEND_LARGE_COMMUNITY);
6133
6134 if (strmatch(type, "both")) {
6135
6136 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6137 PEER_FLAG_SEND_COMMUNITY)
6138 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6139 PEER_FLAG_SEND_EXT_COMMUNITY);
6140 }
6141
6142 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6143 PEER_FLAG_SEND_COMMUNITY)
6144 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6145 PEER_FLAG_SEND_EXT_COMMUNITY)
6146 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6147 PEER_FLAG_SEND_LARGE_COMMUNITY);
6148 }
6149
6150 ALIAS_HIDDEN(
6151 no_neighbor_send_community_type,
6152 no_neighbor_send_community_type_hidden_cmd,
6153 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6154 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6155 "Send Community attribute to this neighbor\n"
6156 "Send Standard and Extended Community attributes\n"
6157 "Send Standard, Large and Extended Community attributes\n"
6158 "Send Extended Community attributes\n"
6159 "Send Standard Community attributes\n"
6160 "Send Large Community attributes\n")
6161
6162 /* neighbor soft-reconfig. */
6163 DEFUN (neighbor_soft_reconfiguration,
6164 neighbor_soft_reconfiguration_cmd,
6165 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6166 NEIGHBOR_STR
6167 NEIGHBOR_ADDR_STR2
6168 "Per neighbor soft reconfiguration\n"
6169 "Allow inbound soft reconfiguration for this neighbor\n")
6170 {
6171 int idx_peer = 1;
6172 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6173 bgp_node_safi(vty),
6174 PEER_FLAG_SOFT_RECONFIG);
6175 }
6176
6177 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6178 neighbor_soft_reconfiguration_hidden_cmd,
6179 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6180 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6181 "Per neighbor soft reconfiguration\n"
6182 "Allow inbound soft reconfiguration for this neighbor\n")
6183
6184 DEFUN (no_neighbor_soft_reconfiguration,
6185 no_neighbor_soft_reconfiguration_cmd,
6186 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6187 NO_STR
6188 NEIGHBOR_STR
6189 NEIGHBOR_ADDR_STR2
6190 "Per neighbor soft reconfiguration\n"
6191 "Allow inbound soft reconfiguration for this neighbor\n")
6192 {
6193 int idx_peer = 2;
6194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6195 bgp_node_afi(vty), bgp_node_safi(vty),
6196 PEER_FLAG_SOFT_RECONFIG);
6197 }
6198
6199 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6200 no_neighbor_soft_reconfiguration_hidden_cmd,
6201 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6203 "Per neighbor soft reconfiguration\n"
6204 "Allow inbound soft reconfiguration for this neighbor\n")
6205
6206 DEFUN (neighbor_route_reflector_client,
6207 neighbor_route_reflector_client_cmd,
6208 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6209 NEIGHBOR_STR
6210 NEIGHBOR_ADDR_STR2
6211 "Configure a neighbor as Route Reflector client\n")
6212 {
6213 int idx_peer = 1;
6214 struct peer *peer;
6215
6216
6217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6218 if (!peer)
6219 return CMD_WARNING_CONFIG_FAILED;
6220
6221 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6222 bgp_node_safi(vty),
6223 PEER_FLAG_REFLECTOR_CLIENT);
6224 }
6225
6226 ALIAS_HIDDEN(neighbor_route_reflector_client,
6227 neighbor_route_reflector_client_hidden_cmd,
6228 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6229 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6230 "Configure a neighbor as Route Reflector client\n")
6231
6232 DEFUN (no_neighbor_route_reflector_client,
6233 no_neighbor_route_reflector_client_cmd,
6234 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6235 NO_STR
6236 NEIGHBOR_STR
6237 NEIGHBOR_ADDR_STR2
6238 "Configure a neighbor as Route Reflector client\n")
6239 {
6240 int idx_peer = 2;
6241 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6242 bgp_node_afi(vty), bgp_node_safi(vty),
6243 PEER_FLAG_REFLECTOR_CLIENT);
6244 }
6245
6246 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6247 no_neighbor_route_reflector_client_hidden_cmd,
6248 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6249 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6250 "Configure a neighbor as Route Reflector client\n")
6251
6252 /* neighbor route-server-client. */
6253 DEFUN (neighbor_route_server_client,
6254 neighbor_route_server_client_cmd,
6255 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6256 NEIGHBOR_STR
6257 NEIGHBOR_ADDR_STR2
6258 "Configure a neighbor as Route Server client\n")
6259 {
6260 int idx_peer = 1;
6261 struct peer *peer;
6262
6263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6264 if (!peer)
6265 return CMD_WARNING_CONFIG_FAILED;
6266 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6267 bgp_node_safi(vty),
6268 PEER_FLAG_RSERVER_CLIENT);
6269 }
6270
6271 ALIAS_HIDDEN(neighbor_route_server_client,
6272 neighbor_route_server_client_hidden_cmd,
6273 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6275 "Configure a neighbor as Route Server client\n")
6276
6277 DEFUN (no_neighbor_route_server_client,
6278 no_neighbor_route_server_client_cmd,
6279 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6280 NO_STR
6281 NEIGHBOR_STR
6282 NEIGHBOR_ADDR_STR2
6283 "Configure a neighbor as Route Server client\n")
6284 {
6285 int idx_peer = 2;
6286 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6287 bgp_node_afi(vty), bgp_node_safi(vty),
6288 PEER_FLAG_RSERVER_CLIENT);
6289 }
6290
6291 ALIAS_HIDDEN(no_neighbor_route_server_client,
6292 no_neighbor_route_server_client_hidden_cmd,
6293 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6294 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6295 "Configure a neighbor as Route Server client\n")
6296
6297 DEFUN (neighbor_nexthop_local_unchanged,
6298 neighbor_nexthop_local_unchanged_cmd,
6299 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "Configure treatment of outgoing link-local nexthop attribute\n"
6303 "Leave link-local nexthop unchanged for this peer\n")
6304 {
6305 int idx_peer = 1;
6306 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6307 bgp_node_safi(vty),
6308 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6309 }
6310
6311 DEFUN (no_neighbor_nexthop_local_unchanged,
6312 no_neighbor_nexthop_local_unchanged_cmd,
6313 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6314 NO_STR
6315 NEIGHBOR_STR
6316 NEIGHBOR_ADDR_STR2
6317 "Configure treatment of outgoing link-local-nexthop attribute\n"
6318 "Leave link-local nexthop unchanged for this peer\n")
6319 {
6320 int idx_peer = 2;
6321 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6322 bgp_node_afi(vty), bgp_node_safi(vty),
6323 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6324 }
6325
6326 DEFUN (neighbor_attr_unchanged,
6327 neighbor_attr_unchanged_cmd,
6328 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6329 NEIGHBOR_STR
6330 NEIGHBOR_ADDR_STR2
6331 "BGP attribute is propagated unchanged to this neighbor\n"
6332 "As-path attribute\n"
6333 "Nexthop attribute\n"
6334 "Med attribute\n")
6335 {
6336 int idx = 0;
6337 char *peer_str = argv[1]->arg;
6338 struct peer *peer;
6339 bool aspath = false;
6340 bool nexthop = false;
6341 bool med = false;
6342 afi_t afi = bgp_node_afi(vty);
6343 safi_t safi = bgp_node_safi(vty);
6344 int ret = 0;
6345
6346 peer = peer_and_group_lookup_vty(vty, peer_str);
6347 if (!peer)
6348 return CMD_WARNING_CONFIG_FAILED;
6349
6350 if (argv_find(argv, argc, "as-path", &idx))
6351 aspath = true;
6352
6353 idx = 0;
6354 if (argv_find(argv, argc, "next-hop", &idx))
6355 nexthop = true;
6356
6357 idx = 0;
6358 if (argv_find(argv, argc, "med", &idx))
6359 med = true;
6360
6361 /* no flags means all of them! */
6362 if (!aspath && !nexthop && !med) {
6363 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6364 PEER_FLAG_AS_PATH_UNCHANGED);
6365 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6366 PEER_FLAG_NEXTHOP_UNCHANGED);
6367 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6368 PEER_FLAG_MED_UNCHANGED);
6369 } else {
6370 if (!aspath) {
6371 if (peer_af_flag_check(peer, afi, safi,
6372 PEER_FLAG_AS_PATH_UNCHANGED)) {
6373 ret |= peer_af_flag_unset_vty(
6374 vty, peer_str, afi, safi,
6375 PEER_FLAG_AS_PATH_UNCHANGED);
6376 }
6377 } else
6378 ret |= peer_af_flag_set_vty(
6379 vty, peer_str, afi, safi,
6380 PEER_FLAG_AS_PATH_UNCHANGED);
6381
6382 if (!nexthop) {
6383 if (peer_af_flag_check(peer, afi, safi,
6384 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6385 ret |= peer_af_flag_unset_vty(
6386 vty, peer_str, afi, safi,
6387 PEER_FLAG_NEXTHOP_UNCHANGED);
6388 }
6389 } else
6390 ret |= peer_af_flag_set_vty(
6391 vty, peer_str, afi, safi,
6392 PEER_FLAG_NEXTHOP_UNCHANGED);
6393
6394 if (!med) {
6395 if (peer_af_flag_check(peer, afi, safi,
6396 PEER_FLAG_MED_UNCHANGED)) {
6397 ret |= peer_af_flag_unset_vty(
6398 vty, peer_str, afi, safi,
6399 PEER_FLAG_MED_UNCHANGED);
6400 }
6401 } else
6402 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6403 PEER_FLAG_MED_UNCHANGED);
6404 }
6405
6406 return ret;
6407 }
6408
6409 ALIAS_HIDDEN(
6410 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6411 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6412 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6413 "BGP attribute is propagated unchanged to this neighbor\n"
6414 "As-path attribute\n"
6415 "Nexthop attribute\n"
6416 "Med attribute\n")
6417
6418 DEFUN (no_neighbor_attr_unchanged,
6419 no_neighbor_attr_unchanged_cmd,
6420 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR2
6424 "BGP attribute is propagated unchanged to this neighbor\n"
6425 "As-path attribute\n"
6426 "Nexthop attribute\n"
6427 "Med attribute\n")
6428 {
6429 int idx = 0;
6430 char *peer_str = argv[2]->arg;
6431 struct peer *peer;
6432 bool aspath = false;
6433 bool nexthop = false;
6434 bool med = false;
6435 afi_t afi = bgp_node_afi(vty);
6436 safi_t safi = bgp_node_safi(vty);
6437 int ret = 0;
6438
6439 peer = peer_and_group_lookup_vty(vty, peer_str);
6440 if (!peer)
6441 return CMD_WARNING_CONFIG_FAILED;
6442
6443 if (argv_find(argv, argc, "as-path", &idx))
6444 aspath = true;
6445
6446 idx = 0;
6447 if (argv_find(argv, argc, "next-hop", &idx))
6448 nexthop = true;
6449
6450 idx = 0;
6451 if (argv_find(argv, argc, "med", &idx))
6452 med = true;
6453
6454 if (!aspath && !nexthop && !med) // no flags means all of them!
6455 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6456 PEER_FLAG_AS_PATH_UNCHANGED)
6457 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6458 PEER_FLAG_NEXTHOP_UNCHANGED)
6459 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6460 PEER_FLAG_MED_UNCHANGED);
6461
6462 if (aspath)
6463 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6464 PEER_FLAG_AS_PATH_UNCHANGED);
6465
6466 if (nexthop)
6467 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6468 PEER_FLAG_NEXTHOP_UNCHANGED);
6469
6470 if (med)
6471 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6472 PEER_FLAG_MED_UNCHANGED);
6473
6474 return ret;
6475 }
6476
6477 ALIAS_HIDDEN(
6478 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6479 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6481 "BGP attribute is propagated unchanged to this neighbor\n"
6482 "As-path attribute\n"
6483 "Nexthop attribute\n"
6484 "Med attribute\n")
6485
6486 /* EBGP multihop configuration. */
6487 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6488 const char *ttl_str)
6489 {
6490 struct peer *peer;
6491 unsigned int ttl;
6492
6493 peer = peer_and_group_lookup_vty(vty, ip_str);
6494 if (!peer)
6495 return CMD_WARNING_CONFIG_FAILED;
6496
6497 if (peer->conf_if)
6498 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6499
6500 if (!ttl_str)
6501 ttl = MAXTTL;
6502 else
6503 ttl = strtoul(ttl_str, NULL, 10);
6504
6505 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6506 }
6507
6508 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6509 {
6510 struct peer *peer;
6511
6512 peer = peer_and_group_lookup_vty(vty, ip_str);
6513 if (!peer)
6514 return CMD_WARNING_CONFIG_FAILED;
6515
6516 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6517 }
6518
6519 /* neighbor ebgp-multihop. */
6520 DEFUN (neighbor_ebgp_multihop,
6521 neighbor_ebgp_multihop_cmd,
6522 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6523 NEIGHBOR_STR
6524 NEIGHBOR_ADDR_STR2
6525 "Allow EBGP neighbors not on directly connected networks\n")
6526 {
6527 int idx_peer = 1;
6528 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6529 }
6530
6531 DEFUN (neighbor_ebgp_multihop_ttl,
6532 neighbor_ebgp_multihop_ttl_cmd,
6533 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6534 NEIGHBOR_STR
6535 NEIGHBOR_ADDR_STR2
6536 "Allow EBGP neighbors not on directly connected networks\n"
6537 "maximum hop count\n")
6538 {
6539 int idx_peer = 1;
6540 int idx_number = 3;
6541 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6542 argv[idx_number]->arg);
6543 }
6544
6545 DEFUN (no_neighbor_ebgp_multihop,
6546 no_neighbor_ebgp_multihop_cmd,
6547 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6548 NO_STR
6549 NEIGHBOR_STR
6550 NEIGHBOR_ADDR_STR2
6551 "Allow EBGP neighbors not on directly connected networks\n"
6552 "maximum hop count\n")
6553 {
6554 int idx_peer = 2;
6555 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6556 }
6557
6558 DEFPY (neighbor_aigp,
6559 neighbor_aigp_cmd,
6560 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6561 NO_STR
6562 NEIGHBOR_STR
6563 NEIGHBOR_ADDR_STR2
6564 "Enable send and receive of the AIGP attribute per neighbor\n")
6565 {
6566 struct peer *peer;
6567
6568 peer = peer_and_group_lookup_vty(vty, neighbor);
6569 if (!peer)
6570 return CMD_WARNING_CONFIG_FAILED;
6571
6572 if (no)
6573 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6574 else
6575 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6576 }
6577
6578 static uint8_t get_role_by_name(const char *role_str)
6579 {
6580 if (strncmp(role_str, "peer", 2) == 0)
6581 return ROLE_PEER;
6582 if (strncmp(role_str, "provider", 2) == 0)
6583 return ROLE_PROVIDER;
6584 if (strncmp(role_str, "customer", 2) == 0)
6585 return ROLE_CUSTOMER;
6586 if (strncmp(role_str, "rs-server", 4) == 0)
6587 return ROLE_RS_SERVER;
6588 if (strncmp(role_str, "rs-client", 4) == 0)
6589 return ROLE_RS_CLIENT;
6590 return ROLE_UNDEFINED;
6591 }
6592
6593 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6594 const char *role_str, bool strict_mode)
6595 {
6596 struct peer *peer;
6597
6598 peer = peer_and_group_lookup_vty(vty, ip_str);
6599 if (!peer)
6600 return CMD_WARNING_CONFIG_FAILED;
6601 uint8_t role = get_role_by_name(role_str);
6602
6603 if (role == ROLE_UNDEFINED)
6604 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6605 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6606 }
6607
6608 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6609 {
6610 struct peer *peer;
6611
6612 peer = peer_and_group_lookup_vty(vty, ip_str);
6613 if (!peer)
6614 return CMD_WARNING_CONFIG_FAILED;
6615 return bgp_vty_return(vty, peer_role_unset(peer));
6616 }
6617
6618 DEFPY(neighbor_role,
6619 neighbor_role_cmd,
6620 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6621 NEIGHBOR_STR
6622 NEIGHBOR_ADDR_STR2
6623 "Set session role\n"
6624 ROLE_STR)
6625 {
6626 int idx_peer = 1;
6627 int idx_role = 3;
6628
6629 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6630 false);
6631 }
6632
6633 DEFPY(neighbor_role_strict,
6634 neighbor_role_strict_cmd,
6635 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6636 NEIGHBOR_STR
6637 NEIGHBOR_ADDR_STR2
6638 "Set session role\n"
6639 ROLE_STR
6640 "Use additional restriction on peer\n")
6641 {
6642 int idx_peer = 1;
6643 int idx_role = 3;
6644
6645 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6646 true);
6647 }
6648
6649 DEFPY(no_neighbor_role,
6650 no_neighbor_role_cmd,
6651 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6652 NO_STR
6653 NEIGHBOR_STR
6654 NEIGHBOR_ADDR_STR2
6655 "Set session role\n"
6656 ROLE_STR
6657 "Use additional restriction on peer\n")
6658 {
6659 int idx_peer = 2;
6660
6661 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6662 }
6663
6664 /* disable-connected-check */
6665 DEFUN (neighbor_disable_connected_check,
6666 neighbor_disable_connected_check_cmd,
6667 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6668 NEIGHBOR_STR
6669 NEIGHBOR_ADDR_STR2
6670 "one-hop away EBGP peer using loopback address\n"
6671 "Enforce EBGP neighbors perform multihop\n")
6672 {
6673 int idx_peer = 1;
6674 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6675 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6676 }
6677
6678 DEFUN (no_neighbor_disable_connected_check,
6679 no_neighbor_disable_connected_check_cmd,
6680 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6681 NO_STR
6682 NEIGHBOR_STR
6683 NEIGHBOR_ADDR_STR2
6684 "one-hop away EBGP peer using loopback address\n"
6685 "Enforce EBGP neighbors perform multihop\n")
6686 {
6687 int idx_peer = 2;
6688 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6689 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6690 }
6691
6692 /* disable-link-bw-encoding-ieee */
6693 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6694 neighbor_disable_link_bw_encoding_ieee_cmd,
6695 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6696 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6697 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6698 {
6699 int idx_peer = 1;
6700
6701 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6702 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6703 }
6704
6705 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6706 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6707 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6708 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6709 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6710 {
6711 int idx_peer = 2;
6712
6713 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6714 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6715 }
6716
6717 /* extended-optional-parameters */
6718 DEFUN(neighbor_extended_optional_parameters,
6719 neighbor_extended_optional_parameters_cmd,
6720 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6722 "Force the extended optional parameters format for OPEN messages\n")
6723 {
6724 int idx_peer = 1;
6725
6726 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6727 PEER_FLAG_EXTENDED_OPT_PARAMS);
6728 }
6729
6730 DEFUN(no_neighbor_extended_optional_parameters,
6731 no_neighbor_extended_optional_parameters_cmd,
6732 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6733 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6734 "Force the extended optional parameters format for OPEN messages\n")
6735 {
6736 int idx_peer = 2;
6737
6738 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6739 PEER_FLAG_EXTENDED_OPT_PARAMS);
6740 }
6741
6742 /* enforce-first-as */
6743 DEFUN (neighbor_enforce_first_as,
6744 neighbor_enforce_first_as_cmd,
6745 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6746 NEIGHBOR_STR
6747 NEIGHBOR_ADDR_STR2
6748 "Enforce the first AS for EBGP routes\n")
6749 {
6750 int idx_peer = 1;
6751
6752 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6753 PEER_FLAG_ENFORCE_FIRST_AS);
6754 }
6755
6756 DEFUN (no_neighbor_enforce_first_as,
6757 no_neighbor_enforce_first_as_cmd,
6758 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6759 NO_STR
6760 NEIGHBOR_STR
6761 NEIGHBOR_ADDR_STR2
6762 "Enforce the first AS for EBGP routes\n")
6763 {
6764 int idx_peer = 2;
6765
6766 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6767 PEER_FLAG_ENFORCE_FIRST_AS);
6768 }
6769
6770
6771 DEFUN (neighbor_description,
6772 neighbor_description_cmd,
6773 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6774 NEIGHBOR_STR
6775 NEIGHBOR_ADDR_STR2
6776 "Neighbor specific description\n"
6777 "Up to 80 characters describing this neighbor\n")
6778 {
6779 int idx_peer = 1;
6780 int idx_line = 3;
6781 struct peer *peer;
6782 char *str;
6783
6784 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6785 if (!peer)
6786 return CMD_WARNING_CONFIG_FAILED;
6787
6788 str = argv_concat(argv, argc, idx_line);
6789
6790 peer_description_set(peer, str);
6791
6792 XFREE(MTYPE_TMP, str);
6793
6794 return CMD_SUCCESS;
6795 }
6796
6797 DEFUN (no_neighbor_description,
6798 no_neighbor_description_cmd,
6799 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6800 NO_STR
6801 NEIGHBOR_STR
6802 NEIGHBOR_ADDR_STR2
6803 "Neighbor specific description\n")
6804 {
6805 int idx_peer = 2;
6806 struct peer *peer;
6807
6808 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6809 if (!peer)
6810 return CMD_WARNING_CONFIG_FAILED;
6811
6812 peer_description_unset(peer);
6813
6814 return CMD_SUCCESS;
6815 }
6816
6817 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6818 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6819 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6820 "Neighbor specific description\n"
6821 "Up to 80 characters describing this neighbor\n")
6822
6823 /* Neighbor update-source. */
6824 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6825 const char *source_str)
6826 {
6827 struct peer *peer;
6828 struct prefix p;
6829 union sockunion su;
6830
6831 peer = peer_and_group_lookup_vty(vty, peer_str);
6832 if (!peer)
6833 return CMD_WARNING_CONFIG_FAILED;
6834
6835 if (peer->conf_if)
6836 return CMD_WARNING;
6837
6838 if (source_str) {
6839 if (str2sockunion(source_str, &su) == 0)
6840 peer_update_source_addr_set(peer, &su);
6841 else {
6842 if (str2prefix(source_str, &p)) {
6843 vty_out(vty,
6844 "%% Invalid update-source, remove prefix length \n");
6845 return CMD_WARNING_CONFIG_FAILED;
6846 } else
6847 peer_update_source_if_set(peer, source_str);
6848 }
6849 } else
6850 peer_update_source_unset(peer);
6851
6852 return CMD_SUCCESS;
6853 }
6854
6855 #define BGP_UPDATE_SOURCE_HELP_STR \
6856 "IPv4 address\n" \
6857 "IPv6 address\n" \
6858 "Interface name (requires zebra to be running)\n"
6859
6860 DEFUN (neighbor_update_source,
6861 neighbor_update_source_cmd,
6862 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6863 NEIGHBOR_STR
6864 NEIGHBOR_ADDR_STR2
6865 "Source of routing updates\n"
6866 BGP_UPDATE_SOURCE_HELP_STR)
6867 {
6868 int idx_peer = 1;
6869 int idx_peer_2 = 3;
6870 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6871 argv[idx_peer_2]->arg);
6872 }
6873
6874 DEFUN (no_neighbor_update_source,
6875 no_neighbor_update_source_cmd,
6876 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6877 NO_STR
6878 NEIGHBOR_STR
6879 NEIGHBOR_ADDR_STR2
6880 "Source of routing updates\n"
6881 BGP_UPDATE_SOURCE_HELP_STR)
6882 {
6883 int idx_peer = 2;
6884 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6885 }
6886
6887 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6888 afi_t afi, safi_t safi,
6889 const char *rmap, int set)
6890 {
6891 int ret;
6892 struct peer *peer;
6893 struct route_map *route_map = NULL;
6894
6895 peer = peer_and_group_lookup_vty(vty, peer_str);
6896 if (!peer)
6897 return CMD_WARNING_CONFIG_FAILED;
6898
6899 if (set) {
6900 if (rmap)
6901 route_map = route_map_lookup_warn_noexist(vty, rmap);
6902 ret = peer_default_originate_set(peer, afi, safi,
6903 rmap, route_map);
6904 } else
6905 ret = peer_default_originate_unset(peer, afi, safi);
6906
6907 return bgp_vty_return(vty, ret);
6908 }
6909
6910 /* neighbor default-originate. */
6911 DEFUN (neighbor_default_originate,
6912 neighbor_default_originate_cmd,
6913 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6914 NEIGHBOR_STR
6915 NEIGHBOR_ADDR_STR2
6916 "Originate default route to this neighbor\n")
6917 {
6918 int idx_peer = 1;
6919 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6920 bgp_node_afi(vty),
6921 bgp_node_safi(vty), NULL, 1);
6922 }
6923
6924 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6925 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6926 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6927 "Originate default route to this neighbor\n")
6928
6929 DEFUN (neighbor_default_originate_rmap,
6930 neighbor_default_originate_rmap_cmd,
6931 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6932 NEIGHBOR_STR
6933 NEIGHBOR_ADDR_STR2
6934 "Originate default route to this neighbor\n"
6935 "Route-map to specify criteria to originate default\n"
6936 "route-map name\n")
6937 {
6938 int idx_peer = 1;
6939 int idx_word = 4;
6940 return peer_default_originate_set_vty(
6941 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6942 argv[idx_word]->arg, 1);
6943 }
6944
6945 ALIAS_HIDDEN(
6946 neighbor_default_originate_rmap,
6947 neighbor_default_originate_rmap_hidden_cmd,
6948 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6950 "Originate default route to this neighbor\n"
6951 "Route-map to specify criteria to originate default\n"
6952 "route-map name\n")
6953
6954 DEFUN (no_neighbor_default_originate,
6955 no_neighbor_default_originate_cmd,
6956 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6957 NO_STR
6958 NEIGHBOR_STR
6959 NEIGHBOR_ADDR_STR2
6960 "Originate default route to this neighbor\n"
6961 "Route-map to specify criteria to originate default\n"
6962 "route-map name\n")
6963 {
6964 int idx_peer = 2;
6965 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6966 bgp_node_afi(vty),
6967 bgp_node_safi(vty), NULL, 0);
6968 }
6969
6970 ALIAS_HIDDEN(
6971 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6972 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6974 "Originate default route to this neighbor\n"
6975 "Route-map to specify criteria to originate default\n"
6976 "route-map name\n")
6977
6978
6979 /* Set neighbor's BGP port. */
6980 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6981 const char *port_str)
6982 {
6983 struct peer *peer;
6984 uint16_t port;
6985 struct servent *sp;
6986
6987 peer = peer_and_group_lookup_vty(vty, ip_str);
6988 if (!peer)
6989 return CMD_WARNING_CONFIG_FAILED;
6990
6991 if (!port_str) {
6992 sp = getservbyname("bgp", "tcp");
6993 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6994 } else {
6995 port = strtoul(port_str, NULL, 10);
6996 }
6997
6998 peer_port_set(peer, port);
6999
7000 return CMD_SUCCESS;
7001 }
7002
7003 /* Set specified peer's BGP port. */
7004 DEFUN (neighbor_port,
7005 neighbor_port_cmd,
7006 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7007 NEIGHBOR_STR
7008 NEIGHBOR_ADDR_STR2
7009 "Neighbor's BGP port\n"
7010 "TCP port number\n")
7011 {
7012 int idx_ip = 1;
7013 int idx_number = 3;
7014 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7015 argv[idx_number]->arg);
7016 }
7017
7018 DEFUN (no_neighbor_port,
7019 no_neighbor_port_cmd,
7020 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7021 NO_STR
7022 NEIGHBOR_STR
7023 NEIGHBOR_ADDR_STR2
7024 "Neighbor's BGP port\n"
7025 "TCP port number\n")
7026 {
7027 int idx_ip = 2;
7028 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7029 }
7030
7031
7032 /* neighbor weight. */
7033 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7034 safi_t safi, const char *weight_str)
7035 {
7036 int ret;
7037 struct peer *peer;
7038 unsigned long weight;
7039
7040 peer = peer_and_group_lookup_vty(vty, ip_str);
7041 if (!peer)
7042 return CMD_WARNING_CONFIG_FAILED;
7043
7044 weight = strtoul(weight_str, NULL, 10);
7045
7046 ret = peer_weight_set(peer, afi, safi, weight);
7047 return bgp_vty_return(vty, ret);
7048 }
7049
7050 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7051 safi_t safi)
7052 {
7053 int ret;
7054 struct peer *peer;
7055
7056 peer = peer_and_group_lookup_vty(vty, ip_str);
7057 if (!peer)
7058 return CMD_WARNING_CONFIG_FAILED;
7059
7060 ret = peer_weight_unset(peer, afi, safi);
7061 return bgp_vty_return(vty, ret);
7062 }
7063
7064 DEFUN (neighbor_weight,
7065 neighbor_weight_cmd,
7066 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7067 NEIGHBOR_STR
7068 NEIGHBOR_ADDR_STR2
7069 "Set default weight for routes from this neighbor\n"
7070 "default weight\n")
7071 {
7072 int idx_peer = 1;
7073 int idx_number = 3;
7074 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7075 bgp_node_safi(vty), argv[idx_number]->arg);
7076 }
7077
7078 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7079 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7080 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7081 "Set default weight for routes from this neighbor\n"
7082 "default weight\n")
7083
7084 DEFUN (no_neighbor_weight,
7085 no_neighbor_weight_cmd,
7086 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7087 NO_STR
7088 NEIGHBOR_STR
7089 NEIGHBOR_ADDR_STR2
7090 "Set default weight for routes from this neighbor\n"
7091 "default weight\n")
7092 {
7093 int idx_peer = 2;
7094 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7095 bgp_node_afi(vty), bgp_node_safi(vty));
7096 }
7097
7098 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7099 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7100 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7101 "Set default weight for routes from this neighbor\n"
7102 "default weight\n")
7103
7104
7105 /* Override capability negotiation. */
7106 DEFUN (neighbor_override_capability,
7107 neighbor_override_capability_cmd,
7108 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7109 NEIGHBOR_STR
7110 NEIGHBOR_ADDR_STR2
7111 "Override capability negotiation result\n")
7112 {
7113 int idx_peer = 1;
7114 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7115 PEER_FLAG_OVERRIDE_CAPABILITY);
7116 }
7117
7118 DEFUN (no_neighbor_override_capability,
7119 no_neighbor_override_capability_cmd,
7120 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7121 NO_STR
7122 NEIGHBOR_STR
7123 NEIGHBOR_ADDR_STR2
7124 "Override capability negotiation result\n")
7125 {
7126 int idx_peer = 2;
7127 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7128 PEER_FLAG_OVERRIDE_CAPABILITY);
7129 }
7130
7131 DEFUN (neighbor_strict_capability,
7132 neighbor_strict_capability_cmd,
7133 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7134 NEIGHBOR_STR
7135 NEIGHBOR_ADDR_STR2
7136 "Strict capability negotiation match\n")
7137 {
7138 int idx_peer = 1;
7139
7140 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7141 PEER_FLAG_STRICT_CAP_MATCH);
7142 }
7143
7144 DEFUN (no_neighbor_strict_capability,
7145 no_neighbor_strict_capability_cmd,
7146 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7147 NO_STR
7148 NEIGHBOR_STR
7149 NEIGHBOR_ADDR_STR2
7150 "Strict capability negotiation match\n")
7151 {
7152 int idx_peer = 2;
7153
7154 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7155 PEER_FLAG_STRICT_CAP_MATCH);
7156 }
7157
7158 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7159 const char *keep_str, const char *hold_str)
7160 {
7161 int ret;
7162 struct peer *peer;
7163 uint32_t keepalive;
7164 uint32_t holdtime;
7165
7166 peer = peer_and_group_lookup_vty(vty, ip_str);
7167 if (!peer)
7168 return CMD_WARNING_CONFIG_FAILED;
7169
7170 keepalive = strtoul(keep_str, NULL, 10);
7171 holdtime = strtoul(hold_str, NULL, 10);
7172
7173 ret = peer_timers_set(peer, keepalive, holdtime);
7174
7175 return bgp_vty_return(vty, ret);
7176 }
7177
7178 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7179 {
7180 int ret;
7181 struct peer *peer;
7182
7183 peer = peer_and_group_lookup_vty(vty, ip_str);
7184 if (!peer)
7185 return CMD_WARNING_CONFIG_FAILED;
7186
7187 ret = peer_timers_unset(peer);
7188
7189 return bgp_vty_return(vty, ret);
7190 }
7191
7192 DEFUN (neighbor_timers,
7193 neighbor_timers_cmd,
7194 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7195 NEIGHBOR_STR
7196 NEIGHBOR_ADDR_STR2
7197 "BGP per neighbor timers\n"
7198 "Keepalive interval\n"
7199 "Holdtime\n")
7200 {
7201 int idx_peer = 1;
7202 int idx_number = 3;
7203 int idx_number_2 = 4;
7204 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7205 argv[idx_number]->arg,
7206 argv[idx_number_2]->arg);
7207 }
7208
7209 DEFUN (no_neighbor_timers,
7210 no_neighbor_timers_cmd,
7211 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7212 NO_STR
7213 NEIGHBOR_STR
7214 NEIGHBOR_ADDR_STR2
7215 "BGP per neighbor timers\n"
7216 "Keepalive interval\n"
7217 "Holdtime\n")
7218 {
7219 int idx_peer = 2;
7220 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7221 }
7222
7223
7224 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7225 const char *time_str)
7226 {
7227 int ret;
7228 struct peer *peer;
7229 uint32_t connect;
7230
7231 peer = peer_and_group_lookup_vty(vty, ip_str);
7232 if (!peer)
7233 return CMD_WARNING_CONFIG_FAILED;
7234
7235 connect = strtoul(time_str, NULL, 10);
7236
7237 ret = peer_timers_connect_set(peer, connect);
7238
7239 return bgp_vty_return(vty, ret);
7240 }
7241
7242 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7243 {
7244 int ret;
7245 struct peer *peer;
7246
7247 peer = peer_and_group_lookup_vty(vty, ip_str);
7248 if (!peer)
7249 return CMD_WARNING_CONFIG_FAILED;
7250
7251 ret = peer_timers_connect_unset(peer);
7252
7253 return bgp_vty_return(vty, ret);
7254 }
7255
7256 DEFUN (neighbor_timers_connect,
7257 neighbor_timers_connect_cmd,
7258 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7259 NEIGHBOR_STR
7260 NEIGHBOR_ADDR_STR2
7261 "BGP per neighbor timers\n"
7262 "BGP connect timer\n"
7263 "Connect timer\n")
7264 {
7265 int idx_peer = 1;
7266 int idx_number = 4;
7267 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7268 argv[idx_number]->arg);
7269 }
7270
7271 DEFUN (no_neighbor_timers_connect,
7272 no_neighbor_timers_connect_cmd,
7273 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7274 NO_STR
7275 NEIGHBOR_STR
7276 NEIGHBOR_ADDR_STR2
7277 "BGP per neighbor timers\n"
7278 "BGP connect timer\n"
7279 "Connect timer\n")
7280 {
7281 int idx_peer = 2;
7282 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7283 }
7284
7285 DEFPY (neighbor_timers_delayopen,
7286 neighbor_timers_delayopen_cmd,
7287 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7288 NEIGHBOR_STR
7289 NEIGHBOR_ADDR_STR2
7290 "BGP per neighbor timers\n"
7291 "RFC 4271 DelayOpenTimer\n"
7292 "DelayOpenTime timer interval\n")
7293 {
7294 struct peer *peer;
7295
7296 peer = peer_and_group_lookup_vty(vty, neighbor);
7297 if (!peer)
7298 return CMD_WARNING_CONFIG_FAILED;
7299
7300 if (!interval) {
7301 if (peer_timers_delayopen_unset(peer))
7302 return CMD_WARNING_CONFIG_FAILED;
7303 } else {
7304 if (peer_timers_delayopen_set(peer, interval))
7305 return CMD_WARNING_CONFIG_FAILED;
7306 }
7307
7308 return CMD_SUCCESS;
7309 }
7310
7311 DEFPY (no_neighbor_timers_delayopen,
7312 no_neighbor_timers_delayopen_cmd,
7313 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7314 NO_STR
7315 NEIGHBOR_STR
7316 NEIGHBOR_ADDR_STR2
7317 "BGP per neighbor timers\n"
7318 "RFC 4271 DelayOpenTimer\n"
7319 "DelayOpenTime timer interval\n")
7320 {
7321 struct peer *peer;
7322
7323 peer = peer_and_group_lookup_vty(vty, neighbor);
7324 if (!peer)
7325 return CMD_WARNING_CONFIG_FAILED;
7326
7327 if (peer_timers_delayopen_unset(peer))
7328 return CMD_WARNING_CONFIG_FAILED;
7329
7330 return CMD_SUCCESS;
7331 }
7332
7333 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7334 const char *time_str, int set)
7335 {
7336 int ret;
7337 struct peer *peer;
7338 uint32_t routeadv = 0;
7339
7340 peer = peer_and_group_lookup_vty(vty, ip_str);
7341 if (!peer)
7342 return CMD_WARNING_CONFIG_FAILED;
7343
7344 if (time_str)
7345 routeadv = strtoul(time_str, NULL, 10);
7346
7347 if (set)
7348 ret = peer_advertise_interval_set(peer, routeadv);
7349 else
7350 ret = peer_advertise_interval_unset(peer);
7351
7352 return bgp_vty_return(vty, ret);
7353 }
7354
7355 DEFUN (neighbor_advertise_interval,
7356 neighbor_advertise_interval_cmd,
7357 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7358 NEIGHBOR_STR
7359 NEIGHBOR_ADDR_STR2
7360 "Minimum interval between sending BGP routing updates\n"
7361 "time in seconds\n")
7362 {
7363 int idx_peer = 1;
7364 int idx_number = 3;
7365 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7366 argv[idx_number]->arg, 1);
7367 }
7368
7369 DEFUN (no_neighbor_advertise_interval,
7370 no_neighbor_advertise_interval_cmd,
7371 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7372 NO_STR
7373 NEIGHBOR_STR
7374 NEIGHBOR_ADDR_STR2
7375 "Minimum interval between sending BGP routing updates\n"
7376 "time in seconds\n")
7377 {
7378 int idx_peer = 2;
7379 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7380 }
7381
7382
7383 /* Time to wait before processing route-map updates */
7384 DEFUN (bgp_set_route_map_delay_timer,
7385 bgp_set_route_map_delay_timer_cmd,
7386 "bgp route-map delay-timer (0-600)",
7387 SET_STR
7388 "BGP route-map delay timer\n"
7389 "Time in secs to wait before processing route-map changes\n"
7390 "0 disables the timer, no route updates happen when route-maps change\n")
7391 {
7392 int idx_number = 3;
7393 uint32_t rmap_delay_timer;
7394
7395 if (argv[idx_number]->arg) {
7396 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7397 bm->rmap_update_timer = rmap_delay_timer;
7398
7399 /* if the dynamic update handling is being disabled, and a timer
7400 * is
7401 * running, stop the timer and act as if the timer has already
7402 * fired.
7403 */
7404 if (!rmap_delay_timer && bm->t_rmap_update) {
7405 THREAD_OFF(bm->t_rmap_update);
7406 thread_execute(bm->master, bgp_route_map_update_timer,
7407 NULL, 0);
7408 }
7409 return CMD_SUCCESS;
7410 } else {
7411 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7412 return CMD_WARNING_CONFIG_FAILED;
7413 }
7414 }
7415
7416 DEFUN (no_bgp_set_route_map_delay_timer,
7417 no_bgp_set_route_map_delay_timer_cmd,
7418 "no bgp route-map delay-timer [(0-600)]",
7419 NO_STR
7420 BGP_STR
7421 "Default BGP route-map delay timer\n"
7422 "Reset to default time to wait for processing route-map changes\n"
7423 "0 disables the timer, no route updates happen when route-maps change\n")
7424 {
7425
7426 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7427
7428 return CMD_SUCCESS;
7429 }
7430
7431 /* neighbor interface */
7432 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7433 const char *str)
7434 {
7435 struct peer *peer;
7436
7437 peer = peer_lookup_vty(vty, ip_str);
7438 if (!peer || peer->conf_if) {
7439 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7440 return CMD_WARNING_CONFIG_FAILED;
7441 }
7442
7443 if (str)
7444 peer_interface_set(peer, str);
7445 else
7446 peer_interface_unset(peer);
7447
7448 return CMD_SUCCESS;
7449 }
7450
7451 DEFUN (neighbor_interface,
7452 neighbor_interface_cmd,
7453 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7454 NEIGHBOR_STR
7455 NEIGHBOR_ADDR_STR
7456 "Interface\n"
7457 "Interface name\n")
7458 {
7459 int idx_ip = 1;
7460 int idx_word = 3;
7461
7462 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7463 }
7464
7465 DEFUN (no_neighbor_interface,
7466 no_neighbor_interface_cmd,
7467 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7468 NO_STR
7469 NEIGHBOR_STR
7470 NEIGHBOR_ADDR_STR
7471 "Interface\n"
7472 "Interface name\n")
7473 {
7474 int idx_peer = 2;
7475
7476 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7477 }
7478
7479 DEFUN (neighbor_distribute_list,
7480 neighbor_distribute_list_cmd,
7481 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7482 NEIGHBOR_STR
7483 NEIGHBOR_ADDR_STR2
7484 "Filter updates to/from this neighbor\n"
7485 "IP Access-list name\n"
7486 "Filter incoming updates\n"
7487 "Filter outgoing updates\n")
7488 {
7489 int idx_peer = 1;
7490 int idx_acl = 3;
7491 int direct, ret;
7492 struct peer *peer;
7493
7494 const char *pstr = argv[idx_peer]->arg;
7495 const char *acl = argv[idx_acl]->arg;
7496 const char *inout = argv[argc - 1]->text;
7497
7498 peer = peer_and_group_lookup_vty(vty, pstr);
7499 if (!peer)
7500 return CMD_WARNING_CONFIG_FAILED;
7501
7502 /* Check filter direction. */
7503 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7504 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7505 direct, acl);
7506
7507 return bgp_vty_return(vty, ret);
7508 }
7509
7510 ALIAS_HIDDEN(
7511 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7512 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7513 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7514 "Filter updates to/from this neighbor\n"
7515 "IP Access-list name\n"
7516 "Filter incoming updates\n"
7517 "Filter outgoing updates\n")
7518
7519 DEFUN (no_neighbor_distribute_list,
7520 no_neighbor_distribute_list_cmd,
7521 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7522 NO_STR
7523 NEIGHBOR_STR
7524 NEIGHBOR_ADDR_STR2
7525 "Filter updates to/from this neighbor\n"
7526 "IP Access-list name\n"
7527 "Filter incoming updates\n"
7528 "Filter outgoing updates\n")
7529 {
7530 int idx_peer = 2;
7531 int direct, ret;
7532 struct peer *peer;
7533
7534 const char *pstr = argv[idx_peer]->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_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7544 direct);
7545
7546 return bgp_vty_return(vty, ret);
7547 }
7548
7549 ALIAS_HIDDEN(
7550 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7551 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7552 NO_STR 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 /* Set prefix list to the peer. */
7559 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7560 afi_t afi, safi_t safi,
7561 const char *name_str,
7562 const char *direct_str)
7563 {
7564 int ret;
7565 int direct = FILTER_IN;
7566 struct peer *peer;
7567
7568 peer = peer_and_group_lookup_vty(vty, ip_str);
7569 if (!peer)
7570 return CMD_WARNING_CONFIG_FAILED;
7571
7572 /* Check filter direction. */
7573 if (strncmp(direct_str, "i", 1) == 0)
7574 direct = FILTER_IN;
7575 else if (strncmp(direct_str, "o", 1) == 0)
7576 direct = FILTER_OUT;
7577
7578 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7579
7580 return bgp_vty_return(vty, ret);
7581 }
7582
7583 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7584 afi_t afi, safi_t safi,
7585 const char *direct_str)
7586 {
7587 int ret;
7588 struct peer *peer;
7589 int direct = FILTER_IN;
7590
7591 peer = peer_and_group_lookup_vty(vty, ip_str);
7592 if (!peer)
7593 return CMD_WARNING_CONFIG_FAILED;
7594
7595 /* Check filter direction. */
7596 if (strncmp(direct_str, "i", 1) == 0)
7597 direct = FILTER_IN;
7598 else if (strncmp(direct_str, "o", 1) == 0)
7599 direct = FILTER_OUT;
7600
7601 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7602
7603 return bgp_vty_return(vty, ret);
7604 }
7605
7606 DEFUN (neighbor_prefix_list,
7607 neighbor_prefix_list_cmd,
7608 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7609 NEIGHBOR_STR
7610 NEIGHBOR_ADDR_STR2
7611 "Filter updates to/from this neighbor\n"
7612 "Name of a prefix list\n"
7613 "Filter incoming updates\n"
7614 "Filter outgoing updates\n")
7615 {
7616 int idx_peer = 1;
7617 int idx_word = 3;
7618 int idx_in_out = 4;
7619 return peer_prefix_list_set_vty(
7620 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7621 argv[idx_word]->arg, argv[idx_in_out]->arg);
7622 }
7623
7624 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7625 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7626 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7627 "Filter updates to/from this neighbor\n"
7628 "Name of a prefix list\n"
7629 "Filter incoming updates\n"
7630 "Filter outgoing updates\n")
7631
7632 DEFUN (no_neighbor_prefix_list,
7633 no_neighbor_prefix_list_cmd,
7634 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7635 NO_STR
7636 NEIGHBOR_STR
7637 NEIGHBOR_ADDR_STR2
7638 "Filter updates to/from this neighbor\n"
7639 "Name of a prefix list\n"
7640 "Filter incoming updates\n"
7641 "Filter outgoing updates\n")
7642 {
7643 int idx_peer = 2;
7644 int idx_in_out = 5;
7645 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7646 bgp_node_afi(vty), bgp_node_safi(vty),
7647 argv[idx_in_out]->arg);
7648 }
7649
7650 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7651 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7652 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7653 "Filter updates to/from this neighbor\n"
7654 "Name of a prefix list\n"
7655 "Filter incoming updates\n"
7656 "Filter outgoing updates\n")
7657
7658 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7659 safi_t safi, const char *name_str,
7660 const char *direct_str)
7661 {
7662 int ret;
7663 struct peer *peer;
7664 int direct = FILTER_IN;
7665
7666 peer = peer_and_group_lookup_vty(vty, ip_str);
7667 if (!peer)
7668 return CMD_WARNING_CONFIG_FAILED;
7669
7670 /* Check filter direction. */
7671 if (strncmp(direct_str, "i", 1) == 0)
7672 direct = FILTER_IN;
7673 else if (strncmp(direct_str, "o", 1) == 0)
7674 direct = FILTER_OUT;
7675
7676 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7677
7678 return bgp_vty_return(vty, ret);
7679 }
7680
7681 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7682 safi_t safi, const char *direct_str)
7683 {
7684 int ret;
7685 struct peer *peer;
7686 int direct = FILTER_IN;
7687
7688 peer = peer_and_group_lookup_vty(vty, ip_str);
7689 if (!peer)
7690 return CMD_WARNING_CONFIG_FAILED;
7691
7692 /* Check filter direction. */
7693 if (strncmp(direct_str, "i", 1) == 0)
7694 direct = FILTER_IN;
7695 else if (strncmp(direct_str, "o", 1) == 0)
7696 direct = FILTER_OUT;
7697
7698 ret = peer_aslist_unset(peer, afi, safi, direct);
7699
7700 return bgp_vty_return(vty, ret);
7701 }
7702
7703 DEFUN (neighbor_filter_list,
7704 neighbor_filter_list_cmd,
7705 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7706 NEIGHBOR_STR
7707 NEIGHBOR_ADDR_STR2
7708 "Establish BGP filters\n"
7709 "AS path access-list name\n"
7710 "Filter incoming routes\n"
7711 "Filter outgoing routes\n")
7712 {
7713 int idx_peer = 1;
7714 int idx_word = 3;
7715 int idx_in_out = 4;
7716 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7717 bgp_node_safi(vty), argv[idx_word]->arg,
7718 argv[idx_in_out]->arg);
7719 }
7720
7721 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7722 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7723 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7724 "Establish BGP filters\n"
7725 "AS path access-list name\n"
7726 "Filter incoming routes\n"
7727 "Filter outgoing routes\n")
7728
7729 DEFUN (no_neighbor_filter_list,
7730 no_neighbor_filter_list_cmd,
7731 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7732 NO_STR
7733 NEIGHBOR_STR
7734 NEIGHBOR_ADDR_STR2
7735 "Establish BGP filters\n"
7736 "AS path access-list name\n"
7737 "Filter incoming routes\n"
7738 "Filter outgoing routes\n")
7739 {
7740 int idx_peer = 2;
7741 int idx_in_out = 5;
7742 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7743 bgp_node_afi(vty), bgp_node_safi(vty),
7744 argv[idx_in_out]->arg);
7745 }
7746
7747 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7748 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7749 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7750 "Establish BGP filters\n"
7751 "AS path access-list name\n"
7752 "Filter incoming routes\n"
7753 "Filter outgoing routes\n")
7754
7755 /* Set advertise-map to the peer. */
7756 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7757 afi_t afi, safi_t safi,
7758 const char *advertise_str,
7759 const char *condition_str, bool condition,
7760 bool set)
7761 {
7762 int ret = CMD_WARNING_CONFIG_FAILED;
7763 struct peer *peer;
7764 struct route_map *advertise_map;
7765 struct route_map *condition_map;
7766
7767 peer = peer_and_group_lookup_vty(vty, ip_str);
7768 if (!peer)
7769 return ret;
7770
7771 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7772 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7773
7774 if (set)
7775 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7776 advertise_map, condition_str,
7777 condition_map, condition);
7778 else
7779 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7780 advertise_map, condition_str,
7781 condition_map, condition);
7782
7783 return bgp_vty_return(vty, ret);
7784 }
7785
7786 DEFPY (bgp_condadv_period,
7787 bgp_condadv_period_cmd,
7788 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7789 NO_STR
7790 BGP_STR
7791 "Conditional advertisement settings\n"
7792 "Set period to rescan BGP table to check if condition is met\n"
7793 "Period between BGP table scans, in seconds; default 60\n")
7794 {
7795 VTY_DECLVAR_CONTEXT(bgp, bgp);
7796
7797 bgp->condition_check_period =
7798 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7799
7800 return CMD_SUCCESS;
7801 }
7802
7803 DEFPY (neighbor_advertise_map,
7804 neighbor_advertise_map_cmd,
7805 "[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",
7806 NO_STR
7807 NEIGHBOR_STR
7808 NEIGHBOR_ADDR_STR2
7809 "Route-map to conditionally advertise routes\n"
7810 "Name of advertise map\n"
7811 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7812 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7813 "Name of the exist or non exist map\n")
7814 {
7815 bool condition = CONDITION_EXIST;
7816
7817 if (!strcmp(exist, "non-exist-map"))
7818 condition = CONDITION_NON_EXIST;
7819
7820 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7821 bgp_node_safi(vty), advertise_str,
7822 condition_str, condition, !no);
7823 }
7824
7825 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7826 "[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",
7827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7828 "Route-map to conditionally advertise routes\n"
7829 "Name of advertise map\n"
7830 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7831 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7832 "Name of the exist or non exist map\n")
7833
7834 /* Set route-map to the peer. */
7835 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7836 afi_t afi, safi_t safi, const char *name_str,
7837 const char *direct_str)
7838 {
7839 int ret;
7840 struct peer *peer;
7841 int direct = RMAP_IN;
7842 struct route_map *route_map;
7843
7844 peer = peer_and_group_lookup_vty(vty, ip_str);
7845 if (!peer)
7846 return CMD_WARNING_CONFIG_FAILED;
7847
7848 /* Check filter direction. */
7849 if (strncmp(direct_str, "in", 2) == 0)
7850 direct = RMAP_IN;
7851 else if (strncmp(direct_str, "o", 1) == 0)
7852 direct = RMAP_OUT;
7853
7854 route_map = route_map_lookup_warn_noexist(vty, name_str);
7855 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7856
7857 return bgp_vty_return(vty, ret);
7858 }
7859
7860 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7861 afi_t afi, safi_t safi,
7862 const char *direct_str)
7863 {
7864 int ret;
7865 struct peer *peer;
7866 int direct = RMAP_IN;
7867
7868 peer = peer_and_group_lookup_vty(vty, ip_str);
7869 if (!peer)
7870 return CMD_WARNING_CONFIG_FAILED;
7871
7872 /* Check filter direction. */
7873 if (strncmp(direct_str, "in", 2) == 0)
7874 direct = RMAP_IN;
7875 else if (strncmp(direct_str, "o", 1) == 0)
7876 direct = RMAP_OUT;
7877
7878 ret = peer_route_map_unset(peer, afi, safi, direct);
7879
7880 return bgp_vty_return(vty, ret);
7881 }
7882
7883 DEFUN (neighbor_route_map,
7884 neighbor_route_map_cmd,
7885 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7886 NEIGHBOR_STR
7887 NEIGHBOR_ADDR_STR2
7888 "Apply route map to neighbor\n"
7889 "Name of route map\n"
7890 "Apply map to incoming routes\n"
7891 "Apply map to outbound routes\n")
7892 {
7893 int idx_peer = 1;
7894 int idx_word = 3;
7895 int idx_in_out = 4;
7896 return peer_route_map_set_vty(
7897 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7898 argv[idx_word]->arg, argv[idx_in_out]->arg);
7899 }
7900
7901 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7902 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7903 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7904 "Apply route map to neighbor\n"
7905 "Name of route map\n"
7906 "Apply map to incoming routes\n"
7907 "Apply map to outbound routes\n")
7908
7909 DEFUN (no_neighbor_route_map,
7910 no_neighbor_route_map_cmd,
7911 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7912 NO_STR
7913 NEIGHBOR_STR
7914 NEIGHBOR_ADDR_STR2
7915 "Apply route map to neighbor\n"
7916 "Name of route map\n"
7917 "Apply map to incoming routes\n"
7918 "Apply map to outbound routes\n")
7919 {
7920 int idx_peer = 2;
7921 int idx_in_out = 5;
7922 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7923 bgp_node_afi(vty), bgp_node_safi(vty),
7924 argv[idx_in_out]->arg);
7925 }
7926
7927 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7928 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7929 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7930 "Apply route map to neighbor\n"
7931 "Name of route map\n"
7932 "Apply map to incoming routes\n"
7933 "Apply map to outbound routes\n")
7934
7935 /* Set unsuppress-map to the peer. */
7936 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7937 afi_t afi, safi_t safi,
7938 const char *name_str)
7939 {
7940 int ret;
7941 struct peer *peer;
7942 struct route_map *route_map;
7943
7944 peer = peer_and_group_lookup_vty(vty, ip_str);
7945 if (!peer)
7946 return CMD_WARNING_CONFIG_FAILED;
7947
7948 route_map = route_map_lookup_warn_noexist(vty, name_str);
7949 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7950
7951 return bgp_vty_return(vty, ret);
7952 }
7953
7954 /* Unset route-map from the peer. */
7955 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7956 afi_t afi, safi_t safi)
7957 {
7958 int ret;
7959 struct peer *peer;
7960
7961 peer = peer_and_group_lookup_vty(vty, ip_str);
7962 if (!peer)
7963 return CMD_WARNING_CONFIG_FAILED;
7964
7965 ret = peer_unsuppress_map_unset(peer, afi, safi);
7966
7967 return bgp_vty_return(vty, ret);
7968 }
7969
7970 DEFUN (neighbor_unsuppress_map,
7971 neighbor_unsuppress_map_cmd,
7972 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7973 NEIGHBOR_STR
7974 NEIGHBOR_ADDR_STR2
7975 "Route-map to selectively unsuppress suppressed routes\n"
7976 "Name of route map\n")
7977 {
7978 int idx_peer = 1;
7979 int idx_word = 3;
7980 return peer_unsuppress_map_set_vty(
7981 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7982 argv[idx_word]->arg);
7983 }
7984
7985 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7986 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7987 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7988 "Route-map to selectively unsuppress suppressed routes\n"
7989 "Name of route map\n")
7990
7991 DEFUN (no_neighbor_unsuppress_map,
7992 no_neighbor_unsuppress_map_cmd,
7993 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7994 NO_STR
7995 NEIGHBOR_STR
7996 NEIGHBOR_ADDR_STR2
7997 "Route-map to selectively unsuppress suppressed routes\n"
7998 "Name of route map\n")
7999 {
8000 int idx_peer = 2;
8001 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8002 bgp_node_afi(vty),
8003 bgp_node_safi(vty));
8004 }
8005
8006 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8007 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8008 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8009 "Route-map to selectively unsuppress suppressed routes\n"
8010 "Name of route map\n")
8011
8012 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8013 afi_t afi, safi_t safi,
8014 const char *num_str,
8015 const char *threshold_str, int warning,
8016 const char *restart_str,
8017 const char *force_str)
8018 {
8019 int ret;
8020 struct peer *peer;
8021 uint32_t max;
8022 uint8_t threshold;
8023 uint16_t restart;
8024
8025 peer = peer_and_group_lookup_vty(vty, ip_str);
8026 if (!peer)
8027 return CMD_WARNING_CONFIG_FAILED;
8028
8029 max = strtoul(num_str, NULL, 10);
8030 if (threshold_str)
8031 threshold = atoi(threshold_str);
8032 else
8033 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8034
8035 if (restart_str)
8036 restart = atoi(restart_str);
8037 else
8038 restart = 0;
8039
8040 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8041 restart, force_str ? true : false);
8042
8043 return bgp_vty_return(vty, ret);
8044 }
8045
8046 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8047 afi_t afi, safi_t safi)
8048 {
8049 int ret;
8050 struct peer *peer;
8051
8052 peer = peer_and_group_lookup_vty(vty, ip_str);
8053 if (!peer)
8054 return CMD_WARNING_CONFIG_FAILED;
8055
8056 ret = peer_maximum_prefix_unset(peer, afi, safi);
8057
8058 return bgp_vty_return(vty, ret);
8059 }
8060
8061 /* Maximum number of prefix to be sent to the neighbor. */
8062 DEFUN(neighbor_maximum_prefix_out,
8063 neighbor_maximum_prefix_out_cmd,
8064 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8065 NEIGHBOR_STR
8066 NEIGHBOR_ADDR_STR2
8067 "Maximum number of prefixes to be sent to this peer\n"
8068 "Maximum no. of prefix limit\n")
8069 {
8070 int ret;
8071 int idx_peer = 1;
8072 int idx_number = 3;
8073 struct peer *peer;
8074 uint32_t max;
8075 afi_t afi = bgp_node_afi(vty);
8076 safi_t safi = bgp_node_safi(vty);
8077
8078 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8079 if (!peer)
8080 return CMD_WARNING_CONFIG_FAILED;
8081
8082 max = strtoul(argv[idx_number]->arg, NULL, 10);
8083
8084 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8085
8086 return bgp_vty_return(vty, ret);
8087 }
8088
8089 DEFUN(no_neighbor_maximum_prefix_out,
8090 no_neighbor_maximum_prefix_out_cmd,
8091 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8092 NO_STR
8093 NEIGHBOR_STR
8094 NEIGHBOR_ADDR_STR2
8095 "Maximum number of prefixes to be sent to this peer\n"
8096 "Maximum no. of prefix limit\n")
8097 {
8098 int ret;
8099 int idx_peer = 2;
8100 struct peer *peer;
8101 afi_t afi = bgp_node_afi(vty);
8102 safi_t safi = bgp_node_safi(vty);
8103
8104 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8105 if (!peer)
8106 return CMD_WARNING_CONFIG_FAILED;
8107
8108 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8109
8110 return bgp_vty_return(vty, ret);
8111 }
8112
8113 /* Maximum number of prefix configuration. Prefix count is different
8114 for each peer configuration. So this configuration can be set for
8115 each peer configuration. */
8116 DEFUN (neighbor_maximum_prefix,
8117 neighbor_maximum_prefix_cmd,
8118 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8119 NEIGHBOR_STR
8120 NEIGHBOR_ADDR_STR2
8121 "Maximum number of prefix accept from this peer\n"
8122 "maximum no. of prefix limit\n"
8123 "Force checking all received routes not only accepted\n")
8124 {
8125 int idx_peer = 1;
8126 int idx_number = 3;
8127 int idx_force = 0;
8128 char *force = NULL;
8129
8130 if (argv_find(argv, argc, "force", &idx_force))
8131 force = argv[idx_force]->arg;
8132
8133 return peer_maximum_prefix_set_vty(
8134 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8135 argv[idx_number]->arg, NULL, 0, NULL, force);
8136 }
8137
8138 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8139 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8140 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8141 "Maximum number of prefix accept from this peer\n"
8142 "maximum no. of prefix limit\n"
8143 "Force checking all received routes not only accepted\n")
8144
8145 DEFUN (neighbor_maximum_prefix_threshold,
8146 neighbor_maximum_prefix_threshold_cmd,
8147 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8148 NEIGHBOR_STR
8149 NEIGHBOR_ADDR_STR2
8150 "Maximum number of prefix accept from this peer\n"
8151 "maximum no. of prefix limit\n"
8152 "Threshold value (%) at which to generate a warning msg\n"
8153 "Force checking all received routes not only accepted\n")
8154 {
8155 int idx_peer = 1;
8156 int idx_number = 3;
8157 int idx_number_2 = 4;
8158 int idx_force = 0;
8159 char *force = NULL;
8160
8161 if (argv_find(argv, argc, "force", &idx_force))
8162 force = argv[idx_force]->arg;
8163
8164 return peer_maximum_prefix_set_vty(
8165 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8166 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8167 }
8168
8169 ALIAS_HIDDEN(
8170 neighbor_maximum_prefix_threshold,
8171 neighbor_maximum_prefix_threshold_hidden_cmd,
8172 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8174 "Maximum number of prefix accept from this peer\n"
8175 "maximum no. of prefix limit\n"
8176 "Threshold value (%) at which to generate a warning msg\n"
8177 "Force checking all received routes not only accepted\n")
8178
8179 DEFUN (neighbor_maximum_prefix_warning,
8180 neighbor_maximum_prefix_warning_cmd,
8181 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8182 NEIGHBOR_STR
8183 NEIGHBOR_ADDR_STR2
8184 "Maximum number of prefix accept from this peer\n"
8185 "maximum no. of prefix limit\n"
8186 "Only give warning message when limit is exceeded\n"
8187 "Force checking all received routes not only accepted\n")
8188 {
8189 int idx_peer = 1;
8190 int idx_number = 3;
8191 int idx_force = 0;
8192 char *force = NULL;
8193
8194 if (argv_find(argv, argc, "force", &idx_force))
8195 force = argv[idx_force]->arg;
8196
8197 return peer_maximum_prefix_set_vty(
8198 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8199 argv[idx_number]->arg, NULL, 1, NULL, force);
8200 }
8201
8202 ALIAS_HIDDEN(
8203 neighbor_maximum_prefix_warning,
8204 neighbor_maximum_prefix_warning_hidden_cmd,
8205 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8206 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8207 "Maximum number of prefix accept from this peer\n"
8208 "maximum no. of prefix limit\n"
8209 "Only give warning message when limit is exceeded\n"
8210 "Force checking all received routes not only accepted\n")
8211
8212 DEFUN (neighbor_maximum_prefix_threshold_warning,
8213 neighbor_maximum_prefix_threshold_warning_cmd,
8214 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8215 NEIGHBOR_STR
8216 NEIGHBOR_ADDR_STR2
8217 "Maximum number of prefix accept from this peer\n"
8218 "maximum no. of prefix limit\n"
8219 "Threshold value (%) at which to generate a warning msg\n"
8220 "Only give warning message when limit is exceeded\n"
8221 "Force checking all received routes not only accepted\n")
8222 {
8223 int idx_peer = 1;
8224 int idx_number = 3;
8225 int idx_number_2 = 4;
8226 int idx_force = 0;
8227 char *force = NULL;
8228
8229 if (argv_find(argv, argc, "force", &idx_force))
8230 force = argv[idx_force]->arg;
8231
8232 return peer_maximum_prefix_set_vty(
8233 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8234 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8235 }
8236
8237 ALIAS_HIDDEN(
8238 neighbor_maximum_prefix_threshold_warning,
8239 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8240 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8241 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8242 "Maximum number of prefix accept from this peer\n"
8243 "maximum no. of prefix limit\n"
8244 "Threshold value (%) at which to generate a warning msg\n"
8245 "Only give warning message when limit is exceeded\n"
8246 "Force checking all received routes not only accepted\n")
8247
8248 DEFUN (neighbor_maximum_prefix_restart,
8249 neighbor_maximum_prefix_restart_cmd,
8250 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8251 NEIGHBOR_STR
8252 NEIGHBOR_ADDR_STR2
8253 "Maximum number of prefix accept from this peer\n"
8254 "maximum no. of prefix limit\n"
8255 "Restart bgp connection after limit is exceeded\n"
8256 "Restart interval in minutes\n"
8257 "Force checking all received routes not only accepted\n")
8258 {
8259 int idx_peer = 1;
8260 int idx_number = 3;
8261 int idx_number_2 = 5;
8262 int idx_force = 0;
8263 char *force = NULL;
8264
8265 if (argv_find(argv, argc, "force", &idx_force))
8266 force = argv[idx_force]->arg;
8267
8268 return peer_maximum_prefix_set_vty(
8269 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8270 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8271 }
8272
8273 ALIAS_HIDDEN(
8274 neighbor_maximum_prefix_restart,
8275 neighbor_maximum_prefix_restart_hidden_cmd,
8276 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8277 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8278 "Maximum number of prefix accept from this peer\n"
8279 "maximum no. of prefix limit\n"
8280 "Restart bgp connection after limit is exceeded\n"
8281 "Restart interval in minutes\n"
8282 "Force checking all received routes not only accepted\n")
8283
8284 DEFUN (neighbor_maximum_prefix_threshold_restart,
8285 neighbor_maximum_prefix_threshold_restart_cmd,
8286 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8287 NEIGHBOR_STR
8288 NEIGHBOR_ADDR_STR2
8289 "Maximum number of prefixes to accept from this peer\n"
8290 "maximum no. of prefix limit\n"
8291 "Threshold value (%) at which to generate a warning msg\n"
8292 "Restart bgp connection after limit is exceeded\n"
8293 "Restart interval in minutes\n"
8294 "Force checking all received routes not only accepted\n")
8295 {
8296 int idx_peer = 1;
8297 int idx_number = 3;
8298 int idx_number_2 = 4;
8299 int idx_number_3 = 6;
8300 int idx_force = 0;
8301 char *force = NULL;
8302
8303 if (argv_find(argv, argc, "force", &idx_force))
8304 force = argv[idx_force]->arg;
8305
8306 return peer_maximum_prefix_set_vty(
8307 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8308 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8309 argv[idx_number_3]->arg, force);
8310 }
8311
8312 ALIAS_HIDDEN(
8313 neighbor_maximum_prefix_threshold_restart,
8314 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8315 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8316 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8317 "Maximum number of prefixes to accept from this peer\n"
8318 "maximum no. of prefix limit\n"
8319 "Threshold value (%) at which to generate a warning msg\n"
8320 "Restart bgp connection after limit is exceeded\n"
8321 "Restart interval in minutes\n"
8322 "Force checking all received routes not only accepted\n")
8323
8324 DEFUN (no_neighbor_maximum_prefix,
8325 no_neighbor_maximum_prefix_cmd,
8326 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8327 NO_STR
8328 NEIGHBOR_STR
8329 NEIGHBOR_ADDR_STR2
8330 "Maximum number of prefixes to accept from this peer\n"
8331 "maximum no. of prefix limit\n"
8332 "Threshold value (%) at which to generate a warning msg\n"
8333 "Restart bgp connection after limit is exceeded\n"
8334 "Restart interval in minutes\n"
8335 "Only give warning message when limit is exceeded\n"
8336 "Force checking all received routes not only accepted\n")
8337 {
8338 int idx_peer = 2;
8339 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8340 bgp_node_afi(vty),
8341 bgp_node_safi(vty));
8342 }
8343
8344 ALIAS_HIDDEN(
8345 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8346 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8347 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8348 "Maximum number of prefixes to accept from this peer\n"
8349 "maximum no. of prefix limit\n"
8350 "Threshold value (%) at which to generate a warning msg\n"
8351 "Restart bgp connection after limit is exceeded\n"
8352 "Restart interval in minutes\n"
8353 "Only give warning message when limit is exceeded\n"
8354 "Force checking all received routes not only accepted\n")
8355
8356 /* "neighbor accept-own" */
8357 DEFPY (neighbor_accept_own,
8358 neighbor_accept_own_cmd,
8359 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8360 NO_STR
8361 NEIGHBOR_STR
8362 NEIGHBOR_ADDR_STR2
8363 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8364 {
8365 struct peer *peer;
8366 afi_t afi = bgp_node_afi(vty);
8367 safi_t safi = bgp_node_safi(vty);
8368 int ret;
8369
8370 peer = peer_and_group_lookup_vty(vty, neighbor);
8371 if (!peer)
8372 return CMD_WARNING_CONFIG_FAILED;
8373
8374 if (no)
8375 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8376 else
8377 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8378
8379 return bgp_vty_return(vty, ret);
8380 }
8381
8382 /* "neighbor soo" */
8383 DEFPY (neighbor_soo,
8384 neighbor_soo_cmd,
8385 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8386 NEIGHBOR_STR
8387 NEIGHBOR_ADDR_STR2
8388 "Set the Site-of-Origin (SoO) extended community\n"
8389 "VPN extended community\n")
8390 {
8391 struct peer *peer;
8392 afi_t afi = bgp_node_afi(vty);
8393 safi_t safi = bgp_node_safi(vty);
8394 struct ecommunity *ecomm_soo;
8395
8396 peer = peer_and_group_lookup_vty(vty, neighbor);
8397 if (!peer)
8398 return CMD_WARNING_CONFIG_FAILED;
8399
8400 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8401 if (!ecomm_soo) {
8402 vty_out(vty, "%% Malformed SoO extended community\n");
8403 return CMD_WARNING;
8404 }
8405 ecommunity_str(ecomm_soo);
8406
8407 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8408 ecommunity_free(&peer->soo[afi][safi]);
8409 peer->soo[afi][safi] = ecomm_soo;
8410 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8411 }
8412
8413 return bgp_vty_return(vty,
8414 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8415 }
8416
8417 DEFPY (no_neighbor_soo,
8418 no_neighbor_soo_cmd,
8419 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8420 NO_STR
8421 NEIGHBOR_STR
8422 NEIGHBOR_ADDR_STR2
8423 "Set the Site-of-Origin (SoO) extended community\n"
8424 "VPN extended community\n")
8425 {
8426 struct peer *peer;
8427 afi_t afi = bgp_node_afi(vty);
8428 safi_t safi = bgp_node_safi(vty);
8429
8430 peer = peer_and_group_lookup_vty(vty, neighbor);
8431 if (!peer)
8432 return CMD_WARNING_CONFIG_FAILED;
8433
8434 ecommunity_free(&peer->soo[afi][safi]);
8435
8436 return bgp_vty_return(
8437 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8438 }
8439
8440 /* "neighbor allowas-in" */
8441 DEFUN (neighbor_allowas_in,
8442 neighbor_allowas_in_cmd,
8443 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8444 NEIGHBOR_STR
8445 NEIGHBOR_ADDR_STR2
8446 "Accept as-path with my AS present in it\n"
8447 "Number of occurrences of AS number\n"
8448 "Only accept my AS in the as-path if the route was originated in my AS\n")
8449 {
8450 int idx_peer = 1;
8451 int idx_number_origin = 3;
8452 int ret;
8453 int origin = 0;
8454 struct peer *peer;
8455 int allow_num = 0;
8456
8457 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8458 if (!peer)
8459 return CMD_WARNING_CONFIG_FAILED;
8460
8461 if (argc <= idx_number_origin)
8462 allow_num = 3;
8463 else {
8464 if (argv[idx_number_origin]->type == WORD_TKN)
8465 origin = 1;
8466 else
8467 allow_num = atoi(argv[idx_number_origin]->arg);
8468 }
8469
8470 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8471 allow_num, origin);
8472
8473 return bgp_vty_return(vty, ret);
8474 }
8475
8476 ALIAS_HIDDEN(
8477 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8478 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8479 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8480 "Accept as-path with my AS present in it\n"
8481 "Number of occurrences of AS number\n"
8482 "Only accept my AS in the as-path if the route was originated in my AS\n")
8483
8484 DEFUN (no_neighbor_allowas_in,
8485 no_neighbor_allowas_in_cmd,
8486 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8487 NO_STR
8488 NEIGHBOR_STR
8489 NEIGHBOR_ADDR_STR2
8490 "allow local ASN appears in aspath attribute\n"
8491 "Number of occurrences of AS number\n"
8492 "Only accept my AS in the as-path if the route was originated in my AS\n")
8493 {
8494 int idx_peer = 2;
8495 int ret;
8496 struct peer *peer;
8497
8498 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8499 if (!peer)
8500 return CMD_WARNING_CONFIG_FAILED;
8501
8502 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8503 bgp_node_safi(vty));
8504
8505 return bgp_vty_return(vty, ret);
8506 }
8507
8508 ALIAS_HIDDEN(
8509 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8510 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8511 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8512 "allow local ASN appears in aspath attribute\n"
8513 "Number of occurrences of AS number\n"
8514 "Only accept my AS in the as-path if the route was originated in my AS\n")
8515
8516 DEFUN (neighbor_ttl_security,
8517 neighbor_ttl_security_cmd,
8518 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8519 NEIGHBOR_STR
8520 NEIGHBOR_ADDR_STR2
8521 "BGP ttl-security parameters\n"
8522 "Specify the maximum number of hops to the BGP peer\n"
8523 "Number of hops to BGP peer\n")
8524 {
8525 int idx_peer = 1;
8526 int idx_number = 4;
8527 struct peer *peer;
8528 int gtsm_hops;
8529
8530 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8531 if (!peer)
8532 return CMD_WARNING_CONFIG_FAILED;
8533
8534 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8535
8536 /*
8537 * If 'neighbor swpX', then this is for directly connected peers,
8538 * we should not accept a ttl-security hops value greater than 1.
8539 */
8540 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8541 vty_out(vty,
8542 "%s is directly connected peer, hops cannot exceed 1\n",
8543 argv[idx_peer]->arg);
8544 return CMD_WARNING_CONFIG_FAILED;
8545 }
8546
8547 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8548 }
8549
8550 DEFUN (no_neighbor_ttl_security,
8551 no_neighbor_ttl_security_cmd,
8552 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8553 NO_STR
8554 NEIGHBOR_STR
8555 NEIGHBOR_ADDR_STR2
8556 "BGP ttl-security parameters\n"
8557 "Specify the maximum number of hops to the BGP peer\n"
8558 "Number of hops to BGP peer\n")
8559 {
8560 int idx_peer = 2;
8561 struct peer *peer;
8562
8563 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8564 if (!peer)
8565 return CMD_WARNING_CONFIG_FAILED;
8566
8567 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8568 }
8569
8570 /* disable-addpath-rx */
8571 DEFUN(neighbor_disable_addpath_rx,
8572 neighbor_disable_addpath_rx_cmd,
8573 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8574 NEIGHBOR_STR
8575 NEIGHBOR_ADDR_STR2
8576 "Do not accept additional paths\n")
8577 {
8578 char *peer_str = argv[1]->arg;
8579 struct peer *peer;
8580 afi_t afi = bgp_node_afi(vty);
8581 safi_t safi = bgp_node_safi(vty);
8582
8583 peer = peer_and_group_lookup_vty(vty, peer_str);
8584 if (!peer)
8585 return CMD_WARNING_CONFIG_FAILED;
8586
8587 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8588 PEER_FLAG_DISABLE_ADDPATH_RX);
8589 }
8590
8591 DEFUN(no_neighbor_disable_addpath_rx,
8592 no_neighbor_disable_addpath_rx_cmd,
8593 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8594 NO_STR
8595 NEIGHBOR_STR
8596 NEIGHBOR_ADDR_STR2
8597 "Do not accept additional paths\n")
8598 {
8599 char *peer_str = argv[2]->arg;
8600 struct peer *peer;
8601 afi_t afi = bgp_node_afi(vty);
8602 safi_t safi = bgp_node_safi(vty);
8603
8604 peer = peer_and_group_lookup_vty(vty, peer_str);
8605 if (!peer)
8606 return CMD_WARNING_CONFIG_FAILED;
8607
8608 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8609 PEER_FLAG_DISABLE_ADDPATH_RX);
8610 }
8611
8612 DEFUN (neighbor_addpath_tx_all_paths,
8613 neighbor_addpath_tx_all_paths_cmd,
8614 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8615 NEIGHBOR_STR
8616 NEIGHBOR_ADDR_STR2
8617 "Use addpath to advertise all paths to a neighbor\n")
8618 {
8619 int idx_peer = 1;
8620 struct peer *peer;
8621
8622 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8623 if (!peer)
8624 return CMD_WARNING_CONFIG_FAILED;
8625
8626 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8627 BGP_ADDPATH_ALL);
8628 return CMD_SUCCESS;
8629 }
8630
8631 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8632 neighbor_addpath_tx_all_paths_hidden_cmd,
8633 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8634 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8635 "Use addpath to advertise all paths to a neighbor\n")
8636
8637 DEFUN (no_neighbor_addpath_tx_all_paths,
8638 no_neighbor_addpath_tx_all_paths_cmd,
8639 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8640 NO_STR
8641 NEIGHBOR_STR
8642 NEIGHBOR_ADDR_STR2
8643 "Use addpath to advertise all paths to a neighbor\n")
8644 {
8645 int idx_peer = 2;
8646 struct peer *peer;
8647
8648 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8649 if (!peer)
8650 return CMD_WARNING_CONFIG_FAILED;
8651
8652 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8653 != BGP_ADDPATH_ALL) {
8654 vty_out(vty,
8655 "%% Peer not currently configured to transmit all paths.");
8656 return CMD_WARNING_CONFIG_FAILED;
8657 }
8658
8659 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8660 BGP_ADDPATH_NONE);
8661
8662 return CMD_SUCCESS;
8663 }
8664
8665 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8666 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8667 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8669 "Use addpath to advertise all paths to a neighbor\n")
8670
8671 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8672 neighbor_addpath_tx_bestpath_per_as_cmd,
8673 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8674 NEIGHBOR_STR
8675 NEIGHBOR_ADDR_STR2
8676 "Use addpath to advertise the bestpath per each neighboring AS\n")
8677 {
8678 int idx_peer = 1;
8679 struct peer *peer;
8680
8681 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8682 if (!peer)
8683 return CMD_WARNING_CONFIG_FAILED;
8684
8685 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8686 BGP_ADDPATH_BEST_PER_AS);
8687
8688 return CMD_SUCCESS;
8689 }
8690
8691 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8692 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8693 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8694 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8695 "Use addpath to advertise the bestpath per each neighboring AS\n")
8696
8697 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8698 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8699 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8700 NO_STR
8701 NEIGHBOR_STR
8702 NEIGHBOR_ADDR_STR2
8703 "Use addpath to advertise the bestpath per each neighboring AS\n")
8704 {
8705 int idx_peer = 2;
8706 struct peer *peer;
8707
8708 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8709 if (!peer)
8710 return CMD_WARNING_CONFIG_FAILED;
8711
8712 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8713 != BGP_ADDPATH_BEST_PER_AS) {
8714 vty_out(vty,
8715 "%% Peer not currently configured to transmit all best path per as.");
8716 return CMD_WARNING_CONFIG_FAILED;
8717 }
8718
8719 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8720 BGP_ADDPATH_NONE);
8721
8722 return CMD_SUCCESS;
8723 }
8724
8725 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8726 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8727 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8728 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8729 "Use addpath to advertise the bestpath per each neighboring AS\n")
8730
8731 DEFPY(
8732 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8733 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8734 NEIGHBOR_STR
8735 NEIGHBOR_ADDR_STR2
8736 "Detect AS loops before sending to neighbor\n")
8737 {
8738 struct peer *peer;
8739
8740 peer = peer_and_group_lookup_vty(vty, neighbor);
8741 if (!peer)
8742 return CMD_WARNING_CONFIG_FAILED;
8743
8744 peer->as_path_loop_detection = true;
8745
8746 return CMD_SUCCESS;
8747 }
8748
8749 DEFPY(
8750 no_neighbor_aspath_loop_detection,
8751 no_neighbor_aspath_loop_detection_cmd,
8752 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8753 NO_STR
8754 NEIGHBOR_STR
8755 NEIGHBOR_ADDR_STR2
8756 "Detect AS loops before sending to neighbor\n")
8757 {
8758 struct peer *peer;
8759
8760 peer = peer_and_group_lookup_vty(vty, neighbor);
8761 if (!peer)
8762 return CMD_WARNING_CONFIG_FAILED;
8763
8764 peer->as_path_loop_detection = false;
8765
8766 return CMD_SUCCESS;
8767 }
8768
8769 DEFPY(neighbor_path_attribute_discard,
8770 neighbor_path_attribute_discard_cmd,
8771 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8772 NEIGHBOR_STR
8773 NEIGHBOR_ADDR_STR2
8774 "Manipulate path attributes from incoming UPDATE messages\n"
8775 "Drop specified attributes from incoming UPDATE messages\n"
8776 "Attribute number\n")
8777 {
8778 struct peer *peer;
8779 int idx = 0;
8780 const char *discard_attrs = NULL;
8781
8782 peer = peer_and_group_lookup_vty(vty, neighbor);
8783 if (!peer)
8784 return CMD_WARNING_CONFIG_FAILED;
8785
8786 argv_find(argv, argc, "(1-255)", &idx);
8787 if (idx)
8788 discard_attrs = argv_concat(argv, argc, idx);
8789
8790 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8791
8792 return CMD_SUCCESS;
8793 }
8794
8795 DEFPY(no_neighbor_path_attribute_discard,
8796 no_neighbor_path_attribute_discard_cmd,
8797 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8798 NO_STR
8799 NEIGHBOR_STR
8800 NEIGHBOR_ADDR_STR2
8801 "Manipulate path attributes from incoming UPDATE messages\n"
8802 "Drop specified attributes from incoming UPDATE messages\n"
8803 "Attribute number\n")
8804 {
8805 struct peer *peer;
8806 int idx = 0;
8807 const char *discard_attrs = NULL;
8808
8809 peer = peer_and_group_lookup_vty(vty, neighbor);
8810 if (!peer)
8811 return CMD_WARNING_CONFIG_FAILED;
8812
8813 argv_find(argv, argc, "(1-255)", &idx);
8814 if (idx)
8815 discard_attrs = argv[idx]->arg;
8816
8817 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
8818
8819 return CMD_SUCCESS;
8820 }
8821
8822 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8823 struct ecommunity **list, bool is_rt6)
8824 {
8825 struct ecommunity *ecom = NULL;
8826 struct ecommunity *ecomadd;
8827
8828 for (; argc; --argc, ++argv) {
8829 if (is_rt6)
8830 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8831 ECOMMUNITY_ROUTE_TARGET,
8832 0);
8833 else
8834 ecomadd = ecommunity_str2com(argv[0]->arg,
8835 ECOMMUNITY_ROUTE_TARGET,
8836 0);
8837 if (!ecomadd) {
8838 vty_out(vty, "Malformed community-list value\n");
8839 if (ecom)
8840 ecommunity_free(&ecom);
8841 return CMD_WARNING_CONFIG_FAILED;
8842 }
8843
8844 if (ecom) {
8845 ecommunity_merge(ecom, ecomadd);
8846 ecommunity_free(&ecomadd);
8847 } else {
8848 ecom = ecomadd;
8849 }
8850 }
8851
8852 if (*list) {
8853 ecommunity_free(&*list);
8854 }
8855 *list = ecom;
8856
8857 return CMD_SUCCESS;
8858 }
8859
8860 /*
8861 * v2vimport is true if we are handling a `import vrf ...` command
8862 */
8863 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8864 {
8865 afi_t afi;
8866
8867 switch (vty->node) {
8868 case BGP_IPV4_NODE:
8869 afi = AFI_IP;
8870 break;
8871 case BGP_IPV6_NODE:
8872 afi = AFI_IP6;
8873 break;
8874 default:
8875 vty_out(vty,
8876 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8877 return AFI_MAX;
8878 }
8879
8880 if (!v2vimport) {
8881 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8882 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8883 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8884 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8885 vty_out(vty,
8886 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8887 return AFI_MAX;
8888 }
8889 } else {
8890 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8891 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8892 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8893 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8894 vty_out(vty,
8895 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8896 return AFI_MAX;
8897 }
8898 }
8899 return afi;
8900 }
8901
8902 DEFPY (af_rd_vpn_export,
8903 af_rd_vpn_export_cmd,
8904 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8905 NO_STR
8906 "Specify route distinguisher\n"
8907 "Between current address-family and vpn\n"
8908 "For routes leaked from current address-family to vpn\n"
8909 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8910 {
8911 VTY_DECLVAR_CONTEXT(bgp, bgp);
8912 struct prefix_rd prd;
8913 int ret;
8914 afi_t afi;
8915 int idx = 0;
8916 bool yes = true;
8917
8918 if (argv_find(argv, argc, "no", &idx))
8919 yes = false;
8920
8921 if (yes) {
8922 ret = str2prefix_rd(rd_str, &prd);
8923 if (!ret) {
8924 vty_out(vty, "%% Malformed rd\n");
8925 return CMD_WARNING_CONFIG_FAILED;
8926 }
8927 }
8928
8929 afi = vpn_policy_getafi(vty, bgp, false);
8930 if (afi == AFI_MAX)
8931 return CMD_WARNING_CONFIG_FAILED;
8932
8933 /*
8934 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8935 */
8936 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8937 bgp_get_default(), bgp);
8938
8939 if (yes) {
8940 bgp->vpn_policy[afi].tovpn_rd = prd;
8941 SET_FLAG(bgp->vpn_policy[afi].flags,
8942 BGP_VPN_POLICY_TOVPN_RD_SET);
8943 } else {
8944 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8945 BGP_VPN_POLICY_TOVPN_RD_SET);
8946 }
8947
8948 /* post-change: re-export vpn routes */
8949 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8950 bgp_get_default(), bgp);
8951
8952 return CMD_SUCCESS;
8953 }
8954
8955 ALIAS (af_rd_vpn_export,
8956 af_no_rd_vpn_export_cmd,
8957 "no rd vpn export",
8958 NO_STR
8959 "Specify route distinguisher\n"
8960 "Between current address-family and vpn\n"
8961 "For routes leaked from current address-family to vpn\n")
8962
8963 DEFPY (af_label_vpn_export,
8964 af_label_vpn_export_cmd,
8965 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8966 NO_STR
8967 "label value for VRF\n"
8968 "Between current address-family and vpn\n"
8969 "For routes leaked from current address-family to vpn\n"
8970 "Label Value <0-1048575>\n"
8971 "Automatically assign a label\n")
8972 {
8973 VTY_DECLVAR_CONTEXT(bgp, bgp);
8974 mpls_label_t label = MPLS_LABEL_NONE;
8975 afi_t afi;
8976 int idx = 0;
8977 bool yes = true;
8978
8979 if (argv_find(argv, argc, "no", &idx))
8980 yes = false;
8981
8982 /* If "no ...", squash trailing parameter */
8983 if (!yes)
8984 label_auto = NULL;
8985
8986 if (yes) {
8987 if (!label_auto)
8988 label = label_val; /* parser should force unsigned */
8989 }
8990
8991 afi = vpn_policy_getafi(vty, bgp, false);
8992 if (afi == AFI_MAX)
8993 return CMD_WARNING_CONFIG_FAILED;
8994
8995
8996 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8997 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8998 /* no change */
8999 return CMD_SUCCESS;
9000
9001 /*
9002 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9003 */
9004 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9005 bgp_get_default(), bgp);
9006
9007 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9008 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9009
9010 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9011
9012 /*
9013 * label has previously been automatically
9014 * assigned by labelpool: release it
9015 *
9016 * NB if tovpn_label == MPLS_LABEL_NONE it
9017 * means the automatic assignment is in flight
9018 * and therefore the labelpool callback must
9019 * detect that the auto label is not needed.
9020 */
9021
9022 bgp_lp_release(LP_TYPE_VRF,
9023 &bgp->vpn_policy[afi],
9024 bgp->vpn_policy[afi].tovpn_label);
9025 }
9026 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9027 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9028 }
9029
9030 bgp->vpn_policy[afi].tovpn_label = label;
9031 if (label_auto) {
9032 SET_FLAG(bgp->vpn_policy[afi].flags,
9033 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9034 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9035 vpn_leak_label_callback);
9036 }
9037
9038 /* post-change: re-export vpn routes */
9039 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9040 bgp_get_default(), bgp);
9041
9042 hook_call(bgp_snmp_update_last_changed, bgp);
9043 return CMD_SUCCESS;
9044 }
9045
9046 DEFPY (af_sid_vpn_export,
9047 af_sid_vpn_export_cmd,
9048 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9049 NO_STR
9050 "sid value for VRF\n"
9051 "Between current address-family and vpn\n"
9052 "For routes leaked from current address-family to vpn\n"
9053 "Sid allocation index\n"
9054 "Automatically assign a label\n")
9055 {
9056 VTY_DECLVAR_CONTEXT(bgp, bgp);
9057 afi_t afi;
9058 int debug = 0;
9059 int idx = 0;
9060 bool yes = true;
9061
9062 if (argv_find(argv, argc, "no", &idx))
9063 yes = false;
9064 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9065 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9066
9067 afi = vpn_policy_getafi(vty, bgp, false);
9068 if (afi == AFI_MAX)
9069 return CMD_WARNING_CONFIG_FAILED;
9070
9071 if (!yes) {
9072 /* implement me */
9073 vty_out(vty, "It's not implemented\n");
9074 return CMD_WARNING_CONFIG_FAILED;
9075 }
9076
9077 if (bgp->tovpn_sid_index != 0 ||
9078 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9079 vty_out(vty,
9080 "per-vrf sid and per-af sid are mutually exclusive\n"
9081 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9082 return CMD_WARNING_CONFIG_FAILED;
9083 }
9084
9085 /* skip when it's already configured */
9086 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9087 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9088 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9089 return CMD_SUCCESS;
9090
9091 /*
9092 * mode change between sid_idx and sid_auto isn't supported.
9093 * user must negate sid vpn export when they want to change the mode
9094 */
9095 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9096 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9097 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9098 vty_out(vty, "it's already configured as %s.\n",
9099 sid_auto ? "auto-mode" : "idx-mode");
9100 return CMD_WARNING_CONFIG_FAILED;
9101 }
9102
9103 /* pre-change */
9104 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9105 bgp_get_default(), bgp);
9106
9107 if (sid_auto) {
9108 /* SID allocation auto-mode */
9109 if (debug)
9110 zlog_debug("%s: auto sid alloc.", __func__);
9111 SET_FLAG(bgp->vpn_policy[afi].flags,
9112 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9113 } else {
9114 /* SID allocation index-mode */
9115 if (debug)
9116 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9117 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9118 }
9119
9120 /* post-change */
9121 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9122 bgp_get_default(), bgp);
9123 return CMD_SUCCESS;
9124 }
9125
9126 DEFPY (bgp_sid_vpn_export,
9127 bgp_sid_vpn_export_cmd,
9128 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9129 NO_STR
9130 "sid value for VRF\n"
9131 "Between current vrf and vpn\n"
9132 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9133 "For routes leaked from current vrf to vpn\n"
9134 "Sid allocation index\n"
9135 "Automatically assign a label\n")
9136 {
9137 VTY_DECLVAR_CONTEXT(bgp, bgp);
9138 int debug;
9139
9140 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9141 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9142
9143 if (no) {
9144 /* when per-VRF SID is not set, do nothing */
9145 if (bgp->tovpn_sid_index == 0 &&
9146 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9147 return CMD_SUCCESS;
9148
9149 sid_idx = 0;
9150 sid_auto = false;
9151 bgp->tovpn_sid_index = 0;
9152 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9153 }
9154
9155 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9156 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9157 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9158 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9159 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9160 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9161 vty_out(vty,
9162 "per-vrf sid and per-af sid are mutually exclusive\n"
9163 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9164 return CMD_WARNING_CONFIG_FAILED;
9165 }
9166
9167 /* skip when it's already configured */
9168 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9169 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9170 return CMD_SUCCESS;
9171
9172 /*
9173 * mode change between sid_idx and sid_auto isn't supported.
9174 * user must negate sid vpn export when they want to change the mode
9175 */
9176 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9177 (sid_idx != 0 &&
9178 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9179 vty_out(vty, "it's already configured as %s.\n",
9180 sid_auto ? "auto-mode" : "idx-mode");
9181 return CMD_WARNING_CONFIG_FAILED;
9182 }
9183
9184 /* pre-change */
9185 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9186 bgp);
9187 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9188 bgp);
9189
9190 if (sid_auto) {
9191 /* SID allocation auto-mode */
9192 if (debug)
9193 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9194 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9195 } else if (sid_idx != 0) {
9196 /* SID allocation index-mode */
9197 if (debug)
9198 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9199 sid_idx);
9200 bgp->tovpn_sid_index = sid_idx;
9201 }
9202
9203 /* post-change */
9204 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9205 bgp);
9206 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9207 bgp_get_default(), bgp);
9208
9209 return CMD_SUCCESS;
9210 }
9211
9212 ALIAS (af_label_vpn_export,
9213 af_no_label_vpn_export_cmd,
9214 "no label vpn export",
9215 NO_STR
9216 "label value for VRF\n"
9217 "Between current address-family and vpn\n"
9218 "For routes leaked from current address-family to vpn\n")
9219
9220 ALIAS (bgp_sid_vpn_export,
9221 no_bgp_sid_vpn_export_cmd,
9222 "no$no sid vpn per-vrf export",
9223 NO_STR
9224 "sid value for VRF\n"
9225 "Between current vrf and vpn\n"
9226 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9227 "For routes leaked from current vrf to vpn\n")
9228
9229 DEFPY (af_nexthop_vpn_export,
9230 af_nexthop_vpn_export_cmd,
9231 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9232 NO_STR
9233 "Specify next hop to use for VRF advertised prefixes\n"
9234 "Between current address-family and vpn\n"
9235 "For routes leaked from current address-family to vpn\n"
9236 "IPv4 prefix\n"
9237 "IPv6 prefix\n")
9238 {
9239 VTY_DECLVAR_CONTEXT(bgp, bgp);
9240 afi_t afi;
9241 struct prefix p;
9242
9243 if (!no) {
9244 if (!nexthop_su) {
9245 vty_out(vty, "%% Nexthop required\n");
9246 return CMD_WARNING_CONFIG_FAILED;
9247 }
9248 if (!sockunion2hostprefix(nexthop_su, &p))
9249 return CMD_WARNING_CONFIG_FAILED;
9250 }
9251
9252 afi = vpn_policy_getafi(vty, bgp, false);
9253 if (afi == AFI_MAX)
9254 return CMD_WARNING_CONFIG_FAILED;
9255
9256 /*
9257 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9258 */
9259 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9260 bgp_get_default(), bgp);
9261
9262 if (!no) {
9263 bgp->vpn_policy[afi].tovpn_nexthop = p;
9264 SET_FLAG(bgp->vpn_policy[afi].flags,
9265 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9266 } else {
9267 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9268 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9269 }
9270
9271 /* post-change: re-export vpn routes */
9272 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9273 bgp_get_default(), bgp);
9274
9275 return CMD_SUCCESS;
9276 }
9277
9278 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9279 {
9280 if (!strcmp(dstr, "import")) {
9281 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9282 } else if (!strcmp(dstr, "export")) {
9283 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9284 } else if (!strcmp(dstr, "both")) {
9285 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9286 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9287 } else {
9288 vty_out(vty, "%% direction parse error\n");
9289 return CMD_WARNING_CONFIG_FAILED;
9290 }
9291 return CMD_SUCCESS;
9292 }
9293
9294 DEFPY (af_rt_vpn_imexport,
9295 af_rt_vpn_imexport_cmd,
9296 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9297 NO_STR
9298 "Specify route target list\n"
9299 "Specify route target list\n"
9300 "Between current address-family and vpn\n"
9301 "For routes leaked from vpn to current address-family: match any\n"
9302 "For routes leaked from current address-family to vpn: set\n"
9303 "both import: match any and export: set\n"
9304 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9305 {
9306 VTY_DECLVAR_CONTEXT(bgp, bgp);
9307 int ret;
9308 struct ecommunity *ecom = NULL;
9309 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9310 enum vpn_policy_direction dir;
9311 afi_t afi;
9312 int idx = 0;
9313 bool yes = true;
9314
9315 if (argv_find(argv, argc, "no", &idx))
9316 yes = false;
9317
9318 afi = vpn_policy_getafi(vty, bgp, false);
9319 if (afi == AFI_MAX)
9320 return CMD_WARNING_CONFIG_FAILED;
9321
9322 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9323 if (ret != CMD_SUCCESS)
9324 return ret;
9325
9326 if (yes) {
9327 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9328 vty_out(vty, "%% Missing RTLIST\n");
9329 return CMD_WARNING_CONFIG_FAILED;
9330 }
9331 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9332 if (ret != CMD_SUCCESS) {
9333 return ret;
9334 }
9335 }
9336
9337 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9338 if (!dodir[dir])
9339 continue;
9340
9341 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9342
9343 if (yes) {
9344 if (bgp->vpn_policy[afi].rtlist[dir])
9345 ecommunity_free(
9346 &bgp->vpn_policy[afi].rtlist[dir]);
9347 bgp->vpn_policy[afi].rtlist[dir] =
9348 ecommunity_dup(ecom);
9349 } else {
9350 if (bgp->vpn_policy[afi].rtlist[dir])
9351 ecommunity_free(
9352 &bgp->vpn_policy[afi].rtlist[dir]);
9353 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9354 }
9355
9356 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9357 }
9358
9359 if (ecom)
9360 ecommunity_free(&ecom);
9361
9362 return CMD_SUCCESS;
9363 }
9364
9365 ALIAS (af_rt_vpn_imexport,
9366 af_no_rt_vpn_imexport_cmd,
9367 "no <rt|route-target> vpn <import|export|both>$direction_str",
9368 NO_STR
9369 "Specify route target list\n"
9370 "Specify route target list\n"
9371 "Between current address-family and vpn\n"
9372 "For routes leaked from vpn to current address-family\n"
9373 "For routes leaked from current address-family to vpn\n"
9374 "both import and export\n")
9375
9376 DEFPY (af_route_map_vpn_imexport,
9377 af_route_map_vpn_imexport_cmd,
9378 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9379 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9380 NO_STR
9381 "Specify route map\n"
9382 "Between current address-family and vpn\n"
9383 "For routes leaked from vpn to current address-family\n"
9384 "For routes leaked from current address-family to vpn\n"
9385 "name of route-map\n")
9386 {
9387 VTY_DECLVAR_CONTEXT(bgp, bgp);
9388 int ret;
9389 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9390 enum vpn_policy_direction dir;
9391 afi_t afi;
9392 int idx = 0;
9393 bool yes = true;
9394
9395 if (argv_find(argv, argc, "no", &idx))
9396 yes = false;
9397
9398 afi = vpn_policy_getafi(vty, bgp, false);
9399 if (afi == AFI_MAX)
9400 return CMD_WARNING_CONFIG_FAILED;
9401
9402 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9403 if (ret != CMD_SUCCESS)
9404 return ret;
9405
9406 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9407 if (!dodir[dir])
9408 continue;
9409
9410 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9411
9412 if (yes) {
9413 if (bgp->vpn_policy[afi].rmap_name[dir])
9414 XFREE(MTYPE_ROUTE_MAP_NAME,
9415 bgp->vpn_policy[afi].rmap_name[dir]);
9416 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9417 MTYPE_ROUTE_MAP_NAME, rmap_str);
9418 bgp->vpn_policy[afi].rmap[dir] =
9419 route_map_lookup_warn_noexist(vty, rmap_str);
9420 if (!bgp->vpn_policy[afi].rmap[dir])
9421 return CMD_SUCCESS;
9422 } else {
9423 if (bgp->vpn_policy[afi].rmap_name[dir])
9424 XFREE(MTYPE_ROUTE_MAP_NAME,
9425 bgp->vpn_policy[afi].rmap_name[dir]);
9426 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9427 bgp->vpn_policy[afi].rmap[dir] = NULL;
9428 }
9429
9430 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9431 }
9432
9433 return CMD_SUCCESS;
9434 }
9435
9436 ALIAS (af_route_map_vpn_imexport,
9437 af_no_route_map_vpn_imexport_cmd,
9438 "no route-map vpn <import|export>$direction_str",
9439 NO_STR
9440 "Specify route map\n"
9441 "Between current address-family and vpn\n"
9442 "For routes leaked from vpn to current address-family\n"
9443 "For routes leaked from current address-family to vpn\n")
9444
9445 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9446 "import vrf route-map RMAP$rmap_str",
9447 "Import routes from another VRF\n"
9448 "Vrf routes being filtered\n"
9449 "Specify route map\n"
9450 "name of route-map\n")
9451 {
9452 VTY_DECLVAR_CONTEXT(bgp, bgp);
9453 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9454 afi_t afi;
9455 struct bgp *bgp_default;
9456
9457 afi = vpn_policy_getafi(vty, bgp, true);
9458 if (afi == AFI_MAX)
9459 return CMD_WARNING_CONFIG_FAILED;
9460
9461 bgp_default = bgp_get_default();
9462 if (!bgp_default) {
9463 int32_t ret;
9464 as_t as = bgp->as;
9465
9466 /* Auto-create assuming the same AS */
9467 ret = bgp_get_vty(&bgp_default, &as, NULL,
9468 BGP_INSTANCE_TYPE_DEFAULT);
9469
9470 if (ret) {
9471 vty_out(vty,
9472 "VRF default is not configured as a bgp instance\n");
9473 return CMD_WARNING;
9474 }
9475 }
9476
9477 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9478
9479 if (bgp->vpn_policy[afi].rmap_name[dir])
9480 XFREE(MTYPE_ROUTE_MAP_NAME,
9481 bgp->vpn_policy[afi].rmap_name[dir]);
9482 bgp->vpn_policy[afi].rmap_name[dir] =
9483 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9484 bgp->vpn_policy[afi].rmap[dir] =
9485 route_map_lookup_warn_noexist(vty, rmap_str);
9486 if (!bgp->vpn_policy[afi].rmap[dir])
9487 return CMD_SUCCESS;
9488
9489 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9490 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9491
9492 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9493
9494 return CMD_SUCCESS;
9495 }
9496
9497 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9498 "no import vrf route-map [RMAP$rmap_str]",
9499 NO_STR
9500 "Import routes from another VRF\n"
9501 "Vrf routes being filtered\n"
9502 "Specify route map\n"
9503 "name of route-map\n")
9504 {
9505 VTY_DECLVAR_CONTEXT(bgp, bgp);
9506 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9507 afi_t afi;
9508
9509 afi = vpn_policy_getafi(vty, bgp, true);
9510 if (afi == AFI_MAX)
9511 return CMD_WARNING_CONFIG_FAILED;
9512
9513 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9514
9515 if (bgp->vpn_policy[afi].rmap_name[dir])
9516 XFREE(MTYPE_ROUTE_MAP_NAME,
9517 bgp->vpn_policy[afi].rmap_name[dir]);
9518 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9519 bgp->vpn_policy[afi].rmap[dir] = NULL;
9520
9521 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9522 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9523 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9524
9525 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9526
9527 return CMD_SUCCESS;
9528 }
9529
9530 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9531 "[no] import vrf VIEWVRFNAME$import_name",
9532 NO_STR
9533 "Import routes from another VRF\n"
9534 "VRF to import from\n"
9535 "The name of the VRF\n")
9536 {
9537 VTY_DECLVAR_CONTEXT(bgp, bgp);
9538 struct listnode *node;
9539 struct bgp *vrf_bgp, *bgp_default;
9540 int32_t ret = 0;
9541 as_t as = bgp->as;
9542 bool remove = false;
9543 int32_t idx = 0;
9544 char *vname;
9545 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9546 safi_t safi;
9547 afi_t afi;
9548
9549 if (import_name == NULL) {
9550 vty_out(vty, "%% Missing import name\n");
9551 return CMD_WARNING;
9552 }
9553
9554 if (strcmp(import_name, "route-map") == 0) {
9555 vty_out(vty, "%% Must include route-map name\n");
9556 return CMD_WARNING;
9557 }
9558
9559 if (argv_find(argv, argc, "no", &idx))
9560 remove = true;
9561
9562 afi = vpn_policy_getafi(vty, bgp, true);
9563 if (afi == AFI_MAX)
9564 return CMD_WARNING_CONFIG_FAILED;
9565
9566 safi = bgp_node_safi(vty);
9567
9568 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9569 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9570 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9571 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9572 remove ? "unimport" : "import", import_name);
9573 return CMD_WARNING;
9574 }
9575
9576 bgp_default = bgp_get_default();
9577 if (!bgp_default) {
9578 /* Auto-create assuming the same AS */
9579 ret = bgp_get_vty(&bgp_default, &as, NULL,
9580 BGP_INSTANCE_TYPE_DEFAULT);
9581
9582 if (ret) {
9583 vty_out(vty,
9584 "VRF default is not configured as a bgp instance\n");
9585 return CMD_WARNING;
9586 }
9587 }
9588
9589 vrf_bgp = bgp_lookup_by_name(import_name);
9590 if (!vrf_bgp) {
9591 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9592 vrf_bgp = bgp_default;
9593 else
9594 /* Auto-create assuming the same AS */
9595 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9596
9597 if (ret) {
9598 vty_out(vty,
9599 "VRF %s is not configured as a bgp instance\n",
9600 import_name);
9601 return CMD_WARNING;
9602 }
9603 }
9604
9605 if (remove) {
9606 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9607 } else {
9608 /* Already importing from "import_vrf"? */
9609 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9610 vname)) {
9611 if (strcmp(vname, import_name) == 0)
9612 return CMD_WARNING;
9613 }
9614
9615 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9616 }
9617
9618 return CMD_SUCCESS;
9619 }
9620
9621 /* This command is valid only in a bgp vrf instance or the default instance */
9622 DEFPY (bgp_imexport_vpn,
9623 bgp_imexport_vpn_cmd,
9624 "[no] <import|export>$direction_str vpn",
9625 NO_STR
9626 "Import routes to this address-family\n"
9627 "Export routes from this address-family\n"
9628 "to/from default instance VPN RIB\n")
9629 {
9630 VTY_DECLVAR_CONTEXT(bgp, bgp);
9631 int previous_state;
9632 afi_t afi;
9633 safi_t safi;
9634 int idx = 0;
9635 bool yes = true;
9636 int flag;
9637 enum vpn_policy_direction dir;
9638
9639 if (argv_find(argv, argc, "no", &idx))
9640 yes = false;
9641
9642 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9643 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9644
9645 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9646 return CMD_WARNING_CONFIG_FAILED;
9647 }
9648
9649 afi = bgp_node_afi(vty);
9650 safi = bgp_node_safi(vty);
9651 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9652 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9653 return CMD_WARNING_CONFIG_FAILED;
9654 }
9655
9656 if (!strcmp(direction_str, "import")) {
9657 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9658 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9659 } else if (!strcmp(direction_str, "export")) {
9660 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9661 dir = BGP_VPN_POLICY_DIR_TOVPN;
9662 } else {
9663 vty_out(vty, "%% unknown direction %s\n", direction_str);
9664 return CMD_WARNING_CONFIG_FAILED;
9665 }
9666
9667 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9668
9669 if (yes) {
9670 SET_FLAG(bgp->af_flags[afi][safi], flag);
9671 if (!previous_state) {
9672 /* trigger export current vrf */
9673 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9674 }
9675 } else {
9676 if (previous_state) {
9677 /* trigger un-export current vrf */
9678 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9679 }
9680 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9681 }
9682
9683 hook_call(bgp_snmp_init_stats, bgp);
9684
9685 return CMD_SUCCESS;
9686 }
9687
9688 DEFPY (af_routetarget_import,
9689 af_routetarget_import_cmd,
9690 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9691 NO_STR
9692 "Specify route target list\n"
9693 "Specify route target list\n"
9694 "Specify route target list\n"
9695 "Specify route target list\n"
9696 "Flow-spec redirect type route target\n"
9697 "Import routes to this address-family\n"
9698 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9699 {
9700 VTY_DECLVAR_CONTEXT(bgp, bgp);
9701 int ret;
9702 struct ecommunity *ecom = NULL;
9703 afi_t afi;
9704 int idx = 0, idx_unused = 0;
9705 bool yes = true;
9706 bool rt6 = false;
9707
9708 if (argv_find(argv, argc, "no", &idx))
9709 yes = false;
9710
9711 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9712 argv_find(argv, argc, "route-target6", &idx_unused))
9713 rt6 = true;
9714
9715 afi = vpn_policy_getafi(vty, bgp, false);
9716 if (afi == AFI_MAX)
9717 return CMD_WARNING_CONFIG_FAILED;
9718
9719 if (rt6 && afi != AFI_IP6)
9720 return CMD_WARNING_CONFIG_FAILED;
9721
9722 if (yes) {
9723 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9724 vty_out(vty, "%% Missing RTLIST\n");
9725 return CMD_WARNING_CONFIG_FAILED;
9726 }
9727 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9728 if (ret != CMD_SUCCESS)
9729 return ret;
9730 }
9731
9732 if (yes) {
9733 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9734 ecommunity_free(&bgp->vpn_policy[afi]
9735 .import_redirect_rtlist);
9736 bgp->vpn_policy[afi].import_redirect_rtlist =
9737 ecommunity_dup(ecom);
9738 } else {
9739 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9740 ecommunity_free(&bgp->vpn_policy[afi]
9741 .import_redirect_rtlist);
9742 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9743 }
9744
9745 if (ecom)
9746 ecommunity_free(&ecom);
9747
9748 return CMD_SUCCESS;
9749 }
9750
9751 DEFUN_NOSH (address_family_ipv4_safi,
9752 address_family_ipv4_safi_cmd,
9753 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9754 "Enter Address Family command mode\n"
9755 BGP_AF_STR
9756 BGP_SAFI_WITH_LABEL_HELP_STR)
9757 {
9758
9759 if (argc == 3) {
9760 VTY_DECLVAR_CONTEXT(bgp, bgp);
9761 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9762 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9763 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9764 && safi != SAFI_EVPN) {
9765 vty_out(vty,
9766 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9767 return CMD_WARNING_CONFIG_FAILED;
9768 }
9769 vty->node = bgp_node_type(AFI_IP, safi);
9770 } else
9771 vty->node = BGP_IPV4_NODE;
9772
9773 return CMD_SUCCESS;
9774 }
9775
9776 DEFUN_NOSH (address_family_ipv6_safi,
9777 address_family_ipv6_safi_cmd,
9778 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9779 "Enter Address Family command mode\n"
9780 BGP_AF_STR
9781 BGP_SAFI_WITH_LABEL_HELP_STR)
9782 {
9783 if (argc == 3) {
9784 VTY_DECLVAR_CONTEXT(bgp, bgp);
9785 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9786 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9787 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9788 && safi != SAFI_EVPN) {
9789 vty_out(vty,
9790 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9791 return CMD_WARNING_CONFIG_FAILED;
9792 }
9793 vty->node = bgp_node_type(AFI_IP6, safi);
9794 } else
9795 vty->node = BGP_IPV6_NODE;
9796
9797 return CMD_SUCCESS;
9798 }
9799
9800 #ifdef KEEP_OLD_VPN_COMMANDS
9801 DEFUN_NOSH (address_family_vpnv4,
9802 address_family_vpnv4_cmd,
9803 "address-family vpnv4 [unicast]",
9804 "Enter Address Family command mode\n"
9805 BGP_AF_STR
9806 BGP_AF_MODIFIER_STR)
9807 {
9808 vty->node = BGP_VPNV4_NODE;
9809 return CMD_SUCCESS;
9810 }
9811
9812 DEFUN_NOSH (address_family_vpnv6,
9813 address_family_vpnv6_cmd,
9814 "address-family vpnv6 [unicast]",
9815 "Enter Address Family command mode\n"
9816 BGP_AF_STR
9817 BGP_AF_MODIFIER_STR)
9818 {
9819 vty->node = BGP_VPNV6_NODE;
9820 return CMD_SUCCESS;
9821 }
9822 #endif /* KEEP_OLD_VPN_COMMANDS */
9823
9824 DEFUN_NOSH (address_family_evpn,
9825 address_family_evpn_cmd,
9826 "address-family l2vpn evpn",
9827 "Enter Address Family command mode\n"
9828 BGP_AF_STR
9829 BGP_AF_MODIFIER_STR)
9830 {
9831 VTY_DECLVAR_CONTEXT(bgp, bgp);
9832 vty->node = BGP_EVPN_NODE;
9833 return CMD_SUCCESS;
9834 }
9835
9836 DEFUN_NOSH (bgp_segment_routing_srv6,
9837 bgp_segment_routing_srv6_cmd,
9838 "segment-routing srv6",
9839 "Segment-Routing configuration\n"
9840 "Segment-Routing SRv6 configuration\n")
9841 {
9842 VTY_DECLVAR_CONTEXT(bgp, bgp);
9843 bgp->srv6_enabled = true;
9844 vty->node = BGP_SRV6_NODE;
9845 return CMD_SUCCESS;
9846 }
9847
9848 DEFUN (no_bgp_segment_routing_srv6,
9849 no_bgp_segment_routing_srv6_cmd,
9850 "no segment-routing srv6",
9851 NO_STR
9852 "Segment-Routing configuration\n"
9853 "Segment-Routing SRv6 configuration\n")
9854 {
9855 VTY_DECLVAR_CONTEXT(bgp, bgp);
9856
9857 if (strlen(bgp->srv6_locator_name) > 0)
9858 if (bgp_srv6_locator_unset(bgp) < 0)
9859 return CMD_WARNING_CONFIG_FAILED;
9860
9861 bgp->srv6_enabled = false;
9862 return CMD_SUCCESS;
9863 }
9864
9865 DEFPY (bgp_srv6_locator,
9866 bgp_srv6_locator_cmd,
9867 "locator NAME$name",
9868 "Specify SRv6 locator\n"
9869 "Specify SRv6 locator\n")
9870 {
9871 VTY_DECLVAR_CONTEXT(bgp, bgp);
9872 int ret;
9873
9874 if (strlen(bgp->srv6_locator_name) > 0
9875 && strcmp(name, bgp->srv6_locator_name) != 0) {
9876 vty_out(vty, "srv6 locator is already configured\n");
9877 return CMD_WARNING_CONFIG_FAILED;
9878 }
9879
9880 snprintf(bgp->srv6_locator_name,
9881 sizeof(bgp->srv6_locator_name), "%s", name);
9882
9883 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9884 if (ret < 0)
9885 return CMD_WARNING_CONFIG_FAILED;
9886
9887 return CMD_SUCCESS;
9888 }
9889
9890 DEFPY (no_bgp_srv6_locator,
9891 no_bgp_srv6_locator_cmd,
9892 "no locator NAME$name",
9893 NO_STR
9894 "Specify SRv6 locator\n"
9895 "Specify SRv6 locator\n")
9896 {
9897 VTY_DECLVAR_CONTEXT(bgp, bgp);
9898
9899 /* when locator isn't configured, do nothing */
9900 if (strlen(bgp->srv6_locator_name) < 1)
9901 return CMD_SUCCESS;
9902
9903 /* name validation */
9904 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9905 vty_out(vty, "%% No srv6 locator is configured\n");
9906 return CMD_WARNING_CONFIG_FAILED;
9907 }
9908
9909 /* unset locator */
9910 if (bgp_srv6_locator_unset(bgp) < 0)
9911 return CMD_WARNING_CONFIG_FAILED;
9912
9913 return CMD_SUCCESS;
9914 }
9915
9916 DEFPY (show_bgp_srv6,
9917 show_bgp_srv6_cmd,
9918 "show bgp segment-routing srv6",
9919 SHOW_STR
9920 BGP_STR
9921 "BGP Segment Routing\n"
9922 "BGP Segment Routing SRv6\n")
9923 {
9924 struct bgp *bgp;
9925 struct listnode *node;
9926 struct srv6_locator_chunk *chunk;
9927 struct bgp_srv6_function *func;
9928
9929 bgp = bgp_get_default();
9930 if (!bgp)
9931 return CMD_SUCCESS;
9932
9933 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9934 vty_out(vty, "locator_chunks:\n");
9935 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9936 vty_out(vty, "- %pFX\n", &chunk->prefix);
9937 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9938 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9939 vty_out(vty, " func-length: %d\n",
9940 chunk->function_bits_length);
9941 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9942 }
9943
9944 vty_out(vty, "functions:\n");
9945 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9946 vty_out(vty, "- sid: %pI6\n", &func->sid);
9947 vty_out(vty, " locator: %s\n", func->locator_name);
9948 }
9949
9950 vty_out(vty, "bgps:\n");
9951 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9952 vty_out(vty, "- name: %s\n",
9953 bgp->name ? bgp->name : "default");
9954
9955 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9956 bgp->vpn_policy[AFI_IP].tovpn_sid);
9957 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9958 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9959 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
9960 }
9961
9962 return CMD_SUCCESS;
9963 }
9964
9965 DEFUN_NOSH (exit_address_family,
9966 exit_address_family_cmd,
9967 "exit-address-family",
9968 "Exit from Address Family configuration mode\n")
9969 {
9970 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9971 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9972 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9973 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9974 || vty->node == BGP_EVPN_NODE
9975 || vty->node == BGP_FLOWSPECV4_NODE
9976 || vty->node == BGP_FLOWSPECV6_NODE)
9977 vty->node = BGP_NODE;
9978 return CMD_SUCCESS;
9979 }
9980
9981 /* Recalculate bestpath and re-advertise a prefix */
9982 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9983 const char *ip_str, afi_t afi, safi_t safi,
9984 struct prefix_rd *prd)
9985 {
9986 int ret;
9987 struct prefix match;
9988 struct bgp_dest *dest;
9989 struct bgp_dest *rm;
9990 struct bgp *bgp;
9991 struct bgp_table *table;
9992 struct bgp_table *rib;
9993
9994 /* BGP structure lookup. */
9995 if (view_name) {
9996 bgp = bgp_lookup_by_name(view_name);
9997 if (bgp == NULL) {
9998 vty_out(vty, "%% Can't find BGP instance %s\n",
9999 view_name);
10000 return CMD_WARNING;
10001 }
10002 } else {
10003 bgp = bgp_get_default();
10004 if (bgp == NULL) {
10005 vty_out(vty, "%% No BGP process is configured\n");
10006 return CMD_WARNING;
10007 }
10008 }
10009
10010 /* Check IP address argument. */
10011 ret = str2prefix(ip_str, &match);
10012 if (!ret) {
10013 vty_out(vty, "%% address is malformed\n");
10014 return CMD_WARNING;
10015 }
10016
10017 match.family = afi2family(afi);
10018 rib = bgp->rib[afi][safi];
10019
10020 if (safi == SAFI_MPLS_VPN) {
10021 for (dest = bgp_table_top(rib); dest;
10022 dest = bgp_route_next(dest)) {
10023 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10024
10025 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10026 continue;
10027
10028 table = bgp_dest_get_bgp_table_info(dest);
10029 if (table == NULL)
10030 continue;
10031
10032 rm = bgp_node_match(table, &match);
10033 if (rm != NULL) {
10034 const struct prefix *rm_p =
10035 bgp_dest_get_prefix(rm);
10036
10037 if (rm_p->prefixlen == match.prefixlen) {
10038 SET_FLAG(rm->flags,
10039 BGP_NODE_USER_CLEAR);
10040 bgp_process(bgp, rm, afi, safi);
10041 }
10042 bgp_dest_unlock_node(rm);
10043 }
10044 }
10045 } else {
10046 dest = bgp_node_match(rib, &match);
10047 if (dest != NULL) {
10048 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10049
10050 if (dest_p->prefixlen == match.prefixlen) {
10051 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10052 bgp_process(bgp, dest, afi, safi);
10053 }
10054 bgp_dest_unlock_node(dest);
10055 }
10056 }
10057
10058 return CMD_SUCCESS;
10059 }
10060
10061 /* one clear bgp command to rule them all */
10062 DEFUN (clear_ip_bgp_all,
10063 clear_ip_bgp_all_cmd,
10064 "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>]",
10065 CLEAR_STR
10066 IP_STR
10067 BGP_STR
10068 BGP_INSTANCE_HELP_STR
10069 BGP_AFI_HELP_STR
10070 BGP_AF_STR
10071 BGP_SAFI_WITH_LABEL_HELP_STR
10072 BGP_AF_MODIFIER_STR
10073 "Clear all peers\n"
10074 "BGP IPv4 neighbor to clear\n"
10075 "BGP IPv6 neighbor to clear\n"
10076 "BGP neighbor on interface to clear\n"
10077 "Clear peers with the AS number\n"
10078 "Clear all external peers\n"
10079 "Clear all members of peer-group\n"
10080 "BGP peer-group name\n"
10081 BGP_SOFT_STR
10082 BGP_SOFT_IN_STR
10083 BGP_SOFT_OUT_STR
10084 BGP_SOFT_IN_STR
10085 "Push out prefix-list ORF and do inbound soft reconfig\n"
10086 BGP_SOFT_OUT_STR
10087 "Reset message statistics\n")
10088 {
10089 char *vrf = NULL;
10090
10091 afi_t afi = AFI_UNSPEC;
10092 safi_t safi = SAFI_UNSPEC;
10093 enum clear_sort clr_sort = clear_peer;
10094 enum bgp_clear_type clr_type;
10095 char *clr_arg = NULL;
10096
10097 int idx = 0;
10098
10099 /* clear [ip] bgp */
10100 if (argv_find(argv, argc, "ip", &idx))
10101 afi = AFI_IP;
10102
10103 /* [<vrf> VIEWVRFNAME] */
10104 if (argv_find(argv, argc, "vrf", &idx)) {
10105 vrf = argv[idx + 1]->arg;
10106 idx += 2;
10107 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10108 vrf = NULL;
10109 } else if (argv_find(argv, argc, "view", &idx)) {
10110 /* [<view> VIEWVRFNAME] */
10111 vrf = argv[idx + 1]->arg;
10112 idx += 2;
10113 }
10114 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10115 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10116 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10117
10118 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10119 if (argv_find(argv, argc, "*", &idx)) {
10120 clr_sort = clear_all;
10121 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10122 clr_sort = clear_peer;
10123 clr_arg = argv[idx]->arg;
10124 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10125 clr_sort = clear_peer;
10126 clr_arg = argv[idx]->arg;
10127 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10128 clr_sort = clear_group;
10129 idx++;
10130 clr_arg = argv[idx]->arg;
10131 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10132 clr_sort = clear_peer;
10133 clr_arg = argv[idx]->arg;
10134 } else if (argv_find(argv, argc, "WORD", &idx)) {
10135 clr_sort = clear_peer;
10136 clr_arg = argv[idx]->arg;
10137 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10138 clr_sort = clear_as;
10139 clr_arg = argv[idx]->arg;
10140 } else if (argv_find(argv, argc, "external", &idx)) {
10141 clr_sort = clear_external;
10142 }
10143
10144 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10145 if (argv_find(argv, argc, "soft", &idx)) {
10146 if (argv_find(argv, argc, "in", &idx)
10147 || argv_find(argv, argc, "out", &idx))
10148 clr_type = strmatch(argv[idx]->text, "in")
10149 ? BGP_CLEAR_SOFT_IN
10150 : BGP_CLEAR_SOFT_OUT;
10151 else
10152 clr_type = BGP_CLEAR_SOFT_BOTH;
10153 } else if (argv_find(argv, argc, "in", &idx)) {
10154 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10155 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10156 : BGP_CLEAR_SOFT_IN;
10157 } else if (argv_find(argv, argc, "out", &idx)) {
10158 clr_type = BGP_CLEAR_SOFT_OUT;
10159 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10160 clr_type = BGP_CLEAR_MESSAGE_STATS;
10161 } else
10162 clr_type = BGP_CLEAR_SOFT_NONE;
10163
10164 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10165 }
10166
10167 DEFUN (clear_ip_bgp_prefix,
10168 clear_ip_bgp_prefix_cmd,
10169 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10170 CLEAR_STR
10171 IP_STR
10172 BGP_STR
10173 BGP_INSTANCE_HELP_STR
10174 "Clear bestpath and re-advertise\n"
10175 "IPv4 prefix\n")
10176 {
10177 char *vrf = NULL;
10178 char *prefix = NULL;
10179
10180 int idx = 0;
10181
10182 /* [<view|vrf> VIEWVRFNAME] */
10183 if (argv_find(argv, argc, "vrf", &idx)) {
10184 vrf = argv[idx + 1]->arg;
10185 idx += 2;
10186 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10187 vrf = NULL;
10188 } else if (argv_find(argv, argc, "view", &idx)) {
10189 /* [<view> VIEWVRFNAME] */
10190 vrf = argv[idx + 1]->arg;
10191 idx += 2;
10192 }
10193
10194 prefix = argv[argc - 1]->arg;
10195
10196 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10197 }
10198
10199 DEFUN (clear_bgp_ipv6_safi_prefix,
10200 clear_bgp_ipv6_safi_prefix_cmd,
10201 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10202 CLEAR_STR
10203 IP_STR
10204 BGP_STR
10205 BGP_AF_STR
10206 BGP_SAFI_HELP_STR
10207 "Clear bestpath and re-advertise\n"
10208 "IPv6 prefix\n")
10209 {
10210 int idx_safi = 0;
10211 int idx_ipv6_prefix = 0;
10212 safi_t safi = SAFI_UNICAST;
10213 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10214 argv[idx_ipv6_prefix]->arg : NULL;
10215
10216 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10217 return bgp_clear_prefix(
10218 vty, NULL, prefix, AFI_IP6,
10219 safi, NULL);
10220 }
10221
10222 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10223 clear_bgp_instance_ipv6_safi_prefix_cmd,
10224 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10225 CLEAR_STR
10226 IP_STR
10227 BGP_STR
10228 BGP_INSTANCE_HELP_STR
10229 BGP_AF_STR
10230 BGP_SAFI_HELP_STR
10231 "Clear bestpath and re-advertise\n"
10232 "IPv6 prefix\n")
10233 {
10234 int idx_safi = 0;
10235 int idx_vrfview = 0;
10236 int idx_ipv6_prefix = 0;
10237 safi_t safi = SAFI_UNICAST;
10238 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10239 argv[idx_ipv6_prefix]->arg : NULL;
10240 char *vrfview = NULL;
10241
10242 /* [<view|vrf> VIEWVRFNAME] */
10243 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10244 vrfview = argv[idx_vrfview + 1]->arg;
10245 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10246 vrfview = NULL;
10247 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10248 /* [<view> VIEWVRFNAME] */
10249 vrfview = argv[idx_vrfview + 1]->arg;
10250 }
10251 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10252
10253 return bgp_clear_prefix(
10254 vty, vrfview, prefix,
10255 AFI_IP6, safi, NULL);
10256 }
10257
10258 DEFUN (show_bgp_views,
10259 show_bgp_views_cmd,
10260 "show [ip] bgp views",
10261 SHOW_STR
10262 IP_STR
10263 BGP_STR
10264 "Show the defined BGP views\n")
10265 {
10266 struct list *inst = bm->bgp;
10267 struct listnode *node;
10268 struct bgp *bgp;
10269
10270 vty_out(vty, "Defined BGP views:\n");
10271 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10272 /* Skip VRFs. */
10273 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10274 continue;
10275 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10276 bgp->as);
10277 }
10278
10279 return CMD_SUCCESS;
10280 }
10281
10282 static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10283 int *peers_estbd)
10284 {
10285 struct peer *peer;
10286 struct listnode *node;
10287
10288 *peers_cfgd = *peers_estbd = 0;
10289 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10290 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10291 continue;
10292 (*peers_cfgd)++;
10293 if (peer_established(peer))
10294 (*peers_estbd)++;
10295 }
10296 }
10297
10298 static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10299 const char *type)
10300 {
10301 int peers_cfg, peers_estb;
10302
10303 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10304
10305 if (json) {
10306 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10307 ? -1
10308 : (int64_t)bgp->vrf_id;
10309 json_object_string_add(json, "type", type);
10310 json_object_int_add(json, "vrfId", vrf_id_ui);
10311 json_object_string_addf(json, "routerId", "%pI4",
10312 &bgp->router_id);
10313 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10314 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10315 json_object_int_add(json, "l3vni", bgp->l3vni);
10316 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10317 json_object_string_add(
10318 json, "interface",
10319 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10320 }
10321 }
10322
10323 static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10324 json_object *json, const char *name,
10325 const char *type, bool use_vrf)
10326 {
10327 int peers_cfg, peers_estb;
10328
10329 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10330
10331 if (use_vrf) {
10332 if (json) {
10333 print_bgp_vrfs(bgp, vty, json, type);
10334 } else {
10335 vty_out(vty, "BGP instance %s VRF id %d\n",
10336 bgp->name_pretty,
10337 bgp->vrf_id == VRF_UNKNOWN ? -1
10338 : (int)bgp->vrf_id);
10339 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10340 vty_out(vty,
10341 "Num Configured Peers %d, Established %d\n",
10342 peers_cfg, peers_estb);
10343 if (bgp->l3vni) {
10344 vty_out(vty,
10345 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10346 bgp->l3vni,
10347 ifindex2ifname(bgp->l3vni_svi_ifindex,
10348 bgp->vrf_id),
10349 &bgp->rmac);
10350 }
10351 }
10352 } else {
10353 if (json) {
10354 print_bgp_vrfs(bgp, vty, json, type);
10355 } else {
10356 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10357 type,
10358 bgp->vrf_id == VRF_UNKNOWN ? -1
10359 : (int)bgp->vrf_id,
10360 &bgp->router_id, peers_cfg, peers_estb, name);
10361 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10362 bgp->l3vni, &bgp->rmac,
10363 ifindex2ifname(bgp->l3vni_svi_ifindex,
10364 bgp->vrf_id));
10365 }
10366 }
10367
10368 return CMD_SUCCESS;
10369 }
10370
10371 DEFPY (show_bgp_vrfs,
10372 show_bgp_vrfs_cmd,
10373 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10374 SHOW_STR
10375 IP_STR
10376 BGP_STR
10377 "Show BGP VRFs\n"
10378 "Specific VRF name\n"
10379 JSON_STR)
10380 {
10381 struct list *inst = bm->bgp;
10382 struct listnode *node;
10383 struct bgp *bgp;
10384 bool uj = use_json(argc, argv);
10385 json_object *json = NULL;
10386 json_object *json_vrfs = NULL;
10387 json_object *json_vrf = NULL;
10388 int count = 0;
10389 const char *name = vrf_name;
10390 const char *type;
10391
10392 if (uj)
10393 json = json_object_new_object();
10394
10395 if (name) {
10396 if (strmatch(name, VRF_DEFAULT_NAME)) {
10397 bgp = bgp_get_default();
10398 type = "DFLT";
10399 } else {
10400 bgp = bgp_lookup_by_name(name);
10401 type = "VRF";
10402 }
10403 if (!bgp) {
10404 if (uj)
10405 vty_json(vty, json);
10406 else
10407 vty_out(vty,
10408 "%% Specified BGP instance not found\n");
10409
10410 return CMD_WARNING;
10411 }
10412 }
10413
10414 if (vrf_name) {
10415 if (uj)
10416 json_vrf = json_object_new_object();
10417
10418 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10419 true);
10420
10421 if (uj) {
10422 json_object_object_add(json, name, json_vrf);
10423 vty_json(vty, json);
10424 }
10425
10426 return CMD_SUCCESS;
10427 }
10428
10429 if (uj)
10430 json_vrfs = json_object_new_object();
10431
10432 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10433 const char *name;
10434
10435 /* Skip Views. */
10436 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10437 continue;
10438
10439 count++;
10440 if (!uj && count == 1) {
10441 vty_out(vty,
10442 "%4s %-5s %-16s %9s %10s %-37s\n",
10443 "Type", "Id", "routerId", "#PeersCfg",
10444 "#PeersEstb", "Name");
10445 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10446 "L3-VNI", "RouterMAC", "Interface");
10447 }
10448 if (uj)
10449 json_vrf = json_object_new_object();
10450
10451 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10452 name = VRF_DEFAULT_NAME;
10453 type = "DFLT";
10454 } else {
10455 name = bgp->name;
10456 type = "VRF";
10457 }
10458
10459 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10460 false);
10461
10462 if (uj)
10463 json_object_object_add(json_vrfs, name, json_vrf);
10464 }
10465
10466 if (uj) {
10467 json_object_object_add(json, "vrfs", json_vrfs);
10468 json_object_int_add(json, "totalVrfs", count);
10469 vty_json(vty, json);
10470 } else {
10471 if (count)
10472 vty_out(vty,
10473 "\nTotal number of VRFs (including default): %d\n",
10474 count);
10475 }
10476
10477 return CMD_SUCCESS;
10478 }
10479
10480 DEFUN (show_bgp_mac_hash,
10481 show_bgp_mac_hash_cmd,
10482 "show bgp mac hash",
10483 SHOW_STR
10484 BGP_STR
10485 "Mac Address\n"
10486 "Mac Address database\n")
10487 {
10488 bgp_mac_dump_table(vty);
10489
10490 return CMD_SUCCESS;
10491 }
10492
10493 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10494 {
10495 struct vty *vty = (struct vty *)args;
10496 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10497
10498 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10499 }
10500
10501 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10502 {
10503 vty_out(vty, "self nexthop database:\n");
10504 bgp_nexthop_show_address_hash(vty, bgp);
10505
10506 vty_out(vty, "Tunnel-ip database:\n");
10507 hash_iterate(bgp->tip_hash,
10508 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10509 vty);
10510 }
10511
10512 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10513 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10514 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10515 "martian next-hops\n"
10516 "martian next-hop database\n")
10517 {
10518 struct bgp *bgp = NULL;
10519 int idx = 0;
10520 char *name = NULL;
10521
10522 /* [<vrf> VIEWVRFNAME] */
10523 if (argv_find(argv, argc, "vrf", &idx)) {
10524 name = argv[idx + 1]->arg;
10525 if (name && strmatch(name, VRF_DEFAULT_NAME))
10526 name = NULL;
10527 } else if (argv_find(argv, argc, "view", &idx))
10528 /* [<view> VIEWVRFNAME] */
10529 name = argv[idx + 1]->arg;
10530 if (name)
10531 bgp = bgp_lookup_by_name(name);
10532 else
10533 bgp = bgp_get_default();
10534
10535 if (!bgp) {
10536 vty_out(vty, "%% No BGP process is configured\n");
10537 return CMD_WARNING;
10538 }
10539 bgp_show_martian_nexthops(vty, bgp);
10540
10541 return CMD_SUCCESS;
10542 }
10543
10544 DEFUN (show_bgp_memory,
10545 show_bgp_memory_cmd,
10546 "show [ip] bgp memory",
10547 SHOW_STR
10548 IP_STR
10549 BGP_STR
10550 "Global BGP memory statistics\n")
10551 {
10552 char memstrbuf[MTYPE_MEMSTR_LEN];
10553 unsigned long count;
10554
10555 /* RIB related usage stats */
10556 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10557 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10558 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10559 count * sizeof(struct bgp_dest)));
10560
10561 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10562 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10563 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10564 count * sizeof(struct bgp_path_info)));
10565 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10566 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10567 count,
10568 mtype_memstr(
10569 memstrbuf, sizeof(memstrbuf),
10570 count * sizeof(struct bgp_path_info_extra)));
10571
10572 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10573 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10574 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10575 count * sizeof(struct bgp_static)));
10576
10577 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10578 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10579 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10580 count * sizeof(struct bpacket)));
10581
10582 /* Adj-In/Out */
10583 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10584 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10585 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10586 count * sizeof(struct bgp_adj_in)));
10587 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10588 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10589 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10590 count * sizeof(struct bgp_adj_out)));
10591
10592 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10593 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10594 count,
10595 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10596 count * sizeof(struct bgp_nexthop_cache)));
10597
10598 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10599 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10600 count,
10601 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10602 count * sizeof(struct bgp_damp_info)));
10603
10604 /* Attributes */
10605 count = attr_count();
10606 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10607 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10608 count * sizeof(struct attr)));
10609
10610 if ((count = attr_unknown_count()))
10611 vty_out(vty, "%ld unknown attributes\n", count);
10612
10613 /* AS_PATH attributes */
10614 count = aspath_count();
10615 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10616 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10617 count * sizeof(struct aspath)));
10618
10619 count = mtype_stats_alloc(MTYPE_AS_SEG);
10620 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10621 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10622 count * sizeof(struct assegment)));
10623
10624 /* Other attributes */
10625 if ((count = community_count()))
10626 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10627 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10628 count * sizeof(struct community)));
10629 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10630 vty_out(vty,
10631 "%ld BGP ext-community entries, using %s of memory\n",
10632 count,
10633 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10634 count * sizeof(struct ecommunity)));
10635 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10636 vty_out(vty,
10637 "%ld BGP large-community entries, using %s of memory\n",
10638 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10639 count * sizeof(struct lcommunity)));
10640
10641 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10642 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10643 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10644 count * sizeof(struct cluster_list)));
10645
10646 /* Peer related usage */
10647 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10648 vty_out(vty, "%ld peers, using %s of memory\n", count,
10649 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10650 count * sizeof(struct peer)));
10651
10652 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10653 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10654 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10655 count * sizeof(struct peer_group)));
10656
10657 /* Other */
10658 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10659 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10660 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10661 count * sizeof(regex_t)));
10662 return CMD_SUCCESS;
10663 }
10664
10665 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10666 {
10667 json_object *bestpath = json_object_new_object();
10668
10669 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10670 json_object_string_add(bestpath, "asPath", "ignore");
10671
10672 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10673 json_object_string_add(bestpath, "asPath", "confed");
10674
10675 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10676 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10677 json_object_string_add(bestpath, "multiPathRelax",
10678 "as-set");
10679 else
10680 json_object_string_add(bestpath, "multiPathRelax",
10681 "true");
10682 } else
10683 json_object_string_add(bestpath, "multiPathRelax", "false");
10684
10685 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10686 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10687
10688 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10689 json_object_string_add(bestpath, "compareRouterId", "true");
10690 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10691 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10692 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10693 json_object_string_add(bestpath, "med", "confed");
10694 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10695 json_object_string_add(bestpath, "med",
10696 "missing-as-worst");
10697 else
10698 json_object_string_add(bestpath, "med", "true");
10699 }
10700
10701 json_object_object_add(json, "bestPath", bestpath);
10702 }
10703
10704 /* Print the error code/subcode for why the peer is down */
10705 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10706 json_object *json_peer, bool use_json)
10707 {
10708 const char *code_str;
10709 const char *subcode_str;
10710
10711 if (use_json) {
10712 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10713 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10714 char errorcodesubcode_hexstr[5];
10715 char errorcodesubcode_str[256];
10716
10717 code_str = bgp_notify_code_str(peer->notify.code);
10718 subcode_str = bgp_notify_subcode_str(
10719 peer->notify.code,
10720 peer->notify.subcode);
10721
10722 snprintf(errorcodesubcode_hexstr,
10723 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10724 peer->notify.code, peer->notify.subcode);
10725 json_object_string_add(json_peer,
10726 "lastErrorCodeSubcode",
10727 errorcodesubcode_hexstr);
10728 snprintf(errorcodesubcode_str, 255, "%s%s",
10729 code_str, subcode_str);
10730 json_object_string_add(json_peer,
10731 "lastNotificationReason",
10732 errorcodesubcode_str);
10733 json_object_boolean_add(json_peer,
10734 "lastNotificationHardReset",
10735 peer->notify.hard_reset);
10736 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10737 && peer->notify.code == BGP_NOTIFY_CEASE
10738 && (peer->notify.subcode
10739 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10740 || peer->notify.subcode
10741 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10742 && peer->notify.length) {
10743 char msgbuf[1024];
10744 const char *msg_str;
10745
10746 msg_str = bgp_notify_admin_message(
10747 msgbuf, sizeof(msgbuf),
10748 (uint8_t *)peer->notify.data,
10749 peer->notify.length);
10750 if (msg_str)
10751 json_object_string_add(
10752 json_peer,
10753 "lastShutdownDescription",
10754 msg_str);
10755 }
10756
10757 }
10758 json_object_string_add(json_peer, "lastResetDueTo",
10759 peer_down_str[(int)peer->last_reset]);
10760 json_object_int_add(json_peer, "lastResetCode",
10761 peer->last_reset);
10762 } else {
10763 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10764 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10765 code_str = bgp_notify_code_str(peer->notify.code);
10766 subcode_str =
10767 bgp_notify_subcode_str(peer->notify.code,
10768 peer->notify.subcode);
10769 vty_out(vty, " Notification %s (%s%s%s)\n",
10770 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10771 ? "sent"
10772 : "received",
10773 code_str, subcode_str,
10774 peer->notify.hard_reset
10775 ? bgp_notify_subcode_str(
10776 BGP_NOTIFY_CEASE,
10777 BGP_NOTIFY_CEASE_HARD_RESET)
10778 : "");
10779 } else {
10780 vty_out(vty, " %s\n",
10781 peer_down_str[(int)peer->last_reset]);
10782 }
10783 }
10784 }
10785
10786 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10787 safi_t safi)
10788 {
10789 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10790 }
10791
10792 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10793 struct peer *peer, json_object *json_peer,
10794 int max_neighbor_width, bool use_json)
10795 {
10796 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10797 int len;
10798
10799 if (use_json) {
10800 if (peer_dynamic_neighbor(peer))
10801 json_object_boolean_true_add(json_peer,
10802 "dynamicPeer");
10803 if (peer->hostname)
10804 json_object_string_add(json_peer, "hostname",
10805 peer->hostname);
10806
10807 if (peer->domainname)
10808 json_object_string_add(json_peer, "domainname",
10809 peer->domainname);
10810 json_object_int_add(json_peer, "connectionsEstablished",
10811 peer->established);
10812 json_object_int_add(json_peer, "connectionsDropped",
10813 peer->dropped);
10814 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10815 use_json, json_peer);
10816 if (peer_established(peer))
10817 json_object_string_add(json_peer, "lastResetDueTo",
10818 "AFI/SAFI Not Negotiated");
10819 else
10820 bgp_show_peer_reset(NULL, peer, json_peer, true);
10821 } else {
10822 dn_flag[1] = '\0';
10823 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10824 if (peer->hostname
10825 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10826 len = vty_out(vty, "%s%s(%s)", dn_flag,
10827 peer->hostname, peer->host);
10828 else
10829 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10830
10831 /* pad the neighbor column with spaces */
10832 if (len < max_neighbor_width)
10833 vty_out(vty, "%*s", max_neighbor_width - len,
10834 " ");
10835 vty_out(vty, "%7d %7d %9s", peer->established,
10836 peer->dropped,
10837 peer_uptime(peer->uptime, timebuf,
10838 BGP_UPTIME_LEN, 0, NULL));
10839 if (peer_established(peer))
10840 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10841 else
10842 bgp_show_peer_reset(vty, peer, NULL,
10843 false);
10844 }
10845 }
10846
10847 /* Strip peer's description to the given size. */
10848 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10849 {
10850 static char stripped[BUFSIZ];
10851 uint32_t i = 0;
10852 uint32_t last_space = 0;
10853
10854 while (i < size) {
10855 if (*(desc + i) == 0) {
10856 stripped[i] = '\0';
10857 return stripped;
10858 }
10859 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10860 last_space = i;
10861 stripped[i] = *(desc + i);
10862 i++;
10863 }
10864
10865 if (last_space > size)
10866 stripped[size + 1] = '\0';
10867 else
10868 stripped[last_space] = '\0';
10869
10870 return stripped;
10871 }
10872
10873 /* Determine whether var peer should be filtered out of the summary. */
10874 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10875 struct peer *fpeer, int as_type,
10876 as_t as)
10877 {
10878
10879 /* filter neighbor XXXX */
10880 if (fpeer && fpeer != peer)
10881 return true;
10882
10883 /* filter remote-as (internal|external) */
10884 if (as_type != AS_UNSPECIFIED) {
10885 if (peer->as_type == AS_SPECIFIED) {
10886 if (as_type == AS_INTERNAL) {
10887 if (peer->as != peer->local_as)
10888 return true;
10889 } else if (peer->as == peer->local_as)
10890 return true;
10891 } else if (as_type != peer->as_type)
10892 return true;
10893 } else if (as && as != peer->as) /* filter remote-as XXX */
10894 return true;
10895
10896 return false;
10897 }
10898
10899 /* Show BGP peer's summary information.
10900 *
10901 * Peer's description is stripped according to if `wide` option is given
10902 * or not.
10903 *
10904 * When adding new columns to `show bgp summary` output, please make
10905 * sure `Desc` is the lastest column to show because it can contain
10906 * whitespaces and the whole output will be tricky.
10907 */
10908 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10909 struct peer *fpeer, int as_type, as_t as,
10910 uint16_t show_flags)
10911 {
10912 struct peer *peer;
10913 struct listnode *node, *nnode;
10914 unsigned int count = 0, dn_count = 0;
10915 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10916 char neighbor_buf[VTY_BUFSIZ];
10917 int neighbor_col_default_width = 16;
10918 int len, failed_count = 0;
10919 unsigned int filtered_count = 0;
10920 int max_neighbor_width = 0;
10921 int pfx_rcd_safi;
10922 json_object *json = NULL;
10923 json_object *json_peer = NULL;
10924 json_object *json_peers = NULL;
10925 struct peer_af *paf;
10926 struct bgp_filter *filter;
10927 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10928 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10929 bool show_established =
10930 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10931 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10932 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10933
10934 /* labeled-unicast routes are installed in the unicast table so in order
10935 * to
10936 * display the correct PfxRcd value we must look at SAFI_UNICAST
10937 */
10938
10939 if (safi == SAFI_LABELED_UNICAST)
10940 pfx_rcd_safi = SAFI_UNICAST;
10941 else
10942 pfx_rcd_safi = safi;
10943
10944 if (use_json) {
10945 json = json_object_new_object();
10946 json_peers = json_object_new_object();
10947 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10948 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10949 as_type, as)) {
10950 filtered_count++;
10951 count++;
10952 continue;
10953 }
10954
10955 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10956 continue;
10957
10958 if (peer->afc[afi][safi]) {
10959 /* See if we have at least a single failed peer */
10960 if (bgp_has_peer_failed(peer, afi, safi))
10961 failed_count++;
10962 count++;
10963 }
10964 if (peer_dynamic_neighbor(peer))
10965 dn_count++;
10966 }
10967
10968 } else {
10969 /* Loop over all neighbors that will be displayed to determine
10970 * how many
10971 * characters are needed for the Neighbor column
10972 */
10973 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10974 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10975 as_type, as)) {
10976 filtered_count++;
10977 count++;
10978 continue;
10979 }
10980
10981 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10982 continue;
10983
10984 if (peer->afc[afi][safi]) {
10985 memset(dn_flag, '\0', sizeof(dn_flag));
10986 if (peer_dynamic_neighbor(peer))
10987 dn_flag[0] = '*';
10988
10989 if (peer->hostname
10990 && CHECK_FLAG(bgp->flags,
10991 BGP_FLAG_SHOW_HOSTNAME))
10992 snprintf(neighbor_buf,
10993 sizeof(neighbor_buf),
10994 "%s%s(%s) ", dn_flag,
10995 peer->hostname, peer->host);
10996 else
10997 snprintf(neighbor_buf,
10998 sizeof(neighbor_buf), "%s%s ",
10999 dn_flag, peer->host);
11000
11001 len = strlen(neighbor_buf);
11002
11003 if (len > max_neighbor_width)
11004 max_neighbor_width = len;
11005
11006 /* See if we have at least a single failed peer */
11007 if (bgp_has_peer_failed(peer, afi, safi))
11008 failed_count++;
11009 count++;
11010 }
11011 }
11012
11013 /* Originally we displayed the Neighbor column as 16
11014 * characters wide so make that the default
11015 */
11016 if (max_neighbor_width < neighbor_col_default_width)
11017 max_neighbor_width = neighbor_col_default_width;
11018 }
11019
11020 if (show_failed && !failed_count) {
11021 if (use_json) {
11022 json_object_int_add(json, "failedPeersCount", 0);
11023 json_object_int_add(json, "dynamicPeers", dn_count);
11024 json_object_int_add(json, "totalPeers", count);
11025
11026 vty_json(vty, json);
11027 } else {
11028 vty_out(vty, "%% No failed BGP neighbors found\n");
11029 }
11030 return CMD_SUCCESS;
11031 }
11032
11033 count = 0; /* Reset the value as its used again */
11034 filtered_count = 0;
11035 dn_count = 0;
11036 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11037 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11038 continue;
11039
11040 if (!peer->afc[afi][safi])
11041 continue;
11042
11043 if (!count) {
11044 unsigned long ents;
11045 char memstrbuf[MTYPE_MEMSTR_LEN];
11046 int64_t vrf_id_ui;
11047
11048 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11049 ? -1
11050 : (int64_t)bgp->vrf_id;
11051
11052 /* Usage summary and header */
11053 if (use_json) {
11054 json_object_string_addf(json, "routerId",
11055 "%pI4",
11056 &bgp->router_id);
11057 json_object_int_add(json, "as", bgp->as);
11058 json_object_int_add(json, "vrfId", vrf_id_ui);
11059 json_object_string_add(
11060 json, "vrfName",
11061 (bgp->inst_type
11062 == BGP_INSTANCE_TYPE_DEFAULT)
11063 ? VRF_DEFAULT_NAME
11064 : bgp->name);
11065 } else {
11066 vty_out(vty,
11067 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11068 &bgp->router_id, bgp->as,
11069 bgp->vrf_id == VRF_UNKNOWN
11070 ? -1
11071 : (int)bgp->vrf_id);
11072 vty_out(vty, "\n");
11073 }
11074
11075 if (bgp_update_delay_configured(bgp)) {
11076 if (use_json) {
11077 json_object_int_add(
11078 json, "updateDelayLimit",
11079 bgp->v_update_delay);
11080
11081 if (bgp->v_update_delay
11082 != bgp->v_establish_wait)
11083 json_object_int_add(
11084 json,
11085 "updateDelayEstablishWait",
11086 bgp->v_establish_wait);
11087
11088 if (bgp_update_delay_active(bgp)) {
11089 json_object_string_add(
11090 json,
11091 "updateDelayFirstNeighbor",
11092 bgp->update_delay_begin_time);
11093 json_object_boolean_true_add(
11094 json,
11095 "updateDelayInProgress");
11096 } else {
11097 if (bgp->update_delay_over) {
11098 json_object_string_add(
11099 json,
11100 "updateDelayFirstNeighbor",
11101 bgp->update_delay_begin_time);
11102 json_object_string_add(
11103 json,
11104 "updateDelayBestpathResumed",
11105 bgp->update_delay_end_time);
11106 json_object_string_add(
11107 json,
11108 "updateDelayZebraUpdateResume",
11109 bgp->update_delay_zebra_resume_time);
11110 json_object_string_add(
11111 json,
11112 "updateDelayPeerUpdateResume",
11113 bgp->update_delay_peers_resume_time);
11114 }
11115 }
11116 } else {
11117 vty_out(vty,
11118 "Read-only mode update-delay limit: %d seconds\n",
11119 bgp->v_update_delay);
11120 if (bgp->v_update_delay
11121 != bgp->v_establish_wait)
11122 vty_out(vty,
11123 " Establish wait: %d seconds\n",
11124 bgp->v_establish_wait);
11125
11126 if (bgp_update_delay_active(bgp)) {
11127 vty_out(vty,
11128 " First neighbor established: %s\n",
11129 bgp->update_delay_begin_time);
11130 vty_out(vty,
11131 " Delay in progress\n");
11132 } else {
11133 if (bgp->update_delay_over) {
11134 vty_out(vty,
11135 " First neighbor established: %s\n",
11136 bgp->update_delay_begin_time);
11137 vty_out(vty,
11138 " Best-paths resumed: %s\n",
11139 bgp->update_delay_end_time);
11140 vty_out(vty,
11141 " zebra update resumed: %s\n",
11142 bgp->update_delay_zebra_resume_time);
11143 vty_out(vty,
11144 " peers update resumed: %s\n",
11145 bgp->update_delay_peers_resume_time);
11146 }
11147 }
11148 }
11149 }
11150
11151 if (use_json) {
11152 if (bgp_maxmed_onstartup_configured(bgp)
11153 && bgp->maxmed_active)
11154 json_object_boolean_true_add(
11155 json, "maxMedOnStartup");
11156 if (bgp->v_maxmed_admin)
11157 json_object_boolean_true_add(
11158 json, "maxMedAdministrative");
11159
11160 json_object_int_add(
11161 json, "tableVersion",
11162 bgp_table_version(bgp->rib[afi][safi]));
11163
11164 ents = bgp_table_count(bgp->rib[afi][safi]);
11165 json_object_int_add(json, "ribCount", ents);
11166 json_object_int_add(
11167 json, "ribMemory",
11168 ents * sizeof(struct bgp_dest));
11169
11170 ents = bgp->af_peer_count[afi][safi];
11171 json_object_int_add(json, "peerCount", ents);
11172 json_object_int_add(json, "peerMemory",
11173 ents * sizeof(struct peer));
11174
11175 if ((ents = listcount(bgp->group))) {
11176 json_object_int_add(
11177 json, "peerGroupCount", ents);
11178 json_object_int_add(
11179 json, "peerGroupMemory",
11180 ents * sizeof(struct
11181 peer_group));
11182 }
11183
11184 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11185 BGP_CONFIG_DAMPENING))
11186 json_object_boolean_true_add(
11187 json, "dampeningEnabled");
11188 } else {
11189 if (!show_terse) {
11190 if (bgp_maxmed_onstartup_configured(bgp)
11191 && bgp->maxmed_active)
11192 vty_out(vty,
11193 "Max-med on-startup active\n");
11194 if (bgp->v_maxmed_admin)
11195 vty_out(vty,
11196 "Max-med administrative active\n");
11197
11198 vty_out(vty,
11199 "BGP table version %" PRIu64
11200 "\n",
11201 bgp_table_version(
11202 bgp->rib[afi][safi]));
11203
11204 ents = bgp_table_count(
11205 bgp->rib[afi][safi]);
11206 vty_out(vty,
11207 "RIB entries %ld, using %s of memory\n",
11208 ents,
11209 mtype_memstr(
11210 memstrbuf,
11211 sizeof(memstrbuf),
11212 ents
11213 * sizeof(
11214 struct
11215 bgp_dest)));
11216
11217 /* Peer related usage */
11218 ents = bgp->af_peer_count[afi][safi];
11219 vty_out(vty,
11220 "Peers %ld, using %s of memory\n",
11221 ents,
11222 mtype_memstr(
11223 memstrbuf,
11224 sizeof(memstrbuf),
11225 ents
11226 * sizeof(
11227 struct
11228 peer)));
11229
11230 if ((ents = listcount(bgp->group)))
11231 vty_out(vty,
11232 "Peer groups %ld, using %s of memory\n",
11233 ents,
11234 mtype_memstr(
11235 memstrbuf,
11236 sizeof(memstrbuf),
11237 ents
11238 * sizeof(
11239 struct
11240 peer_group)));
11241
11242 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11243 BGP_CONFIG_DAMPENING))
11244 vty_out(vty,
11245 "Dampening enabled.\n");
11246 }
11247 if (show_failed) {
11248 vty_out(vty, "\n");
11249
11250 /* Subtract 8 here because 'Neighbor' is
11251 * 8 characters */
11252 vty_out(vty, "Neighbor");
11253 vty_out(vty, "%*s",
11254 max_neighbor_width - 8, " ");
11255 vty_out(vty,
11256 BGP_SHOW_SUMMARY_HEADER_FAILED);
11257 }
11258 }
11259 }
11260
11261 paf = peer_af_find(peer, afi, safi);
11262 filter = &peer->filter[afi][safi];
11263
11264 count++;
11265 /* Works for both failed & successful cases */
11266 if (peer_dynamic_neighbor(peer))
11267 dn_count++;
11268
11269 if (use_json) {
11270 json_peer = NULL;
11271 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11272 as_type, as)) {
11273 filtered_count++;
11274 continue;
11275 }
11276 if (show_failed &&
11277 bgp_has_peer_failed(peer, afi, safi)) {
11278 json_peer = json_object_new_object();
11279 bgp_show_failed_summary(vty, bgp, peer,
11280 json_peer, 0, use_json);
11281 } else if (!show_failed) {
11282 if (show_established
11283 && bgp_has_peer_failed(peer, afi, safi)) {
11284 filtered_count++;
11285 continue;
11286 }
11287
11288 json_peer = json_object_new_object();
11289 if (peer_dynamic_neighbor(peer)) {
11290 json_object_boolean_true_add(json_peer,
11291 "dynamicPeer");
11292 }
11293
11294 if (peer->hostname)
11295 json_object_string_add(json_peer, "hostname",
11296 peer->hostname);
11297
11298 if (peer->domainname)
11299 json_object_string_add(json_peer, "domainname",
11300 peer->domainname);
11301
11302 json_object_int_add(json_peer, "remoteAs", peer->as);
11303 json_object_int_add(
11304 json_peer, "localAs",
11305 peer->change_local_as
11306 ? peer->change_local_as
11307 : peer->local_as);
11308 json_object_int_add(json_peer, "version", 4);
11309 json_object_int_add(json_peer, "msgRcvd",
11310 PEER_TOTAL_RX(peer));
11311 json_object_int_add(json_peer, "msgSent",
11312 PEER_TOTAL_TX(peer));
11313
11314 atomic_size_t outq_count, inq_count;
11315 outq_count = atomic_load_explicit(
11316 &peer->obuf->count,
11317 memory_order_relaxed);
11318 inq_count = atomic_load_explicit(
11319 &peer->ibuf->count,
11320 memory_order_relaxed);
11321
11322 json_object_int_add(json_peer, "tableVersion",
11323 peer->version[afi][safi]);
11324 json_object_int_add(json_peer, "outq",
11325 outq_count);
11326 json_object_int_add(json_peer, "inq",
11327 inq_count);
11328 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11329 use_json, json_peer);
11330
11331 json_object_int_add(json_peer, "pfxRcd",
11332 peer->pcount[afi][pfx_rcd_safi]);
11333
11334 if (paf && PAF_SUBGRP(paf))
11335 json_object_int_add(
11336 json_peer, "pfxSnt",
11337 (PAF_SUBGRP(paf))->scount);
11338 else
11339 json_object_int_add(json_peer, "pfxSnt",
11340 0);
11341
11342 /* BGP FSM state */
11343 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11344 || CHECK_FLAG(peer->bgp->flags,
11345 BGP_FLAG_SHUTDOWN))
11346 json_object_string_add(json_peer,
11347 "state",
11348 "Idle (Admin)");
11349 else if (peer->afc_recv[afi][safi])
11350 json_object_string_add(
11351 json_peer, "state",
11352 lookup_msg(bgp_status_msg,
11353 peer->status, NULL));
11354 else if (CHECK_FLAG(
11355 peer->sflags,
11356 PEER_STATUS_PREFIX_OVERFLOW))
11357 json_object_string_add(json_peer,
11358 "state",
11359 "Idle (PfxCt)");
11360 else
11361 json_object_string_add(
11362 json_peer, "state",
11363 lookup_msg(bgp_status_msg,
11364 peer->status, NULL));
11365
11366 /* BGP peer state */
11367 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11368 || CHECK_FLAG(peer->bgp->flags,
11369 BGP_FLAG_SHUTDOWN))
11370 json_object_string_add(json_peer,
11371 "peerState",
11372 "Admin");
11373 else if (CHECK_FLAG(
11374 peer->sflags,
11375 PEER_STATUS_PREFIX_OVERFLOW))
11376 json_object_string_add(json_peer,
11377 "peerState",
11378 "PfxCt");
11379 else if (CHECK_FLAG(peer->flags,
11380 PEER_FLAG_PASSIVE))
11381 json_object_string_add(json_peer,
11382 "peerState",
11383 "Passive");
11384 else if (CHECK_FLAG(peer->sflags,
11385 PEER_STATUS_NSF_WAIT))
11386 json_object_string_add(json_peer,
11387 "peerState",
11388 "NSF passive");
11389 else if (CHECK_FLAG(
11390 peer->bgp->flags,
11391 BGP_FLAG_EBGP_REQUIRES_POLICY)
11392 && (!bgp_inbound_policy_exists(peer,
11393 filter)
11394 || !bgp_outbound_policy_exists(
11395 peer, filter)))
11396 json_object_string_add(json_peer,
11397 "peerState",
11398 "Policy");
11399 else
11400 json_object_string_add(
11401 json_peer, "peerState", "OK");
11402
11403 json_object_int_add(json_peer, "connectionsEstablished",
11404 peer->established);
11405 json_object_int_add(json_peer, "connectionsDropped",
11406 peer->dropped);
11407 if (peer->desc)
11408 json_object_string_add(
11409 json_peer, "desc", peer->desc);
11410 }
11411 /* Avoid creating empty peer dicts in JSON */
11412 if (json_peer == NULL)
11413 continue;
11414
11415 if (peer->conf_if)
11416 json_object_string_add(json_peer, "idType",
11417 "interface");
11418 else if (peer->su.sa.sa_family == AF_INET)
11419 json_object_string_add(json_peer, "idType",
11420 "ipv4");
11421 else if (peer->su.sa.sa_family == AF_INET6)
11422 json_object_string_add(json_peer, "idType",
11423 "ipv6");
11424 json_object_object_add(json_peers, peer->host,
11425 json_peer);
11426 } else {
11427 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11428 as_type, as)) {
11429 filtered_count++;
11430 continue;
11431 }
11432 if (show_failed &&
11433 bgp_has_peer_failed(peer, afi, safi)) {
11434 bgp_show_failed_summary(vty, bgp, peer, NULL,
11435 max_neighbor_width,
11436 use_json);
11437 } else if (!show_failed) {
11438 if (show_established
11439 && bgp_has_peer_failed(peer, afi, safi)) {
11440 filtered_count++;
11441 continue;
11442 }
11443
11444 if ((count - filtered_count) == 1) {
11445 /* display headline before the first
11446 * neighbor line */
11447 vty_out(vty, "\n");
11448
11449 /* Subtract 8 here because 'Neighbor' is
11450 * 8 characters */
11451 vty_out(vty, "Neighbor");
11452 vty_out(vty, "%*s",
11453 max_neighbor_width - 8, " ");
11454 vty_out(vty,
11455 show_wide
11456 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11457 : BGP_SHOW_SUMMARY_HEADER_ALL);
11458 }
11459
11460 memset(dn_flag, '\0', sizeof(dn_flag));
11461 if (peer_dynamic_neighbor(peer)) {
11462 dn_flag[0] = '*';
11463 }
11464
11465 if (peer->hostname
11466 && CHECK_FLAG(bgp->flags,
11467 BGP_FLAG_SHOW_HOSTNAME))
11468 len = vty_out(vty, "%s%s(%s)", dn_flag,
11469 peer->hostname,
11470 peer->host);
11471 else
11472 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11473
11474 /* pad the neighbor column with spaces */
11475 if (len < max_neighbor_width)
11476 vty_out(vty, "%*s", max_neighbor_width - len,
11477 " ");
11478
11479 atomic_size_t outq_count, inq_count;
11480 outq_count = atomic_load_explicit(
11481 &peer->obuf->count,
11482 memory_order_relaxed);
11483 inq_count = atomic_load_explicit(
11484 &peer->ibuf->count,
11485 memory_order_relaxed);
11486
11487 if (show_wide)
11488 vty_out(vty,
11489 "4 %10u %10u %9u %9u %8" PRIu64
11490 " %4zu %4zu %8s",
11491 peer->as,
11492 peer->change_local_as
11493 ? peer->change_local_as
11494 : peer->local_as,
11495 PEER_TOTAL_RX(peer),
11496 PEER_TOTAL_TX(peer),
11497 peer->version[afi][safi],
11498 inq_count, outq_count,
11499 peer_uptime(peer->uptime,
11500 timebuf,
11501 BGP_UPTIME_LEN, 0,
11502 NULL));
11503 else
11504 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11505 " %4zu %4zu %8s",
11506 peer->as, PEER_TOTAL_RX(peer),
11507 PEER_TOTAL_TX(peer),
11508 peer->version[afi][safi],
11509 inq_count, outq_count,
11510 peer_uptime(peer->uptime,
11511 timebuf,
11512 BGP_UPTIME_LEN, 0,
11513 NULL));
11514
11515 if (peer_established(peer)) {
11516 if (peer->afc_recv[afi][safi]) {
11517 if (CHECK_FLAG(
11518 bgp->flags,
11519 BGP_FLAG_EBGP_REQUIRES_POLICY)
11520 && !bgp_inbound_policy_exists(
11521 peer, filter))
11522 vty_out(vty, " %12s",
11523 "(Policy)");
11524 else
11525 vty_out(vty,
11526 " %12u",
11527 peer->pcount
11528 [afi]
11529 [pfx_rcd_safi]);
11530 } else {
11531 vty_out(vty, " NoNeg");
11532 }
11533
11534 if (paf && PAF_SUBGRP(paf)) {
11535 if (CHECK_FLAG(
11536 bgp->flags,
11537 BGP_FLAG_EBGP_REQUIRES_POLICY)
11538 && !bgp_outbound_policy_exists(
11539 peer, filter))
11540 vty_out(vty, " %8s",
11541 "(Policy)");
11542 else
11543 vty_out(vty,
11544 " %8u",
11545 (PAF_SUBGRP(
11546 paf))
11547 ->scount);
11548 } else {
11549 vty_out(vty, " NoNeg");
11550 }
11551 } else {
11552 if (CHECK_FLAG(peer->flags,
11553 PEER_FLAG_SHUTDOWN)
11554 || CHECK_FLAG(peer->bgp->flags,
11555 BGP_FLAG_SHUTDOWN))
11556 vty_out(vty, " Idle (Admin)");
11557 else if (CHECK_FLAG(
11558 peer->sflags,
11559 PEER_STATUS_PREFIX_OVERFLOW))
11560 vty_out(vty, " Idle (PfxCt)");
11561 else
11562 vty_out(vty, " %12s",
11563 lookup_msg(bgp_status_msg,
11564 peer->status, NULL));
11565
11566 vty_out(vty, " %8u", 0);
11567 }
11568 /* Make sure `Desc` column is the lastest in
11569 * the output.
11570 */
11571 if (peer->desc)
11572 vty_out(vty, " %s",
11573 bgp_peer_description_stripped(
11574 peer->desc,
11575 show_wide ? 64 : 20));
11576 else
11577 vty_out(vty, " N/A");
11578 vty_out(vty, "\n");
11579 }
11580
11581 }
11582 }
11583
11584 if (use_json) {
11585 json_object_object_add(json, "peers", json_peers);
11586 json_object_int_add(json, "failedPeers", failed_count);
11587 json_object_int_add(json, "displayedPeers",
11588 count - filtered_count);
11589 json_object_int_add(json, "totalPeers", count);
11590 json_object_int_add(json, "dynamicPeers", dn_count);
11591
11592 if (!show_failed)
11593 bgp_show_bestpath_json(bgp, json);
11594
11595 vty_json(vty, json);
11596 } else {
11597 if (count) {
11598 if (filtered_count == count)
11599 vty_out(vty, "\n%% No matching neighbor\n");
11600 else {
11601 if (show_failed)
11602 vty_out(vty, "\nDisplayed neighbors %d",
11603 failed_count);
11604 else if (as_type != AS_UNSPECIFIED || as
11605 || fpeer || show_established)
11606 vty_out(vty, "\nDisplayed neighbors %d",
11607 count - filtered_count);
11608
11609 vty_out(vty, "\nTotal number of neighbors %d\n",
11610 count);
11611 }
11612 } else {
11613 vty_out(vty, "No %s neighbor is configured\n",
11614 get_afi_safi_str(afi, safi, false));
11615 }
11616
11617 if (dn_count) {
11618 vty_out(vty, "* - dynamic neighbor\n");
11619 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11620 dn_count, bgp->dynamic_neighbors_limit);
11621 }
11622 }
11623
11624 return CMD_SUCCESS;
11625 }
11626
11627 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11628 int safi, struct peer *fpeer, int as_type,
11629 as_t as, uint16_t show_flags)
11630 {
11631 int is_first = 1;
11632 int afi_wildcard = (afi == AFI_MAX);
11633 int safi_wildcard = (safi == SAFI_MAX);
11634 int is_wildcard = (afi_wildcard || safi_wildcard);
11635 bool nbr_output = false;
11636 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11637
11638 if (use_json && is_wildcard)
11639 vty_out(vty, "{\n");
11640 if (afi_wildcard)
11641 afi = 1; /* AFI_IP */
11642 while (afi < AFI_MAX) {
11643 if (safi_wildcard)
11644 safi = 1; /* SAFI_UNICAST */
11645 while (safi < SAFI_MAX) {
11646 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11647 nbr_output = true;
11648
11649 if (is_wildcard) {
11650 /*
11651 * So limit output to those afi/safi
11652 * pairs that
11653 * actualy have something interesting in
11654 * them
11655 */
11656 if (use_json) {
11657 if (!is_first)
11658 vty_out(vty, ",\n");
11659 else
11660 is_first = 0;
11661
11662 vty_out(vty, "\"%s\":",
11663 get_afi_safi_str(afi,
11664 safi,
11665 true));
11666 } else {
11667 vty_out(vty,
11668 "\n%s Summary (%s):\n",
11669 get_afi_safi_str(afi,
11670 safi,
11671 false),
11672 bgp->name_pretty);
11673 }
11674 }
11675 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11676 as_type, as, show_flags);
11677 }
11678 safi++;
11679 if (!safi_wildcard)
11680 safi = SAFI_MAX;
11681 }
11682 afi++;
11683 if (!afi_wildcard)
11684 afi = AFI_MAX;
11685 }
11686
11687 if (use_json && is_wildcard)
11688 vty_out(vty, "}\n");
11689 else if (!nbr_output) {
11690 if (use_json)
11691 vty_out(vty, "{}\n");
11692 else
11693 vty_out(vty, "%% No BGP neighbors found in %s\n",
11694 bgp->name_pretty);
11695 }
11696 }
11697
11698 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11699 safi_t safi,
11700 const char *neighbor,
11701 int as_type, as_t as,
11702 uint16_t show_flags)
11703 {
11704 struct listnode *node, *nnode;
11705 struct bgp *bgp;
11706 struct peer *fpeer = NULL;
11707 int is_first = 1;
11708 bool nbr_output = false;
11709 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11710
11711 if (use_json)
11712 vty_out(vty, "{\n");
11713
11714 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11715 nbr_output = true;
11716 if (use_json) {
11717 if (!is_first)
11718 vty_out(vty, ",\n");
11719 else
11720 is_first = 0;
11721
11722 vty_out(vty, "\"%s\":",
11723 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11724 ? VRF_DEFAULT_NAME
11725 : bgp->name);
11726 }
11727 if (neighbor) {
11728 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11729 use_json);
11730 if (!fpeer)
11731 continue;
11732 }
11733 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11734 as, show_flags);
11735 }
11736
11737 if (use_json)
11738 vty_out(vty, "}\n");
11739 else if (!nbr_output)
11740 vty_out(vty, "%% BGP instance not found\n");
11741 }
11742
11743 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11744 safi_t safi, const char *neighbor, int as_type,
11745 as_t as, uint16_t show_flags)
11746 {
11747 struct bgp *bgp;
11748 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11749 struct peer *fpeer = NULL;
11750
11751 if (name) {
11752 if (strmatch(name, "all")) {
11753 bgp_show_all_instances_summary_vty(vty, afi, safi,
11754 neighbor, as_type,
11755 as, show_flags);
11756 return CMD_SUCCESS;
11757 } else {
11758 bgp = bgp_lookup_by_name(name);
11759
11760 if (!bgp) {
11761 if (use_json)
11762 vty_out(vty, "{}\n");
11763 else
11764 vty_out(vty,
11765 "%% BGP instance not found\n");
11766 return CMD_WARNING;
11767 }
11768
11769 if (neighbor) {
11770 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11771 use_json);
11772 if (!fpeer)
11773 return CMD_WARNING;
11774 }
11775 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11776 as_type, as, show_flags);
11777 return CMD_SUCCESS;
11778 }
11779 }
11780
11781 bgp = bgp_get_default();
11782
11783 if (bgp) {
11784 if (neighbor) {
11785 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11786 use_json);
11787 if (!fpeer)
11788 return CMD_WARNING;
11789 }
11790 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11791 as, show_flags);
11792 } else {
11793 if (use_json)
11794 vty_out(vty, "{}\n");
11795 else
11796 vty_out(vty, "%% BGP instance not found\n");
11797 return CMD_WARNING;
11798 }
11799
11800 return CMD_SUCCESS;
11801 }
11802
11803 /* `show [ip] bgp summary' commands. */
11804 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11805 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11806 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11807 "]] [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]",
11808 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11809 BGP_SAFI_WITH_LABEL_HELP_STR
11810 "Display the entries for all address families\n"
11811 "Summary of BGP neighbor status\n"
11812 "Show only sessions in Established state\n"
11813 "Show only sessions not in Established state\n"
11814 "Show only the specified neighbor session\n"
11815 "Neighbor to display information about\n"
11816 "Neighbor to display information about\n"
11817 "Neighbor on BGP configured interface\n"
11818 "Show only the specified remote AS sessions\n"
11819 "AS number\n"
11820 "Internal (iBGP) AS sessions\n"
11821 "External (eBGP) AS sessions\n"
11822 "Shorten the information on BGP instances\n"
11823 "Increase table width for longer output\n" JSON_STR)
11824 {
11825 char *vrf = NULL;
11826 afi_t afi = AFI_MAX;
11827 safi_t safi = SAFI_MAX;
11828 as_t as = 0; /* 0 means AS filter not set */
11829 int as_type = AS_UNSPECIFIED;
11830 uint16_t show_flags = 0;
11831
11832 int idx = 0;
11833
11834 /* show [ip] bgp */
11835 if (!all && argv_find(argv, argc, "ip", &idx))
11836 afi = AFI_IP;
11837 /* [<vrf> VIEWVRFNAME] */
11838 if (argv_find(argv, argc, "vrf", &idx)) {
11839 vrf = argv[idx + 1]->arg;
11840 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11841 vrf = NULL;
11842 } else if (argv_find(argv, argc, "view", &idx))
11843 /* [<view> VIEWVRFNAME] */
11844 vrf = argv[idx + 1]->arg;
11845 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11846 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11847 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11848 }
11849
11850 if (argv_find(argv, argc, "failed", &idx))
11851 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11852
11853 if (argv_find(argv, argc, "established", &idx))
11854 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11855
11856 if (argv_find(argv, argc, "remote-as", &idx)) {
11857 if (argv[idx + 1]->arg[0] == 'i')
11858 as_type = AS_INTERNAL;
11859 else if (argv[idx + 1]->arg[0] == 'e')
11860 as_type = AS_EXTERNAL;
11861 else
11862 as = (as_t)atoi(argv[idx + 1]->arg);
11863 }
11864
11865 if (argv_find(argv, argc, "terse", &idx))
11866 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11867
11868 if (argv_find(argv, argc, "wide", &idx))
11869 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11870
11871 if (argv_find(argv, argc, "json", &idx))
11872 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11873
11874 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11875 show_flags);
11876 }
11877
11878 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11879 {
11880 if (for_json)
11881 return get_afi_safi_json_str(afi, safi);
11882 else
11883 return get_afi_safi_vty_str(afi, safi);
11884 }
11885
11886
11887 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11888 afi_t afi, safi_t safi,
11889 uint16_t adv_smcap, uint16_t adv_rmcap,
11890 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11891 bool use_json, json_object *json_pref)
11892 {
11893 /* Send-Mode */
11894 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11895 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11896 if (use_json) {
11897 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11898 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11899 json_object_string_add(json_pref, "sendMode",
11900 "advertisedAndReceived");
11901 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11902 json_object_string_add(json_pref, "sendMode",
11903 "advertised");
11904 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11905 json_object_string_add(json_pref, "sendMode",
11906 "received");
11907 } else {
11908 vty_out(vty, " Send-mode: ");
11909 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11910 vty_out(vty, "advertised");
11911 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11912 vty_out(vty, "%sreceived",
11913 CHECK_FLAG(p->af_cap[afi][safi],
11914 adv_smcap)
11915 ? ", "
11916 : "");
11917 vty_out(vty, "\n");
11918 }
11919 }
11920
11921 /* Receive-Mode */
11922 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11923 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11924 if (use_json) {
11925 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11926 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11927 json_object_string_add(json_pref, "recvMode",
11928 "advertisedAndReceived");
11929 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11930 json_object_string_add(json_pref, "recvMode",
11931 "advertised");
11932 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11933 json_object_string_add(json_pref, "recvMode",
11934 "received");
11935 } else {
11936 vty_out(vty, " Receive-mode: ");
11937 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11938 vty_out(vty, "advertised");
11939 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11940 vty_out(vty, "%sreceived",
11941 CHECK_FLAG(p->af_cap[afi][safi],
11942 adv_rmcap)
11943 ? ", "
11944 : "");
11945 vty_out(vty, "\n");
11946 }
11947 }
11948 }
11949
11950 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11951 struct peer *p,
11952 json_object *json)
11953 {
11954 bool rbit = false;
11955 bool nbit = false;
11956
11957 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11958 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11959 && (peer_established(p))) {
11960 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11961 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11962 }
11963
11964 if (json) {
11965 json_object_boolean_add(json, "rBit", rbit);
11966 json_object_boolean_add(json, "nBit", nbit);
11967 } else {
11968 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11969 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11970 }
11971 }
11972
11973 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11974 struct peer *peer,
11975 json_object *json)
11976 {
11977 const char *mode = "NotApplicable";
11978
11979 if (!json)
11980 vty_out(vty, "\n Remote GR Mode: ");
11981
11982 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11983 && (peer_established(peer))) {
11984
11985 if ((peer->nsf_af_count == 0)
11986 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11987
11988 mode = "Disable";
11989
11990 } else if (peer->nsf_af_count == 0
11991 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11992
11993 mode = "Helper";
11994
11995 } else if (peer->nsf_af_count != 0
11996 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11997
11998 mode = "Restart";
11999 }
12000 }
12001
12002 if (json)
12003 json_object_string_add(json, "remoteGrMode", mode);
12004 else
12005 vty_out(vty, mode, "\n");
12006 }
12007
12008 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12009 struct peer *p,
12010 json_object *json)
12011 {
12012 const char *mode = "Invalid";
12013
12014 if (!json)
12015 vty_out(vty, " Local GR Mode: ");
12016
12017 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12018 mode = "Helper";
12019 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12020 mode = "Restart";
12021 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12022 mode = "Disable";
12023 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12024 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12025 mode = "Helper*";
12026 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12027 mode = "Restart*";
12028 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12029 mode = "Disable*";
12030 else
12031 mode = "Invalid*";
12032 }
12033
12034 if (json)
12035 json_object_string_add(json, "localGrMode", mode);
12036 else
12037 vty_out(vty, mode, "\n");
12038 }
12039
12040 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12041 struct vty *vty, struct peer *peer, json_object *json)
12042 {
12043 afi_t afi;
12044 safi_t safi;
12045 json_object *json_afi_safi = NULL;
12046 json_object *json_timer = NULL;
12047 json_object *json_endofrib_status = NULL;
12048 bool eor_flag = false;
12049
12050 FOREACH_AFI_SAFI_NSF (afi, safi) {
12051 if (!peer->afc[afi][safi])
12052 continue;
12053
12054 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12055 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12056 continue;
12057
12058 if (json) {
12059 json_afi_safi = json_object_new_object();
12060 json_endofrib_status = json_object_new_object();
12061 json_timer = json_object_new_object();
12062 }
12063
12064 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12065 eor_flag = true;
12066 else
12067 eor_flag = false;
12068
12069 if (!json) {
12070 vty_out(vty, " %s:\n",
12071 get_afi_safi_str(afi, safi, false));
12072
12073 vty_out(vty, " F bit: ");
12074 }
12075
12076 if (peer->nsf[afi][safi] &&
12077 CHECK_FLAG(peer->af_cap[afi][safi],
12078 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12079
12080 if (json) {
12081 json_object_boolean_true_add(json_afi_safi,
12082 "fBit");
12083 } else
12084 vty_out(vty, "True\n");
12085 } else {
12086 if (json)
12087 json_object_boolean_false_add(json_afi_safi,
12088 "fBit");
12089 else
12090 vty_out(vty, "False\n");
12091 }
12092
12093 if (!json)
12094 vty_out(vty, " End-of-RIB sent: ");
12095
12096 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12097 PEER_STATUS_EOR_SEND)) {
12098 if (json) {
12099 json_object_boolean_true_add(
12100 json_endofrib_status, "endOfRibSend");
12101
12102 PRINT_EOR_JSON(eor_flag);
12103 } else {
12104 vty_out(vty, "Yes\n");
12105 vty_out(vty,
12106 " End-of-RIB sent after update: ");
12107
12108 PRINT_EOR(eor_flag);
12109 }
12110 } else {
12111 if (json) {
12112 json_object_boolean_false_add(
12113 json_endofrib_status, "endOfRibSend");
12114 json_object_boolean_false_add(
12115 json_endofrib_status,
12116 "endOfRibSentAfterUpdate");
12117 } else {
12118 vty_out(vty, "No\n");
12119 vty_out(vty,
12120 " End-of-RIB sent after update: ");
12121 vty_out(vty, "No\n");
12122 }
12123 }
12124
12125 if (!json)
12126 vty_out(vty, " End-of-RIB received: ");
12127
12128 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12129 PEER_STATUS_EOR_RECEIVED)) {
12130 if (json)
12131 json_object_boolean_true_add(
12132 json_endofrib_status, "endOfRibRecv");
12133 else
12134 vty_out(vty, "Yes\n");
12135 } else {
12136 if (json)
12137 json_object_boolean_false_add(
12138 json_endofrib_status, "endOfRibRecv");
12139 else
12140 vty_out(vty, "No\n");
12141 }
12142
12143 if (json) {
12144 json_object_int_add(json_timer, "stalePathTimer",
12145 peer->bgp->stalepath_time);
12146
12147 if (peer->t_gr_stale != NULL) {
12148 json_object_int_add(json_timer,
12149 "stalePathTimerRemaining",
12150 thread_timer_remain_second(
12151 peer->t_gr_stale));
12152 }
12153
12154 /* Display Configured Selection
12155 * Deferral only when when
12156 * Gr mode is enabled.
12157 */
12158 if (CHECK_FLAG(peer->flags,
12159 PEER_FLAG_GRACEFUL_RESTART)) {
12160 json_object_int_add(json_timer,
12161 "selectionDeferralTimer",
12162 peer->bgp->stalepath_time);
12163 }
12164
12165 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12166 NULL) {
12167
12168 json_object_int_add(
12169 json_timer,
12170 "selectionDeferralTimerRemaining",
12171 thread_timer_remain_second(
12172 peer->bgp->gr_info[afi][safi]
12173 .t_select_deferral));
12174 }
12175 } else {
12176 vty_out(vty, " Timers:\n");
12177 vty_out(vty,
12178 " Configured Stale Path Time(sec): %u\n",
12179 peer->bgp->stalepath_time);
12180
12181 if (peer->t_gr_stale != NULL)
12182 vty_out(vty,
12183 " Stale Path Remaining(sec): %ld\n",
12184 thread_timer_remain_second(
12185 peer->t_gr_stale));
12186 /* Display Configured Selection
12187 * Deferral only when when
12188 * Gr mode is enabled.
12189 */
12190 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12191 vty_out(vty,
12192 " Configured Selection Deferral Time(sec): %u\n",
12193 peer->bgp->select_defer_time);
12194
12195 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12196 NULL)
12197 vty_out(vty,
12198 " Selection Deferral Time Remaining(sec): %ld\n",
12199 thread_timer_remain_second(
12200 peer->bgp->gr_info[afi][safi]
12201 .t_select_deferral));
12202 }
12203 if (json) {
12204 json_object_object_add(json_afi_safi, "endOfRibStatus",
12205 json_endofrib_status);
12206 json_object_object_add(json_afi_safi, "timers",
12207 json_timer);
12208 json_object_object_add(
12209 json, get_afi_safi_str(afi, safi, true),
12210 json_afi_safi);
12211 }
12212 }
12213 }
12214
12215 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12216 struct peer *p,
12217 json_object *json)
12218 {
12219 if (json) {
12220 json_object *json_timer = NULL;
12221
12222 json_timer = json_object_new_object();
12223
12224 json_object_int_add(json_timer, "configuredRestartTimer",
12225 p->bgp->restart_time);
12226
12227 json_object_int_add(json_timer, "receivedRestartTimer",
12228 p->v_gr_restart);
12229
12230 if (p->t_gr_restart != NULL)
12231 json_object_int_add(
12232 json_timer, "restartTimerRemaining",
12233 thread_timer_remain_second(p->t_gr_restart));
12234
12235 json_object_object_add(json, "timers", json_timer);
12236 } else {
12237
12238 vty_out(vty, " Timers:\n");
12239 vty_out(vty, " Configured Restart Time(sec): %u\n",
12240 p->bgp->restart_time);
12241
12242 vty_out(vty, " Received Restart Time(sec): %u\n",
12243 p->v_gr_restart);
12244 if (p->t_gr_restart != NULL)
12245 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12246 thread_timer_remain_second(p->t_gr_restart));
12247 if (p->t_gr_restart != NULL) {
12248 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12249 thread_timer_remain_second(p->t_gr_restart));
12250 }
12251 }
12252 }
12253
12254 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12255 json_object *json)
12256 {
12257 char dn_flag[2] = {0};
12258 /* '*' + v6 address of neighbor */
12259 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12260
12261 if (!p->conf_if && peer_dynamic_neighbor(p))
12262 dn_flag[0] = '*';
12263
12264 if (p->conf_if) {
12265 if (json)
12266 json_object_string_addf(json, "neighborAddr", "%pSU",
12267 &p->su);
12268 else
12269 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12270 &p->su);
12271 } else {
12272 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12273 p->host);
12274
12275 if (json)
12276 json_object_string_add(json, "neighborAddr",
12277 neighborAddr);
12278 else
12279 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12280 }
12281
12282 /* more gr info in new format */
12283 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12284 }
12285
12286 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12287 safi_t safi, bool use_json,
12288 json_object *json_neigh)
12289 {
12290 struct bgp_filter *filter;
12291 struct peer_af *paf;
12292 char orf_pfx_name[BUFSIZ];
12293 int orf_pfx_count;
12294 json_object *json_af = NULL;
12295 json_object *json_prefA = NULL;
12296 json_object *json_prefB = NULL;
12297 json_object *json_addr = NULL;
12298 json_object *json_advmap = NULL;
12299
12300 if (use_json) {
12301 json_addr = json_object_new_object();
12302 json_af = json_object_new_object();
12303 filter = &p->filter[afi][safi];
12304
12305 if (peer_group_active(p))
12306 json_object_string_add(json_addr, "peerGroupMember",
12307 p->group->name);
12308
12309 paf = peer_af_find(p, afi, safi);
12310 if (paf && PAF_SUBGRP(paf)) {
12311 json_object_int_add(json_addr, "updateGroupId",
12312 PAF_UPDGRP(paf)->id);
12313 json_object_int_add(json_addr, "subGroupId",
12314 PAF_SUBGRP(paf)->id);
12315 json_object_int_add(json_addr, "packetQueueLength",
12316 bpacket_queue_virtual_length(paf));
12317 }
12318
12319 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12320 || CHECK_FLAG(p->af_cap[afi][safi],
12321 PEER_CAP_ORF_PREFIX_SM_RCV)
12322 || CHECK_FLAG(p->af_cap[afi][safi],
12323 PEER_CAP_ORF_PREFIX_RM_ADV)
12324 || CHECK_FLAG(p->af_cap[afi][safi],
12325 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12326 json_object_int_add(json_af, "orfType",
12327 ORF_TYPE_PREFIX);
12328 json_prefA = json_object_new_object();
12329 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12330 PEER_CAP_ORF_PREFIX_SM_ADV,
12331 PEER_CAP_ORF_PREFIX_RM_ADV,
12332 PEER_CAP_ORF_PREFIX_SM_RCV,
12333 PEER_CAP_ORF_PREFIX_RM_RCV,
12334 use_json, json_prefA);
12335 json_object_object_add(json_af, "orfPrefixList",
12336 json_prefA);
12337 }
12338
12339 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12340 || CHECK_FLAG(p->af_cap[afi][safi],
12341 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12342 || CHECK_FLAG(p->af_cap[afi][safi],
12343 PEER_CAP_ORF_PREFIX_RM_ADV)
12344 || CHECK_FLAG(p->af_cap[afi][safi],
12345 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12346 json_object_int_add(json_af, "orfOldType",
12347 ORF_TYPE_PREFIX_OLD);
12348 json_prefB = json_object_new_object();
12349 bgp_show_peer_afi_orf_cap(
12350 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12351 PEER_CAP_ORF_PREFIX_RM_ADV,
12352 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12353 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12354 json_prefB);
12355 json_object_object_add(json_af, "orfOldPrefixList",
12356 json_prefB);
12357 }
12358
12359 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12360 || CHECK_FLAG(p->af_cap[afi][safi],
12361 PEER_CAP_ORF_PREFIX_SM_RCV)
12362 || CHECK_FLAG(p->af_cap[afi][safi],
12363 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12364 || CHECK_FLAG(p->af_cap[afi][safi],
12365 PEER_CAP_ORF_PREFIX_RM_ADV)
12366 || CHECK_FLAG(p->af_cap[afi][safi],
12367 PEER_CAP_ORF_PREFIX_RM_RCV)
12368 || CHECK_FLAG(p->af_cap[afi][safi],
12369 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12370 json_object_object_add(json_addr, "afDependentCap",
12371 json_af);
12372 else
12373 json_object_free(json_af);
12374
12375 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12376 p->host, afi, safi);
12377 orf_pfx_count = prefix_bgp_show_prefix_list(
12378 NULL, afi, orf_pfx_name, use_json);
12379
12380 if (CHECK_FLAG(p->af_sflags[afi][safi],
12381 PEER_STATUS_ORF_PREFIX_SEND)
12382 || orf_pfx_count) {
12383 if (CHECK_FLAG(p->af_sflags[afi][safi],
12384 PEER_STATUS_ORF_PREFIX_SEND))
12385 json_object_boolean_true_add(json_neigh,
12386 "orfSent");
12387 if (orf_pfx_count)
12388 json_object_int_add(json_addr, "orfRecvCounter",
12389 orf_pfx_count);
12390 }
12391 if (CHECK_FLAG(p->af_sflags[afi][safi],
12392 PEER_STATUS_ORF_WAIT_REFRESH))
12393 json_object_string_add(
12394 json_addr, "orfFirstUpdate",
12395 "deferredUntilORFOrRouteRefreshRecvd");
12396
12397 if (CHECK_FLAG(p->af_flags[afi][safi],
12398 PEER_FLAG_REFLECTOR_CLIENT))
12399 json_object_boolean_true_add(json_addr,
12400 "routeReflectorClient");
12401 if (CHECK_FLAG(p->af_flags[afi][safi],
12402 PEER_FLAG_RSERVER_CLIENT))
12403 json_object_boolean_true_add(json_addr,
12404 "routeServerClient");
12405 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12406 json_object_boolean_true_add(json_addr,
12407 "inboundSoftConfigPermit");
12408
12409 if (CHECK_FLAG(p->af_flags[afi][safi],
12410 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12411 json_object_boolean_true_add(
12412 json_addr,
12413 "privateAsNumsAllReplacedInUpdatesToNbr");
12414 else if (CHECK_FLAG(p->af_flags[afi][safi],
12415 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12416 json_object_boolean_true_add(
12417 json_addr,
12418 "privateAsNumsReplacedInUpdatesToNbr");
12419 else if (CHECK_FLAG(p->af_flags[afi][safi],
12420 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12421 json_object_boolean_true_add(
12422 json_addr,
12423 "privateAsNumsAllRemovedInUpdatesToNbr");
12424 else if (CHECK_FLAG(p->af_flags[afi][safi],
12425 PEER_FLAG_REMOVE_PRIVATE_AS))
12426 json_object_boolean_true_add(
12427 json_addr,
12428 "privateAsNumsRemovedInUpdatesToNbr");
12429
12430 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12431 if (CHECK_FLAG(p->af_flags[afi][safi],
12432 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12433 json_object_boolean_true_add(json_addr,
12434 "allowAsInOrigin");
12435 else
12436 json_object_int_add(json_addr, "allowAsInCount",
12437 p->allowas_in[afi][safi]);
12438 }
12439
12440 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12441 json_object_boolean_true_add(
12442 json_addr,
12443 bgp_addpath_names(p->addpath_type[afi][safi])
12444 ->type_json_name);
12445
12446 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12447 json_object_string_add(json_addr,
12448 "overrideASNsInOutboundUpdates",
12449 "ifAspathEqualRemoteAs");
12450
12451 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12452 || CHECK_FLAG(p->af_flags[afi][safi],
12453 PEER_FLAG_FORCE_NEXTHOP_SELF))
12454 json_object_boolean_true_add(json_addr,
12455 "routerAlwaysNextHop");
12456 if (CHECK_FLAG(p->af_flags[afi][safi],
12457 PEER_FLAG_AS_PATH_UNCHANGED))
12458 json_object_boolean_true_add(
12459 json_addr, "unchangedAsPathPropogatedToNbr");
12460 if (CHECK_FLAG(p->af_flags[afi][safi],
12461 PEER_FLAG_NEXTHOP_UNCHANGED))
12462 json_object_boolean_true_add(
12463 json_addr, "unchangedNextHopPropogatedToNbr");
12464 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12465 json_object_boolean_true_add(
12466 json_addr, "unchangedMedPropogatedToNbr");
12467 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12468 || CHECK_FLAG(p->af_flags[afi][safi],
12469 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12470 if (CHECK_FLAG(p->af_flags[afi][safi],
12471 PEER_FLAG_SEND_COMMUNITY)
12472 && CHECK_FLAG(p->af_flags[afi][safi],
12473 PEER_FLAG_SEND_EXT_COMMUNITY))
12474 json_object_string_add(json_addr,
12475 "commAttriSentToNbr",
12476 "extendedAndStandard");
12477 else if (CHECK_FLAG(p->af_flags[afi][safi],
12478 PEER_FLAG_SEND_EXT_COMMUNITY))
12479 json_object_string_add(json_addr,
12480 "commAttriSentToNbr",
12481 "extended");
12482 else
12483 json_object_string_add(json_addr,
12484 "commAttriSentToNbr",
12485 "standard");
12486 }
12487 if (CHECK_FLAG(p->af_flags[afi][safi],
12488 PEER_FLAG_DEFAULT_ORIGINATE)) {
12489 if (p->default_rmap[afi][safi].name)
12490 json_object_string_add(
12491 json_addr, "defaultRouteMap",
12492 p->default_rmap[afi][safi].name);
12493
12494 if (paf && PAF_SUBGRP(paf)
12495 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12496 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12497 json_object_boolean_true_add(json_addr,
12498 "defaultSent");
12499 else
12500 json_object_boolean_true_add(json_addr,
12501 "defaultNotSent");
12502 }
12503
12504 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12505 if (is_evpn_enabled())
12506 json_object_boolean_true_add(
12507 json_addr, "advertiseAllVnis");
12508 }
12509
12510 if (filter->plist[FILTER_IN].name
12511 || filter->dlist[FILTER_IN].name
12512 || filter->aslist[FILTER_IN].name
12513 || filter->map[RMAP_IN].name)
12514 json_object_boolean_true_add(json_addr,
12515 "inboundPathPolicyConfig");
12516 if (filter->plist[FILTER_OUT].name
12517 || filter->dlist[FILTER_OUT].name
12518 || filter->aslist[FILTER_OUT].name
12519 || filter->map[RMAP_OUT].name || filter->usmap.name)
12520 json_object_boolean_true_add(
12521 json_addr, "outboundPathPolicyConfig");
12522
12523 /* prefix-list */
12524 if (filter->plist[FILTER_IN].name)
12525 json_object_string_add(json_addr,
12526 "incomingUpdatePrefixFilterList",
12527 filter->plist[FILTER_IN].name);
12528 if (filter->plist[FILTER_OUT].name)
12529 json_object_string_add(json_addr,
12530 "outgoingUpdatePrefixFilterList",
12531 filter->plist[FILTER_OUT].name);
12532
12533 /* distribute-list */
12534 if (filter->dlist[FILTER_IN].name)
12535 json_object_string_add(
12536 json_addr, "incomingUpdateNetworkFilterList",
12537 filter->dlist[FILTER_IN].name);
12538 if (filter->dlist[FILTER_OUT].name)
12539 json_object_string_add(
12540 json_addr, "outgoingUpdateNetworkFilterList",
12541 filter->dlist[FILTER_OUT].name);
12542
12543 /* filter-list. */
12544 if (filter->aslist[FILTER_IN].name)
12545 json_object_string_add(json_addr,
12546 "incomingUpdateAsPathFilterList",
12547 filter->aslist[FILTER_IN].name);
12548 if (filter->aslist[FILTER_OUT].name)
12549 json_object_string_add(json_addr,
12550 "outgoingUpdateAsPathFilterList",
12551 filter->aslist[FILTER_OUT].name);
12552
12553 /* route-map. */
12554 if (filter->map[RMAP_IN].name)
12555 json_object_string_add(
12556 json_addr, "routeMapForIncomingAdvertisements",
12557 filter->map[RMAP_IN].name);
12558 if (filter->map[RMAP_OUT].name)
12559 json_object_string_add(
12560 json_addr, "routeMapForOutgoingAdvertisements",
12561 filter->map[RMAP_OUT].name);
12562
12563 /* ebgp-requires-policy (inbound) */
12564 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12565 && !bgp_inbound_policy_exists(p, filter))
12566 json_object_string_add(
12567 json_addr, "inboundEbgpRequiresPolicy",
12568 "Inbound updates discarded due to missing policy");
12569
12570 /* ebgp-requires-policy (outbound) */
12571 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12572 && (!bgp_outbound_policy_exists(p, filter)))
12573 json_object_string_add(
12574 json_addr, "outboundEbgpRequiresPolicy",
12575 "Outbound updates discarded due to missing policy");
12576
12577 /* unsuppress-map */
12578 if (filter->usmap.name)
12579 json_object_string_add(json_addr,
12580 "selectiveUnsuppressRouteMap",
12581 filter->usmap.name);
12582
12583 /* advertise-map */
12584 if (filter->advmap.aname) {
12585 json_advmap = json_object_new_object();
12586 json_object_string_add(json_advmap, "condition",
12587 filter->advmap.condition
12588 ? "EXIST"
12589 : "NON_EXIST");
12590 json_object_string_add(json_advmap, "conditionMap",
12591 filter->advmap.cname);
12592 json_object_string_add(json_advmap, "advertiseMap",
12593 filter->advmap.aname);
12594 json_object_string_add(
12595 json_advmap, "advertiseStatus",
12596 filter->advmap.update_type ==
12597 UPDATE_TYPE_ADVERTISE
12598 ? "Advertise"
12599 : "Withdraw");
12600 json_object_object_add(json_addr, "advertiseMap",
12601 json_advmap);
12602 }
12603
12604 /* Receive prefix count */
12605 json_object_int_add(json_addr, "acceptedPrefixCounter",
12606 p->pcount[afi][safi]);
12607 if (paf && PAF_SUBGRP(paf))
12608 json_object_int_add(json_addr, "sentPrefixCounter",
12609 (PAF_SUBGRP(paf))->scount);
12610
12611 /* Maximum prefix */
12612 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12613 json_object_int_add(json_addr, "prefixOutAllowedMax",
12614 p->pmax_out[afi][safi]);
12615
12616 /* Maximum prefix */
12617 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12618 json_object_int_add(json_addr, "prefixAllowedMax",
12619 p->pmax[afi][safi]);
12620 if (CHECK_FLAG(p->af_flags[afi][safi],
12621 PEER_FLAG_MAX_PREFIX_WARNING))
12622 json_object_boolean_true_add(
12623 json_addr, "prefixAllowedMaxWarning");
12624 json_object_int_add(json_addr,
12625 "prefixAllowedWarningThresh",
12626 p->pmax_threshold[afi][safi]);
12627 if (p->pmax_restart[afi][safi])
12628 json_object_int_add(
12629 json_addr,
12630 "prefixAllowedRestartIntervalMsecs",
12631 p->pmax_restart[afi][safi] * 60000);
12632 }
12633 json_object_object_add(json_neigh,
12634 get_afi_safi_str(afi, safi, true),
12635 json_addr);
12636
12637 } else {
12638 filter = &p->filter[afi][safi];
12639
12640 vty_out(vty, " For address family: %s\n",
12641 get_afi_safi_str(afi, safi, false));
12642
12643 if (peer_group_active(p))
12644 vty_out(vty, " %s peer-group member\n",
12645 p->group->name);
12646
12647 paf = peer_af_find(p, afi, safi);
12648 if (paf && PAF_SUBGRP(paf)) {
12649 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12650 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12651 vty_out(vty, " Packet Queue length %d\n",
12652 bpacket_queue_virtual_length(paf));
12653 } else {
12654 vty_out(vty, " Not part of any update group\n");
12655 }
12656 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12657 || CHECK_FLAG(p->af_cap[afi][safi],
12658 PEER_CAP_ORF_PREFIX_SM_RCV)
12659 || CHECK_FLAG(p->af_cap[afi][safi],
12660 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12661 || CHECK_FLAG(p->af_cap[afi][safi],
12662 PEER_CAP_ORF_PREFIX_RM_ADV)
12663 || CHECK_FLAG(p->af_cap[afi][safi],
12664 PEER_CAP_ORF_PREFIX_RM_RCV)
12665 || CHECK_FLAG(p->af_cap[afi][safi],
12666 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12667 vty_out(vty, " AF-dependant capabilities:\n");
12668
12669 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12670 || CHECK_FLAG(p->af_cap[afi][safi],
12671 PEER_CAP_ORF_PREFIX_SM_RCV)
12672 || CHECK_FLAG(p->af_cap[afi][safi],
12673 PEER_CAP_ORF_PREFIX_RM_ADV)
12674 || CHECK_FLAG(p->af_cap[afi][safi],
12675 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12676 vty_out(vty,
12677 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12678 ORF_TYPE_PREFIX);
12679 bgp_show_peer_afi_orf_cap(
12680 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12681 PEER_CAP_ORF_PREFIX_RM_ADV,
12682 PEER_CAP_ORF_PREFIX_SM_RCV,
12683 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12684 }
12685 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12686 || CHECK_FLAG(p->af_cap[afi][safi],
12687 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12688 || CHECK_FLAG(p->af_cap[afi][safi],
12689 PEER_CAP_ORF_PREFIX_RM_ADV)
12690 || CHECK_FLAG(p->af_cap[afi][safi],
12691 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12692 vty_out(vty,
12693 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12694 ORF_TYPE_PREFIX_OLD);
12695 bgp_show_peer_afi_orf_cap(
12696 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12697 PEER_CAP_ORF_PREFIX_RM_ADV,
12698 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12699 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12700 }
12701
12702 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12703 p->host, afi, safi);
12704 orf_pfx_count = prefix_bgp_show_prefix_list(
12705 NULL, afi, orf_pfx_name, use_json);
12706
12707 if (CHECK_FLAG(p->af_sflags[afi][safi],
12708 PEER_STATUS_ORF_PREFIX_SEND)
12709 || orf_pfx_count) {
12710 vty_out(vty, " Outbound Route Filter (ORF):");
12711 if (CHECK_FLAG(p->af_sflags[afi][safi],
12712 PEER_STATUS_ORF_PREFIX_SEND))
12713 vty_out(vty, " sent;");
12714 if (orf_pfx_count)
12715 vty_out(vty, " received (%d entries)",
12716 orf_pfx_count);
12717 vty_out(vty, "\n");
12718 }
12719 if (CHECK_FLAG(p->af_sflags[afi][safi],
12720 PEER_STATUS_ORF_WAIT_REFRESH))
12721 vty_out(vty,
12722 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12723
12724 if (CHECK_FLAG(p->af_flags[afi][safi],
12725 PEER_FLAG_REFLECTOR_CLIENT))
12726 vty_out(vty, " Route-Reflector Client\n");
12727 if (CHECK_FLAG(p->af_flags[afi][safi],
12728 PEER_FLAG_RSERVER_CLIENT))
12729 vty_out(vty, " Route-Server Client\n");
12730 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12731 vty_out(vty,
12732 " Inbound soft reconfiguration allowed\n");
12733
12734 if (CHECK_FLAG(p->af_flags[afi][safi],
12735 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12736 vty_out(vty,
12737 " Private AS numbers (all) replaced in updates to this neighbor\n");
12738 else if (CHECK_FLAG(p->af_flags[afi][safi],
12739 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12740 vty_out(vty,
12741 " Private AS numbers replaced in updates to this neighbor\n");
12742 else if (CHECK_FLAG(p->af_flags[afi][safi],
12743 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12744 vty_out(vty,
12745 " Private AS numbers (all) removed in updates to this neighbor\n");
12746 else if (CHECK_FLAG(p->af_flags[afi][safi],
12747 PEER_FLAG_REMOVE_PRIVATE_AS))
12748 vty_out(vty,
12749 " Private AS numbers removed in updates to this neighbor\n");
12750
12751 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12752 if (CHECK_FLAG(p->af_flags[afi][safi],
12753 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12754 vty_out(vty,
12755 " Local AS allowed as path origin\n");
12756 else
12757 vty_out(vty,
12758 " Local AS allowed in path, %d occurrences\n",
12759 p->allowas_in[afi][safi]);
12760 }
12761
12762 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12763 vty_out(vty, " %s\n",
12764 bgp_addpath_names(p->addpath_type[afi][safi])
12765 ->human_description);
12766
12767 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12768 vty_out(vty,
12769 " Override ASNs in outbound updates if aspath equals remote-as\n");
12770
12771 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12772 || CHECK_FLAG(p->af_flags[afi][safi],
12773 PEER_FLAG_FORCE_NEXTHOP_SELF))
12774 vty_out(vty, " NEXT_HOP is always this router\n");
12775 if (CHECK_FLAG(p->af_flags[afi][safi],
12776 PEER_FLAG_AS_PATH_UNCHANGED))
12777 vty_out(vty,
12778 " AS_PATH is propagated unchanged to this neighbor\n");
12779 if (CHECK_FLAG(p->af_flags[afi][safi],
12780 PEER_FLAG_NEXTHOP_UNCHANGED))
12781 vty_out(vty,
12782 " NEXT_HOP is propagated unchanged to this neighbor\n");
12783 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12784 vty_out(vty,
12785 " MED is propagated unchanged to this neighbor\n");
12786 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12787 || CHECK_FLAG(p->af_flags[afi][safi],
12788 PEER_FLAG_SEND_EXT_COMMUNITY)
12789 || CHECK_FLAG(p->af_flags[afi][safi],
12790 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12791 vty_out(vty,
12792 " Community attribute sent to this neighbor");
12793 if (CHECK_FLAG(p->af_flags[afi][safi],
12794 PEER_FLAG_SEND_COMMUNITY)
12795 && CHECK_FLAG(p->af_flags[afi][safi],
12796 PEER_FLAG_SEND_EXT_COMMUNITY)
12797 && CHECK_FLAG(p->af_flags[afi][safi],
12798 PEER_FLAG_SEND_LARGE_COMMUNITY))
12799 vty_out(vty, "(all)\n");
12800 else if (CHECK_FLAG(p->af_flags[afi][safi],
12801 PEER_FLAG_SEND_LARGE_COMMUNITY))
12802 vty_out(vty, "(large)\n");
12803 else if (CHECK_FLAG(p->af_flags[afi][safi],
12804 PEER_FLAG_SEND_EXT_COMMUNITY))
12805 vty_out(vty, "(extended)\n");
12806 else
12807 vty_out(vty, "(standard)\n");
12808 }
12809 if (CHECK_FLAG(p->af_flags[afi][safi],
12810 PEER_FLAG_DEFAULT_ORIGINATE)) {
12811 vty_out(vty, " Default information originate,");
12812
12813 if (p->default_rmap[afi][safi].name)
12814 vty_out(vty, " default route-map %s%s,",
12815 p->default_rmap[afi][safi].map ? "*"
12816 : "",
12817 p->default_rmap[afi][safi].name);
12818 if (paf && PAF_SUBGRP(paf)
12819 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12820 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12821 vty_out(vty, " default sent\n");
12822 else
12823 vty_out(vty, " default not sent\n");
12824 }
12825
12826 /* advertise-vni-all */
12827 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12828 if (is_evpn_enabled())
12829 vty_out(vty, " advertise-all-vni\n");
12830 }
12831
12832 if (filter->plist[FILTER_IN].name
12833 || filter->dlist[FILTER_IN].name
12834 || filter->aslist[FILTER_IN].name
12835 || filter->map[RMAP_IN].name)
12836 vty_out(vty, " Inbound path policy configured\n");
12837 if (filter->plist[FILTER_OUT].name
12838 || filter->dlist[FILTER_OUT].name
12839 || filter->aslist[FILTER_OUT].name
12840 || filter->map[RMAP_OUT].name || filter->usmap.name)
12841 vty_out(vty, " Outbound path policy configured\n");
12842
12843 /* prefix-list */
12844 if (filter->plist[FILTER_IN].name)
12845 vty_out(vty,
12846 " Incoming update prefix filter list is %s%s\n",
12847 filter->plist[FILTER_IN].plist ? "*" : "",
12848 filter->plist[FILTER_IN].name);
12849 if (filter->plist[FILTER_OUT].name)
12850 vty_out(vty,
12851 " Outgoing update prefix filter list is %s%s\n",
12852 filter->plist[FILTER_OUT].plist ? "*" : "",
12853 filter->plist[FILTER_OUT].name);
12854
12855 /* distribute-list */
12856 if (filter->dlist[FILTER_IN].name)
12857 vty_out(vty,
12858 " Incoming update network filter list is %s%s\n",
12859 filter->dlist[FILTER_IN].alist ? "*" : "",
12860 filter->dlist[FILTER_IN].name);
12861 if (filter->dlist[FILTER_OUT].name)
12862 vty_out(vty,
12863 " Outgoing update network filter list is %s%s\n",
12864 filter->dlist[FILTER_OUT].alist ? "*" : "",
12865 filter->dlist[FILTER_OUT].name);
12866
12867 /* filter-list. */
12868 if (filter->aslist[FILTER_IN].name)
12869 vty_out(vty,
12870 " Incoming update AS path filter list is %s%s\n",
12871 filter->aslist[FILTER_IN].aslist ? "*" : "",
12872 filter->aslist[FILTER_IN].name);
12873 if (filter->aslist[FILTER_OUT].name)
12874 vty_out(vty,
12875 " Outgoing update AS path filter list is %s%s\n",
12876 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12877 filter->aslist[FILTER_OUT].name);
12878
12879 /* route-map. */
12880 if (filter->map[RMAP_IN].name)
12881 vty_out(vty,
12882 " Route map for incoming advertisements is %s%s\n",
12883 filter->map[RMAP_IN].map ? "*" : "",
12884 filter->map[RMAP_IN].name);
12885 if (filter->map[RMAP_OUT].name)
12886 vty_out(vty,
12887 " Route map for outgoing advertisements is %s%s\n",
12888 filter->map[RMAP_OUT].map ? "*" : "",
12889 filter->map[RMAP_OUT].name);
12890
12891 /* ebgp-requires-policy (inbound) */
12892 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12893 && !bgp_inbound_policy_exists(p, filter))
12894 vty_out(vty,
12895 " Inbound updates discarded due to missing policy\n");
12896
12897 /* ebgp-requires-policy (outbound) */
12898 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12899 && !bgp_outbound_policy_exists(p, filter))
12900 vty_out(vty,
12901 " Outbound updates discarded due to missing policy\n");
12902
12903 /* unsuppress-map */
12904 if (filter->usmap.name)
12905 vty_out(vty,
12906 " Route map for selective unsuppress is %s%s\n",
12907 filter->usmap.map ? "*" : "",
12908 filter->usmap.name);
12909
12910 /* advertise-map */
12911 if (filter->advmap.aname && filter->advmap.cname)
12912 vty_out(vty,
12913 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12914 filter->advmap.condition ? "EXIST"
12915 : "NON_EXIST",
12916 filter->advmap.cmap ? "*" : "",
12917 filter->advmap.cname,
12918 filter->advmap.amap ? "*" : "",
12919 filter->advmap.aname,
12920 filter->advmap.update_type ==
12921 UPDATE_TYPE_ADVERTISE
12922 ? "Advertise"
12923 : "Withdraw");
12924
12925 /* Receive prefix count */
12926 vty_out(vty, " %u accepted prefixes\n",
12927 p->pcount[afi][safi]);
12928
12929 /* maximum-prefix-out */
12930 if (CHECK_FLAG(p->af_flags[afi][safi],
12931 PEER_FLAG_MAX_PREFIX_OUT))
12932 vty_out(vty,
12933 " Maximum allowed prefixes sent %u\n",
12934 p->pmax_out[afi][safi]);
12935
12936 /* Maximum prefix */
12937 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12938 vty_out(vty,
12939 " Maximum prefixes allowed %u%s\n",
12940 p->pmax[afi][safi],
12941 CHECK_FLAG(p->af_flags[afi][safi],
12942 PEER_FLAG_MAX_PREFIX_WARNING)
12943 ? " (warning-only)"
12944 : "");
12945 vty_out(vty, " Threshold for warning message %d%%",
12946 p->pmax_threshold[afi][safi]);
12947 if (p->pmax_restart[afi][safi])
12948 vty_out(vty, ", restart interval %d min",
12949 p->pmax_restart[afi][safi]);
12950 vty_out(vty, "\n");
12951 }
12952
12953 vty_out(vty, "\n");
12954 }
12955 }
12956
12957 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12958 json_object *json)
12959 {
12960 struct bgp *bgp;
12961 char timebuf[BGP_UPTIME_LEN];
12962 char dn_flag[2];
12963 afi_t afi;
12964 safi_t safi;
12965 uint16_t i;
12966 uint8_t *msg;
12967 json_object *json_neigh = NULL;
12968 time_t epoch_tbuf;
12969 uint32_t sync_tcp_mss;
12970
12971 bgp = p->bgp;
12972
12973 if (use_json)
12974 json_neigh = json_object_new_object();
12975
12976 memset(dn_flag, '\0', sizeof(dn_flag));
12977 if (!p->conf_if && peer_dynamic_neighbor(p))
12978 dn_flag[0] = '*';
12979
12980 if (!use_json) {
12981 if (p->conf_if) /* Configured interface name. */
12982 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12983 &p->su);
12984 else /* Configured IP address. */
12985 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12986 p->host);
12987 }
12988
12989 if (use_json) {
12990 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12991 json_object_string_add(json_neigh, "bgpNeighborAddr",
12992 "none");
12993 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12994 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12995 "%pSU", &p->su);
12996
12997 json_object_int_add(json_neigh, "remoteAs", p->as);
12998
12999 if (p->change_local_as)
13000 json_object_int_add(json_neigh, "localAs",
13001 p->change_local_as);
13002 else
13003 json_object_int_add(json_neigh, "localAs", p->local_as);
13004
13005 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13006 json_object_boolean_true_add(json_neigh,
13007 "localAsNoPrepend");
13008
13009 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13010 json_object_boolean_true_add(json_neigh,
13011 "localAsReplaceAs");
13012 } else {
13013 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13014 || (p->as_type == AS_INTERNAL))
13015 vty_out(vty, "remote AS %u, ", p->as);
13016 else
13017 vty_out(vty, "remote AS Unspecified, ");
13018 vty_out(vty, "local AS %u%s%s, ",
13019 p->change_local_as ? p->change_local_as : p->local_as,
13020 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13021 ? " no-prepend"
13022 : "",
13023 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13024 ? " replace-as"
13025 : "");
13026 }
13027 /* peer type internal or confed-internal */
13028 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13029 if (use_json) {
13030 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13031 json_object_boolean_true_add(
13032 json_neigh, "nbrConfedInternalLink");
13033 else
13034 json_object_boolean_true_add(json_neigh,
13035 "nbrInternalLink");
13036 } else {
13037 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13038 vty_out(vty, "confed-internal link\n");
13039 else
13040 vty_out(vty, "internal link\n");
13041 }
13042 /* peer type external or confed-external */
13043 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13044 if (use_json) {
13045 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13046 json_object_boolean_true_add(
13047 json_neigh, "nbrConfedExternalLink");
13048 else
13049 json_object_boolean_true_add(json_neigh,
13050 "nbrExternalLink");
13051 } else {
13052 if (bgp_confederation_peers_check(bgp, p->as))
13053 vty_out(vty, "confed-external link\n");
13054 else
13055 vty_out(vty, "external link\n");
13056 }
13057 } else {
13058 if (use_json)
13059 json_object_boolean_true_add(json_neigh,
13060 "nbrUnspecifiedLink");
13061 else
13062 vty_out(vty, "unspecified link\n");
13063 }
13064
13065 /* Roles */
13066 if (use_json) {
13067 json_object_string_add(json_neigh, "localRole",
13068 bgp_get_name_by_role(p->local_role));
13069 json_object_string_add(json_neigh, "remoteRole",
13070 bgp_get_name_by_role(p->remote_role));
13071 } else {
13072 vty_out(vty, " Local Role: %s\n",
13073 bgp_get_name_by_role(p->local_role));
13074 vty_out(vty, " Remote Role: %s\n",
13075 bgp_get_name_by_role(p->remote_role));
13076 }
13077
13078
13079 /* Description. */
13080 if (p->desc) {
13081 if (use_json)
13082 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13083 else
13084 vty_out(vty, " Description: %s\n", p->desc);
13085 }
13086
13087 if (p->hostname) {
13088 if (use_json) {
13089 json_object_string_add(json_neigh, "hostname",
13090 p->hostname);
13091
13092 if (p->domainname)
13093 json_object_string_add(json_neigh, "domainname",
13094 p->domainname);
13095 } else {
13096 if (p->domainname && (p->domainname[0] != '\0'))
13097 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13098 p->domainname);
13099 else
13100 vty_out(vty, "Hostname: %s\n", p->hostname);
13101 }
13102 } else {
13103 if (use_json)
13104 json_object_string_add(json_neigh, "hostname",
13105 "Unknown");
13106 }
13107
13108 /* Peer-group */
13109 if (p->group) {
13110 if (use_json) {
13111 json_object_string_add(json_neigh, "peerGroup",
13112 p->group->name);
13113
13114 if (dn_flag[0]) {
13115 struct prefix prefix, *range = NULL;
13116
13117 if (sockunion2hostprefix(&(p->su), &prefix))
13118 range = peer_group_lookup_dynamic_neighbor_range(
13119 p->group, &prefix);
13120
13121 if (range) {
13122 json_object_string_addf(
13123 json_neigh,
13124 "peerSubnetRangeGroup", "%pFX",
13125 range);
13126 }
13127 }
13128 } else {
13129 vty_out(vty,
13130 " Member of peer-group %s for session parameters\n",
13131 p->group->name);
13132
13133 if (dn_flag[0]) {
13134 struct prefix prefix, *range = NULL;
13135
13136 if (sockunion2hostprefix(&(p->su), &prefix))
13137 range = peer_group_lookup_dynamic_neighbor_range(
13138 p->group, &prefix);
13139
13140 if (range) {
13141 vty_out(vty,
13142 " Belongs to the subnet range group: %pFX\n",
13143 range);
13144 }
13145 }
13146 }
13147 }
13148
13149 if (use_json) {
13150 /* Administrative shutdown. */
13151 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13152 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13153 json_object_boolean_true_add(json_neigh,
13154 "adminShutDown");
13155
13156 /* BGP Version. */
13157 json_object_int_add(json_neigh, "bgpVersion", 4);
13158 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13159 &p->remote_id);
13160 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13161 &bgp->router_id);
13162
13163 /* Confederation */
13164 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13165 && bgp_confederation_peers_check(bgp, p->as))
13166 json_object_boolean_true_add(json_neigh,
13167 "nbrCommonAdmin");
13168
13169 /* Status. */
13170 json_object_string_add(
13171 json_neigh, "bgpState",
13172 lookup_msg(bgp_status_msg, p->status, NULL));
13173
13174 if (peer_established(p)) {
13175 time_t uptime;
13176
13177 uptime = monotime(NULL);
13178 uptime -= p->uptime;
13179 epoch_tbuf = time(NULL) - uptime;
13180
13181 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13182 uptime * 1000);
13183 json_object_string_add(json_neigh, "bgpTimerUpString",
13184 peer_uptime(p->uptime, timebuf,
13185 BGP_UPTIME_LEN, 0,
13186 NULL));
13187 json_object_int_add(json_neigh,
13188 "bgpTimerUpEstablishedEpoch",
13189 epoch_tbuf);
13190 }
13191
13192 else if (p->status == Active) {
13193 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13194 json_object_string_add(json_neigh, "bgpStateIs",
13195 "passive");
13196 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13197 json_object_string_add(json_neigh, "bgpStateIs",
13198 "passiveNSF");
13199 }
13200
13201 /* read timer */
13202 time_t uptime;
13203 struct tm tm;
13204
13205 uptime = monotime(NULL);
13206 uptime -= p->readtime;
13207 gmtime_r(&uptime, &tm);
13208
13209 json_object_int_add(json_neigh, "bgpTimerLastRead",
13210 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13211 + (tm.tm_hour * 3600000));
13212
13213 uptime = monotime(NULL);
13214 uptime -= p->last_write;
13215 gmtime_r(&uptime, &tm);
13216
13217 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13218 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13219 + (tm.tm_hour * 3600000));
13220
13221 uptime = monotime(NULL);
13222 uptime -= p->update_time;
13223 gmtime_r(&uptime, &tm);
13224
13225 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13226 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13227 + (tm.tm_hour * 3600000));
13228
13229 /* Configured timer values. */
13230 json_object_int_add(json_neigh,
13231 "bgpTimerConfiguredHoldTimeMsecs",
13232 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13233 ? p->holdtime * 1000
13234 : bgp->default_holdtime * 1000);
13235 json_object_int_add(json_neigh,
13236 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13237 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13238 ? p->keepalive * 1000
13239 : bgp->default_keepalive * 1000);
13240 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13241 p->v_holdtime * 1000);
13242 json_object_int_add(json_neigh,
13243 "bgpTimerKeepAliveIntervalMsecs",
13244 p->v_keepalive * 1000);
13245 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13246 json_object_int_add(json_neigh,
13247 "bgpTimerDelayOpenTimeMsecs",
13248 p->v_delayopen * 1000);
13249 }
13250
13251 /* Configured and Synced tcp-mss value for peer */
13252 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13253 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13254 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13255 p->tcp_mss);
13256 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13257 sync_tcp_mss);
13258 }
13259
13260 /* Extended Optional Parameters Length for BGP OPEN Message */
13261 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13262 json_object_boolean_true_add(
13263 json_neigh, "extendedOptionalParametersLength");
13264 else
13265 json_object_boolean_false_add(
13266 json_neigh, "extendedOptionalParametersLength");
13267
13268 /* Conditional advertisements */
13269 json_object_int_add(
13270 json_neigh,
13271 "bgpTimerConfiguredConditionalAdvertisementsSec",
13272 bgp->condition_check_period);
13273 if (thread_is_scheduled(bgp->t_condition_check))
13274 json_object_int_add(
13275 json_neigh,
13276 "bgpTimerUntilConditionalAdvertisementsSec",
13277 thread_timer_remain_second(
13278 bgp->t_condition_check));
13279 } else {
13280 /* Administrative shutdown. */
13281 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13282 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13283 vty_out(vty, " Administratively shut down\n");
13284
13285 /* BGP Version. */
13286 vty_out(vty, " BGP version 4");
13287 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13288 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13289
13290 /* Confederation */
13291 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13292 && bgp_confederation_peers_check(bgp, p->as))
13293 vty_out(vty,
13294 " Neighbor under common administration\n");
13295
13296 /* Status. */
13297 vty_out(vty, " BGP state = %s",
13298 lookup_msg(bgp_status_msg, p->status, NULL));
13299
13300 if (peer_established(p))
13301 vty_out(vty, ", up for %8s",
13302 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13303 0, NULL));
13304
13305 else if (p->status == Active) {
13306 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13307 vty_out(vty, " (passive)");
13308 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13309 vty_out(vty, " (NSF passive)");
13310 }
13311 vty_out(vty, "\n");
13312
13313 /* read timer */
13314 vty_out(vty, " Last read %s",
13315 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13316 NULL));
13317 vty_out(vty, ", Last write %s\n",
13318 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13319 NULL));
13320
13321 /* Configured timer values. */
13322 vty_out(vty,
13323 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13324 p->v_holdtime, p->v_keepalive);
13325 vty_out(vty, " Configured hold time is %d seconds",
13326 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13327 ? p->holdtime
13328 : bgp->default_holdtime);
13329 vty_out(vty, ", keepalive interval is %d seconds\n",
13330 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13331 ? p->keepalive
13332 : bgp->default_keepalive);
13333 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13334 vty_out(vty,
13335 " Configured DelayOpenTime is %d seconds\n",
13336 p->delayopen);
13337
13338 /* Configured and synced tcp-mss value for peer */
13339 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13340 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13341 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13342 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13343 }
13344
13345 /* Extended Optional Parameters Length for BGP OPEN Message */
13346 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13347 vty_out(vty,
13348 " Extended Optional Parameters Length is enabled\n");
13349
13350 /* Conditional advertisements */
13351 vty_out(vty,
13352 " Configured conditional advertisements interval is %d seconds\n",
13353 bgp->condition_check_period);
13354 if (thread_is_scheduled(bgp->t_condition_check))
13355 vty_out(vty,
13356 " Time until conditional advertisements begin is %lu seconds\n",
13357 thread_timer_remain_second(
13358 bgp->t_condition_check));
13359 }
13360 /* Capability. */
13361 if (peer_established(p) &&
13362 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13363 if (use_json) {
13364 json_object *json_cap = NULL;
13365
13366 json_cap = json_object_new_object();
13367
13368 /* AS4 */
13369 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13370 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13371 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13372 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13373 json_object_string_add(
13374 json_cap, "4byteAs",
13375 "advertisedAndReceived");
13376 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13377 json_object_string_add(json_cap,
13378 "4byteAs",
13379 "advertised");
13380 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13381 json_object_string_add(json_cap,
13382 "4byteAs",
13383 "received");
13384 }
13385
13386 /* Extended Message Support */
13387 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13388 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13389 json_object_string_add(json_cap,
13390 "extendedMessage",
13391 "advertisedAndReceived");
13392 else if (CHECK_FLAG(p->cap,
13393 PEER_CAP_EXTENDED_MESSAGE_ADV))
13394 json_object_string_add(json_cap,
13395 "extendedMessage",
13396 "advertised");
13397 else if (CHECK_FLAG(p->cap,
13398 PEER_CAP_EXTENDED_MESSAGE_RCV))
13399 json_object_string_add(json_cap,
13400 "extendedMessage",
13401 "received");
13402
13403 /* AddPath */
13404 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13405 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13406 json_object *json_add = NULL;
13407 const char *print_store;
13408
13409 json_add = json_object_new_object();
13410
13411 FOREACH_AFI_SAFI (afi, safi) {
13412 json_object *json_sub = NULL;
13413 json_sub = json_object_new_object();
13414 print_store = get_afi_safi_str(
13415 afi, safi, true);
13416
13417 if (CHECK_FLAG(
13418 p->af_cap[afi][safi],
13419 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13420 CHECK_FLAG(
13421 p->af_cap[afi][safi],
13422 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13423 if (CHECK_FLAG(
13424 p->af_cap[afi]
13425 [safi],
13426 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13427 CHECK_FLAG(
13428 p->af_cap[afi]
13429 [safi],
13430 PEER_CAP_ADDPATH_AF_TX_RCV))
13431 json_object_boolean_true_add(
13432 json_sub,
13433 "txAdvertisedAndReceived");
13434 else if (
13435 CHECK_FLAG(
13436 p->af_cap[afi]
13437 [safi],
13438 PEER_CAP_ADDPATH_AF_TX_ADV))
13439 json_object_boolean_true_add(
13440 json_sub,
13441 "txAdvertised");
13442 else if (
13443 CHECK_FLAG(
13444 p->af_cap[afi]
13445 [safi],
13446 PEER_CAP_ADDPATH_AF_TX_RCV))
13447 json_object_boolean_true_add(
13448 json_sub,
13449 "txReceived");
13450 }
13451
13452 if (CHECK_FLAG(
13453 p->af_cap[afi][safi],
13454 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13455 CHECK_FLAG(
13456 p->af_cap[afi][safi],
13457 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13458 if (CHECK_FLAG(
13459 p->af_cap[afi]
13460 [safi],
13461 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13462 CHECK_FLAG(
13463 p->af_cap[afi]
13464 [safi],
13465 PEER_CAP_ADDPATH_AF_RX_RCV))
13466 json_object_boolean_true_add(
13467 json_sub,
13468 "rxAdvertisedAndReceived");
13469 else if (
13470 CHECK_FLAG(
13471 p->af_cap[afi]
13472 [safi],
13473 PEER_CAP_ADDPATH_AF_RX_ADV))
13474 json_object_boolean_true_add(
13475 json_sub,
13476 "rxAdvertised");
13477 else if (
13478 CHECK_FLAG(
13479 p->af_cap[afi]
13480 [safi],
13481 PEER_CAP_ADDPATH_AF_RX_RCV))
13482 json_object_boolean_true_add(
13483 json_sub,
13484 "rxReceived");
13485 }
13486
13487 if (CHECK_FLAG(
13488 p->af_cap[afi][safi],
13489 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13490 CHECK_FLAG(
13491 p->af_cap[afi][safi],
13492 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13493 CHECK_FLAG(
13494 p->af_cap[afi][safi],
13495 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13496 CHECK_FLAG(
13497 p->af_cap[afi][safi],
13498 PEER_CAP_ADDPATH_AF_RX_RCV))
13499 json_object_object_add(
13500 json_add, print_store,
13501 json_sub);
13502 else
13503 json_object_free(json_sub);
13504 }
13505
13506 json_object_object_add(json_cap, "addPath",
13507 json_add);
13508 }
13509
13510 /* Dynamic */
13511 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13512 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13513 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13514 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13515 json_object_string_add(
13516 json_cap, "dynamic",
13517 "advertisedAndReceived");
13518 else if (CHECK_FLAG(p->cap,
13519 PEER_CAP_DYNAMIC_ADV))
13520 json_object_string_add(json_cap,
13521 "dynamic",
13522 "advertised");
13523 else if (CHECK_FLAG(p->cap,
13524 PEER_CAP_DYNAMIC_RCV))
13525 json_object_string_add(json_cap,
13526 "dynamic",
13527 "received");
13528 }
13529
13530 /* Role */
13531 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13532 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13533 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13534 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13535 json_object_string_add(
13536 json_cap, "role",
13537 "advertisedAndReceived");
13538 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13539 json_object_string_add(json_cap, "role",
13540 "advertised");
13541 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13542 json_object_string_add(json_cap, "role",
13543 "received");
13544 }
13545
13546 /* Extended nexthop */
13547 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13548 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13549 json_object *json_nxt = NULL;
13550 const char *print_store;
13551
13552
13553 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13554 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13555 json_object_string_add(
13556 json_cap, "extendedNexthop",
13557 "advertisedAndReceived");
13558 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13559 json_object_string_add(
13560 json_cap, "extendedNexthop",
13561 "advertised");
13562 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13563 json_object_string_add(
13564 json_cap, "extendedNexthop",
13565 "received");
13566
13567 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13568 json_nxt = json_object_new_object();
13569
13570 for (safi = SAFI_UNICAST;
13571 safi < SAFI_MAX; safi++) {
13572 if (CHECK_FLAG(
13573 p->af_cap[AFI_IP]
13574 [safi],
13575 PEER_CAP_ENHE_AF_RCV)) {
13576 print_store =
13577 get_afi_safi_str(
13578 AFI_IP,
13579 safi,
13580 true);
13581 json_object_string_add(
13582 json_nxt,
13583 print_store,
13584 "recieved"); /* misspelled for compatibility */
13585 }
13586 }
13587 json_object_object_add(
13588 json_cap,
13589 "extendedNexthopFamililesByPeer",
13590 json_nxt);
13591 }
13592 }
13593
13594 /* Long-lived Graceful Restart */
13595 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13596 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13597 json_object *json_llgr = NULL;
13598 const char *afi_safi_str;
13599
13600 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13601 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13602 json_object_string_add(
13603 json_cap,
13604 "longLivedGracefulRestart",
13605 "advertisedAndReceived");
13606 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13607 json_object_string_add(
13608 json_cap,
13609 "longLivedGracefulRestart",
13610 "advertised");
13611 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13612 json_object_string_add(
13613 json_cap,
13614 "longLivedGracefulRestart",
13615 "received");
13616
13617 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13618 json_llgr = json_object_new_object();
13619
13620 FOREACH_AFI_SAFI (afi, safi) {
13621 if (CHECK_FLAG(
13622 p->af_cap[afi]
13623 [safi],
13624 PEER_CAP_ENHE_AF_RCV)) {
13625 afi_safi_str =
13626 get_afi_safi_str(
13627 afi,
13628 safi,
13629 true);
13630 json_object_string_add(
13631 json_llgr,
13632 afi_safi_str,
13633 "received");
13634 }
13635 }
13636 json_object_object_add(
13637 json_cap,
13638 "longLivedGracefulRestartByPeer",
13639 json_llgr);
13640 }
13641 }
13642
13643 /* Route Refresh */
13644 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13645 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13646 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13647 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13648 (CHECK_FLAG(p->cap,
13649 PEER_CAP_REFRESH_NEW_RCV) ||
13650 CHECK_FLAG(p->cap,
13651 PEER_CAP_REFRESH_OLD_RCV))) {
13652 if (CHECK_FLAG(
13653 p->cap,
13654 PEER_CAP_REFRESH_OLD_RCV) &&
13655 CHECK_FLAG(
13656 p->cap,
13657 PEER_CAP_REFRESH_NEW_RCV))
13658 json_object_string_add(
13659 json_cap,
13660 "routeRefresh",
13661 "advertisedAndReceivedOldNew");
13662 else {
13663 if (CHECK_FLAG(
13664 p->cap,
13665 PEER_CAP_REFRESH_OLD_RCV))
13666 json_object_string_add(
13667 json_cap,
13668 "routeRefresh",
13669 "advertisedAndReceivedOld");
13670 else
13671 json_object_string_add(
13672 json_cap,
13673 "routeRefresh",
13674 "advertisedAndReceivedNew");
13675 }
13676 } else if (CHECK_FLAG(p->cap,
13677 PEER_CAP_REFRESH_ADV))
13678 json_object_string_add(json_cap,
13679 "routeRefresh",
13680 "advertised");
13681 else if (CHECK_FLAG(p->cap,
13682 PEER_CAP_REFRESH_NEW_RCV) ||
13683 CHECK_FLAG(p->cap,
13684 PEER_CAP_REFRESH_OLD_RCV))
13685 json_object_string_add(json_cap,
13686 "routeRefresh",
13687 "received");
13688 }
13689
13690 /* Enhanced Route Refresh */
13691 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13692 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13693 if (CHECK_FLAG(p->cap,
13694 PEER_CAP_ENHANCED_RR_ADV) &&
13695 CHECK_FLAG(p->cap,
13696 PEER_CAP_ENHANCED_RR_RCV))
13697 json_object_string_add(
13698 json_cap,
13699 "enhancedRouteRefresh",
13700 "advertisedAndReceived");
13701 else if (CHECK_FLAG(p->cap,
13702 PEER_CAP_ENHANCED_RR_ADV))
13703 json_object_string_add(
13704 json_cap,
13705 "enhancedRouteRefresh",
13706 "advertised");
13707 else if (CHECK_FLAG(p->cap,
13708 PEER_CAP_ENHANCED_RR_RCV))
13709 json_object_string_add(
13710 json_cap,
13711 "enhancedRouteRefresh",
13712 "received");
13713 }
13714
13715 /* Multiprotocol Extensions */
13716 json_object *json_multi = NULL;
13717
13718 json_multi = json_object_new_object();
13719
13720 FOREACH_AFI_SAFI (afi, safi) {
13721 if (p->afc_adv[afi][safi] ||
13722 p->afc_recv[afi][safi]) {
13723 json_object *json_exten = NULL;
13724 json_exten = json_object_new_object();
13725
13726 if (p->afc_adv[afi][safi] &&
13727 p->afc_recv[afi][safi])
13728 json_object_boolean_true_add(
13729 json_exten,
13730 "advertisedAndReceived");
13731 else if (p->afc_adv[afi][safi])
13732 json_object_boolean_true_add(
13733 json_exten,
13734 "advertised");
13735 else if (p->afc_recv[afi][safi])
13736 json_object_boolean_true_add(
13737 json_exten, "received");
13738
13739 json_object_object_add(
13740 json_multi,
13741 get_afi_safi_str(afi, safi,
13742 true),
13743 json_exten);
13744 }
13745 }
13746 json_object_object_add(json_cap,
13747 "multiprotocolExtensions",
13748 json_multi);
13749
13750 /* Hostname capabilities */
13751 json_object *json_hname = NULL;
13752
13753 json_hname = json_object_new_object();
13754
13755 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13756 json_object_string_add(
13757 json_hname, "advHostName",
13758 bgp->peer_self->hostname
13759 ? bgp->peer_self->hostname
13760 : "n/a");
13761 json_object_string_add(
13762 json_hname, "advDomainName",
13763 bgp->peer_self->domainname
13764 ? bgp->peer_self->domainname
13765 : "n/a");
13766 }
13767
13768
13769 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13770 json_object_string_add(
13771 json_hname, "rcvHostName",
13772 p->hostname ? p->hostname : "n/a");
13773 json_object_string_add(
13774 json_hname, "rcvDomainName",
13775 p->domainname ? p->domainname : "n/a");
13776 }
13777
13778 json_object_object_add(json_cap, "hostName",
13779 json_hname);
13780
13781 /* Graceful Restart */
13782 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13783 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13784 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13785 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13786 json_object_string_add(
13787 json_cap, "gracefulRestart",
13788 "advertisedAndReceived");
13789 else if (CHECK_FLAG(p->cap,
13790 PEER_CAP_RESTART_ADV))
13791 json_object_string_add(
13792 json_cap,
13793 "gracefulRestartCapability",
13794 "advertised");
13795 else if (CHECK_FLAG(p->cap,
13796 PEER_CAP_RESTART_RCV))
13797 json_object_string_add(
13798 json_cap,
13799 "gracefulRestartCapability",
13800 "received");
13801
13802 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13803 int restart_af_count = 0;
13804 json_object *json_restart = NULL;
13805 json_restart = json_object_new_object();
13806
13807 json_object_int_add(
13808 json_cap,
13809 "gracefulRestartRemoteTimerMsecs",
13810 p->v_gr_restart * 1000);
13811
13812 FOREACH_AFI_SAFI (afi, safi) {
13813 if (CHECK_FLAG(
13814 p->af_cap[afi]
13815 [safi],
13816 PEER_CAP_RESTART_AF_RCV)) {
13817 json_object *json_sub =
13818 NULL;
13819 json_sub =
13820 json_object_new_object();
13821
13822 if (CHECK_FLAG(
13823 p->af_cap
13824 [afi]
13825 [safi],
13826 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13827 json_object_boolean_true_add(
13828 json_sub,
13829 "preserved");
13830 restart_af_count++;
13831 json_object_object_add(
13832 json_restart,
13833 get_afi_safi_str(
13834 afi,
13835 safi,
13836 true),
13837 json_sub);
13838 }
13839 }
13840 if (!restart_af_count) {
13841 json_object_string_add(
13842 json_cap,
13843 "addressFamiliesByPeer",
13844 "none");
13845 json_object_free(json_restart);
13846 } else
13847 json_object_object_add(
13848 json_cap,
13849 "addressFamiliesByPeer",
13850 json_restart);
13851 }
13852 }
13853 json_object_object_add(
13854 json_neigh, "neighborCapabilities", json_cap);
13855 } else {
13856 vty_out(vty, " Neighbor capabilities:\n");
13857
13858 /* AS4 */
13859 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13860 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13861 vty_out(vty, " 4 Byte AS:");
13862 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13863 vty_out(vty, " advertised");
13864 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13865 vty_out(vty, " %sreceived",
13866 CHECK_FLAG(p->cap,
13867 PEER_CAP_AS4_ADV)
13868 ? "and "
13869 : "");
13870 vty_out(vty, "\n");
13871 }
13872
13873 /* Extended Message Support */
13874 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13875 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13876 vty_out(vty, " Extended Message:");
13877 if (CHECK_FLAG(p->cap,
13878 PEER_CAP_EXTENDED_MESSAGE_ADV))
13879 vty_out(vty, " advertised");
13880 if (CHECK_FLAG(p->cap,
13881 PEER_CAP_EXTENDED_MESSAGE_RCV))
13882 vty_out(vty, " %sreceived",
13883 CHECK_FLAG(
13884 p->cap,
13885 PEER_CAP_EXTENDED_MESSAGE_ADV)
13886 ? "and "
13887 : "");
13888 vty_out(vty, "\n");
13889 }
13890
13891 /* AddPath */
13892 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13893 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13894 vty_out(vty, " AddPath:\n");
13895
13896 FOREACH_AFI_SAFI (afi, safi) {
13897 if (CHECK_FLAG(
13898 p->af_cap[afi][safi],
13899 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13900 CHECK_FLAG(
13901 p->af_cap[afi][safi],
13902 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13903 vty_out(vty, " %s: TX ",
13904 get_afi_safi_str(
13905 afi, safi,
13906 false));
13907
13908 if (CHECK_FLAG(
13909 p->af_cap[afi]
13910 [safi],
13911 PEER_CAP_ADDPATH_AF_TX_ADV))
13912 vty_out(vty,
13913 "advertised");
13914
13915 if (CHECK_FLAG(
13916 p->af_cap[afi]
13917 [safi],
13918 PEER_CAP_ADDPATH_AF_TX_RCV))
13919 vty_out(vty,
13920 "%sreceived",
13921 CHECK_FLAG(
13922 p->af_cap
13923 [afi]
13924 [safi],
13925 PEER_CAP_ADDPATH_AF_TX_ADV)
13926 ? " and "
13927 : "");
13928
13929 vty_out(vty, "\n");
13930 }
13931
13932 if (CHECK_FLAG(
13933 p->af_cap[afi][safi],
13934 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13935 CHECK_FLAG(
13936 p->af_cap[afi][safi],
13937 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13938 vty_out(vty, " %s: RX ",
13939 get_afi_safi_str(
13940 afi, safi,
13941 false));
13942
13943 if (CHECK_FLAG(
13944 p->af_cap[afi]
13945 [safi],
13946 PEER_CAP_ADDPATH_AF_RX_ADV))
13947 vty_out(vty,
13948 "advertised");
13949
13950 if (CHECK_FLAG(
13951 p->af_cap[afi]
13952 [safi],
13953 PEER_CAP_ADDPATH_AF_RX_RCV))
13954 vty_out(vty,
13955 "%sreceived",
13956 CHECK_FLAG(
13957 p->af_cap
13958 [afi]
13959 [safi],
13960 PEER_CAP_ADDPATH_AF_RX_ADV)
13961 ? " and "
13962 : "");
13963
13964 vty_out(vty, "\n");
13965 }
13966 }
13967 }
13968
13969 /* Dynamic */
13970 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13971 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13972 vty_out(vty, " Dynamic:");
13973 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13974 vty_out(vty, " advertised");
13975 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13976 vty_out(vty, " %sreceived",
13977 CHECK_FLAG(p->cap,
13978 PEER_CAP_DYNAMIC_ADV)
13979 ? "and "
13980 : "");
13981 vty_out(vty, "\n");
13982 }
13983
13984 /* Role */
13985 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13986 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13987 vty_out(vty, " Role:");
13988 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13989 vty_out(vty, " advertised");
13990 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13991 vty_out(vty, " %sreceived",
13992 CHECK_FLAG(p->cap,
13993 PEER_CAP_ROLE_ADV)
13994 ? "and "
13995 : "");
13996 vty_out(vty, "\n");
13997 }
13998
13999 /* Extended nexthop */
14000 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14001 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14002 vty_out(vty, " Extended nexthop:");
14003 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14004 vty_out(vty, " advertised");
14005 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14006 vty_out(vty, " %sreceived",
14007 CHECK_FLAG(p->cap,
14008 PEER_CAP_ENHE_ADV)
14009 ? "and "
14010 : "");
14011 vty_out(vty, "\n");
14012
14013 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
14014 vty_out(vty,
14015 " Address families by peer:\n ");
14016 for (safi = SAFI_UNICAST;
14017 safi < SAFI_MAX; safi++)
14018 if (CHECK_FLAG(
14019 p->af_cap[AFI_IP]
14020 [safi],
14021 PEER_CAP_ENHE_AF_RCV))
14022 vty_out(vty,
14023 " %s\n",
14024 get_afi_safi_str(
14025 AFI_IP,
14026 safi,
14027 false));
14028 }
14029 }
14030
14031 /* Long-lived Graceful Restart */
14032 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14033 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14034 vty_out(vty,
14035 " Long-lived Graceful Restart:");
14036 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14037 vty_out(vty, " advertised");
14038 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14039 vty_out(vty, " %sreceived",
14040 CHECK_FLAG(p->cap,
14041 PEER_CAP_LLGR_ADV)
14042 ? "and "
14043 : "");
14044 vty_out(vty, "\n");
14045
14046 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14047 vty_out(vty,
14048 " Address families by peer:\n");
14049 FOREACH_AFI_SAFI (afi, safi)
14050 if (CHECK_FLAG(
14051 p->af_cap[afi]
14052 [safi],
14053 PEER_CAP_LLGR_AF_RCV))
14054 vty_out(vty,
14055 " %s\n",
14056 get_afi_safi_str(
14057 afi,
14058 safi,
14059 false));
14060 }
14061 }
14062
14063 /* Route Refresh */
14064 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14065 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14066 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14067 vty_out(vty, " Route refresh:");
14068 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14069 vty_out(vty, " advertised");
14070 if (CHECK_FLAG(p->cap,
14071 PEER_CAP_REFRESH_NEW_RCV) ||
14072 CHECK_FLAG(p->cap,
14073 PEER_CAP_REFRESH_OLD_RCV))
14074 vty_out(vty, " %sreceived(%s)",
14075 CHECK_FLAG(p->cap,
14076 PEER_CAP_REFRESH_ADV)
14077 ? "and "
14078 : "",
14079 (CHECK_FLAG(
14080 p->cap,
14081 PEER_CAP_REFRESH_OLD_RCV) &&
14082 CHECK_FLAG(
14083 p->cap,
14084 PEER_CAP_REFRESH_NEW_RCV))
14085 ? "old & new"
14086 : CHECK_FLAG(
14087 p->cap,
14088 PEER_CAP_REFRESH_OLD_RCV)
14089 ? "old"
14090 : "new");
14091
14092 vty_out(vty, "\n");
14093 }
14094
14095 /* Enhanced Route Refresh */
14096 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14097 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14098 vty_out(vty, " Enhanced Route Refresh:");
14099 if (CHECK_FLAG(p->cap,
14100 PEER_CAP_ENHANCED_RR_ADV))
14101 vty_out(vty, " advertised");
14102 if (CHECK_FLAG(p->cap,
14103 PEER_CAP_ENHANCED_RR_RCV))
14104 vty_out(vty, " %sreceived",
14105 CHECK_FLAG(p->cap,
14106 PEER_CAP_REFRESH_ADV)
14107 ? "and "
14108 : "");
14109 vty_out(vty, "\n");
14110 }
14111
14112 /* Multiprotocol Extensions */
14113 FOREACH_AFI_SAFI (afi, safi)
14114 if (p->afc_adv[afi][safi] ||
14115 p->afc_recv[afi][safi]) {
14116 vty_out(vty, " Address Family %s:",
14117 get_afi_safi_str(afi, safi,
14118 false));
14119 if (p->afc_adv[afi][safi])
14120 vty_out(vty, " advertised");
14121 if (p->afc_recv[afi][safi])
14122 vty_out(vty, " %sreceived",
14123 p->afc_adv[afi][safi]
14124 ? "and "
14125 : "");
14126 vty_out(vty, "\n");
14127 }
14128
14129 /* Hostname capability */
14130 vty_out(vty, " Hostname Capability:");
14131
14132 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14133 vty_out(vty,
14134 " advertised (name: %s,domain name: %s)",
14135 bgp->peer_self->hostname
14136 ? bgp->peer_self->hostname
14137 : "n/a",
14138 bgp->peer_self->domainname
14139 ? bgp->peer_self->domainname
14140 : "n/a");
14141 } else {
14142 vty_out(vty, " not advertised");
14143 }
14144
14145 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14146 vty_out(vty,
14147 " received (name: %s,domain name: %s)",
14148 p->hostname ? p->hostname : "n/a",
14149 p->domainname ? p->domainname : "n/a");
14150 } else {
14151 vty_out(vty, " not received");
14152 }
14153
14154 vty_out(vty, "\n");
14155
14156 /* Graceful Restart */
14157 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14158 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14159 vty_out(vty,
14160 " Graceful Restart Capability:");
14161 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14162 vty_out(vty, " advertised");
14163 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14164 vty_out(vty, " %sreceived",
14165 CHECK_FLAG(p->cap,
14166 PEER_CAP_RESTART_ADV)
14167 ? "and "
14168 : "");
14169 vty_out(vty, "\n");
14170
14171 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14172 int restart_af_count = 0;
14173
14174 vty_out(vty,
14175 " Remote Restart timer is %d seconds\n",
14176 p->v_gr_restart);
14177 vty_out(vty,
14178 " Address families by peer:\n ");
14179
14180 FOREACH_AFI_SAFI (afi, safi)
14181 if (CHECK_FLAG(
14182 p->af_cap[afi]
14183 [safi],
14184 PEER_CAP_RESTART_AF_RCV)) {
14185 vty_out(vty, "%s%s(%s)",
14186 restart_af_count
14187 ? ", "
14188 : "",
14189 get_afi_safi_str(
14190 afi,
14191 safi,
14192 false),
14193 CHECK_FLAG(
14194 p->af_cap
14195 [afi]
14196 [safi],
14197 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14198 ? "preserved"
14199 : "not preserved");
14200 restart_af_count++;
14201 }
14202 if (!restart_af_count)
14203 vty_out(vty, "none");
14204 vty_out(vty, "\n");
14205 }
14206 } /* Graceful Restart */
14207 }
14208 }
14209
14210 /* graceful restart information */
14211 json_object *json_grace = NULL;
14212 json_object *json_grace_send = NULL;
14213 json_object *json_grace_recv = NULL;
14214 int eor_send_af_count = 0;
14215 int eor_receive_af_count = 0;
14216
14217 if (use_json) {
14218 json_grace = json_object_new_object();
14219 json_grace_send = json_object_new_object();
14220 json_grace_recv = json_object_new_object();
14221
14222 if ((peer_established(p)) &&
14223 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14224 FOREACH_AFI_SAFI (afi, safi) {
14225 if (CHECK_FLAG(p->af_sflags[afi][safi],
14226 PEER_STATUS_EOR_SEND)) {
14227 json_object_boolean_true_add(
14228 json_grace_send,
14229 get_afi_safi_str(afi, safi,
14230 true));
14231 eor_send_af_count++;
14232 }
14233 }
14234 FOREACH_AFI_SAFI (afi, safi) {
14235 if (CHECK_FLAG(p->af_sflags[afi][safi],
14236 PEER_STATUS_EOR_RECEIVED)) {
14237 json_object_boolean_true_add(
14238 json_grace_recv,
14239 get_afi_safi_str(afi, safi,
14240 true));
14241 eor_receive_af_count++;
14242 }
14243 }
14244 }
14245 json_object_object_add(json_grace, "endOfRibSend",
14246 json_grace_send);
14247 json_object_object_add(json_grace, "endOfRibRecv",
14248 json_grace_recv);
14249
14250
14251 if (p->t_gr_restart)
14252 json_object_int_add(
14253 json_grace, "gracefulRestartTimerMsecs",
14254 thread_timer_remain_second(p->t_gr_restart) *
14255 1000);
14256
14257 if (p->t_gr_stale)
14258 json_object_int_add(
14259 json_grace, "gracefulStalepathTimerMsecs",
14260 thread_timer_remain_second(p->t_gr_stale) *
14261 1000);
14262 /* more gr info in new format */
14263 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14264 json_object_object_add(json_neigh, "gracefulRestartInfo",
14265 json_grace);
14266 } else {
14267 vty_out(vty, " Graceful restart information:\n");
14268 if ((peer_established(p)) &&
14269 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14270
14271 vty_out(vty, " End-of-RIB send: ");
14272 FOREACH_AFI_SAFI (afi, safi) {
14273 if (CHECK_FLAG(p->af_sflags[afi][safi],
14274 PEER_STATUS_EOR_SEND)) {
14275 vty_out(vty, "%s%s",
14276 eor_send_af_count ? ", " : "",
14277 get_afi_safi_str(afi, safi,
14278 false));
14279 eor_send_af_count++;
14280 }
14281 }
14282 vty_out(vty, "\n");
14283 vty_out(vty, " End-of-RIB received: ");
14284 FOREACH_AFI_SAFI (afi, safi) {
14285 if (CHECK_FLAG(p->af_sflags[afi][safi],
14286 PEER_STATUS_EOR_RECEIVED)) {
14287 vty_out(vty, "%s%s",
14288 eor_receive_af_count ? ", "
14289 : "",
14290 get_afi_safi_str(afi, safi,
14291 false));
14292 eor_receive_af_count++;
14293 }
14294 }
14295 vty_out(vty, "\n");
14296 }
14297
14298 if (p->t_gr_restart)
14299 vty_out(vty,
14300 " The remaining time of restart timer is %ld\n",
14301 thread_timer_remain_second(p->t_gr_restart));
14302
14303 if (p->t_gr_stale)
14304 vty_out(vty,
14305 " The remaining time of stalepath timer is %ld\n",
14306 thread_timer_remain_second(p->t_gr_stale));
14307
14308 /* more gr info in new format */
14309 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14310 }
14311
14312 if (use_json) {
14313 json_object *json_stat = NULL;
14314 json_stat = json_object_new_object();
14315 /* Packet counts. */
14316
14317 atomic_size_t outq_count, inq_count;
14318 outq_count = atomic_load_explicit(&p->obuf->count,
14319 memory_order_relaxed);
14320 inq_count = atomic_load_explicit(&p->ibuf->count,
14321 memory_order_relaxed);
14322
14323 json_object_int_add(json_stat, "depthInq",
14324 (unsigned long)inq_count);
14325 json_object_int_add(json_stat, "depthOutq",
14326 (unsigned long)outq_count);
14327 json_object_int_add(json_stat, "opensSent",
14328 atomic_load_explicit(&p->open_out,
14329 memory_order_relaxed));
14330 json_object_int_add(json_stat, "opensRecv",
14331 atomic_load_explicit(&p->open_in,
14332 memory_order_relaxed));
14333 json_object_int_add(json_stat, "notificationsSent",
14334 atomic_load_explicit(&p->notify_out,
14335 memory_order_relaxed));
14336 json_object_int_add(json_stat, "notificationsRecv",
14337 atomic_load_explicit(&p->notify_in,
14338 memory_order_relaxed));
14339 json_object_int_add(json_stat, "updatesSent",
14340 atomic_load_explicit(&p->update_out,
14341 memory_order_relaxed));
14342 json_object_int_add(json_stat, "updatesRecv",
14343 atomic_load_explicit(&p->update_in,
14344 memory_order_relaxed));
14345 json_object_int_add(json_stat, "keepalivesSent",
14346 atomic_load_explicit(&p->keepalive_out,
14347 memory_order_relaxed));
14348 json_object_int_add(json_stat, "keepalivesRecv",
14349 atomic_load_explicit(&p->keepalive_in,
14350 memory_order_relaxed));
14351 json_object_int_add(json_stat, "routeRefreshSent",
14352 atomic_load_explicit(&p->refresh_out,
14353 memory_order_relaxed));
14354 json_object_int_add(json_stat, "routeRefreshRecv",
14355 atomic_load_explicit(&p->refresh_in,
14356 memory_order_relaxed));
14357 json_object_int_add(json_stat, "capabilitySent",
14358 atomic_load_explicit(&p->dynamic_cap_out,
14359 memory_order_relaxed));
14360 json_object_int_add(json_stat, "capabilityRecv",
14361 atomic_load_explicit(&p->dynamic_cap_in,
14362 memory_order_relaxed));
14363 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14364 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14365 json_object_object_add(json_neigh, "messageStats", json_stat);
14366 } else {
14367 atomic_size_t outq_count, inq_count, open_out, open_in,
14368 notify_out, notify_in, update_out, update_in,
14369 keepalive_out, keepalive_in, refresh_out, refresh_in,
14370 dynamic_cap_out, dynamic_cap_in;
14371 outq_count = atomic_load_explicit(&p->obuf->count,
14372 memory_order_relaxed);
14373 inq_count = atomic_load_explicit(&p->ibuf->count,
14374 memory_order_relaxed);
14375 open_out = atomic_load_explicit(&p->open_out,
14376 memory_order_relaxed);
14377 open_in =
14378 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14379 notify_out = atomic_load_explicit(&p->notify_out,
14380 memory_order_relaxed);
14381 notify_in = atomic_load_explicit(&p->notify_in,
14382 memory_order_relaxed);
14383 update_out = atomic_load_explicit(&p->update_out,
14384 memory_order_relaxed);
14385 update_in = atomic_load_explicit(&p->update_in,
14386 memory_order_relaxed);
14387 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14388 memory_order_relaxed);
14389 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14390 memory_order_relaxed);
14391 refresh_out = atomic_load_explicit(&p->refresh_out,
14392 memory_order_relaxed);
14393 refresh_in = atomic_load_explicit(&p->refresh_in,
14394 memory_order_relaxed);
14395 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14396 memory_order_relaxed);
14397 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14398 memory_order_relaxed);
14399
14400 /* Packet counts. */
14401 vty_out(vty, " Message statistics:\n");
14402 vty_out(vty, " Inq depth is %zu\n", inq_count);
14403 vty_out(vty, " Outq depth is %zu\n", outq_count);
14404 vty_out(vty, " Sent Rcvd\n");
14405 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14406 open_in);
14407 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14408 notify_in);
14409 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14410 update_in);
14411 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14412 keepalive_in);
14413 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14414 refresh_in);
14415 vty_out(vty, " Capability: %10zu %10zu\n",
14416 dynamic_cap_out, dynamic_cap_in);
14417 vty_out(vty, " Total: %10u %10u\n",
14418 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14419 }
14420
14421 if (use_json) {
14422 /* advertisement-interval */
14423 json_object_int_add(json_neigh,
14424 "minBtwnAdvertisementRunsTimerMsecs",
14425 p->v_routeadv * 1000);
14426
14427 /* Update-source. */
14428 if (p->update_if || p->update_source) {
14429 if (p->update_if)
14430 json_object_string_add(json_neigh,
14431 "updateSource",
14432 p->update_if);
14433 else if (p->update_source)
14434 json_object_string_addf(json_neigh,
14435 "updateSource", "%pSU",
14436 p->update_source);
14437 }
14438 } else {
14439 /* advertisement-interval */
14440 vty_out(vty,
14441 " Minimum time between advertisement runs is %d seconds\n",
14442 p->v_routeadv);
14443
14444 /* Update-source. */
14445 if (p->update_if || p->update_source) {
14446 vty_out(vty, " Update source is ");
14447 if (p->update_if)
14448 vty_out(vty, "%s", p->update_if);
14449 else if (p->update_source)
14450 vty_out(vty, "%pSU", p->update_source);
14451 vty_out(vty, "\n");
14452 }
14453
14454 vty_out(vty, "\n");
14455 }
14456
14457 /* Address Family Information */
14458 json_object *json_hold = NULL;
14459
14460 if (use_json)
14461 json_hold = json_object_new_object();
14462
14463 FOREACH_AFI_SAFI (afi, safi)
14464 if (p->afc[afi][safi])
14465 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14466 json_hold);
14467
14468 if (use_json) {
14469 json_object_object_add(json_neigh, "addressFamilyInfo",
14470 json_hold);
14471 json_object_int_add(json_neigh, "connectionsEstablished",
14472 p->established);
14473 json_object_int_add(json_neigh, "connectionsDropped",
14474 p->dropped);
14475 } else
14476 vty_out(vty, " Connections established %d; dropped %d\n",
14477 p->established, p->dropped);
14478
14479 if (!p->last_reset) {
14480 if (use_json)
14481 json_object_string_add(json_neigh, "lastReset",
14482 "never");
14483 else
14484 vty_out(vty, " Last reset never\n");
14485 } else {
14486 if (use_json) {
14487 time_t uptime;
14488 struct tm tm;
14489
14490 uptime = monotime(NULL);
14491 uptime -= p->resettime;
14492 gmtime_r(&uptime, &tm);
14493
14494 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14495 (tm.tm_sec * 1000)
14496 + (tm.tm_min * 60000)
14497 + (tm.tm_hour * 3600000));
14498 bgp_show_peer_reset(NULL, p, json_neigh, true);
14499 } else {
14500 vty_out(vty, " Last reset %s, ",
14501 peer_uptime(p->resettime, timebuf,
14502 BGP_UPTIME_LEN, 0, NULL));
14503
14504 bgp_show_peer_reset(vty, p, NULL, false);
14505 if (p->last_reset_cause_size) {
14506 msg = p->last_reset_cause;
14507 vty_out(vty,
14508 " Message received that caused BGP to send a NOTIFICATION:\n ");
14509 for (i = 1; i <= p->last_reset_cause_size;
14510 i++) {
14511 vty_out(vty, "%02X", *msg++);
14512
14513 if (i != p->last_reset_cause_size) {
14514 if (i % 16 == 0) {
14515 vty_out(vty, "\n ");
14516 } else if (i % 4 == 0) {
14517 vty_out(vty, " ");
14518 }
14519 }
14520 }
14521 vty_out(vty, "\n");
14522 }
14523 }
14524 }
14525
14526 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14527 if (use_json)
14528 json_object_boolean_true_add(json_neigh,
14529 "prefixesConfigExceedMax");
14530 else
14531 vty_out(vty,
14532 " Peer had exceeded the max. no. of prefixes configured.\n");
14533
14534 if (p->t_pmax_restart) {
14535 if (use_json) {
14536 json_object_boolean_true_add(
14537 json_neigh, "reducePrefixNumFrom");
14538 json_object_int_add(json_neigh,
14539 "restartInTimerMsec",
14540 thread_timer_remain_second(
14541 p->t_pmax_restart)
14542 * 1000);
14543 } else
14544 vty_out(vty,
14545 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14546 p->host, thread_timer_remain_second(
14547 p->t_pmax_restart));
14548 } else {
14549 if (use_json)
14550 json_object_boolean_true_add(
14551 json_neigh,
14552 "reducePrefixNumAndClearIpBgp");
14553 else
14554 vty_out(vty,
14555 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14556 p->host);
14557 }
14558 }
14559
14560 /* EBGP Multihop and GTSM */
14561 if (p->sort != BGP_PEER_IBGP) {
14562 if (use_json) {
14563 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14564 json_object_int_add(json_neigh,
14565 "externalBgpNbrMaxHopsAway",
14566 p->gtsm_hops);
14567 else
14568 json_object_int_add(json_neigh,
14569 "externalBgpNbrMaxHopsAway",
14570 p->ttl);
14571 } else {
14572 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14573 vty_out(vty,
14574 " External BGP neighbor may be up to %d hops away.\n",
14575 p->gtsm_hops);
14576 else
14577 vty_out(vty,
14578 " External BGP neighbor may be up to %d hops away.\n",
14579 p->ttl);
14580 }
14581 } else {
14582 if (use_json) {
14583 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14584 json_object_int_add(json_neigh,
14585 "internalBgpNbrMaxHopsAway",
14586 p->gtsm_hops);
14587 else
14588 json_object_int_add(json_neigh,
14589 "internalBgpNbrMaxHopsAway",
14590 p->ttl);
14591 } else {
14592 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14593 vty_out(vty,
14594 " Internal BGP neighbor may be up to %d hops away.\n",
14595 p->gtsm_hops);
14596 else
14597 vty_out(vty,
14598 " Internal BGP neighbor may be up to %d hops away.\n",
14599 p->ttl);
14600 }
14601 }
14602
14603 /* Local address. */
14604 if (p->su_local) {
14605 if (use_json) {
14606 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14607 p->su_local);
14608 json_object_int_add(json_neigh, "portLocal",
14609 ntohs(p->su_local->sin.sin_port));
14610 } else
14611 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14612 p->su_local, ntohs(p->su_local->sin.sin_port));
14613 } else {
14614 if (use_json) {
14615 json_object_string_add(json_neigh, "hostLocal",
14616 "Unknown");
14617 json_object_int_add(json_neigh, "portLocal", -1);
14618 }
14619 }
14620
14621 /* Remote address. */
14622 if (p->su_remote) {
14623 if (use_json) {
14624 json_object_string_addf(json_neigh, "hostForeign",
14625 "%pSU", p->su_remote);
14626 json_object_int_add(json_neigh, "portForeign",
14627 ntohs(p->su_remote->sin.sin_port));
14628 } else
14629 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14630 p->su_remote,
14631 ntohs(p->su_remote->sin.sin_port));
14632 } else {
14633 if (use_json) {
14634 json_object_string_add(json_neigh, "hostForeign",
14635 "Unknown");
14636 json_object_int_add(json_neigh, "portForeign", -1);
14637 }
14638 }
14639
14640 /* Nexthop display. */
14641 if (p->su_local) {
14642 if (use_json) {
14643 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14644 &p->nexthop.v4);
14645 json_object_string_addf(json_neigh, "nexthopGlobal",
14646 "%pI6", &p->nexthop.v6_global);
14647 json_object_string_addf(json_neigh, "nexthopLocal",
14648 "%pI6", &p->nexthop.v6_local);
14649 if (p->shared_network)
14650 json_object_string_add(json_neigh,
14651 "bgpConnection",
14652 "sharedNetwork");
14653 else
14654 json_object_string_add(json_neigh,
14655 "bgpConnection",
14656 "nonSharedNetwork");
14657 } else {
14658 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14659 vty_out(vty, "Nexthop global: %pI6\n",
14660 &p->nexthop.v6_global);
14661 vty_out(vty, "Nexthop local: %pI6\n",
14662 &p->nexthop.v6_local);
14663 vty_out(vty, "BGP connection: %s\n",
14664 p->shared_network ? "shared network"
14665 : "non shared network");
14666 }
14667 } else {
14668 if (use_json) {
14669 json_object_string_add(json_neigh, "nexthop",
14670 "Unknown");
14671 json_object_string_add(json_neigh, "nexthopGlobal",
14672 "Unknown");
14673 json_object_string_add(json_neigh, "nexthopLocal",
14674 "Unknown");
14675 json_object_string_add(json_neigh, "bgpConnection",
14676 "Unknown");
14677 }
14678 }
14679
14680 /* Timer information. */
14681 if (use_json) {
14682 json_object_int_add(json_neigh, "connectRetryTimer",
14683 p->v_connect);
14684 if (peer_established(p)) {
14685 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14686 p->rtt);
14687 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14688 json_object_int_add(json_neigh,
14689 "shutdownRttInMsecs",
14690 p->rtt_expected);
14691 json_object_int_add(json_neigh,
14692 "shutdownRttAfterCount",
14693 p->rtt_keepalive_rcv);
14694 }
14695 }
14696 if (p->t_start)
14697 json_object_int_add(
14698 json_neigh, "nextStartTimerDueInMsecs",
14699 thread_timer_remain_second(p->t_start) * 1000);
14700 if (p->t_connect)
14701 json_object_int_add(
14702 json_neigh, "nextConnectTimerDueInMsecs",
14703 thread_timer_remain_second(p->t_connect)
14704 * 1000);
14705 if (p->t_routeadv) {
14706 json_object_int_add(json_neigh, "mraiInterval",
14707 p->v_routeadv);
14708 json_object_int_add(
14709 json_neigh, "mraiTimerExpireInMsecs",
14710 thread_timer_remain_second(p->t_routeadv)
14711 * 1000);
14712 }
14713 if (p->password)
14714 json_object_int_add(json_neigh, "authenticationEnabled",
14715 1);
14716
14717 if (p->t_read)
14718 json_object_string_add(json_neigh, "readThread", "on");
14719 else
14720 json_object_string_add(json_neigh, "readThread", "off");
14721
14722 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14723 json_object_string_add(json_neigh, "writeThread", "on");
14724 else
14725 json_object_string_add(json_neigh, "writeThread",
14726 "off");
14727 } else {
14728 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14729 p->v_connect);
14730 if (peer_established(p)) {
14731 vty_out(vty, "Estimated round trip time: %d ms\n",
14732 p->rtt);
14733 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14734 vty_out(vty,
14735 "Shutdown when RTT > %dms, count > %u\n",
14736 p->rtt_expected, p->rtt_keepalive_rcv);
14737 }
14738 if (p->t_start)
14739 vty_out(vty, "Next start timer due in %ld seconds\n",
14740 thread_timer_remain_second(p->t_start));
14741 if (p->t_connect)
14742 vty_out(vty, "Next connect timer due in %ld seconds\n",
14743 thread_timer_remain_second(p->t_connect));
14744 if (p->t_routeadv)
14745 vty_out(vty,
14746 "MRAI (interval %u) timer expires in %ld seconds\n",
14747 p->v_routeadv,
14748 thread_timer_remain_second(p->t_routeadv));
14749 if (p->password)
14750 vty_out(vty, "Peer Authentication Enabled\n");
14751
14752 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14753 p->t_read ? "on" : "off",
14754 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14755 ? "on"
14756 : "off", p->fd);
14757 }
14758
14759 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14760 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14761 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14762
14763 if (!use_json)
14764 vty_out(vty, "\n");
14765
14766 /* BFD information. */
14767 if (p->bfd_config)
14768 bgp_bfd_show_info(vty, p, json_neigh);
14769
14770 if (use_json) {
14771 if (p->conf_if) /* Configured interface name. */
14772 json_object_object_add(json, p->conf_if, json_neigh);
14773 else /* Configured IP address. */
14774 json_object_object_add(json, p->host, json_neigh);
14775 }
14776 }
14777
14778 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14779 enum show_type type,
14780 union sockunion *su,
14781 const char *conf_if, afi_t afi,
14782 json_object *json)
14783 {
14784 struct listnode *node, *nnode;
14785 struct peer *peer;
14786 bool found = false;
14787 safi_t safi = SAFI_UNICAST;
14788 json_object *json_neighbor = NULL;
14789
14790 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14791
14792 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14793 continue;
14794
14795 if ((peer->afc[afi][safi]) == 0)
14796 continue;
14797
14798 if (json)
14799 json_neighbor = json_object_new_object();
14800
14801 if (type == show_all) {
14802 bgp_show_peer_gr_status(vty, peer, json_neighbor);
14803
14804 if (json)
14805 json_object_object_add(json, peer->host,
14806 json_neighbor);
14807
14808 } else if (type == show_peer) {
14809 if (conf_if) {
14810 if ((peer->conf_if
14811 && !strcmp(peer->conf_if, conf_if))
14812 || (peer->hostname
14813 && !strcmp(peer->hostname, conf_if))) {
14814 found = true;
14815 bgp_show_peer_gr_status(vty, peer,
14816 json_neighbor);
14817 }
14818 } else {
14819 if (sockunion_same(&peer->su, su)) {
14820 found = true;
14821 bgp_show_peer_gr_status(vty, peer,
14822 json_neighbor);
14823 }
14824 }
14825 if (json) {
14826 if (found)
14827 json_object_object_add(json, peer->host,
14828 json_neighbor);
14829 else
14830 json_object_free(json_neighbor);
14831 }
14832 }
14833
14834 if (found)
14835 break;
14836 }
14837
14838 if (type == show_peer && !found) {
14839 if (json)
14840 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14841 else
14842 vty_out(vty, "%% No such neighbor\n");
14843 }
14844
14845 if (!json)
14846 vty_out(vty, "\n");
14847
14848 return CMD_SUCCESS;
14849 }
14850
14851 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14852 enum show_type type, union sockunion *su,
14853 const char *conf_if, bool use_json,
14854 json_object *json)
14855 {
14856 struct listnode *node, *nnode;
14857 struct peer *peer;
14858 int find = 0;
14859 bool nbr_output = false;
14860 afi_t afi = AFI_MAX;
14861 safi_t safi = SAFI_MAX;
14862
14863 if (type == show_ipv4_peer || type == show_ipv4_all) {
14864 afi = AFI_IP;
14865 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14866 afi = AFI_IP6;
14867 }
14868
14869 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14870 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14871 continue;
14872
14873 switch (type) {
14874 case show_all:
14875 bgp_show_peer(vty, peer, use_json, json);
14876 nbr_output = true;
14877 break;
14878 case show_peer:
14879 if (conf_if) {
14880 if ((peer->conf_if
14881 && !strcmp(peer->conf_if, conf_if))
14882 || (peer->hostname
14883 && !strcmp(peer->hostname, conf_if))) {
14884 find = 1;
14885 bgp_show_peer(vty, peer, use_json,
14886 json);
14887 }
14888 } else {
14889 if (sockunion_same(&peer->su, su)) {
14890 find = 1;
14891 bgp_show_peer(vty, peer, use_json,
14892 json);
14893 }
14894 }
14895 break;
14896 case show_ipv4_peer:
14897 case show_ipv6_peer:
14898 FOREACH_SAFI (safi) {
14899 if (peer->afc[afi][safi]) {
14900 if (conf_if) {
14901 if ((peer->conf_if
14902 && !strcmp(peer->conf_if, conf_if))
14903 || (peer->hostname
14904 && !strcmp(peer->hostname, conf_if))) {
14905 find = 1;
14906 bgp_show_peer(vty, peer, use_json,
14907 json);
14908 break;
14909 }
14910 } else {
14911 if (sockunion_same(&peer->su, su)) {
14912 find = 1;
14913 bgp_show_peer(vty, peer, use_json,
14914 json);
14915 break;
14916 }
14917 }
14918 }
14919 }
14920 break;
14921 case show_ipv4_all:
14922 case show_ipv6_all:
14923 FOREACH_SAFI (safi) {
14924 if (peer->afc[afi][safi]) {
14925 bgp_show_peer(vty, peer, use_json, json);
14926 nbr_output = true;
14927 break;
14928 }
14929 }
14930 break;
14931 }
14932 }
14933
14934 if ((type == show_peer || type == show_ipv4_peer ||
14935 type == show_ipv6_peer) && !find) {
14936 if (use_json)
14937 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14938 else
14939 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14940 }
14941
14942 if (type != show_peer && type != show_ipv4_peer &&
14943 type != show_ipv6_peer && !nbr_output && !use_json)
14944 vty_out(vty, "%% No BGP neighbors found\n");
14945
14946 if (use_json) {
14947 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14948 json, JSON_C_TO_STRING_PRETTY));
14949 } else {
14950 vty_out(vty, "\n");
14951 }
14952
14953 return CMD_SUCCESS;
14954 }
14955
14956 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14957 enum show_type type,
14958 const char *ip_str,
14959 afi_t afi, json_object *json)
14960 {
14961
14962 int ret;
14963 struct bgp *bgp;
14964 union sockunion su;
14965
14966 bgp = bgp_get_default();
14967
14968 if (!bgp)
14969 return;
14970
14971 if (!json)
14972 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
14973
14974 if (ip_str) {
14975 ret = str2sockunion(ip_str, &su);
14976 if (ret < 0)
14977 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
14978 ip_str, afi, json);
14979 else
14980 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14981 NULL, afi, json);
14982 } else
14983 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14984 afi, json);
14985 }
14986
14987 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14988 enum show_type type,
14989 const char *ip_str,
14990 bool use_json)
14991 {
14992 struct listnode *node, *nnode;
14993 struct bgp *bgp;
14994 union sockunion su;
14995 json_object *json = NULL;
14996 int ret, is_first = 1;
14997 bool nbr_output = false;
14998
14999 if (use_json)
15000 vty_out(vty, "{\n");
15001
15002 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15003 nbr_output = true;
15004 if (use_json) {
15005 if (!(json = json_object_new_object())) {
15006 flog_err(
15007 EC_BGP_JSON_MEM_ERROR,
15008 "Unable to allocate memory for JSON object");
15009 vty_out(vty,
15010 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15011 return;
15012 }
15013
15014 json_object_int_add(json, "vrfId",
15015 (bgp->vrf_id == VRF_UNKNOWN)
15016 ? -1
15017 : (int64_t)bgp->vrf_id);
15018 json_object_string_add(
15019 json, "vrfName",
15020 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15021 ? VRF_DEFAULT_NAME
15022 : bgp->name);
15023
15024 if (!is_first)
15025 vty_out(vty, ",\n");
15026 else
15027 is_first = 0;
15028
15029 vty_out(vty, "\"%s\":",
15030 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15031 ? VRF_DEFAULT_NAME
15032 : bgp->name);
15033 } else {
15034 vty_out(vty, "\nInstance %s:\n",
15035 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15036 ? VRF_DEFAULT_NAME
15037 : bgp->name);
15038 }
15039
15040 if (type == show_peer || type == show_ipv4_peer ||
15041 type == show_ipv6_peer) {
15042 ret = str2sockunion(ip_str, &su);
15043 if (ret < 0)
15044 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15045 use_json, json);
15046 else
15047 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15048 use_json, json);
15049 } else {
15050 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15051 use_json, json);
15052 }
15053 json_object_free(json);
15054 json = NULL;
15055 }
15056
15057 if (use_json)
15058 vty_out(vty, "}\n");
15059 else if (!nbr_output)
15060 vty_out(vty, "%% BGP instance not found\n");
15061 }
15062
15063 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15064 enum show_type type, const char *ip_str,
15065 bool use_json)
15066 {
15067 int ret;
15068 struct bgp *bgp;
15069 union sockunion su;
15070 json_object *json = NULL;
15071
15072 if (name) {
15073 if (strmatch(name, "all")) {
15074 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15075 use_json);
15076 return CMD_SUCCESS;
15077 } else {
15078 bgp = bgp_lookup_by_name(name);
15079 if (!bgp) {
15080 if (use_json) {
15081 json = json_object_new_object();
15082 vty_json(vty, json);
15083 } else
15084 vty_out(vty,
15085 "%% BGP instance not found\n");
15086
15087 return CMD_WARNING;
15088 }
15089 }
15090 } else {
15091 bgp = bgp_get_default();
15092 }
15093
15094 if (bgp) {
15095 json = json_object_new_object();
15096 if (ip_str) {
15097 ret = str2sockunion(ip_str, &su);
15098 if (ret < 0)
15099 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15100 use_json, json);
15101 else
15102 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15103 use_json, json);
15104 } else {
15105 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15106 json);
15107 }
15108 json_object_free(json);
15109 } else {
15110 if (use_json)
15111 vty_out(vty, "{}\n");
15112 else
15113 vty_out(vty, "%% BGP instance not found\n");
15114 }
15115
15116 return CMD_SUCCESS;
15117 }
15118
15119
15120
15121 /* "show [ip] bgp neighbors graceful-restart" commands. */
15122 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15123 show_ip_bgp_neighbors_graceful_restart_cmd,
15124 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15125 SHOW_STR
15126 BGP_STR
15127 IP_STR
15128 IPV6_STR
15129 NEIGHBOR_STR
15130 "Neighbor to display information about\n"
15131 "Neighbor to display information about\n"
15132 "Neighbor on BGP configured interface\n"
15133 GR_SHOW
15134 JSON_STR)
15135 {
15136 char *sh_arg = NULL;
15137 enum show_type sh_type;
15138 int idx = 0;
15139 afi_t afi = AFI_MAX;
15140 bool uj = use_json(argc, argv);
15141
15142 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15143 afi = AFI_MAX;
15144
15145 idx++;
15146
15147 if (argv_find(argv, argc, "A.B.C.D", &idx)
15148 || argv_find(argv, argc, "X:X::X:X", &idx)
15149 || argv_find(argv, argc, "WORD", &idx)) {
15150 sh_type = show_peer;
15151 sh_arg = argv[idx]->arg;
15152 } else
15153 sh_type = show_all;
15154
15155 if (!argv_find(argv, argc, "graceful-restart", &idx))
15156 return CMD_SUCCESS;
15157
15158
15159 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15160 afi, uj);
15161 }
15162
15163 /* "show [ip] bgp neighbors" commands. */
15164 DEFUN (show_ip_bgp_neighbors,
15165 show_ip_bgp_neighbors_cmd,
15166 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15167 SHOW_STR
15168 IP_STR
15169 BGP_STR
15170 BGP_INSTANCE_HELP_STR
15171 BGP_AF_STR
15172 BGP_AF_STR
15173 "Detailed information on TCP and BGP neighbor connections\n"
15174 "Neighbor to display information about\n"
15175 "Neighbor to display information about\n"
15176 "Neighbor on BGP configured interface\n"
15177 JSON_STR)
15178 {
15179 char *vrf = NULL;
15180 char *sh_arg = NULL;
15181 enum show_type sh_type;
15182 afi_t afi = AFI_MAX;
15183
15184 bool uj = use_json(argc, argv);
15185
15186 int idx = 0;
15187
15188 /* [<vrf> VIEWVRFNAME] */
15189 if (argv_find(argv, argc, "vrf", &idx)) {
15190 vrf = argv[idx + 1]->arg;
15191 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15192 vrf = NULL;
15193 } else if (argv_find(argv, argc, "view", &idx))
15194 /* [<view> VIEWVRFNAME] */
15195 vrf = argv[idx + 1]->arg;
15196
15197 idx++;
15198
15199 if (argv_find(argv, argc, "ipv4", &idx)) {
15200 sh_type = show_ipv4_all;
15201 afi = AFI_IP;
15202 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15203 sh_type = show_ipv6_all;
15204 afi = AFI_IP6;
15205 } else {
15206 sh_type = show_all;
15207 }
15208
15209 if (argv_find(argv, argc, "A.B.C.D", &idx)
15210 || argv_find(argv, argc, "X:X::X:X", &idx)
15211 || argv_find(argv, argc, "WORD", &idx)) {
15212 sh_type = show_peer;
15213 sh_arg = argv[idx]->arg;
15214 }
15215
15216 if (sh_type == show_peer && afi == AFI_IP) {
15217 sh_type = show_ipv4_peer;
15218 } else if (sh_type == show_peer && afi == AFI_IP6) {
15219 sh_type = show_ipv6_peer;
15220 }
15221
15222 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15223 }
15224
15225 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15226 paths' and `show ip mbgp paths'. Those functions results are the
15227 same.*/
15228 DEFUN (show_ip_bgp_paths,
15229 show_ip_bgp_paths_cmd,
15230 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15231 SHOW_STR
15232 IP_STR
15233 BGP_STR
15234 BGP_SAFI_HELP_STR
15235 "Path information\n")
15236 {
15237 vty_out(vty, "Address Refcnt Path\n");
15238 aspath_print_all_vty(vty);
15239 return CMD_SUCCESS;
15240 }
15241
15242 #include "hash.h"
15243
15244 static void community_show_all_iterator(struct hash_bucket *bucket,
15245 struct vty *vty)
15246 {
15247 struct community *com;
15248
15249 com = (struct community *)bucket->data;
15250 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15251 community_str(com, false, false));
15252 }
15253
15254 /* Show BGP's community internal data. */
15255 DEFUN (show_ip_bgp_community_info,
15256 show_ip_bgp_community_info_cmd,
15257 "show [ip] bgp community-info",
15258 SHOW_STR
15259 IP_STR
15260 BGP_STR
15261 "List all bgp community information\n")
15262 {
15263 vty_out(vty, "Address Refcnt Community\n");
15264
15265 hash_iterate(community_hash(),
15266 (void (*)(struct hash_bucket *,
15267 void *))community_show_all_iterator,
15268 vty);
15269
15270 return CMD_SUCCESS;
15271 }
15272
15273 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15274 struct vty *vty)
15275 {
15276 struct lcommunity *lcom;
15277
15278 lcom = (struct lcommunity *)bucket->data;
15279 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15280 lcommunity_str(lcom, false, false));
15281 }
15282
15283 /* Show BGP's community internal data. */
15284 DEFUN (show_ip_bgp_lcommunity_info,
15285 show_ip_bgp_lcommunity_info_cmd,
15286 "show ip bgp large-community-info",
15287 SHOW_STR
15288 IP_STR
15289 BGP_STR
15290 "List all bgp large-community information\n")
15291 {
15292 vty_out(vty, "Address Refcnt Large-community\n");
15293
15294 hash_iterate(lcommunity_hash(),
15295 (void (*)(struct hash_bucket *,
15296 void *))lcommunity_show_all_iterator,
15297 vty);
15298
15299 return CMD_SUCCESS;
15300 }
15301 /* Graceful Restart */
15302
15303 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15304 struct bgp *bgp)
15305 {
15306
15307
15308 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15309
15310 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15311
15312 switch (bgp_global_gr_mode) {
15313
15314 case GLOBAL_HELPER:
15315 vty_out(vty, "Global BGP GR Mode : Helper\n");
15316 break;
15317
15318 case GLOBAL_GR:
15319 vty_out(vty, "Global BGP GR Mode : Restart\n");
15320 break;
15321
15322 case GLOBAL_DISABLE:
15323 vty_out(vty, "Global BGP GR Mode : Disable\n");
15324 break;
15325
15326 case GLOBAL_INVALID:
15327 vty_out(vty,
15328 "Global BGP GR Mode Invalid\n");
15329 break;
15330 }
15331 vty_out(vty, "\n");
15332 }
15333
15334 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15335 enum show_type type,
15336 const char *ip_str,
15337 afi_t afi, bool use_json)
15338 {
15339 json_object *json = NULL;
15340
15341 if (use_json)
15342 json = json_object_new_object();
15343
15344 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15345 afi = AFI_IP;
15346
15347 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15348
15349 bgp_show_neighbor_graceful_restart_vty(
15350 vty, type, ip_str, afi, json);
15351 afi++;
15352 }
15353 } else if (afi != AFI_MAX) {
15354 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15355 json);
15356 } else {
15357 if (json)
15358 json_object_free(json);
15359 return CMD_ERR_INCOMPLETE;
15360 }
15361
15362 if (json)
15363 vty_json(vty, json);
15364
15365 return CMD_SUCCESS;
15366 }
15367 /* Graceful Restart */
15368
15369 DEFUN (show_ip_bgp_attr_info,
15370 show_ip_bgp_attr_info_cmd,
15371 "show [ip] bgp attribute-info",
15372 SHOW_STR
15373 IP_STR
15374 BGP_STR
15375 "List all bgp attribute information\n")
15376 {
15377 attr_show_all(vty);
15378 return CMD_SUCCESS;
15379 }
15380
15381 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15382 afi_t afi, safi_t safi,
15383 bool use_json, json_object *json)
15384 {
15385 struct bgp *bgp;
15386 struct listnode *node;
15387 char *vname;
15388 char *ecom_str;
15389 enum vpn_policy_direction dir;
15390
15391 if (json) {
15392 json_object *json_import_vrfs = NULL;
15393 json_object *json_export_vrfs = NULL;
15394
15395 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15396
15397 if (!bgp) {
15398 vty_json(vty, json);
15399
15400 return CMD_WARNING;
15401 }
15402
15403 /* Provide context for the block */
15404 json_object_string_add(json, "vrf", name ? name : "default");
15405 json_object_string_add(json, "afiSafi",
15406 get_afi_safi_str(afi, safi, true));
15407
15408 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15409 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15410 json_object_string_add(json, "importFromVrfs", "none");
15411 json_object_string_add(json, "importRts", "none");
15412 } else {
15413 json_import_vrfs = json_object_new_array();
15414
15415 for (ALL_LIST_ELEMENTS_RO(
15416 bgp->vpn_policy[afi].import_vrf,
15417 node, vname))
15418 json_object_array_add(json_import_vrfs,
15419 json_object_new_string(vname));
15420
15421 json_object_object_add(json, "importFromVrfs",
15422 json_import_vrfs);
15423 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15424 if (bgp->vpn_policy[afi].rtlist[dir]) {
15425 ecom_str = ecommunity_ecom2str(
15426 bgp->vpn_policy[afi].rtlist[dir],
15427 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15428 json_object_string_add(json, "importRts",
15429 ecom_str);
15430 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15431 } else
15432 json_object_string_add(json, "importRts",
15433 "none");
15434 }
15435
15436 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15437 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15438 json_object_string_add(json, "exportToVrfs", "none");
15439 json_object_string_add(json, "routeDistinguisher",
15440 "none");
15441 json_object_string_add(json, "exportRts", "none");
15442 } else {
15443 json_export_vrfs = json_object_new_array();
15444
15445 for (ALL_LIST_ELEMENTS_RO(
15446 bgp->vpn_policy[afi].export_vrf,
15447 node, vname))
15448 json_object_array_add(json_export_vrfs,
15449 json_object_new_string(vname));
15450 json_object_object_add(json, "exportToVrfs",
15451 json_export_vrfs);
15452 json_object_string_addf(json, "routeDistinguisher",
15453 "%pRD",
15454 &bgp->vpn_policy[afi].tovpn_rd);
15455
15456 dir = BGP_VPN_POLICY_DIR_TOVPN;
15457 if (bgp->vpn_policy[afi].rtlist[dir]) {
15458 ecom_str = ecommunity_ecom2str(
15459 bgp->vpn_policy[afi].rtlist[dir],
15460 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15461 json_object_string_add(json, "exportRts",
15462 ecom_str);
15463 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15464 } else
15465 json_object_string_add(json, "exportRts",
15466 "none");
15467 }
15468
15469 if (use_json) {
15470 vty_json(vty, json);
15471 }
15472 } else {
15473 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15474
15475 if (!bgp) {
15476 vty_out(vty, "%% No such BGP instance exist\n");
15477 return CMD_WARNING;
15478 }
15479
15480 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15481 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15482 vty_out(vty,
15483 "This VRF is not importing %s routes from any other VRF\n",
15484 get_afi_safi_str(afi, safi, false));
15485 else {
15486 vty_out(vty,
15487 "This VRF is importing %s routes from the following VRFs:\n",
15488 get_afi_safi_str(afi, safi, false));
15489
15490 for (ALL_LIST_ELEMENTS_RO(
15491 bgp->vpn_policy[afi].import_vrf,
15492 node, vname))
15493 vty_out(vty, " %s\n", vname);
15494
15495 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15496 ecom_str = NULL;
15497 if (bgp->vpn_policy[afi].rtlist[dir]) {
15498 ecom_str = ecommunity_ecom2str(
15499 bgp->vpn_policy[afi].rtlist[dir],
15500 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15501 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15502
15503 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15504 } else
15505 vty_out(vty, "Import RT(s):\n");
15506 }
15507
15508 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15509 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15510 vty_out(vty,
15511 "This VRF is not exporting %s routes to any other VRF\n",
15512 get_afi_safi_str(afi, safi, false));
15513 else {
15514 vty_out(vty,
15515 "This VRF is exporting %s routes to the following VRFs:\n",
15516 get_afi_safi_str(afi, safi, false));
15517
15518 for (ALL_LIST_ELEMENTS_RO(
15519 bgp->vpn_policy[afi].export_vrf,
15520 node, vname))
15521 vty_out(vty, " %s\n", vname);
15522
15523 vty_out(vty, "RD: %pRD\n",
15524 &bgp->vpn_policy[afi].tovpn_rd);
15525
15526 dir = BGP_VPN_POLICY_DIR_TOVPN;
15527 if (bgp->vpn_policy[afi].rtlist[dir]) {
15528 ecom_str = ecommunity_ecom2str(
15529 bgp->vpn_policy[afi].rtlist[dir],
15530 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15531 vty_out(vty, "Export RT: %s\n", ecom_str);
15532 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15533 } else
15534 vty_out(vty, "Import RT(s):\n");
15535 }
15536 }
15537
15538 return CMD_SUCCESS;
15539 }
15540
15541 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15542 safi_t safi, bool use_json)
15543 {
15544 struct listnode *node, *nnode;
15545 struct bgp *bgp;
15546 char *vrf_name = NULL;
15547 json_object *json = NULL;
15548 json_object *json_vrf = NULL;
15549 json_object *json_vrfs = NULL;
15550
15551 if (use_json) {
15552 json = json_object_new_object();
15553 json_vrfs = json_object_new_object();
15554 }
15555
15556 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15557
15558 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15559 vrf_name = bgp->name;
15560
15561 if (use_json) {
15562 json_vrf = json_object_new_object();
15563 } else {
15564 vty_out(vty, "\nInstance %s:\n",
15565 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15566 ? VRF_DEFAULT_NAME : bgp->name);
15567 }
15568 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15569 if (use_json) {
15570 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15571 json_object_object_add(json_vrfs,
15572 VRF_DEFAULT_NAME, json_vrf);
15573 else
15574 json_object_object_add(json_vrfs, vrf_name,
15575 json_vrf);
15576 }
15577 }
15578
15579 if (use_json) {
15580 json_object_object_add(json, "vrfs", json_vrfs);
15581 vty_json(vty, json);
15582 }
15583
15584 return CMD_SUCCESS;
15585 }
15586
15587 /* "show [ip] bgp route-leak" command. */
15588 DEFUN (show_ip_bgp_route_leak,
15589 show_ip_bgp_route_leak_cmd,
15590 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15591 SHOW_STR
15592 IP_STR
15593 BGP_STR
15594 BGP_INSTANCE_HELP_STR
15595 BGP_AFI_HELP_STR
15596 BGP_SAFI_HELP_STR
15597 "Route leaking information\n"
15598 JSON_STR)
15599 {
15600 char *vrf = NULL;
15601 afi_t afi = AFI_MAX;
15602 safi_t safi = SAFI_MAX;
15603
15604 bool uj = use_json(argc, argv);
15605 int idx = 0;
15606 json_object *json = NULL;
15607
15608 /* show [ip] bgp */
15609 if (argv_find(argv, argc, "ip", &idx)) {
15610 afi = AFI_IP;
15611 safi = SAFI_UNICAST;
15612 }
15613 /* [vrf VIEWVRFNAME] */
15614 if (argv_find(argv, argc, "view", &idx)) {
15615 vty_out(vty,
15616 "%% This command is not applicable to BGP views\n");
15617 return CMD_WARNING;
15618 }
15619
15620 if (argv_find(argv, argc, "vrf", &idx)) {
15621 vrf = argv[idx + 1]->arg;
15622 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15623 vrf = NULL;
15624 }
15625 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15626 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15627 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15628
15629 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15630 vty_out(vty,
15631 "%% This command is applicable only for unicast ipv4|ipv6\n");
15632 return CMD_WARNING;
15633 }
15634
15635 if (vrf && strmatch(vrf, "all"))
15636 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15637
15638 if (uj)
15639 json = json_object_new_object();
15640
15641 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15642 }
15643
15644 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15645 safi_t safi, bool uj)
15646 {
15647 struct listnode *node, *nnode;
15648 struct bgp *bgp;
15649
15650 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15651 if (!uj)
15652 vty_out(vty, "\nInstance %s:\n",
15653 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15654 ? VRF_DEFAULT_NAME
15655 : bgp->name);
15656
15657 update_group_show(bgp, afi, safi, vty, 0, uj);
15658 }
15659 }
15660
15661 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15662 int safi, uint64_t subgrp_id, bool uj)
15663 {
15664 struct bgp *bgp;
15665
15666 if (name) {
15667 if (strmatch(name, "all")) {
15668 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15669 return CMD_SUCCESS;
15670 } else {
15671 bgp = bgp_lookup_by_name(name);
15672 }
15673 } else {
15674 bgp = bgp_get_default();
15675 }
15676
15677 if (bgp)
15678 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15679 return CMD_SUCCESS;
15680 }
15681
15682 DEFUN (show_ip_bgp_updgrps,
15683 show_ip_bgp_updgrps_cmd,
15684 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15685 SHOW_STR
15686 IP_STR
15687 BGP_STR
15688 BGP_INSTANCE_HELP_STR
15689 BGP_AFI_HELP_STR
15690 BGP_SAFI_WITH_LABEL_HELP_STR
15691 "Detailed info about dynamic update groups\n"
15692 "Specific subgroup to display detailed info for\n"
15693 JSON_STR)
15694 {
15695 char *vrf = NULL;
15696 afi_t afi = AFI_IP6;
15697 safi_t safi = SAFI_UNICAST;
15698 uint64_t subgrp_id = 0;
15699
15700 int idx = 0;
15701
15702 bool uj = use_json(argc, argv);
15703
15704 /* show [ip] bgp */
15705 if (argv_find(argv, argc, "ip", &idx))
15706 afi = AFI_IP;
15707 /* [<vrf> VIEWVRFNAME] */
15708 if (argv_find(argv, argc, "vrf", &idx)) {
15709 vrf = argv[idx + 1]->arg;
15710 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15711 vrf = NULL;
15712 } else if (argv_find(argv, argc, "view", &idx))
15713 /* [<view> VIEWVRFNAME] */
15714 vrf = argv[idx + 1]->arg;
15715 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15716 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15717 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15718 }
15719
15720 /* get subgroup id, if provided */
15721 idx = argc - 1;
15722 if (argv[idx]->type == VARIABLE_TKN)
15723 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15724
15725 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15726 }
15727
15728 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15729 show_bgp_instance_all_ipv6_updgrps_cmd,
15730 "show [ip] bgp <view|vrf> all update-groups [json]",
15731 SHOW_STR
15732 IP_STR
15733 BGP_STR
15734 BGP_INSTANCE_ALL_HELP_STR
15735 "Detailed info about dynamic update groups\n"
15736 JSON_STR)
15737 {
15738 bool uj = use_json(argc, argv);
15739
15740 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15741 return CMD_SUCCESS;
15742 }
15743
15744 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15745 show_bgp_l2vpn_evpn_updgrps_cmd,
15746 "show [ip] bgp l2vpn evpn update-groups",
15747 SHOW_STR
15748 IP_STR
15749 BGP_STR
15750 "l2vpn address family\n"
15751 "evpn sub-address family\n"
15752 "Detailed info about dynamic update groups\n")
15753 {
15754 char *vrf = NULL;
15755 uint64_t subgrp_id = 0;
15756
15757 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15758 return CMD_SUCCESS;
15759 }
15760
15761 DEFUN (show_bgp_updgrps_stats,
15762 show_bgp_updgrps_stats_cmd,
15763 "show [ip] bgp update-groups statistics",
15764 SHOW_STR
15765 IP_STR
15766 BGP_STR
15767 "Detailed info about dynamic update groups\n"
15768 "Statistics\n")
15769 {
15770 struct bgp *bgp;
15771
15772 bgp = bgp_get_default();
15773 if (bgp)
15774 update_group_show_stats(bgp, vty);
15775
15776 return CMD_SUCCESS;
15777 }
15778
15779 DEFUN (show_bgp_instance_updgrps_stats,
15780 show_bgp_instance_updgrps_stats_cmd,
15781 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15782 SHOW_STR
15783 IP_STR
15784 BGP_STR
15785 BGP_INSTANCE_HELP_STR
15786 "Detailed info about dynamic update groups\n"
15787 "Statistics\n")
15788 {
15789 int idx_word = 3;
15790 struct bgp *bgp;
15791
15792 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15793 if (bgp)
15794 update_group_show_stats(bgp, vty);
15795
15796 return CMD_SUCCESS;
15797 }
15798
15799 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15800 afi_t afi, safi_t safi,
15801 const char *what, uint64_t subgrp_id)
15802 {
15803 struct bgp *bgp;
15804
15805 if (name)
15806 bgp = bgp_lookup_by_name(name);
15807 else
15808 bgp = bgp_get_default();
15809
15810 if (bgp) {
15811 if (!strcmp(what, "advertise-queue"))
15812 update_group_show_adj_queue(bgp, afi, safi, vty,
15813 subgrp_id);
15814 else if (!strcmp(what, "advertised-routes"))
15815 update_group_show_advertised(bgp, afi, safi, vty,
15816 subgrp_id);
15817 else if (!strcmp(what, "packet-queue"))
15818 update_group_show_packet_queue(bgp, afi, safi, vty,
15819 subgrp_id);
15820 }
15821 }
15822
15823 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15824 show_ip_bgp_instance_updgrps_adj_s_cmd,
15825 "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",
15826 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15827 BGP_SAFI_HELP_STR
15828 "Detailed info about dynamic update groups\n"
15829 "Specific subgroup to display info for\n"
15830 "Advertisement queue\n"
15831 "Announced routes\n"
15832 "Packet queue\n")
15833 {
15834 uint64_t subgrp_id = 0;
15835 afi_t afiz;
15836 safi_t safiz;
15837 if (sgid)
15838 subgrp_id = strtoull(sgid, NULL, 10);
15839
15840 if (!ip && !afi)
15841 afiz = AFI_IP6;
15842 if (!ip && afi)
15843 afiz = bgp_vty_afi_from_str(afi);
15844 if (ip && !afi)
15845 afiz = AFI_IP;
15846 if (ip && afi) {
15847 afiz = bgp_vty_afi_from_str(afi);
15848 if (afiz != AFI_IP)
15849 vty_out(vty,
15850 "%% Cannot specify both 'ip' and 'ipv6'\n");
15851 return CMD_WARNING;
15852 }
15853
15854 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15855
15856 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15857 return CMD_SUCCESS;
15858 }
15859
15860 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15861 json_object *json)
15862 {
15863 struct listnode *node, *nnode;
15864 struct prefix *range;
15865 struct peer *conf;
15866 struct peer *peer;
15867 afi_t afi;
15868 safi_t safi;
15869 const char *peer_status;
15870 int lr_count;
15871 int dynamic;
15872 bool af_cfgd;
15873 json_object *json_peer_group = NULL;
15874 json_object *json_peer_group_afc = NULL;
15875 json_object *json_peer_group_members = NULL;
15876 json_object *json_peer_group_dynamic = NULL;
15877 json_object *json_peer_group_dynamic_af = NULL;
15878 json_object *json_peer_group_ranges = NULL;
15879
15880 conf = group->conf;
15881
15882 if (json) {
15883 json_peer_group = json_object_new_object();
15884 json_peer_group_afc = json_object_new_array();
15885 }
15886
15887 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15888 if (json)
15889 json_object_int_add(json_peer_group, "remoteAs",
15890 conf->as);
15891 else
15892 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15893 group->name, conf->as);
15894 } else if (conf->as_type == AS_INTERNAL) {
15895 if (json)
15896 json_object_int_add(json_peer_group, "remoteAs",
15897 group->bgp->as);
15898 else
15899 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15900 group->name, group->bgp->as);
15901 } else {
15902 if (!json)
15903 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15904 }
15905
15906 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15907 if (json)
15908 json_object_string_add(json_peer_group, "type",
15909 "internal");
15910 else
15911 vty_out(vty, " Peer-group type is internal\n");
15912 } else {
15913 if (json)
15914 json_object_string_add(json_peer_group, "type",
15915 "external");
15916 else
15917 vty_out(vty, " Peer-group type is external\n");
15918 }
15919
15920 /* Display AFs configured. */
15921 if (!json)
15922 vty_out(vty, " Configured address-families:");
15923
15924 FOREACH_AFI_SAFI (afi, safi) {
15925 if (conf->afc[afi][safi]) {
15926 af_cfgd = true;
15927 if (json)
15928 json_object_array_add(
15929 json_peer_group_afc,
15930 json_object_new_string(get_afi_safi_str(
15931 afi, safi, false)));
15932 else
15933 vty_out(vty, " %s;",
15934 get_afi_safi_str(afi, safi, false));
15935 }
15936 }
15937
15938 if (json) {
15939 json_object_object_add(json_peer_group,
15940 "addressFamiliesConfigured",
15941 json_peer_group_afc);
15942 } else {
15943 if (!af_cfgd)
15944 vty_out(vty, " none\n");
15945 else
15946 vty_out(vty, "\n");
15947 }
15948
15949 /* Display listen ranges (for dynamic neighbors), if any */
15950 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15951 lr_count = listcount(group->listen_range[afi]);
15952 if (lr_count) {
15953 if (json) {
15954 if (!json_peer_group_dynamic)
15955 json_peer_group_dynamic =
15956 json_object_new_object();
15957
15958 json_peer_group_dynamic_af =
15959 json_object_new_object();
15960 json_peer_group_ranges =
15961 json_object_new_array();
15962 json_object_int_add(json_peer_group_dynamic_af,
15963 "count", lr_count);
15964 } else {
15965 vty_out(vty, " %d %s listen range(s)\n",
15966 lr_count, afi2str(afi));
15967 }
15968
15969 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15970 nnode, range)) {
15971 if (json) {
15972 char buf[BUFSIZ];
15973
15974 snprintfrr(buf, sizeof(buf), "%pFX",
15975 range);
15976
15977 json_object_array_add(
15978 json_peer_group_ranges,
15979 json_object_new_string(buf));
15980 } else {
15981 vty_out(vty, " %pFX\n", range);
15982 }
15983 }
15984
15985 if (json) {
15986 json_object_object_add(
15987 json_peer_group_dynamic_af, "ranges",
15988 json_peer_group_ranges);
15989
15990 json_object_object_add(
15991 json_peer_group_dynamic, afi2str(afi),
15992 json_peer_group_dynamic_af);
15993 }
15994 }
15995 }
15996
15997 if (json_peer_group_dynamic)
15998 json_object_object_add(json_peer_group, "dynamicRanges",
15999 json_peer_group_dynamic);
16000
16001 /* Display group members and their status */
16002 if (listcount(group->peer)) {
16003 if (json)
16004 json_peer_group_members = json_object_new_object();
16005 else
16006 vty_out(vty, " Peer-group members:\n");
16007 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16008 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16009 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16010 peer_status = "Idle (Admin)";
16011 else if (CHECK_FLAG(peer->sflags,
16012 PEER_STATUS_PREFIX_OVERFLOW))
16013 peer_status = "Idle (PfxCt)";
16014 else
16015 peer_status = lookup_msg(bgp_status_msg,
16016 peer->status, NULL);
16017
16018 dynamic = peer_dynamic_neighbor(peer);
16019
16020 if (json) {
16021 json_object *json_peer_group_member =
16022 json_object_new_object();
16023
16024 json_object_string_add(json_peer_group_member,
16025 "status", peer_status);
16026
16027 if (dynamic)
16028 json_object_boolean_true_add(
16029 json_peer_group_member,
16030 "dynamic");
16031
16032 json_object_object_add(json_peer_group_members,
16033 peer->host,
16034 json_peer_group_member);
16035 } else {
16036 vty_out(vty, " %s %s %s \n", peer->host,
16037 dynamic ? "(dynamic)" : "",
16038 peer_status);
16039 }
16040 }
16041 if (json)
16042 json_object_object_add(json_peer_group, "members",
16043 json_peer_group_members);
16044 }
16045
16046 if (json)
16047 json_object_object_add(json, group->name, json_peer_group);
16048
16049 return CMD_SUCCESS;
16050 }
16051
16052 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16053 const char *group_name, bool uj)
16054 {
16055 struct bgp *bgp;
16056 struct listnode *node, *nnode;
16057 struct peer_group *group;
16058 bool found = false;
16059 json_object *json = NULL;
16060
16061 if (uj)
16062 json = json_object_new_object();
16063
16064 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16065
16066 if (!bgp) {
16067 if (uj)
16068 vty_json(vty, json);
16069 else
16070 vty_out(vty, "%% BGP instance not found\n");
16071
16072 return CMD_WARNING;
16073 }
16074
16075 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16076 if (group_name) {
16077 if (strmatch(group->name, group_name)) {
16078 bgp_show_one_peer_group(vty, group, json);
16079 found = true;
16080 break;
16081 }
16082 } else {
16083 bgp_show_one_peer_group(vty, group, json);
16084 }
16085 }
16086
16087 if (group_name && !found && !uj)
16088 vty_out(vty, "%% No such peer-group\n");
16089
16090 if (uj)
16091 vty_json(vty, json);
16092
16093 return CMD_SUCCESS;
16094 }
16095
16096 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16097 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16098 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16099 "Detailed information on BGP peer groups\n"
16100 "Peer group name\n" JSON_STR)
16101 {
16102 char *vrf, *pg;
16103 int idx = 0;
16104 bool uj = use_json(argc, argv);
16105
16106 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16107 : NULL;
16108 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16109
16110 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16111 }
16112
16113
16114 /* Redistribute VTY commands. */
16115
16116 DEFUN (bgp_redistribute_ipv4,
16117 bgp_redistribute_ipv4_cmd,
16118 "redistribute " FRR_IP_REDIST_STR_BGPD,
16119 "Redistribute information from another routing protocol\n"
16120 FRR_IP_REDIST_HELP_STR_BGPD)
16121 {
16122 VTY_DECLVAR_CONTEXT(bgp, bgp);
16123 int idx_protocol = 1;
16124 int type;
16125
16126 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16127 if (type < 0) {
16128 vty_out(vty, "%% Invalid route type\n");
16129 return CMD_WARNING_CONFIG_FAILED;
16130 }
16131
16132 bgp_redist_add(bgp, AFI_IP, type, 0);
16133 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16134 }
16135
16136 ALIAS_HIDDEN(
16137 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16138 "redistribute " FRR_IP_REDIST_STR_BGPD,
16139 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16140
16141 DEFUN (bgp_redistribute_ipv4_rmap,
16142 bgp_redistribute_ipv4_rmap_cmd,
16143 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16144 "Redistribute information from another routing protocol\n"
16145 FRR_IP_REDIST_HELP_STR_BGPD
16146 "Route map reference\n"
16147 "Pointer to route-map entries\n")
16148 {
16149 VTY_DECLVAR_CONTEXT(bgp, bgp);
16150 int idx_protocol = 1;
16151 int idx_word = 3;
16152 int type;
16153 struct bgp_redist *red;
16154 bool changed;
16155 struct route_map *route_map = route_map_lookup_warn_noexist(
16156 vty, argv[idx_word]->arg);
16157
16158 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16159 if (type < 0) {
16160 vty_out(vty, "%% Invalid route type\n");
16161 return CMD_WARNING_CONFIG_FAILED;
16162 }
16163
16164 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16165 changed =
16166 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16167 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16168 }
16169
16170 ALIAS_HIDDEN(
16171 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16172 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16173 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16174 "Route map reference\n"
16175 "Pointer to route-map entries\n")
16176
16177 DEFUN (bgp_redistribute_ipv4_metric,
16178 bgp_redistribute_ipv4_metric_cmd,
16179 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16180 "Redistribute information from another routing protocol\n"
16181 FRR_IP_REDIST_HELP_STR_BGPD
16182 "Metric for redistributed routes\n"
16183 "Default metric\n")
16184 {
16185 VTY_DECLVAR_CONTEXT(bgp, bgp);
16186 int idx_protocol = 1;
16187 int idx_number = 3;
16188 int type;
16189 uint32_t metric;
16190 struct bgp_redist *red;
16191 bool changed;
16192
16193 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16194 if (type < 0) {
16195 vty_out(vty, "%% Invalid route type\n");
16196 return CMD_WARNING_CONFIG_FAILED;
16197 }
16198 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16199
16200 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16201 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16202 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16203 }
16204
16205 ALIAS_HIDDEN(
16206 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16207 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16208 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16209 "Metric for redistributed routes\n"
16210 "Default metric\n")
16211
16212 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16213 bgp_redistribute_ipv4_rmap_metric_cmd,
16214 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16215 "Redistribute information from another routing protocol\n"
16216 FRR_IP_REDIST_HELP_STR_BGPD
16217 "Route map reference\n"
16218 "Pointer to route-map entries\n"
16219 "Metric for redistributed routes\n"
16220 "Default metric\n")
16221 {
16222 VTY_DECLVAR_CONTEXT(bgp, bgp);
16223 int idx_protocol = 1;
16224 int idx_word = 3;
16225 int idx_number = 5;
16226 int type;
16227 uint32_t metric;
16228 struct bgp_redist *red;
16229 bool changed;
16230 struct route_map *route_map =
16231 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16232
16233 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16234 if (type < 0) {
16235 vty_out(vty, "%% Invalid route type\n");
16236 return CMD_WARNING_CONFIG_FAILED;
16237 }
16238 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16239
16240 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16241 changed =
16242 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16243 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16244 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16245 }
16246
16247 ALIAS_HIDDEN(
16248 bgp_redistribute_ipv4_rmap_metric,
16249 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16250 "redistribute " FRR_IP_REDIST_STR_BGPD
16251 " route-map RMAP_NAME metric (0-4294967295)",
16252 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16253 "Route map reference\n"
16254 "Pointer to route-map entries\n"
16255 "Metric for redistributed routes\n"
16256 "Default metric\n")
16257
16258 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16259 bgp_redistribute_ipv4_metric_rmap_cmd,
16260 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16261 "Redistribute information from another routing protocol\n"
16262 FRR_IP_REDIST_HELP_STR_BGPD
16263 "Metric for redistributed routes\n"
16264 "Default metric\n"
16265 "Route map reference\n"
16266 "Pointer to route-map entries\n")
16267 {
16268 VTY_DECLVAR_CONTEXT(bgp, bgp);
16269 int idx_protocol = 1;
16270 int idx_number = 3;
16271 int idx_word = 5;
16272 int type;
16273 uint32_t metric;
16274 struct bgp_redist *red;
16275 bool changed;
16276 struct route_map *route_map =
16277 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16278
16279 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16280 if (type < 0) {
16281 vty_out(vty, "%% Invalid route type\n");
16282 return CMD_WARNING_CONFIG_FAILED;
16283 }
16284 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16285
16286 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16287 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16288 changed |=
16289 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16290 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16291 }
16292
16293 ALIAS_HIDDEN(
16294 bgp_redistribute_ipv4_metric_rmap,
16295 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16296 "redistribute " FRR_IP_REDIST_STR_BGPD
16297 " metric (0-4294967295) route-map RMAP_NAME",
16298 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16299 "Metric for redistributed routes\n"
16300 "Default metric\n"
16301 "Route map reference\n"
16302 "Pointer to route-map entries\n")
16303
16304 DEFUN (bgp_redistribute_ipv4_ospf,
16305 bgp_redistribute_ipv4_ospf_cmd,
16306 "redistribute <ospf|table> (1-65535)",
16307 "Redistribute information from another routing protocol\n"
16308 "Open Shortest Path First (OSPFv2)\n"
16309 "Non-main Kernel Routing Table\n"
16310 "Instance ID/Table ID\n")
16311 {
16312 VTY_DECLVAR_CONTEXT(bgp, bgp);
16313 int idx_ospf_table = 1;
16314 int idx_number = 2;
16315 unsigned short instance;
16316 unsigned short protocol;
16317
16318 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16319
16320 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16321 protocol = ZEBRA_ROUTE_OSPF;
16322 else
16323 protocol = ZEBRA_ROUTE_TABLE;
16324
16325 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16326 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16327 }
16328
16329 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16330 "redistribute <ospf|table> (1-65535)",
16331 "Redistribute information from another routing protocol\n"
16332 "Open Shortest Path First (OSPFv2)\n"
16333 "Non-main Kernel Routing Table\n"
16334 "Instance ID/Table ID\n")
16335
16336 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16337 bgp_redistribute_ipv4_ospf_rmap_cmd,
16338 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16339 "Redistribute information from another routing protocol\n"
16340 "Open Shortest Path First (OSPFv2)\n"
16341 "Non-main Kernel Routing Table\n"
16342 "Instance ID/Table ID\n"
16343 "Route map reference\n"
16344 "Pointer to route-map entries\n")
16345 {
16346 VTY_DECLVAR_CONTEXT(bgp, bgp);
16347 int idx_ospf_table = 1;
16348 int idx_number = 2;
16349 int idx_word = 4;
16350 struct bgp_redist *red;
16351 unsigned short instance;
16352 int protocol;
16353 bool changed;
16354 struct route_map *route_map =
16355 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16356
16357 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16358 protocol = ZEBRA_ROUTE_OSPF;
16359 else
16360 protocol = ZEBRA_ROUTE_TABLE;
16361
16362 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16363 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16364 changed =
16365 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16366 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16367 }
16368
16369 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16370 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16371 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16372 "Redistribute information from another routing protocol\n"
16373 "Open Shortest Path First (OSPFv2)\n"
16374 "Non-main Kernel Routing Table\n"
16375 "Instance ID/Table ID\n"
16376 "Route map reference\n"
16377 "Pointer to route-map entries\n")
16378
16379 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16380 bgp_redistribute_ipv4_ospf_metric_cmd,
16381 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16382 "Redistribute information from another routing protocol\n"
16383 "Open Shortest Path First (OSPFv2)\n"
16384 "Non-main Kernel Routing Table\n"
16385 "Instance ID/Table ID\n"
16386 "Metric for redistributed routes\n"
16387 "Default metric\n")
16388 {
16389 VTY_DECLVAR_CONTEXT(bgp, bgp);
16390 int idx_ospf_table = 1;
16391 int idx_number = 2;
16392 int idx_number_2 = 4;
16393 uint32_t metric;
16394 struct bgp_redist *red;
16395 unsigned short instance;
16396 int protocol;
16397 bool changed;
16398
16399 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16400 protocol = ZEBRA_ROUTE_OSPF;
16401 else
16402 protocol = ZEBRA_ROUTE_TABLE;
16403
16404 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16405 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16406
16407 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16408 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16409 metric);
16410 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16411 }
16412
16413 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16414 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16415 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16416 "Redistribute information from another routing protocol\n"
16417 "Open Shortest Path First (OSPFv2)\n"
16418 "Non-main Kernel Routing Table\n"
16419 "Instance ID/Table ID\n"
16420 "Metric for redistributed routes\n"
16421 "Default metric\n")
16422
16423 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16424 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16425 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16426 "Redistribute information from another routing protocol\n"
16427 "Open Shortest Path First (OSPFv2)\n"
16428 "Non-main Kernel Routing Table\n"
16429 "Instance ID/Table ID\n"
16430 "Route map reference\n"
16431 "Pointer to route-map entries\n"
16432 "Metric for redistributed routes\n"
16433 "Default metric\n")
16434 {
16435 VTY_DECLVAR_CONTEXT(bgp, bgp);
16436 int idx_ospf_table = 1;
16437 int idx_number = 2;
16438 int idx_word = 4;
16439 int idx_number_2 = 6;
16440 uint32_t metric;
16441 struct bgp_redist *red;
16442 unsigned short instance;
16443 int protocol;
16444 bool changed;
16445 struct route_map *route_map =
16446 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16447
16448 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16449 protocol = ZEBRA_ROUTE_OSPF;
16450 else
16451 protocol = ZEBRA_ROUTE_TABLE;
16452
16453 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16454 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16455
16456 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16457 changed =
16458 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16459 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16460 metric);
16461 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16462 }
16463
16464 ALIAS_HIDDEN(
16465 bgp_redistribute_ipv4_ospf_rmap_metric,
16466 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16467 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16468 "Redistribute information from another routing protocol\n"
16469 "Open Shortest Path First (OSPFv2)\n"
16470 "Non-main Kernel Routing Table\n"
16471 "Instance ID/Table ID\n"
16472 "Route map reference\n"
16473 "Pointer to route-map entries\n"
16474 "Metric for redistributed routes\n"
16475 "Default metric\n")
16476
16477 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16478 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16479 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16480 "Redistribute information from another routing protocol\n"
16481 "Open Shortest Path First (OSPFv2)\n"
16482 "Non-main Kernel Routing Table\n"
16483 "Instance ID/Table ID\n"
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_ospf_table = 1;
16491 int idx_number = 2;
16492 int idx_number_2 = 4;
16493 int idx_word = 6;
16494 uint32_t metric;
16495 struct bgp_redist *red;
16496 unsigned short instance;
16497 int protocol;
16498 bool changed;
16499 struct route_map *route_map =
16500 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16501
16502 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16503 protocol = ZEBRA_ROUTE_OSPF;
16504 else
16505 protocol = ZEBRA_ROUTE_TABLE;
16506
16507 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16508 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16509
16510 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16511 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16512 metric);
16513 changed |=
16514 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16515 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16516 }
16517
16518 ALIAS_HIDDEN(
16519 bgp_redistribute_ipv4_ospf_metric_rmap,
16520 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16521 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16522 "Redistribute information from another routing protocol\n"
16523 "Open Shortest Path First (OSPFv2)\n"
16524 "Non-main Kernel Routing Table\n"
16525 "Instance ID/Table ID\n"
16526 "Metric for redistributed routes\n"
16527 "Default metric\n"
16528 "Route map reference\n"
16529 "Pointer to route-map entries\n")
16530
16531 DEFUN (no_bgp_redistribute_ipv4_ospf,
16532 no_bgp_redistribute_ipv4_ospf_cmd,
16533 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16534 NO_STR
16535 "Redistribute information from another routing protocol\n"
16536 "Open Shortest Path First (OSPFv2)\n"
16537 "Non-main Kernel Routing Table\n"
16538 "Instance ID/Table ID\n"
16539 "Metric for redistributed routes\n"
16540 "Default metric\n"
16541 "Route map reference\n"
16542 "Pointer to route-map entries\n")
16543 {
16544 VTY_DECLVAR_CONTEXT(bgp, bgp);
16545 int idx_ospf_table = 2;
16546 int idx_number = 3;
16547 unsigned short instance;
16548 int protocol;
16549
16550 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16551 protocol = ZEBRA_ROUTE_OSPF;
16552 else
16553 protocol = ZEBRA_ROUTE_TABLE;
16554
16555 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16556 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16557 }
16558
16559 ALIAS_HIDDEN(
16560 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16561 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16562 NO_STR
16563 "Redistribute information from another routing protocol\n"
16564 "Open Shortest Path First (OSPFv2)\n"
16565 "Non-main Kernel Routing Table\n"
16566 "Instance ID/Table ID\n"
16567 "Metric for redistributed routes\n"
16568 "Default metric\n"
16569 "Route map reference\n"
16570 "Pointer to route-map entries\n")
16571
16572 DEFUN (no_bgp_redistribute_ipv4,
16573 no_bgp_redistribute_ipv4_cmd,
16574 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16575 NO_STR
16576 "Redistribute information from another routing protocol\n"
16577 FRR_IP_REDIST_HELP_STR_BGPD
16578 "Metric for redistributed routes\n"
16579 "Default metric\n"
16580 "Route map reference\n"
16581 "Pointer to route-map entries\n")
16582 {
16583 VTY_DECLVAR_CONTEXT(bgp, bgp);
16584 int idx_protocol = 2;
16585 int type;
16586
16587 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16588 if (type < 0) {
16589 vty_out(vty, "%% Invalid route type\n");
16590 return CMD_WARNING_CONFIG_FAILED;
16591 }
16592 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16593 }
16594
16595 ALIAS_HIDDEN(
16596 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16597 "no redistribute " FRR_IP_REDIST_STR_BGPD
16598 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16599 NO_STR
16600 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16601 "Metric for redistributed routes\n"
16602 "Default metric\n"
16603 "Route map reference\n"
16604 "Pointer to route-map entries\n")
16605
16606 DEFUN (bgp_redistribute_ipv6,
16607 bgp_redistribute_ipv6_cmd,
16608 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16609 "Redistribute information from another routing protocol\n"
16610 FRR_IP6_REDIST_HELP_STR_BGPD)
16611 {
16612 VTY_DECLVAR_CONTEXT(bgp, bgp);
16613 int idx_protocol = 1;
16614 int type;
16615
16616 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16617 if (type < 0) {
16618 vty_out(vty, "%% Invalid route type\n");
16619 return CMD_WARNING_CONFIG_FAILED;
16620 }
16621
16622 bgp_redist_add(bgp, AFI_IP6, type, 0);
16623 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16624 }
16625
16626 DEFUN (bgp_redistribute_ipv6_rmap,
16627 bgp_redistribute_ipv6_rmap_cmd,
16628 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16629 "Redistribute information from another routing protocol\n"
16630 FRR_IP6_REDIST_HELP_STR_BGPD
16631 "Route map reference\n"
16632 "Pointer to route-map entries\n")
16633 {
16634 VTY_DECLVAR_CONTEXT(bgp, bgp);
16635 int idx_protocol = 1;
16636 int idx_word = 3;
16637 int type;
16638 struct bgp_redist *red;
16639 bool changed;
16640 struct route_map *route_map =
16641 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16642
16643 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16644 if (type < 0) {
16645 vty_out(vty, "%% Invalid route type\n");
16646 return CMD_WARNING_CONFIG_FAILED;
16647 }
16648
16649 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16650 changed =
16651 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16652 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16653 }
16654
16655 DEFUN (bgp_redistribute_ipv6_metric,
16656 bgp_redistribute_ipv6_metric_cmd,
16657 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16658 "Redistribute information from another routing protocol\n"
16659 FRR_IP6_REDIST_HELP_STR_BGPD
16660 "Metric for redistributed routes\n"
16661 "Default metric\n")
16662 {
16663 VTY_DECLVAR_CONTEXT(bgp, bgp);
16664 int idx_protocol = 1;
16665 int idx_number = 3;
16666 int type;
16667 uint32_t metric;
16668 struct bgp_redist *red;
16669 bool changed;
16670
16671 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16672 if (type < 0) {
16673 vty_out(vty, "%% Invalid route type\n");
16674 return CMD_WARNING_CONFIG_FAILED;
16675 }
16676 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16677
16678 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16679 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16680 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16681 }
16682
16683 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16684 bgp_redistribute_ipv6_rmap_metric_cmd,
16685 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16686 "Redistribute information from another routing protocol\n"
16687 FRR_IP6_REDIST_HELP_STR_BGPD
16688 "Route map reference\n"
16689 "Pointer to route-map entries\n"
16690 "Metric for redistributed routes\n"
16691 "Default metric\n")
16692 {
16693 VTY_DECLVAR_CONTEXT(bgp, bgp);
16694 int idx_protocol = 1;
16695 int idx_word = 3;
16696 int idx_number = 5;
16697 int type;
16698 uint32_t metric;
16699 struct bgp_redist *red;
16700 bool changed;
16701 struct route_map *route_map =
16702 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16703
16704 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16705 if (type < 0) {
16706 vty_out(vty, "%% Invalid route type\n");
16707 return CMD_WARNING_CONFIG_FAILED;
16708 }
16709 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16710
16711 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16712 changed =
16713 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16714 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16715 metric);
16716 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16717 }
16718
16719 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16720 bgp_redistribute_ipv6_metric_rmap_cmd,
16721 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16722 "Redistribute information from another routing protocol\n"
16723 FRR_IP6_REDIST_HELP_STR_BGPD
16724 "Metric for redistributed routes\n"
16725 "Default metric\n"
16726 "Route map reference\n"
16727 "Pointer to route-map entries\n")
16728 {
16729 VTY_DECLVAR_CONTEXT(bgp, bgp);
16730 int idx_protocol = 1;
16731 int idx_number = 3;
16732 int idx_word = 5;
16733 int type;
16734 uint32_t metric;
16735 struct bgp_redist *red;
16736 bool changed;
16737 struct route_map *route_map =
16738 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16739
16740 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16741 if (type < 0) {
16742 vty_out(vty, "%% Invalid route type\n");
16743 return CMD_WARNING_CONFIG_FAILED;
16744 }
16745 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16746
16747 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16748 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16749 metric);
16750 changed |=
16751 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16752 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16753 }
16754
16755 DEFUN (no_bgp_redistribute_ipv6,
16756 no_bgp_redistribute_ipv6_cmd,
16757 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16758 NO_STR
16759 "Redistribute information from another routing protocol\n"
16760 FRR_IP6_REDIST_HELP_STR_BGPD
16761 "Metric for redistributed routes\n"
16762 "Default metric\n"
16763 "Route map reference\n"
16764 "Pointer to route-map entries\n")
16765 {
16766 VTY_DECLVAR_CONTEXT(bgp, bgp);
16767 int idx_protocol = 2;
16768 int type;
16769
16770 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16771 if (type < 0) {
16772 vty_out(vty, "%% Invalid route type\n");
16773 return CMD_WARNING_CONFIG_FAILED;
16774 }
16775
16776 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16777 }
16778
16779 /* Neighbor update tcp-mss. */
16780 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16781 const char *tcp_mss_str)
16782 {
16783 struct peer *peer;
16784 uint32_t tcp_mss_val = 0;
16785
16786 peer = peer_and_group_lookup_vty(vty, peer_str);
16787 if (!peer)
16788 return CMD_WARNING_CONFIG_FAILED;
16789
16790 if (tcp_mss_str) {
16791 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16792 peer_tcp_mss_set(peer, tcp_mss_val);
16793 } else {
16794 peer_tcp_mss_unset(peer);
16795 }
16796
16797 return CMD_SUCCESS;
16798 }
16799
16800 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16801 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16803 "TCP max segment size\n"
16804 "TCP MSS value\n")
16805 {
16806 int peer_index = 1;
16807 int mss_index = 3;
16808
16809 vty_out(vty,
16810 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16811 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16812 argv[mss_index]->arg);
16813 }
16814
16815 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16816 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16817 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16818 "TCP max segment size\n"
16819 "TCP MSS value\n")
16820 {
16821 int peer_index = 2;
16822
16823 vty_out(vty,
16824 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16825 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16826 }
16827
16828 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16829 "[no$no] bgp retain route-target all",
16830 NO_STR BGP_STR
16831 "Retain BGP updates\n"
16832 "Retain BGP updates based on route-target values\n"
16833 "Retain all BGP updates\n")
16834 {
16835 bool check;
16836 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16837
16838 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16839 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16840 if (check != !no) {
16841 if (!no)
16842 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16843 [bgp_node_safi(vty)],
16844 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16845 else
16846 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16847 [bgp_node_safi(vty)],
16848 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16849 /* trigger a flush to re-sync with ADJ-RIB-in */
16850 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16851 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16852 }
16853 return CMD_SUCCESS;
16854 }
16855
16856 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16857 afi_t afi, safi_t safi)
16858 {
16859 int i;
16860
16861 /* Unicast redistribution only. */
16862 if (safi != SAFI_UNICAST)
16863 return;
16864
16865 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16866 /* Redistribute BGP does not make sense. */
16867 if (i != ZEBRA_ROUTE_BGP) {
16868 struct list *red_list;
16869 struct listnode *node;
16870 struct bgp_redist *red;
16871
16872 red_list = bgp->redist[afi][i];
16873 if (!red_list)
16874 continue;
16875
16876 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16877 /* "redistribute" configuration. */
16878 vty_out(vty, " redistribute %s",
16879 zebra_route_string(i));
16880 if (red->instance)
16881 vty_out(vty, " %d", red->instance);
16882 if (red->redist_metric_flag)
16883 vty_out(vty, " metric %u",
16884 red->redist_metric);
16885 if (red->rmap.name)
16886 vty_out(vty, " route-map %s",
16887 red->rmap.name);
16888 vty_out(vty, "\n");
16889 }
16890 }
16891 }
16892 }
16893
16894 /* peer-group helpers for config-write */
16895
16896 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16897 {
16898 if (!peer_group_active(peer)) {
16899 if (CHECK_FLAG(peer->flags_invert, flag))
16900 return !CHECK_FLAG(peer->flags, flag);
16901 else
16902 return !!CHECK_FLAG(peer->flags, flag);
16903 }
16904
16905 return !!CHECK_FLAG(peer->flags_override, flag);
16906 }
16907
16908 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16909 uint64_t flag)
16910 {
16911 if (!peer_group_active(peer)) {
16912 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16913 return !peer_af_flag_check(peer, afi, safi, flag);
16914 else
16915 return !!peer_af_flag_check(peer, afi, safi, flag);
16916 }
16917
16918 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16919 }
16920
16921 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16922 uint8_t type, int direct)
16923 {
16924 struct bgp_filter *filter;
16925
16926 if (peer_group_active(peer))
16927 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16928 type);
16929
16930 filter = &peer->filter[afi][safi];
16931 switch (type) {
16932 case PEER_FT_DISTRIBUTE_LIST:
16933 return !!(filter->dlist[direct].name);
16934 case PEER_FT_FILTER_LIST:
16935 return !!(filter->aslist[direct].name);
16936 case PEER_FT_PREFIX_LIST:
16937 return !!(filter->plist[direct].name);
16938 case PEER_FT_ROUTE_MAP:
16939 return !!(filter->map[direct].name);
16940 case PEER_FT_UNSUPPRESS_MAP:
16941 return !!(filter->usmap.name);
16942 case PEER_FT_ADVERTISE_MAP:
16943 return !!(filter->advmap.aname
16944 && ((filter->advmap.condition == direct)
16945 && filter->advmap.cname));
16946 default:
16947 return false;
16948 }
16949 }
16950
16951 /* Return true if the addpath type is set for peer and different from
16952 * peer-group.
16953 */
16954 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16955 safi_t safi)
16956 {
16957 enum bgp_addpath_strat type, g_type;
16958
16959 type = peer->addpath_type[afi][safi];
16960
16961 if (type != BGP_ADDPATH_NONE) {
16962 if (peer_group_active(peer)) {
16963 g_type = peer->group->conf->addpath_type[afi][safi];
16964
16965 if (type != g_type)
16966 return true;
16967 else
16968 return false;
16969 }
16970
16971 return true;
16972 }
16973
16974 return false;
16975 }
16976
16977 /* This is part of the address-family block (unicast only) */
16978 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16979 afi_t afi)
16980 {
16981 int indent = 2;
16982 uint32_t tovpn_sid_index = 0;
16983
16984 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16985 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16986 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16987 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16988 bgp->vpn_policy[afi]
16989 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16990 else
16991 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16992 bgp->vpn_policy[afi]
16993 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16994 }
16995 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16996 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16997 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16998 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16999 return;
17000
17001 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17002 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17003
17004 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17005
17006 } else {
17007 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17008 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17009 bgp->vpn_policy[afi].tovpn_label);
17010 }
17011 }
17012
17013 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17014 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17015 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17016 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17017 } else if (tovpn_sid_index != 0) {
17018 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17019 tovpn_sid_index);
17020 }
17021
17022 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17023 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17024 &bgp->vpn_policy[afi].tovpn_rd);
17025
17026 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17027 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17028
17029 char buf[PREFIX_STRLEN];
17030 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17031 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17032 sizeof(buf))) {
17033
17034 vty_out(vty, "%*snexthop vpn export %s\n",
17035 indent, "", buf);
17036 }
17037 }
17038 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17039 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17040 && ecommunity_cmp(
17041 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17042 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17043
17044 char *b = ecommunity_ecom2str(
17045 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17046 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17047 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17048 XFREE(MTYPE_ECOMMUNITY_STR, b);
17049 } else {
17050 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17051 char *b = ecommunity_ecom2str(
17052 bgp->vpn_policy[afi]
17053 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17054 ECOMMUNITY_FORMAT_ROUTE_MAP,
17055 ECOMMUNITY_ROUTE_TARGET);
17056 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17057 XFREE(MTYPE_ECOMMUNITY_STR, b);
17058 }
17059 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17060 char *b = ecommunity_ecom2str(
17061 bgp->vpn_policy[afi]
17062 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17063 ECOMMUNITY_FORMAT_ROUTE_MAP,
17064 ECOMMUNITY_ROUTE_TARGET);
17065 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17066 XFREE(MTYPE_ECOMMUNITY_STR, b);
17067 }
17068 }
17069
17070 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17071 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17072 bgp->vpn_policy[afi]
17073 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17074
17075 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17076 char *b = ecommunity_ecom2str(
17077 bgp->vpn_policy[afi]
17078 .import_redirect_rtlist,
17079 ECOMMUNITY_FORMAT_ROUTE_MAP,
17080 ECOMMUNITY_ROUTE_TARGET);
17081
17082 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17083 != ECOMMUNITY_SIZE)
17084 vty_out(vty, "%*srt6 redirect import %s\n",
17085 indent, "", b);
17086 else
17087 vty_out(vty, "%*srt redirect import %s\n",
17088 indent, "", b);
17089 XFREE(MTYPE_ECOMMUNITY_STR, b);
17090 }
17091 }
17092
17093 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17094 afi_t afi, safi_t safi)
17095 {
17096 struct bgp_filter *filter;
17097 char *addr;
17098
17099 addr = peer->host;
17100 filter = &peer->filter[afi][safi];
17101
17102 /* distribute-list. */
17103 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17104 FILTER_IN))
17105 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17106 filter->dlist[FILTER_IN].name);
17107
17108 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17109 FILTER_OUT))
17110 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17111 filter->dlist[FILTER_OUT].name);
17112
17113 /* prefix-list. */
17114 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17115 FILTER_IN))
17116 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17117 filter->plist[FILTER_IN].name);
17118
17119 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17120 FILTER_OUT))
17121 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17122 filter->plist[FILTER_OUT].name);
17123
17124 /* route-map. */
17125 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17126 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17127 filter->map[RMAP_IN].name);
17128
17129 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17130 RMAP_OUT))
17131 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17132 filter->map[RMAP_OUT].name);
17133
17134 /* unsuppress-map */
17135 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17136 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17137 filter->usmap.name);
17138
17139 /* advertise-map : always applied in OUT direction*/
17140 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17141 CONDITION_NON_EXIST))
17142 vty_out(vty,
17143 " neighbor %s advertise-map %s non-exist-map %s\n",
17144 addr, filter->advmap.aname, filter->advmap.cname);
17145
17146 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17147 CONDITION_EXIST))
17148 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17149 addr, filter->advmap.aname, filter->advmap.cname);
17150
17151 /* filter-list. */
17152 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17153 FILTER_IN))
17154 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17155 filter->aslist[FILTER_IN].name);
17156
17157 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17158 FILTER_OUT))
17159 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17160 filter->aslist[FILTER_OUT].name);
17161 }
17162
17163 /* BGP peer configuration display function. */
17164 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17165 struct peer *peer)
17166 {
17167 struct peer *g_peer = NULL;
17168 char *addr;
17169 int if_pg_printed = false;
17170 int if_ras_printed = false;
17171
17172 /* Skip dynamic neighbors. */
17173 if (peer_dynamic_neighbor(peer))
17174 return;
17175
17176 if (peer->conf_if)
17177 addr = peer->conf_if;
17178 else
17179 addr = peer->host;
17180
17181 /************************************
17182 ****** Global to the neighbor ******
17183 ************************************/
17184 if (peer->conf_if) {
17185 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17186 vty_out(vty, " neighbor %s interface v6only", addr);
17187 else
17188 vty_out(vty, " neighbor %s interface", addr);
17189
17190 if (peer_group_active(peer)) {
17191 vty_out(vty, " peer-group %s", peer->group->name);
17192 if_pg_printed = true;
17193 } else if (peer->as_type == AS_SPECIFIED) {
17194 vty_out(vty, " remote-as %u", peer->as);
17195 if_ras_printed = true;
17196 } else if (peer->as_type == AS_INTERNAL) {
17197 vty_out(vty, " remote-as internal");
17198 if_ras_printed = true;
17199 } else if (peer->as_type == AS_EXTERNAL) {
17200 vty_out(vty, " remote-as external");
17201 if_ras_printed = true;
17202 }
17203
17204 vty_out(vty, "\n");
17205 }
17206
17207 /* remote-as and peer-group */
17208 /* peer is a member of a peer-group */
17209 if (peer_group_active(peer)) {
17210 g_peer = peer->group->conf;
17211
17212 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17213 if (peer->as_type == AS_SPECIFIED) {
17214 vty_out(vty, " neighbor %s remote-as %u\n",
17215 addr, peer->as);
17216 } else if (peer->as_type == AS_INTERNAL) {
17217 vty_out(vty,
17218 " neighbor %s remote-as internal\n",
17219 addr);
17220 } else if (peer->as_type == AS_EXTERNAL) {
17221 vty_out(vty,
17222 " neighbor %s remote-as external\n",
17223 addr);
17224 }
17225 }
17226
17227 /* For swpX peers we displayed the peer-group
17228 * via 'neighbor swpX interface peer-group PGNAME' */
17229 if (!if_pg_printed)
17230 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17231 peer->group->name);
17232 }
17233
17234 /* peer is NOT a member of a peer-group */
17235 else {
17236 /* peer is a peer-group, declare the peer-group */
17237 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17238 vty_out(vty, " neighbor %s peer-group\n", addr);
17239 }
17240
17241 if (!if_ras_printed) {
17242 if (peer->as_type == AS_SPECIFIED) {
17243 vty_out(vty, " neighbor %s remote-as %u\n",
17244 addr, peer->as);
17245 } else if (peer->as_type == AS_INTERNAL) {
17246 vty_out(vty,
17247 " neighbor %s remote-as internal\n",
17248 addr);
17249 } else if (peer->as_type == AS_EXTERNAL) {
17250 vty_out(vty,
17251 " neighbor %s remote-as external\n",
17252 addr);
17253 }
17254 }
17255 }
17256
17257 /* local-as */
17258 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17259 vty_out(vty, " neighbor %s local-as %u", addr,
17260 peer->change_local_as);
17261 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17262 vty_out(vty, " no-prepend");
17263 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17264 vty_out(vty, " replace-as");
17265 vty_out(vty, "\n");
17266 }
17267
17268 /* description */
17269 if (peer->desc) {
17270 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17271 }
17272
17273 /* shutdown */
17274 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17275 if (peer->tx_shutdown_message)
17276 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17277 peer->tx_shutdown_message);
17278 else
17279 vty_out(vty, " neighbor %s shutdown\n", addr);
17280 }
17281
17282 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17283 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17284 peer->rtt_expected, peer->rtt_keepalive_conf);
17285
17286 /* bfd */
17287 if (peer->bfd_config)
17288 bgp_bfd_peer_config_write(vty, peer, addr);
17289
17290 /* password */
17291 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17292 vty_out(vty, " neighbor %s password %s\n", addr,
17293 peer->password);
17294
17295 /* neighbor solo */
17296 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17297 if (!peer_group_active(peer)) {
17298 vty_out(vty, " neighbor %s solo\n", addr);
17299 }
17300 }
17301
17302 /* BGP port */
17303 if (peer->port != BGP_PORT_DEFAULT) {
17304 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17305 }
17306
17307 /* Local interface name */
17308 if (peer->ifname) {
17309 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17310 }
17311
17312 /* TCP max segment size */
17313 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17314 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17315
17316 /* passive */
17317 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17318 vty_out(vty, " neighbor %s passive\n", addr);
17319
17320 /* ebgp-multihop */
17321 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17322 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17323 && peer->ttl == MAXTTL)) {
17324 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17325 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17326 peer->ttl);
17327 }
17328 }
17329
17330 /* aigp */
17331 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17332 vty_out(vty, " neighbor %s aigp\n", addr);
17333
17334 /* graceful-shutdown */
17335 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17336 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17337
17338 /* role */
17339 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17340 peer->local_role != ROLE_UNDEFINED)
17341 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17342 bgp_get_name_by_role(peer->local_role),
17343 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17344 ? " strict-mode"
17345 : "");
17346
17347 /* ttl-security hops */
17348 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17349 if (!peer_group_active(peer)
17350 || g_peer->gtsm_hops != peer->gtsm_hops) {
17351 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17352 addr, peer->gtsm_hops);
17353 }
17354 }
17355
17356 /* disable-connected-check */
17357 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17358 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17359
17360 /* link-bw-encoding-ieee */
17361 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17362 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17363 addr);
17364
17365 /* extended-optional-parameters */
17366 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17367 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17368 addr);
17369
17370 /* enforce-first-as */
17371 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17372 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17373
17374 /* update-source */
17375 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17376 if (peer->update_source)
17377 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17378 peer->update_source);
17379 else if (peer->update_if)
17380 vty_out(vty, " neighbor %s update-source %s\n", addr,
17381 peer->update_if);
17382 }
17383
17384 /* advertisement-interval */
17385 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17386 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17387 peer->routeadv);
17388
17389 /* timers */
17390 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17391 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17392 peer->keepalive, peer->holdtime);
17393
17394 /* timers connect */
17395 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17396 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17397 peer->connect);
17398 /* need special-case handling for changed default values due to
17399 * config profile / version (because there is no "timers bgp connect"
17400 * command, we need to save this per-peer :/)
17401 */
17402 else if (!peer_group_active(peer) && !peer->connect &&
17403 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17404 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17405 peer->bgp->default_connect_retry);
17406
17407 /* timers delayopen */
17408 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17409 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17410 peer->delayopen);
17411 /* Save config even though flag is not set if default values have been
17412 * changed
17413 */
17414 else if (!peer_group_active(peer) && !peer->delayopen
17415 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17416 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17417 peer->bgp->default_delayopen);
17418
17419 /* capability dynamic */
17420 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17421 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17422
17423 /* capability extended-nexthop */
17424 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17425 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17426 !peer->conf_if)
17427 vty_out(vty,
17428 " no neighbor %s capability extended-nexthop\n",
17429 addr);
17430 else if (!peer->conf_if)
17431 vty_out(vty,
17432 " neighbor %s capability extended-nexthop\n",
17433 addr);
17434 }
17435
17436 /* dont-capability-negotiation */
17437 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17438 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17439
17440 /* override-capability */
17441 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17442 vty_out(vty, " neighbor %s override-capability\n", addr);
17443
17444 /* strict-capability-match */
17445 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17446 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17447
17448 /* Sender side AS path loop detection. */
17449 if (peer->as_path_loop_detection)
17450 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17451 addr);
17452
17453 /* path-attribute discard */
17454 char discard_attrs_str[BUFSIZ] = {0};
17455 bool discard_attrs = bgp_path_attribute_discard(
17456 peer, discard_attrs_str, sizeof(discard_attrs_str));
17457
17458 if (discard_attrs)
17459 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17460 discard_attrs_str);
17461
17462 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17463 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17464
17465 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17466 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17467 vty_out(vty,
17468 " neighbor %s graceful-restart-helper\n", addr);
17469 } else if (CHECK_FLAG(
17470 peer->peer_gr_new_status_flag,
17471 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17472 vty_out(vty,
17473 " neighbor %s graceful-restart\n", addr);
17474 } else if (
17475 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17476 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17477 && !(CHECK_FLAG(
17478 peer->peer_gr_new_status_flag,
17479 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17480 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17481 addr);
17482 }
17483 }
17484 }
17485
17486 /* BGP peer configuration display function. */
17487 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17488 struct peer *peer, afi_t afi, safi_t safi)
17489 {
17490 struct peer *g_peer = NULL;
17491 char *addr;
17492 bool flag_scomm, flag_secomm, flag_slcomm;
17493
17494 /* Skip dynamic neighbors. */
17495 if (peer_dynamic_neighbor(peer))
17496 return;
17497
17498 if (peer->conf_if)
17499 addr = peer->conf_if;
17500 else
17501 addr = peer->host;
17502
17503 /************************************
17504 ****** Per AF to the neighbor ******
17505 ************************************/
17506 if (peer_group_active(peer)) {
17507 g_peer = peer->group->conf;
17508
17509 /* If the peer-group is active but peer is not, print a 'no
17510 * activate' */
17511 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17512 vty_out(vty, " no neighbor %s activate\n", addr);
17513 }
17514
17515 /* If the peer-group is not active but peer is, print an
17516 'activate' */
17517 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17518 vty_out(vty, " neighbor %s activate\n", addr);
17519 }
17520 } else {
17521 if (peer->afc[afi][safi]) {
17522 if (safi == SAFI_ENCAP)
17523 vty_out(vty, " neighbor %s activate\n", addr);
17524 else if (!bgp->default_af[afi][safi])
17525 vty_out(vty, " neighbor %s activate\n", addr);
17526 } else {
17527 if (bgp->default_af[afi][safi])
17528 vty_out(vty, " no neighbor %s activate\n",
17529 addr);
17530 }
17531 }
17532
17533 /* addpath TX knobs */
17534 if (peergroup_af_addpath_check(peer, afi, safi)) {
17535 switch (peer->addpath_type[afi][safi]) {
17536 case BGP_ADDPATH_ALL:
17537 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17538 addr);
17539 break;
17540 case BGP_ADDPATH_BEST_PER_AS:
17541 vty_out(vty,
17542 " neighbor %s addpath-tx-bestpath-per-AS\n",
17543 addr);
17544 break;
17545 case BGP_ADDPATH_MAX:
17546 case BGP_ADDPATH_NONE:
17547 break;
17548 }
17549 }
17550
17551 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17552 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17553
17554 /* ORF capability. */
17555 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17556 || peergroup_af_flag_check(peer, afi, safi,
17557 PEER_FLAG_ORF_PREFIX_RM)) {
17558 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17559
17560 if (peergroup_af_flag_check(peer, afi, safi,
17561 PEER_FLAG_ORF_PREFIX_SM)
17562 && peergroup_af_flag_check(peer, afi, safi,
17563 PEER_FLAG_ORF_PREFIX_RM))
17564 vty_out(vty, " both");
17565 else if (peergroup_af_flag_check(peer, afi, safi,
17566 PEER_FLAG_ORF_PREFIX_SM))
17567 vty_out(vty, " send");
17568 else
17569 vty_out(vty, " receive");
17570 vty_out(vty, "\n");
17571 }
17572
17573 /* Route reflector client. */
17574 if (peergroup_af_flag_check(peer, afi, safi,
17575 PEER_FLAG_REFLECTOR_CLIENT)) {
17576 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17577 }
17578
17579 /* next-hop-self force */
17580 if (peergroup_af_flag_check(peer, afi, safi,
17581 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17582 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17583 }
17584
17585 /* next-hop-self */
17586 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17587 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17588 }
17589
17590 /* remove-private-AS */
17591 if (peergroup_af_flag_check(peer, afi, safi,
17592 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17593 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17594 addr);
17595 }
17596
17597 else if (peergroup_af_flag_check(peer, afi, safi,
17598 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17599 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17600 addr);
17601 }
17602
17603 else if (peergroup_af_flag_check(peer, afi, safi,
17604 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17605 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17606 }
17607
17608 else if (peergroup_af_flag_check(peer, afi, safi,
17609 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17610 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17611 }
17612
17613 /* as-override */
17614 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17615 vty_out(vty, " neighbor %s as-override\n", addr);
17616 }
17617
17618 /* send-community print. */
17619 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17620 PEER_FLAG_SEND_COMMUNITY);
17621 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17622 PEER_FLAG_SEND_EXT_COMMUNITY);
17623 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17624 PEER_FLAG_SEND_LARGE_COMMUNITY);
17625
17626 if (flag_scomm && flag_secomm && flag_slcomm) {
17627 vty_out(vty, " no neighbor %s send-community all\n", addr);
17628 } else {
17629 if (flag_scomm)
17630 vty_out(vty, " no neighbor %s send-community\n", addr);
17631 if (flag_secomm)
17632 vty_out(vty,
17633 " no neighbor %s send-community extended\n",
17634 addr);
17635
17636 if (flag_slcomm)
17637 vty_out(vty, " no neighbor %s send-community large\n",
17638 addr);
17639 }
17640
17641 /* Default information */
17642 if (peergroup_af_flag_check(peer, afi, safi,
17643 PEER_FLAG_DEFAULT_ORIGINATE)) {
17644 vty_out(vty, " neighbor %s default-originate", addr);
17645
17646 if (peer->default_rmap[afi][safi].name)
17647 vty_out(vty, " route-map %s",
17648 peer->default_rmap[afi][safi].name);
17649
17650 vty_out(vty, "\n");
17651 }
17652
17653 /* Soft reconfiguration inbound. */
17654 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17655 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17656 addr);
17657 }
17658
17659 /* maximum-prefix. */
17660 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17661 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17662 peer->pmax[afi][safi]);
17663
17664 if (peer->pmax_threshold[afi][safi]
17665 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17666 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17667 if (peer_af_flag_check(peer, afi, safi,
17668 PEER_FLAG_MAX_PREFIX_WARNING))
17669 vty_out(vty, " warning-only");
17670 if (peer->pmax_restart[afi][safi])
17671 vty_out(vty, " restart %u",
17672 peer->pmax_restart[afi][safi]);
17673 if (peer_af_flag_check(peer, afi, safi,
17674 PEER_FLAG_MAX_PREFIX_FORCE))
17675 vty_out(vty, " force");
17676
17677 vty_out(vty, "\n");
17678 }
17679
17680 /* maximum-prefix-out */
17681 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17682 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17683 addr, peer->pmax_out[afi][safi]);
17684
17685 /* Route server client. */
17686 if (peergroup_af_flag_check(peer, afi, safi,
17687 PEER_FLAG_RSERVER_CLIENT)) {
17688 vty_out(vty, " neighbor %s route-server-client\n", addr);
17689 }
17690
17691 /* Nexthop-local unchanged. */
17692 if (peergroup_af_flag_check(peer, afi, safi,
17693 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17694 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17695 }
17696
17697 /* allowas-in <1-10> */
17698 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17699 if (peer_af_flag_check(peer, afi, safi,
17700 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17701 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17702 } else if (peer->allowas_in[afi][safi] == 3) {
17703 vty_out(vty, " neighbor %s allowas-in\n", addr);
17704 } else {
17705 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17706 peer->allowas_in[afi][safi]);
17707 }
17708 }
17709
17710 /* accept-own */
17711 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17712 vty_out(vty, " neighbor %s accept-own\n", addr);
17713
17714 /* soo */
17715 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17716 char *soo_str = ecommunity_ecom2str(
17717 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17718
17719 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17720 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17721 }
17722
17723 /* weight */
17724 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17725 vty_out(vty, " neighbor %s weight %lu\n", addr,
17726 peer->weight[afi][safi]);
17727
17728 /* Filter. */
17729 bgp_config_write_filter(vty, peer, afi, safi);
17730
17731 /* atribute-unchanged. */
17732 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17733 || (safi != SAFI_EVPN
17734 && peer_af_flag_check(peer, afi, safi,
17735 PEER_FLAG_NEXTHOP_UNCHANGED))
17736 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17737
17738 if (!peer_group_active(peer)
17739 || peergroup_af_flag_check(peer, afi, safi,
17740 PEER_FLAG_AS_PATH_UNCHANGED)
17741 || peergroup_af_flag_check(peer, afi, safi,
17742 PEER_FLAG_NEXTHOP_UNCHANGED)
17743 || peergroup_af_flag_check(peer, afi, safi,
17744 PEER_FLAG_MED_UNCHANGED)) {
17745
17746 vty_out(vty,
17747 " neighbor %s attribute-unchanged%s%s%s\n",
17748 addr,
17749 peer_af_flag_check(peer, afi, safi,
17750 PEER_FLAG_AS_PATH_UNCHANGED)
17751 ? " as-path"
17752 : "",
17753 peer_af_flag_check(peer, afi, safi,
17754 PEER_FLAG_NEXTHOP_UNCHANGED)
17755 ? " next-hop"
17756 : "",
17757 peer_af_flag_check(peer, afi, safi,
17758 PEER_FLAG_MED_UNCHANGED)
17759 ? " med"
17760 : "");
17761 }
17762 }
17763 }
17764
17765 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17766 safi_t safi)
17767 {
17768 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17769 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17770 vty_out(vty, " no bgp retain route-target all\n");
17771 }
17772
17773 /* Address family based peer configuration display. */
17774 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17775 safi_t safi)
17776 {
17777 struct peer *peer;
17778 struct peer_group *group;
17779 struct listnode *node, *nnode;
17780
17781
17782 vty_frame(vty, " !\n address-family ");
17783 if (afi == AFI_IP) {
17784 if (safi == SAFI_UNICAST)
17785 vty_frame(vty, "ipv4 unicast");
17786 else if (safi == SAFI_LABELED_UNICAST)
17787 vty_frame(vty, "ipv4 labeled-unicast");
17788 else if (safi == SAFI_MULTICAST)
17789 vty_frame(vty, "ipv4 multicast");
17790 else if (safi == SAFI_MPLS_VPN)
17791 vty_frame(vty, "ipv4 vpn");
17792 else if (safi == SAFI_ENCAP)
17793 vty_frame(vty, "ipv4 encap");
17794 else if (safi == SAFI_FLOWSPEC)
17795 vty_frame(vty, "ipv4 flowspec");
17796 } else if (afi == AFI_IP6) {
17797 if (safi == SAFI_UNICAST)
17798 vty_frame(vty, "ipv6 unicast");
17799 else if (safi == SAFI_LABELED_UNICAST)
17800 vty_frame(vty, "ipv6 labeled-unicast");
17801 else if (safi == SAFI_MULTICAST)
17802 vty_frame(vty, "ipv6 multicast");
17803 else if (safi == SAFI_MPLS_VPN)
17804 vty_frame(vty, "ipv6 vpn");
17805 else if (safi == SAFI_ENCAP)
17806 vty_frame(vty, "ipv6 encap");
17807 else if (safi == SAFI_FLOWSPEC)
17808 vty_frame(vty, "ipv6 flowspec");
17809 } else if (afi == AFI_L2VPN) {
17810 if (safi == SAFI_EVPN)
17811 vty_frame(vty, "l2vpn evpn");
17812 }
17813 vty_frame(vty, "\n");
17814
17815 bgp_config_write_distance(vty, bgp, afi, safi);
17816
17817 bgp_config_write_network(vty, bgp, afi, safi);
17818
17819 bgp_config_write_redistribute(vty, bgp, afi, safi);
17820
17821 /* BGP flag dampening. */
17822 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17823 bgp_config_write_damp(vty, afi, safi);
17824
17825 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17826 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17827
17828 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17829 /* Do not display doppelganger peers */
17830 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17831 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17832 }
17833
17834 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17835 bgp_config_write_table_map(vty, bgp, afi, safi);
17836
17837 if (safi == SAFI_EVPN)
17838 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17839
17840 if (safi == SAFI_FLOWSPEC)
17841 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17842
17843 if (safi == SAFI_MPLS_VPN)
17844 bgp_vpn_config_write(vty, bgp, afi, safi);
17845
17846 if (safi == SAFI_UNICAST) {
17847 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17848 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17849 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17850
17851 vty_out(vty, " export vpn\n");
17852 }
17853 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17854 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17855
17856 vty_out(vty, " import vpn\n");
17857 }
17858 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17859 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17860 char *name;
17861
17862 for (ALL_LIST_ELEMENTS_RO(
17863 bgp->vpn_policy[afi].import_vrf, node,
17864 name))
17865 vty_out(vty, " import vrf %s\n", name);
17866 }
17867 }
17868
17869 vty_endframe(vty, " exit-address-family\n");
17870 }
17871
17872 int bgp_config_write(struct vty *vty)
17873 {
17874 struct bgp *bgp;
17875 struct peer_group *group;
17876 struct peer *peer;
17877 struct listnode *node, *nnode;
17878 struct listnode *mnode, *mnnode;
17879 afi_t afi;
17880 safi_t safi;
17881 uint32_t tovpn_sid_index = 0;
17882
17883 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17884 vty_out(vty, "bgp route-map delay-timer %u\n",
17885 bm->rmap_update_timer);
17886
17887 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17888 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17889 if (bm->v_update_delay != bm->v_establish_wait)
17890 vty_out(vty, " %d", bm->v_establish_wait);
17891 vty_out(vty, "\n");
17892 }
17893
17894 if (bm->wait_for_fib)
17895 vty_out(vty, "bgp suppress-fib-pending\n");
17896
17897 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17898 vty_out(vty, "bgp graceful-shutdown\n");
17899
17900 /* No-RIB (Zebra) option flag configuration */
17901 if (bgp_option_check(BGP_OPT_NO_FIB))
17902 vty_out(vty, "bgp no-rib\n");
17903
17904 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17905 vty_out(vty, "bgp send-extra-data zebra\n");
17906
17907 /* BGP session DSCP value */
17908 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17909 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17910
17911 /* BGP InQ limit */
17912 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
17913 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17914
17915 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
17916 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
17917
17918 /* BGP configuration. */
17919 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17920
17921 /* skip all auto created vrf as they dont have user config */
17922 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17923 continue;
17924
17925 /* Router bgp ASN */
17926 vty_out(vty, "router bgp %u", bgp->as);
17927
17928 if (bgp->name)
17929 vty_out(vty, " %s %s",
17930 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17931 ? "view" : "vrf", bgp->name);
17932 vty_out(vty, "\n");
17933
17934 /* BGP fast-external-failover. */
17935 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17936 vty_out(vty, " no bgp fast-external-failover\n");
17937
17938 /* BGP router ID. */
17939 if (bgp->router_id_static.s_addr != INADDR_ANY)
17940 vty_out(vty, " bgp router-id %pI4\n",
17941 &bgp->router_id_static);
17942
17943 /* Suppress fib pending */
17944 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17945 vty_out(vty, " bgp suppress-fib-pending\n");
17946
17947 /* BGP log-neighbor-changes. */
17948 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17949 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17950 vty_out(vty, " %sbgp log-neighbor-changes\n",
17951 CHECK_FLAG(bgp->flags,
17952 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17953 ? ""
17954 : "no ");
17955
17956 /* BGP configuration. */
17957 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17958 vty_out(vty, " bgp always-compare-med\n");
17959
17960 /* RFC8212 default eBGP policy. */
17961 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17962 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17963 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17964 CHECK_FLAG(bgp->flags,
17965 BGP_FLAG_EBGP_REQUIRES_POLICY)
17966 ? ""
17967 : "no ");
17968
17969 /* draft-ietf-idr-deprecate-as-set-confed-set */
17970 if (bgp->reject_as_sets)
17971 vty_out(vty, " bgp reject-as-sets\n");
17972
17973 /* Suppress duplicate updates if the route actually not changed
17974 */
17975 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17976 != SAVE_BGP_SUPPRESS_DUPLICATES)
17977 vty_out(vty, " %sbgp suppress-duplicates\n",
17978 CHECK_FLAG(bgp->flags,
17979 BGP_FLAG_SUPPRESS_DUPLICATES)
17980 ? ""
17981 : "no ");
17982
17983 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17984 */
17985 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17986 SAVE_BGP_HARD_ADMIN_RESET)
17987 vty_out(vty, " %sbgp hard-administrative-reset\n",
17988 CHECK_FLAG(bgp->flags,
17989 BGP_FLAG_HARD_ADMIN_RESET)
17990 ? ""
17991 : "no ");
17992
17993 /* BGP default <afi>-<safi> */
17994 FOREACH_AFI_SAFI (afi, safi) {
17995 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17996 if (!bgp->default_af[afi][safi])
17997 vty_out(vty, " no bgp default %s\n",
17998 get_bgp_default_af_flag(afi,
17999 safi));
18000 } else if (bgp->default_af[afi][safi])
18001 vty_out(vty, " bgp default %s\n",
18002 get_bgp_default_af_flag(afi, safi));
18003 }
18004
18005 /* BGP default local-preference. */
18006 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18007 vty_out(vty, " bgp default local-preference %u\n",
18008 bgp->default_local_pref);
18009
18010 /* BGP default show-hostname */
18011 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18012 != SAVE_BGP_SHOW_HOSTNAME)
18013 vty_out(vty, " %sbgp default show-hostname\n",
18014 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18015 ? ""
18016 : "no ");
18017
18018 /* BGP default show-nexthop-hostname */
18019 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18020 != SAVE_BGP_SHOW_HOSTNAME)
18021 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18022 CHECK_FLAG(bgp->flags,
18023 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18024 ? ""
18025 : "no ");
18026
18027 /* BGP default subgroup-pkt-queue-max. */
18028 if (bgp->default_subgroup_pkt_queue_max
18029 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18030 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18031 bgp->default_subgroup_pkt_queue_max);
18032
18033 /* BGP client-to-client reflection. */
18034 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18035 vty_out(vty, " no bgp client-to-client reflection\n");
18036
18037 /* BGP cluster ID. */
18038 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18039 vty_out(vty, " bgp cluster-id %pI4\n",
18040 &bgp->cluster_id);
18041
18042 /* Disable ebgp connected nexthop check */
18043 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18044 vty_out(vty,
18045 " bgp disable-ebgp-connected-route-check\n");
18046
18047 /* Confederation identifier*/
18048 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18049 vty_out(vty, " bgp confederation identifier %u\n",
18050 bgp->confed_id);
18051
18052 /* Confederation peer */
18053 if (bgp->confed_peers_cnt > 0) {
18054 int i;
18055
18056 vty_out(vty, " bgp confederation peers");
18057
18058 for (i = 0; i < bgp->confed_peers_cnt; i++)
18059 vty_out(vty, " %u", bgp->confed_peers[i]);
18060
18061 vty_out(vty, "\n");
18062 }
18063
18064 /* BGP deterministic-med. */
18065 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18066 != SAVE_BGP_DETERMINISTIC_MED)
18067 vty_out(vty, " %sbgp deterministic-med\n",
18068 CHECK_FLAG(bgp->flags,
18069 BGP_FLAG_DETERMINISTIC_MED)
18070 ? ""
18071 : "no ");
18072
18073 /* BGP update-delay. */
18074 bgp_config_write_update_delay(vty, bgp);
18075
18076 if (bgp->v_maxmed_onstartup
18077 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18078 vty_out(vty, " bgp max-med on-startup %u",
18079 bgp->v_maxmed_onstartup);
18080 if (bgp->maxmed_onstartup_value
18081 != BGP_MAXMED_VALUE_DEFAULT)
18082 vty_out(vty, " %u",
18083 bgp->maxmed_onstartup_value);
18084 vty_out(vty, "\n");
18085 }
18086 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18087 vty_out(vty, " bgp max-med administrative");
18088 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18089 vty_out(vty, " %u", bgp->maxmed_admin_value);
18090 vty_out(vty, "\n");
18091 }
18092
18093 /* write quanta */
18094 bgp_config_write_wpkt_quanta(vty, bgp);
18095 /* read quanta */
18096 bgp_config_write_rpkt_quanta(vty, bgp);
18097
18098 /* coalesce time */
18099 bgp_config_write_coalesce_time(vty, bgp);
18100
18101 /* BGP per-instance graceful-shutdown */
18102 /* BGP-wide settings and per-instance settings are mutually
18103 * exclusive.
18104 */
18105 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18106 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18107 vty_out(vty, " bgp graceful-shutdown\n");
18108
18109 /* Long-lived Graceful Restart */
18110 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18111 vty_out(vty,
18112 " bgp long-lived-graceful-restart stale-time %u\n",
18113 bgp->llgr_stale_time);
18114
18115 /* BGP graceful-restart. */
18116 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18117 vty_out(vty,
18118 " bgp graceful-restart stalepath-time %u\n",
18119 bgp->stalepath_time);
18120
18121 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18122 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18123 bgp->restart_time);
18124
18125 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18126 SAVE_BGP_GRACEFUL_NOTIFICATION)
18127 vty_out(vty, " %sbgp graceful-restart notification\n",
18128 CHECK_FLAG(bgp->flags,
18129 BGP_FLAG_GRACEFUL_NOTIFICATION)
18130 ? ""
18131 : "no ");
18132
18133 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18134 vty_out(vty,
18135 " bgp graceful-restart select-defer-time %u\n",
18136 bgp->select_defer_time);
18137
18138 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18139 vty_out(vty, " bgp graceful-restart\n");
18140
18141 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18142 vty_out(vty, " bgp graceful-restart-disable\n");
18143
18144 /* BGP graceful-restart Preserve State F bit. */
18145 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18146 vty_out(vty,
18147 " bgp graceful-restart preserve-fw-state\n");
18148
18149 /* BGP TCP keepalive */
18150 bgp_config_tcp_keepalive(vty, bgp);
18151
18152 /* Stale timer for RIB */
18153 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18154 vty_out(vty,
18155 " bgp graceful-restart rib-stale-time %u\n",
18156 bgp->rib_stale_time);
18157
18158 /* BGP bestpath method. */
18159 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18160 vty_out(vty, " bgp bestpath as-path ignore\n");
18161 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18162 vty_out(vty, " bgp bestpath as-path confed\n");
18163
18164 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18165 if (CHECK_FLAG(bgp->flags,
18166 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18167 vty_out(vty,
18168 " bgp bestpath as-path multipath-relax as-set\n");
18169 } else {
18170 vty_out(vty,
18171 " bgp bestpath as-path multipath-relax\n");
18172 }
18173 }
18174
18175 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18176 vty_out(vty,
18177 " bgp route-reflector allow-outbound-policy\n");
18178 }
18179 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18180 vty_out(vty, " bgp bestpath compare-routerid\n");
18181 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18182 vty_out(vty, " bgp bestpath aigp\n");
18183 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18184 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18185 vty_out(vty, " bgp bestpath med");
18186 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18187 vty_out(vty, " confed");
18188 if (CHECK_FLAG(bgp->flags,
18189 BGP_FLAG_MED_MISSING_AS_WORST))
18190 vty_out(vty, " missing-as-worst");
18191 vty_out(vty, "\n");
18192 }
18193
18194 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18195 vty_out(vty,
18196 " bgp bestpath peer-type multipath-relax\n");
18197
18198 /* Link bandwidth handling. */
18199 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18200 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18201 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18202 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18203 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18204 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18205
18206 /* BGP network import check. */
18207 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18208 != SAVE_BGP_IMPORT_CHECK)
18209 vty_out(vty, " %sbgp network import-check\n",
18210 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18211 ? ""
18212 : "no ");
18213
18214 /* BGP timers configuration. */
18215 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18216 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18217 vty_out(vty, " timers bgp %u %u\n",
18218 bgp->default_keepalive, bgp->default_holdtime);
18219
18220 /* BGP minimum holdtime configuration. */
18221 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18222 && bgp->default_min_holdtime != 0)
18223 vty_out(vty, " bgp minimum-holdtime %u\n",
18224 bgp->default_min_holdtime);
18225
18226 /* Conditional advertisement timer configuration */
18227 if (bgp->condition_check_period
18228 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18229 vty_out(vty,
18230 " bgp conditional-advertisement timer %u\n",
18231 bgp->condition_check_period);
18232
18233 /* peer-group */
18234 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18235 bgp_config_write_peer_global(vty, bgp, group->conf);
18236 }
18237
18238 /* Normal neighbor configuration. */
18239 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18240 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18241 bgp_config_write_peer_global(vty, bgp, peer);
18242 }
18243
18244 /* listen range and limit for dynamic BGP neighbors */
18245 bgp_config_write_listen(vty, bgp);
18246
18247 /*
18248 * BGP default autoshutdown neighbors
18249 *
18250 * This must be placed after any peer and peer-group
18251 * configuration, to avoid setting all peers to shutdown after
18252 * a daemon restart, which is undesired behavior. (see #2286)
18253 */
18254 if (bgp->autoshutdown)
18255 vty_out(vty, " bgp default shutdown\n");
18256
18257 /* BGP instance administrative shutdown */
18258 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18259 vty_out(vty, " bgp shutdown\n");
18260
18261 if (bgp->allow_martian)
18262 vty_out(vty, " bgp allow-martian-nexthop\n");
18263
18264 if (bgp->fast_convergence)
18265 vty_out(vty, " bgp fast-convergence\n");
18266
18267 if (bgp->srv6_enabled) {
18268 vty_frame(vty, " !\n segment-routing srv6\n");
18269 if (strlen(bgp->srv6_locator_name))
18270 vty_out(vty, " locator %s\n",
18271 bgp->srv6_locator_name);
18272 vty_endframe(vty, " exit\n");
18273 }
18274
18275 tovpn_sid_index = bgp->tovpn_sid_index;
18276 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18277 vty_out(vty, " sid vpn per-vrf export auto\n");
18278 } else if (tovpn_sid_index != 0) {
18279 vty_out(vty, " sid vpn per-vrf export %d\n",
18280 tovpn_sid_index);
18281 }
18282
18283 /* IPv4 unicast configuration. */
18284 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18285
18286 /* IPv4 multicast configuration. */
18287 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18288
18289 /* IPv4 labeled-unicast configuration. */
18290 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18291
18292 /* IPv4 VPN configuration. */
18293 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18294
18295 /* ENCAPv4 configuration. */
18296 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18297
18298 /* FLOWSPEC v4 configuration. */
18299 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18300
18301 /* IPv6 unicast configuration. */
18302 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18303
18304 /* IPv6 multicast configuration. */
18305 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18306
18307 /* IPv6 labeled-unicast configuration. */
18308 bgp_config_write_family(vty, bgp, AFI_IP6,
18309 SAFI_LABELED_UNICAST);
18310
18311 /* IPv6 VPN configuration. */
18312 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18313
18314 /* ENCAPv6 configuration. */
18315 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18316
18317 /* FLOWSPEC v6 configuration. */
18318 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18319
18320 /* EVPN configuration. */
18321 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18322
18323 hook_call(bgp_inst_config_write, bgp, vty);
18324
18325 #ifdef ENABLE_BGP_VNC
18326 bgp_rfapi_cfg_write(vty, bgp);
18327 #endif
18328
18329 vty_out(vty, "exit\n");
18330 vty_out(vty, "!\n");
18331 }
18332 return 0;
18333 }
18334
18335
18336 /* BGP node structure. */
18337 static struct cmd_node bgp_node = {
18338 .name = "bgp",
18339 .node = BGP_NODE,
18340 .parent_node = CONFIG_NODE,
18341 .prompt = "%s(config-router)# ",
18342 .config_write = bgp_config_write,
18343 };
18344
18345 static struct cmd_node bgp_ipv4_unicast_node = {
18346 .name = "bgp ipv4 unicast",
18347 .node = BGP_IPV4_NODE,
18348 .parent_node = BGP_NODE,
18349 .prompt = "%s(config-router-af)# ",
18350 .no_xpath = true,
18351 };
18352
18353 static struct cmd_node bgp_ipv4_multicast_node = {
18354 .name = "bgp ipv4 multicast",
18355 .node = BGP_IPV4M_NODE,
18356 .parent_node = BGP_NODE,
18357 .prompt = "%s(config-router-af)# ",
18358 .no_xpath = true,
18359 };
18360
18361 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18362 .name = "bgp ipv4 labeled unicast",
18363 .node = BGP_IPV4L_NODE,
18364 .parent_node = BGP_NODE,
18365 .prompt = "%s(config-router-af)# ",
18366 .no_xpath = true,
18367 };
18368
18369 static struct cmd_node bgp_ipv6_unicast_node = {
18370 .name = "bgp ipv6 unicast",
18371 .node = BGP_IPV6_NODE,
18372 .parent_node = BGP_NODE,
18373 .prompt = "%s(config-router-af)# ",
18374 .no_xpath = true,
18375 };
18376
18377 static struct cmd_node bgp_ipv6_multicast_node = {
18378 .name = "bgp ipv6 multicast",
18379 .node = BGP_IPV6M_NODE,
18380 .parent_node = BGP_NODE,
18381 .prompt = "%s(config-router-af)# ",
18382 .no_xpath = true,
18383 };
18384
18385 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18386 .name = "bgp ipv6 labeled unicast",
18387 .node = BGP_IPV6L_NODE,
18388 .parent_node = BGP_NODE,
18389 .prompt = "%s(config-router-af)# ",
18390 .no_xpath = true,
18391 };
18392
18393 static struct cmd_node bgp_vpnv4_node = {
18394 .name = "bgp vpnv4",
18395 .node = BGP_VPNV4_NODE,
18396 .parent_node = BGP_NODE,
18397 .prompt = "%s(config-router-af)# ",
18398 .no_xpath = true,
18399 };
18400
18401 static struct cmd_node bgp_vpnv6_node = {
18402 .name = "bgp vpnv6",
18403 .node = BGP_VPNV6_NODE,
18404 .parent_node = BGP_NODE,
18405 .prompt = "%s(config-router-af-vpnv6)# ",
18406 .no_xpath = true,
18407 };
18408
18409 static struct cmd_node bgp_evpn_node = {
18410 .name = "bgp evpn",
18411 .node = BGP_EVPN_NODE,
18412 .parent_node = BGP_NODE,
18413 .prompt = "%s(config-router-evpn)# ",
18414 .no_xpath = true,
18415 };
18416
18417 static struct cmd_node bgp_evpn_vni_node = {
18418 .name = "bgp evpn vni",
18419 .node = BGP_EVPN_VNI_NODE,
18420 .parent_node = BGP_EVPN_NODE,
18421 .prompt = "%s(config-router-af-vni)# ",
18422 };
18423
18424 static struct cmd_node bgp_flowspecv4_node = {
18425 .name = "bgp ipv4 flowspec",
18426 .node = BGP_FLOWSPECV4_NODE,
18427 .parent_node = BGP_NODE,
18428 .prompt = "%s(config-router-af)# ",
18429 .no_xpath = true,
18430 };
18431
18432 static struct cmd_node bgp_flowspecv6_node = {
18433 .name = "bgp ipv6 flowspec",
18434 .node = BGP_FLOWSPECV6_NODE,
18435 .parent_node = BGP_NODE,
18436 .prompt = "%s(config-router-af-vpnv6)# ",
18437 .no_xpath = true,
18438 };
18439
18440 static struct cmd_node bgp_srv6_node = {
18441 .name = "bgp srv6",
18442 .node = BGP_SRV6_NODE,
18443 .parent_node = BGP_NODE,
18444 .prompt = "%s(config-router-srv6)# ",
18445 };
18446
18447 static void community_list_vty(void);
18448
18449 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18450 {
18451 struct bgp *bgp;
18452 struct peer_group *group;
18453 struct listnode *lnbgp, *lnpeer;
18454
18455 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18456 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18457 vector_set(comps,
18458 XSTRDUP(MTYPE_COMPLETION, group->name));
18459 }
18460 }
18461
18462 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18463 {
18464 struct bgp *bgp;
18465 struct peer *peer;
18466 struct listnode *lnbgp, *lnpeer;
18467
18468 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18469 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18470 /* only provide suggestions on the appropriate input
18471 * token type,
18472 * they'll otherwise show up multiple times */
18473 enum cmd_token_type match_type;
18474 char *name = peer->host;
18475
18476 if (peer->conf_if) {
18477 match_type = VARIABLE_TKN;
18478 name = peer->conf_if;
18479 } else if (strchr(peer->host, ':'))
18480 match_type = IPV6_TKN;
18481 else
18482 match_type = IPV4_TKN;
18483
18484 if (token->type != match_type)
18485 continue;
18486
18487 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18488 }
18489 }
18490 }
18491
18492 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18493 {
18494 bgp_ac_peer(comps, token);
18495
18496 if (token->type == VARIABLE_TKN)
18497 bgp_ac_peergroup(comps, token);
18498 }
18499
18500 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18501 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18502 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18503 {.varname = "peer", .completions = bgp_ac_neighbor},
18504 {.completions = NULL}};
18505
18506 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18507 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18508 {.completions = NULL} };
18509
18510 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18511
18512 static struct thread *t_bgp_cfg;
18513
18514 bool bgp_config_inprocess(void)
18515 {
18516 return thread_is_scheduled(t_bgp_cfg);
18517 }
18518
18519 static void bgp_config_finish(struct thread *t)
18520 {
18521 struct listnode *node;
18522 struct bgp *bgp;
18523
18524 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18525 hook_call(bgp_config_end, bgp);
18526 }
18527
18528 static void bgp_config_start(void)
18529 {
18530 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18531 THREAD_OFF(t_bgp_cfg);
18532 thread_add_timer(bm->master, bgp_config_finish, NULL,
18533 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18534 }
18535
18536 /* When we receive a hook the configuration is read,
18537 * we start a timer to make sure we postpone sending
18538 * EoR before route-maps are processed.
18539 * This is especially valid if using `bgp route-map delay-timer`.
18540 */
18541 static void bgp_config_end(void)
18542 {
18543 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18544 uint32_t bgp_post_config_delay =
18545 thread_is_scheduled(bm->t_rmap_update)
18546 ? thread_timer_remain_second(bm->t_rmap_update)
18547 : BGP_POST_CONFIG_DELAY_SECONDS;
18548
18549 /* If BGP config processing thread isn't running, then
18550 * we can return and rely it's properly handled.
18551 */
18552 if (!bgp_config_inprocess())
18553 return;
18554
18555 THREAD_OFF(t_bgp_cfg);
18556
18557 /* Start a new timer to make sure we don't send EoR
18558 * before route-maps are processed.
18559 */
18560 thread_add_timer(bm->master, bgp_config_finish, NULL,
18561 bgp_post_config_delay, &t_bgp_cfg);
18562 }
18563
18564 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18565 {
18566 int write = 0;
18567 struct interface *ifp;
18568 struct bgp_interface *iifp;
18569
18570 FOR_ALL_INTERFACES (vrf, ifp) {
18571 iifp = ifp->info;
18572 if (!iifp)
18573 continue;
18574
18575 if_vty_config_start(vty, ifp);
18576
18577 if (CHECK_FLAG(iifp->flags,
18578 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18579 vty_out(vty, " mpls bgp forwarding\n");
18580 write++;
18581 }
18582
18583 if_vty_config_end(vty);
18584 }
18585
18586 return write;
18587 }
18588
18589 /* Configuration write function for bgpd. */
18590 static int config_write_interface(struct vty *vty)
18591 {
18592 int write = 0;
18593 struct vrf *vrf = NULL;
18594
18595 /* Display all VRF aware OSPF interface configuration */
18596 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18597 write += config_write_interface_one(vty, vrf);
18598 }
18599
18600 return write;
18601 }
18602
18603 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18604 "[no$no] mpls bgp forwarding",
18605 NO_STR MPLS_STR BGP_STR
18606 "Enable MPLS forwarding for eBGP directly connected peers\n")
18607 {
18608 bool check;
18609 struct bgp_interface *iifp;
18610
18611 VTY_DECLVAR_CONTEXT(interface, ifp);
18612 iifp = ifp->info;
18613 if (!iifp) {
18614 vty_out(vty, "Interface %s not available\n", ifp->name);
18615 return CMD_WARNING_CONFIG_FAILED;
18616 }
18617 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18618 if (check != !no) {
18619 if (no)
18620 UNSET_FLAG(iifp->flags,
18621 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18622 else
18623 SET_FLAG(iifp->flags,
18624 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18625 /* trigger a nht update on eBGP sessions */
18626 if (if_is_operative(ifp))
18627 bgp_nht_ifp_up(ifp);
18628 }
18629 return CMD_SUCCESS;
18630 }
18631
18632 DEFPY (bgp_inq_limit,
18633 bgp_inq_limit_cmd,
18634 "bgp input-queue-limit (1-4294967295)$limit",
18635 BGP_STR
18636 "Set the BGP Input Queue limit for all peers when message parsing\n"
18637 "Input-Queue limit\n")
18638 {
18639 bm->inq_limit = limit;
18640
18641 return CMD_SUCCESS;
18642 }
18643
18644 DEFPY (no_bgp_inq_limit,
18645 no_bgp_inq_limit_cmd,
18646 "no bgp input-queue-limit [(1-4294967295)$limit]",
18647 NO_STR
18648 BGP_STR
18649 "Set the BGP Input Queue limit for all peers when message parsing\n"
18650 "Input-Queue limit\n")
18651 {
18652 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18653
18654 return CMD_SUCCESS;
18655 }
18656
18657 DEFPY (bgp_outq_limit,
18658 bgp_outq_limit_cmd,
18659 "bgp output-queue-limit (1-4294967295)$limit",
18660 BGP_STR
18661 "Set the BGP Output Queue limit for all peers when message parsing\n"
18662 "Output-Queue limit\n")
18663 {
18664 bm->outq_limit = limit;
18665
18666 return CMD_SUCCESS;
18667 }
18668
18669 DEFPY (no_bgp_outq_limit,
18670 no_bgp_outq_limit_cmd,
18671 "no bgp output-queue-limit [(1-4294967295)$limit]",
18672 NO_STR
18673 BGP_STR
18674 "Set the BGP Output Queue limit for all peers when message parsing\n"
18675 "Output-Queue limit\n")
18676 {
18677 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18678
18679 return CMD_SUCCESS;
18680 }
18681
18682
18683 /* Initialization of BGP interface. */
18684 static void bgp_vty_if_init(void)
18685 {
18686 /* Install interface node. */
18687 if_cmd_init(config_write_interface);
18688
18689 /* "mpls bgp forwarding" commands. */
18690 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18691 }
18692
18693 void bgp_vty_init(void)
18694 {
18695 cmd_variable_handler_register(bgp_var_neighbor);
18696 cmd_variable_handler_register(bgp_var_peergroup);
18697
18698 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18699
18700 /* Install bgp top node. */
18701 install_node(&bgp_node);
18702 install_node(&bgp_ipv4_unicast_node);
18703 install_node(&bgp_ipv4_multicast_node);
18704 install_node(&bgp_ipv4_labeled_unicast_node);
18705 install_node(&bgp_ipv6_unicast_node);
18706 install_node(&bgp_ipv6_multicast_node);
18707 install_node(&bgp_ipv6_labeled_unicast_node);
18708 install_node(&bgp_vpnv4_node);
18709 install_node(&bgp_vpnv6_node);
18710 install_node(&bgp_evpn_node);
18711 install_node(&bgp_evpn_vni_node);
18712 install_node(&bgp_flowspecv4_node);
18713 install_node(&bgp_flowspecv6_node);
18714 install_node(&bgp_srv6_node);
18715
18716 /* Install default VTY commands to new nodes. */
18717 install_default(BGP_NODE);
18718 install_default(BGP_IPV4_NODE);
18719 install_default(BGP_IPV4M_NODE);
18720 install_default(BGP_IPV4L_NODE);
18721 install_default(BGP_IPV6_NODE);
18722 install_default(BGP_IPV6M_NODE);
18723 install_default(BGP_IPV6L_NODE);
18724 install_default(BGP_VPNV4_NODE);
18725 install_default(BGP_VPNV6_NODE);
18726 install_default(BGP_FLOWSPECV4_NODE);
18727 install_default(BGP_FLOWSPECV6_NODE);
18728 install_default(BGP_EVPN_NODE);
18729 install_default(BGP_EVPN_VNI_NODE);
18730 install_default(BGP_SRV6_NODE);
18731
18732 /* "global bgp inq-limit command */
18733 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18734 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18735 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18736 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
18737
18738 /* "bgp local-mac" hidden commands. */
18739 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18740 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18741
18742 /* "bgp suppress-fib-pending" global */
18743 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18744
18745 /* bgp route-map delay-timer commands. */
18746 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18747 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18748
18749 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18750
18751 /* bgp fast-convergence command */
18752 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18753 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18754
18755 /* global bgp update-delay command */
18756 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18757 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18758
18759 /* global bgp graceful-shutdown command */
18760 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18761 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18762
18763 /* Dummy commands (Currently not supported) */
18764 install_element(BGP_NODE, &no_synchronization_cmd);
18765 install_element(BGP_NODE, &no_auto_summary_cmd);
18766
18767 /* "router bgp" commands. */
18768 install_element(CONFIG_NODE, &router_bgp_cmd);
18769
18770 /* "no router bgp" commands. */
18771 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18772
18773 /* "bgp session-dscp command */
18774 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18775 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18776
18777 /* "bgp router-id" commands. */
18778 install_element(BGP_NODE, &bgp_router_id_cmd);
18779 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18780
18781 /* "bgp suppress-fib-pending" command */
18782 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18783
18784 /* "bgp cluster-id" commands. */
18785 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18786 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18787
18788 /* "bgp no-rib" commands. */
18789 install_element(CONFIG_NODE, &bgp_norib_cmd);
18790 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18791
18792 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18793
18794 /* "bgp confederation" commands. */
18795 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18796 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18797
18798 /* "bgp confederation peers" commands. */
18799 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18800 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18801
18802 /* bgp max-med command */
18803 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18804 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18805 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18806 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18807 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18808
18809 /* "neighbor role" commands. */
18810 install_element(BGP_NODE, &neighbor_role_cmd);
18811 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18812 install_element(BGP_NODE, &no_neighbor_role_cmd);
18813
18814 /* "neighbor aigp" commands. */
18815 install_element(BGP_NODE, &neighbor_aigp_cmd);
18816
18817 /* "neighbor graceful-shutdown" command */
18818 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18819
18820 /* bgp disable-ebgp-connected-nh-check */
18821 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18822 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18823
18824 /* bgp update-delay command */
18825 install_element(BGP_NODE, &bgp_update_delay_cmd);
18826 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18827
18828 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18829 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18830
18831 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18832 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18833
18834 /* "maximum-paths" commands. */
18835 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18836 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18837 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18838 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18839 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18840 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18841 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18842 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18843 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18844 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18845 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18846 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18847 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18848 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18849 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18850
18851 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18852 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18853 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18854 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18855 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18856 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18857 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18858 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18859 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18860 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18861
18862 /* "timers bgp" commands. */
18863 install_element(BGP_NODE, &bgp_timers_cmd);
18864 install_element(BGP_NODE, &no_bgp_timers_cmd);
18865
18866 /* "minimum-holdtime" commands. */
18867 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18868 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18869
18870 /* route-map delay-timer commands - per instance for backwards compat.
18871 */
18872 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18873 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18874
18875 /* "bgp client-to-client reflection" commands */
18876 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18877 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18878
18879 /* "bgp always-compare-med" commands */
18880 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18881 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18882
18883 /* bgp ebgp-requires-policy */
18884 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18885 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18886
18887 /* bgp suppress-duplicates */
18888 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18889 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18890
18891 /* bgp reject-as-sets */
18892 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18893 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18894
18895 /* "bgp deterministic-med" commands */
18896 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18897 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18898
18899 /* "bgp graceful-restart" command */
18900 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18901 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18902
18903 /* "bgp graceful-restart-disable" command */
18904 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18905 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18906
18907 /* "neighbor a:b:c:d graceful-restart" command */
18908 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18909 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18910
18911 /* "neighbor a:b:c:d graceful-restart-disable" command */
18912 install_element(BGP_NODE,
18913 &bgp_neighbor_graceful_restart_disable_set_cmd);
18914 install_element(BGP_NODE,
18915 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18916
18917 /* "neighbor a:b:c:d graceful-restart-helper" command */
18918 install_element(BGP_NODE,
18919 &bgp_neighbor_graceful_restart_helper_set_cmd);
18920 install_element(BGP_NODE,
18921 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18922
18923 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18924 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18925 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18926 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18927 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18928 install_element(BGP_NODE,
18929 &no_bgp_graceful_restart_select_defer_time_cmd);
18930 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18931 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18932 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18933
18934 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18935 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18936 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18937 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18938
18939 /* "bgp graceful-shutdown" commands */
18940 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18941 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18942
18943 /* "bgp hard-administrative-reset" commands */
18944 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18945
18946 /* "bgp long-lived-graceful-restart" commands */
18947 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18948 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18949
18950 /* "bgp fast-external-failover" commands */
18951 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18952 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18953
18954 /* "bgp bestpath aigp" commands */
18955 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
18956
18957 /* "bgp bestpath compare-routerid" commands */
18958 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18959 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18960
18961 /* "bgp bestpath as-path ignore" commands */
18962 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18963 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18964
18965 /* "bgp bestpath as-path confed" commands */
18966 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18967 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18968
18969 /* "bgp bestpath as-path multipath-relax" commands */
18970 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18971 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18972
18973 /* "bgp bestpath peer-type multipath-relax" commands */
18974 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18975 install_element(BGP_NODE,
18976 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18977
18978 /* "bgp log-neighbor-changes" commands */
18979 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18980 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18981
18982 /* "bgp bestpath med" commands */
18983 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18984 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18985
18986 /* "bgp bestpath bandwidth" commands */
18987 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18988 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18989
18990 /* "no bgp default <afi>-<safi>" commands. */
18991 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18992
18993 /* "bgp network import-check" commands. */
18994 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18995 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18996 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18997
18998 /* "bgp default local-preference" commands. */
18999 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19000 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19001
19002 /* bgp default show-hostname */
19003 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19004 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19005
19006 /* bgp default show-nexthop-hostname */
19007 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19008 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19009
19010 /* "bgp default subgroup-pkt-queue-max" commands. */
19011 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19012 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19013
19014 /* bgp ibgp-allow-policy-mods command */
19015 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19016 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19017
19018 /* "bgp listen limit" commands. */
19019 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19020 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19021
19022 /* "bgp listen range" commands. */
19023 install_element(BGP_NODE, &bgp_listen_range_cmd);
19024 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19025
19026 /* "bgp default shutdown" command */
19027 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19028
19029 /* "bgp shutdown" commands */
19030 install_element(BGP_NODE, &bgp_shutdown_cmd);
19031 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19032 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19033 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19034
19035 /* "neighbor remote-as" commands. */
19036 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19037 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19038 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19039 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19040 install_element(BGP_NODE,
19041 &neighbor_interface_v6only_config_remote_as_cmd);
19042 install_element(BGP_NODE, &no_neighbor_cmd);
19043 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19044
19045 /* "neighbor peer-group" commands. */
19046 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19047 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19048 install_element(BGP_NODE,
19049 &no_neighbor_interface_peer_group_remote_as_cmd);
19050
19051 /* "neighbor local-as" commands. */
19052 install_element(BGP_NODE, &neighbor_local_as_cmd);
19053 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19054 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19055 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19056
19057 /* "neighbor solo" commands. */
19058 install_element(BGP_NODE, &neighbor_solo_cmd);
19059 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19060
19061 /* "neighbor password" commands. */
19062 install_element(BGP_NODE, &neighbor_password_cmd);
19063 install_element(BGP_NODE, &no_neighbor_password_cmd);
19064
19065 /* "neighbor activate" commands. */
19066 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19067 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19068 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19069 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19070 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19071 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19072 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19073 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19074 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19075 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19076 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19077 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19078
19079 /* "no neighbor activate" commands. */
19080 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19081 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19082 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19083 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19084 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19085 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19086 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19087 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19088 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19089 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19090 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19091 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19092
19093 /* "neighbor peer-group" set commands. */
19094 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19095 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19096 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19097 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19098 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19099 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19100 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19101 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19102 install_element(BGP_FLOWSPECV4_NODE,
19103 &neighbor_set_peer_group_hidden_cmd);
19104 install_element(BGP_FLOWSPECV6_NODE,
19105 &neighbor_set_peer_group_hidden_cmd);
19106
19107 /* "no neighbor peer-group unset" commands. */
19108 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19109 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19110 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19111 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19112 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19113 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19114 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19115 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19116 install_element(BGP_FLOWSPECV4_NODE,
19117 &no_neighbor_set_peer_group_hidden_cmd);
19118 install_element(BGP_FLOWSPECV6_NODE,
19119 &no_neighbor_set_peer_group_hidden_cmd);
19120
19121 /* "neighbor softreconfiguration inbound" commands.*/
19122 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19123 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19124 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19125 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19126 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19127 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19128 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19129 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19130 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19131 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19132 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19133 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19134 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19135 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19136 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19137 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19138 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19139 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19140 install_element(BGP_FLOWSPECV4_NODE,
19141 &neighbor_soft_reconfiguration_cmd);
19142 install_element(BGP_FLOWSPECV4_NODE,
19143 &no_neighbor_soft_reconfiguration_cmd);
19144 install_element(BGP_FLOWSPECV6_NODE,
19145 &neighbor_soft_reconfiguration_cmd);
19146 install_element(BGP_FLOWSPECV6_NODE,
19147 &no_neighbor_soft_reconfiguration_cmd);
19148 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19149 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19150
19151 /* "neighbor attribute-unchanged" commands. */
19152 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19153 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19154 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19155 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19156 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19157 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19158 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19159 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19160 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19161 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19162 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19163 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19164 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19165 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19166 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19167 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19168 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19169 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19170
19171 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19172 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19173
19174 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19175 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19176 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19177 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19178
19179 /* "nexthop-local unchanged" commands */
19180 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19181 install_element(BGP_IPV6_NODE,
19182 &no_neighbor_nexthop_local_unchanged_cmd);
19183
19184 /* "neighbor next-hop-self" commands. */
19185 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19186 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19187 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19188 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19189 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19190 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19191 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19192 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19193 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19194 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19195 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19196 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19197 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19198 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19199 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19200 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19201 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19202 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19203 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19204 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19205
19206 /* "neighbor next-hop-self force" commands. */
19207 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19208 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19209 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19210 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19211 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19212 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19213 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19214 install_element(BGP_IPV4_NODE,
19215 &no_neighbor_nexthop_self_all_hidden_cmd);
19216 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19217 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19218 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19219 install_element(BGP_IPV4M_NODE,
19220 &no_neighbor_nexthop_self_all_hidden_cmd);
19221 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19222 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19223 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19224 install_element(BGP_IPV4L_NODE,
19225 &no_neighbor_nexthop_self_all_hidden_cmd);
19226 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19227 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19228 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19229 install_element(BGP_IPV6_NODE,
19230 &no_neighbor_nexthop_self_all_hidden_cmd);
19231 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19232 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19233 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19234 install_element(BGP_IPV6M_NODE,
19235 &no_neighbor_nexthop_self_all_hidden_cmd);
19236 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19237 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19238 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19239 install_element(BGP_IPV6L_NODE,
19240 &no_neighbor_nexthop_self_all_hidden_cmd);
19241 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19242 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19243 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19244 install_element(BGP_VPNV4_NODE,
19245 &no_neighbor_nexthop_self_all_hidden_cmd);
19246 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19247 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19248 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19249 install_element(BGP_VPNV6_NODE,
19250 &no_neighbor_nexthop_self_all_hidden_cmd);
19251 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19252 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19253
19254 /* "neighbor as-override" commands. */
19255 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19256 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19257 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19258 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19259 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19260 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19261 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19262 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19263 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19264 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19265 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19266 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19267 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19268 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19269 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19270 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19271 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19272 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19273
19274 /* "neighbor remove-private-AS" commands. */
19275 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19276 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19277 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19278 install_element(BGP_NODE,
19279 &no_neighbor_remove_private_as_all_hidden_cmd);
19280 install_element(BGP_NODE,
19281 &neighbor_remove_private_as_replace_as_hidden_cmd);
19282 install_element(BGP_NODE,
19283 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19284 install_element(BGP_NODE,
19285 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19286 install_element(
19287 BGP_NODE,
19288 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19289 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19290 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19291 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19292 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19293 install_element(BGP_IPV4_NODE,
19294 &neighbor_remove_private_as_replace_as_cmd);
19295 install_element(BGP_IPV4_NODE,
19296 &no_neighbor_remove_private_as_replace_as_cmd);
19297 install_element(BGP_IPV4_NODE,
19298 &neighbor_remove_private_as_all_replace_as_cmd);
19299 install_element(BGP_IPV4_NODE,
19300 &no_neighbor_remove_private_as_all_replace_as_cmd);
19301 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19302 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19303 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19304 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19305 install_element(BGP_IPV4M_NODE,
19306 &neighbor_remove_private_as_replace_as_cmd);
19307 install_element(BGP_IPV4M_NODE,
19308 &no_neighbor_remove_private_as_replace_as_cmd);
19309 install_element(BGP_IPV4M_NODE,
19310 &neighbor_remove_private_as_all_replace_as_cmd);
19311 install_element(BGP_IPV4M_NODE,
19312 &no_neighbor_remove_private_as_all_replace_as_cmd);
19313 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19314 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19315 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19316 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19317 install_element(BGP_IPV4L_NODE,
19318 &neighbor_remove_private_as_replace_as_cmd);
19319 install_element(BGP_IPV4L_NODE,
19320 &no_neighbor_remove_private_as_replace_as_cmd);
19321 install_element(BGP_IPV4L_NODE,
19322 &neighbor_remove_private_as_all_replace_as_cmd);
19323 install_element(BGP_IPV4L_NODE,
19324 &no_neighbor_remove_private_as_all_replace_as_cmd);
19325 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19326 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19327 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19328 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19329 install_element(BGP_IPV6_NODE,
19330 &neighbor_remove_private_as_replace_as_cmd);
19331 install_element(BGP_IPV6_NODE,
19332 &no_neighbor_remove_private_as_replace_as_cmd);
19333 install_element(BGP_IPV6_NODE,
19334 &neighbor_remove_private_as_all_replace_as_cmd);
19335 install_element(BGP_IPV6_NODE,
19336 &no_neighbor_remove_private_as_all_replace_as_cmd);
19337 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19338 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19339 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19340 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19341 install_element(BGP_IPV6M_NODE,
19342 &neighbor_remove_private_as_replace_as_cmd);
19343 install_element(BGP_IPV6M_NODE,
19344 &no_neighbor_remove_private_as_replace_as_cmd);
19345 install_element(BGP_IPV6M_NODE,
19346 &neighbor_remove_private_as_all_replace_as_cmd);
19347 install_element(BGP_IPV6M_NODE,
19348 &no_neighbor_remove_private_as_all_replace_as_cmd);
19349 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19350 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19351 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19352 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19353 install_element(BGP_IPV6L_NODE,
19354 &neighbor_remove_private_as_replace_as_cmd);
19355 install_element(BGP_IPV6L_NODE,
19356 &no_neighbor_remove_private_as_replace_as_cmd);
19357 install_element(BGP_IPV6L_NODE,
19358 &neighbor_remove_private_as_all_replace_as_cmd);
19359 install_element(BGP_IPV6L_NODE,
19360 &no_neighbor_remove_private_as_all_replace_as_cmd);
19361 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19362 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19363 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19364 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19365 install_element(BGP_VPNV4_NODE,
19366 &neighbor_remove_private_as_replace_as_cmd);
19367 install_element(BGP_VPNV4_NODE,
19368 &no_neighbor_remove_private_as_replace_as_cmd);
19369 install_element(BGP_VPNV4_NODE,
19370 &neighbor_remove_private_as_all_replace_as_cmd);
19371 install_element(BGP_VPNV4_NODE,
19372 &no_neighbor_remove_private_as_all_replace_as_cmd);
19373 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19374 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19375 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19376 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19377 install_element(BGP_VPNV6_NODE,
19378 &neighbor_remove_private_as_replace_as_cmd);
19379 install_element(BGP_VPNV6_NODE,
19380 &no_neighbor_remove_private_as_replace_as_cmd);
19381 install_element(BGP_VPNV6_NODE,
19382 &neighbor_remove_private_as_all_replace_as_cmd);
19383 install_element(BGP_VPNV6_NODE,
19384 &no_neighbor_remove_private_as_all_replace_as_cmd);
19385
19386 /* "neighbor send-community" commands.*/
19387 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19388 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19389 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19390 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19391 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19392 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19393 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19394 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19395 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19396 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19397 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19398 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19399 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19400 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19401 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19402 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19403 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19404 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19405 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19406 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19407 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19408 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19409 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19410 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19411 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19412 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19413 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19414 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19415 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19416 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19417 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19418 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19419 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19420 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19421 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19422 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19423
19424 /* "neighbor route-reflector" commands.*/
19425 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19426 install_element(BGP_NODE,
19427 &no_neighbor_route_reflector_client_hidden_cmd);
19428 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19429 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19430 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19431 install_element(BGP_IPV4M_NODE,
19432 &no_neighbor_route_reflector_client_cmd);
19433 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19434 install_element(BGP_IPV4L_NODE,
19435 &no_neighbor_route_reflector_client_cmd);
19436 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19437 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19438 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19439 install_element(BGP_IPV6M_NODE,
19440 &no_neighbor_route_reflector_client_cmd);
19441 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19442 install_element(BGP_IPV6L_NODE,
19443 &no_neighbor_route_reflector_client_cmd);
19444 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19445 install_element(BGP_VPNV4_NODE,
19446 &no_neighbor_route_reflector_client_cmd);
19447 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19448 install_element(BGP_VPNV6_NODE,
19449 &no_neighbor_route_reflector_client_cmd);
19450 install_element(BGP_FLOWSPECV4_NODE,
19451 &neighbor_route_reflector_client_cmd);
19452 install_element(BGP_FLOWSPECV4_NODE,
19453 &no_neighbor_route_reflector_client_cmd);
19454 install_element(BGP_FLOWSPECV6_NODE,
19455 &neighbor_route_reflector_client_cmd);
19456 install_element(BGP_FLOWSPECV6_NODE,
19457 &no_neighbor_route_reflector_client_cmd);
19458 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19459 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19460
19461 /* "neighbor route-server" commands.*/
19462 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19463 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19464 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19465 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19466 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19467 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19468 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19469 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19470 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19471 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19472 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19473 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19474 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19475 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19476 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19477 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19478 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19479 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19480 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19481 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19482 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19483 install_element(BGP_FLOWSPECV4_NODE,
19484 &no_neighbor_route_server_client_cmd);
19485 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19486 install_element(BGP_FLOWSPECV6_NODE,
19487 &no_neighbor_route_server_client_cmd);
19488
19489 /* "neighbor disable-addpath-rx" commands. */
19490 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19491 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19492 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19493 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19494 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19495 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19496 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19497 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19498 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19499 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19500 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19501 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19502 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19503 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19504 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19505 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19506
19507 /* "neighbor addpath-tx-all-paths" commands.*/
19508 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19509 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19510 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19511 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19512 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19513 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19514 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19515 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19516 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19517 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19518 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19519 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19520 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19521 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19522 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19523 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19524 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19525 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19526
19527 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19528 install_element(BGP_NODE,
19529 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19530 install_element(BGP_NODE,
19531 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19532 install_element(BGP_IPV4_NODE,
19533 &neighbor_addpath_tx_bestpath_per_as_cmd);
19534 install_element(BGP_IPV4_NODE,
19535 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19536 install_element(BGP_IPV4M_NODE,
19537 &neighbor_addpath_tx_bestpath_per_as_cmd);
19538 install_element(BGP_IPV4M_NODE,
19539 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19540 install_element(BGP_IPV4L_NODE,
19541 &neighbor_addpath_tx_bestpath_per_as_cmd);
19542 install_element(BGP_IPV4L_NODE,
19543 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19544 install_element(BGP_IPV6_NODE,
19545 &neighbor_addpath_tx_bestpath_per_as_cmd);
19546 install_element(BGP_IPV6_NODE,
19547 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19548 install_element(BGP_IPV6M_NODE,
19549 &neighbor_addpath_tx_bestpath_per_as_cmd);
19550 install_element(BGP_IPV6M_NODE,
19551 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19552 install_element(BGP_IPV6L_NODE,
19553 &neighbor_addpath_tx_bestpath_per_as_cmd);
19554 install_element(BGP_IPV6L_NODE,
19555 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19556 install_element(BGP_VPNV4_NODE,
19557 &neighbor_addpath_tx_bestpath_per_as_cmd);
19558 install_element(BGP_VPNV4_NODE,
19559 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19560 install_element(BGP_VPNV6_NODE,
19561 &neighbor_addpath_tx_bestpath_per_as_cmd);
19562 install_element(BGP_VPNV6_NODE,
19563 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19564
19565 /* "neighbor sender-as-path-loop-detection" commands. */
19566 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19567 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19568
19569 /* "neighbor path-attribute discard" commands. */
19570 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19571 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
19572
19573 /* "neighbor passive" commands. */
19574 install_element(BGP_NODE, &neighbor_passive_cmd);
19575 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19576
19577
19578 /* "neighbor shutdown" commands. */
19579 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19580 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19581 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19582 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19583 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19584 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19585
19586 /* "neighbor capability extended-nexthop" commands.*/
19587 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19588 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19589
19590 /* "neighbor capability orf prefix-list" commands.*/
19591 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19592 install_element(BGP_NODE,
19593 &no_neighbor_capability_orf_prefix_hidden_cmd);
19594 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19595 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19596 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19597 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19598 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19599 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19600 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19601 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19602 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19603 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19604 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19605 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19606
19607 /* "neighbor capability dynamic" commands.*/
19608 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19609 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19610
19611 /* "neighbor dont-capability-negotiate" commands. */
19612 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19613 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19614
19615 /* "neighbor ebgp-multihop" commands. */
19616 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19617 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19618 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19619
19620 /* "neighbor disable-connected-check" commands. */
19621 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19622 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19623
19624 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19625 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19626 install_element(BGP_NODE,
19627 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19628
19629 /* "neighbor extended-optional-parameters" commands. */
19630 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19631 install_element(BGP_NODE,
19632 &no_neighbor_extended_optional_parameters_cmd);
19633
19634 /* "neighbor enforce-first-as" commands. */
19635 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19636 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19637
19638 /* "neighbor description" commands. */
19639 install_element(BGP_NODE, &neighbor_description_cmd);
19640 install_element(BGP_NODE, &no_neighbor_description_cmd);
19641 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19642
19643 /* "neighbor update-source" commands. "*/
19644 install_element(BGP_NODE, &neighbor_update_source_cmd);
19645 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19646
19647 /* "neighbor default-originate" commands. */
19648 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19649 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19650 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19651 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19652 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19653 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19654 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19655 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19656 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19657 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19658 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19659 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19660 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19661 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19662 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19663 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19664 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19665 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19666 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19667 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19668 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19669
19670 /* "neighbor port" commands. */
19671 install_element(BGP_NODE, &neighbor_port_cmd);
19672 install_element(BGP_NODE, &no_neighbor_port_cmd);
19673
19674 /* "neighbor weight" commands. */
19675 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19676 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19677
19678 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19679 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19680 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19681 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19682 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19683 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19684 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19685 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19686 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19687 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19688 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19689 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19690 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19691 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19692 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19693 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19694
19695 /* "neighbor override-capability" commands. */
19696 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19697 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19698
19699 /* "neighbor strict-capability-match" commands. */
19700 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19701 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19702
19703 /* "neighbor timers" commands. */
19704 install_element(BGP_NODE, &neighbor_timers_cmd);
19705 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19706
19707 /* "neighbor timers connect" commands. */
19708 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19709 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19710
19711 /* "neighbor timers delayopen" commands. */
19712 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19713 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19714
19715 /* "neighbor advertisement-interval" commands. */
19716 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19717 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19718
19719 /* "neighbor interface" commands. */
19720 install_element(BGP_NODE, &neighbor_interface_cmd);
19721 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19722
19723 /* "neighbor distribute" commands. */
19724 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19725 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19726 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19727 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19728 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19729 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19730 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19731 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19732 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19733 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19734 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19735 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19736 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19737 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19738 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19739 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19740 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19741 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19742
19743 /* "neighbor prefix-list" commands. */
19744 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19745 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19746 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19747 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19748 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19749 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19750 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19751 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19752 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19753 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19754 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19755 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19756 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19757 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19758 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19759 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19760 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19761 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19762 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19763 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19764 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19765 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19766
19767 /* "neighbor filter-list" commands. */
19768 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19769 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19770 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19771 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19772 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19773 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19774 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19775 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19776 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19777 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19778 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19779 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19780 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19781 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19782 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19783 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19784 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19785 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19786 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19787 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19788 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19789 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19790
19791 /* "neighbor route-map" commands. */
19792 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19793 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19794 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19795 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19796 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19797 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19798 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19799 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19800 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19801 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19802 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19803 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19804 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19805 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19806 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19807 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19808 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19809 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19810 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19811 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19812 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19813 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19814 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19815 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19816
19817 /* "neighbor unsuppress-map" commands. */
19818 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19819 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19820 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19821 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19822 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19823 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19824 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19825 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19826 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19827 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19828 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19829 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19830 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19831 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19832 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19833 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19834 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19835 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19836
19837 /* "neighbor advertise-map" commands. */
19838 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19839 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19840 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19841 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19842 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19843 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19844 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19845 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19846 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19847 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19848
19849 /* neighbor maximum-prefix-out commands. */
19850 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19851 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19852 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19853 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19854 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19855 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19856 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19857 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19858 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19859 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19860 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19861 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19862 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19863 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19864 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19865 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19866 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19867 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19868
19869 /* "neighbor maximum-prefix" commands. */
19870 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19871 install_element(BGP_NODE,
19872 &neighbor_maximum_prefix_threshold_hidden_cmd);
19873 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19874 install_element(BGP_NODE,
19875 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19876 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19877 install_element(BGP_NODE,
19878 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19879 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19880 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19881 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19882 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19883 install_element(BGP_IPV4_NODE,
19884 &neighbor_maximum_prefix_threshold_warning_cmd);
19885 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19886 install_element(BGP_IPV4_NODE,
19887 &neighbor_maximum_prefix_threshold_restart_cmd);
19888 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19889 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19890 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19891 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19892 install_element(BGP_IPV4M_NODE,
19893 &neighbor_maximum_prefix_threshold_warning_cmd);
19894 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19895 install_element(BGP_IPV4M_NODE,
19896 &neighbor_maximum_prefix_threshold_restart_cmd);
19897 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19898 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19899 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19900 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19901 install_element(BGP_IPV4L_NODE,
19902 &neighbor_maximum_prefix_threshold_warning_cmd);
19903 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19904 install_element(BGP_IPV4L_NODE,
19905 &neighbor_maximum_prefix_threshold_restart_cmd);
19906 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19907 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19908 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19909 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19910 install_element(BGP_IPV6_NODE,
19911 &neighbor_maximum_prefix_threshold_warning_cmd);
19912 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19913 install_element(BGP_IPV6_NODE,
19914 &neighbor_maximum_prefix_threshold_restart_cmd);
19915 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19916 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19917 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19918 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19919 install_element(BGP_IPV6M_NODE,
19920 &neighbor_maximum_prefix_threshold_warning_cmd);
19921 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19922 install_element(BGP_IPV6M_NODE,
19923 &neighbor_maximum_prefix_threshold_restart_cmd);
19924 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19925 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19926 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19927 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19928 install_element(BGP_IPV6L_NODE,
19929 &neighbor_maximum_prefix_threshold_warning_cmd);
19930 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19931 install_element(BGP_IPV6L_NODE,
19932 &neighbor_maximum_prefix_threshold_restart_cmd);
19933 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19934 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19935 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19936 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19937 install_element(BGP_VPNV4_NODE,
19938 &neighbor_maximum_prefix_threshold_warning_cmd);
19939 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19940 install_element(BGP_VPNV4_NODE,
19941 &neighbor_maximum_prefix_threshold_restart_cmd);
19942 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19943 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19944 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19945 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19946 install_element(BGP_VPNV6_NODE,
19947 &neighbor_maximum_prefix_threshold_warning_cmd);
19948 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19949 install_element(BGP_VPNV6_NODE,
19950 &neighbor_maximum_prefix_threshold_restart_cmd);
19951 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19952
19953 /* "neighbor allowas-in" */
19954 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19955 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19956 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19957 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19958 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19959 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19960 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19961 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19962 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19963 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19964 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19965 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19966 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19967 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19968 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19969 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19970 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19971 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19972 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19973 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19974
19975 /* neighbor accept-own */
19976 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19977 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19978
19979 /* "neighbor soo" */
19980 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19981 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19982 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19983 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19984 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19985 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19986 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19987 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19988 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19989 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19990 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19991 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19992 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19993 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19994 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19995 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19996 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19997 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19998
19999 /* address-family commands. */
20000 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20001 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
20002 #ifdef KEEP_OLD_VPN_COMMANDS
20003 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20004 install_element(BGP_NODE, &address_family_vpnv6_cmd);
20005 #endif /* KEEP_OLD_VPN_COMMANDS */
20006
20007 install_element(BGP_NODE, &address_family_evpn_cmd);
20008
20009 /* "exit-address-family" command. */
20010 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20011 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20012 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20013 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20014 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20015 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20016 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20017 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
20018 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20019 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
20020 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20021
20022 /* BGP retain all route-target */
20023 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20024 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20025
20026 /* "clear ip bgp commands" */
20027 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20028
20029 /* clear ip bgp prefix */
20030 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20031 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20032 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20033
20034 /* "show [ip] bgp summary" commands. */
20035 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20036 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20037 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20038 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20039 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20040 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20041 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20042
20043 /* "show [ip] bgp neighbors" commands. */
20044 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20045
20046 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20047
20048 /* "show [ip] bgp peer-group" commands. */
20049 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20050
20051 /* "show [ip] bgp paths" commands. */
20052 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20053
20054 /* "show [ip] bgp community" commands. */
20055 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20056
20057 /* "show ip bgp large-community" commands. */
20058 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20059 /* "show [ip] bgp attribute-info" commands. */
20060 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20061 /* "show [ip] bgp route-leak" command */
20062 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20063
20064 /* "redistribute" commands. */
20065 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20066 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20067 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20068 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20069 install_element(BGP_NODE,
20070 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20071 install_element(BGP_NODE,
20072 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20073 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20074 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20075 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20076 install_element(BGP_NODE,
20077 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20078 install_element(BGP_NODE,
20079 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20080 install_element(BGP_NODE,
20081 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20082 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20083 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20084 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20085 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20086 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20087 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20088 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20089 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20090 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20091 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20092 install_element(BGP_IPV4_NODE,
20093 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20094 install_element(BGP_IPV4_NODE,
20095 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20096 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20097 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20098 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20099 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20100 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20101 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20102
20103 /* import|export vpn [route-map RMAP_NAME] */
20104 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20105 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20106
20107 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20108 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20109
20110 /* ttl_security commands */
20111 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20112 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20113
20114 /* "bgp tcp-keepalive" commands */
20115 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20116 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20117
20118 /* "show [ip] bgp memory" commands. */
20119 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20120
20121 /* "show bgp martian next-hop" */
20122 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20123
20124 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20125
20126 /* "show [ip] bgp views" commands. */
20127 install_element(VIEW_NODE, &show_bgp_views_cmd);
20128
20129 /* "show [ip] bgp vrfs" commands. */
20130 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20131
20132 /* Community-list. */
20133 community_list_vty();
20134
20135 community_alias_vty();
20136
20137 /* vpn-policy commands */
20138 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20139 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20140 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20141 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20142 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20143 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20144 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20145 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20146 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20147 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20148 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20149 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20150
20151 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20152 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20153
20154 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20155 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20156 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20157 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20158 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20159 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20160 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20161 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20162 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20163 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20164
20165 /* tcp-mss command */
20166 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20167 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20168
20169 /* srv6 commands */
20170 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20171 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20172 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20173 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20174 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20175 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20176 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20177 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20178 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20179
20180 bgp_vty_if_init();
20181 }
20182
20183 #include "memory.h"
20184 #include "bgp_regex.h"
20185 #include "bgp_clist.h"
20186 #include "bgp_ecommunity.h"
20187
20188 /* VTY functions. */
20189
20190 /* Direction value to string conversion. */
20191 static const char *community_direct_str(int direct)
20192 {
20193 switch (direct) {
20194 case COMMUNITY_DENY:
20195 return "deny";
20196 case COMMUNITY_PERMIT:
20197 return "permit";
20198 default:
20199 return "unknown";
20200 }
20201 }
20202
20203 /* Display error string. */
20204 static void community_list_perror(struct vty *vty, int ret)
20205 {
20206 switch (ret) {
20207 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20208 vty_out(vty, "%% Can't find community-list\n");
20209 break;
20210 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20211 vty_out(vty, "%% Malformed community-list value\n");
20212 break;
20213 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20214 vty_out(vty,
20215 "%% Community name conflict, previously defined as standard community\n");
20216 break;
20217 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20218 vty_out(vty,
20219 "%% Community name conflict, previously defined as expanded community\n");
20220 break;
20221 }
20222 }
20223
20224 /* "community-list" keyword help string. */
20225 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20226
20227 /*community-list standard */
20228 DEFUN (community_list_standard,
20229 bgp_community_list_standard_cmd,
20230 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20231 BGP_STR
20232 COMMUNITY_LIST_STR
20233 "Community list number (standard)\n"
20234 "Add an standard community-list entry\n"
20235 "Community list name\n"
20236 "Sequence number of an entry\n"
20237 "Sequence number\n"
20238 "Specify community to reject\n"
20239 "Specify community to accept\n"
20240 COMMUNITY_VAL_STR)
20241 {
20242 char *cl_name_or_number = NULL;
20243 char *seq = NULL;
20244 int direct = 0;
20245 int style = COMMUNITY_LIST_STANDARD;
20246 int idx = 0;
20247
20248 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20249 seq = argv[idx]->arg;
20250
20251 idx = 0;
20252 argv_find(argv, argc, "(1-99)", &idx);
20253 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20254 cl_name_or_number = argv[idx]->arg;
20255 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20256 : COMMUNITY_DENY;
20257 argv_find(argv, argc, "AA:NN", &idx);
20258 char *str = argv_concat(argv, argc, idx);
20259
20260 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20261 direct, style);
20262
20263 XFREE(MTYPE_TMP, str);
20264
20265 if (ret < 0) {
20266 /* Display error string. */
20267 community_list_perror(vty, ret);
20268 return CMD_WARNING_CONFIG_FAILED;
20269 }
20270
20271 return CMD_SUCCESS;
20272 }
20273
20274 DEFUN (no_community_list_standard_all,
20275 no_bgp_community_list_standard_all_cmd,
20276 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20277 NO_STR
20278 BGP_STR
20279 COMMUNITY_LIST_STR
20280 "Community list number (standard)\n"
20281 "Add an standard community-list entry\n"
20282 "Community list name\n"
20283 "Sequence number of an entry\n"
20284 "Sequence number\n"
20285 "Specify community to reject\n"
20286 "Specify community to accept\n"
20287 COMMUNITY_VAL_STR)
20288 {
20289 char *cl_name_or_number = NULL;
20290 char *str = NULL;
20291 int direct = 0;
20292 int style = COMMUNITY_LIST_STANDARD;
20293 char *seq = NULL;
20294 int idx = 0;
20295
20296 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20297 seq = argv[idx]->arg;
20298
20299 idx = 0;
20300 argv_find(argv, argc, "permit", &idx);
20301 argv_find(argv, argc, "deny", &idx);
20302
20303 if (idx) {
20304 direct = argv_find(argv, argc, "permit", &idx)
20305 ? COMMUNITY_PERMIT
20306 : COMMUNITY_DENY;
20307
20308 idx = 0;
20309 argv_find(argv, argc, "AA:NN", &idx);
20310 str = argv_concat(argv, argc, idx);
20311 }
20312
20313 idx = 0;
20314 argv_find(argv, argc, "(1-99)", &idx);
20315 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20316 cl_name_or_number = argv[idx]->arg;
20317
20318 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20319 direct, style);
20320
20321 XFREE(MTYPE_TMP, str);
20322
20323 if (ret < 0) {
20324 community_list_perror(vty, ret);
20325 return CMD_WARNING_CONFIG_FAILED;
20326 }
20327
20328 return CMD_SUCCESS;
20329 }
20330
20331 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20332 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20333 NO_STR BGP_STR COMMUNITY_LIST_STR
20334 "Community list number (standard)\n"
20335 "Add an standard community-list entry\n"
20336 "Community list name\n")
20337
20338 /*community-list expanded */
20339 DEFUN (community_list_expanded_all,
20340 bgp_community_list_expanded_all_cmd,
20341 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20342 BGP_STR
20343 COMMUNITY_LIST_STR
20344 "Community list number (expanded)\n"
20345 "Add an expanded community-list entry\n"
20346 "Community list name\n"
20347 "Sequence number of an entry\n"
20348 "Sequence number\n"
20349 "Specify community to reject\n"
20350 "Specify community to accept\n"
20351 COMMUNITY_VAL_STR)
20352 {
20353 char *cl_name_or_number = NULL;
20354 char *seq = NULL;
20355 int direct = 0;
20356 int style = COMMUNITY_LIST_EXPANDED;
20357 int idx = 0;
20358
20359 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20360 seq = argv[idx]->arg;
20361
20362 idx = 0;
20363
20364 argv_find(argv, argc, "(100-500)", &idx);
20365 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20366 cl_name_or_number = argv[idx]->arg;
20367 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20368 : COMMUNITY_DENY;
20369 argv_find(argv, argc, "AA:NN", &idx);
20370 char *str = argv_concat(argv, argc, idx);
20371
20372 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20373 direct, style);
20374
20375 XFREE(MTYPE_TMP, str);
20376
20377 if (ret < 0) {
20378 /* Display error string. */
20379 community_list_perror(vty, ret);
20380 return CMD_WARNING_CONFIG_FAILED;
20381 }
20382
20383 return CMD_SUCCESS;
20384 }
20385
20386 DEFUN (no_community_list_expanded_all,
20387 no_bgp_community_list_expanded_all_cmd,
20388 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20389 NO_STR
20390 BGP_STR
20391 COMMUNITY_LIST_STR
20392 "Community list number (expanded)\n"
20393 "Add an expanded community-list entry\n"
20394 "Community list name\n"
20395 "Sequence number of an entry\n"
20396 "Sequence number\n"
20397 "Specify community to reject\n"
20398 "Specify community to accept\n"
20399 COMMUNITY_VAL_STR)
20400 {
20401 char *cl_name_or_number = NULL;
20402 char *seq = NULL;
20403 char *str = NULL;
20404 int direct = 0;
20405 int style = COMMUNITY_LIST_EXPANDED;
20406 int idx = 0;
20407
20408 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20409 seq = argv[idx]->arg;
20410
20411 idx = 0;
20412 argv_find(argv, argc, "permit", &idx);
20413 argv_find(argv, argc, "deny", &idx);
20414
20415 if (idx) {
20416 direct = argv_find(argv, argc, "permit", &idx)
20417 ? COMMUNITY_PERMIT
20418 : COMMUNITY_DENY;
20419
20420 idx = 0;
20421 argv_find(argv, argc, "AA:NN", &idx);
20422 str = argv_concat(argv, argc, idx);
20423 }
20424
20425 idx = 0;
20426 argv_find(argv, argc, "(100-500)", &idx);
20427 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20428 cl_name_or_number = argv[idx]->arg;
20429
20430 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20431 direct, style);
20432
20433 XFREE(MTYPE_TMP, str);
20434
20435 if (ret < 0) {
20436 community_list_perror(vty, ret);
20437 return CMD_WARNING_CONFIG_FAILED;
20438 }
20439
20440 return CMD_SUCCESS;
20441 }
20442
20443 ALIAS(no_community_list_expanded_all,
20444 no_bgp_community_list_expanded_all_list_cmd,
20445 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20446 NO_STR BGP_STR COMMUNITY_LIST_STR
20447 "Community list number (expanded)\n"
20448 "Add an expanded community-list entry\n"
20449 "Community list name\n")
20450
20451 /* Return configuration string of community-list entry. */
20452 static const char *community_list_config_str(struct community_entry *entry)
20453 {
20454 const char *str;
20455
20456 if (entry->any)
20457 str = "";
20458 else {
20459 if (entry->style == COMMUNITY_LIST_STANDARD)
20460 str = community_str(entry->u.com, false, false);
20461 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20462 str = lcommunity_str(entry->u.lcom, false, false);
20463 else
20464 str = entry->config;
20465 }
20466 return str;
20467 }
20468
20469 static void community_list_show(struct vty *vty, struct community_list *list)
20470 {
20471 struct community_entry *entry;
20472
20473 for (entry = list->head; entry; entry = entry->next) {
20474 if (entry == list->head) {
20475 if (all_digit(list->name))
20476 vty_out(vty, "Community %s list %s\n",
20477 entry->style == COMMUNITY_LIST_STANDARD
20478 ? "standard"
20479 : "(expanded) access",
20480 list->name);
20481 else
20482 vty_out(vty, "Named Community %s list %s\n",
20483 entry->style == COMMUNITY_LIST_STANDARD
20484 ? "standard"
20485 : "expanded",
20486 list->name);
20487 }
20488 if (entry->any)
20489 vty_out(vty, " %s\n",
20490 community_direct_str(entry->direct));
20491 else
20492 vty_out(vty, " %s %s\n",
20493 community_direct_str(entry->direct),
20494 community_list_config_str(entry));
20495 }
20496 }
20497
20498 DEFUN (show_community_list,
20499 show_bgp_community_list_cmd,
20500 "show bgp community-list",
20501 SHOW_STR
20502 BGP_STR
20503 "List community-list\n")
20504 {
20505 struct community_list *list;
20506 struct community_list_master *cm;
20507
20508 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20509 if (!cm)
20510 return CMD_SUCCESS;
20511
20512 for (list = cm->num.head; list; list = list->next)
20513 community_list_show(vty, list);
20514
20515 for (list = cm->str.head; list; list = list->next)
20516 community_list_show(vty, list);
20517
20518 return CMD_SUCCESS;
20519 }
20520
20521 DEFUN (show_community_list_arg,
20522 show_bgp_community_list_arg_cmd,
20523 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20524 SHOW_STR
20525 BGP_STR
20526 "List community-list\n"
20527 "Community-list number\n"
20528 "Community-list name\n"
20529 "Detailed information on community-list\n")
20530 {
20531 int idx_comm_list = 3;
20532 struct community_list *list;
20533
20534 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20535 COMMUNITY_LIST_MASTER);
20536 if (!list) {
20537 vty_out(vty, "%% Can't find community-list\n");
20538 return CMD_WARNING;
20539 }
20540
20541 community_list_show(vty, list);
20542
20543 return CMD_SUCCESS;
20544 }
20545
20546 /*
20547 * Large Community code.
20548 */
20549 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20550 struct cmd_token **argv, int style,
20551 int reject_all_digit_name)
20552 {
20553 int ret;
20554 int direct;
20555 char *str;
20556 int idx = 0;
20557 char *cl_name;
20558 char *seq = NULL;
20559
20560 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20561 seq = argv[idx]->arg;
20562
20563 idx = 0;
20564 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20565 : COMMUNITY_DENY;
20566
20567 /* All digit name check. */
20568 idx = 0;
20569 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20570 argv_find(argv, argc, "(1-99)", &idx);
20571 argv_find(argv, argc, "(100-500)", &idx);
20572 cl_name = argv[idx]->arg;
20573 if (reject_all_digit_name && all_digit(cl_name)) {
20574 vty_out(vty, "%% Community name cannot have all digits\n");
20575 return CMD_WARNING_CONFIG_FAILED;
20576 }
20577
20578 idx = 0;
20579 argv_find(argv, argc, "AA:BB:CC", &idx);
20580 argv_find(argv, argc, "LINE", &idx);
20581 /* Concat community string argument. */
20582 if (idx)
20583 str = argv_concat(argv, argc, idx);
20584 else
20585 str = NULL;
20586
20587 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20588
20589 /* Free temporary community list string allocated by
20590 argv_concat(). */
20591 XFREE(MTYPE_TMP, str);
20592
20593 if (ret < 0) {
20594 community_list_perror(vty, ret);
20595 return CMD_WARNING_CONFIG_FAILED;
20596 }
20597 return CMD_SUCCESS;
20598 }
20599
20600 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20601 struct cmd_token **argv, int style)
20602 {
20603 int ret;
20604 int direct = 0;
20605 char *str = NULL;
20606 int idx = 0;
20607 char *seq = NULL;
20608
20609 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20610 seq = argv[idx]->arg;
20611
20612 idx = 0;
20613 argv_find(argv, argc, "permit", &idx);
20614 argv_find(argv, argc, "deny", &idx);
20615
20616 if (idx) {
20617 /* Check the list direct. */
20618 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20619 direct = COMMUNITY_PERMIT;
20620 else
20621 direct = COMMUNITY_DENY;
20622
20623 idx = 0;
20624 argv_find(argv, argc, "LINE", &idx);
20625 argv_find(argv, argc, "AA:AA:NN", &idx);
20626 /* Concat community string argument. */
20627 str = argv_concat(argv, argc, idx);
20628 }
20629
20630 idx = 0;
20631 argv_find(argv, argc, "(1-99)", &idx);
20632 argv_find(argv, argc, "(100-500)", &idx);
20633 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20634
20635 /* Unset community list. */
20636 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20637 style);
20638
20639 /* Free temporary community list string allocated by
20640 argv_concat(). */
20641 XFREE(MTYPE_TMP, str);
20642
20643 if (ret < 0) {
20644 community_list_perror(vty, ret);
20645 return CMD_WARNING_CONFIG_FAILED;
20646 }
20647
20648 return CMD_SUCCESS;
20649 }
20650
20651 /* "large-community-list" keyword help string. */
20652 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20653 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20654
20655 DEFUN (lcommunity_list_standard,
20656 bgp_lcommunity_list_standard_cmd,
20657 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20658 BGP_STR
20659 LCOMMUNITY_LIST_STR
20660 "Large Community list number (standard)\n"
20661 "Sequence number of an entry\n"
20662 "Sequence number\n"
20663 "Specify large community to reject\n"
20664 "Specify large community to accept\n"
20665 LCOMMUNITY_VAL_STR)
20666 {
20667 return lcommunity_list_set_vty(vty, argc, argv,
20668 LARGE_COMMUNITY_LIST_STANDARD, 0);
20669 }
20670
20671 DEFUN (lcommunity_list_expanded,
20672 bgp_lcommunity_list_expanded_cmd,
20673 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20674 BGP_STR
20675 LCOMMUNITY_LIST_STR
20676 "Large Community list number (expanded)\n"
20677 "Sequence number of an entry\n"
20678 "Sequence number\n"
20679 "Specify large community to reject\n"
20680 "Specify large community to accept\n"
20681 "An ordered list as a regular-expression\n")
20682 {
20683 return lcommunity_list_set_vty(vty, argc, argv,
20684 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20685 }
20686
20687 DEFUN (lcommunity_list_name_standard,
20688 bgp_lcommunity_list_name_standard_cmd,
20689 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20690 BGP_STR
20691 LCOMMUNITY_LIST_STR
20692 "Specify standard large-community-list\n"
20693 "Large Community list name\n"
20694 "Sequence number of an entry\n"
20695 "Sequence number\n"
20696 "Specify large community to reject\n"
20697 "Specify large community to accept\n"
20698 LCOMMUNITY_VAL_STR)
20699 {
20700 return lcommunity_list_set_vty(vty, argc, argv,
20701 LARGE_COMMUNITY_LIST_STANDARD, 1);
20702 }
20703
20704 DEFUN (lcommunity_list_name_expanded,
20705 bgp_lcommunity_list_name_expanded_cmd,
20706 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20707 BGP_STR
20708 LCOMMUNITY_LIST_STR
20709 "Specify expanded large-community-list\n"
20710 "Large Community list name\n"
20711 "Sequence number of an entry\n"
20712 "Sequence number\n"
20713 "Specify large community to reject\n"
20714 "Specify large community to accept\n"
20715 "An ordered list as a regular-expression\n")
20716 {
20717 return lcommunity_list_set_vty(vty, argc, argv,
20718 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20719 }
20720
20721 DEFUN (no_lcommunity_list_all,
20722 no_bgp_lcommunity_list_all_cmd,
20723 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20724 NO_STR
20725 BGP_STR
20726 LCOMMUNITY_LIST_STR
20727 "Large Community list number (standard)\n"
20728 "Large Community list number (expanded)\n"
20729 "Large Community list name\n")
20730 {
20731 return lcommunity_list_unset_vty(vty, argc, argv,
20732 LARGE_COMMUNITY_LIST_STANDARD);
20733 }
20734
20735 DEFUN (no_lcommunity_list_name_standard_all,
20736 no_bgp_lcommunity_list_name_standard_all_cmd,
20737 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20738 NO_STR
20739 BGP_STR
20740 LCOMMUNITY_LIST_STR
20741 "Specify standard large-community-list\n"
20742 "Large Community list name\n")
20743 {
20744 return lcommunity_list_unset_vty(vty, argc, argv,
20745 LARGE_COMMUNITY_LIST_STANDARD);
20746 }
20747
20748 DEFUN (no_lcommunity_list_name_expanded_all,
20749 no_bgp_lcommunity_list_name_expanded_all_cmd,
20750 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20751 NO_STR
20752 BGP_STR
20753 LCOMMUNITY_LIST_STR
20754 "Specify expanded large-community-list\n"
20755 "Large Community list name\n")
20756 {
20757 return lcommunity_list_unset_vty(vty, argc, argv,
20758 LARGE_COMMUNITY_LIST_EXPANDED);
20759 }
20760
20761 DEFUN (no_lcommunity_list_standard,
20762 no_bgp_lcommunity_list_standard_cmd,
20763 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20764 NO_STR
20765 BGP_STR
20766 LCOMMUNITY_LIST_STR
20767 "Large Community list number (standard)\n"
20768 "Sequence number of an entry\n"
20769 "Sequence number\n"
20770 "Specify large community to reject\n"
20771 "Specify large community to accept\n"
20772 LCOMMUNITY_VAL_STR)
20773 {
20774 return lcommunity_list_unset_vty(vty, argc, argv,
20775 LARGE_COMMUNITY_LIST_STANDARD);
20776 }
20777
20778 DEFUN (no_lcommunity_list_expanded,
20779 no_bgp_lcommunity_list_expanded_cmd,
20780 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20781 NO_STR
20782 BGP_STR
20783 LCOMMUNITY_LIST_STR
20784 "Large Community list number (expanded)\n"
20785 "Sequence number of an entry\n"
20786 "Sequence number\n"
20787 "Specify large community to reject\n"
20788 "Specify large community to accept\n"
20789 "An ordered list as a regular-expression\n")
20790 {
20791 return lcommunity_list_unset_vty(vty, argc, argv,
20792 LARGE_COMMUNITY_LIST_EXPANDED);
20793 }
20794
20795 DEFUN (no_lcommunity_list_name_standard,
20796 no_bgp_lcommunity_list_name_standard_cmd,
20797 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20798 NO_STR
20799 BGP_STR
20800 LCOMMUNITY_LIST_STR
20801 "Specify standard large-community-list\n"
20802 "Large Community list name\n"
20803 "Sequence number of an entry\n"
20804 "Sequence number\n"
20805 "Specify large community to reject\n"
20806 "Specify large community to accept\n"
20807 LCOMMUNITY_VAL_STR)
20808 {
20809 return lcommunity_list_unset_vty(vty, argc, argv,
20810 LARGE_COMMUNITY_LIST_STANDARD);
20811 }
20812
20813 DEFUN (no_lcommunity_list_name_expanded,
20814 no_bgp_lcommunity_list_name_expanded_cmd,
20815 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20816 NO_STR
20817 BGP_STR
20818 LCOMMUNITY_LIST_STR
20819 "Specify expanded large-community-list\n"
20820 "Large community list name\n"
20821 "Sequence number of an entry\n"
20822 "Sequence number\n"
20823 "Specify large community to reject\n"
20824 "Specify large community to accept\n"
20825 "An ordered list as a regular-expression\n")
20826 {
20827 return lcommunity_list_unset_vty(vty, argc, argv,
20828 LARGE_COMMUNITY_LIST_EXPANDED);
20829 }
20830
20831 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20832 {
20833 struct community_entry *entry;
20834
20835 for (entry = list->head; entry; entry = entry->next) {
20836 if (entry == list->head) {
20837 if (all_digit(list->name))
20838 vty_out(vty, "Large community %s list %s\n",
20839 entry->style ==
20840 LARGE_COMMUNITY_LIST_STANDARD
20841 ? "standard"
20842 : "(expanded) access",
20843 list->name);
20844 else
20845 vty_out(vty,
20846 "Named large community %s list %s\n",
20847 entry->style ==
20848 LARGE_COMMUNITY_LIST_STANDARD
20849 ? "standard"
20850 : "expanded",
20851 list->name);
20852 }
20853 if (entry->any)
20854 vty_out(vty, " %s\n",
20855 community_direct_str(entry->direct));
20856 else
20857 vty_out(vty, " %s %s\n",
20858 community_direct_str(entry->direct),
20859 community_list_config_str(entry));
20860 }
20861 }
20862
20863 DEFUN (show_lcommunity_list,
20864 show_bgp_lcommunity_list_cmd,
20865 "show bgp large-community-list",
20866 SHOW_STR
20867 BGP_STR
20868 "List large-community list\n")
20869 {
20870 struct community_list *list;
20871 struct community_list_master *cm;
20872
20873 cm = community_list_master_lookup(bgp_clist,
20874 LARGE_COMMUNITY_LIST_MASTER);
20875 if (!cm)
20876 return CMD_SUCCESS;
20877
20878 for (list = cm->num.head; list; list = list->next)
20879 lcommunity_list_show(vty, list);
20880
20881 for (list = cm->str.head; list; list = list->next)
20882 lcommunity_list_show(vty, list);
20883
20884 return CMD_SUCCESS;
20885 }
20886
20887 DEFUN (show_lcommunity_list_arg,
20888 show_bgp_lcommunity_list_arg_cmd,
20889 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20890 SHOW_STR
20891 BGP_STR
20892 "List large-community list\n"
20893 "Large-community-list number\n"
20894 "Large-community-list name\n"
20895 "Detailed information on large-community-list\n")
20896 {
20897 struct community_list *list;
20898
20899 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20900 LARGE_COMMUNITY_LIST_MASTER);
20901 if (!list) {
20902 vty_out(vty, "%% Can't find large-community-list\n");
20903 return CMD_WARNING;
20904 }
20905
20906 lcommunity_list_show(vty, list);
20907
20908 return CMD_SUCCESS;
20909 }
20910
20911 /* "extcommunity-list" keyword help string. */
20912 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20913 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20914
20915 DEFUN (extcommunity_list_standard,
20916 bgp_extcommunity_list_standard_cmd,
20917 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20918 BGP_STR
20919 EXTCOMMUNITY_LIST_STR
20920 "Extended Community list number (standard)\n"
20921 "Specify standard extcommunity-list\n"
20922 "Community list name\n"
20923 "Sequence number of an entry\n"
20924 "Sequence number\n"
20925 "Specify community to reject\n"
20926 "Specify community to accept\n"
20927 EXTCOMMUNITY_VAL_STR)
20928 {
20929 int style = EXTCOMMUNITY_LIST_STANDARD;
20930 int direct = 0;
20931 char *cl_number_or_name = NULL;
20932 char *seq = NULL;
20933
20934 int idx = 0;
20935
20936 argv_find(argv, argc, "(1-99)", &idx);
20937 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20938 cl_number_or_name = argv[idx]->arg;
20939
20940 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20941 seq = argv[idx]->arg;
20942
20943 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20944 : COMMUNITY_DENY;
20945 argv_find(argv, argc, "AA:NN", &idx);
20946 char *str = argv_concat(argv, argc, idx);
20947
20948 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20949 direct, style);
20950
20951 XFREE(MTYPE_TMP, str);
20952
20953 if (ret < 0) {
20954 community_list_perror(vty, ret);
20955 return CMD_WARNING_CONFIG_FAILED;
20956 }
20957
20958 return CMD_SUCCESS;
20959 }
20960
20961 DEFUN (extcommunity_list_name_expanded,
20962 bgp_extcommunity_list_name_expanded_cmd,
20963 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20964 BGP_STR
20965 EXTCOMMUNITY_LIST_STR
20966 "Extended Community list number (expanded)\n"
20967 "Specify expanded extcommunity-list\n"
20968 "Extended Community list name\n"
20969 "Sequence number of an entry\n"
20970 "Sequence number\n"
20971 "Specify community to reject\n"
20972 "Specify community to accept\n"
20973 "An ordered list as a regular-expression\n")
20974 {
20975 int style = EXTCOMMUNITY_LIST_EXPANDED;
20976 int direct = 0;
20977 char *cl_number_or_name = NULL;
20978 char *seq = NULL;
20979 int idx = 0;
20980
20981 argv_find(argv, argc, "(100-500)", &idx);
20982 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20983 cl_number_or_name = argv[idx]->arg;
20984
20985 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20986 seq = argv[idx]->arg;
20987
20988 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20989 : COMMUNITY_DENY;
20990 argv_find(argv, argc, "LINE", &idx);
20991 char *str = argv_concat(argv, argc, idx);
20992
20993 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20994 direct, style);
20995
20996 XFREE(MTYPE_TMP, str);
20997
20998 if (ret < 0) {
20999 community_list_perror(vty, ret);
21000 return CMD_WARNING_CONFIG_FAILED;
21001 }
21002
21003 return CMD_SUCCESS;
21004 }
21005
21006 DEFUN (no_extcommunity_list_standard_all,
21007 no_bgp_extcommunity_list_standard_all_cmd,
21008 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21009 NO_STR
21010 BGP_STR
21011 EXTCOMMUNITY_LIST_STR
21012 "Extended Community list number (standard)\n"
21013 "Specify standard extcommunity-list\n"
21014 "Community list name\n"
21015 "Sequence number of an entry\n"
21016 "Sequence number\n"
21017 "Specify community to reject\n"
21018 "Specify community to accept\n"
21019 EXTCOMMUNITY_VAL_STR)
21020 {
21021 int style = EXTCOMMUNITY_LIST_STANDARD;
21022 int direct = 0;
21023 char *cl_number_or_name = NULL;
21024 char *str = NULL;
21025 char *seq = NULL;
21026 int idx = 0;
21027
21028 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21029 seq = argv[idx]->arg;
21030
21031 idx = 0;
21032 argv_find(argv, argc, "permit", &idx);
21033 argv_find(argv, argc, "deny", &idx);
21034 if (idx) {
21035 direct = argv_find(argv, argc, "permit", &idx)
21036 ? COMMUNITY_PERMIT
21037 : COMMUNITY_DENY;
21038
21039 idx = 0;
21040 argv_find(argv, argc, "AA:NN", &idx);
21041 str = argv_concat(argv, argc, idx);
21042 }
21043
21044 idx = 0;
21045 argv_find(argv, argc, "(1-99)", &idx);
21046 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21047 cl_number_or_name = argv[idx]->arg;
21048
21049 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21050 seq, direct, style);
21051
21052 XFREE(MTYPE_TMP, str);
21053
21054 if (ret < 0) {
21055 community_list_perror(vty, ret);
21056 return CMD_WARNING_CONFIG_FAILED;
21057 }
21058
21059 return CMD_SUCCESS;
21060 }
21061
21062 ALIAS(no_extcommunity_list_standard_all,
21063 no_bgp_extcommunity_list_standard_all_list_cmd,
21064 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21065 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21066 "Extended Community list number (standard)\n"
21067 "Specify standard extcommunity-list\n"
21068 "Community list name\n")
21069
21070 DEFUN (no_extcommunity_list_expanded_all,
21071 no_bgp_extcommunity_list_expanded_all_cmd,
21072 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21073 NO_STR
21074 BGP_STR
21075 EXTCOMMUNITY_LIST_STR
21076 "Extended Community list number (expanded)\n"
21077 "Specify expanded extcommunity-list\n"
21078 "Extended Community list name\n"
21079 "Sequence number of an entry\n"
21080 "Sequence number\n"
21081 "Specify community to reject\n"
21082 "Specify community to accept\n"
21083 "An ordered list as a regular-expression\n")
21084 {
21085 int style = EXTCOMMUNITY_LIST_EXPANDED;
21086 int direct = 0;
21087 char *cl_number_or_name = NULL;
21088 char *str = NULL;
21089 char *seq = NULL;
21090 int idx = 0;
21091
21092 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21093 seq = argv[idx]->arg;
21094
21095 idx = 0;
21096 argv_find(argv, argc, "permit", &idx);
21097 argv_find(argv, argc, "deny", &idx);
21098
21099 if (idx) {
21100 direct = argv_find(argv, argc, "permit", &idx)
21101 ? COMMUNITY_PERMIT
21102 : COMMUNITY_DENY;
21103
21104 idx = 0;
21105 argv_find(argv, argc, "LINE", &idx);
21106 str = argv_concat(argv, argc, idx);
21107 }
21108
21109 idx = 0;
21110 argv_find(argv, argc, "(100-500)", &idx);
21111 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21112 cl_number_or_name = argv[idx]->arg;
21113
21114 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21115 seq, direct, style);
21116
21117 XFREE(MTYPE_TMP, str);
21118
21119 if (ret < 0) {
21120 community_list_perror(vty, ret);
21121 return CMD_WARNING_CONFIG_FAILED;
21122 }
21123
21124 return CMD_SUCCESS;
21125 }
21126
21127 ALIAS(no_extcommunity_list_expanded_all,
21128 no_bgp_extcommunity_list_expanded_all_list_cmd,
21129 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21130 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21131 "Extended Community list number (expanded)\n"
21132 "Specify expanded extcommunity-list\n"
21133 "Extended Community list name\n")
21134
21135 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21136 {
21137 struct community_entry *entry;
21138
21139 for (entry = list->head; entry; entry = entry->next) {
21140 if (entry == list->head) {
21141 if (all_digit(list->name))
21142 vty_out(vty, "Extended community %s list %s\n",
21143 entry->style == EXTCOMMUNITY_LIST_STANDARD
21144 ? "standard"
21145 : "(expanded) access",
21146 list->name);
21147 else
21148 vty_out(vty,
21149 "Named extended community %s list %s\n",
21150 entry->style == EXTCOMMUNITY_LIST_STANDARD
21151 ? "standard"
21152 : "expanded",
21153 list->name);
21154 }
21155 if (entry->any)
21156 vty_out(vty, " %s\n",
21157 community_direct_str(entry->direct));
21158 else
21159 vty_out(vty, " %s %s\n",
21160 community_direct_str(entry->direct),
21161 community_list_config_str(entry));
21162 }
21163 }
21164
21165 DEFUN (show_extcommunity_list,
21166 show_bgp_extcommunity_list_cmd,
21167 "show bgp extcommunity-list",
21168 SHOW_STR
21169 BGP_STR
21170 "List extended-community list\n")
21171 {
21172 struct community_list *list;
21173 struct community_list_master *cm;
21174
21175 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21176 if (!cm)
21177 return CMD_SUCCESS;
21178
21179 for (list = cm->num.head; list; list = list->next)
21180 extcommunity_list_show(vty, list);
21181
21182 for (list = cm->str.head; list; list = list->next)
21183 extcommunity_list_show(vty, list);
21184
21185 return CMD_SUCCESS;
21186 }
21187
21188 DEFUN (show_extcommunity_list_arg,
21189 show_bgp_extcommunity_list_arg_cmd,
21190 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21191 SHOW_STR
21192 BGP_STR
21193 "List extended-community list\n"
21194 "Extcommunity-list number\n"
21195 "Extcommunity-list name\n"
21196 "Detailed information on extcommunity-list\n")
21197 {
21198 int idx_comm_list = 3;
21199 struct community_list *list;
21200
21201 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21202 EXTCOMMUNITY_LIST_MASTER);
21203 if (!list) {
21204 vty_out(vty, "%% Can't find extcommunity-list\n");
21205 return CMD_WARNING;
21206 }
21207
21208 extcommunity_list_show(vty, list);
21209
21210 return CMD_SUCCESS;
21211 }
21212
21213 /* Display community-list and extcommunity-list configuration. */
21214 static int community_list_config_write(struct vty *vty)
21215 {
21216 struct community_list *list;
21217 struct community_entry *entry;
21218 struct community_list_master *cm;
21219 int write = 0;
21220
21221 /* Community-list. */
21222 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21223
21224 for (list = cm->num.head; list; list = list->next)
21225 for (entry = list->head; entry; entry = entry->next) {
21226 vty_out(vty,
21227 "bgp community-list %s seq %" PRId64 " %s %s\n",
21228 list->name, entry->seq,
21229 community_direct_str(entry->direct),
21230 community_list_config_str(entry));
21231 write++;
21232 }
21233 for (list = cm->str.head; list; list = list->next)
21234 for (entry = list->head; entry; entry = entry->next) {
21235 vty_out(vty,
21236 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21237 entry->style == COMMUNITY_LIST_STANDARD
21238 ? "standard"
21239 : "expanded",
21240 list->name, entry->seq,
21241 community_direct_str(entry->direct),
21242 community_list_config_str(entry));
21243 write++;
21244 }
21245
21246 /* Extcommunity-list. */
21247 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21248
21249 for (list = cm->num.head; list; list = list->next)
21250 for (entry = list->head; entry; entry = entry->next) {
21251 vty_out(vty,
21252 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21253 list->name, entry->seq,
21254 community_direct_str(entry->direct),
21255 community_list_config_str(entry));
21256 write++;
21257 }
21258 for (list = cm->str.head; list; list = list->next)
21259 for (entry = list->head; entry; entry = entry->next) {
21260 vty_out(vty,
21261 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21262 entry->style == EXTCOMMUNITY_LIST_STANDARD
21263 ? "standard"
21264 : "expanded",
21265 list->name, entry->seq,
21266 community_direct_str(entry->direct),
21267 community_list_config_str(entry));
21268 write++;
21269 }
21270
21271
21272 /* lcommunity-list. */
21273 cm = community_list_master_lookup(bgp_clist,
21274 LARGE_COMMUNITY_LIST_MASTER);
21275
21276 for (list = cm->num.head; list; list = list->next)
21277 for (entry = list->head; entry; entry = entry->next) {
21278 vty_out(vty,
21279 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21280 list->name, entry->seq,
21281 community_direct_str(entry->direct),
21282 community_list_config_str(entry));
21283 write++;
21284 }
21285 for (list = cm->str.head; list; list = list->next)
21286 for (entry = list->head; entry; entry = entry->next) {
21287 vty_out(vty,
21288 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21289
21290 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21291 ? "standard"
21292 : "expanded",
21293 list->name, entry->seq, community_direct_str(entry->direct),
21294 community_list_config_str(entry));
21295 write++;
21296 }
21297
21298 return write;
21299 }
21300
21301 static int community_list_config_write(struct vty *vty);
21302 static struct cmd_node community_list_node = {
21303 .name = "community list",
21304 .node = COMMUNITY_LIST_NODE,
21305 .prompt = "",
21306 .config_write = community_list_config_write,
21307 };
21308
21309 static void community_list_vty(void)
21310 {
21311 install_node(&community_list_node);
21312
21313 /* Community-list. */
21314 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21315 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21316 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21317 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21318 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21319 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21320 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21321 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21322
21323 /* Extcommunity-list. */
21324 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21325 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21326 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21327 install_element(CONFIG_NODE,
21328 &no_bgp_extcommunity_list_standard_all_list_cmd);
21329 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21330 install_element(CONFIG_NODE,
21331 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21332 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21333 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21334
21335 /* Large Community List */
21336 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21337 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21338 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21339 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21340 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21341 install_element(CONFIG_NODE,
21342 &no_bgp_lcommunity_list_name_standard_all_cmd);
21343 install_element(CONFIG_NODE,
21344 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21345 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21346 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21347 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21348 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21349 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21350 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21351
21352 bgp_community_list_command_completion_setup();
21353 }
21354
21355 static struct cmd_node community_alias_node = {
21356 .name = "community alias",
21357 .node = COMMUNITY_ALIAS_NODE,
21358 .prompt = "",
21359 .config_write = bgp_community_alias_write,
21360 };
21361
21362 void community_alias_vty(void)
21363 {
21364 install_node(&community_alias_node);
21365
21366 /* Community-list. */
21367 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21368
21369 bgp_community_alias_command_completion_setup();
21370 }