]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #12671 from vfreex/babel-fix-terminal
[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);
8791
8792 return CMD_SUCCESS;
8793 }
8794
8795 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8796 struct ecommunity **list, bool is_rt6)
8797 {
8798 struct ecommunity *ecom = NULL;
8799 struct ecommunity *ecomadd;
8800
8801 for (; argc; --argc, ++argv) {
8802 if (is_rt6)
8803 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8804 ECOMMUNITY_ROUTE_TARGET,
8805 0);
8806 else
8807 ecomadd = ecommunity_str2com(argv[0]->arg,
8808 ECOMMUNITY_ROUTE_TARGET,
8809 0);
8810 if (!ecomadd) {
8811 vty_out(vty, "Malformed community-list value\n");
8812 if (ecom)
8813 ecommunity_free(&ecom);
8814 return CMD_WARNING_CONFIG_FAILED;
8815 }
8816
8817 if (ecom) {
8818 ecommunity_merge(ecom, ecomadd);
8819 ecommunity_free(&ecomadd);
8820 } else {
8821 ecom = ecomadd;
8822 }
8823 }
8824
8825 if (*list) {
8826 ecommunity_free(&*list);
8827 }
8828 *list = ecom;
8829
8830 return CMD_SUCCESS;
8831 }
8832
8833 /*
8834 * v2vimport is true if we are handling a `import vrf ...` command
8835 */
8836 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8837 {
8838 afi_t afi;
8839
8840 switch (vty->node) {
8841 case BGP_IPV4_NODE:
8842 afi = AFI_IP;
8843 break;
8844 case BGP_IPV6_NODE:
8845 afi = AFI_IP6;
8846 break;
8847 default:
8848 vty_out(vty,
8849 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8850 return AFI_MAX;
8851 }
8852
8853 if (!v2vimport) {
8854 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8855 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8856 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8857 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8858 vty_out(vty,
8859 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8860 return AFI_MAX;
8861 }
8862 } else {
8863 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8864 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8865 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8866 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8867 vty_out(vty,
8868 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8869 return AFI_MAX;
8870 }
8871 }
8872 return afi;
8873 }
8874
8875 DEFPY (af_rd_vpn_export,
8876 af_rd_vpn_export_cmd,
8877 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8878 NO_STR
8879 "Specify route distinguisher\n"
8880 "Between current address-family and vpn\n"
8881 "For routes leaked from current address-family to vpn\n"
8882 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8883 {
8884 VTY_DECLVAR_CONTEXT(bgp, bgp);
8885 struct prefix_rd prd;
8886 int ret;
8887 afi_t afi;
8888 int idx = 0;
8889 bool yes = true;
8890
8891 if (argv_find(argv, argc, "no", &idx))
8892 yes = false;
8893
8894 if (yes) {
8895 ret = str2prefix_rd(rd_str, &prd);
8896 if (!ret) {
8897 vty_out(vty, "%% Malformed rd\n");
8898 return CMD_WARNING_CONFIG_FAILED;
8899 }
8900 }
8901
8902 afi = vpn_policy_getafi(vty, bgp, false);
8903 if (afi == AFI_MAX)
8904 return CMD_WARNING_CONFIG_FAILED;
8905
8906 /*
8907 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8908 */
8909 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8910 bgp_get_default(), bgp);
8911
8912 if (yes) {
8913 bgp->vpn_policy[afi].tovpn_rd = prd;
8914 SET_FLAG(bgp->vpn_policy[afi].flags,
8915 BGP_VPN_POLICY_TOVPN_RD_SET);
8916 } else {
8917 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8918 BGP_VPN_POLICY_TOVPN_RD_SET);
8919 }
8920
8921 /* post-change: re-export vpn routes */
8922 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8923 bgp_get_default(), bgp);
8924
8925 return CMD_SUCCESS;
8926 }
8927
8928 ALIAS (af_rd_vpn_export,
8929 af_no_rd_vpn_export_cmd,
8930 "no rd vpn export",
8931 NO_STR
8932 "Specify route distinguisher\n"
8933 "Between current address-family and vpn\n"
8934 "For routes leaked from current address-family to vpn\n")
8935
8936 DEFPY (af_label_vpn_export,
8937 af_label_vpn_export_cmd,
8938 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8939 NO_STR
8940 "label value for VRF\n"
8941 "Between current address-family and vpn\n"
8942 "For routes leaked from current address-family to vpn\n"
8943 "Label Value <0-1048575>\n"
8944 "Automatically assign a label\n")
8945 {
8946 VTY_DECLVAR_CONTEXT(bgp, bgp);
8947 mpls_label_t label = MPLS_LABEL_NONE;
8948 afi_t afi;
8949 int idx = 0;
8950 bool yes = true;
8951
8952 if (argv_find(argv, argc, "no", &idx))
8953 yes = false;
8954
8955 /* If "no ...", squash trailing parameter */
8956 if (!yes)
8957 label_auto = NULL;
8958
8959 if (yes) {
8960 if (!label_auto)
8961 label = label_val; /* parser should force unsigned */
8962 }
8963
8964 afi = vpn_policy_getafi(vty, bgp, false);
8965 if (afi == AFI_MAX)
8966 return CMD_WARNING_CONFIG_FAILED;
8967
8968
8969 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8970 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8971 /* no change */
8972 return CMD_SUCCESS;
8973
8974 /*
8975 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8976 */
8977 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8978 bgp_get_default(), bgp);
8979
8980 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8981 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8982
8983 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8984
8985 /*
8986 * label has previously been automatically
8987 * assigned by labelpool: release it
8988 *
8989 * NB if tovpn_label == MPLS_LABEL_NONE it
8990 * means the automatic assignment is in flight
8991 * and therefore the labelpool callback must
8992 * detect that the auto label is not needed.
8993 */
8994
8995 bgp_lp_release(LP_TYPE_VRF,
8996 &bgp->vpn_policy[afi],
8997 bgp->vpn_policy[afi].tovpn_label);
8998 }
8999 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9000 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9001 }
9002
9003 bgp->vpn_policy[afi].tovpn_label = label;
9004 if (label_auto) {
9005 SET_FLAG(bgp->vpn_policy[afi].flags,
9006 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9007 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9008 vpn_leak_label_callback);
9009 }
9010
9011 /* post-change: re-export vpn routes */
9012 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9013 bgp_get_default(), bgp);
9014
9015 hook_call(bgp_snmp_update_last_changed, bgp);
9016 return CMD_SUCCESS;
9017 }
9018
9019 DEFPY (af_sid_vpn_export,
9020 af_sid_vpn_export_cmd,
9021 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9022 NO_STR
9023 "sid value for VRF\n"
9024 "Between current address-family and vpn\n"
9025 "For routes leaked from current address-family to vpn\n"
9026 "Sid allocation index\n"
9027 "Automatically assign a label\n")
9028 {
9029 VTY_DECLVAR_CONTEXT(bgp, bgp);
9030 afi_t afi;
9031 int debug = 0;
9032 int idx = 0;
9033 bool yes = true;
9034
9035 if (argv_find(argv, argc, "no", &idx))
9036 yes = false;
9037 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9038 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9039
9040 afi = vpn_policy_getafi(vty, bgp, false);
9041 if (afi == AFI_MAX)
9042 return CMD_WARNING_CONFIG_FAILED;
9043
9044 if (!yes) {
9045 /* implement me */
9046 vty_out(vty, "It's not implemented\n");
9047 return CMD_WARNING_CONFIG_FAILED;
9048 }
9049
9050 if (bgp->tovpn_sid_index != 0 ||
9051 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9052 vty_out(vty,
9053 "per-vrf sid and per-af sid are mutually exclusive\n"
9054 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9055 return CMD_WARNING_CONFIG_FAILED;
9056 }
9057
9058 /* skip when it's already configured */
9059 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9060 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9061 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9062 return CMD_SUCCESS;
9063
9064 /*
9065 * mode change between sid_idx and sid_auto isn't supported.
9066 * user must negate sid vpn export when they want to change the mode
9067 */
9068 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9069 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9070 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9071 vty_out(vty, "it's already configured as %s.\n",
9072 sid_auto ? "auto-mode" : "idx-mode");
9073 return CMD_WARNING_CONFIG_FAILED;
9074 }
9075
9076 /* pre-change */
9077 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9078 bgp_get_default(), bgp);
9079
9080 if (sid_auto) {
9081 /* SID allocation auto-mode */
9082 if (debug)
9083 zlog_debug("%s: auto sid alloc.", __func__);
9084 SET_FLAG(bgp->vpn_policy[afi].flags,
9085 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9086 } else {
9087 /* SID allocation index-mode */
9088 if (debug)
9089 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9090 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9091 }
9092
9093 /* post-change */
9094 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9095 bgp_get_default(), bgp);
9096 return CMD_SUCCESS;
9097 }
9098
9099 DEFPY (bgp_sid_vpn_export,
9100 bgp_sid_vpn_export_cmd,
9101 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9102 NO_STR
9103 "sid value for VRF\n"
9104 "Between current vrf and vpn\n"
9105 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9106 "For routes leaked from current vrf to vpn\n"
9107 "Sid allocation index\n"
9108 "Automatically assign a label\n")
9109 {
9110 VTY_DECLVAR_CONTEXT(bgp, bgp);
9111 int debug;
9112
9113 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9114 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9115
9116 if (no) {
9117 /* when per-VRF SID is not set, do nothing */
9118 if (bgp->tovpn_sid_index == 0 &&
9119 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9120 return CMD_SUCCESS;
9121
9122 sid_idx = 0;
9123 sid_auto = false;
9124 bgp->tovpn_sid_index = 0;
9125 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9126 }
9127
9128 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9129 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9130 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9131 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9132 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9133 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9134 vty_out(vty,
9135 "per-vrf sid and per-af sid are mutually exclusive\n"
9136 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9137 return CMD_WARNING_CONFIG_FAILED;
9138 }
9139
9140 /* skip when it's already configured */
9141 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9142 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9143 return CMD_SUCCESS;
9144
9145 /*
9146 * mode change between sid_idx and sid_auto isn't supported.
9147 * user must negate sid vpn export when they want to change the mode
9148 */
9149 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9150 (sid_idx != 0 &&
9151 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9152 vty_out(vty, "it's already configured as %s.\n",
9153 sid_auto ? "auto-mode" : "idx-mode");
9154 return CMD_WARNING_CONFIG_FAILED;
9155 }
9156
9157 /* pre-change */
9158 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9159 bgp);
9160 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9161 bgp);
9162
9163 if (sid_auto) {
9164 /* SID allocation auto-mode */
9165 if (debug)
9166 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9167 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9168 } else if (sid_idx != 0) {
9169 /* SID allocation index-mode */
9170 if (debug)
9171 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9172 sid_idx);
9173 bgp->tovpn_sid_index = sid_idx;
9174 }
9175
9176 /* post-change */
9177 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9178 bgp);
9179 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9180 bgp_get_default(), bgp);
9181
9182 return CMD_SUCCESS;
9183 }
9184
9185 ALIAS (af_label_vpn_export,
9186 af_no_label_vpn_export_cmd,
9187 "no label vpn export",
9188 NO_STR
9189 "label value for VRF\n"
9190 "Between current address-family and vpn\n"
9191 "For routes leaked from current address-family to vpn\n")
9192
9193 ALIAS (bgp_sid_vpn_export,
9194 no_bgp_sid_vpn_export_cmd,
9195 "no$no sid vpn per-vrf export",
9196 NO_STR
9197 "sid value for VRF\n"
9198 "Between current vrf and vpn\n"
9199 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9200 "For routes leaked from current vrf to vpn\n")
9201
9202 DEFPY (af_nexthop_vpn_export,
9203 af_nexthop_vpn_export_cmd,
9204 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9205 NO_STR
9206 "Specify next hop to use for VRF advertised prefixes\n"
9207 "Between current address-family and vpn\n"
9208 "For routes leaked from current address-family to vpn\n"
9209 "IPv4 prefix\n"
9210 "IPv6 prefix\n")
9211 {
9212 VTY_DECLVAR_CONTEXT(bgp, bgp);
9213 afi_t afi;
9214 struct prefix p;
9215
9216 if (!no) {
9217 if (!nexthop_su) {
9218 vty_out(vty, "%% Nexthop required\n");
9219 return CMD_WARNING_CONFIG_FAILED;
9220 }
9221 if (!sockunion2hostprefix(nexthop_su, &p))
9222 return CMD_WARNING_CONFIG_FAILED;
9223 }
9224
9225 afi = vpn_policy_getafi(vty, bgp, false);
9226 if (afi == AFI_MAX)
9227 return CMD_WARNING_CONFIG_FAILED;
9228
9229 /*
9230 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9231 */
9232 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9233 bgp_get_default(), bgp);
9234
9235 if (!no) {
9236 bgp->vpn_policy[afi].tovpn_nexthop = p;
9237 SET_FLAG(bgp->vpn_policy[afi].flags,
9238 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9239 } else {
9240 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9241 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9242 }
9243
9244 /* post-change: re-export vpn routes */
9245 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9246 bgp_get_default(), bgp);
9247
9248 return CMD_SUCCESS;
9249 }
9250
9251 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9252 {
9253 if (!strcmp(dstr, "import")) {
9254 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9255 } else if (!strcmp(dstr, "export")) {
9256 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9257 } else if (!strcmp(dstr, "both")) {
9258 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9259 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9260 } else {
9261 vty_out(vty, "%% direction parse error\n");
9262 return CMD_WARNING_CONFIG_FAILED;
9263 }
9264 return CMD_SUCCESS;
9265 }
9266
9267 DEFPY (af_rt_vpn_imexport,
9268 af_rt_vpn_imexport_cmd,
9269 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9270 NO_STR
9271 "Specify route target list\n"
9272 "Specify route target list\n"
9273 "Between current address-family and vpn\n"
9274 "For routes leaked from vpn to current address-family: match any\n"
9275 "For routes leaked from current address-family to vpn: set\n"
9276 "both import: match any and export: set\n"
9277 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9278 {
9279 VTY_DECLVAR_CONTEXT(bgp, bgp);
9280 int ret;
9281 struct ecommunity *ecom = NULL;
9282 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9283 enum vpn_policy_direction dir;
9284 afi_t afi;
9285 int idx = 0;
9286 bool yes = true;
9287
9288 if (argv_find(argv, argc, "no", &idx))
9289 yes = false;
9290
9291 afi = vpn_policy_getafi(vty, bgp, false);
9292 if (afi == AFI_MAX)
9293 return CMD_WARNING_CONFIG_FAILED;
9294
9295 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9296 if (ret != CMD_SUCCESS)
9297 return ret;
9298
9299 if (yes) {
9300 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9301 vty_out(vty, "%% Missing RTLIST\n");
9302 return CMD_WARNING_CONFIG_FAILED;
9303 }
9304 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9305 if (ret != CMD_SUCCESS) {
9306 return ret;
9307 }
9308 }
9309
9310 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9311 if (!dodir[dir])
9312 continue;
9313
9314 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9315
9316 if (yes) {
9317 if (bgp->vpn_policy[afi].rtlist[dir])
9318 ecommunity_free(
9319 &bgp->vpn_policy[afi].rtlist[dir]);
9320 bgp->vpn_policy[afi].rtlist[dir] =
9321 ecommunity_dup(ecom);
9322 } else {
9323 if (bgp->vpn_policy[afi].rtlist[dir])
9324 ecommunity_free(
9325 &bgp->vpn_policy[afi].rtlist[dir]);
9326 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9327 }
9328
9329 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9330 }
9331
9332 if (ecom)
9333 ecommunity_free(&ecom);
9334
9335 return CMD_SUCCESS;
9336 }
9337
9338 ALIAS (af_rt_vpn_imexport,
9339 af_no_rt_vpn_imexport_cmd,
9340 "no <rt|route-target> vpn <import|export|both>$direction_str",
9341 NO_STR
9342 "Specify route target list\n"
9343 "Specify route target list\n"
9344 "Between current address-family and vpn\n"
9345 "For routes leaked from vpn to current address-family\n"
9346 "For routes leaked from current address-family to vpn\n"
9347 "both import and export\n")
9348
9349 DEFPY (af_route_map_vpn_imexport,
9350 af_route_map_vpn_imexport_cmd,
9351 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9352 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9353 NO_STR
9354 "Specify route map\n"
9355 "Between current address-family and vpn\n"
9356 "For routes leaked from vpn to current address-family\n"
9357 "For routes leaked from current address-family to vpn\n"
9358 "name of route-map\n")
9359 {
9360 VTY_DECLVAR_CONTEXT(bgp, bgp);
9361 int ret;
9362 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9363 enum vpn_policy_direction dir;
9364 afi_t afi;
9365 int idx = 0;
9366 bool yes = true;
9367
9368 if (argv_find(argv, argc, "no", &idx))
9369 yes = false;
9370
9371 afi = vpn_policy_getafi(vty, bgp, false);
9372 if (afi == AFI_MAX)
9373 return CMD_WARNING_CONFIG_FAILED;
9374
9375 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9376 if (ret != CMD_SUCCESS)
9377 return ret;
9378
9379 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9380 if (!dodir[dir])
9381 continue;
9382
9383 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9384
9385 if (yes) {
9386 if (bgp->vpn_policy[afi].rmap_name[dir])
9387 XFREE(MTYPE_ROUTE_MAP_NAME,
9388 bgp->vpn_policy[afi].rmap_name[dir]);
9389 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9390 MTYPE_ROUTE_MAP_NAME, rmap_str);
9391 bgp->vpn_policy[afi].rmap[dir] =
9392 route_map_lookup_warn_noexist(vty, rmap_str);
9393 if (!bgp->vpn_policy[afi].rmap[dir])
9394 return CMD_SUCCESS;
9395 } else {
9396 if (bgp->vpn_policy[afi].rmap_name[dir])
9397 XFREE(MTYPE_ROUTE_MAP_NAME,
9398 bgp->vpn_policy[afi].rmap_name[dir]);
9399 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9400 bgp->vpn_policy[afi].rmap[dir] = NULL;
9401 }
9402
9403 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9404 }
9405
9406 return CMD_SUCCESS;
9407 }
9408
9409 ALIAS (af_route_map_vpn_imexport,
9410 af_no_route_map_vpn_imexport_cmd,
9411 "no route-map vpn <import|export>$direction_str",
9412 NO_STR
9413 "Specify route map\n"
9414 "Between current address-family and vpn\n"
9415 "For routes leaked from vpn to current address-family\n"
9416 "For routes leaked from current address-family to vpn\n")
9417
9418 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9419 "import vrf route-map RMAP$rmap_str",
9420 "Import routes from another VRF\n"
9421 "Vrf routes being filtered\n"
9422 "Specify route map\n"
9423 "name of route-map\n")
9424 {
9425 VTY_DECLVAR_CONTEXT(bgp, bgp);
9426 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9427 afi_t afi;
9428 struct bgp *bgp_default;
9429
9430 afi = vpn_policy_getafi(vty, bgp, true);
9431 if (afi == AFI_MAX)
9432 return CMD_WARNING_CONFIG_FAILED;
9433
9434 bgp_default = bgp_get_default();
9435 if (!bgp_default) {
9436 int32_t ret;
9437 as_t as = bgp->as;
9438
9439 /* Auto-create assuming the same AS */
9440 ret = bgp_get_vty(&bgp_default, &as, NULL,
9441 BGP_INSTANCE_TYPE_DEFAULT);
9442
9443 if (ret) {
9444 vty_out(vty,
9445 "VRF default is not configured as a bgp instance\n");
9446 return CMD_WARNING;
9447 }
9448 }
9449
9450 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9451
9452 if (bgp->vpn_policy[afi].rmap_name[dir])
9453 XFREE(MTYPE_ROUTE_MAP_NAME,
9454 bgp->vpn_policy[afi].rmap_name[dir]);
9455 bgp->vpn_policy[afi].rmap_name[dir] =
9456 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9457 bgp->vpn_policy[afi].rmap[dir] =
9458 route_map_lookup_warn_noexist(vty, rmap_str);
9459 if (!bgp->vpn_policy[afi].rmap[dir])
9460 return CMD_SUCCESS;
9461
9462 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9463 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9464
9465 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9466
9467 return CMD_SUCCESS;
9468 }
9469
9470 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9471 "no import vrf route-map [RMAP$rmap_str]",
9472 NO_STR
9473 "Import routes from another VRF\n"
9474 "Vrf routes being filtered\n"
9475 "Specify route map\n"
9476 "name of route-map\n")
9477 {
9478 VTY_DECLVAR_CONTEXT(bgp, bgp);
9479 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9480 afi_t afi;
9481
9482 afi = vpn_policy_getafi(vty, bgp, true);
9483 if (afi == AFI_MAX)
9484 return CMD_WARNING_CONFIG_FAILED;
9485
9486 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9487
9488 if (bgp->vpn_policy[afi].rmap_name[dir])
9489 XFREE(MTYPE_ROUTE_MAP_NAME,
9490 bgp->vpn_policy[afi].rmap_name[dir]);
9491 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9492 bgp->vpn_policy[afi].rmap[dir] = NULL;
9493
9494 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9495 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9496 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9497
9498 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9499
9500 return CMD_SUCCESS;
9501 }
9502
9503 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9504 "[no] import vrf VIEWVRFNAME$import_name",
9505 NO_STR
9506 "Import routes from another VRF\n"
9507 "VRF to import from\n"
9508 "The name of the VRF\n")
9509 {
9510 VTY_DECLVAR_CONTEXT(bgp, bgp);
9511 struct listnode *node;
9512 struct bgp *vrf_bgp, *bgp_default;
9513 int32_t ret = 0;
9514 as_t as = bgp->as;
9515 bool remove = false;
9516 int32_t idx = 0;
9517 char *vname;
9518 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9519 safi_t safi;
9520 afi_t afi;
9521
9522 if (import_name == NULL) {
9523 vty_out(vty, "%% Missing import name\n");
9524 return CMD_WARNING;
9525 }
9526
9527 if (strcmp(import_name, "route-map") == 0) {
9528 vty_out(vty, "%% Must include route-map name\n");
9529 return CMD_WARNING;
9530 }
9531
9532 if (argv_find(argv, argc, "no", &idx))
9533 remove = true;
9534
9535 afi = vpn_policy_getafi(vty, bgp, true);
9536 if (afi == AFI_MAX)
9537 return CMD_WARNING_CONFIG_FAILED;
9538
9539 safi = bgp_node_safi(vty);
9540
9541 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9542 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9543 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9544 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9545 remove ? "unimport" : "import", import_name);
9546 return CMD_WARNING;
9547 }
9548
9549 bgp_default = bgp_get_default();
9550 if (!bgp_default) {
9551 /* Auto-create assuming the same AS */
9552 ret = bgp_get_vty(&bgp_default, &as, NULL,
9553 BGP_INSTANCE_TYPE_DEFAULT);
9554
9555 if (ret) {
9556 vty_out(vty,
9557 "VRF default is not configured as a bgp instance\n");
9558 return CMD_WARNING;
9559 }
9560 }
9561
9562 vrf_bgp = bgp_lookup_by_name(import_name);
9563 if (!vrf_bgp) {
9564 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9565 vrf_bgp = bgp_default;
9566 else
9567 /* Auto-create assuming the same AS */
9568 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9569
9570 if (ret) {
9571 vty_out(vty,
9572 "VRF %s is not configured as a bgp instance\n",
9573 import_name);
9574 return CMD_WARNING;
9575 }
9576 }
9577
9578 if (remove) {
9579 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9580 } else {
9581 /* Already importing from "import_vrf"? */
9582 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9583 vname)) {
9584 if (strcmp(vname, import_name) == 0)
9585 return CMD_WARNING;
9586 }
9587
9588 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9589 }
9590
9591 return CMD_SUCCESS;
9592 }
9593
9594 /* This command is valid only in a bgp vrf instance or the default instance */
9595 DEFPY (bgp_imexport_vpn,
9596 bgp_imexport_vpn_cmd,
9597 "[no] <import|export>$direction_str vpn",
9598 NO_STR
9599 "Import routes to this address-family\n"
9600 "Export routes from this address-family\n"
9601 "to/from default instance VPN RIB\n")
9602 {
9603 VTY_DECLVAR_CONTEXT(bgp, bgp);
9604 int previous_state;
9605 afi_t afi;
9606 safi_t safi;
9607 int idx = 0;
9608 bool yes = true;
9609 int flag;
9610 enum vpn_policy_direction dir;
9611
9612 if (argv_find(argv, argc, "no", &idx))
9613 yes = false;
9614
9615 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9616 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9617
9618 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9619 return CMD_WARNING_CONFIG_FAILED;
9620 }
9621
9622 afi = bgp_node_afi(vty);
9623 safi = bgp_node_safi(vty);
9624 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9625 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9626 return CMD_WARNING_CONFIG_FAILED;
9627 }
9628
9629 if (!strcmp(direction_str, "import")) {
9630 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9631 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9632 } else if (!strcmp(direction_str, "export")) {
9633 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9634 dir = BGP_VPN_POLICY_DIR_TOVPN;
9635 } else {
9636 vty_out(vty, "%% unknown direction %s\n", direction_str);
9637 return CMD_WARNING_CONFIG_FAILED;
9638 }
9639
9640 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9641
9642 if (yes) {
9643 SET_FLAG(bgp->af_flags[afi][safi], flag);
9644 if (!previous_state) {
9645 /* trigger export current vrf */
9646 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9647 }
9648 } else {
9649 if (previous_state) {
9650 /* trigger un-export current vrf */
9651 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9652 }
9653 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9654 }
9655
9656 hook_call(bgp_snmp_init_stats, bgp);
9657
9658 return CMD_SUCCESS;
9659 }
9660
9661 DEFPY (af_routetarget_import,
9662 af_routetarget_import_cmd,
9663 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9664 NO_STR
9665 "Specify route target list\n"
9666 "Specify route target list\n"
9667 "Specify route target list\n"
9668 "Specify route target list\n"
9669 "Flow-spec redirect type route target\n"
9670 "Import routes to this address-family\n"
9671 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9672 {
9673 VTY_DECLVAR_CONTEXT(bgp, bgp);
9674 int ret;
9675 struct ecommunity *ecom = NULL;
9676 afi_t afi;
9677 int idx = 0, idx_unused = 0;
9678 bool yes = true;
9679 bool rt6 = false;
9680
9681 if (argv_find(argv, argc, "no", &idx))
9682 yes = false;
9683
9684 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9685 argv_find(argv, argc, "route-target6", &idx_unused))
9686 rt6 = true;
9687
9688 afi = vpn_policy_getafi(vty, bgp, false);
9689 if (afi == AFI_MAX)
9690 return CMD_WARNING_CONFIG_FAILED;
9691
9692 if (rt6 && afi != AFI_IP6)
9693 return CMD_WARNING_CONFIG_FAILED;
9694
9695 if (yes) {
9696 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9697 vty_out(vty, "%% Missing RTLIST\n");
9698 return CMD_WARNING_CONFIG_FAILED;
9699 }
9700 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9701 if (ret != CMD_SUCCESS)
9702 return ret;
9703 }
9704
9705 if (yes) {
9706 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9707 ecommunity_free(&bgp->vpn_policy[afi]
9708 .import_redirect_rtlist);
9709 bgp->vpn_policy[afi].import_redirect_rtlist =
9710 ecommunity_dup(ecom);
9711 } else {
9712 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9713 ecommunity_free(&bgp->vpn_policy[afi]
9714 .import_redirect_rtlist);
9715 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9716 }
9717
9718 if (ecom)
9719 ecommunity_free(&ecom);
9720
9721 return CMD_SUCCESS;
9722 }
9723
9724 DEFUN_NOSH (address_family_ipv4_safi,
9725 address_family_ipv4_safi_cmd,
9726 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9727 "Enter Address Family command mode\n"
9728 BGP_AF_STR
9729 BGP_SAFI_WITH_LABEL_HELP_STR)
9730 {
9731
9732 if (argc == 3) {
9733 VTY_DECLVAR_CONTEXT(bgp, bgp);
9734 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9735 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9736 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9737 && safi != SAFI_EVPN) {
9738 vty_out(vty,
9739 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9740 return CMD_WARNING_CONFIG_FAILED;
9741 }
9742 vty->node = bgp_node_type(AFI_IP, safi);
9743 } else
9744 vty->node = BGP_IPV4_NODE;
9745
9746 return CMD_SUCCESS;
9747 }
9748
9749 DEFUN_NOSH (address_family_ipv6_safi,
9750 address_family_ipv6_safi_cmd,
9751 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9752 "Enter Address Family command mode\n"
9753 BGP_AF_STR
9754 BGP_SAFI_WITH_LABEL_HELP_STR)
9755 {
9756 if (argc == 3) {
9757 VTY_DECLVAR_CONTEXT(bgp, bgp);
9758 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9759 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9760 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9761 && safi != SAFI_EVPN) {
9762 vty_out(vty,
9763 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9764 return CMD_WARNING_CONFIG_FAILED;
9765 }
9766 vty->node = bgp_node_type(AFI_IP6, safi);
9767 } else
9768 vty->node = BGP_IPV6_NODE;
9769
9770 return CMD_SUCCESS;
9771 }
9772
9773 #ifdef KEEP_OLD_VPN_COMMANDS
9774 DEFUN_NOSH (address_family_vpnv4,
9775 address_family_vpnv4_cmd,
9776 "address-family vpnv4 [unicast]",
9777 "Enter Address Family command mode\n"
9778 BGP_AF_STR
9779 BGP_AF_MODIFIER_STR)
9780 {
9781 vty->node = BGP_VPNV4_NODE;
9782 return CMD_SUCCESS;
9783 }
9784
9785 DEFUN_NOSH (address_family_vpnv6,
9786 address_family_vpnv6_cmd,
9787 "address-family vpnv6 [unicast]",
9788 "Enter Address Family command mode\n"
9789 BGP_AF_STR
9790 BGP_AF_MODIFIER_STR)
9791 {
9792 vty->node = BGP_VPNV6_NODE;
9793 return CMD_SUCCESS;
9794 }
9795 #endif /* KEEP_OLD_VPN_COMMANDS */
9796
9797 DEFUN_NOSH (address_family_evpn,
9798 address_family_evpn_cmd,
9799 "address-family l2vpn evpn",
9800 "Enter Address Family command mode\n"
9801 BGP_AF_STR
9802 BGP_AF_MODIFIER_STR)
9803 {
9804 VTY_DECLVAR_CONTEXT(bgp, bgp);
9805 vty->node = BGP_EVPN_NODE;
9806 return CMD_SUCCESS;
9807 }
9808
9809 DEFUN_NOSH (bgp_segment_routing_srv6,
9810 bgp_segment_routing_srv6_cmd,
9811 "segment-routing srv6",
9812 "Segment-Routing configuration\n"
9813 "Segment-Routing SRv6 configuration\n")
9814 {
9815 VTY_DECLVAR_CONTEXT(bgp, bgp);
9816 bgp->srv6_enabled = true;
9817 vty->node = BGP_SRV6_NODE;
9818 return CMD_SUCCESS;
9819 }
9820
9821 DEFUN (no_bgp_segment_routing_srv6,
9822 no_bgp_segment_routing_srv6_cmd,
9823 "no segment-routing srv6",
9824 NO_STR
9825 "Segment-Routing configuration\n"
9826 "Segment-Routing SRv6 configuration\n")
9827 {
9828 VTY_DECLVAR_CONTEXT(bgp, bgp);
9829
9830 if (strlen(bgp->srv6_locator_name) > 0)
9831 if (bgp_srv6_locator_unset(bgp) < 0)
9832 return CMD_WARNING_CONFIG_FAILED;
9833
9834 bgp->srv6_enabled = false;
9835 return CMD_SUCCESS;
9836 }
9837
9838 DEFPY (bgp_srv6_locator,
9839 bgp_srv6_locator_cmd,
9840 "locator NAME$name",
9841 "Specify SRv6 locator\n"
9842 "Specify SRv6 locator\n")
9843 {
9844 VTY_DECLVAR_CONTEXT(bgp, bgp);
9845 int ret;
9846
9847 if (strlen(bgp->srv6_locator_name) > 0
9848 && strcmp(name, bgp->srv6_locator_name) != 0) {
9849 vty_out(vty, "srv6 locator is already configured\n");
9850 return CMD_WARNING_CONFIG_FAILED;
9851 }
9852
9853 snprintf(bgp->srv6_locator_name,
9854 sizeof(bgp->srv6_locator_name), "%s", name);
9855
9856 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9857 if (ret < 0)
9858 return CMD_WARNING_CONFIG_FAILED;
9859
9860 return CMD_SUCCESS;
9861 }
9862
9863 DEFPY (no_bgp_srv6_locator,
9864 no_bgp_srv6_locator_cmd,
9865 "no locator NAME$name",
9866 NO_STR
9867 "Specify SRv6 locator\n"
9868 "Specify SRv6 locator\n")
9869 {
9870 VTY_DECLVAR_CONTEXT(bgp, bgp);
9871
9872 /* when locator isn't configured, do nothing */
9873 if (strlen(bgp->srv6_locator_name) < 1)
9874 return CMD_SUCCESS;
9875
9876 /* name validation */
9877 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9878 vty_out(vty, "%% No srv6 locator is configured\n");
9879 return CMD_WARNING_CONFIG_FAILED;
9880 }
9881
9882 /* unset locator */
9883 if (bgp_srv6_locator_unset(bgp) < 0)
9884 return CMD_WARNING_CONFIG_FAILED;
9885
9886 return CMD_SUCCESS;
9887 }
9888
9889 DEFPY (show_bgp_srv6,
9890 show_bgp_srv6_cmd,
9891 "show bgp segment-routing srv6",
9892 SHOW_STR
9893 BGP_STR
9894 "BGP Segment Routing\n"
9895 "BGP Segment Routing SRv6\n")
9896 {
9897 struct bgp *bgp;
9898 struct listnode *node;
9899 struct srv6_locator_chunk *chunk;
9900 struct bgp_srv6_function *func;
9901
9902 bgp = bgp_get_default();
9903 if (!bgp)
9904 return CMD_SUCCESS;
9905
9906 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9907 vty_out(vty, "locator_chunks:\n");
9908 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9909 vty_out(vty, "- %pFX\n", &chunk->prefix);
9910 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9911 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9912 vty_out(vty, " func-length: %d\n",
9913 chunk->function_bits_length);
9914 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9915 }
9916
9917 vty_out(vty, "functions:\n");
9918 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9919 vty_out(vty, "- sid: %pI6\n", &func->sid);
9920 vty_out(vty, " locator: %s\n", func->locator_name);
9921 }
9922
9923 vty_out(vty, "bgps:\n");
9924 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9925 vty_out(vty, "- name: %s\n",
9926 bgp->name ? bgp->name : "default");
9927
9928 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9929 bgp->vpn_policy[AFI_IP].tovpn_sid);
9930 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9931 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9932 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
9933 }
9934
9935 return CMD_SUCCESS;
9936 }
9937
9938 DEFUN_NOSH (exit_address_family,
9939 exit_address_family_cmd,
9940 "exit-address-family",
9941 "Exit from Address Family configuration mode\n")
9942 {
9943 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9944 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9945 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9946 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9947 || vty->node == BGP_EVPN_NODE
9948 || vty->node == BGP_FLOWSPECV4_NODE
9949 || vty->node == BGP_FLOWSPECV6_NODE)
9950 vty->node = BGP_NODE;
9951 return CMD_SUCCESS;
9952 }
9953
9954 /* Recalculate bestpath and re-advertise a prefix */
9955 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9956 const char *ip_str, afi_t afi, safi_t safi,
9957 struct prefix_rd *prd)
9958 {
9959 int ret;
9960 struct prefix match;
9961 struct bgp_dest *dest;
9962 struct bgp_dest *rm;
9963 struct bgp *bgp;
9964 struct bgp_table *table;
9965 struct bgp_table *rib;
9966
9967 /* BGP structure lookup. */
9968 if (view_name) {
9969 bgp = bgp_lookup_by_name(view_name);
9970 if (bgp == NULL) {
9971 vty_out(vty, "%% Can't find BGP instance %s\n",
9972 view_name);
9973 return CMD_WARNING;
9974 }
9975 } else {
9976 bgp = bgp_get_default();
9977 if (bgp == NULL) {
9978 vty_out(vty, "%% No BGP process is configured\n");
9979 return CMD_WARNING;
9980 }
9981 }
9982
9983 /* Check IP address argument. */
9984 ret = str2prefix(ip_str, &match);
9985 if (!ret) {
9986 vty_out(vty, "%% address is malformed\n");
9987 return CMD_WARNING;
9988 }
9989
9990 match.family = afi2family(afi);
9991 rib = bgp->rib[afi][safi];
9992
9993 if (safi == SAFI_MPLS_VPN) {
9994 for (dest = bgp_table_top(rib); dest;
9995 dest = bgp_route_next(dest)) {
9996 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9997
9998 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9999 continue;
10000
10001 table = bgp_dest_get_bgp_table_info(dest);
10002 if (table == NULL)
10003 continue;
10004
10005 rm = bgp_node_match(table, &match);
10006 if (rm != NULL) {
10007 const struct prefix *rm_p =
10008 bgp_dest_get_prefix(rm);
10009
10010 if (rm_p->prefixlen == match.prefixlen) {
10011 SET_FLAG(rm->flags,
10012 BGP_NODE_USER_CLEAR);
10013 bgp_process(bgp, rm, afi, safi);
10014 }
10015 bgp_dest_unlock_node(rm);
10016 }
10017 }
10018 } else {
10019 dest = bgp_node_match(rib, &match);
10020 if (dest != NULL) {
10021 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10022
10023 if (dest_p->prefixlen == match.prefixlen) {
10024 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10025 bgp_process(bgp, dest, afi, safi);
10026 }
10027 bgp_dest_unlock_node(dest);
10028 }
10029 }
10030
10031 return CMD_SUCCESS;
10032 }
10033
10034 /* one clear bgp command to rule them all */
10035 DEFUN (clear_ip_bgp_all,
10036 clear_ip_bgp_all_cmd,
10037 "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>]",
10038 CLEAR_STR
10039 IP_STR
10040 BGP_STR
10041 BGP_INSTANCE_HELP_STR
10042 BGP_AFI_HELP_STR
10043 BGP_AF_STR
10044 BGP_SAFI_WITH_LABEL_HELP_STR
10045 BGP_AF_MODIFIER_STR
10046 "Clear all peers\n"
10047 "BGP IPv4 neighbor to clear\n"
10048 "BGP IPv6 neighbor to clear\n"
10049 "BGP neighbor on interface to clear\n"
10050 "Clear peers with the AS number\n"
10051 "Clear all external peers\n"
10052 "Clear all members of peer-group\n"
10053 "BGP peer-group name\n"
10054 BGP_SOFT_STR
10055 BGP_SOFT_IN_STR
10056 BGP_SOFT_OUT_STR
10057 BGP_SOFT_IN_STR
10058 "Push out prefix-list ORF and do inbound soft reconfig\n"
10059 BGP_SOFT_OUT_STR
10060 "Reset message statistics\n")
10061 {
10062 char *vrf = NULL;
10063
10064 afi_t afi = AFI_UNSPEC;
10065 safi_t safi = SAFI_UNSPEC;
10066 enum clear_sort clr_sort = clear_peer;
10067 enum bgp_clear_type clr_type;
10068 char *clr_arg = NULL;
10069
10070 int idx = 0;
10071
10072 /* clear [ip] bgp */
10073 if (argv_find(argv, argc, "ip", &idx))
10074 afi = AFI_IP;
10075
10076 /* [<vrf> VIEWVRFNAME] */
10077 if (argv_find(argv, argc, "vrf", &idx)) {
10078 vrf = argv[idx + 1]->arg;
10079 idx += 2;
10080 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10081 vrf = NULL;
10082 } else if (argv_find(argv, argc, "view", &idx)) {
10083 /* [<view> VIEWVRFNAME] */
10084 vrf = argv[idx + 1]->arg;
10085 idx += 2;
10086 }
10087 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10088 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10089 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10090
10091 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10092 if (argv_find(argv, argc, "*", &idx)) {
10093 clr_sort = clear_all;
10094 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10095 clr_sort = clear_peer;
10096 clr_arg = argv[idx]->arg;
10097 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10098 clr_sort = clear_peer;
10099 clr_arg = argv[idx]->arg;
10100 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10101 clr_sort = clear_group;
10102 idx++;
10103 clr_arg = argv[idx]->arg;
10104 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10105 clr_sort = clear_peer;
10106 clr_arg = argv[idx]->arg;
10107 } else if (argv_find(argv, argc, "WORD", &idx)) {
10108 clr_sort = clear_peer;
10109 clr_arg = argv[idx]->arg;
10110 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10111 clr_sort = clear_as;
10112 clr_arg = argv[idx]->arg;
10113 } else if (argv_find(argv, argc, "external", &idx)) {
10114 clr_sort = clear_external;
10115 }
10116
10117 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10118 if (argv_find(argv, argc, "soft", &idx)) {
10119 if (argv_find(argv, argc, "in", &idx)
10120 || argv_find(argv, argc, "out", &idx))
10121 clr_type = strmatch(argv[idx]->text, "in")
10122 ? BGP_CLEAR_SOFT_IN
10123 : BGP_CLEAR_SOFT_OUT;
10124 else
10125 clr_type = BGP_CLEAR_SOFT_BOTH;
10126 } else if (argv_find(argv, argc, "in", &idx)) {
10127 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10128 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10129 : BGP_CLEAR_SOFT_IN;
10130 } else if (argv_find(argv, argc, "out", &idx)) {
10131 clr_type = BGP_CLEAR_SOFT_OUT;
10132 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10133 clr_type = BGP_CLEAR_MESSAGE_STATS;
10134 } else
10135 clr_type = BGP_CLEAR_SOFT_NONE;
10136
10137 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10138 }
10139
10140 DEFUN (clear_ip_bgp_prefix,
10141 clear_ip_bgp_prefix_cmd,
10142 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10143 CLEAR_STR
10144 IP_STR
10145 BGP_STR
10146 BGP_INSTANCE_HELP_STR
10147 "Clear bestpath and re-advertise\n"
10148 "IPv4 prefix\n")
10149 {
10150 char *vrf = NULL;
10151 char *prefix = NULL;
10152
10153 int idx = 0;
10154
10155 /* [<view|vrf> VIEWVRFNAME] */
10156 if (argv_find(argv, argc, "vrf", &idx)) {
10157 vrf = argv[idx + 1]->arg;
10158 idx += 2;
10159 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10160 vrf = NULL;
10161 } else if (argv_find(argv, argc, "view", &idx)) {
10162 /* [<view> VIEWVRFNAME] */
10163 vrf = argv[idx + 1]->arg;
10164 idx += 2;
10165 }
10166
10167 prefix = argv[argc - 1]->arg;
10168
10169 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10170 }
10171
10172 DEFUN (clear_bgp_ipv6_safi_prefix,
10173 clear_bgp_ipv6_safi_prefix_cmd,
10174 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10175 CLEAR_STR
10176 IP_STR
10177 BGP_STR
10178 BGP_AF_STR
10179 BGP_SAFI_HELP_STR
10180 "Clear bestpath and re-advertise\n"
10181 "IPv6 prefix\n")
10182 {
10183 int idx_safi = 0;
10184 int idx_ipv6_prefix = 0;
10185 safi_t safi = SAFI_UNICAST;
10186 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10187 argv[idx_ipv6_prefix]->arg : NULL;
10188
10189 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10190 return bgp_clear_prefix(
10191 vty, NULL, prefix, AFI_IP6,
10192 safi, NULL);
10193 }
10194
10195 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10196 clear_bgp_instance_ipv6_safi_prefix_cmd,
10197 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10198 CLEAR_STR
10199 IP_STR
10200 BGP_STR
10201 BGP_INSTANCE_HELP_STR
10202 BGP_AF_STR
10203 BGP_SAFI_HELP_STR
10204 "Clear bestpath and re-advertise\n"
10205 "IPv6 prefix\n")
10206 {
10207 int idx_safi = 0;
10208 int idx_vrfview = 0;
10209 int idx_ipv6_prefix = 0;
10210 safi_t safi = SAFI_UNICAST;
10211 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10212 argv[idx_ipv6_prefix]->arg : NULL;
10213 char *vrfview = NULL;
10214
10215 /* [<view|vrf> VIEWVRFNAME] */
10216 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10217 vrfview = argv[idx_vrfview + 1]->arg;
10218 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10219 vrfview = NULL;
10220 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10221 /* [<view> VIEWVRFNAME] */
10222 vrfview = argv[idx_vrfview + 1]->arg;
10223 }
10224 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10225
10226 return bgp_clear_prefix(
10227 vty, vrfview, prefix,
10228 AFI_IP6, safi, NULL);
10229 }
10230
10231 DEFUN (show_bgp_views,
10232 show_bgp_views_cmd,
10233 "show [ip] bgp views",
10234 SHOW_STR
10235 IP_STR
10236 BGP_STR
10237 "Show the defined BGP views\n")
10238 {
10239 struct list *inst = bm->bgp;
10240 struct listnode *node;
10241 struct bgp *bgp;
10242
10243 vty_out(vty, "Defined BGP views:\n");
10244 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10245 /* Skip VRFs. */
10246 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10247 continue;
10248 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10249 bgp->as);
10250 }
10251
10252 return CMD_SUCCESS;
10253 }
10254
10255 static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10256 int *peers_estbd)
10257 {
10258 struct peer *peer;
10259 struct listnode *node;
10260
10261 *peers_cfgd = *peers_estbd = 0;
10262 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10263 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10264 continue;
10265 (*peers_cfgd)++;
10266 if (peer_established(peer))
10267 (*peers_estbd)++;
10268 }
10269 }
10270
10271 static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10272 const char *type)
10273 {
10274 int peers_cfg, peers_estb;
10275
10276 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10277
10278 if (json) {
10279 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10280 ? -1
10281 : (int64_t)bgp->vrf_id;
10282 json_object_string_add(json, "type", type);
10283 json_object_int_add(json, "vrfId", vrf_id_ui);
10284 json_object_string_addf(json, "routerId", "%pI4",
10285 &bgp->router_id);
10286 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10287 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10288 json_object_int_add(json, "l3vni", bgp->l3vni);
10289 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10290 json_object_string_add(
10291 json, "interface",
10292 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10293 }
10294 }
10295
10296 static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10297 json_object *json, const char *name,
10298 const char *type, bool use_vrf)
10299 {
10300 int peers_cfg, peers_estb;
10301
10302 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10303
10304 if (use_vrf) {
10305 if (json) {
10306 print_bgp_vrfs(bgp, vty, json, type);
10307 } else {
10308 vty_out(vty, "BGP instance %s VRF id %d\n",
10309 bgp->name_pretty,
10310 bgp->vrf_id == VRF_UNKNOWN ? -1
10311 : (int)bgp->vrf_id);
10312 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10313 vty_out(vty,
10314 "Num Configured Peers %d, Established %d\n",
10315 peers_cfg, peers_estb);
10316 if (bgp->l3vni) {
10317 vty_out(vty,
10318 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10319 bgp->l3vni,
10320 ifindex2ifname(bgp->l3vni_svi_ifindex,
10321 bgp->vrf_id),
10322 &bgp->rmac);
10323 }
10324 }
10325 } else {
10326 if (json) {
10327 print_bgp_vrfs(bgp, vty, json, type);
10328 } else {
10329 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10330 type,
10331 bgp->vrf_id == VRF_UNKNOWN ? -1
10332 : (int)bgp->vrf_id,
10333 &bgp->router_id, peers_cfg, peers_estb, name);
10334 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10335 bgp->l3vni, &bgp->rmac,
10336 ifindex2ifname(bgp->l3vni_svi_ifindex,
10337 bgp->vrf_id));
10338 }
10339 }
10340
10341 return CMD_SUCCESS;
10342 }
10343
10344 DEFPY (show_bgp_vrfs,
10345 show_bgp_vrfs_cmd,
10346 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10347 SHOW_STR
10348 IP_STR
10349 BGP_STR
10350 "Show BGP VRFs\n"
10351 "Specific VRF name\n"
10352 JSON_STR)
10353 {
10354 struct list *inst = bm->bgp;
10355 struct listnode *node;
10356 struct bgp *bgp;
10357 bool uj = use_json(argc, argv);
10358 json_object *json = NULL;
10359 json_object *json_vrfs = NULL;
10360 json_object *json_vrf = NULL;
10361 int count = 0;
10362 const char *name = vrf_name;
10363 const char *type;
10364
10365 if (uj)
10366 json = json_object_new_object();
10367
10368 if (name) {
10369 if (strmatch(name, VRF_DEFAULT_NAME)) {
10370 bgp = bgp_get_default();
10371 type = "DFLT";
10372 } else {
10373 bgp = bgp_lookup_by_name(name);
10374 type = "VRF";
10375 }
10376 if (!bgp) {
10377 if (uj)
10378 vty_json(vty, json);
10379 else
10380 vty_out(vty,
10381 "%% Specified BGP instance not found\n");
10382
10383 return CMD_WARNING;
10384 }
10385 }
10386
10387 if (vrf_name) {
10388 if (uj)
10389 json_vrf = json_object_new_object();
10390
10391 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10392 true);
10393
10394 if (uj) {
10395 json_object_object_add(json, name, json_vrf);
10396 vty_json(vty, json);
10397 }
10398
10399 return CMD_SUCCESS;
10400 }
10401
10402 if (uj)
10403 json_vrfs = json_object_new_object();
10404
10405 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10406 const char *name;
10407
10408 /* Skip Views. */
10409 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10410 continue;
10411
10412 count++;
10413 if (!uj && count == 1) {
10414 vty_out(vty,
10415 "%4s %-5s %-16s %9s %10s %-37s\n",
10416 "Type", "Id", "routerId", "#PeersCfg",
10417 "#PeersEstb", "Name");
10418 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10419 "L3-VNI", "RouterMAC", "Interface");
10420 }
10421 if (uj)
10422 json_vrf = json_object_new_object();
10423
10424 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10425 name = VRF_DEFAULT_NAME;
10426 type = "DFLT";
10427 } else {
10428 name = bgp->name;
10429 type = "VRF";
10430 }
10431
10432 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10433 false);
10434
10435 if (uj)
10436 json_object_object_add(json_vrfs, name, json_vrf);
10437 }
10438
10439 if (uj) {
10440 json_object_object_add(json, "vrfs", json_vrfs);
10441 json_object_int_add(json, "totalVrfs", count);
10442 vty_json(vty, json);
10443 } else {
10444 if (count)
10445 vty_out(vty,
10446 "\nTotal number of VRFs (including default): %d\n",
10447 count);
10448 }
10449
10450 return CMD_SUCCESS;
10451 }
10452
10453 DEFUN (show_bgp_mac_hash,
10454 show_bgp_mac_hash_cmd,
10455 "show bgp mac hash",
10456 SHOW_STR
10457 BGP_STR
10458 "Mac Address\n"
10459 "Mac Address database\n")
10460 {
10461 bgp_mac_dump_table(vty);
10462
10463 return CMD_SUCCESS;
10464 }
10465
10466 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10467 {
10468 struct vty *vty = (struct vty *)args;
10469 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10470
10471 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10472 }
10473
10474 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10475 {
10476 vty_out(vty, "self nexthop database:\n");
10477 bgp_nexthop_show_address_hash(vty, bgp);
10478
10479 vty_out(vty, "Tunnel-ip database:\n");
10480 hash_iterate(bgp->tip_hash,
10481 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10482 vty);
10483 }
10484
10485 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10486 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10487 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10488 "martian next-hops\n"
10489 "martian next-hop database\n")
10490 {
10491 struct bgp *bgp = NULL;
10492 int idx = 0;
10493 char *name = NULL;
10494
10495 /* [<vrf> VIEWVRFNAME] */
10496 if (argv_find(argv, argc, "vrf", &idx)) {
10497 name = argv[idx + 1]->arg;
10498 if (name && strmatch(name, VRF_DEFAULT_NAME))
10499 name = NULL;
10500 } else if (argv_find(argv, argc, "view", &idx))
10501 /* [<view> VIEWVRFNAME] */
10502 name = argv[idx + 1]->arg;
10503 if (name)
10504 bgp = bgp_lookup_by_name(name);
10505 else
10506 bgp = bgp_get_default();
10507
10508 if (!bgp) {
10509 vty_out(vty, "%% No BGP process is configured\n");
10510 return CMD_WARNING;
10511 }
10512 bgp_show_martian_nexthops(vty, bgp);
10513
10514 return CMD_SUCCESS;
10515 }
10516
10517 DEFUN (show_bgp_memory,
10518 show_bgp_memory_cmd,
10519 "show [ip] bgp memory",
10520 SHOW_STR
10521 IP_STR
10522 BGP_STR
10523 "Global BGP memory statistics\n")
10524 {
10525 char memstrbuf[MTYPE_MEMSTR_LEN];
10526 unsigned long count;
10527
10528 /* RIB related usage stats */
10529 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10530 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10531 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10532 count * sizeof(struct bgp_dest)));
10533
10534 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10535 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10537 count * sizeof(struct bgp_path_info)));
10538 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10539 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10540 count,
10541 mtype_memstr(
10542 memstrbuf, sizeof(memstrbuf),
10543 count * sizeof(struct bgp_path_info_extra)));
10544
10545 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10546 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10547 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10548 count * sizeof(struct bgp_static)));
10549
10550 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10551 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10552 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10553 count * sizeof(struct bpacket)));
10554
10555 /* Adj-In/Out */
10556 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10557 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10558 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10559 count * sizeof(struct bgp_adj_in)));
10560 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10561 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10562 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10563 count * sizeof(struct bgp_adj_out)));
10564
10565 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10566 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10567 count,
10568 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10569 count * sizeof(struct bgp_nexthop_cache)));
10570
10571 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10572 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10573 count,
10574 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10575 count * sizeof(struct bgp_damp_info)));
10576
10577 /* Attributes */
10578 count = attr_count();
10579 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10580 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10581 count * sizeof(struct attr)));
10582
10583 if ((count = attr_unknown_count()))
10584 vty_out(vty, "%ld unknown attributes\n", count);
10585
10586 /* AS_PATH attributes */
10587 count = aspath_count();
10588 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10589 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10590 count * sizeof(struct aspath)));
10591
10592 count = mtype_stats_alloc(MTYPE_AS_SEG);
10593 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10594 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10595 count * sizeof(struct assegment)));
10596
10597 /* Other attributes */
10598 if ((count = community_count()))
10599 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10600 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10601 count * sizeof(struct community)));
10602 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10603 vty_out(vty,
10604 "%ld BGP ext-community entries, using %s of memory\n",
10605 count,
10606 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10607 count * sizeof(struct ecommunity)));
10608 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10609 vty_out(vty,
10610 "%ld BGP large-community entries, using %s of memory\n",
10611 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10612 count * sizeof(struct lcommunity)));
10613
10614 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10615 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10616 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10617 count * sizeof(struct cluster_list)));
10618
10619 /* Peer related usage */
10620 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10621 vty_out(vty, "%ld peers, using %s of memory\n", count,
10622 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10623 count * sizeof(struct peer)));
10624
10625 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10626 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10627 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10628 count * sizeof(struct peer_group)));
10629
10630 /* Other */
10631 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10632 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10633 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10634 count * sizeof(regex_t)));
10635 return CMD_SUCCESS;
10636 }
10637
10638 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10639 {
10640 json_object *bestpath = json_object_new_object();
10641
10642 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10643 json_object_string_add(bestpath, "asPath", "ignore");
10644
10645 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10646 json_object_string_add(bestpath, "asPath", "confed");
10647
10648 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10649 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10650 json_object_string_add(bestpath, "multiPathRelax",
10651 "as-set");
10652 else
10653 json_object_string_add(bestpath, "multiPathRelax",
10654 "true");
10655 } else
10656 json_object_string_add(bestpath, "multiPathRelax", "false");
10657
10658 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10659 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10660
10661 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10662 json_object_string_add(bestpath, "compareRouterId", "true");
10663 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10664 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10665 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10666 json_object_string_add(bestpath, "med", "confed");
10667 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10668 json_object_string_add(bestpath, "med",
10669 "missing-as-worst");
10670 else
10671 json_object_string_add(bestpath, "med", "true");
10672 }
10673
10674 json_object_object_add(json, "bestPath", bestpath);
10675 }
10676
10677 /* Print the error code/subcode for why the peer is down */
10678 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10679 json_object *json_peer, bool use_json)
10680 {
10681 const char *code_str;
10682 const char *subcode_str;
10683
10684 if (use_json) {
10685 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10686 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10687 char errorcodesubcode_hexstr[5];
10688 char errorcodesubcode_str[256];
10689
10690 code_str = bgp_notify_code_str(peer->notify.code);
10691 subcode_str = bgp_notify_subcode_str(
10692 peer->notify.code,
10693 peer->notify.subcode);
10694
10695 snprintf(errorcodesubcode_hexstr,
10696 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10697 peer->notify.code, peer->notify.subcode);
10698 json_object_string_add(json_peer,
10699 "lastErrorCodeSubcode",
10700 errorcodesubcode_hexstr);
10701 snprintf(errorcodesubcode_str, 255, "%s%s",
10702 code_str, subcode_str);
10703 json_object_string_add(json_peer,
10704 "lastNotificationReason",
10705 errorcodesubcode_str);
10706 json_object_boolean_add(json_peer,
10707 "lastNotificationHardReset",
10708 peer->notify.hard_reset);
10709 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10710 && peer->notify.code == BGP_NOTIFY_CEASE
10711 && (peer->notify.subcode
10712 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10713 || peer->notify.subcode
10714 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10715 && peer->notify.length) {
10716 char msgbuf[1024];
10717 const char *msg_str;
10718
10719 msg_str = bgp_notify_admin_message(
10720 msgbuf, sizeof(msgbuf),
10721 (uint8_t *)peer->notify.data,
10722 peer->notify.length);
10723 if (msg_str)
10724 json_object_string_add(
10725 json_peer,
10726 "lastShutdownDescription",
10727 msg_str);
10728 }
10729
10730 }
10731 json_object_string_add(json_peer, "lastResetDueTo",
10732 peer_down_str[(int)peer->last_reset]);
10733 json_object_int_add(json_peer, "lastResetCode",
10734 peer->last_reset);
10735 } else {
10736 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10737 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10738 code_str = bgp_notify_code_str(peer->notify.code);
10739 subcode_str =
10740 bgp_notify_subcode_str(peer->notify.code,
10741 peer->notify.subcode);
10742 vty_out(vty, " Notification %s (%s%s%s)\n",
10743 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10744 ? "sent"
10745 : "received",
10746 code_str, subcode_str,
10747 peer->notify.hard_reset
10748 ? bgp_notify_subcode_str(
10749 BGP_NOTIFY_CEASE,
10750 BGP_NOTIFY_CEASE_HARD_RESET)
10751 : "");
10752 } else {
10753 vty_out(vty, " %s\n",
10754 peer_down_str[(int)peer->last_reset]);
10755 }
10756 }
10757 }
10758
10759 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10760 safi_t safi)
10761 {
10762 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10763 }
10764
10765 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10766 struct peer *peer, json_object *json_peer,
10767 int max_neighbor_width, bool use_json)
10768 {
10769 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10770 int len;
10771
10772 if (use_json) {
10773 if (peer_dynamic_neighbor(peer))
10774 json_object_boolean_true_add(json_peer,
10775 "dynamicPeer");
10776 if (peer->hostname)
10777 json_object_string_add(json_peer, "hostname",
10778 peer->hostname);
10779
10780 if (peer->domainname)
10781 json_object_string_add(json_peer, "domainname",
10782 peer->domainname);
10783 json_object_int_add(json_peer, "connectionsEstablished",
10784 peer->established);
10785 json_object_int_add(json_peer, "connectionsDropped",
10786 peer->dropped);
10787 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10788 use_json, json_peer);
10789 if (peer_established(peer))
10790 json_object_string_add(json_peer, "lastResetDueTo",
10791 "AFI/SAFI Not Negotiated");
10792 else
10793 bgp_show_peer_reset(NULL, peer, json_peer, true);
10794 } else {
10795 dn_flag[1] = '\0';
10796 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10797 if (peer->hostname
10798 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10799 len = vty_out(vty, "%s%s(%s)", dn_flag,
10800 peer->hostname, peer->host);
10801 else
10802 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10803
10804 /* pad the neighbor column with spaces */
10805 if (len < max_neighbor_width)
10806 vty_out(vty, "%*s", max_neighbor_width - len,
10807 " ");
10808 vty_out(vty, "%7d %7d %9s", peer->established,
10809 peer->dropped,
10810 peer_uptime(peer->uptime, timebuf,
10811 BGP_UPTIME_LEN, 0, NULL));
10812 if (peer_established(peer))
10813 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10814 else
10815 bgp_show_peer_reset(vty, peer, NULL,
10816 false);
10817 }
10818 }
10819
10820 /* Strip peer's description to the given size. */
10821 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10822 {
10823 static char stripped[BUFSIZ];
10824 uint32_t i = 0;
10825 uint32_t last_space = 0;
10826
10827 while (i < size) {
10828 if (*(desc + i) == 0) {
10829 stripped[i] = '\0';
10830 return stripped;
10831 }
10832 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10833 last_space = i;
10834 stripped[i] = *(desc + i);
10835 i++;
10836 }
10837
10838 if (last_space > size)
10839 stripped[size + 1] = '\0';
10840 else
10841 stripped[last_space] = '\0';
10842
10843 return stripped;
10844 }
10845
10846 /* Determine whether var peer should be filtered out of the summary. */
10847 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10848 struct peer *fpeer, int as_type,
10849 as_t as)
10850 {
10851
10852 /* filter neighbor XXXX */
10853 if (fpeer && fpeer != peer)
10854 return true;
10855
10856 /* filter remote-as (internal|external) */
10857 if (as_type != AS_UNSPECIFIED) {
10858 if (peer->as_type == AS_SPECIFIED) {
10859 if (as_type == AS_INTERNAL) {
10860 if (peer->as != peer->local_as)
10861 return true;
10862 } else if (peer->as == peer->local_as)
10863 return true;
10864 } else if (as_type != peer->as_type)
10865 return true;
10866 } else if (as && as != peer->as) /* filter remote-as XXX */
10867 return true;
10868
10869 return false;
10870 }
10871
10872 /* Show BGP peer's summary information.
10873 *
10874 * Peer's description is stripped according to if `wide` option is given
10875 * or not.
10876 *
10877 * When adding new columns to `show bgp summary` output, please make
10878 * sure `Desc` is the lastest column to show because it can contain
10879 * whitespaces and the whole output will be tricky.
10880 */
10881 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10882 struct peer *fpeer, int as_type, as_t as,
10883 uint16_t show_flags)
10884 {
10885 struct peer *peer;
10886 struct listnode *node, *nnode;
10887 unsigned int count = 0, dn_count = 0;
10888 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10889 char neighbor_buf[VTY_BUFSIZ];
10890 int neighbor_col_default_width = 16;
10891 int len, failed_count = 0;
10892 unsigned int filtered_count = 0;
10893 int max_neighbor_width = 0;
10894 int pfx_rcd_safi;
10895 json_object *json = NULL;
10896 json_object *json_peer = NULL;
10897 json_object *json_peers = NULL;
10898 struct peer_af *paf;
10899 struct bgp_filter *filter;
10900 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10901 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10902 bool show_established =
10903 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10904 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10905 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10906
10907 /* labeled-unicast routes are installed in the unicast table so in order
10908 * to
10909 * display the correct PfxRcd value we must look at SAFI_UNICAST
10910 */
10911
10912 if (safi == SAFI_LABELED_UNICAST)
10913 pfx_rcd_safi = SAFI_UNICAST;
10914 else
10915 pfx_rcd_safi = safi;
10916
10917 if (use_json) {
10918 json = json_object_new_object();
10919 json_peers = json_object_new_object();
10920 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10921 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10922 as_type, as)) {
10923 filtered_count++;
10924 count++;
10925 continue;
10926 }
10927
10928 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10929 continue;
10930
10931 if (peer->afc[afi][safi]) {
10932 /* See if we have at least a single failed peer */
10933 if (bgp_has_peer_failed(peer, afi, safi))
10934 failed_count++;
10935 count++;
10936 }
10937 if (peer_dynamic_neighbor(peer))
10938 dn_count++;
10939 }
10940
10941 } else {
10942 /* Loop over all neighbors that will be displayed to determine
10943 * how many
10944 * characters are needed for the Neighbor column
10945 */
10946 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10947 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10948 as_type, as)) {
10949 filtered_count++;
10950 count++;
10951 continue;
10952 }
10953
10954 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10955 continue;
10956
10957 if (peer->afc[afi][safi]) {
10958 memset(dn_flag, '\0', sizeof(dn_flag));
10959 if (peer_dynamic_neighbor(peer))
10960 dn_flag[0] = '*';
10961
10962 if (peer->hostname
10963 && CHECK_FLAG(bgp->flags,
10964 BGP_FLAG_SHOW_HOSTNAME))
10965 snprintf(neighbor_buf,
10966 sizeof(neighbor_buf),
10967 "%s%s(%s) ", dn_flag,
10968 peer->hostname, peer->host);
10969 else
10970 snprintf(neighbor_buf,
10971 sizeof(neighbor_buf), "%s%s ",
10972 dn_flag, peer->host);
10973
10974 len = strlen(neighbor_buf);
10975
10976 if (len > max_neighbor_width)
10977 max_neighbor_width = len;
10978
10979 /* See if we have at least a single failed peer */
10980 if (bgp_has_peer_failed(peer, afi, safi))
10981 failed_count++;
10982 count++;
10983 }
10984 }
10985
10986 /* Originally we displayed the Neighbor column as 16
10987 * characters wide so make that the default
10988 */
10989 if (max_neighbor_width < neighbor_col_default_width)
10990 max_neighbor_width = neighbor_col_default_width;
10991 }
10992
10993 if (show_failed && !failed_count) {
10994 if (use_json) {
10995 json_object_int_add(json, "failedPeersCount", 0);
10996 json_object_int_add(json, "dynamicPeers", dn_count);
10997 json_object_int_add(json, "totalPeers", count);
10998
10999 vty_json(vty, json);
11000 } else {
11001 vty_out(vty, "%% No failed BGP neighbors found\n");
11002 }
11003 return CMD_SUCCESS;
11004 }
11005
11006 count = 0; /* Reset the value as its used again */
11007 filtered_count = 0;
11008 dn_count = 0;
11009 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11010 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11011 continue;
11012
11013 if (!peer->afc[afi][safi])
11014 continue;
11015
11016 if (!count) {
11017 unsigned long ents;
11018 char memstrbuf[MTYPE_MEMSTR_LEN];
11019 int64_t vrf_id_ui;
11020
11021 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11022 ? -1
11023 : (int64_t)bgp->vrf_id;
11024
11025 /* Usage summary and header */
11026 if (use_json) {
11027 json_object_string_addf(json, "routerId",
11028 "%pI4",
11029 &bgp->router_id);
11030 json_object_int_add(json, "as", bgp->as);
11031 json_object_int_add(json, "vrfId", vrf_id_ui);
11032 json_object_string_add(
11033 json, "vrfName",
11034 (bgp->inst_type
11035 == BGP_INSTANCE_TYPE_DEFAULT)
11036 ? VRF_DEFAULT_NAME
11037 : bgp->name);
11038 } else {
11039 vty_out(vty,
11040 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11041 &bgp->router_id, bgp->as,
11042 bgp->vrf_id == VRF_UNKNOWN
11043 ? -1
11044 : (int)bgp->vrf_id);
11045 vty_out(vty, "\n");
11046 }
11047
11048 if (bgp_update_delay_configured(bgp)) {
11049 if (use_json) {
11050 json_object_int_add(
11051 json, "updateDelayLimit",
11052 bgp->v_update_delay);
11053
11054 if (bgp->v_update_delay
11055 != bgp->v_establish_wait)
11056 json_object_int_add(
11057 json,
11058 "updateDelayEstablishWait",
11059 bgp->v_establish_wait);
11060
11061 if (bgp_update_delay_active(bgp)) {
11062 json_object_string_add(
11063 json,
11064 "updateDelayFirstNeighbor",
11065 bgp->update_delay_begin_time);
11066 json_object_boolean_true_add(
11067 json,
11068 "updateDelayInProgress");
11069 } else {
11070 if (bgp->update_delay_over) {
11071 json_object_string_add(
11072 json,
11073 "updateDelayFirstNeighbor",
11074 bgp->update_delay_begin_time);
11075 json_object_string_add(
11076 json,
11077 "updateDelayBestpathResumed",
11078 bgp->update_delay_end_time);
11079 json_object_string_add(
11080 json,
11081 "updateDelayZebraUpdateResume",
11082 bgp->update_delay_zebra_resume_time);
11083 json_object_string_add(
11084 json,
11085 "updateDelayPeerUpdateResume",
11086 bgp->update_delay_peers_resume_time);
11087 }
11088 }
11089 } else {
11090 vty_out(vty,
11091 "Read-only mode update-delay limit: %d seconds\n",
11092 bgp->v_update_delay);
11093 if (bgp->v_update_delay
11094 != bgp->v_establish_wait)
11095 vty_out(vty,
11096 " Establish wait: %d seconds\n",
11097 bgp->v_establish_wait);
11098
11099 if (bgp_update_delay_active(bgp)) {
11100 vty_out(vty,
11101 " First neighbor established: %s\n",
11102 bgp->update_delay_begin_time);
11103 vty_out(vty,
11104 " Delay in progress\n");
11105 } else {
11106 if (bgp->update_delay_over) {
11107 vty_out(vty,
11108 " First neighbor established: %s\n",
11109 bgp->update_delay_begin_time);
11110 vty_out(vty,
11111 " Best-paths resumed: %s\n",
11112 bgp->update_delay_end_time);
11113 vty_out(vty,
11114 " zebra update resumed: %s\n",
11115 bgp->update_delay_zebra_resume_time);
11116 vty_out(vty,
11117 " peers update resumed: %s\n",
11118 bgp->update_delay_peers_resume_time);
11119 }
11120 }
11121 }
11122 }
11123
11124 if (use_json) {
11125 if (bgp_maxmed_onstartup_configured(bgp)
11126 && bgp->maxmed_active)
11127 json_object_boolean_true_add(
11128 json, "maxMedOnStartup");
11129 if (bgp->v_maxmed_admin)
11130 json_object_boolean_true_add(
11131 json, "maxMedAdministrative");
11132
11133 json_object_int_add(
11134 json, "tableVersion",
11135 bgp_table_version(bgp->rib[afi][safi]));
11136
11137 ents = bgp_table_count(bgp->rib[afi][safi]);
11138 json_object_int_add(json, "ribCount", ents);
11139 json_object_int_add(
11140 json, "ribMemory",
11141 ents * sizeof(struct bgp_dest));
11142
11143 ents = bgp->af_peer_count[afi][safi];
11144 json_object_int_add(json, "peerCount", ents);
11145 json_object_int_add(json, "peerMemory",
11146 ents * sizeof(struct peer));
11147
11148 if ((ents = listcount(bgp->group))) {
11149 json_object_int_add(
11150 json, "peerGroupCount", ents);
11151 json_object_int_add(
11152 json, "peerGroupMemory",
11153 ents * sizeof(struct
11154 peer_group));
11155 }
11156
11157 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11158 BGP_CONFIG_DAMPENING))
11159 json_object_boolean_true_add(
11160 json, "dampeningEnabled");
11161 } else {
11162 if (!show_terse) {
11163 if (bgp_maxmed_onstartup_configured(bgp)
11164 && bgp->maxmed_active)
11165 vty_out(vty,
11166 "Max-med on-startup active\n");
11167 if (bgp->v_maxmed_admin)
11168 vty_out(vty,
11169 "Max-med administrative active\n");
11170
11171 vty_out(vty,
11172 "BGP table version %" PRIu64
11173 "\n",
11174 bgp_table_version(
11175 bgp->rib[afi][safi]));
11176
11177 ents = bgp_table_count(
11178 bgp->rib[afi][safi]);
11179 vty_out(vty,
11180 "RIB entries %ld, using %s of memory\n",
11181 ents,
11182 mtype_memstr(
11183 memstrbuf,
11184 sizeof(memstrbuf),
11185 ents
11186 * sizeof(
11187 struct
11188 bgp_dest)));
11189
11190 /* Peer related usage */
11191 ents = bgp->af_peer_count[afi][safi];
11192 vty_out(vty,
11193 "Peers %ld, using %s of memory\n",
11194 ents,
11195 mtype_memstr(
11196 memstrbuf,
11197 sizeof(memstrbuf),
11198 ents
11199 * sizeof(
11200 struct
11201 peer)));
11202
11203 if ((ents = listcount(bgp->group)))
11204 vty_out(vty,
11205 "Peer groups %ld, using %s of memory\n",
11206 ents,
11207 mtype_memstr(
11208 memstrbuf,
11209 sizeof(memstrbuf),
11210 ents
11211 * sizeof(
11212 struct
11213 peer_group)));
11214
11215 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11216 BGP_CONFIG_DAMPENING))
11217 vty_out(vty,
11218 "Dampening enabled.\n");
11219 }
11220 if (show_failed) {
11221 vty_out(vty, "\n");
11222
11223 /* Subtract 8 here because 'Neighbor' is
11224 * 8 characters */
11225 vty_out(vty, "Neighbor");
11226 vty_out(vty, "%*s",
11227 max_neighbor_width - 8, " ");
11228 vty_out(vty,
11229 BGP_SHOW_SUMMARY_HEADER_FAILED);
11230 }
11231 }
11232 }
11233
11234 paf = peer_af_find(peer, afi, safi);
11235 filter = &peer->filter[afi][safi];
11236
11237 count++;
11238 /* Works for both failed & successful cases */
11239 if (peer_dynamic_neighbor(peer))
11240 dn_count++;
11241
11242 if (use_json) {
11243 json_peer = NULL;
11244 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11245 as_type, as)) {
11246 filtered_count++;
11247 continue;
11248 }
11249 if (show_failed &&
11250 bgp_has_peer_failed(peer, afi, safi)) {
11251 json_peer = json_object_new_object();
11252 bgp_show_failed_summary(vty, bgp, peer,
11253 json_peer, 0, use_json);
11254 } else if (!show_failed) {
11255 if (show_established
11256 && bgp_has_peer_failed(peer, afi, safi)) {
11257 filtered_count++;
11258 continue;
11259 }
11260
11261 json_peer = json_object_new_object();
11262 if (peer_dynamic_neighbor(peer)) {
11263 json_object_boolean_true_add(json_peer,
11264 "dynamicPeer");
11265 }
11266
11267 if (peer->hostname)
11268 json_object_string_add(json_peer, "hostname",
11269 peer->hostname);
11270
11271 if (peer->domainname)
11272 json_object_string_add(json_peer, "domainname",
11273 peer->domainname);
11274
11275 json_object_int_add(json_peer, "remoteAs", peer->as);
11276 json_object_int_add(
11277 json_peer, "localAs",
11278 peer->change_local_as
11279 ? peer->change_local_as
11280 : peer->local_as);
11281 json_object_int_add(json_peer, "version", 4);
11282 json_object_int_add(json_peer, "msgRcvd",
11283 PEER_TOTAL_RX(peer));
11284 json_object_int_add(json_peer, "msgSent",
11285 PEER_TOTAL_TX(peer));
11286
11287 atomic_size_t outq_count, inq_count;
11288 outq_count = atomic_load_explicit(
11289 &peer->obuf->count,
11290 memory_order_relaxed);
11291 inq_count = atomic_load_explicit(
11292 &peer->ibuf->count,
11293 memory_order_relaxed);
11294
11295 json_object_int_add(json_peer, "tableVersion",
11296 peer->version[afi][safi]);
11297 json_object_int_add(json_peer, "outq",
11298 outq_count);
11299 json_object_int_add(json_peer, "inq",
11300 inq_count);
11301 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11302 use_json, json_peer);
11303
11304 json_object_int_add(json_peer, "pfxRcd",
11305 peer->pcount[afi][pfx_rcd_safi]);
11306
11307 if (paf && PAF_SUBGRP(paf))
11308 json_object_int_add(
11309 json_peer, "pfxSnt",
11310 (PAF_SUBGRP(paf))->scount);
11311 else
11312 json_object_int_add(json_peer, "pfxSnt",
11313 0);
11314
11315 /* BGP FSM state */
11316 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11317 || CHECK_FLAG(peer->bgp->flags,
11318 BGP_FLAG_SHUTDOWN))
11319 json_object_string_add(json_peer,
11320 "state",
11321 "Idle (Admin)");
11322 else if (peer->afc_recv[afi][safi])
11323 json_object_string_add(
11324 json_peer, "state",
11325 lookup_msg(bgp_status_msg,
11326 peer->status, NULL));
11327 else if (CHECK_FLAG(
11328 peer->sflags,
11329 PEER_STATUS_PREFIX_OVERFLOW))
11330 json_object_string_add(json_peer,
11331 "state",
11332 "Idle (PfxCt)");
11333 else
11334 json_object_string_add(
11335 json_peer, "state",
11336 lookup_msg(bgp_status_msg,
11337 peer->status, NULL));
11338
11339 /* BGP peer state */
11340 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11341 || CHECK_FLAG(peer->bgp->flags,
11342 BGP_FLAG_SHUTDOWN))
11343 json_object_string_add(json_peer,
11344 "peerState",
11345 "Admin");
11346 else if (CHECK_FLAG(
11347 peer->sflags,
11348 PEER_STATUS_PREFIX_OVERFLOW))
11349 json_object_string_add(json_peer,
11350 "peerState",
11351 "PfxCt");
11352 else if (CHECK_FLAG(peer->flags,
11353 PEER_FLAG_PASSIVE))
11354 json_object_string_add(json_peer,
11355 "peerState",
11356 "Passive");
11357 else if (CHECK_FLAG(peer->sflags,
11358 PEER_STATUS_NSF_WAIT))
11359 json_object_string_add(json_peer,
11360 "peerState",
11361 "NSF passive");
11362 else if (CHECK_FLAG(
11363 peer->bgp->flags,
11364 BGP_FLAG_EBGP_REQUIRES_POLICY)
11365 && (!bgp_inbound_policy_exists(peer,
11366 filter)
11367 || !bgp_outbound_policy_exists(
11368 peer, filter)))
11369 json_object_string_add(json_peer,
11370 "peerState",
11371 "Policy");
11372 else
11373 json_object_string_add(
11374 json_peer, "peerState", "OK");
11375
11376 json_object_int_add(json_peer, "connectionsEstablished",
11377 peer->established);
11378 json_object_int_add(json_peer, "connectionsDropped",
11379 peer->dropped);
11380 if (peer->desc)
11381 json_object_string_add(
11382 json_peer, "desc", peer->desc);
11383 }
11384 /* Avoid creating empty peer dicts in JSON */
11385 if (json_peer == NULL)
11386 continue;
11387
11388 if (peer->conf_if)
11389 json_object_string_add(json_peer, "idType",
11390 "interface");
11391 else if (peer->su.sa.sa_family == AF_INET)
11392 json_object_string_add(json_peer, "idType",
11393 "ipv4");
11394 else if (peer->su.sa.sa_family == AF_INET6)
11395 json_object_string_add(json_peer, "idType",
11396 "ipv6");
11397 json_object_object_add(json_peers, peer->host,
11398 json_peer);
11399 } else {
11400 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11401 as_type, as)) {
11402 filtered_count++;
11403 continue;
11404 }
11405 if (show_failed &&
11406 bgp_has_peer_failed(peer, afi, safi)) {
11407 bgp_show_failed_summary(vty, bgp, peer, NULL,
11408 max_neighbor_width,
11409 use_json);
11410 } else if (!show_failed) {
11411 if (show_established
11412 && bgp_has_peer_failed(peer, afi, safi)) {
11413 filtered_count++;
11414 continue;
11415 }
11416
11417 if ((count - filtered_count) == 1) {
11418 /* display headline before the first
11419 * neighbor line */
11420 vty_out(vty, "\n");
11421
11422 /* Subtract 8 here because 'Neighbor' is
11423 * 8 characters */
11424 vty_out(vty, "Neighbor");
11425 vty_out(vty, "%*s",
11426 max_neighbor_width - 8, " ");
11427 vty_out(vty,
11428 show_wide
11429 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11430 : BGP_SHOW_SUMMARY_HEADER_ALL);
11431 }
11432
11433 memset(dn_flag, '\0', sizeof(dn_flag));
11434 if (peer_dynamic_neighbor(peer)) {
11435 dn_flag[0] = '*';
11436 }
11437
11438 if (peer->hostname
11439 && CHECK_FLAG(bgp->flags,
11440 BGP_FLAG_SHOW_HOSTNAME))
11441 len = vty_out(vty, "%s%s(%s)", dn_flag,
11442 peer->hostname,
11443 peer->host);
11444 else
11445 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11446
11447 /* pad the neighbor column with spaces */
11448 if (len < max_neighbor_width)
11449 vty_out(vty, "%*s", max_neighbor_width - len,
11450 " ");
11451
11452 atomic_size_t outq_count, inq_count;
11453 outq_count = atomic_load_explicit(
11454 &peer->obuf->count,
11455 memory_order_relaxed);
11456 inq_count = atomic_load_explicit(
11457 &peer->ibuf->count,
11458 memory_order_relaxed);
11459
11460 if (show_wide)
11461 vty_out(vty,
11462 "4 %10u %10u %9u %9u %8" PRIu64
11463 " %4zu %4zu %8s",
11464 peer->as,
11465 peer->change_local_as
11466 ? peer->change_local_as
11467 : peer->local_as,
11468 PEER_TOTAL_RX(peer),
11469 PEER_TOTAL_TX(peer),
11470 peer->version[afi][safi],
11471 inq_count, outq_count,
11472 peer_uptime(peer->uptime,
11473 timebuf,
11474 BGP_UPTIME_LEN, 0,
11475 NULL));
11476 else
11477 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11478 " %4zu %4zu %8s",
11479 peer->as, PEER_TOTAL_RX(peer),
11480 PEER_TOTAL_TX(peer),
11481 peer->version[afi][safi],
11482 inq_count, outq_count,
11483 peer_uptime(peer->uptime,
11484 timebuf,
11485 BGP_UPTIME_LEN, 0,
11486 NULL));
11487
11488 if (peer_established(peer)) {
11489 if (peer->afc_recv[afi][safi]) {
11490 if (CHECK_FLAG(
11491 bgp->flags,
11492 BGP_FLAG_EBGP_REQUIRES_POLICY)
11493 && !bgp_inbound_policy_exists(
11494 peer, filter))
11495 vty_out(vty, " %12s",
11496 "(Policy)");
11497 else
11498 vty_out(vty,
11499 " %12u",
11500 peer->pcount
11501 [afi]
11502 [pfx_rcd_safi]);
11503 } else {
11504 vty_out(vty, " NoNeg");
11505 }
11506
11507 if (paf && PAF_SUBGRP(paf)) {
11508 if (CHECK_FLAG(
11509 bgp->flags,
11510 BGP_FLAG_EBGP_REQUIRES_POLICY)
11511 && !bgp_outbound_policy_exists(
11512 peer, filter))
11513 vty_out(vty, " %8s",
11514 "(Policy)");
11515 else
11516 vty_out(vty,
11517 " %8u",
11518 (PAF_SUBGRP(
11519 paf))
11520 ->scount);
11521 } else {
11522 vty_out(vty, " NoNeg");
11523 }
11524 } else {
11525 if (CHECK_FLAG(peer->flags,
11526 PEER_FLAG_SHUTDOWN)
11527 || CHECK_FLAG(peer->bgp->flags,
11528 BGP_FLAG_SHUTDOWN))
11529 vty_out(vty, " Idle (Admin)");
11530 else if (CHECK_FLAG(
11531 peer->sflags,
11532 PEER_STATUS_PREFIX_OVERFLOW))
11533 vty_out(vty, " Idle (PfxCt)");
11534 else
11535 vty_out(vty, " %12s",
11536 lookup_msg(bgp_status_msg,
11537 peer->status, NULL));
11538
11539 vty_out(vty, " %8u", 0);
11540 }
11541 /* Make sure `Desc` column is the lastest in
11542 * the output.
11543 */
11544 if (peer->desc)
11545 vty_out(vty, " %s",
11546 bgp_peer_description_stripped(
11547 peer->desc,
11548 show_wide ? 64 : 20));
11549 else
11550 vty_out(vty, " N/A");
11551 vty_out(vty, "\n");
11552 }
11553
11554 }
11555 }
11556
11557 if (use_json) {
11558 json_object_object_add(json, "peers", json_peers);
11559 json_object_int_add(json, "failedPeers", failed_count);
11560 json_object_int_add(json, "displayedPeers",
11561 count - filtered_count);
11562 json_object_int_add(json, "totalPeers", count);
11563 json_object_int_add(json, "dynamicPeers", dn_count);
11564
11565 if (!show_failed)
11566 bgp_show_bestpath_json(bgp, json);
11567
11568 vty_json(vty, json);
11569 } else {
11570 if (count) {
11571 if (filtered_count == count)
11572 vty_out(vty, "\n%% No matching neighbor\n");
11573 else {
11574 if (show_failed)
11575 vty_out(vty, "\nDisplayed neighbors %d",
11576 failed_count);
11577 else if (as_type != AS_UNSPECIFIED || as
11578 || fpeer || show_established)
11579 vty_out(vty, "\nDisplayed neighbors %d",
11580 count - filtered_count);
11581
11582 vty_out(vty, "\nTotal number of neighbors %d\n",
11583 count);
11584 }
11585 } else {
11586 vty_out(vty, "No %s neighbor is configured\n",
11587 get_afi_safi_str(afi, safi, false));
11588 }
11589
11590 if (dn_count) {
11591 vty_out(vty, "* - dynamic neighbor\n");
11592 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11593 dn_count, bgp->dynamic_neighbors_limit);
11594 }
11595 }
11596
11597 return CMD_SUCCESS;
11598 }
11599
11600 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11601 int safi, struct peer *fpeer, int as_type,
11602 as_t as, uint16_t show_flags)
11603 {
11604 int is_first = 1;
11605 int afi_wildcard = (afi == AFI_MAX);
11606 int safi_wildcard = (safi == SAFI_MAX);
11607 int is_wildcard = (afi_wildcard || safi_wildcard);
11608 bool nbr_output = false;
11609 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11610
11611 if (use_json && is_wildcard)
11612 vty_out(vty, "{\n");
11613 if (afi_wildcard)
11614 afi = 1; /* AFI_IP */
11615 while (afi < AFI_MAX) {
11616 if (safi_wildcard)
11617 safi = 1; /* SAFI_UNICAST */
11618 while (safi < SAFI_MAX) {
11619 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11620 nbr_output = true;
11621
11622 if (is_wildcard) {
11623 /*
11624 * So limit output to those afi/safi
11625 * pairs that
11626 * actualy have something interesting in
11627 * them
11628 */
11629 if (use_json) {
11630 if (!is_first)
11631 vty_out(vty, ",\n");
11632 else
11633 is_first = 0;
11634
11635 vty_out(vty, "\"%s\":",
11636 get_afi_safi_str(afi,
11637 safi,
11638 true));
11639 } else {
11640 vty_out(vty,
11641 "\n%s Summary (%s):\n",
11642 get_afi_safi_str(afi,
11643 safi,
11644 false),
11645 bgp->name_pretty);
11646 }
11647 }
11648 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11649 as_type, as, show_flags);
11650 }
11651 safi++;
11652 if (!safi_wildcard)
11653 safi = SAFI_MAX;
11654 }
11655 afi++;
11656 if (!afi_wildcard)
11657 afi = AFI_MAX;
11658 }
11659
11660 if (use_json && is_wildcard)
11661 vty_out(vty, "}\n");
11662 else if (!nbr_output) {
11663 if (use_json)
11664 vty_out(vty, "{}\n");
11665 else
11666 vty_out(vty, "%% No BGP neighbors found in %s\n",
11667 bgp->name_pretty);
11668 }
11669 }
11670
11671 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11672 safi_t safi,
11673 const char *neighbor,
11674 int as_type, as_t as,
11675 uint16_t show_flags)
11676 {
11677 struct listnode *node, *nnode;
11678 struct bgp *bgp;
11679 struct peer *fpeer = NULL;
11680 int is_first = 1;
11681 bool nbr_output = false;
11682 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11683
11684 if (use_json)
11685 vty_out(vty, "{\n");
11686
11687 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11688 nbr_output = true;
11689 if (use_json) {
11690 if (!is_first)
11691 vty_out(vty, ",\n");
11692 else
11693 is_first = 0;
11694
11695 vty_out(vty, "\"%s\":",
11696 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11697 ? VRF_DEFAULT_NAME
11698 : bgp->name);
11699 }
11700 if (neighbor) {
11701 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11702 use_json);
11703 if (!fpeer)
11704 continue;
11705 }
11706 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11707 as, show_flags);
11708 }
11709
11710 if (use_json)
11711 vty_out(vty, "}\n");
11712 else if (!nbr_output)
11713 vty_out(vty, "%% BGP instance not found\n");
11714 }
11715
11716 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11717 safi_t safi, const char *neighbor, int as_type,
11718 as_t as, uint16_t show_flags)
11719 {
11720 struct bgp *bgp;
11721 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11722 struct peer *fpeer = NULL;
11723
11724 if (name) {
11725 if (strmatch(name, "all")) {
11726 bgp_show_all_instances_summary_vty(vty, afi, safi,
11727 neighbor, as_type,
11728 as, show_flags);
11729 return CMD_SUCCESS;
11730 } else {
11731 bgp = bgp_lookup_by_name(name);
11732
11733 if (!bgp) {
11734 if (use_json)
11735 vty_out(vty, "{}\n");
11736 else
11737 vty_out(vty,
11738 "%% BGP instance not found\n");
11739 return CMD_WARNING;
11740 }
11741
11742 if (neighbor) {
11743 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11744 use_json);
11745 if (!fpeer)
11746 return CMD_WARNING;
11747 }
11748 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11749 as_type, as, show_flags);
11750 return CMD_SUCCESS;
11751 }
11752 }
11753
11754 bgp = bgp_get_default();
11755
11756 if (bgp) {
11757 if (neighbor) {
11758 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11759 use_json);
11760 if (!fpeer)
11761 return CMD_WARNING;
11762 }
11763 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11764 as, show_flags);
11765 } else {
11766 if (use_json)
11767 vty_out(vty, "{}\n");
11768 else
11769 vty_out(vty, "%% BGP instance not found\n");
11770 return CMD_WARNING;
11771 }
11772
11773 return CMD_SUCCESS;
11774 }
11775
11776 /* `show [ip] bgp summary' commands. */
11777 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11778 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11779 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11780 "]] [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]",
11781 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11782 BGP_SAFI_WITH_LABEL_HELP_STR
11783 "Display the entries for all address families\n"
11784 "Summary of BGP neighbor status\n"
11785 "Show only sessions in Established state\n"
11786 "Show only sessions not in Established state\n"
11787 "Show only the specified neighbor session\n"
11788 "Neighbor to display information about\n"
11789 "Neighbor to display information about\n"
11790 "Neighbor on BGP configured interface\n"
11791 "Show only the specified remote AS sessions\n"
11792 "AS number\n"
11793 "Internal (iBGP) AS sessions\n"
11794 "External (eBGP) AS sessions\n"
11795 "Shorten the information on BGP instances\n"
11796 "Increase table width for longer output\n" JSON_STR)
11797 {
11798 char *vrf = NULL;
11799 afi_t afi = AFI_MAX;
11800 safi_t safi = SAFI_MAX;
11801 as_t as = 0; /* 0 means AS filter not set */
11802 int as_type = AS_UNSPECIFIED;
11803 uint16_t show_flags = 0;
11804
11805 int idx = 0;
11806
11807 /* show [ip] bgp */
11808 if (!all && argv_find(argv, argc, "ip", &idx))
11809 afi = AFI_IP;
11810 /* [<vrf> VIEWVRFNAME] */
11811 if (argv_find(argv, argc, "vrf", &idx)) {
11812 vrf = argv[idx + 1]->arg;
11813 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11814 vrf = NULL;
11815 } else if (argv_find(argv, argc, "view", &idx))
11816 /* [<view> VIEWVRFNAME] */
11817 vrf = argv[idx + 1]->arg;
11818 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11819 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11820 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11821 }
11822
11823 if (argv_find(argv, argc, "failed", &idx))
11824 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11825
11826 if (argv_find(argv, argc, "established", &idx))
11827 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11828
11829 if (argv_find(argv, argc, "remote-as", &idx)) {
11830 if (argv[idx + 1]->arg[0] == 'i')
11831 as_type = AS_INTERNAL;
11832 else if (argv[idx + 1]->arg[0] == 'e')
11833 as_type = AS_EXTERNAL;
11834 else
11835 as = (as_t)atoi(argv[idx + 1]->arg);
11836 }
11837
11838 if (argv_find(argv, argc, "terse", &idx))
11839 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11840
11841 if (argv_find(argv, argc, "wide", &idx))
11842 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11843
11844 if (argv_find(argv, argc, "json", &idx))
11845 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11846
11847 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11848 show_flags);
11849 }
11850
11851 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11852 {
11853 if (for_json)
11854 return get_afi_safi_json_str(afi, safi);
11855 else
11856 return get_afi_safi_vty_str(afi, safi);
11857 }
11858
11859
11860 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11861 afi_t afi, safi_t safi,
11862 uint16_t adv_smcap, uint16_t adv_rmcap,
11863 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11864 bool use_json, json_object *json_pref)
11865 {
11866 /* Send-Mode */
11867 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11868 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11869 if (use_json) {
11870 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11871 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11872 json_object_string_add(json_pref, "sendMode",
11873 "advertisedAndReceived");
11874 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11875 json_object_string_add(json_pref, "sendMode",
11876 "advertised");
11877 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11878 json_object_string_add(json_pref, "sendMode",
11879 "received");
11880 } else {
11881 vty_out(vty, " Send-mode: ");
11882 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11883 vty_out(vty, "advertised");
11884 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11885 vty_out(vty, "%sreceived",
11886 CHECK_FLAG(p->af_cap[afi][safi],
11887 adv_smcap)
11888 ? ", "
11889 : "");
11890 vty_out(vty, "\n");
11891 }
11892 }
11893
11894 /* Receive-Mode */
11895 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11896 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11897 if (use_json) {
11898 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11899 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11900 json_object_string_add(json_pref, "recvMode",
11901 "advertisedAndReceived");
11902 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11903 json_object_string_add(json_pref, "recvMode",
11904 "advertised");
11905 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11906 json_object_string_add(json_pref, "recvMode",
11907 "received");
11908 } else {
11909 vty_out(vty, " Receive-mode: ");
11910 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11911 vty_out(vty, "advertised");
11912 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11913 vty_out(vty, "%sreceived",
11914 CHECK_FLAG(p->af_cap[afi][safi],
11915 adv_rmcap)
11916 ? ", "
11917 : "");
11918 vty_out(vty, "\n");
11919 }
11920 }
11921 }
11922
11923 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11924 struct peer *p,
11925 json_object *json)
11926 {
11927 bool rbit = false;
11928 bool nbit = false;
11929
11930 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11931 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11932 && (peer_established(p))) {
11933 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11934 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11935 }
11936
11937 if (json) {
11938 json_object_boolean_add(json, "rBit", rbit);
11939 json_object_boolean_add(json, "nBit", nbit);
11940 } else {
11941 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11942 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11943 }
11944 }
11945
11946 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11947 struct peer *peer,
11948 json_object *json)
11949 {
11950 const char *mode = "NotApplicable";
11951
11952 if (!json)
11953 vty_out(vty, "\n Remote GR Mode: ");
11954
11955 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11956 && (peer_established(peer))) {
11957
11958 if ((peer->nsf_af_count == 0)
11959 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11960
11961 mode = "Disable";
11962
11963 } else if (peer->nsf_af_count == 0
11964 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11965
11966 mode = "Helper";
11967
11968 } else if (peer->nsf_af_count != 0
11969 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11970
11971 mode = "Restart";
11972 }
11973 }
11974
11975 if (json)
11976 json_object_string_add(json, "remoteGrMode", mode);
11977 else
11978 vty_out(vty, mode, "\n");
11979 }
11980
11981 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11982 struct peer *p,
11983 json_object *json)
11984 {
11985 const char *mode = "Invalid";
11986
11987 if (!json)
11988 vty_out(vty, " Local GR Mode: ");
11989
11990 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11991 mode = "Helper";
11992 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11993 mode = "Restart";
11994 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11995 mode = "Disable";
11996 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11997 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11998 mode = "Helper*";
11999 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12000 mode = "Restart*";
12001 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12002 mode = "Disable*";
12003 else
12004 mode = "Invalid*";
12005 }
12006
12007 if (json)
12008 json_object_string_add(json, "localGrMode", mode);
12009 else
12010 vty_out(vty, mode, "\n");
12011 }
12012
12013 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12014 struct vty *vty, struct peer *peer, json_object *json)
12015 {
12016 afi_t afi;
12017 safi_t safi;
12018 json_object *json_afi_safi = NULL;
12019 json_object *json_timer = NULL;
12020 json_object *json_endofrib_status = NULL;
12021 bool eor_flag = false;
12022
12023 FOREACH_AFI_SAFI_NSF (afi, safi) {
12024 if (!peer->afc[afi][safi])
12025 continue;
12026
12027 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12028 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12029 continue;
12030
12031 if (json) {
12032 json_afi_safi = json_object_new_object();
12033 json_endofrib_status = json_object_new_object();
12034 json_timer = json_object_new_object();
12035 }
12036
12037 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12038 eor_flag = true;
12039 else
12040 eor_flag = false;
12041
12042 if (!json) {
12043 vty_out(vty, " %s:\n",
12044 get_afi_safi_str(afi, safi, false));
12045
12046 vty_out(vty, " F bit: ");
12047 }
12048
12049 if (peer->nsf[afi][safi] &&
12050 CHECK_FLAG(peer->af_cap[afi][safi],
12051 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12052
12053 if (json) {
12054 json_object_boolean_true_add(json_afi_safi,
12055 "fBit");
12056 } else
12057 vty_out(vty, "True\n");
12058 } else {
12059 if (json)
12060 json_object_boolean_false_add(json_afi_safi,
12061 "fBit");
12062 else
12063 vty_out(vty, "False\n");
12064 }
12065
12066 if (!json)
12067 vty_out(vty, " End-of-RIB sent: ");
12068
12069 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12070 PEER_STATUS_EOR_SEND)) {
12071 if (json) {
12072 json_object_boolean_true_add(
12073 json_endofrib_status, "endOfRibSend");
12074
12075 PRINT_EOR_JSON(eor_flag);
12076 } else {
12077 vty_out(vty, "Yes\n");
12078 vty_out(vty,
12079 " End-of-RIB sent after update: ");
12080
12081 PRINT_EOR(eor_flag);
12082 }
12083 } else {
12084 if (json) {
12085 json_object_boolean_false_add(
12086 json_endofrib_status, "endOfRibSend");
12087 json_object_boolean_false_add(
12088 json_endofrib_status,
12089 "endOfRibSentAfterUpdate");
12090 } else {
12091 vty_out(vty, "No\n");
12092 vty_out(vty,
12093 " End-of-RIB sent after update: ");
12094 vty_out(vty, "No\n");
12095 }
12096 }
12097
12098 if (!json)
12099 vty_out(vty, " End-of-RIB received: ");
12100
12101 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12102 PEER_STATUS_EOR_RECEIVED)) {
12103 if (json)
12104 json_object_boolean_true_add(
12105 json_endofrib_status, "endOfRibRecv");
12106 else
12107 vty_out(vty, "Yes\n");
12108 } else {
12109 if (json)
12110 json_object_boolean_false_add(
12111 json_endofrib_status, "endOfRibRecv");
12112 else
12113 vty_out(vty, "No\n");
12114 }
12115
12116 if (json) {
12117 json_object_int_add(json_timer, "stalePathTimer",
12118 peer->bgp->stalepath_time);
12119
12120 if (peer->t_gr_stale != NULL) {
12121 json_object_int_add(json_timer,
12122 "stalePathTimerRemaining",
12123 thread_timer_remain_second(
12124 peer->t_gr_stale));
12125 }
12126
12127 /* Display Configured Selection
12128 * Deferral only when when
12129 * Gr mode is enabled.
12130 */
12131 if (CHECK_FLAG(peer->flags,
12132 PEER_FLAG_GRACEFUL_RESTART)) {
12133 json_object_int_add(json_timer,
12134 "selectionDeferralTimer",
12135 peer->bgp->stalepath_time);
12136 }
12137
12138 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12139 NULL) {
12140
12141 json_object_int_add(
12142 json_timer,
12143 "selectionDeferralTimerRemaining",
12144 thread_timer_remain_second(
12145 peer->bgp->gr_info[afi][safi]
12146 .t_select_deferral));
12147 }
12148 } else {
12149 vty_out(vty, " Timers:\n");
12150 vty_out(vty,
12151 " Configured Stale Path Time(sec): %u\n",
12152 peer->bgp->stalepath_time);
12153
12154 if (peer->t_gr_stale != NULL)
12155 vty_out(vty,
12156 " Stale Path Remaining(sec): %ld\n",
12157 thread_timer_remain_second(
12158 peer->t_gr_stale));
12159 /* Display Configured Selection
12160 * Deferral only when when
12161 * Gr mode is enabled.
12162 */
12163 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12164 vty_out(vty,
12165 " Configured Selection Deferral Time(sec): %u\n",
12166 peer->bgp->select_defer_time);
12167
12168 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12169 NULL)
12170 vty_out(vty,
12171 " Selection Deferral Time Remaining(sec): %ld\n",
12172 thread_timer_remain_second(
12173 peer->bgp->gr_info[afi][safi]
12174 .t_select_deferral));
12175 }
12176 if (json) {
12177 json_object_object_add(json_afi_safi, "endOfRibStatus",
12178 json_endofrib_status);
12179 json_object_object_add(json_afi_safi, "timers",
12180 json_timer);
12181 json_object_object_add(
12182 json, get_afi_safi_str(afi, safi, true),
12183 json_afi_safi);
12184 }
12185 }
12186 }
12187
12188 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12189 struct peer *p,
12190 json_object *json)
12191 {
12192 if (json) {
12193 json_object *json_timer = NULL;
12194
12195 json_timer = json_object_new_object();
12196
12197 json_object_int_add(json_timer, "configuredRestartTimer",
12198 p->bgp->restart_time);
12199
12200 json_object_int_add(json_timer, "receivedRestartTimer",
12201 p->v_gr_restart);
12202
12203 if (p->t_gr_restart != NULL)
12204 json_object_int_add(
12205 json_timer, "restartTimerRemaining",
12206 thread_timer_remain_second(p->t_gr_restart));
12207
12208 json_object_object_add(json, "timers", json_timer);
12209 } else {
12210
12211 vty_out(vty, " Timers:\n");
12212 vty_out(vty, " Configured Restart Time(sec): %u\n",
12213 p->bgp->restart_time);
12214
12215 vty_out(vty, " Received Restart Time(sec): %u\n",
12216 p->v_gr_restart);
12217 if (p->t_gr_restart != NULL)
12218 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12219 thread_timer_remain_second(p->t_gr_restart));
12220 if (p->t_gr_restart != NULL) {
12221 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12222 thread_timer_remain_second(p->t_gr_restart));
12223 }
12224 }
12225 }
12226
12227 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12228 json_object *json)
12229 {
12230 char dn_flag[2] = {0};
12231 /* '*' + v6 address of neighbor */
12232 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12233
12234 if (!p->conf_if && peer_dynamic_neighbor(p))
12235 dn_flag[0] = '*';
12236
12237 if (p->conf_if) {
12238 if (json)
12239 json_object_string_addf(json, "neighborAddr", "%pSU",
12240 &p->su);
12241 else
12242 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12243 &p->su);
12244 } else {
12245 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12246 p->host);
12247
12248 if (json)
12249 json_object_string_add(json, "neighborAddr",
12250 neighborAddr);
12251 else
12252 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12253 }
12254
12255 /* more gr info in new format */
12256 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12257 }
12258
12259 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12260 safi_t safi, bool use_json,
12261 json_object *json_neigh)
12262 {
12263 struct bgp_filter *filter;
12264 struct peer_af *paf;
12265 char orf_pfx_name[BUFSIZ];
12266 int orf_pfx_count;
12267 json_object *json_af = NULL;
12268 json_object *json_prefA = NULL;
12269 json_object *json_prefB = NULL;
12270 json_object *json_addr = NULL;
12271 json_object *json_advmap = NULL;
12272
12273 if (use_json) {
12274 json_addr = json_object_new_object();
12275 json_af = json_object_new_object();
12276 filter = &p->filter[afi][safi];
12277
12278 if (peer_group_active(p))
12279 json_object_string_add(json_addr, "peerGroupMember",
12280 p->group->name);
12281
12282 paf = peer_af_find(p, afi, safi);
12283 if (paf && PAF_SUBGRP(paf)) {
12284 json_object_int_add(json_addr, "updateGroupId",
12285 PAF_UPDGRP(paf)->id);
12286 json_object_int_add(json_addr, "subGroupId",
12287 PAF_SUBGRP(paf)->id);
12288 json_object_int_add(json_addr, "packetQueueLength",
12289 bpacket_queue_virtual_length(paf));
12290 }
12291
12292 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12293 || CHECK_FLAG(p->af_cap[afi][safi],
12294 PEER_CAP_ORF_PREFIX_SM_RCV)
12295 || CHECK_FLAG(p->af_cap[afi][safi],
12296 PEER_CAP_ORF_PREFIX_RM_ADV)
12297 || CHECK_FLAG(p->af_cap[afi][safi],
12298 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12299 json_object_int_add(json_af, "orfType",
12300 ORF_TYPE_PREFIX);
12301 json_prefA = json_object_new_object();
12302 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12303 PEER_CAP_ORF_PREFIX_SM_ADV,
12304 PEER_CAP_ORF_PREFIX_RM_ADV,
12305 PEER_CAP_ORF_PREFIX_SM_RCV,
12306 PEER_CAP_ORF_PREFIX_RM_RCV,
12307 use_json, json_prefA);
12308 json_object_object_add(json_af, "orfPrefixList",
12309 json_prefA);
12310 }
12311
12312 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12313 || CHECK_FLAG(p->af_cap[afi][safi],
12314 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12315 || CHECK_FLAG(p->af_cap[afi][safi],
12316 PEER_CAP_ORF_PREFIX_RM_ADV)
12317 || CHECK_FLAG(p->af_cap[afi][safi],
12318 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12319 json_object_int_add(json_af, "orfOldType",
12320 ORF_TYPE_PREFIX_OLD);
12321 json_prefB = json_object_new_object();
12322 bgp_show_peer_afi_orf_cap(
12323 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12324 PEER_CAP_ORF_PREFIX_RM_ADV,
12325 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12326 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12327 json_prefB);
12328 json_object_object_add(json_af, "orfOldPrefixList",
12329 json_prefB);
12330 }
12331
12332 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12333 || CHECK_FLAG(p->af_cap[afi][safi],
12334 PEER_CAP_ORF_PREFIX_SM_RCV)
12335 || CHECK_FLAG(p->af_cap[afi][safi],
12336 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12337 || CHECK_FLAG(p->af_cap[afi][safi],
12338 PEER_CAP_ORF_PREFIX_RM_ADV)
12339 || CHECK_FLAG(p->af_cap[afi][safi],
12340 PEER_CAP_ORF_PREFIX_RM_RCV)
12341 || CHECK_FLAG(p->af_cap[afi][safi],
12342 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12343 json_object_object_add(json_addr, "afDependentCap",
12344 json_af);
12345 else
12346 json_object_free(json_af);
12347
12348 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12349 p->host, afi, safi);
12350 orf_pfx_count = prefix_bgp_show_prefix_list(
12351 NULL, afi, orf_pfx_name, use_json);
12352
12353 if (CHECK_FLAG(p->af_sflags[afi][safi],
12354 PEER_STATUS_ORF_PREFIX_SEND)
12355 || orf_pfx_count) {
12356 if (CHECK_FLAG(p->af_sflags[afi][safi],
12357 PEER_STATUS_ORF_PREFIX_SEND))
12358 json_object_boolean_true_add(json_neigh,
12359 "orfSent");
12360 if (orf_pfx_count)
12361 json_object_int_add(json_addr, "orfRecvCounter",
12362 orf_pfx_count);
12363 }
12364 if (CHECK_FLAG(p->af_sflags[afi][safi],
12365 PEER_STATUS_ORF_WAIT_REFRESH))
12366 json_object_string_add(
12367 json_addr, "orfFirstUpdate",
12368 "deferredUntilORFOrRouteRefreshRecvd");
12369
12370 if (CHECK_FLAG(p->af_flags[afi][safi],
12371 PEER_FLAG_REFLECTOR_CLIENT))
12372 json_object_boolean_true_add(json_addr,
12373 "routeReflectorClient");
12374 if (CHECK_FLAG(p->af_flags[afi][safi],
12375 PEER_FLAG_RSERVER_CLIENT))
12376 json_object_boolean_true_add(json_addr,
12377 "routeServerClient");
12378 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12379 json_object_boolean_true_add(json_addr,
12380 "inboundSoftConfigPermit");
12381
12382 if (CHECK_FLAG(p->af_flags[afi][safi],
12383 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12384 json_object_boolean_true_add(
12385 json_addr,
12386 "privateAsNumsAllReplacedInUpdatesToNbr");
12387 else if (CHECK_FLAG(p->af_flags[afi][safi],
12388 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12389 json_object_boolean_true_add(
12390 json_addr,
12391 "privateAsNumsReplacedInUpdatesToNbr");
12392 else if (CHECK_FLAG(p->af_flags[afi][safi],
12393 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12394 json_object_boolean_true_add(
12395 json_addr,
12396 "privateAsNumsAllRemovedInUpdatesToNbr");
12397 else if (CHECK_FLAG(p->af_flags[afi][safi],
12398 PEER_FLAG_REMOVE_PRIVATE_AS))
12399 json_object_boolean_true_add(
12400 json_addr,
12401 "privateAsNumsRemovedInUpdatesToNbr");
12402
12403 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12404 if (CHECK_FLAG(p->af_flags[afi][safi],
12405 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12406 json_object_boolean_true_add(json_addr,
12407 "allowAsInOrigin");
12408 else
12409 json_object_int_add(json_addr, "allowAsInCount",
12410 p->allowas_in[afi][safi]);
12411 }
12412
12413 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12414 json_object_boolean_true_add(
12415 json_addr,
12416 bgp_addpath_names(p->addpath_type[afi][safi])
12417 ->type_json_name);
12418
12419 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12420 json_object_string_add(json_addr,
12421 "overrideASNsInOutboundUpdates",
12422 "ifAspathEqualRemoteAs");
12423
12424 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12425 || CHECK_FLAG(p->af_flags[afi][safi],
12426 PEER_FLAG_FORCE_NEXTHOP_SELF))
12427 json_object_boolean_true_add(json_addr,
12428 "routerAlwaysNextHop");
12429 if (CHECK_FLAG(p->af_flags[afi][safi],
12430 PEER_FLAG_AS_PATH_UNCHANGED))
12431 json_object_boolean_true_add(
12432 json_addr, "unchangedAsPathPropogatedToNbr");
12433 if (CHECK_FLAG(p->af_flags[afi][safi],
12434 PEER_FLAG_NEXTHOP_UNCHANGED))
12435 json_object_boolean_true_add(
12436 json_addr, "unchangedNextHopPropogatedToNbr");
12437 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12438 json_object_boolean_true_add(
12439 json_addr, "unchangedMedPropogatedToNbr");
12440 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12441 || CHECK_FLAG(p->af_flags[afi][safi],
12442 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12443 if (CHECK_FLAG(p->af_flags[afi][safi],
12444 PEER_FLAG_SEND_COMMUNITY)
12445 && CHECK_FLAG(p->af_flags[afi][safi],
12446 PEER_FLAG_SEND_EXT_COMMUNITY))
12447 json_object_string_add(json_addr,
12448 "commAttriSentToNbr",
12449 "extendedAndStandard");
12450 else if (CHECK_FLAG(p->af_flags[afi][safi],
12451 PEER_FLAG_SEND_EXT_COMMUNITY))
12452 json_object_string_add(json_addr,
12453 "commAttriSentToNbr",
12454 "extended");
12455 else
12456 json_object_string_add(json_addr,
12457 "commAttriSentToNbr",
12458 "standard");
12459 }
12460 if (CHECK_FLAG(p->af_flags[afi][safi],
12461 PEER_FLAG_DEFAULT_ORIGINATE)) {
12462 if (p->default_rmap[afi][safi].name)
12463 json_object_string_add(
12464 json_addr, "defaultRouteMap",
12465 p->default_rmap[afi][safi].name);
12466
12467 if (paf && PAF_SUBGRP(paf)
12468 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12469 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12470 json_object_boolean_true_add(json_addr,
12471 "defaultSent");
12472 else
12473 json_object_boolean_true_add(json_addr,
12474 "defaultNotSent");
12475 }
12476
12477 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12478 if (is_evpn_enabled())
12479 json_object_boolean_true_add(
12480 json_addr, "advertiseAllVnis");
12481 }
12482
12483 if (filter->plist[FILTER_IN].name
12484 || filter->dlist[FILTER_IN].name
12485 || filter->aslist[FILTER_IN].name
12486 || filter->map[RMAP_IN].name)
12487 json_object_boolean_true_add(json_addr,
12488 "inboundPathPolicyConfig");
12489 if (filter->plist[FILTER_OUT].name
12490 || filter->dlist[FILTER_OUT].name
12491 || filter->aslist[FILTER_OUT].name
12492 || filter->map[RMAP_OUT].name || filter->usmap.name)
12493 json_object_boolean_true_add(
12494 json_addr, "outboundPathPolicyConfig");
12495
12496 /* prefix-list */
12497 if (filter->plist[FILTER_IN].name)
12498 json_object_string_add(json_addr,
12499 "incomingUpdatePrefixFilterList",
12500 filter->plist[FILTER_IN].name);
12501 if (filter->plist[FILTER_OUT].name)
12502 json_object_string_add(json_addr,
12503 "outgoingUpdatePrefixFilterList",
12504 filter->plist[FILTER_OUT].name);
12505
12506 /* distribute-list */
12507 if (filter->dlist[FILTER_IN].name)
12508 json_object_string_add(
12509 json_addr, "incomingUpdateNetworkFilterList",
12510 filter->dlist[FILTER_IN].name);
12511 if (filter->dlist[FILTER_OUT].name)
12512 json_object_string_add(
12513 json_addr, "outgoingUpdateNetworkFilterList",
12514 filter->dlist[FILTER_OUT].name);
12515
12516 /* filter-list. */
12517 if (filter->aslist[FILTER_IN].name)
12518 json_object_string_add(json_addr,
12519 "incomingUpdateAsPathFilterList",
12520 filter->aslist[FILTER_IN].name);
12521 if (filter->aslist[FILTER_OUT].name)
12522 json_object_string_add(json_addr,
12523 "outgoingUpdateAsPathFilterList",
12524 filter->aslist[FILTER_OUT].name);
12525
12526 /* route-map. */
12527 if (filter->map[RMAP_IN].name)
12528 json_object_string_add(
12529 json_addr, "routeMapForIncomingAdvertisements",
12530 filter->map[RMAP_IN].name);
12531 if (filter->map[RMAP_OUT].name)
12532 json_object_string_add(
12533 json_addr, "routeMapForOutgoingAdvertisements",
12534 filter->map[RMAP_OUT].name);
12535
12536 /* ebgp-requires-policy (inbound) */
12537 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12538 && !bgp_inbound_policy_exists(p, filter))
12539 json_object_string_add(
12540 json_addr, "inboundEbgpRequiresPolicy",
12541 "Inbound updates discarded due to missing policy");
12542
12543 /* ebgp-requires-policy (outbound) */
12544 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12545 && (!bgp_outbound_policy_exists(p, filter)))
12546 json_object_string_add(
12547 json_addr, "outboundEbgpRequiresPolicy",
12548 "Outbound updates discarded due to missing policy");
12549
12550 /* unsuppress-map */
12551 if (filter->usmap.name)
12552 json_object_string_add(json_addr,
12553 "selectiveUnsuppressRouteMap",
12554 filter->usmap.name);
12555
12556 /* advertise-map */
12557 if (filter->advmap.aname) {
12558 json_advmap = json_object_new_object();
12559 json_object_string_add(json_advmap, "condition",
12560 filter->advmap.condition
12561 ? "EXIST"
12562 : "NON_EXIST");
12563 json_object_string_add(json_advmap, "conditionMap",
12564 filter->advmap.cname);
12565 json_object_string_add(json_advmap, "advertiseMap",
12566 filter->advmap.aname);
12567 json_object_string_add(
12568 json_advmap, "advertiseStatus",
12569 filter->advmap.update_type ==
12570 UPDATE_TYPE_ADVERTISE
12571 ? "Advertise"
12572 : "Withdraw");
12573 json_object_object_add(json_addr, "advertiseMap",
12574 json_advmap);
12575 }
12576
12577 /* Receive prefix count */
12578 json_object_int_add(json_addr, "acceptedPrefixCounter",
12579 p->pcount[afi][safi]);
12580 if (paf && PAF_SUBGRP(paf))
12581 json_object_int_add(json_addr, "sentPrefixCounter",
12582 (PAF_SUBGRP(paf))->scount);
12583
12584 /* Maximum prefix */
12585 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12586 json_object_int_add(json_addr, "prefixOutAllowedMax",
12587 p->pmax_out[afi][safi]);
12588
12589 /* Maximum prefix */
12590 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12591 json_object_int_add(json_addr, "prefixAllowedMax",
12592 p->pmax[afi][safi]);
12593 if (CHECK_FLAG(p->af_flags[afi][safi],
12594 PEER_FLAG_MAX_PREFIX_WARNING))
12595 json_object_boolean_true_add(
12596 json_addr, "prefixAllowedMaxWarning");
12597 json_object_int_add(json_addr,
12598 "prefixAllowedWarningThresh",
12599 p->pmax_threshold[afi][safi]);
12600 if (p->pmax_restart[afi][safi])
12601 json_object_int_add(
12602 json_addr,
12603 "prefixAllowedRestartIntervalMsecs",
12604 p->pmax_restart[afi][safi] * 60000);
12605 }
12606 json_object_object_add(json_neigh,
12607 get_afi_safi_str(afi, safi, true),
12608 json_addr);
12609
12610 } else {
12611 filter = &p->filter[afi][safi];
12612
12613 vty_out(vty, " For address family: %s\n",
12614 get_afi_safi_str(afi, safi, false));
12615
12616 if (peer_group_active(p))
12617 vty_out(vty, " %s peer-group member\n",
12618 p->group->name);
12619
12620 paf = peer_af_find(p, afi, safi);
12621 if (paf && PAF_SUBGRP(paf)) {
12622 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12623 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12624 vty_out(vty, " Packet Queue length %d\n",
12625 bpacket_queue_virtual_length(paf));
12626 } else {
12627 vty_out(vty, " Not part of any update group\n");
12628 }
12629 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12630 || CHECK_FLAG(p->af_cap[afi][safi],
12631 PEER_CAP_ORF_PREFIX_SM_RCV)
12632 || CHECK_FLAG(p->af_cap[afi][safi],
12633 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12634 || CHECK_FLAG(p->af_cap[afi][safi],
12635 PEER_CAP_ORF_PREFIX_RM_ADV)
12636 || CHECK_FLAG(p->af_cap[afi][safi],
12637 PEER_CAP_ORF_PREFIX_RM_RCV)
12638 || CHECK_FLAG(p->af_cap[afi][safi],
12639 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12640 vty_out(vty, " AF-dependant capabilities:\n");
12641
12642 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12643 || CHECK_FLAG(p->af_cap[afi][safi],
12644 PEER_CAP_ORF_PREFIX_SM_RCV)
12645 || CHECK_FLAG(p->af_cap[afi][safi],
12646 PEER_CAP_ORF_PREFIX_RM_ADV)
12647 || CHECK_FLAG(p->af_cap[afi][safi],
12648 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12649 vty_out(vty,
12650 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12651 ORF_TYPE_PREFIX);
12652 bgp_show_peer_afi_orf_cap(
12653 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12654 PEER_CAP_ORF_PREFIX_RM_ADV,
12655 PEER_CAP_ORF_PREFIX_SM_RCV,
12656 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12657 }
12658 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
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_OLD_RCV)) {
12665 vty_out(vty,
12666 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12667 ORF_TYPE_PREFIX_OLD);
12668 bgp_show_peer_afi_orf_cap(
12669 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12670 PEER_CAP_ORF_PREFIX_RM_ADV,
12671 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12672 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12673 }
12674
12675 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12676 p->host, afi, safi);
12677 orf_pfx_count = prefix_bgp_show_prefix_list(
12678 NULL, afi, orf_pfx_name, use_json);
12679
12680 if (CHECK_FLAG(p->af_sflags[afi][safi],
12681 PEER_STATUS_ORF_PREFIX_SEND)
12682 || orf_pfx_count) {
12683 vty_out(vty, " Outbound Route Filter (ORF):");
12684 if (CHECK_FLAG(p->af_sflags[afi][safi],
12685 PEER_STATUS_ORF_PREFIX_SEND))
12686 vty_out(vty, " sent;");
12687 if (orf_pfx_count)
12688 vty_out(vty, " received (%d entries)",
12689 orf_pfx_count);
12690 vty_out(vty, "\n");
12691 }
12692 if (CHECK_FLAG(p->af_sflags[afi][safi],
12693 PEER_STATUS_ORF_WAIT_REFRESH))
12694 vty_out(vty,
12695 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12696
12697 if (CHECK_FLAG(p->af_flags[afi][safi],
12698 PEER_FLAG_REFLECTOR_CLIENT))
12699 vty_out(vty, " Route-Reflector Client\n");
12700 if (CHECK_FLAG(p->af_flags[afi][safi],
12701 PEER_FLAG_RSERVER_CLIENT))
12702 vty_out(vty, " Route-Server Client\n");
12703 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12704 vty_out(vty,
12705 " Inbound soft reconfiguration allowed\n");
12706
12707 if (CHECK_FLAG(p->af_flags[afi][safi],
12708 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12709 vty_out(vty,
12710 " Private AS numbers (all) replaced in updates to this neighbor\n");
12711 else if (CHECK_FLAG(p->af_flags[afi][safi],
12712 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12713 vty_out(vty,
12714 " Private AS numbers replaced in updates to this neighbor\n");
12715 else if (CHECK_FLAG(p->af_flags[afi][safi],
12716 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12717 vty_out(vty,
12718 " Private AS numbers (all) removed in updates to this neighbor\n");
12719 else if (CHECK_FLAG(p->af_flags[afi][safi],
12720 PEER_FLAG_REMOVE_PRIVATE_AS))
12721 vty_out(vty,
12722 " Private AS numbers removed in updates to this neighbor\n");
12723
12724 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12725 if (CHECK_FLAG(p->af_flags[afi][safi],
12726 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12727 vty_out(vty,
12728 " Local AS allowed as path origin\n");
12729 else
12730 vty_out(vty,
12731 " Local AS allowed in path, %d occurrences\n",
12732 p->allowas_in[afi][safi]);
12733 }
12734
12735 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12736 vty_out(vty, " %s\n",
12737 bgp_addpath_names(p->addpath_type[afi][safi])
12738 ->human_description);
12739
12740 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12741 vty_out(vty,
12742 " Override ASNs in outbound updates if aspath equals remote-as\n");
12743
12744 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12745 || CHECK_FLAG(p->af_flags[afi][safi],
12746 PEER_FLAG_FORCE_NEXTHOP_SELF))
12747 vty_out(vty, " NEXT_HOP is always this router\n");
12748 if (CHECK_FLAG(p->af_flags[afi][safi],
12749 PEER_FLAG_AS_PATH_UNCHANGED))
12750 vty_out(vty,
12751 " AS_PATH is propagated unchanged to this neighbor\n");
12752 if (CHECK_FLAG(p->af_flags[afi][safi],
12753 PEER_FLAG_NEXTHOP_UNCHANGED))
12754 vty_out(vty,
12755 " NEXT_HOP is propagated unchanged to this neighbor\n");
12756 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12757 vty_out(vty,
12758 " MED is propagated unchanged to this neighbor\n");
12759 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12760 || CHECK_FLAG(p->af_flags[afi][safi],
12761 PEER_FLAG_SEND_EXT_COMMUNITY)
12762 || CHECK_FLAG(p->af_flags[afi][safi],
12763 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12764 vty_out(vty,
12765 " Community attribute sent to this neighbor");
12766 if (CHECK_FLAG(p->af_flags[afi][safi],
12767 PEER_FLAG_SEND_COMMUNITY)
12768 && CHECK_FLAG(p->af_flags[afi][safi],
12769 PEER_FLAG_SEND_EXT_COMMUNITY)
12770 && CHECK_FLAG(p->af_flags[afi][safi],
12771 PEER_FLAG_SEND_LARGE_COMMUNITY))
12772 vty_out(vty, "(all)\n");
12773 else if (CHECK_FLAG(p->af_flags[afi][safi],
12774 PEER_FLAG_SEND_LARGE_COMMUNITY))
12775 vty_out(vty, "(large)\n");
12776 else if (CHECK_FLAG(p->af_flags[afi][safi],
12777 PEER_FLAG_SEND_EXT_COMMUNITY))
12778 vty_out(vty, "(extended)\n");
12779 else
12780 vty_out(vty, "(standard)\n");
12781 }
12782 if (CHECK_FLAG(p->af_flags[afi][safi],
12783 PEER_FLAG_DEFAULT_ORIGINATE)) {
12784 vty_out(vty, " Default information originate,");
12785
12786 if (p->default_rmap[afi][safi].name)
12787 vty_out(vty, " default route-map %s%s,",
12788 p->default_rmap[afi][safi].map ? "*"
12789 : "",
12790 p->default_rmap[afi][safi].name);
12791 if (paf && PAF_SUBGRP(paf)
12792 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12793 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12794 vty_out(vty, " default sent\n");
12795 else
12796 vty_out(vty, " default not sent\n");
12797 }
12798
12799 /* advertise-vni-all */
12800 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12801 if (is_evpn_enabled())
12802 vty_out(vty, " advertise-all-vni\n");
12803 }
12804
12805 if (filter->plist[FILTER_IN].name
12806 || filter->dlist[FILTER_IN].name
12807 || filter->aslist[FILTER_IN].name
12808 || filter->map[RMAP_IN].name)
12809 vty_out(vty, " Inbound path policy configured\n");
12810 if (filter->plist[FILTER_OUT].name
12811 || filter->dlist[FILTER_OUT].name
12812 || filter->aslist[FILTER_OUT].name
12813 || filter->map[RMAP_OUT].name || filter->usmap.name)
12814 vty_out(vty, " Outbound path policy configured\n");
12815
12816 /* prefix-list */
12817 if (filter->plist[FILTER_IN].name)
12818 vty_out(vty,
12819 " Incoming update prefix filter list is %s%s\n",
12820 filter->plist[FILTER_IN].plist ? "*" : "",
12821 filter->plist[FILTER_IN].name);
12822 if (filter->plist[FILTER_OUT].name)
12823 vty_out(vty,
12824 " Outgoing update prefix filter list is %s%s\n",
12825 filter->plist[FILTER_OUT].plist ? "*" : "",
12826 filter->plist[FILTER_OUT].name);
12827
12828 /* distribute-list */
12829 if (filter->dlist[FILTER_IN].name)
12830 vty_out(vty,
12831 " Incoming update network filter list is %s%s\n",
12832 filter->dlist[FILTER_IN].alist ? "*" : "",
12833 filter->dlist[FILTER_IN].name);
12834 if (filter->dlist[FILTER_OUT].name)
12835 vty_out(vty,
12836 " Outgoing update network filter list is %s%s\n",
12837 filter->dlist[FILTER_OUT].alist ? "*" : "",
12838 filter->dlist[FILTER_OUT].name);
12839
12840 /* filter-list. */
12841 if (filter->aslist[FILTER_IN].name)
12842 vty_out(vty,
12843 " Incoming update AS path filter list is %s%s\n",
12844 filter->aslist[FILTER_IN].aslist ? "*" : "",
12845 filter->aslist[FILTER_IN].name);
12846 if (filter->aslist[FILTER_OUT].name)
12847 vty_out(vty,
12848 " Outgoing update AS path filter list is %s%s\n",
12849 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12850 filter->aslist[FILTER_OUT].name);
12851
12852 /* route-map. */
12853 if (filter->map[RMAP_IN].name)
12854 vty_out(vty,
12855 " Route map for incoming advertisements is %s%s\n",
12856 filter->map[RMAP_IN].map ? "*" : "",
12857 filter->map[RMAP_IN].name);
12858 if (filter->map[RMAP_OUT].name)
12859 vty_out(vty,
12860 " Route map for outgoing advertisements is %s%s\n",
12861 filter->map[RMAP_OUT].map ? "*" : "",
12862 filter->map[RMAP_OUT].name);
12863
12864 /* ebgp-requires-policy (inbound) */
12865 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12866 && !bgp_inbound_policy_exists(p, filter))
12867 vty_out(vty,
12868 " Inbound updates discarded due to missing policy\n");
12869
12870 /* ebgp-requires-policy (outbound) */
12871 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12872 && !bgp_outbound_policy_exists(p, filter))
12873 vty_out(vty,
12874 " Outbound updates discarded due to missing policy\n");
12875
12876 /* unsuppress-map */
12877 if (filter->usmap.name)
12878 vty_out(vty,
12879 " Route map for selective unsuppress is %s%s\n",
12880 filter->usmap.map ? "*" : "",
12881 filter->usmap.name);
12882
12883 /* advertise-map */
12884 if (filter->advmap.aname && filter->advmap.cname)
12885 vty_out(vty,
12886 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12887 filter->advmap.condition ? "EXIST"
12888 : "NON_EXIST",
12889 filter->advmap.cmap ? "*" : "",
12890 filter->advmap.cname,
12891 filter->advmap.amap ? "*" : "",
12892 filter->advmap.aname,
12893 filter->advmap.update_type ==
12894 UPDATE_TYPE_ADVERTISE
12895 ? "Advertise"
12896 : "Withdraw");
12897
12898 /* Receive prefix count */
12899 vty_out(vty, " %u accepted prefixes\n",
12900 p->pcount[afi][safi]);
12901
12902 /* maximum-prefix-out */
12903 if (CHECK_FLAG(p->af_flags[afi][safi],
12904 PEER_FLAG_MAX_PREFIX_OUT))
12905 vty_out(vty,
12906 " Maximum allowed prefixes sent %u\n",
12907 p->pmax_out[afi][safi]);
12908
12909 /* Maximum prefix */
12910 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12911 vty_out(vty,
12912 " Maximum prefixes allowed %u%s\n",
12913 p->pmax[afi][safi],
12914 CHECK_FLAG(p->af_flags[afi][safi],
12915 PEER_FLAG_MAX_PREFIX_WARNING)
12916 ? " (warning-only)"
12917 : "");
12918 vty_out(vty, " Threshold for warning message %d%%",
12919 p->pmax_threshold[afi][safi]);
12920 if (p->pmax_restart[afi][safi])
12921 vty_out(vty, ", restart interval %d min",
12922 p->pmax_restart[afi][safi]);
12923 vty_out(vty, "\n");
12924 }
12925
12926 vty_out(vty, "\n");
12927 }
12928 }
12929
12930 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12931 json_object *json)
12932 {
12933 struct bgp *bgp;
12934 char timebuf[BGP_UPTIME_LEN];
12935 char dn_flag[2];
12936 afi_t afi;
12937 safi_t safi;
12938 uint16_t i;
12939 uint8_t *msg;
12940 json_object *json_neigh = NULL;
12941 time_t epoch_tbuf;
12942 uint32_t sync_tcp_mss;
12943
12944 bgp = p->bgp;
12945
12946 if (use_json)
12947 json_neigh = json_object_new_object();
12948
12949 memset(dn_flag, '\0', sizeof(dn_flag));
12950 if (!p->conf_if && peer_dynamic_neighbor(p))
12951 dn_flag[0] = '*';
12952
12953 if (!use_json) {
12954 if (p->conf_if) /* Configured interface name. */
12955 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12956 &p->su);
12957 else /* Configured IP address. */
12958 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12959 p->host);
12960 }
12961
12962 if (use_json) {
12963 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12964 json_object_string_add(json_neigh, "bgpNeighborAddr",
12965 "none");
12966 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12967 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12968 "%pSU", &p->su);
12969
12970 json_object_int_add(json_neigh, "remoteAs", p->as);
12971
12972 if (p->change_local_as)
12973 json_object_int_add(json_neigh, "localAs",
12974 p->change_local_as);
12975 else
12976 json_object_int_add(json_neigh, "localAs", p->local_as);
12977
12978 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12979 json_object_boolean_true_add(json_neigh,
12980 "localAsNoPrepend");
12981
12982 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12983 json_object_boolean_true_add(json_neigh,
12984 "localAsReplaceAs");
12985 } else {
12986 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12987 || (p->as_type == AS_INTERNAL))
12988 vty_out(vty, "remote AS %u, ", p->as);
12989 else
12990 vty_out(vty, "remote AS Unspecified, ");
12991 vty_out(vty, "local AS %u%s%s, ",
12992 p->change_local_as ? p->change_local_as : p->local_as,
12993 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12994 ? " no-prepend"
12995 : "",
12996 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12997 ? " replace-as"
12998 : "");
12999 }
13000 /* peer type internal or confed-internal */
13001 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13002 if (use_json) {
13003 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13004 json_object_boolean_true_add(
13005 json_neigh, "nbrConfedInternalLink");
13006 else
13007 json_object_boolean_true_add(json_neigh,
13008 "nbrInternalLink");
13009 } else {
13010 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13011 vty_out(vty, "confed-internal link\n");
13012 else
13013 vty_out(vty, "internal link\n");
13014 }
13015 /* peer type external or confed-external */
13016 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13017 if (use_json) {
13018 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13019 json_object_boolean_true_add(
13020 json_neigh, "nbrConfedExternalLink");
13021 else
13022 json_object_boolean_true_add(json_neigh,
13023 "nbrExternalLink");
13024 } else {
13025 if (bgp_confederation_peers_check(bgp, p->as))
13026 vty_out(vty, "confed-external link\n");
13027 else
13028 vty_out(vty, "external link\n");
13029 }
13030 } else {
13031 if (use_json)
13032 json_object_boolean_true_add(json_neigh,
13033 "nbrUnspecifiedLink");
13034 else
13035 vty_out(vty, "unspecified link\n");
13036 }
13037
13038 /* Roles */
13039 if (use_json) {
13040 json_object_string_add(json_neigh, "localRole",
13041 bgp_get_name_by_role(p->local_role));
13042 json_object_string_add(json_neigh, "remoteRole",
13043 bgp_get_name_by_role(p->remote_role));
13044 } else {
13045 vty_out(vty, " Local Role: %s\n",
13046 bgp_get_name_by_role(p->local_role));
13047 vty_out(vty, " Remote Role: %s\n",
13048 bgp_get_name_by_role(p->remote_role));
13049 }
13050
13051
13052 /* Description. */
13053 if (p->desc) {
13054 if (use_json)
13055 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13056 else
13057 vty_out(vty, " Description: %s\n", p->desc);
13058 }
13059
13060 if (p->hostname) {
13061 if (use_json) {
13062 json_object_string_add(json_neigh, "hostname",
13063 p->hostname);
13064
13065 if (p->domainname)
13066 json_object_string_add(json_neigh, "domainname",
13067 p->domainname);
13068 } else {
13069 if (p->domainname && (p->domainname[0] != '\0'))
13070 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13071 p->domainname);
13072 else
13073 vty_out(vty, "Hostname: %s\n", p->hostname);
13074 }
13075 } else {
13076 if (use_json)
13077 json_object_string_add(json_neigh, "hostname",
13078 "Unknown");
13079 }
13080
13081 /* Peer-group */
13082 if (p->group) {
13083 if (use_json) {
13084 json_object_string_add(json_neigh, "peerGroup",
13085 p->group->name);
13086
13087 if (dn_flag[0]) {
13088 struct prefix prefix, *range = NULL;
13089
13090 if (sockunion2hostprefix(&(p->su), &prefix))
13091 range = peer_group_lookup_dynamic_neighbor_range(
13092 p->group, &prefix);
13093
13094 if (range) {
13095 json_object_string_addf(
13096 json_neigh,
13097 "peerSubnetRangeGroup", "%pFX",
13098 range);
13099 }
13100 }
13101 } else {
13102 vty_out(vty,
13103 " Member of peer-group %s for session parameters\n",
13104 p->group->name);
13105
13106 if (dn_flag[0]) {
13107 struct prefix prefix, *range = NULL;
13108
13109 if (sockunion2hostprefix(&(p->su), &prefix))
13110 range = peer_group_lookup_dynamic_neighbor_range(
13111 p->group, &prefix);
13112
13113 if (range) {
13114 vty_out(vty,
13115 " Belongs to the subnet range group: %pFX\n",
13116 range);
13117 }
13118 }
13119 }
13120 }
13121
13122 if (use_json) {
13123 /* Administrative shutdown. */
13124 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13125 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13126 json_object_boolean_true_add(json_neigh,
13127 "adminShutDown");
13128
13129 /* BGP Version. */
13130 json_object_int_add(json_neigh, "bgpVersion", 4);
13131 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13132 &p->remote_id);
13133 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13134 &bgp->router_id);
13135
13136 /* Confederation */
13137 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13138 && bgp_confederation_peers_check(bgp, p->as))
13139 json_object_boolean_true_add(json_neigh,
13140 "nbrCommonAdmin");
13141
13142 /* Status. */
13143 json_object_string_add(
13144 json_neigh, "bgpState",
13145 lookup_msg(bgp_status_msg, p->status, NULL));
13146
13147 if (peer_established(p)) {
13148 time_t uptime;
13149
13150 uptime = monotime(NULL);
13151 uptime -= p->uptime;
13152 epoch_tbuf = time(NULL) - uptime;
13153
13154 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13155 uptime * 1000);
13156 json_object_string_add(json_neigh, "bgpTimerUpString",
13157 peer_uptime(p->uptime, timebuf,
13158 BGP_UPTIME_LEN, 0,
13159 NULL));
13160 json_object_int_add(json_neigh,
13161 "bgpTimerUpEstablishedEpoch",
13162 epoch_tbuf);
13163 }
13164
13165 else if (p->status == Active) {
13166 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13167 json_object_string_add(json_neigh, "bgpStateIs",
13168 "passive");
13169 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13170 json_object_string_add(json_neigh, "bgpStateIs",
13171 "passiveNSF");
13172 }
13173
13174 /* read timer */
13175 time_t uptime;
13176 struct tm tm;
13177
13178 uptime = monotime(NULL);
13179 uptime -= p->readtime;
13180 gmtime_r(&uptime, &tm);
13181
13182 json_object_int_add(json_neigh, "bgpTimerLastRead",
13183 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13184 + (tm.tm_hour * 3600000));
13185
13186 uptime = monotime(NULL);
13187 uptime -= p->last_write;
13188 gmtime_r(&uptime, &tm);
13189
13190 json_object_int_add(json_neigh, "bgpTimerLastWrite",
13191 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13192 + (tm.tm_hour * 3600000));
13193
13194 uptime = monotime(NULL);
13195 uptime -= p->update_time;
13196 gmtime_r(&uptime, &tm);
13197
13198 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13199 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13200 + (tm.tm_hour * 3600000));
13201
13202 /* Configured timer values. */
13203 json_object_int_add(json_neigh,
13204 "bgpTimerConfiguredHoldTimeMsecs",
13205 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13206 ? p->holdtime * 1000
13207 : bgp->default_holdtime * 1000);
13208 json_object_int_add(json_neigh,
13209 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13210 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13211 ? p->keepalive * 1000
13212 : bgp->default_keepalive * 1000);
13213 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13214 p->v_holdtime * 1000);
13215 json_object_int_add(json_neigh,
13216 "bgpTimerKeepAliveIntervalMsecs",
13217 p->v_keepalive * 1000);
13218 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13219 json_object_int_add(json_neigh,
13220 "bgpTimerDelayOpenTimeMsecs",
13221 p->v_delayopen * 1000);
13222 }
13223
13224 /* Configured and Synced tcp-mss value for peer */
13225 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13226 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13227 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13228 p->tcp_mss);
13229 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13230 sync_tcp_mss);
13231 }
13232
13233 /* Extended Optional Parameters Length for BGP OPEN Message */
13234 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13235 json_object_boolean_true_add(
13236 json_neigh, "extendedOptionalParametersLength");
13237 else
13238 json_object_boolean_false_add(
13239 json_neigh, "extendedOptionalParametersLength");
13240
13241 /* Conditional advertisements */
13242 json_object_int_add(
13243 json_neigh,
13244 "bgpTimerConfiguredConditionalAdvertisementsSec",
13245 bgp->condition_check_period);
13246 if (thread_is_scheduled(bgp->t_condition_check))
13247 json_object_int_add(
13248 json_neigh,
13249 "bgpTimerUntilConditionalAdvertisementsSec",
13250 thread_timer_remain_second(
13251 bgp->t_condition_check));
13252 } else {
13253 /* Administrative shutdown. */
13254 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13255 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13256 vty_out(vty, " Administratively shut down\n");
13257
13258 /* BGP Version. */
13259 vty_out(vty, " BGP version 4");
13260 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13261 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13262
13263 /* Confederation */
13264 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13265 && bgp_confederation_peers_check(bgp, p->as))
13266 vty_out(vty,
13267 " Neighbor under common administration\n");
13268
13269 /* Status. */
13270 vty_out(vty, " BGP state = %s",
13271 lookup_msg(bgp_status_msg, p->status, NULL));
13272
13273 if (peer_established(p))
13274 vty_out(vty, ", up for %8s",
13275 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13276 0, NULL));
13277
13278 else if (p->status == Active) {
13279 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13280 vty_out(vty, " (passive)");
13281 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13282 vty_out(vty, " (NSF passive)");
13283 }
13284 vty_out(vty, "\n");
13285
13286 /* read timer */
13287 vty_out(vty, " Last read %s",
13288 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13289 NULL));
13290 vty_out(vty, ", Last write %s\n",
13291 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13292 NULL));
13293
13294 /* Configured timer values. */
13295 vty_out(vty,
13296 " Hold time is %d seconds, keepalive interval is %d seconds\n",
13297 p->v_holdtime, p->v_keepalive);
13298 vty_out(vty, " Configured hold time is %d seconds",
13299 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13300 ? p->holdtime
13301 : bgp->default_holdtime);
13302 vty_out(vty, ", keepalive interval is %d seconds\n",
13303 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13304 ? p->keepalive
13305 : bgp->default_keepalive);
13306 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13307 vty_out(vty,
13308 " Configured DelayOpenTime is %d seconds\n",
13309 p->delayopen);
13310
13311 /* Configured and synced tcp-mss value for peer */
13312 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13313 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13314 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13315 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13316 }
13317
13318 /* Extended Optional Parameters Length for BGP OPEN Message */
13319 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13320 vty_out(vty,
13321 " Extended Optional Parameters Length is enabled\n");
13322
13323 /* Conditional advertisements */
13324 vty_out(vty,
13325 " Configured conditional advertisements interval is %d seconds\n",
13326 bgp->condition_check_period);
13327 if (thread_is_scheduled(bgp->t_condition_check))
13328 vty_out(vty,
13329 " Time until conditional advertisements begin is %lu seconds\n",
13330 thread_timer_remain_second(
13331 bgp->t_condition_check));
13332 }
13333 /* Capability. */
13334 if (peer_established(p) &&
13335 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13336 if (use_json) {
13337 json_object *json_cap = NULL;
13338
13339 json_cap = json_object_new_object();
13340
13341 /* AS4 */
13342 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13343 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13344 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13345 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13346 json_object_string_add(
13347 json_cap, "4byteAs",
13348 "advertisedAndReceived");
13349 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13350 json_object_string_add(json_cap,
13351 "4byteAs",
13352 "advertised");
13353 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13354 json_object_string_add(json_cap,
13355 "4byteAs",
13356 "received");
13357 }
13358
13359 /* Extended Message Support */
13360 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13361 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13362 json_object_string_add(json_cap,
13363 "extendedMessage",
13364 "advertisedAndReceived");
13365 else if (CHECK_FLAG(p->cap,
13366 PEER_CAP_EXTENDED_MESSAGE_ADV))
13367 json_object_string_add(json_cap,
13368 "extendedMessage",
13369 "advertised");
13370 else if (CHECK_FLAG(p->cap,
13371 PEER_CAP_EXTENDED_MESSAGE_RCV))
13372 json_object_string_add(json_cap,
13373 "extendedMessage",
13374 "received");
13375
13376 /* AddPath */
13377 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13378 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13379 json_object *json_add = NULL;
13380 const char *print_store;
13381
13382 json_add = json_object_new_object();
13383
13384 FOREACH_AFI_SAFI (afi, safi) {
13385 json_object *json_sub = NULL;
13386 json_sub = json_object_new_object();
13387 print_store = get_afi_safi_str(
13388 afi, safi, true);
13389
13390 if (CHECK_FLAG(
13391 p->af_cap[afi][safi],
13392 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13393 CHECK_FLAG(
13394 p->af_cap[afi][safi],
13395 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13396 if (CHECK_FLAG(
13397 p->af_cap[afi]
13398 [safi],
13399 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13400 CHECK_FLAG(
13401 p->af_cap[afi]
13402 [safi],
13403 PEER_CAP_ADDPATH_AF_TX_RCV))
13404 json_object_boolean_true_add(
13405 json_sub,
13406 "txAdvertisedAndReceived");
13407 else if (
13408 CHECK_FLAG(
13409 p->af_cap[afi]
13410 [safi],
13411 PEER_CAP_ADDPATH_AF_TX_ADV))
13412 json_object_boolean_true_add(
13413 json_sub,
13414 "txAdvertised");
13415 else if (
13416 CHECK_FLAG(
13417 p->af_cap[afi]
13418 [safi],
13419 PEER_CAP_ADDPATH_AF_TX_RCV))
13420 json_object_boolean_true_add(
13421 json_sub,
13422 "txReceived");
13423 }
13424
13425 if (CHECK_FLAG(
13426 p->af_cap[afi][safi],
13427 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13428 CHECK_FLAG(
13429 p->af_cap[afi][safi],
13430 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13431 if (CHECK_FLAG(
13432 p->af_cap[afi]
13433 [safi],
13434 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13435 CHECK_FLAG(
13436 p->af_cap[afi]
13437 [safi],
13438 PEER_CAP_ADDPATH_AF_RX_RCV))
13439 json_object_boolean_true_add(
13440 json_sub,
13441 "rxAdvertisedAndReceived");
13442 else if (
13443 CHECK_FLAG(
13444 p->af_cap[afi]
13445 [safi],
13446 PEER_CAP_ADDPATH_AF_RX_ADV))
13447 json_object_boolean_true_add(
13448 json_sub,
13449 "rxAdvertised");
13450 else if (
13451 CHECK_FLAG(
13452 p->af_cap[afi]
13453 [safi],
13454 PEER_CAP_ADDPATH_AF_RX_RCV))
13455 json_object_boolean_true_add(
13456 json_sub,
13457 "rxReceived");
13458 }
13459
13460 if (CHECK_FLAG(
13461 p->af_cap[afi][safi],
13462 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13463 CHECK_FLAG(
13464 p->af_cap[afi][safi],
13465 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13466 CHECK_FLAG(
13467 p->af_cap[afi][safi],
13468 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13469 CHECK_FLAG(
13470 p->af_cap[afi][safi],
13471 PEER_CAP_ADDPATH_AF_RX_RCV))
13472 json_object_object_add(
13473 json_add, print_store,
13474 json_sub);
13475 else
13476 json_object_free(json_sub);
13477 }
13478
13479 json_object_object_add(json_cap, "addPath",
13480 json_add);
13481 }
13482
13483 /* Dynamic */
13484 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13485 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13486 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13487 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13488 json_object_string_add(
13489 json_cap, "dynamic",
13490 "advertisedAndReceived");
13491 else if (CHECK_FLAG(p->cap,
13492 PEER_CAP_DYNAMIC_ADV))
13493 json_object_string_add(json_cap,
13494 "dynamic",
13495 "advertised");
13496 else if (CHECK_FLAG(p->cap,
13497 PEER_CAP_DYNAMIC_RCV))
13498 json_object_string_add(json_cap,
13499 "dynamic",
13500 "received");
13501 }
13502
13503 /* Role */
13504 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13505 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13506 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13507 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13508 json_object_string_add(
13509 json_cap, "role",
13510 "advertisedAndReceived");
13511 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13512 json_object_string_add(json_cap, "role",
13513 "advertised");
13514 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13515 json_object_string_add(json_cap, "role",
13516 "received");
13517 }
13518
13519 /* Extended nexthop */
13520 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13521 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13522 json_object *json_nxt = NULL;
13523 const char *print_store;
13524
13525
13526 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13527 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13528 json_object_string_add(
13529 json_cap, "extendedNexthop",
13530 "advertisedAndReceived");
13531 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13532 json_object_string_add(
13533 json_cap, "extendedNexthop",
13534 "advertised");
13535 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13536 json_object_string_add(
13537 json_cap, "extendedNexthop",
13538 "received");
13539
13540 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13541 json_nxt = json_object_new_object();
13542
13543 for (safi = SAFI_UNICAST;
13544 safi < SAFI_MAX; safi++) {
13545 if (CHECK_FLAG(
13546 p->af_cap[AFI_IP]
13547 [safi],
13548 PEER_CAP_ENHE_AF_RCV)) {
13549 print_store =
13550 get_afi_safi_str(
13551 AFI_IP,
13552 safi,
13553 true);
13554 json_object_string_add(
13555 json_nxt,
13556 print_store,
13557 "recieved"); /* misspelled for compatibility */
13558 }
13559 }
13560 json_object_object_add(
13561 json_cap,
13562 "extendedNexthopFamililesByPeer",
13563 json_nxt);
13564 }
13565 }
13566
13567 /* Long-lived Graceful Restart */
13568 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13569 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13570 json_object *json_llgr = NULL;
13571 const char *afi_safi_str;
13572
13573 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13574 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13575 json_object_string_add(
13576 json_cap,
13577 "longLivedGracefulRestart",
13578 "advertisedAndReceived");
13579 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13580 json_object_string_add(
13581 json_cap,
13582 "longLivedGracefulRestart",
13583 "advertised");
13584 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13585 json_object_string_add(
13586 json_cap,
13587 "longLivedGracefulRestart",
13588 "received");
13589
13590 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13591 json_llgr = json_object_new_object();
13592
13593 FOREACH_AFI_SAFI (afi, safi) {
13594 if (CHECK_FLAG(
13595 p->af_cap[afi]
13596 [safi],
13597 PEER_CAP_ENHE_AF_RCV)) {
13598 afi_safi_str =
13599 get_afi_safi_str(
13600 afi,
13601 safi,
13602 true);
13603 json_object_string_add(
13604 json_llgr,
13605 afi_safi_str,
13606 "received");
13607 }
13608 }
13609 json_object_object_add(
13610 json_cap,
13611 "longLivedGracefulRestartByPeer",
13612 json_llgr);
13613 }
13614 }
13615
13616 /* Route Refresh */
13617 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13618 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13619 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13620 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13621 (CHECK_FLAG(p->cap,
13622 PEER_CAP_REFRESH_NEW_RCV) ||
13623 CHECK_FLAG(p->cap,
13624 PEER_CAP_REFRESH_OLD_RCV))) {
13625 if (CHECK_FLAG(
13626 p->cap,
13627 PEER_CAP_REFRESH_OLD_RCV) &&
13628 CHECK_FLAG(
13629 p->cap,
13630 PEER_CAP_REFRESH_NEW_RCV))
13631 json_object_string_add(
13632 json_cap,
13633 "routeRefresh",
13634 "advertisedAndReceivedOldNew");
13635 else {
13636 if (CHECK_FLAG(
13637 p->cap,
13638 PEER_CAP_REFRESH_OLD_RCV))
13639 json_object_string_add(
13640 json_cap,
13641 "routeRefresh",
13642 "advertisedAndReceivedOld");
13643 else
13644 json_object_string_add(
13645 json_cap,
13646 "routeRefresh",
13647 "advertisedAndReceivedNew");
13648 }
13649 } else if (CHECK_FLAG(p->cap,
13650 PEER_CAP_REFRESH_ADV))
13651 json_object_string_add(json_cap,
13652 "routeRefresh",
13653 "advertised");
13654 else if (CHECK_FLAG(p->cap,
13655 PEER_CAP_REFRESH_NEW_RCV) ||
13656 CHECK_FLAG(p->cap,
13657 PEER_CAP_REFRESH_OLD_RCV))
13658 json_object_string_add(json_cap,
13659 "routeRefresh",
13660 "received");
13661 }
13662
13663 /* Enhanced Route Refresh */
13664 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13665 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13666 if (CHECK_FLAG(p->cap,
13667 PEER_CAP_ENHANCED_RR_ADV) &&
13668 CHECK_FLAG(p->cap,
13669 PEER_CAP_ENHANCED_RR_RCV))
13670 json_object_string_add(
13671 json_cap,
13672 "enhancedRouteRefresh",
13673 "advertisedAndReceived");
13674 else if (CHECK_FLAG(p->cap,
13675 PEER_CAP_ENHANCED_RR_ADV))
13676 json_object_string_add(
13677 json_cap,
13678 "enhancedRouteRefresh",
13679 "advertised");
13680 else if (CHECK_FLAG(p->cap,
13681 PEER_CAP_ENHANCED_RR_RCV))
13682 json_object_string_add(
13683 json_cap,
13684 "enhancedRouteRefresh",
13685 "received");
13686 }
13687
13688 /* Multiprotocol Extensions */
13689 json_object *json_multi = NULL;
13690
13691 json_multi = json_object_new_object();
13692
13693 FOREACH_AFI_SAFI (afi, safi) {
13694 if (p->afc_adv[afi][safi] ||
13695 p->afc_recv[afi][safi]) {
13696 json_object *json_exten = NULL;
13697 json_exten = json_object_new_object();
13698
13699 if (p->afc_adv[afi][safi] &&
13700 p->afc_recv[afi][safi])
13701 json_object_boolean_true_add(
13702 json_exten,
13703 "advertisedAndReceived");
13704 else if (p->afc_adv[afi][safi])
13705 json_object_boolean_true_add(
13706 json_exten,
13707 "advertised");
13708 else if (p->afc_recv[afi][safi])
13709 json_object_boolean_true_add(
13710 json_exten, "received");
13711
13712 json_object_object_add(
13713 json_multi,
13714 get_afi_safi_str(afi, safi,
13715 true),
13716 json_exten);
13717 }
13718 }
13719 json_object_object_add(json_cap,
13720 "multiprotocolExtensions",
13721 json_multi);
13722
13723 /* Hostname capabilities */
13724 json_object *json_hname = NULL;
13725
13726 json_hname = json_object_new_object();
13727
13728 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13729 json_object_string_add(
13730 json_hname, "advHostName",
13731 bgp->peer_self->hostname
13732 ? bgp->peer_self->hostname
13733 : "n/a");
13734 json_object_string_add(
13735 json_hname, "advDomainName",
13736 bgp->peer_self->domainname
13737 ? bgp->peer_self->domainname
13738 : "n/a");
13739 }
13740
13741
13742 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13743 json_object_string_add(
13744 json_hname, "rcvHostName",
13745 p->hostname ? p->hostname : "n/a");
13746 json_object_string_add(
13747 json_hname, "rcvDomainName",
13748 p->domainname ? p->domainname : "n/a");
13749 }
13750
13751 json_object_object_add(json_cap, "hostName",
13752 json_hname);
13753
13754 /* Graceful Restart */
13755 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13756 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13757 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13758 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13759 json_object_string_add(
13760 json_cap, "gracefulRestart",
13761 "advertisedAndReceived");
13762 else if (CHECK_FLAG(p->cap,
13763 PEER_CAP_RESTART_ADV))
13764 json_object_string_add(
13765 json_cap,
13766 "gracefulRestartCapability",
13767 "advertised");
13768 else if (CHECK_FLAG(p->cap,
13769 PEER_CAP_RESTART_RCV))
13770 json_object_string_add(
13771 json_cap,
13772 "gracefulRestartCapability",
13773 "received");
13774
13775 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13776 int restart_af_count = 0;
13777 json_object *json_restart = NULL;
13778 json_restart = json_object_new_object();
13779
13780 json_object_int_add(
13781 json_cap,
13782 "gracefulRestartRemoteTimerMsecs",
13783 p->v_gr_restart * 1000);
13784
13785 FOREACH_AFI_SAFI (afi, safi) {
13786 if (CHECK_FLAG(
13787 p->af_cap[afi]
13788 [safi],
13789 PEER_CAP_RESTART_AF_RCV)) {
13790 json_object *json_sub =
13791 NULL;
13792 json_sub =
13793 json_object_new_object();
13794
13795 if (CHECK_FLAG(
13796 p->af_cap
13797 [afi]
13798 [safi],
13799 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13800 json_object_boolean_true_add(
13801 json_sub,
13802 "preserved");
13803 restart_af_count++;
13804 json_object_object_add(
13805 json_restart,
13806 get_afi_safi_str(
13807 afi,
13808 safi,
13809 true),
13810 json_sub);
13811 }
13812 }
13813 if (!restart_af_count) {
13814 json_object_string_add(
13815 json_cap,
13816 "addressFamiliesByPeer",
13817 "none");
13818 json_object_free(json_restart);
13819 } else
13820 json_object_object_add(
13821 json_cap,
13822 "addressFamiliesByPeer",
13823 json_restart);
13824 }
13825 }
13826 json_object_object_add(
13827 json_neigh, "neighborCapabilities", json_cap);
13828 } else {
13829 vty_out(vty, " Neighbor capabilities:\n");
13830
13831 /* AS4 */
13832 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13833 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13834 vty_out(vty, " 4 Byte AS:");
13835 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13836 vty_out(vty, " advertised");
13837 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13838 vty_out(vty, " %sreceived",
13839 CHECK_FLAG(p->cap,
13840 PEER_CAP_AS4_ADV)
13841 ? "and "
13842 : "");
13843 vty_out(vty, "\n");
13844 }
13845
13846 /* Extended Message Support */
13847 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13848 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13849 vty_out(vty, " Extended Message:");
13850 if (CHECK_FLAG(p->cap,
13851 PEER_CAP_EXTENDED_MESSAGE_ADV))
13852 vty_out(vty, " advertised");
13853 if (CHECK_FLAG(p->cap,
13854 PEER_CAP_EXTENDED_MESSAGE_RCV))
13855 vty_out(vty, " %sreceived",
13856 CHECK_FLAG(
13857 p->cap,
13858 PEER_CAP_EXTENDED_MESSAGE_ADV)
13859 ? "and "
13860 : "");
13861 vty_out(vty, "\n");
13862 }
13863
13864 /* AddPath */
13865 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13866 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13867 vty_out(vty, " AddPath:\n");
13868
13869 FOREACH_AFI_SAFI (afi, safi) {
13870 if (CHECK_FLAG(
13871 p->af_cap[afi][safi],
13872 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13873 CHECK_FLAG(
13874 p->af_cap[afi][safi],
13875 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13876 vty_out(vty, " %s: TX ",
13877 get_afi_safi_str(
13878 afi, safi,
13879 false));
13880
13881 if (CHECK_FLAG(
13882 p->af_cap[afi]
13883 [safi],
13884 PEER_CAP_ADDPATH_AF_TX_ADV))
13885 vty_out(vty,
13886 "advertised");
13887
13888 if (CHECK_FLAG(
13889 p->af_cap[afi]
13890 [safi],
13891 PEER_CAP_ADDPATH_AF_TX_RCV))
13892 vty_out(vty,
13893 "%sreceived",
13894 CHECK_FLAG(
13895 p->af_cap
13896 [afi]
13897 [safi],
13898 PEER_CAP_ADDPATH_AF_TX_ADV)
13899 ? " and "
13900 : "");
13901
13902 vty_out(vty, "\n");
13903 }
13904
13905 if (CHECK_FLAG(
13906 p->af_cap[afi][safi],
13907 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13908 CHECK_FLAG(
13909 p->af_cap[afi][safi],
13910 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13911 vty_out(vty, " %s: RX ",
13912 get_afi_safi_str(
13913 afi, safi,
13914 false));
13915
13916 if (CHECK_FLAG(
13917 p->af_cap[afi]
13918 [safi],
13919 PEER_CAP_ADDPATH_AF_RX_ADV))
13920 vty_out(vty,
13921 "advertised");
13922
13923 if (CHECK_FLAG(
13924 p->af_cap[afi]
13925 [safi],
13926 PEER_CAP_ADDPATH_AF_RX_RCV))
13927 vty_out(vty,
13928 "%sreceived",
13929 CHECK_FLAG(
13930 p->af_cap
13931 [afi]
13932 [safi],
13933 PEER_CAP_ADDPATH_AF_RX_ADV)
13934 ? " and "
13935 : "");
13936
13937 vty_out(vty, "\n");
13938 }
13939 }
13940 }
13941
13942 /* Dynamic */
13943 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13944 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13945 vty_out(vty, " Dynamic:");
13946 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13947 vty_out(vty, " advertised");
13948 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13949 vty_out(vty, " %sreceived",
13950 CHECK_FLAG(p->cap,
13951 PEER_CAP_DYNAMIC_ADV)
13952 ? "and "
13953 : "");
13954 vty_out(vty, "\n");
13955 }
13956
13957 /* Role */
13958 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13959 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13960 vty_out(vty, " Role:");
13961 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13962 vty_out(vty, " advertised");
13963 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13964 vty_out(vty, " %sreceived",
13965 CHECK_FLAG(p->cap,
13966 PEER_CAP_ROLE_ADV)
13967 ? "and "
13968 : "");
13969 vty_out(vty, "\n");
13970 }
13971
13972 /* Extended nexthop */
13973 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13974 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13975 vty_out(vty, " Extended nexthop:");
13976 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13977 vty_out(vty, " advertised");
13978 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13979 vty_out(vty, " %sreceived",
13980 CHECK_FLAG(p->cap,
13981 PEER_CAP_ENHE_ADV)
13982 ? "and "
13983 : "");
13984 vty_out(vty, "\n");
13985
13986 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13987 vty_out(vty,
13988 " Address families by peer:\n ");
13989 for (safi = SAFI_UNICAST;
13990 safi < SAFI_MAX; safi++)
13991 if (CHECK_FLAG(
13992 p->af_cap[AFI_IP]
13993 [safi],
13994 PEER_CAP_ENHE_AF_RCV))
13995 vty_out(vty,
13996 " %s\n",
13997 get_afi_safi_str(
13998 AFI_IP,
13999 safi,
14000 false));
14001 }
14002 }
14003
14004 /* Long-lived Graceful Restart */
14005 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14006 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14007 vty_out(vty,
14008 " Long-lived Graceful Restart:");
14009 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14010 vty_out(vty, " advertised");
14011 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14012 vty_out(vty, " %sreceived",
14013 CHECK_FLAG(p->cap,
14014 PEER_CAP_LLGR_ADV)
14015 ? "and "
14016 : "");
14017 vty_out(vty, "\n");
14018
14019 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14020 vty_out(vty,
14021 " Address families by peer:\n");
14022 FOREACH_AFI_SAFI (afi, safi)
14023 if (CHECK_FLAG(
14024 p->af_cap[afi]
14025 [safi],
14026 PEER_CAP_LLGR_AF_RCV))
14027 vty_out(vty,
14028 " %s\n",
14029 get_afi_safi_str(
14030 afi,
14031 safi,
14032 false));
14033 }
14034 }
14035
14036 /* Route Refresh */
14037 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14038 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14039 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14040 vty_out(vty, " Route refresh:");
14041 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14042 vty_out(vty, " advertised");
14043 if (CHECK_FLAG(p->cap,
14044 PEER_CAP_REFRESH_NEW_RCV) ||
14045 CHECK_FLAG(p->cap,
14046 PEER_CAP_REFRESH_OLD_RCV))
14047 vty_out(vty, " %sreceived(%s)",
14048 CHECK_FLAG(p->cap,
14049 PEER_CAP_REFRESH_ADV)
14050 ? "and "
14051 : "",
14052 (CHECK_FLAG(
14053 p->cap,
14054 PEER_CAP_REFRESH_OLD_RCV) &&
14055 CHECK_FLAG(
14056 p->cap,
14057 PEER_CAP_REFRESH_NEW_RCV))
14058 ? "old & new"
14059 : CHECK_FLAG(
14060 p->cap,
14061 PEER_CAP_REFRESH_OLD_RCV)
14062 ? "old"
14063 : "new");
14064
14065 vty_out(vty, "\n");
14066 }
14067
14068 /* Enhanced Route Refresh */
14069 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14070 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14071 vty_out(vty, " Enhanced Route Refresh:");
14072 if (CHECK_FLAG(p->cap,
14073 PEER_CAP_ENHANCED_RR_ADV))
14074 vty_out(vty, " advertised");
14075 if (CHECK_FLAG(p->cap,
14076 PEER_CAP_ENHANCED_RR_RCV))
14077 vty_out(vty, " %sreceived",
14078 CHECK_FLAG(p->cap,
14079 PEER_CAP_REFRESH_ADV)
14080 ? "and "
14081 : "");
14082 vty_out(vty, "\n");
14083 }
14084
14085 /* Multiprotocol Extensions */
14086 FOREACH_AFI_SAFI (afi, safi)
14087 if (p->afc_adv[afi][safi] ||
14088 p->afc_recv[afi][safi]) {
14089 vty_out(vty, " Address Family %s:",
14090 get_afi_safi_str(afi, safi,
14091 false));
14092 if (p->afc_adv[afi][safi])
14093 vty_out(vty, " advertised");
14094 if (p->afc_recv[afi][safi])
14095 vty_out(vty, " %sreceived",
14096 p->afc_adv[afi][safi]
14097 ? "and "
14098 : "");
14099 vty_out(vty, "\n");
14100 }
14101
14102 /* Hostname capability */
14103 vty_out(vty, " Hostname Capability:");
14104
14105 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14106 vty_out(vty,
14107 " advertised (name: %s,domain name: %s)",
14108 bgp->peer_self->hostname
14109 ? bgp->peer_self->hostname
14110 : "n/a",
14111 bgp->peer_self->domainname
14112 ? bgp->peer_self->domainname
14113 : "n/a");
14114 } else {
14115 vty_out(vty, " not advertised");
14116 }
14117
14118 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14119 vty_out(vty,
14120 " received (name: %s,domain name: %s)",
14121 p->hostname ? p->hostname : "n/a",
14122 p->domainname ? p->domainname : "n/a");
14123 } else {
14124 vty_out(vty, " not received");
14125 }
14126
14127 vty_out(vty, "\n");
14128
14129 /* Graceful Restart */
14130 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14131 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14132 vty_out(vty,
14133 " Graceful Restart Capability:");
14134 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14135 vty_out(vty, " advertised");
14136 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14137 vty_out(vty, " %sreceived",
14138 CHECK_FLAG(p->cap,
14139 PEER_CAP_RESTART_ADV)
14140 ? "and "
14141 : "");
14142 vty_out(vty, "\n");
14143
14144 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14145 int restart_af_count = 0;
14146
14147 vty_out(vty,
14148 " Remote Restart timer is %d seconds\n",
14149 p->v_gr_restart);
14150 vty_out(vty,
14151 " Address families by peer:\n ");
14152
14153 FOREACH_AFI_SAFI (afi, safi)
14154 if (CHECK_FLAG(
14155 p->af_cap[afi]
14156 [safi],
14157 PEER_CAP_RESTART_AF_RCV)) {
14158 vty_out(vty, "%s%s(%s)",
14159 restart_af_count
14160 ? ", "
14161 : "",
14162 get_afi_safi_str(
14163 afi,
14164 safi,
14165 false),
14166 CHECK_FLAG(
14167 p->af_cap
14168 [afi]
14169 [safi],
14170 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14171 ? "preserved"
14172 : "not preserved");
14173 restart_af_count++;
14174 }
14175 if (!restart_af_count)
14176 vty_out(vty, "none");
14177 vty_out(vty, "\n");
14178 }
14179 } /* Graceful Restart */
14180 }
14181 }
14182
14183 /* graceful restart information */
14184 json_object *json_grace = NULL;
14185 json_object *json_grace_send = NULL;
14186 json_object *json_grace_recv = NULL;
14187 int eor_send_af_count = 0;
14188 int eor_receive_af_count = 0;
14189
14190 if (use_json) {
14191 json_grace = json_object_new_object();
14192 json_grace_send = json_object_new_object();
14193 json_grace_recv = json_object_new_object();
14194
14195 if ((peer_established(p)) &&
14196 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14197 FOREACH_AFI_SAFI (afi, safi) {
14198 if (CHECK_FLAG(p->af_sflags[afi][safi],
14199 PEER_STATUS_EOR_SEND)) {
14200 json_object_boolean_true_add(
14201 json_grace_send,
14202 get_afi_safi_str(afi, safi,
14203 true));
14204 eor_send_af_count++;
14205 }
14206 }
14207 FOREACH_AFI_SAFI (afi, safi) {
14208 if (CHECK_FLAG(p->af_sflags[afi][safi],
14209 PEER_STATUS_EOR_RECEIVED)) {
14210 json_object_boolean_true_add(
14211 json_grace_recv,
14212 get_afi_safi_str(afi, safi,
14213 true));
14214 eor_receive_af_count++;
14215 }
14216 }
14217 }
14218 json_object_object_add(json_grace, "endOfRibSend",
14219 json_grace_send);
14220 json_object_object_add(json_grace, "endOfRibRecv",
14221 json_grace_recv);
14222
14223
14224 if (p->t_gr_restart)
14225 json_object_int_add(
14226 json_grace, "gracefulRestartTimerMsecs",
14227 thread_timer_remain_second(p->t_gr_restart) *
14228 1000);
14229
14230 if (p->t_gr_stale)
14231 json_object_int_add(
14232 json_grace, "gracefulStalepathTimerMsecs",
14233 thread_timer_remain_second(p->t_gr_stale) *
14234 1000);
14235 /* more gr info in new format */
14236 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14237 json_object_object_add(json_neigh, "gracefulRestartInfo",
14238 json_grace);
14239 } else {
14240 vty_out(vty, " Graceful restart information:\n");
14241 if ((peer_established(p)) &&
14242 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14243
14244 vty_out(vty, " End-of-RIB send: ");
14245 FOREACH_AFI_SAFI (afi, safi) {
14246 if (CHECK_FLAG(p->af_sflags[afi][safi],
14247 PEER_STATUS_EOR_SEND)) {
14248 vty_out(vty, "%s%s",
14249 eor_send_af_count ? ", " : "",
14250 get_afi_safi_str(afi, safi,
14251 false));
14252 eor_send_af_count++;
14253 }
14254 }
14255 vty_out(vty, "\n");
14256 vty_out(vty, " End-of-RIB received: ");
14257 FOREACH_AFI_SAFI (afi, safi) {
14258 if (CHECK_FLAG(p->af_sflags[afi][safi],
14259 PEER_STATUS_EOR_RECEIVED)) {
14260 vty_out(vty, "%s%s",
14261 eor_receive_af_count ? ", "
14262 : "",
14263 get_afi_safi_str(afi, safi,
14264 false));
14265 eor_receive_af_count++;
14266 }
14267 }
14268 vty_out(vty, "\n");
14269 }
14270
14271 if (p->t_gr_restart)
14272 vty_out(vty,
14273 " The remaining time of restart timer is %ld\n",
14274 thread_timer_remain_second(p->t_gr_restart));
14275
14276 if (p->t_gr_stale)
14277 vty_out(vty,
14278 " The remaining time of stalepath timer is %ld\n",
14279 thread_timer_remain_second(p->t_gr_stale));
14280
14281 /* more gr info in new format */
14282 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14283 }
14284
14285 if (use_json) {
14286 json_object *json_stat = NULL;
14287 json_stat = json_object_new_object();
14288 /* Packet counts. */
14289
14290 atomic_size_t outq_count, inq_count;
14291 outq_count = atomic_load_explicit(&p->obuf->count,
14292 memory_order_relaxed);
14293 inq_count = atomic_load_explicit(&p->ibuf->count,
14294 memory_order_relaxed);
14295
14296 json_object_int_add(json_stat, "depthInq",
14297 (unsigned long)inq_count);
14298 json_object_int_add(json_stat, "depthOutq",
14299 (unsigned long)outq_count);
14300 json_object_int_add(json_stat, "opensSent",
14301 atomic_load_explicit(&p->open_out,
14302 memory_order_relaxed));
14303 json_object_int_add(json_stat, "opensRecv",
14304 atomic_load_explicit(&p->open_in,
14305 memory_order_relaxed));
14306 json_object_int_add(json_stat, "notificationsSent",
14307 atomic_load_explicit(&p->notify_out,
14308 memory_order_relaxed));
14309 json_object_int_add(json_stat, "notificationsRecv",
14310 atomic_load_explicit(&p->notify_in,
14311 memory_order_relaxed));
14312 json_object_int_add(json_stat, "updatesSent",
14313 atomic_load_explicit(&p->update_out,
14314 memory_order_relaxed));
14315 json_object_int_add(json_stat, "updatesRecv",
14316 atomic_load_explicit(&p->update_in,
14317 memory_order_relaxed));
14318 json_object_int_add(json_stat, "keepalivesSent",
14319 atomic_load_explicit(&p->keepalive_out,
14320 memory_order_relaxed));
14321 json_object_int_add(json_stat, "keepalivesRecv",
14322 atomic_load_explicit(&p->keepalive_in,
14323 memory_order_relaxed));
14324 json_object_int_add(json_stat, "routeRefreshSent",
14325 atomic_load_explicit(&p->refresh_out,
14326 memory_order_relaxed));
14327 json_object_int_add(json_stat, "routeRefreshRecv",
14328 atomic_load_explicit(&p->refresh_in,
14329 memory_order_relaxed));
14330 json_object_int_add(json_stat, "capabilitySent",
14331 atomic_load_explicit(&p->dynamic_cap_out,
14332 memory_order_relaxed));
14333 json_object_int_add(json_stat, "capabilityRecv",
14334 atomic_load_explicit(&p->dynamic_cap_in,
14335 memory_order_relaxed));
14336 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14337 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14338 json_object_object_add(json_neigh, "messageStats", json_stat);
14339 } else {
14340 atomic_size_t outq_count, inq_count, open_out, open_in,
14341 notify_out, notify_in, update_out, update_in,
14342 keepalive_out, keepalive_in, refresh_out, refresh_in,
14343 dynamic_cap_out, dynamic_cap_in;
14344 outq_count = atomic_load_explicit(&p->obuf->count,
14345 memory_order_relaxed);
14346 inq_count = atomic_load_explicit(&p->ibuf->count,
14347 memory_order_relaxed);
14348 open_out = atomic_load_explicit(&p->open_out,
14349 memory_order_relaxed);
14350 open_in =
14351 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14352 notify_out = atomic_load_explicit(&p->notify_out,
14353 memory_order_relaxed);
14354 notify_in = atomic_load_explicit(&p->notify_in,
14355 memory_order_relaxed);
14356 update_out = atomic_load_explicit(&p->update_out,
14357 memory_order_relaxed);
14358 update_in = atomic_load_explicit(&p->update_in,
14359 memory_order_relaxed);
14360 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14361 memory_order_relaxed);
14362 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14363 memory_order_relaxed);
14364 refresh_out = atomic_load_explicit(&p->refresh_out,
14365 memory_order_relaxed);
14366 refresh_in = atomic_load_explicit(&p->refresh_in,
14367 memory_order_relaxed);
14368 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14369 memory_order_relaxed);
14370 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14371 memory_order_relaxed);
14372
14373 /* Packet counts. */
14374 vty_out(vty, " Message statistics:\n");
14375 vty_out(vty, " Inq depth is %zu\n", inq_count);
14376 vty_out(vty, " Outq depth is %zu\n", outq_count);
14377 vty_out(vty, " Sent Rcvd\n");
14378 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14379 open_in);
14380 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14381 notify_in);
14382 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14383 update_in);
14384 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14385 keepalive_in);
14386 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14387 refresh_in);
14388 vty_out(vty, " Capability: %10zu %10zu\n",
14389 dynamic_cap_out, dynamic_cap_in);
14390 vty_out(vty, " Total: %10u %10u\n",
14391 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14392 }
14393
14394 if (use_json) {
14395 /* advertisement-interval */
14396 json_object_int_add(json_neigh,
14397 "minBtwnAdvertisementRunsTimerMsecs",
14398 p->v_routeadv * 1000);
14399
14400 /* Update-source. */
14401 if (p->update_if || p->update_source) {
14402 if (p->update_if)
14403 json_object_string_add(json_neigh,
14404 "updateSource",
14405 p->update_if);
14406 else if (p->update_source)
14407 json_object_string_addf(json_neigh,
14408 "updateSource", "%pSU",
14409 p->update_source);
14410 }
14411 } else {
14412 /* advertisement-interval */
14413 vty_out(vty,
14414 " Minimum time between advertisement runs is %d seconds\n",
14415 p->v_routeadv);
14416
14417 /* Update-source. */
14418 if (p->update_if || p->update_source) {
14419 vty_out(vty, " Update source is ");
14420 if (p->update_if)
14421 vty_out(vty, "%s", p->update_if);
14422 else if (p->update_source)
14423 vty_out(vty, "%pSU", p->update_source);
14424 vty_out(vty, "\n");
14425 }
14426
14427 vty_out(vty, "\n");
14428 }
14429
14430 /* Address Family Information */
14431 json_object *json_hold = NULL;
14432
14433 if (use_json)
14434 json_hold = json_object_new_object();
14435
14436 FOREACH_AFI_SAFI (afi, safi)
14437 if (p->afc[afi][safi])
14438 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14439 json_hold);
14440
14441 if (use_json) {
14442 json_object_object_add(json_neigh, "addressFamilyInfo",
14443 json_hold);
14444 json_object_int_add(json_neigh, "connectionsEstablished",
14445 p->established);
14446 json_object_int_add(json_neigh, "connectionsDropped",
14447 p->dropped);
14448 } else
14449 vty_out(vty, " Connections established %d; dropped %d\n",
14450 p->established, p->dropped);
14451
14452 if (!p->last_reset) {
14453 if (use_json)
14454 json_object_string_add(json_neigh, "lastReset",
14455 "never");
14456 else
14457 vty_out(vty, " Last reset never\n");
14458 } else {
14459 if (use_json) {
14460 time_t uptime;
14461 struct tm tm;
14462
14463 uptime = monotime(NULL);
14464 uptime -= p->resettime;
14465 gmtime_r(&uptime, &tm);
14466
14467 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14468 (tm.tm_sec * 1000)
14469 + (tm.tm_min * 60000)
14470 + (tm.tm_hour * 3600000));
14471 bgp_show_peer_reset(NULL, p, json_neigh, true);
14472 } else {
14473 vty_out(vty, " Last reset %s, ",
14474 peer_uptime(p->resettime, timebuf,
14475 BGP_UPTIME_LEN, 0, NULL));
14476
14477 bgp_show_peer_reset(vty, p, NULL, false);
14478 if (p->last_reset_cause_size) {
14479 msg = p->last_reset_cause;
14480 vty_out(vty,
14481 " Message received that caused BGP to send a NOTIFICATION:\n ");
14482 for (i = 1; i <= p->last_reset_cause_size;
14483 i++) {
14484 vty_out(vty, "%02X", *msg++);
14485
14486 if (i != p->last_reset_cause_size) {
14487 if (i % 16 == 0) {
14488 vty_out(vty, "\n ");
14489 } else if (i % 4 == 0) {
14490 vty_out(vty, " ");
14491 }
14492 }
14493 }
14494 vty_out(vty, "\n");
14495 }
14496 }
14497 }
14498
14499 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14500 if (use_json)
14501 json_object_boolean_true_add(json_neigh,
14502 "prefixesConfigExceedMax");
14503 else
14504 vty_out(vty,
14505 " Peer had exceeded the max. no. of prefixes configured.\n");
14506
14507 if (p->t_pmax_restart) {
14508 if (use_json) {
14509 json_object_boolean_true_add(
14510 json_neigh, "reducePrefixNumFrom");
14511 json_object_int_add(json_neigh,
14512 "restartInTimerMsec",
14513 thread_timer_remain_second(
14514 p->t_pmax_restart)
14515 * 1000);
14516 } else
14517 vty_out(vty,
14518 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14519 p->host, thread_timer_remain_second(
14520 p->t_pmax_restart));
14521 } else {
14522 if (use_json)
14523 json_object_boolean_true_add(
14524 json_neigh,
14525 "reducePrefixNumAndClearIpBgp");
14526 else
14527 vty_out(vty,
14528 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14529 p->host);
14530 }
14531 }
14532
14533 /* EBGP Multihop and GTSM */
14534 if (p->sort != BGP_PEER_IBGP) {
14535 if (use_json) {
14536 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14537 json_object_int_add(json_neigh,
14538 "externalBgpNbrMaxHopsAway",
14539 p->gtsm_hops);
14540 else
14541 json_object_int_add(json_neigh,
14542 "externalBgpNbrMaxHopsAway",
14543 p->ttl);
14544 } else {
14545 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14546 vty_out(vty,
14547 " External BGP neighbor may be up to %d hops away.\n",
14548 p->gtsm_hops);
14549 else
14550 vty_out(vty,
14551 " External BGP neighbor may be up to %d hops away.\n",
14552 p->ttl);
14553 }
14554 } else {
14555 if (use_json) {
14556 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14557 json_object_int_add(json_neigh,
14558 "internalBgpNbrMaxHopsAway",
14559 p->gtsm_hops);
14560 else
14561 json_object_int_add(json_neigh,
14562 "internalBgpNbrMaxHopsAway",
14563 p->ttl);
14564 } else {
14565 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14566 vty_out(vty,
14567 " Internal BGP neighbor may be up to %d hops away.\n",
14568 p->gtsm_hops);
14569 else
14570 vty_out(vty,
14571 " Internal BGP neighbor may be up to %d hops away.\n",
14572 p->ttl);
14573 }
14574 }
14575
14576 /* Local address. */
14577 if (p->su_local) {
14578 if (use_json) {
14579 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14580 p->su_local);
14581 json_object_int_add(json_neigh, "portLocal",
14582 ntohs(p->su_local->sin.sin_port));
14583 } else
14584 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14585 p->su_local, ntohs(p->su_local->sin.sin_port));
14586 } else {
14587 if (use_json) {
14588 json_object_string_add(json_neigh, "hostLocal",
14589 "Unknown");
14590 json_object_int_add(json_neigh, "portLocal", -1);
14591 }
14592 }
14593
14594 /* Remote address. */
14595 if (p->su_remote) {
14596 if (use_json) {
14597 json_object_string_addf(json_neigh, "hostForeign",
14598 "%pSU", p->su_remote);
14599 json_object_int_add(json_neigh, "portForeign",
14600 ntohs(p->su_remote->sin.sin_port));
14601 } else
14602 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14603 p->su_remote,
14604 ntohs(p->su_remote->sin.sin_port));
14605 } else {
14606 if (use_json) {
14607 json_object_string_add(json_neigh, "hostForeign",
14608 "Unknown");
14609 json_object_int_add(json_neigh, "portForeign", -1);
14610 }
14611 }
14612
14613 /* Nexthop display. */
14614 if (p->su_local) {
14615 if (use_json) {
14616 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14617 &p->nexthop.v4);
14618 json_object_string_addf(json_neigh, "nexthopGlobal",
14619 "%pI6", &p->nexthop.v6_global);
14620 json_object_string_addf(json_neigh, "nexthopLocal",
14621 "%pI6", &p->nexthop.v6_local);
14622 if (p->shared_network)
14623 json_object_string_add(json_neigh,
14624 "bgpConnection",
14625 "sharedNetwork");
14626 else
14627 json_object_string_add(json_neigh,
14628 "bgpConnection",
14629 "nonSharedNetwork");
14630 } else {
14631 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14632 vty_out(vty, "Nexthop global: %pI6\n",
14633 &p->nexthop.v6_global);
14634 vty_out(vty, "Nexthop local: %pI6\n",
14635 &p->nexthop.v6_local);
14636 vty_out(vty, "BGP connection: %s\n",
14637 p->shared_network ? "shared network"
14638 : "non shared network");
14639 }
14640 } else {
14641 if (use_json) {
14642 json_object_string_add(json_neigh, "nexthop",
14643 "Unknown");
14644 json_object_string_add(json_neigh, "nexthopGlobal",
14645 "Unknown");
14646 json_object_string_add(json_neigh, "nexthopLocal",
14647 "Unknown");
14648 json_object_string_add(json_neigh, "bgpConnection",
14649 "Unknown");
14650 }
14651 }
14652
14653 /* Timer information. */
14654 if (use_json) {
14655 json_object_int_add(json_neigh, "connectRetryTimer",
14656 p->v_connect);
14657 if (peer_established(p)) {
14658 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14659 p->rtt);
14660 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14661 json_object_int_add(json_neigh,
14662 "shutdownRttInMsecs",
14663 p->rtt_expected);
14664 json_object_int_add(json_neigh,
14665 "shutdownRttAfterCount",
14666 p->rtt_keepalive_rcv);
14667 }
14668 }
14669 if (p->t_start)
14670 json_object_int_add(
14671 json_neigh, "nextStartTimerDueInMsecs",
14672 thread_timer_remain_second(p->t_start) * 1000);
14673 if (p->t_connect)
14674 json_object_int_add(
14675 json_neigh, "nextConnectTimerDueInMsecs",
14676 thread_timer_remain_second(p->t_connect)
14677 * 1000);
14678 if (p->t_routeadv) {
14679 json_object_int_add(json_neigh, "mraiInterval",
14680 p->v_routeadv);
14681 json_object_int_add(
14682 json_neigh, "mraiTimerExpireInMsecs",
14683 thread_timer_remain_second(p->t_routeadv)
14684 * 1000);
14685 }
14686 if (p->password)
14687 json_object_int_add(json_neigh, "authenticationEnabled",
14688 1);
14689
14690 if (p->t_read)
14691 json_object_string_add(json_neigh, "readThread", "on");
14692 else
14693 json_object_string_add(json_neigh, "readThread", "off");
14694
14695 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14696 json_object_string_add(json_neigh, "writeThread", "on");
14697 else
14698 json_object_string_add(json_neigh, "writeThread",
14699 "off");
14700 } else {
14701 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14702 p->v_connect);
14703 if (peer_established(p)) {
14704 vty_out(vty, "Estimated round trip time: %d ms\n",
14705 p->rtt);
14706 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14707 vty_out(vty,
14708 "Shutdown when RTT > %dms, count > %u\n",
14709 p->rtt_expected, p->rtt_keepalive_rcv);
14710 }
14711 if (p->t_start)
14712 vty_out(vty, "Next start timer due in %ld seconds\n",
14713 thread_timer_remain_second(p->t_start));
14714 if (p->t_connect)
14715 vty_out(vty, "Next connect timer due in %ld seconds\n",
14716 thread_timer_remain_second(p->t_connect));
14717 if (p->t_routeadv)
14718 vty_out(vty,
14719 "MRAI (interval %u) timer expires in %ld seconds\n",
14720 p->v_routeadv,
14721 thread_timer_remain_second(p->t_routeadv));
14722 if (p->password)
14723 vty_out(vty, "Peer Authentication Enabled\n");
14724
14725 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14726 p->t_read ? "on" : "off",
14727 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14728 ? "on"
14729 : "off", p->fd);
14730 }
14731
14732 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14733 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14734 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14735
14736 if (!use_json)
14737 vty_out(vty, "\n");
14738
14739 /* BFD information. */
14740 if (p->bfd_config)
14741 bgp_bfd_show_info(vty, p, json_neigh);
14742
14743 if (use_json) {
14744 if (p->conf_if) /* Configured interface name. */
14745 json_object_object_add(json, p->conf_if, json_neigh);
14746 else /* Configured IP address. */
14747 json_object_object_add(json, p->host, json_neigh);
14748 }
14749 }
14750
14751 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14752 enum show_type type,
14753 union sockunion *su,
14754 const char *conf_if, afi_t afi,
14755 json_object *json)
14756 {
14757 struct listnode *node, *nnode;
14758 struct peer *peer;
14759 bool found = false;
14760 safi_t safi = SAFI_UNICAST;
14761 json_object *json_neighbor = NULL;
14762
14763 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14764
14765 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14766 continue;
14767
14768 if ((peer->afc[afi][safi]) == 0)
14769 continue;
14770
14771 if (json)
14772 json_neighbor = json_object_new_object();
14773
14774 if (type == show_all) {
14775 bgp_show_peer_gr_status(vty, peer, json_neighbor);
14776
14777 if (json)
14778 json_object_object_add(json, peer->host,
14779 json_neighbor);
14780
14781 } else if (type == show_peer) {
14782 if (conf_if) {
14783 if ((peer->conf_if
14784 && !strcmp(peer->conf_if, conf_if))
14785 || (peer->hostname
14786 && !strcmp(peer->hostname, conf_if))) {
14787 found = true;
14788 bgp_show_peer_gr_status(vty, peer,
14789 json_neighbor);
14790 }
14791 } else {
14792 if (sockunion_same(&peer->su, su)) {
14793 found = true;
14794 bgp_show_peer_gr_status(vty, peer,
14795 json_neighbor);
14796 }
14797 }
14798 if (json) {
14799 if (found)
14800 json_object_object_add(json, peer->host,
14801 json_neighbor);
14802 else
14803 json_object_free(json_neighbor);
14804 }
14805 }
14806
14807 if (found)
14808 break;
14809 }
14810
14811 if (type == show_peer && !found) {
14812 if (json)
14813 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14814 else
14815 vty_out(vty, "%% No such neighbor\n");
14816 }
14817
14818 if (!json)
14819 vty_out(vty, "\n");
14820
14821 return CMD_SUCCESS;
14822 }
14823
14824 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14825 enum show_type type, union sockunion *su,
14826 const char *conf_if, bool use_json,
14827 json_object *json)
14828 {
14829 struct listnode *node, *nnode;
14830 struct peer *peer;
14831 int find = 0;
14832 bool nbr_output = false;
14833 afi_t afi = AFI_MAX;
14834 safi_t safi = SAFI_MAX;
14835
14836 if (type == show_ipv4_peer || type == show_ipv4_all) {
14837 afi = AFI_IP;
14838 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14839 afi = AFI_IP6;
14840 }
14841
14842 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14843 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14844 continue;
14845
14846 switch (type) {
14847 case show_all:
14848 bgp_show_peer(vty, peer, use_json, json);
14849 nbr_output = true;
14850 break;
14851 case show_peer:
14852 if (conf_if) {
14853 if ((peer->conf_if
14854 && !strcmp(peer->conf_if, conf_if))
14855 || (peer->hostname
14856 && !strcmp(peer->hostname, conf_if))) {
14857 find = 1;
14858 bgp_show_peer(vty, peer, use_json,
14859 json);
14860 }
14861 } else {
14862 if (sockunion_same(&peer->su, su)) {
14863 find = 1;
14864 bgp_show_peer(vty, peer, use_json,
14865 json);
14866 }
14867 }
14868 break;
14869 case show_ipv4_peer:
14870 case show_ipv6_peer:
14871 FOREACH_SAFI (safi) {
14872 if (peer->afc[afi][safi]) {
14873 if (conf_if) {
14874 if ((peer->conf_if
14875 && !strcmp(peer->conf_if, conf_if))
14876 || (peer->hostname
14877 && !strcmp(peer->hostname, conf_if))) {
14878 find = 1;
14879 bgp_show_peer(vty, peer, use_json,
14880 json);
14881 break;
14882 }
14883 } else {
14884 if (sockunion_same(&peer->su, su)) {
14885 find = 1;
14886 bgp_show_peer(vty, peer, use_json,
14887 json);
14888 break;
14889 }
14890 }
14891 }
14892 }
14893 break;
14894 case show_ipv4_all:
14895 case show_ipv6_all:
14896 FOREACH_SAFI (safi) {
14897 if (peer->afc[afi][safi]) {
14898 bgp_show_peer(vty, peer, use_json, json);
14899 nbr_output = true;
14900 break;
14901 }
14902 }
14903 break;
14904 }
14905 }
14906
14907 if ((type == show_peer || type == show_ipv4_peer ||
14908 type == show_ipv6_peer) && !find) {
14909 if (use_json)
14910 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14911 else
14912 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14913 }
14914
14915 if (type != show_peer && type != show_ipv4_peer &&
14916 type != show_ipv6_peer && !nbr_output && !use_json)
14917 vty_out(vty, "%% No BGP neighbors found\n");
14918
14919 if (use_json) {
14920 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14921 json, JSON_C_TO_STRING_PRETTY));
14922 } else {
14923 vty_out(vty, "\n");
14924 }
14925
14926 return CMD_SUCCESS;
14927 }
14928
14929 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14930 enum show_type type,
14931 const char *ip_str,
14932 afi_t afi, json_object *json)
14933 {
14934
14935 int ret;
14936 struct bgp *bgp;
14937 union sockunion su;
14938
14939 bgp = bgp_get_default();
14940
14941 if (!bgp)
14942 return;
14943
14944 if (!json)
14945 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
14946
14947 if (ip_str) {
14948 ret = str2sockunion(ip_str, &su);
14949 if (ret < 0)
14950 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
14951 ip_str, afi, json);
14952 else
14953 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14954 NULL, afi, json);
14955 } else
14956 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14957 afi, json);
14958 }
14959
14960 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14961 enum show_type type,
14962 const char *ip_str,
14963 bool use_json)
14964 {
14965 struct listnode *node, *nnode;
14966 struct bgp *bgp;
14967 union sockunion su;
14968 json_object *json = NULL;
14969 int ret, is_first = 1;
14970 bool nbr_output = false;
14971
14972 if (use_json)
14973 vty_out(vty, "{\n");
14974
14975 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14976 nbr_output = true;
14977 if (use_json) {
14978 if (!(json = json_object_new_object())) {
14979 flog_err(
14980 EC_BGP_JSON_MEM_ERROR,
14981 "Unable to allocate memory for JSON object");
14982 vty_out(vty,
14983 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14984 return;
14985 }
14986
14987 json_object_int_add(json, "vrfId",
14988 (bgp->vrf_id == VRF_UNKNOWN)
14989 ? -1
14990 : (int64_t)bgp->vrf_id);
14991 json_object_string_add(
14992 json, "vrfName",
14993 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14994 ? VRF_DEFAULT_NAME
14995 : bgp->name);
14996
14997 if (!is_first)
14998 vty_out(vty, ",\n");
14999 else
15000 is_first = 0;
15001
15002 vty_out(vty, "\"%s\":",
15003 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15004 ? VRF_DEFAULT_NAME
15005 : bgp->name);
15006 } else {
15007 vty_out(vty, "\nInstance %s:\n",
15008 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15009 ? VRF_DEFAULT_NAME
15010 : bgp->name);
15011 }
15012
15013 if (type == show_peer || type == show_ipv4_peer ||
15014 type == show_ipv6_peer) {
15015 ret = str2sockunion(ip_str, &su);
15016 if (ret < 0)
15017 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15018 use_json, json);
15019 else
15020 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15021 use_json, json);
15022 } else {
15023 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15024 use_json, json);
15025 }
15026 json_object_free(json);
15027 json = NULL;
15028 }
15029
15030 if (use_json)
15031 vty_out(vty, "}\n");
15032 else if (!nbr_output)
15033 vty_out(vty, "%% BGP instance not found\n");
15034 }
15035
15036 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15037 enum show_type type, const char *ip_str,
15038 bool use_json)
15039 {
15040 int ret;
15041 struct bgp *bgp;
15042 union sockunion su;
15043 json_object *json = NULL;
15044
15045 if (name) {
15046 if (strmatch(name, "all")) {
15047 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15048 use_json);
15049 return CMD_SUCCESS;
15050 } else {
15051 bgp = bgp_lookup_by_name(name);
15052 if (!bgp) {
15053 if (use_json) {
15054 json = json_object_new_object();
15055 vty_json(vty, json);
15056 } else
15057 vty_out(vty,
15058 "%% BGP instance not found\n");
15059
15060 return CMD_WARNING;
15061 }
15062 }
15063 } else {
15064 bgp = bgp_get_default();
15065 }
15066
15067 if (bgp) {
15068 json = json_object_new_object();
15069 if (ip_str) {
15070 ret = str2sockunion(ip_str, &su);
15071 if (ret < 0)
15072 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15073 use_json, json);
15074 else
15075 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15076 use_json, json);
15077 } else {
15078 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15079 json);
15080 }
15081 json_object_free(json);
15082 } else {
15083 if (use_json)
15084 vty_out(vty, "{}\n");
15085 else
15086 vty_out(vty, "%% BGP instance not found\n");
15087 }
15088
15089 return CMD_SUCCESS;
15090 }
15091
15092
15093
15094 /* "show [ip] bgp neighbors graceful-restart" commands. */
15095 DEFUN (show_ip_bgp_neighbors_graceful_restart,
15096 show_ip_bgp_neighbors_graceful_restart_cmd,
15097 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15098 SHOW_STR
15099 BGP_STR
15100 IP_STR
15101 IPV6_STR
15102 NEIGHBOR_STR
15103 "Neighbor to display information about\n"
15104 "Neighbor to display information about\n"
15105 "Neighbor on BGP configured interface\n"
15106 GR_SHOW
15107 JSON_STR)
15108 {
15109 char *sh_arg = NULL;
15110 enum show_type sh_type;
15111 int idx = 0;
15112 afi_t afi = AFI_MAX;
15113 bool uj = use_json(argc, argv);
15114
15115 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15116 afi = AFI_MAX;
15117
15118 idx++;
15119
15120 if (argv_find(argv, argc, "A.B.C.D", &idx)
15121 || argv_find(argv, argc, "X:X::X:X", &idx)
15122 || argv_find(argv, argc, "WORD", &idx)) {
15123 sh_type = show_peer;
15124 sh_arg = argv[idx]->arg;
15125 } else
15126 sh_type = show_all;
15127
15128 if (!argv_find(argv, argc, "graceful-restart", &idx))
15129 return CMD_SUCCESS;
15130
15131
15132 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15133 afi, uj);
15134 }
15135
15136 /* "show [ip] bgp neighbors" commands. */
15137 DEFUN (show_ip_bgp_neighbors,
15138 show_ip_bgp_neighbors_cmd,
15139 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15140 SHOW_STR
15141 IP_STR
15142 BGP_STR
15143 BGP_INSTANCE_HELP_STR
15144 BGP_AF_STR
15145 BGP_AF_STR
15146 "Detailed information on TCP and BGP neighbor connections\n"
15147 "Neighbor to display information about\n"
15148 "Neighbor to display information about\n"
15149 "Neighbor on BGP configured interface\n"
15150 JSON_STR)
15151 {
15152 char *vrf = NULL;
15153 char *sh_arg = NULL;
15154 enum show_type sh_type;
15155 afi_t afi = AFI_MAX;
15156
15157 bool uj = use_json(argc, argv);
15158
15159 int idx = 0;
15160
15161 /* [<vrf> VIEWVRFNAME] */
15162 if (argv_find(argv, argc, "vrf", &idx)) {
15163 vrf = argv[idx + 1]->arg;
15164 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15165 vrf = NULL;
15166 } else if (argv_find(argv, argc, "view", &idx))
15167 /* [<view> VIEWVRFNAME] */
15168 vrf = argv[idx + 1]->arg;
15169
15170 idx++;
15171
15172 if (argv_find(argv, argc, "ipv4", &idx)) {
15173 sh_type = show_ipv4_all;
15174 afi = AFI_IP;
15175 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15176 sh_type = show_ipv6_all;
15177 afi = AFI_IP6;
15178 } else {
15179 sh_type = show_all;
15180 }
15181
15182 if (argv_find(argv, argc, "A.B.C.D", &idx)
15183 || argv_find(argv, argc, "X:X::X:X", &idx)
15184 || argv_find(argv, argc, "WORD", &idx)) {
15185 sh_type = show_peer;
15186 sh_arg = argv[idx]->arg;
15187 }
15188
15189 if (sh_type == show_peer && afi == AFI_IP) {
15190 sh_type = show_ipv4_peer;
15191 } else if (sh_type == show_peer && afi == AFI_IP6) {
15192 sh_type = show_ipv6_peer;
15193 }
15194
15195 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15196 }
15197
15198 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15199 paths' and `show ip mbgp paths'. Those functions results are the
15200 same.*/
15201 DEFUN (show_ip_bgp_paths,
15202 show_ip_bgp_paths_cmd,
15203 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15204 SHOW_STR
15205 IP_STR
15206 BGP_STR
15207 BGP_SAFI_HELP_STR
15208 "Path information\n")
15209 {
15210 vty_out(vty, "Address Refcnt Path\n");
15211 aspath_print_all_vty(vty);
15212 return CMD_SUCCESS;
15213 }
15214
15215 #include "hash.h"
15216
15217 static void community_show_all_iterator(struct hash_bucket *bucket,
15218 struct vty *vty)
15219 {
15220 struct community *com;
15221
15222 com = (struct community *)bucket->data;
15223 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15224 community_str(com, false, false));
15225 }
15226
15227 /* Show BGP's community internal data. */
15228 DEFUN (show_ip_bgp_community_info,
15229 show_ip_bgp_community_info_cmd,
15230 "show [ip] bgp community-info",
15231 SHOW_STR
15232 IP_STR
15233 BGP_STR
15234 "List all bgp community information\n")
15235 {
15236 vty_out(vty, "Address Refcnt Community\n");
15237
15238 hash_iterate(community_hash(),
15239 (void (*)(struct hash_bucket *,
15240 void *))community_show_all_iterator,
15241 vty);
15242
15243 return CMD_SUCCESS;
15244 }
15245
15246 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15247 struct vty *vty)
15248 {
15249 struct lcommunity *lcom;
15250
15251 lcom = (struct lcommunity *)bucket->data;
15252 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15253 lcommunity_str(lcom, false, false));
15254 }
15255
15256 /* Show BGP's community internal data. */
15257 DEFUN (show_ip_bgp_lcommunity_info,
15258 show_ip_bgp_lcommunity_info_cmd,
15259 "show ip bgp large-community-info",
15260 SHOW_STR
15261 IP_STR
15262 BGP_STR
15263 "List all bgp large-community information\n")
15264 {
15265 vty_out(vty, "Address Refcnt Large-community\n");
15266
15267 hash_iterate(lcommunity_hash(),
15268 (void (*)(struct hash_bucket *,
15269 void *))lcommunity_show_all_iterator,
15270 vty);
15271
15272 return CMD_SUCCESS;
15273 }
15274 /* Graceful Restart */
15275
15276 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15277 struct bgp *bgp)
15278 {
15279
15280
15281 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15282
15283 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15284
15285 switch (bgp_global_gr_mode) {
15286
15287 case GLOBAL_HELPER:
15288 vty_out(vty, "Global BGP GR Mode : Helper\n");
15289 break;
15290
15291 case GLOBAL_GR:
15292 vty_out(vty, "Global BGP GR Mode : Restart\n");
15293 break;
15294
15295 case GLOBAL_DISABLE:
15296 vty_out(vty, "Global BGP GR Mode : Disable\n");
15297 break;
15298
15299 case GLOBAL_INVALID:
15300 vty_out(vty,
15301 "Global BGP GR Mode Invalid\n");
15302 break;
15303 }
15304 vty_out(vty, "\n");
15305 }
15306
15307 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15308 enum show_type type,
15309 const char *ip_str,
15310 afi_t afi, bool use_json)
15311 {
15312 json_object *json = NULL;
15313
15314 if (use_json)
15315 json = json_object_new_object();
15316
15317 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15318 afi = AFI_IP;
15319
15320 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15321
15322 bgp_show_neighbor_graceful_restart_vty(
15323 vty, type, ip_str, afi, json);
15324 afi++;
15325 }
15326 } else if (afi != AFI_MAX) {
15327 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15328 json);
15329 } else {
15330 if (json)
15331 json_object_free(json);
15332 return CMD_ERR_INCOMPLETE;
15333 }
15334
15335 if (json)
15336 vty_json(vty, json);
15337
15338 return CMD_SUCCESS;
15339 }
15340 /* Graceful Restart */
15341
15342 DEFUN (show_ip_bgp_attr_info,
15343 show_ip_bgp_attr_info_cmd,
15344 "show [ip] bgp attribute-info",
15345 SHOW_STR
15346 IP_STR
15347 BGP_STR
15348 "List all bgp attribute information\n")
15349 {
15350 attr_show_all(vty);
15351 return CMD_SUCCESS;
15352 }
15353
15354 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15355 afi_t afi, safi_t safi,
15356 bool use_json, json_object *json)
15357 {
15358 struct bgp *bgp;
15359 struct listnode *node;
15360 char *vname;
15361 char *ecom_str;
15362 enum vpn_policy_direction dir;
15363
15364 if (json) {
15365 json_object *json_import_vrfs = NULL;
15366 json_object *json_export_vrfs = NULL;
15367
15368 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15369
15370 if (!bgp) {
15371 vty_json(vty, json);
15372
15373 return CMD_WARNING;
15374 }
15375
15376 /* Provide context for the block */
15377 json_object_string_add(json, "vrf", name ? name : "default");
15378 json_object_string_add(json, "afiSafi",
15379 get_afi_safi_str(afi, safi, true));
15380
15381 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15382 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15383 json_object_string_add(json, "importFromVrfs", "none");
15384 json_object_string_add(json, "importRts", "none");
15385 } else {
15386 json_import_vrfs = json_object_new_array();
15387
15388 for (ALL_LIST_ELEMENTS_RO(
15389 bgp->vpn_policy[afi].import_vrf,
15390 node, vname))
15391 json_object_array_add(json_import_vrfs,
15392 json_object_new_string(vname));
15393
15394 json_object_object_add(json, "importFromVrfs",
15395 json_import_vrfs);
15396 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15397 if (bgp->vpn_policy[afi].rtlist[dir]) {
15398 ecom_str = ecommunity_ecom2str(
15399 bgp->vpn_policy[afi].rtlist[dir],
15400 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15401 json_object_string_add(json, "importRts",
15402 ecom_str);
15403 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15404 } else
15405 json_object_string_add(json, "importRts",
15406 "none");
15407 }
15408
15409 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15410 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15411 json_object_string_add(json, "exportToVrfs", "none");
15412 json_object_string_add(json, "routeDistinguisher",
15413 "none");
15414 json_object_string_add(json, "exportRts", "none");
15415 } else {
15416 json_export_vrfs = json_object_new_array();
15417
15418 for (ALL_LIST_ELEMENTS_RO(
15419 bgp->vpn_policy[afi].export_vrf,
15420 node, vname))
15421 json_object_array_add(json_export_vrfs,
15422 json_object_new_string(vname));
15423 json_object_object_add(json, "exportToVrfs",
15424 json_export_vrfs);
15425 json_object_string_addf(json, "routeDistinguisher",
15426 "%pRD",
15427 &bgp->vpn_policy[afi].tovpn_rd);
15428
15429 dir = BGP_VPN_POLICY_DIR_TOVPN;
15430 if (bgp->vpn_policy[afi].rtlist[dir]) {
15431 ecom_str = ecommunity_ecom2str(
15432 bgp->vpn_policy[afi].rtlist[dir],
15433 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15434 json_object_string_add(json, "exportRts",
15435 ecom_str);
15436 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15437 } else
15438 json_object_string_add(json, "exportRts",
15439 "none");
15440 }
15441
15442 if (use_json) {
15443 vty_json(vty, json);
15444 }
15445 } else {
15446 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15447
15448 if (!bgp) {
15449 vty_out(vty, "%% No such BGP instance exist\n");
15450 return CMD_WARNING;
15451 }
15452
15453 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15454 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15455 vty_out(vty,
15456 "This VRF is not importing %s routes from any other VRF\n",
15457 get_afi_safi_str(afi, safi, false));
15458 else {
15459 vty_out(vty,
15460 "This VRF is importing %s routes from the following VRFs:\n",
15461 get_afi_safi_str(afi, safi, false));
15462
15463 for (ALL_LIST_ELEMENTS_RO(
15464 bgp->vpn_policy[afi].import_vrf,
15465 node, vname))
15466 vty_out(vty, " %s\n", vname);
15467
15468 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15469 ecom_str = NULL;
15470 if (bgp->vpn_policy[afi].rtlist[dir]) {
15471 ecom_str = ecommunity_ecom2str(
15472 bgp->vpn_policy[afi].rtlist[dir],
15473 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15474 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15475
15476 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15477 } else
15478 vty_out(vty, "Import RT(s):\n");
15479 }
15480
15481 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15482 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15483 vty_out(vty,
15484 "This VRF is not exporting %s routes to any other VRF\n",
15485 get_afi_safi_str(afi, safi, false));
15486 else {
15487 vty_out(vty,
15488 "This VRF is exporting %s routes to the following VRFs:\n",
15489 get_afi_safi_str(afi, safi, false));
15490
15491 for (ALL_LIST_ELEMENTS_RO(
15492 bgp->vpn_policy[afi].export_vrf,
15493 node, vname))
15494 vty_out(vty, " %s\n", vname);
15495
15496 vty_out(vty, "RD: %pRD\n",
15497 &bgp->vpn_policy[afi].tovpn_rd);
15498
15499 dir = BGP_VPN_POLICY_DIR_TOVPN;
15500 if (bgp->vpn_policy[afi].rtlist[dir]) {
15501 ecom_str = ecommunity_ecom2str(
15502 bgp->vpn_policy[afi].rtlist[dir],
15503 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15504 vty_out(vty, "Export RT: %s\n", ecom_str);
15505 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15506 } else
15507 vty_out(vty, "Import RT(s):\n");
15508 }
15509 }
15510
15511 return CMD_SUCCESS;
15512 }
15513
15514 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15515 safi_t safi, bool use_json)
15516 {
15517 struct listnode *node, *nnode;
15518 struct bgp *bgp;
15519 char *vrf_name = NULL;
15520 json_object *json = NULL;
15521 json_object *json_vrf = NULL;
15522 json_object *json_vrfs = NULL;
15523
15524 if (use_json) {
15525 json = json_object_new_object();
15526 json_vrfs = json_object_new_object();
15527 }
15528
15529 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15530
15531 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15532 vrf_name = bgp->name;
15533
15534 if (use_json) {
15535 json_vrf = json_object_new_object();
15536 } else {
15537 vty_out(vty, "\nInstance %s:\n",
15538 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15539 ? VRF_DEFAULT_NAME : bgp->name);
15540 }
15541 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15542 if (use_json) {
15543 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15544 json_object_object_add(json_vrfs,
15545 VRF_DEFAULT_NAME, json_vrf);
15546 else
15547 json_object_object_add(json_vrfs, vrf_name,
15548 json_vrf);
15549 }
15550 }
15551
15552 if (use_json) {
15553 json_object_object_add(json, "vrfs", json_vrfs);
15554 vty_json(vty, json);
15555 }
15556
15557 return CMD_SUCCESS;
15558 }
15559
15560 /* "show [ip] bgp route-leak" command. */
15561 DEFUN (show_ip_bgp_route_leak,
15562 show_ip_bgp_route_leak_cmd,
15563 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15564 SHOW_STR
15565 IP_STR
15566 BGP_STR
15567 BGP_INSTANCE_HELP_STR
15568 BGP_AFI_HELP_STR
15569 BGP_SAFI_HELP_STR
15570 "Route leaking information\n"
15571 JSON_STR)
15572 {
15573 char *vrf = NULL;
15574 afi_t afi = AFI_MAX;
15575 safi_t safi = SAFI_MAX;
15576
15577 bool uj = use_json(argc, argv);
15578 int idx = 0;
15579 json_object *json = NULL;
15580
15581 /* show [ip] bgp */
15582 if (argv_find(argv, argc, "ip", &idx)) {
15583 afi = AFI_IP;
15584 safi = SAFI_UNICAST;
15585 }
15586 /* [vrf VIEWVRFNAME] */
15587 if (argv_find(argv, argc, "view", &idx)) {
15588 vty_out(vty,
15589 "%% This command is not applicable to BGP views\n");
15590 return CMD_WARNING;
15591 }
15592
15593 if (argv_find(argv, argc, "vrf", &idx)) {
15594 vrf = argv[idx + 1]->arg;
15595 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15596 vrf = NULL;
15597 }
15598 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15599 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15600 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15601
15602 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15603 vty_out(vty,
15604 "%% This command is applicable only for unicast ipv4|ipv6\n");
15605 return CMD_WARNING;
15606 }
15607
15608 if (vrf && strmatch(vrf, "all"))
15609 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15610
15611 if (uj)
15612 json = json_object_new_object();
15613
15614 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15615 }
15616
15617 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15618 safi_t safi, bool uj)
15619 {
15620 struct listnode *node, *nnode;
15621 struct bgp *bgp;
15622
15623 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15624 if (!uj)
15625 vty_out(vty, "\nInstance %s:\n",
15626 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15627 ? VRF_DEFAULT_NAME
15628 : bgp->name);
15629
15630 update_group_show(bgp, afi, safi, vty, 0, uj);
15631 }
15632 }
15633
15634 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15635 int safi, uint64_t subgrp_id, bool uj)
15636 {
15637 struct bgp *bgp;
15638
15639 if (name) {
15640 if (strmatch(name, "all")) {
15641 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15642 return CMD_SUCCESS;
15643 } else {
15644 bgp = bgp_lookup_by_name(name);
15645 }
15646 } else {
15647 bgp = bgp_get_default();
15648 }
15649
15650 if (bgp)
15651 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15652 return CMD_SUCCESS;
15653 }
15654
15655 DEFUN (show_ip_bgp_updgrps,
15656 show_ip_bgp_updgrps_cmd,
15657 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15658 SHOW_STR
15659 IP_STR
15660 BGP_STR
15661 BGP_INSTANCE_HELP_STR
15662 BGP_AFI_HELP_STR
15663 BGP_SAFI_WITH_LABEL_HELP_STR
15664 "Detailed info about dynamic update groups\n"
15665 "Specific subgroup to display detailed info for\n"
15666 JSON_STR)
15667 {
15668 char *vrf = NULL;
15669 afi_t afi = AFI_IP6;
15670 safi_t safi = SAFI_UNICAST;
15671 uint64_t subgrp_id = 0;
15672
15673 int idx = 0;
15674
15675 bool uj = use_json(argc, argv);
15676
15677 /* show [ip] bgp */
15678 if (argv_find(argv, argc, "ip", &idx))
15679 afi = AFI_IP;
15680 /* [<vrf> VIEWVRFNAME] */
15681 if (argv_find(argv, argc, "vrf", &idx)) {
15682 vrf = argv[idx + 1]->arg;
15683 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15684 vrf = NULL;
15685 } else if (argv_find(argv, argc, "view", &idx))
15686 /* [<view> VIEWVRFNAME] */
15687 vrf = argv[idx + 1]->arg;
15688 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15689 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15690 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15691 }
15692
15693 /* get subgroup id, if provided */
15694 idx = argc - 1;
15695 if (argv[idx]->type == VARIABLE_TKN)
15696 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15697
15698 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15699 }
15700
15701 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15702 show_bgp_instance_all_ipv6_updgrps_cmd,
15703 "show [ip] bgp <view|vrf> all update-groups [json]",
15704 SHOW_STR
15705 IP_STR
15706 BGP_STR
15707 BGP_INSTANCE_ALL_HELP_STR
15708 "Detailed info about dynamic update groups\n"
15709 JSON_STR)
15710 {
15711 bool uj = use_json(argc, argv);
15712
15713 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15714 return CMD_SUCCESS;
15715 }
15716
15717 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15718 show_bgp_l2vpn_evpn_updgrps_cmd,
15719 "show [ip] bgp l2vpn evpn update-groups",
15720 SHOW_STR
15721 IP_STR
15722 BGP_STR
15723 "l2vpn address family\n"
15724 "evpn sub-address family\n"
15725 "Detailed info about dynamic update groups\n")
15726 {
15727 char *vrf = NULL;
15728 uint64_t subgrp_id = 0;
15729
15730 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15731 return CMD_SUCCESS;
15732 }
15733
15734 DEFUN (show_bgp_updgrps_stats,
15735 show_bgp_updgrps_stats_cmd,
15736 "show [ip] bgp update-groups statistics",
15737 SHOW_STR
15738 IP_STR
15739 BGP_STR
15740 "Detailed info about dynamic update groups\n"
15741 "Statistics\n")
15742 {
15743 struct bgp *bgp;
15744
15745 bgp = bgp_get_default();
15746 if (bgp)
15747 update_group_show_stats(bgp, vty);
15748
15749 return CMD_SUCCESS;
15750 }
15751
15752 DEFUN (show_bgp_instance_updgrps_stats,
15753 show_bgp_instance_updgrps_stats_cmd,
15754 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15755 SHOW_STR
15756 IP_STR
15757 BGP_STR
15758 BGP_INSTANCE_HELP_STR
15759 "Detailed info about dynamic update groups\n"
15760 "Statistics\n")
15761 {
15762 int idx_word = 3;
15763 struct bgp *bgp;
15764
15765 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15766 if (bgp)
15767 update_group_show_stats(bgp, vty);
15768
15769 return CMD_SUCCESS;
15770 }
15771
15772 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15773 afi_t afi, safi_t safi,
15774 const char *what, uint64_t subgrp_id)
15775 {
15776 struct bgp *bgp;
15777
15778 if (name)
15779 bgp = bgp_lookup_by_name(name);
15780 else
15781 bgp = bgp_get_default();
15782
15783 if (bgp) {
15784 if (!strcmp(what, "advertise-queue"))
15785 update_group_show_adj_queue(bgp, afi, safi, vty,
15786 subgrp_id);
15787 else if (!strcmp(what, "advertised-routes"))
15788 update_group_show_advertised(bgp, afi, safi, vty,
15789 subgrp_id);
15790 else if (!strcmp(what, "packet-queue"))
15791 update_group_show_packet_queue(bgp, afi, safi, vty,
15792 subgrp_id);
15793 }
15794 }
15795
15796 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15797 show_ip_bgp_instance_updgrps_adj_s_cmd,
15798 "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",
15799 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15800 BGP_SAFI_HELP_STR
15801 "Detailed info about dynamic update groups\n"
15802 "Specific subgroup to display info for\n"
15803 "Advertisement queue\n"
15804 "Announced routes\n"
15805 "Packet queue\n")
15806 {
15807 uint64_t subgrp_id = 0;
15808 afi_t afiz;
15809 safi_t safiz;
15810 if (sgid)
15811 subgrp_id = strtoull(sgid, NULL, 10);
15812
15813 if (!ip && !afi)
15814 afiz = AFI_IP6;
15815 if (!ip && afi)
15816 afiz = bgp_vty_afi_from_str(afi);
15817 if (ip && !afi)
15818 afiz = AFI_IP;
15819 if (ip && afi) {
15820 afiz = bgp_vty_afi_from_str(afi);
15821 if (afiz != AFI_IP)
15822 vty_out(vty,
15823 "%% Cannot specify both 'ip' and 'ipv6'\n");
15824 return CMD_WARNING;
15825 }
15826
15827 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15828
15829 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15830 return CMD_SUCCESS;
15831 }
15832
15833 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15834 json_object *json)
15835 {
15836 struct listnode *node, *nnode;
15837 struct prefix *range;
15838 struct peer *conf;
15839 struct peer *peer;
15840 afi_t afi;
15841 safi_t safi;
15842 const char *peer_status;
15843 int lr_count;
15844 int dynamic;
15845 bool af_cfgd;
15846 json_object *json_peer_group = NULL;
15847 json_object *json_peer_group_afc = NULL;
15848 json_object *json_peer_group_members = NULL;
15849 json_object *json_peer_group_dynamic = NULL;
15850 json_object *json_peer_group_dynamic_af = NULL;
15851 json_object *json_peer_group_ranges = NULL;
15852
15853 conf = group->conf;
15854
15855 if (json) {
15856 json_peer_group = json_object_new_object();
15857 json_peer_group_afc = json_object_new_array();
15858 }
15859
15860 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15861 if (json)
15862 json_object_int_add(json_peer_group, "remoteAs",
15863 conf->as);
15864 else
15865 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15866 group->name, conf->as);
15867 } else if (conf->as_type == AS_INTERNAL) {
15868 if (json)
15869 json_object_int_add(json_peer_group, "remoteAs",
15870 group->bgp->as);
15871 else
15872 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15873 group->name, group->bgp->as);
15874 } else {
15875 if (!json)
15876 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15877 }
15878
15879 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15880 if (json)
15881 json_object_string_add(json_peer_group, "type",
15882 "internal");
15883 else
15884 vty_out(vty, " Peer-group type is internal\n");
15885 } else {
15886 if (json)
15887 json_object_string_add(json_peer_group, "type",
15888 "external");
15889 else
15890 vty_out(vty, " Peer-group type is external\n");
15891 }
15892
15893 /* Display AFs configured. */
15894 if (!json)
15895 vty_out(vty, " Configured address-families:");
15896
15897 FOREACH_AFI_SAFI (afi, safi) {
15898 if (conf->afc[afi][safi]) {
15899 af_cfgd = true;
15900 if (json)
15901 json_object_array_add(
15902 json_peer_group_afc,
15903 json_object_new_string(get_afi_safi_str(
15904 afi, safi, false)));
15905 else
15906 vty_out(vty, " %s;",
15907 get_afi_safi_str(afi, safi, false));
15908 }
15909 }
15910
15911 if (json) {
15912 json_object_object_add(json_peer_group,
15913 "addressFamiliesConfigured",
15914 json_peer_group_afc);
15915 } else {
15916 if (!af_cfgd)
15917 vty_out(vty, " none\n");
15918 else
15919 vty_out(vty, "\n");
15920 }
15921
15922 /* Display listen ranges (for dynamic neighbors), if any */
15923 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15924 lr_count = listcount(group->listen_range[afi]);
15925 if (lr_count) {
15926 if (json) {
15927 if (!json_peer_group_dynamic)
15928 json_peer_group_dynamic =
15929 json_object_new_object();
15930
15931 json_peer_group_dynamic_af =
15932 json_object_new_object();
15933 json_peer_group_ranges =
15934 json_object_new_array();
15935 json_object_int_add(json_peer_group_dynamic_af,
15936 "count", lr_count);
15937 } else {
15938 vty_out(vty, " %d %s listen range(s)\n",
15939 lr_count, afi2str(afi));
15940 }
15941
15942 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15943 nnode, range)) {
15944 if (json) {
15945 char buf[BUFSIZ];
15946
15947 snprintfrr(buf, sizeof(buf), "%pFX",
15948 range);
15949
15950 json_object_array_add(
15951 json_peer_group_ranges,
15952 json_object_new_string(buf));
15953 } else {
15954 vty_out(vty, " %pFX\n", range);
15955 }
15956 }
15957
15958 if (json) {
15959 json_object_object_add(
15960 json_peer_group_dynamic_af, "ranges",
15961 json_peer_group_ranges);
15962
15963 json_object_object_add(
15964 json_peer_group_dynamic, afi2str(afi),
15965 json_peer_group_dynamic_af);
15966 }
15967 }
15968 }
15969
15970 if (json_peer_group_dynamic)
15971 json_object_object_add(json_peer_group, "dynamicRanges",
15972 json_peer_group_dynamic);
15973
15974 /* Display group members and their status */
15975 if (listcount(group->peer)) {
15976 if (json)
15977 json_peer_group_members = json_object_new_object();
15978 else
15979 vty_out(vty, " Peer-group members:\n");
15980 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15981 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15982 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15983 peer_status = "Idle (Admin)";
15984 else if (CHECK_FLAG(peer->sflags,
15985 PEER_STATUS_PREFIX_OVERFLOW))
15986 peer_status = "Idle (PfxCt)";
15987 else
15988 peer_status = lookup_msg(bgp_status_msg,
15989 peer->status, NULL);
15990
15991 dynamic = peer_dynamic_neighbor(peer);
15992
15993 if (json) {
15994 json_object *json_peer_group_member =
15995 json_object_new_object();
15996
15997 json_object_string_add(json_peer_group_member,
15998 "status", peer_status);
15999
16000 if (dynamic)
16001 json_object_boolean_true_add(
16002 json_peer_group_member,
16003 "dynamic");
16004
16005 json_object_object_add(json_peer_group_members,
16006 peer->host,
16007 json_peer_group_member);
16008 } else {
16009 vty_out(vty, " %s %s %s \n", peer->host,
16010 dynamic ? "(dynamic)" : "",
16011 peer_status);
16012 }
16013 }
16014 if (json)
16015 json_object_object_add(json_peer_group, "members",
16016 json_peer_group_members);
16017 }
16018
16019 if (json)
16020 json_object_object_add(json, group->name, json_peer_group);
16021
16022 return CMD_SUCCESS;
16023 }
16024
16025 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16026 const char *group_name, bool uj)
16027 {
16028 struct bgp *bgp;
16029 struct listnode *node, *nnode;
16030 struct peer_group *group;
16031 bool found = false;
16032 json_object *json = NULL;
16033
16034 if (uj)
16035 json = json_object_new_object();
16036
16037 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16038
16039 if (!bgp) {
16040 if (uj)
16041 vty_json(vty, json);
16042 else
16043 vty_out(vty, "%% BGP instance not found\n");
16044
16045 return CMD_WARNING;
16046 }
16047
16048 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16049 if (group_name) {
16050 if (strmatch(group->name, group_name)) {
16051 bgp_show_one_peer_group(vty, group, json);
16052 found = true;
16053 break;
16054 }
16055 } else {
16056 bgp_show_one_peer_group(vty, group, json);
16057 }
16058 }
16059
16060 if (group_name && !found && !uj)
16061 vty_out(vty, "%% No such peer-group\n");
16062
16063 if (uj)
16064 vty_json(vty, json);
16065
16066 return CMD_SUCCESS;
16067 }
16068
16069 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16070 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16071 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16072 "Detailed information on BGP peer groups\n"
16073 "Peer group name\n" JSON_STR)
16074 {
16075 char *vrf, *pg;
16076 int idx = 0;
16077 bool uj = use_json(argc, argv);
16078
16079 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16080 : NULL;
16081 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16082
16083 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16084 }
16085
16086
16087 /* Redistribute VTY commands. */
16088
16089 DEFUN (bgp_redistribute_ipv4,
16090 bgp_redistribute_ipv4_cmd,
16091 "redistribute " FRR_IP_REDIST_STR_BGPD,
16092 "Redistribute information from another routing protocol\n"
16093 FRR_IP_REDIST_HELP_STR_BGPD)
16094 {
16095 VTY_DECLVAR_CONTEXT(bgp, bgp);
16096 int idx_protocol = 1;
16097 int type;
16098
16099 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16100 if (type < 0) {
16101 vty_out(vty, "%% Invalid route type\n");
16102 return CMD_WARNING_CONFIG_FAILED;
16103 }
16104
16105 bgp_redist_add(bgp, AFI_IP, type, 0);
16106 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16107 }
16108
16109 ALIAS_HIDDEN(
16110 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16111 "redistribute " FRR_IP_REDIST_STR_BGPD,
16112 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16113
16114 DEFUN (bgp_redistribute_ipv4_rmap,
16115 bgp_redistribute_ipv4_rmap_cmd,
16116 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16117 "Redistribute information from another routing protocol\n"
16118 FRR_IP_REDIST_HELP_STR_BGPD
16119 "Route map reference\n"
16120 "Pointer to route-map entries\n")
16121 {
16122 VTY_DECLVAR_CONTEXT(bgp, bgp);
16123 int idx_protocol = 1;
16124 int idx_word = 3;
16125 int type;
16126 struct bgp_redist *red;
16127 bool changed;
16128 struct route_map *route_map = route_map_lookup_warn_noexist(
16129 vty, argv[idx_word]->arg);
16130
16131 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16132 if (type < 0) {
16133 vty_out(vty, "%% Invalid route type\n");
16134 return CMD_WARNING_CONFIG_FAILED;
16135 }
16136
16137 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16138 changed =
16139 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16140 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16141 }
16142
16143 ALIAS_HIDDEN(
16144 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16145 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16146 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16147 "Route map reference\n"
16148 "Pointer to route-map entries\n")
16149
16150 DEFUN (bgp_redistribute_ipv4_metric,
16151 bgp_redistribute_ipv4_metric_cmd,
16152 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16153 "Redistribute information from another routing protocol\n"
16154 FRR_IP_REDIST_HELP_STR_BGPD
16155 "Metric for redistributed routes\n"
16156 "Default metric\n")
16157 {
16158 VTY_DECLVAR_CONTEXT(bgp, bgp);
16159 int idx_protocol = 1;
16160 int idx_number = 3;
16161 int type;
16162 uint32_t metric;
16163 struct bgp_redist *red;
16164 bool changed;
16165
16166 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16167 if (type < 0) {
16168 vty_out(vty, "%% Invalid route type\n");
16169 return CMD_WARNING_CONFIG_FAILED;
16170 }
16171 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16172
16173 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16174 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16175 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16176 }
16177
16178 ALIAS_HIDDEN(
16179 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16180 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16181 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16182 "Metric for redistributed routes\n"
16183 "Default metric\n")
16184
16185 DEFUN (bgp_redistribute_ipv4_rmap_metric,
16186 bgp_redistribute_ipv4_rmap_metric_cmd,
16187 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16188 "Redistribute information from another routing protocol\n"
16189 FRR_IP_REDIST_HELP_STR_BGPD
16190 "Route map reference\n"
16191 "Pointer to route-map entries\n"
16192 "Metric for redistributed routes\n"
16193 "Default metric\n")
16194 {
16195 VTY_DECLVAR_CONTEXT(bgp, bgp);
16196 int idx_protocol = 1;
16197 int idx_word = 3;
16198 int idx_number = 5;
16199 int type;
16200 uint32_t metric;
16201 struct bgp_redist *red;
16202 bool changed;
16203 struct route_map *route_map =
16204 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16205
16206 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16207 if (type < 0) {
16208 vty_out(vty, "%% Invalid route type\n");
16209 return CMD_WARNING_CONFIG_FAILED;
16210 }
16211 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16212
16213 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16214 changed =
16215 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16216 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16217 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16218 }
16219
16220 ALIAS_HIDDEN(
16221 bgp_redistribute_ipv4_rmap_metric,
16222 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16223 "redistribute " FRR_IP_REDIST_STR_BGPD
16224 " route-map RMAP_NAME metric (0-4294967295)",
16225 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16226 "Route map reference\n"
16227 "Pointer to route-map entries\n"
16228 "Metric for redistributed routes\n"
16229 "Default metric\n")
16230
16231 DEFUN (bgp_redistribute_ipv4_metric_rmap,
16232 bgp_redistribute_ipv4_metric_rmap_cmd,
16233 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16234 "Redistribute information from another routing protocol\n"
16235 FRR_IP_REDIST_HELP_STR_BGPD
16236 "Metric for redistributed routes\n"
16237 "Default metric\n"
16238 "Route map reference\n"
16239 "Pointer to route-map entries\n")
16240 {
16241 VTY_DECLVAR_CONTEXT(bgp, bgp);
16242 int idx_protocol = 1;
16243 int idx_number = 3;
16244 int idx_word = 5;
16245 int type;
16246 uint32_t metric;
16247 struct bgp_redist *red;
16248 bool changed;
16249 struct route_map *route_map =
16250 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16251
16252 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16253 if (type < 0) {
16254 vty_out(vty, "%% Invalid route type\n");
16255 return CMD_WARNING_CONFIG_FAILED;
16256 }
16257 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16258
16259 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16260 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16261 changed |=
16262 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16263 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16264 }
16265
16266 ALIAS_HIDDEN(
16267 bgp_redistribute_ipv4_metric_rmap,
16268 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16269 "redistribute " FRR_IP_REDIST_STR_BGPD
16270 " metric (0-4294967295) route-map RMAP_NAME",
16271 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16272 "Metric for redistributed routes\n"
16273 "Default metric\n"
16274 "Route map reference\n"
16275 "Pointer to route-map entries\n")
16276
16277 DEFUN (bgp_redistribute_ipv4_ospf,
16278 bgp_redistribute_ipv4_ospf_cmd,
16279 "redistribute <ospf|table> (1-65535)",
16280 "Redistribute information from another routing protocol\n"
16281 "Open Shortest Path First (OSPFv2)\n"
16282 "Non-main Kernel Routing Table\n"
16283 "Instance ID/Table ID\n")
16284 {
16285 VTY_DECLVAR_CONTEXT(bgp, bgp);
16286 int idx_ospf_table = 1;
16287 int idx_number = 2;
16288 unsigned short instance;
16289 unsigned short protocol;
16290
16291 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16292
16293 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16294 protocol = ZEBRA_ROUTE_OSPF;
16295 else
16296 protocol = ZEBRA_ROUTE_TABLE;
16297
16298 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16299 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16300 }
16301
16302 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16303 "redistribute <ospf|table> (1-65535)",
16304 "Redistribute information from another routing protocol\n"
16305 "Open Shortest Path First (OSPFv2)\n"
16306 "Non-main Kernel Routing Table\n"
16307 "Instance ID/Table ID\n")
16308
16309 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16310 bgp_redistribute_ipv4_ospf_rmap_cmd,
16311 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16312 "Redistribute information from another routing protocol\n"
16313 "Open Shortest Path First (OSPFv2)\n"
16314 "Non-main Kernel Routing Table\n"
16315 "Instance ID/Table ID\n"
16316 "Route map reference\n"
16317 "Pointer to route-map entries\n")
16318 {
16319 VTY_DECLVAR_CONTEXT(bgp, bgp);
16320 int idx_ospf_table = 1;
16321 int idx_number = 2;
16322 int idx_word = 4;
16323 struct bgp_redist *red;
16324 unsigned short instance;
16325 int protocol;
16326 bool changed;
16327 struct route_map *route_map =
16328 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16329
16330 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16331 protocol = ZEBRA_ROUTE_OSPF;
16332 else
16333 protocol = ZEBRA_ROUTE_TABLE;
16334
16335 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16336 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16337 changed =
16338 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16339 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16340 }
16341
16342 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16343 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16344 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16345 "Redistribute information from another routing protocol\n"
16346 "Open Shortest Path First (OSPFv2)\n"
16347 "Non-main Kernel Routing Table\n"
16348 "Instance ID/Table ID\n"
16349 "Route map reference\n"
16350 "Pointer to route-map entries\n")
16351
16352 DEFUN (bgp_redistribute_ipv4_ospf_metric,
16353 bgp_redistribute_ipv4_ospf_metric_cmd,
16354 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16355 "Redistribute information from another routing protocol\n"
16356 "Open Shortest Path First (OSPFv2)\n"
16357 "Non-main Kernel Routing Table\n"
16358 "Instance ID/Table ID\n"
16359 "Metric for redistributed routes\n"
16360 "Default metric\n")
16361 {
16362 VTY_DECLVAR_CONTEXT(bgp, bgp);
16363 int idx_ospf_table = 1;
16364 int idx_number = 2;
16365 int idx_number_2 = 4;
16366 uint32_t metric;
16367 struct bgp_redist *red;
16368 unsigned short instance;
16369 int protocol;
16370 bool changed;
16371
16372 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16373 protocol = ZEBRA_ROUTE_OSPF;
16374 else
16375 protocol = ZEBRA_ROUTE_TABLE;
16376
16377 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16378 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16379
16380 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16381 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16382 metric);
16383 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16384 }
16385
16386 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16387 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16388 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16389 "Redistribute information from another routing protocol\n"
16390 "Open Shortest Path First (OSPFv2)\n"
16391 "Non-main Kernel Routing Table\n"
16392 "Instance ID/Table ID\n"
16393 "Metric for redistributed routes\n"
16394 "Default metric\n")
16395
16396 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16397 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16398 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16399 "Redistribute information from another routing protocol\n"
16400 "Open Shortest Path First (OSPFv2)\n"
16401 "Non-main Kernel Routing Table\n"
16402 "Instance ID/Table ID\n"
16403 "Route map reference\n"
16404 "Pointer to route-map entries\n"
16405 "Metric for redistributed routes\n"
16406 "Default metric\n")
16407 {
16408 VTY_DECLVAR_CONTEXT(bgp, bgp);
16409 int idx_ospf_table = 1;
16410 int idx_number = 2;
16411 int idx_word = 4;
16412 int idx_number_2 = 6;
16413 uint32_t metric;
16414 struct bgp_redist *red;
16415 unsigned short instance;
16416 int protocol;
16417 bool changed;
16418 struct route_map *route_map =
16419 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16420
16421 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16422 protocol = ZEBRA_ROUTE_OSPF;
16423 else
16424 protocol = ZEBRA_ROUTE_TABLE;
16425
16426 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16427 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16428
16429 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16430 changed =
16431 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16432 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16433 metric);
16434 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16435 }
16436
16437 ALIAS_HIDDEN(
16438 bgp_redistribute_ipv4_ospf_rmap_metric,
16439 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16440 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16441 "Redistribute information from another routing protocol\n"
16442 "Open Shortest Path First (OSPFv2)\n"
16443 "Non-main Kernel Routing Table\n"
16444 "Instance ID/Table ID\n"
16445 "Route map reference\n"
16446 "Pointer to route-map entries\n"
16447 "Metric for redistributed routes\n"
16448 "Default metric\n")
16449
16450 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16451 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16452 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16453 "Redistribute information from another routing protocol\n"
16454 "Open Shortest Path First (OSPFv2)\n"
16455 "Non-main Kernel Routing Table\n"
16456 "Instance ID/Table ID\n"
16457 "Metric for redistributed routes\n"
16458 "Default metric\n"
16459 "Route map reference\n"
16460 "Pointer to route-map entries\n")
16461 {
16462 VTY_DECLVAR_CONTEXT(bgp, bgp);
16463 int idx_ospf_table = 1;
16464 int idx_number = 2;
16465 int idx_number_2 = 4;
16466 int idx_word = 6;
16467 uint32_t metric;
16468 struct bgp_redist *red;
16469 unsigned short instance;
16470 int protocol;
16471 bool changed;
16472 struct route_map *route_map =
16473 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16474
16475 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16476 protocol = ZEBRA_ROUTE_OSPF;
16477 else
16478 protocol = ZEBRA_ROUTE_TABLE;
16479
16480 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16481 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16482
16483 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16484 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16485 metric);
16486 changed |=
16487 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16488 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16489 }
16490
16491 ALIAS_HIDDEN(
16492 bgp_redistribute_ipv4_ospf_metric_rmap,
16493 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16494 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16495 "Redistribute information from another routing protocol\n"
16496 "Open Shortest Path First (OSPFv2)\n"
16497 "Non-main Kernel Routing Table\n"
16498 "Instance ID/Table ID\n"
16499 "Metric for redistributed routes\n"
16500 "Default metric\n"
16501 "Route map reference\n"
16502 "Pointer to route-map entries\n")
16503
16504 DEFUN (no_bgp_redistribute_ipv4_ospf,
16505 no_bgp_redistribute_ipv4_ospf_cmd,
16506 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16507 NO_STR
16508 "Redistribute information from another routing protocol\n"
16509 "Open Shortest Path First (OSPFv2)\n"
16510 "Non-main Kernel Routing Table\n"
16511 "Instance ID/Table ID\n"
16512 "Metric for redistributed routes\n"
16513 "Default metric\n"
16514 "Route map reference\n"
16515 "Pointer to route-map entries\n")
16516 {
16517 VTY_DECLVAR_CONTEXT(bgp, bgp);
16518 int idx_ospf_table = 2;
16519 int idx_number = 3;
16520 unsigned short instance;
16521 int protocol;
16522
16523 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16524 protocol = ZEBRA_ROUTE_OSPF;
16525 else
16526 protocol = ZEBRA_ROUTE_TABLE;
16527
16528 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16529 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16530 }
16531
16532 ALIAS_HIDDEN(
16533 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16534 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16535 NO_STR
16536 "Redistribute information from another routing protocol\n"
16537 "Open Shortest Path First (OSPFv2)\n"
16538 "Non-main Kernel Routing Table\n"
16539 "Instance ID/Table ID\n"
16540 "Metric for redistributed routes\n"
16541 "Default metric\n"
16542 "Route map reference\n"
16543 "Pointer to route-map entries\n")
16544
16545 DEFUN (no_bgp_redistribute_ipv4,
16546 no_bgp_redistribute_ipv4_cmd,
16547 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16548 NO_STR
16549 "Redistribute information from another routing protocol\n"
16550 FRR_IP_REDIST_HELP_STR_BGPD
16551 "Metric for redistributed routes\n"
16552 "Default metric\n"
16553 "Route map reference\n"
16554 "Pointer to route-map entries\n")
16555 {
16556 VTY_DECLVAR_CONTEXT(bgp, bgp);
16557 int idx_protocol = 2;
16558 int type;
16559
16560 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16561 if (type < 0) {
16562 vty_out(vty, "%% Invalid route type\n");
16563 return CMD_WARNING_CONFIG_FAILED;
16564 }
16565 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16566 }
16567
16568 ALIAS_HIDDEN(
16569 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16570 "no redistribute " FRR_IP_REDIST_STR_BGPD
16571 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16572 NO_STR
16573 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16574 "Metric for redistributed routes\n"
16575 "Default metric\n"
16576 "Route map reference\n"
16577 "Pointer to route-map entries\n")
16578
16579 DEFUN (bgp_redistribute_ipv6,
16580 bgp_redistribute_ipv6_cmd,
16581 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16582 "Redistribute information from another routing protocol\n"
16583 FRR_IP6_REDIST_HELP_STR_BGPD)
16584 {
16585 VTY_DECLVAR_CONTEXT(bgp, bgp);
16586 int idx_protocol = 1;
16587 int type;
16588
16589 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16590 if (type < 0) {
16591 vty_out(vty, "%% Invalid route type\n");
16592 return CMD_WARNING_CONFIG_FAILED;
16593 }
16594
16595 bgp_redist_add(bgp, AFI_IP6, type, 0);
16596 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16597 }
16598
16599 DEFUN (bgp_redistribute_ipv6_rmap,
16600 bgp_redistribute_ipv6_rmap_cmd,
16601 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16602 "Redistribute information from another routing protocol\n"
16603 FRR_IP6_REDIST_HELP_STR_BGPD
16604 "Route map reference\n"
16605 "Pointer to route-map entries\n")
16606 {
16607 VTY_DECLVAR_CONTEXT(bgp, bgp);
16608 int idx_protocol = 1;
16609 int idx_word = 3;
16610 int type;
16611 struct bgp_redist *red;
16612 bool changed;
16613 struct route_map *route_map =
16614 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
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 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16623 changed =
16624 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16625 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16626 }
16627
16628 DEFUN (bgp_redistribute_ipv6_metric,
16629 bgp_redistribute_ipv6_metric_cmd,
16630 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16631 "Redistribute information from another routing protocol\n"
16632 FRR_IP6_REDIST_HELP_STR_BGPD
16633 "Metric for redistributed routes\n"
16634 "Default metric\n")
16635 {
16636 VTY_DECLVAR_CONTEXT(bgp, bgp);
16637 int idx_protocol = 1;
16638 int idx_number = 3;
16639 int type;
16640 uint32_t metric;
16641 struct bgp_redist *red;
16642 bool changed;
16643
16644 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16645 if (type < 0) {
16646 vty_out(vty, "%% Invalid route type\n");
16647 return CMD_WARNING_CONFIG_FAILED;
16648 }
16649 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16650
16651 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16652 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16653 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16654 }
16655
16656 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16657 bgp_redistribute_ipv6_rmap_metric_cmd,
16658 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16659 "Redistribute information from another routing protocol\n"
16660 FRR_IP6_REDIST_HELP_STR_BGPD
16661 "Route map reference\n"
16662 "Pointer to route-map entries\n"
16663 "Metric for redistributed routes\n"
16664 "Default metric\n")
16665 {
16666 VTY_DECLVAR_CONTEXT(bgp, bgp);
16667 int idx_protocol = 1;
16668 int idx_word = 3;
16669 int idx_number = 5;
16670 int type;
16671 uint32_t metric;
16672 struct bgp_redist *red;
16673 bool changed;
16674 struct route_map *route_map =
16675 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16676
16677 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16678 if (type < 0) {
16679 vty_out(vty, "%% Invalid route type\n");
16680 return CMD_WARNING_CONFIG_FAILED;
16681 }
16682 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16683
16684 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16685 changed =
16686 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16687 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16688 metric);
16689 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16690 }
16691
16692 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16693 bgp_redistribute_ipv6_metric_rmap_cmd,
16694 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16695 "Redistribute information from another routing protocol\n"
16696 FRR_IP6_REDIST_HELP_STR_BGPD
16697 "Metric for redistributed routes\n"
16698 "Default metric\n"
16699 "Route map reference\n"
16700 "Pointer to route-map entries\n")
16701 {
16702 VTY_DECLVAR_CONTEXT(bgp, bgp);
16703 int idx_protocol = 1;
16704 int idx_number = 3;
16705 int idx_word = 5;
16706 int type;
16707 uint32_t metric;
16708 struct bgp_redist *red;
16709 bool changed;
16710 struct route_map *route_map =
16711 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16712
16713 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16714 if (type < 0) {
16715 vty_out(vty, "%% Invalid route type\n");
16716 return CMD_WARNING_CONFIG_FAILED;
16717 }
16718 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16719
16720 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16721 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16722 metric);
16723 changed |=
16724 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16725 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16726 }
16727
16728 DEFUN (no_bgp_redistribute_ipv6,
16729 no_bgp_redistribute_ipv6_cmd,
16730 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16731 NO_STR
16732 "Redistribute information from another routing protocol\n"
16733 FRR_IP6_REDIST_HELP_STR_BGPD
16734 "Metric for redistributed routes\n"
16735 "Default metric\n"
16736 "Route map reference\n"
16737 "Pointer to route-map entries\n")
16738 {
16739 VTY_DECLVAR_CONTEXT(bgp, bgp);
16740 int idx_protocol = 2;
16741 int type;
16742
16743 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16744 if (type < 0) {
16745 vty_out(vty, "%% Invalid route type\n");
16746 return CMD_WARNING_CONFIG_FAILED;
16747 }
16748
16749 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16750 }
16751
16752 /* Neighbor update tcp-mss. */
16753 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16754 const char *tcp_mss_str)
16755 {
16756 struct peer *peer;
16757 uint32_t tcp_mss_val = 0;
16758
16759 peer = peer_and_group_lookup_vty(vty, peer_str);
16760 if (!peer)
16761 return CMD_WARNING_CONFIG_FAILED;
16762
16763 if (tcp_mss_str) {
16764 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16765 peer_tcp_mss_set(peer, tcp_mss_val);
16766 } else {
16767 peer_tcp_mss_unset(peer);
16768 }
16769
16770 return CMD_SUCCESS;
16771 }
16772
16773 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16774 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16775 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16776 "TCP max segment size\n"
16777 "TCP MSS value\n")
16778 {
16779 int peer_index = 1;
16780 int mss_index = 3;
16781
16782 vty_out(vty,
16783 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16784 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16785 argv[mss_index]->arg);
16786 }
16787
16788 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16789 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16790 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16791 "TCP max segment size\n"
16792 "TCP MSS value\n")
16793 {
16794 int peer_index = 2;
16795
16796 vty_out(vty,
16797 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16798 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16799 }
16800
16801 DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16802 "[no$no] bgp retain route-target all",
16803 NO_STR BGP_STR
16804 "Retain BGP updates\n"
16805 "Retain BGP updates based on route-target values\n"
16806 "Retain all BGP updates\n")
16807 {
16808 bool check;
16809 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16810
16811 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16812 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16813 if (check != !no) {
16814 if (!no)
16815 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16816 [bgp_node_safi(vty)],
16817 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16818 else
16819 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16820 [bgp_node_safi(vty)],
16821 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16822 /* trigger a flush to re-sync with ADJ-RIB-in */
16823 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16824 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16825 }
16826 return CMD_SUCCESS;
16827 }
16828
16829 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16830 afi_t afi, safi_t safi)
16831 {
16832 int i;
16833
16834 /* Unicast redistribution only. */
16835 if (safi != SAFI_UNICAST)
16836 return;
16837
16838 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16839 /* Redistribute BGP does not make sense. */
16840 if (i != ZEBRA_ROUTE_BGP) {
16841 struct list *red_list;
16842 struct listnode *node;
16843 struct bgp_redist *red;
16844
16845 red_list = bgp->redist[afi][i];
16846 if (!red_list)
16847 continue;
16848
16849 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16850 /* "redistribute" configuration. */
16851 vty_out(vty, " redistribute %s",
16852 zebra_route_string(i));
16853 if (red->instance)
16854 vty_out(vty, " %d", red->instance);
16855 if (red->redist_metric_flag)
16856 vty_out(vty, " metric %u",
16857 red->redist_metric);
16858 if (red->rmap.name)
16859 vty_out(vty, " route-map %s",
16860 red->rmap.name);
16861 vty_out(vty, "\n");
16862 }
16863 }
16864 }
16865 }
16866
16867 /* peer-group helpers for config-write */
16868
16869 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16870 {
16871 if (!peer_group_active(peer)) {
16872 if (CHECK_FLAG(peer->flags_invert, flag))
16873 return !CHECK_FLAG(peer->flags, flag);
16874 else
16875 return !!CHECK_FLAG(peer->flags, flag);
16876 }
16877
16878 return !!CHECK_FLAG(peer->flags_override, flag);
16879 }
16880
16881 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16882 uint64_t flag)
16883 {
16884 if (!peer_group_active(peer)) {
16885 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16886 return !peer_af_flag_check(peer, afi, safi, flag);
16887 else
16888 return !!peer_af_flag_check(peer, afi, safi, flag);
16889 }
16890
16891 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16892 }
16893
16894 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16895 uint8_t type, int direct)
16896 {
16897 struct bgp_filter *filter;
16898
16899 if (peer_group_active(peer))
16900 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16901 type);
16902
16903 filter = &peer->filter[afi][safi];
16904 switch (type) {
16905 case PEER_FT_DISTRIBUTE_LIST:
16906 return !!(filter->dlist[direct].name);
16907 case PEER_FT_FILTER_LIST:
16908 return !!(filter->aslist[direct].name);
16909 case PEER_FT_PREFIX_LIST:
16910 return !!(filter->plist[direct].name);
16911 case PEER_FT_ROUTE_MAP:
16912 return !!(filter->map[direct].name);
16913 case PEER_FT_UNSUPPRESS_MAP:
16914 return !!(filter->usmap.name);
16915 case PEER_FT_ADVERTISE_MAP:
16916 return !!(filter->advmap.aname
16917 && ((filter->advmap.condition == direct)
16918 && filter->advmap.cname));
16919 default:
16920 return false;
16921 }
16922 }
16923
16924 /* Return true if the addpath type is set for peer and different from
16925 * peer-group.
16926 */
16927 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16928 safi_t safi)
16929 {
16930 enum bgp_addpath_strat type, g_type;
16931
16932 type = peer->addpath_type[afi][safi];
16933
16934 if (type != BGP_ADDPATH_NONE) {
16935 if (peer_group_active(peer)) {
16936 g_type = peer->group->conf->addpath_type[afi][safi];
16937
16938 if (type != g_type)
16939 return true;
16940 else
16941 return false;
16942 }
16943
16944 return true;
16945 }
16946
16947 return false;
16948 }
16949
16950 /* This is part of the address-family block (unicast only) */
16951 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16952 afi_t afi)
16953 {
16954 int indent = 2;
16955 uint32_t tovpn_sid_index = 0;
16956
16957 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16958 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16959 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16960 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16961 bgp->vpn_policy[afi]
16962 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16963 else
16964 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16965 bgp->vpn_policy[afi]
16966 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16967 }
16968 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16969 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16970 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16971 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16972 return;
16973
16974 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16975 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16976
16977 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16978
16979 } else {
16980 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16981 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16982 bgp->vpn_policy[afi].tovpn_label);
16983 }
16984 }
16985
16986 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16987 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16988 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16989 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16990 } else if (tovpn_sid_index != 0) {
16991 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16992 tovpn_sid_index);
16993 }
16994
16995 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16996 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16997 &bgp->vpn_policy[afi].tovpn_rd);
16998
16999 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17000 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17001
17002 char buf[PREFIX_STRLEN];
17003 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17004 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17005 sizeof(buf))) {
17006
17007 vty_out(vty, "%*snexthop vpn export %s\n",
17008 indent, "", buf);
17009 }
17010 }
17011 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17012 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17013 && ecommunity_cmp(
17014 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17015 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17016
17017 char *b = ecommunity_ecom2str(
17018 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17019 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17020 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17021 XFREE(MTYPE_ECOMMUNITY_STR, b);
17022 } else {
17023 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17024 char *b = ecommunity_ecom2str(
17025 bgp->vpn_policy[afi]
17026 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17027 ECOMMUNITY_FORMAT_ROUTE_MAP,
17028 ECOMMUNITY_ROUTE_TARGET);
17029 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17030 XFREE(MTYPE_ECOMMUNITY_STR, b);
17031 }
17032 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17033 char *b = ecommunity_ecom2str(
17034 bgp->vpn_policy[afi]
17035 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17036 ECOMMUNITY_FORMAT_ROUTE_MAP,
17037 ECOMMUNITY_ROUTE_TARGET);
17038 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17039 XFREE(MTYPE_ECOMMUNITY_STR, b);
17040 }
17041 }
17042
17043 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17044 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17045 bgp->vpn_policy[afi]
17046 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17047
17048 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17049 char *b = ecommunity_ecom2str(
17050 bgp->vpn_policy[afi]
17051 .import_redirect_rtlist,
17052 ECOMMUNITY_FORMAT_ROUTE_MAP,
17053 ECOMMUNITY_ROUTE_TARGET);
17054
17055 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17056 != ECOMMUNITY_SIZE)
17057 vty_out(vty, "%*srt6 redirect import %s\n",
17058 indent, "", b);
17059 else
17060 vty_out(vty, "%*srt redirect import %s\n",
17061 indent, "", b);
17062 XFREE(MTYPE_ECOMMUNITY_STR, b);
17063 }
17064 }
17065
17066 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17067 afi_t afi, safi_t safi)
17068 {
17069 struct bgp_filter *filter;
17070 char *addr;
17071
17072 addr = peer->host;
17073 filter = &peer->filter[afi][safi];
17074
17075 /* distribute-list. */
17076 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17077 FILTER_IN))
17078 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17079 filter->dlist[FILTER_IN].name);
17080
17081 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17082 FILTER_OUT))
17083 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17084 filter->dlist[FILTER_OUT].name);
17085
17086 /* prefix-list. */
17087 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17088 FILTER_IN))
17089 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17090 filter->plist[FILTER_IN].name);
17091
17092 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17093 FILTER_OUT))
17094 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17095 filter->plist[FILTER_OUT].name);
17096
17097 /* route-map. */
17098 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17099 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17100 filter->map[RMAP_IN].name);
17101
17102 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17103 RMAP_OUT))
17104 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17105 filter->map[RMAP_OUT].name);
17106
17107 /* unsuppress-map */
17108 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17109 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17110 filter->usmap.name);
17111
17112 /* advertise-map : always applied in OUT direction*/
17113 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17114 CONDITION_NON_EXIST))
17115 vty_out(vty,
17116 " neighbor %s advertise-map %s non-exist-map %s\n",
17117 addr, filter->advmap.aname, filter->advmap.cname);
17118
17119 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17120 CONDITION_EXIST))
17121 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17122 addr, filter->advmap.aname, filter->advmap.cname);
17123
17124 /* filter-list. */
17125 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17126 FILTER_IN))
17127 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17128 filter->aslist[FILTER_IN].name);
17129
17130 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17131 FILTER_OUT))
17132 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17133 filter->aslist[FILTER_OUT].name);
17134 }
17135
17136 /* BGP peer configuration display function. */
17137 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17138 struct peer *peer)
17139 {
17140 struct peer *g_peer = NULL;
17141 char *addr;
17142 int if_pg_printed = false;
17143 int if_ras_printed = false;
17144
17145 /* Skip dynamic neighbors. */
17146 if (peer_dynamic_neighbor(peer))
17147 return;
17148
17149 if (peer->conf_if)
17150 addr = peer->conf_if;
17151 else
17152 addr = peer->host;
17153
17154 /************************************
17155 ****** Global to the neighbor ******
17156 ************************************/
17157 if (peer->conf_if) {
17158 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17159 vty_out(vty, " neighbor %s interface v6only", addr);
17160 else
17161 vty_out(vty, " neighbor %s interface", addr);
17162
17163 if (peer_group_active(peer)) {
17164 vty_out(vty, " peer-group %s", peer->group->name);
17165 if_pg_printed = true;
17166 } else if (peer->as_type == AS_SPECIFIED) {
17167 vty_out(vty, " remote-as %u", peer->as);
17168 if_ras_printed = true;
17169 } else if (peer->as_type == AS_INTERNAL) {
17170 vty_out(vty, " remote-as internal");
17171 if_ras_printed = true;
17172 } else if (peer->as_type == AS_EXTERNAL) {
17173 vty_out(vty, " remote-as external");
17174 if_ras_printed = true;
17175 }
17176
17177 vty_out(vty, "\n");
17178 }
17179
17180 /* remote-as and peer-group */
17181 /* peer is a member of a peer-group */
17182 if (peer_group_active(peer)) {
17183 g_peer = peer->group->conf;
17184
17185 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17186 if (peer->as_type == AS_SPECIFIED) {
17187 vty_out(vty, " neighbor %s remote-as %u\n",
17188 addr, peer->as);
17189 } else if (peer->as_type == AS_INTERNAL) {
17190 vty_out(vty,
17191 " neighbor %s remote-as internal\n",
17192 addr);
17193 } else if (peer->as_type == AS_EXTERNAL) {
17194 vty_out(vty,
17195 " neighbor %s remote-as external\n",
17196 addr);
17197 }
17198 }
17199
17200 /* For swpX peers we displayed the peer-group
17201 * via 'neighbor swpX interface peer-group PGNAME' */
17202 if (!if_pg_printed)
17203 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17204 peer->group->name);
17205 }
17206
17207 /* peer is NOT a member of a peer-group */
17208 else {
17209 /* peer is a peer-group, declare the peer-group */
17210 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17211 vty_out(vty, " neighbor %s peer-group\n", addr);
17212 }
17213
17214 if (!if_ras_printed) {
17215 if (peer->as_type == AS_SPECIFIED) {
17216 vty_out(vty, " neighbor %s remote-as %u\n",
17217 addr, peer->as);
17218 } else if (peer->as_type == AS_INTERNAL) {
17219 vty_out(vty,
17220 " neighbor %s remote-as internal\n",
17221 addr);
17222 } else if (peer->as_type == AS_EXTERNAL) {
17223 vty_out(vty,
17224 " neighbor %s remote-as external\n",
17225 addr);
17226 }
17227 }
17228 }
17229
17230 /* local-as */
17231 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17232 vty_out(vty, " neighbor %s local-as %u", addr,
17233 peer->change_local_as);
17234 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17235 vty_out(vty, " no-prepend");
17236 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17237 vty_out(vty, " replace-as");
17238 vty_out(vty, "\n");
17239 }
17240
17241 /* description */
17242 if (peer->desc) {
17243 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17244 }
17245
17246 /* shutdown */
17247 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17248 if (peer->tx_shutdown_message)
17249 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17250 peer->tx_shutdown_message);
17251 else
17252 vty_out(vty, " neighbor %s shutdown\n", addr);
17253 }
17254
17255 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17256 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17257 peer->rtt_expected, peer->rtt_keepalive_conf);
17258
17259 /* bfd */
17260 if (peer->bfd_config)
17261 bgp_bfd_peer_config_write(vty, peer, addr);
17262
17263 /* password */
17264 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17265 vty_out(vty, " neighbor %s password %s\n", addr,
17266 peer->password);
17267
17268 /* neighbor solo */
17269 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17270 if (!peer_group_active(peer)) {
17271 vty_out(vty, " neighbor %s solo\n", addr);
17272 }
17273 }
17274
17275 /* BGP port */
17276 if (peer->port != BGP_PORT_DEFAULT) {
17277 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17278 }
17279
17280 /* Local interface name */
17281 if (peer->ifname) {
17282 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17283 }
17284
17285 /* TCP max segment size */
17286 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17287 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17288
17289 /* passive */
17290 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17291 vty_out(vty, " neighbor %s passive\n", addr);
17292
17293 /* ebgp-multihop */
17294 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17295 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17296 && peer->ttl == MAXTTL)) {
17297 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17298 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17299 peer->ttl);
17300 }
17301 }
17302
17303 /* aigp */
17304 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17305 vty_out(vty, " neighbor %s aigp\n", addr);
17306
17307 /* graceful-shutdown */
17308 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17309 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17310
17311 /* role */
17312 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17313 peer->local_role != ROLE_UNDEFINED)
17314 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17315 bgp_get_name_by_role(peer->local_role),
17316 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17317 ? " strict-mode"
17318 : "");
17319
17320 /* ttl-security hops */
17321 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17322 if (!peer_group_active(peer)
17323 || g_peer->gtsm_hops != peer->gtsm_hops) {
17324 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17325 addr, peer->gtsm_hops);
17326 }
17327 }
17328
17329 /* disable-connected-check */
17330 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17331 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17332
17333 /* link-bw-encoding-ieee */
17334 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17335 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17336 addr);
17337
17338 /* extended-optional-parameters */
17339 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17340 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17341 addr);
17342
17343 /* enforce-first-as */
17344 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17345 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17346
17347 /* update-source */
17348 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17349 if (peer->update_source)
17350 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17351 peer->update_source);
17352 else if (peer->update_if)
17353 vty_out(vty, " neighbor %s update-source %s\n", addr,
17354 peer->update_if);
17355 }
17356
17357 /* advertisement-interval */
17358 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17359 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17360 peer->routeadv);
17361
17362 /* timers */
17363 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17364 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17365 peer->keepalive, peer->holdtime);
17366
17367 /* timers connect */
17368 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17369 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17370 peer->connect);
17371 /* need special-case handling for changed default values due to
17372 * config profile / version (because there is no "timers bgp connect"
17373 * command, we need to save this per-peer :/)
17374 */
17375 else if (!peer_group_active(peer) && !peer->connect &&
17376 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17377 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17378 peer->bgp->default_connect_retry);
17379
17380 /* timers delayopen */
17381 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17382 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17383 peer->delayopen);
17384 /* Save config even though flag is not set if default values have been
17385 * changed
17386 */
17387 else if (!peer_group_active(peer) && !peer->delayopen
17388 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17389 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17390 peer->bgp->default_delayopen);
17391
17392 /* capability dynamic */
17393 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17394 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17395
17396 /* capability extended-nexthop */
17397 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17398 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17399 !peer->conf_if)
17400 vty_out(vty,
17401 " no neighbor %s capability extended-nexthop\n",
17402 addr);
17403 else if (!peer->conf_if)
17404 vty_out(vty,
17405 " neighbor %s capability extended-nexthop\n",
17406 addr);
17407 }
17408
17409 /* dont-capability-negotiation */
17410 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17411 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17412
17413 /* override-capability */
17414 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17415 vty_out(vty, " neighbor %s override-capability\n", addr);
17416
17417 /* strict-capability-match */
17418 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17419 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17420
17421 /* Sender side AS path loop detection. */
17422 if (peer->as_path_loop_detection)
17423 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17424 addr);
17425
17426 /* path-attribute discard */
17427 char discard_attrs_str[BUFSIZ] = {0};
17428 bool discard_attrs = bgp_path_attribute_discard(
17429 peer, discard_attrs_str, sizeof(discard_attrs_str));
17430
17431 if (discard_attrs)
17432 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17433 discard_attrs_str);
17434
17435 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17436 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17437
17438 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17439 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17440 vty_out(vty,
17441 " neighbor %s graceful-restart-helper\n", addr);
17442 } else if (CHECK_FLAG(
17443 peer->peer_gr_new_status_flag,
17444 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17445 vty_out(vty,
17446 " neighbor %s graceful-restart\n", addr);
17447 } else if (
17448 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17449 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17450 && !(CHECK_FLAG(
17451 peer->peer_gr_new_status_flag,
17452 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17453 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17454 addr);
17455 }
17456 }
17457 }
17458
17459 /* BGP peer configuration display function. */
17460 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17461 struct peer *peer, afi_t afi, safi_t safi)
17462 {
17463 struct peer *g_peer = NULL;
17464 char *addr;
17465 bool flag_scomm, flag_secomm, flag_slcomm;
17466
17467 /* Skip dynamic neighbors. */
17468 if (peer_dynamic_neighbor(peer))
17469 return;
17470
17471 if (peer->conf_if)
17472 addr = peer->conf_if;
17473 else
17474 addr = peer->host;
17475
17476 /************************************
17477 ****** Per AF to the neighbor ******
17478 ************************************/
17479 if (peer_group_active(peer)) {
17480 g_peer = peer->group->conf;
17481
17482 /* If the peer-group is active but peer is not, print a 'no
17483 * activate' */
17484 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17485 vty_out(vty, " no neighbor %s activate\n", addr);
17486 }
17487
17488 /* If the peer-group is not active but peer is, print an
17489 'activate' */
17490 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17491 vty_out(vty, " neighbor %s activate\n", addr);
17492 }
17493 } else {
17494 if (peer->afc[afi][safi]) {
17495 if (safi == SAFI_ENCAP)
17496 vty_out(vty, " neighbor %s activate\n", addr);
17497 else if (!bgp->default_af[afi][safi])
17498 vty_out(vty, " neighbor %s activate\n", addr);
17499 } else {
17500 if (bgp->default_af[afi][safi])
17501 vty_out(vty, " no neighbor %s activate\n",
17502 addr);
17503 }
17504 }
17505
17506 /* addpath TX knobs */
17507 if (peergroup_af_addpath_check(peer, afi, safi)) {
17508 switch (peer->addpath_type[afi][safi]) {
17509 case BGP_ADDPATH_ALL:
17510 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17511 addr);
17512 break;
17513 case BGP_ADDPATH_BEST_PER_AS:
17514 vty_out(vty,
17515 " neighbor %s addpath-tx-bestpath-per-AS\n",
17516 addr);
17517 break;
17518 case BGP_ADDPATH_MAX:
17519 case BGP_ADDPATH_NONE:
17520 break;
17521 }
17522 }
17523
17524 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17525 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17526
17527 /* ORF capability. */
17528 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17529 || peergroup_af_flag_check(peer, afi, safi,
17530 PEER_FLAG_ORF_PREFIX_RM)) {
17531 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17532
17533 if (peergroup_af_flag_check(peer, afi, safi,
17534 PEER_FLAG_ORF_PREFIX_SM)
17535 && peergroup_af_flag_check(peer, afi, safi,
17536 PEER_FLAG_ORF_PREFIX_RM))
17537 vty_out(vty, " both");
17538 else if (peergroup_af_flag_check(peer, afi, safi,
17539 PEER_FLAG_ORF_PREFIX_SM))
17540 vty_out(vty, " send");
17541 else
17542 vty_out(vty, " receive");
17543 vty_out(vty, "\n");
17544 }
17545
17546 /* Route reflector client. */
17547 if (peergroup_af_flag_check(peer, afi, safi,
17548 PEER_FLAG_REFLECTOR_CLIENT)) {
17549 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17550 }
17551
17552 /* next-hop-self force */
17553 if (peergroup_af_flag_check(peer, afi, safi,
17554 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17555 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17556 }
17557
17558 /* next-hop-self */
17559 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17560 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17561 }
17562
17563 /* remove-private-AS */
17564 if (peergroup_af_flag_check(peer, afi, safi,
17565 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17566 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17567 addr);
17568 }
17569
17570 else if (peergroup_af_flag_check(peer, afi, safi,
17571 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17572 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17573 addr);
17574 }
17575
17576 else if (peergroup_af_flag_check(peer, afi, safi,
17577 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17578 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17579 }
17580
17581 else if (peergroup_af_flag_check(peer, afi, safi,
17582 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17583 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17584 }
17585
17586 /* as-override */
17587 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17588 vty_out(vty, " neighbor %s as-override\n", addr);
17589 }
17590
17591 /* send-community print. */
17592 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17593 PEER_FLAG_SEND_COMMUNITY);
17594 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17595 PEER_FLAG_SEND_EXT_COMMUNITY);
17596 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17597 PEER_FLAG_SEND_LARGE_COMMUNITY);
17598
17599 if (flag_scomm && flag_secomm && flag_slcomm) {
17600 vty_out(vty, " no neighbor %s send-community all\n", addr);
17601 } else {
17602 if (flag_scomm)
17603 vty_out(vty, " no neighbor %s send-community\n", addr);
17604 if (flag_secomm)
17605 vty_out(vty,
17606 " no neighbor %s send-community extended\n",
17607 addr);
17608
17609 if (flag_slcomm)
17610 vty_out(vty, " no neighbor %s send-community large\n",
17611 addr);
17612 }
17613
17614 /* Default information */
17615 if (peergroup_af_flag_check(peer, afi, safi,
17616 PEER_FLAG_DEFAULT_ORIGINATE)) {
17617 vty_out(vty, " neighbor %s default-originate", addr);
17618
17619 if (peer->default_rmap[afi][safi].name)
17620 vty_out(vty, " route-map %s",
17621 peer->default_rmap[afi][safi].name);
17622
17623 vty_out(vty, "\n");
17624 }
17625
17626 /* Soft reconfiguration inbound. */
17627 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17628 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17629 addr);
17630 }
17631
17632 /* maximum-prefix. */
17633 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17634 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17635 peer->pmax[afi][safi]);
17636
17637 if (peer->pmax_threshold[afi][safi]
17638 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17639 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17640 if (peer_af_flag_check(peer, afi, safi,
17641 PEER_FLAG_MAX_PREFIX_WARNING))
17642 vty_out(vty, " warning-only");
17643 if (peer->pmax_restart[afi][safi])
17644 vty_out(vty, " restart %u",
17645 peer->pmax_restart[afi][safi]);
17646 if (peer_af_flag_check(peer, afi, safi,
17647 PEER_FLAG_MAX_PREFIX_FORCE))
17648 vty_out(vty, " force");
17649
17650 vty_out(vty, "\n");
17651 }
17652
17653 /* maximum-prefix-out */
17654 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17655 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17656 addr, peer->pmax_out[afi][safi]);
17657
17658 /* Route server client. */
17659 if (peergroup_af_flag_check(peer, afi, safi,
17660 PEER_FLAG_RSERVER_CLIENT)) {
17661 vty_out(vty, " neighbor %s route-server-client\n", addr);
17662 }
17663
17664 /* Nexthop-local unchanged. */
17665 if (peergroup_af_flag_check(peer, afi, safi,
17666 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17667 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17668 }
17669
17670 /* allowas-in <1-10> */
17671 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17672 if (peer_af_flag_check(peer, afi, safi,
17673 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17674 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17675 } else if (peer->allowas_in[afi][safi] == 3) {
17676 vty_out(vty, " neighbor %s allowas-in\n", addr);
17677 } else {
17678 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17679 peer->allowas_in[afi][safi]);
17680 }
17681 }
17682
17683 /* accept-own */
17684 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17685 vty_out(vty, " neighbor %s accept-own\n", addr);
17686
17687 /* soo */
17688 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17689 char *soo_str = ecommunity_ecom2str(
17690 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17691
17692 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17693 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17694 }
17695
17696 /* weight */
17697 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17698 vty_out(vty, " neighbor %s weight %lu\n", addr,
17699 peer->weight[afi][safi]);
17700
17701 /* Filter. */
17702 bgp_config_write_filter(vty, peer, afi, safi);
17703
17704 /* atribute-unchanged. */
17705 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17706 || (safi != SAFI_EVPN
17707 && peer_af_flag_check(peer, afi, safi,
17708 PEER_FLAG_NEXTHOP_UNCHANGED))
17709 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17710
17711 if (!peer_group_active(peer)
17712 || peergroup_af_flag_check(peer, afi, safi,
17713 PEER_FLAG_AS_PATH_UNCHANGED)
17714 || peergroup_af_flag_check(peer, afi, safi,
17715 PEER_FLAG_NEXTHOP_UNCHANGED)
17716 || peergroup_af_flag_check(peer, afi, safi,
17717 PEER_FLAG_MED_UNCHANGED)) {
17718
17719 vty_out(vty,
17720 " neighbor %s attribute-unchanged%s%s%s\n",
17721 addr,
17722 peer_af_flag_check(peer, afi, safi,
17723 PEER_FLAG_AS_PATH_UNCHANGED)
17724 ? " as-path"
17725 : "",
17726 peer_af_flag_check(peer, afi, safi,
17727 PEER_FLAG_NEXTHOP_UNCHANGED)
17728 ? " next-hop"
17729 : "",
17730 peer_af_flag_check(peer, afi, safi,
17731 PEER_FLAG_MED_UNCHANGED)
17732 ? " med"
17733 : "");
17734 }
17735 }
17736 }
17737
17738 static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17739 safi_t safi)
17740 {
17741 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17742 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17743 vty_out(vty, " no bgp retain route-target all\n");
17744 }
17745
17746 /* Address family based peer configuration display. */
17747 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17748 safi_t safi)
17749 {
17750 struct peer *peer;
17751 struct peer_group *group;
17752 struct listnode *node, *nnode;
17753
17754
17755 vty_frame(vty, " !\n address-family ");
17756 if (afi == AFI_IP) {
17757 if (safi == SAFI_UNICAST)
17758 vty_frame(vty, "ipv4 unicast");
17759 else if (safi == SAFI_LABELED_UNICAST)
17760 vty_frame(vty, "ipv4 labeled-unicast");
17761 else if (safi == SAFI_MULTICAST)
17762 vty_frame(vty, "ipv4 multicast");
17763 else if (safi == SAFI_MPLS_VPN)
17764 vty_frame(vty, "ipv4 vpn");
17765 else if (safi == SAFI_ENCAP)
17766 vty_frame(vty, "ipv4 encap");
17767 else if (safi == SAFI_FLOWSPEC)
17768 vty_frame(vty, "ipv4 flowspec");
17769 } else if (afi == AFI_IP6) {
17770 if (safi == SAFI_UNICAST)
17771 vty_frame(vty, "ipv6 unicast");
17772 else if (safi == SAFI_LABELED_UNICAST)
17773 vty_frame(vty, "ipv6 labeled-unicast");
17774 else if (safi == SAFI_MULTICAST)
17775 vty_frame(vty, "ipv6 multicast");
17776 else if (safi == SAFI_MPLS_VPN)
17777 vty_frame(vty, "ipv6 vpn");
17778 else if (safi == SAFI_ENCAP)
17779 vty_frame(vty, "ipv6 encap");
17780 else if (safi == SAFI_FLOWSPEC)
17781 vty_frame(vty, "ipv6 flowspec");
17782 } else if (afi == AFI_L2VPN) {
17783 if (safi == SAFI_EVPN)
17784 vty_frame(vty, "l2vpn evpn");
17785 }
17786 vty_frame(vty, "\n");
17787
17788 bgp_config_write_distance(vty, bgp, afi, safi);
17789
17790 bgp_config_write_network(vty, bgp, afi, safi);
17791
17792 bgp_config_write_redistribute(vty, bgp, afi, safi);
17793
17794 /* BGP flag dampening. */
17795 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17796 bgp_config_write_damp(vty, afi, safi);
17797
17798 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17799 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17800
17801 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17802 /* Do not display doppelganger peers */
17803 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17804 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17805 }
17806
17807 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17808 bgp_config_write_table_map(vty, bgp, afi, safi);
17809
17810 if (safi == SAFI_EVPN)
17811 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17812
17813 if (safi == SAFI_FLOWSPEC)
17814 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17815
17816 if (safi == SAFI_MPLS_VPN)
17817 bgp_vpn_config_write(vty, bgp, afi, safi);
17818
17819 if (safi == SAFI_UNICAST) {
17820 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17821 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17822 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17823
17824 vty_out(vty, " export vpn\n");
17825 }
17826 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17827 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17828
17829 vty_out(vty, " import vpn\n");
17830 }
17831 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17832 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17833 char *name;
17834
17835 for (ALL_LIST_ELEMENTS_RO(
17836 bgp->vpn_policy[afi].import_vrf, node,
17837 name))
17838 vty_out(vty, " import vrf %s\n", name);
17839 }
17840 }
17841
17842 vty_endframe(vty, " exit-address-family\n");
17843 }
17844
17845 int bgp_config_write(struct vty *vty)
17846 {
17847 struct bgp *bgp;
17848 struct peer_group *group;
17849 struct peer *peer;
17850 struct listnode *node, *nnode;
17851 struct listnode *mnode, *mnnode;
17852 afi_t afi;
17853 safi_t safi;
17854 uint32_t tovpn_sid_index = 0;
17855
17856 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17857 vty_out(vty, "bgp route-map delay-timer %u\n",
17858 bm->rmap_update_timer);
17859
17860 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17861 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17862 if (bm->v_update_delay != bm->v_establish_wait)
17863 vty_out(vty, " %d", bm->v_establish_wait);
17864 vty_out(vty, "\n");
17865 }
17866
17867 if (bm->wait_for_fib)
17868 vty_out(vty, "bgp suppress-fib-pending\n");
17869
17870 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17871 vty_out(vty, "bgp graceful-shutdown\n");
17872
17873 /* No-RIB (Zebra) option flag configuration */
17874 if (bgp_option_check(BGP_OPT_NO_FIB))
17875 vty_out(vty, "bgp no-rib\n");
17876
17877 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17878 vty_out(vty, "bgp send-extra-data zebra\n");
17879
17880 /* BGP session DSCP value */
17881 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17882 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17883
17884 /* BGP InQ limit */
17885 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
17886 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17887
17888 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
17889 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
17890
17891 /* BGP configuration. */
17892 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17893
17894 /* skip all auto created vrf as they dont have user config */
17895 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17896 continue;
17897
17898 /* Router bgp ASN */
17899 vty_out(vty, "router bgp %u", bgp->as);
17900
17901 if (bgp->name)
17902 vty_out(vty, " %s %s",
17903 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17904 ? "view" : "vrf", bgp->name);
17905 vty_out(vty, "\n");
17906
17907 /* BGP fast-external-failover. */
17908 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17909 vty_out(vty, " no bgp fast-external-failover\n");
17910
17911 /* BGP router ID. */
17912 if (bgp->router_id_static.s_addr != INADDR_ANY)
17913 vty_out(vty, " bgp router-id %pI4\n",
17914 &bgp->router_id_static);
17915
17916 /* Suppress fib pending */
17917 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17918 vty_out(vty, " bgp suppress-fib-pending\n");
17919
17920 /* BGP log-neighbor-changes. */
17921 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17922 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17923 vty_out(vty, " %sbgp log-neighbor-changes\n",
17924 CHECK_FLAG(bgp->flags,
17925 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17926 ? ""
17927 : "no ");
17928
17929 /* BGP configuration. */
17930 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17931 vty_out(vty, " bgp always-compare-med\n");
17932
17933 /* RFC8212 default eBGP policy. */
17934 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17935 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17936 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17937 CHECK_FLAG(bgp->flags,
17938 BGP_FLAG_EBGP_REQUIRES_POLICY)
17939 ? ""
17940 : "no ");
17941
17942 /* draft-ietf-idr-deprecate-as-set-confed-set */
17943 if (bgp->reject_as_sets)
17944 vty_out(vty, " bgp reject-as-sets\n");
17945
17946 /* Suppress duplicate updates if the route actually not changed
17947 */
17948 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17949 != SAVE_BGP_SUPPRESS_DUPLICATES)
17950 vty_out(vty, " %sbgp suppress-duplicates\n",
17951 CHECK_FLAG(bgp->flags,
17952 BGP_FLAG_SUPPRESS_DUPLICATES)
17953 ? ""
17954 : "no ");
17955
17956 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17957 */
17958 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17959 SAVE_BGP_HARD_ADMIN_RESET)
17960 vty_out(vty, " %sbgp hard-administrative-reset\n",
17961 CHECK_FLAG(bgp->flags,
17962 BGP_FLAG_HARD_ADMIN_RESET)
17963 ? ""
17964 : "no ");
17965
17966 /* BGP default <afi>-<safi> */
17967 FOREACH_AFI_SAFI (afi, safi) {
17968 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17969 if (!bgp->default_af[afi][safi])
17970 vty_out(vty, " no bgp default %s\n",
17971 get_bgp_default_af_flag(afi,
17972 safi));
17973 } else if (bgp->default_af[afi][safi])
17974 vty_out(vty, " bgp default %s\n",
17975 get_bgp_default_af_flag(afi, safi));
17976 }
17977
17978 /* BGP default local-preference. */
17979 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17980 vty_out(vty, " bgp default local-preference %u\n",
17981 bgp->default_local_pref);
17982
17983 /* BGP default show-hostname */
17984 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17985 != SAVE_BGP_SHOW_HOSTNAME)
17986 vty_out(vty, " %sbgp default show-hostname\n",
17987 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17988 ? ""
17989 : "no ");
17990
17991 /* BGP default show-nexthop-hostname */
17992 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17993 != SAVE_BGP_SHOW_HOSTNAME)
17994 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17995 CHECK_FLAG(bgp->flags,
17996 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17997 ? ""
17998 : "no ");
17999
18000 /* BGP default subgroup-pkt-queue-max. */
18001 if (bgp->default_subgroup_pkt_queue_max
18002 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18003 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18004 bgp->default_subgroup_pkt_queue_max);
18005
18006 /* BGP client-to-client reflection. */
18007 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18008 vty_out(vty, " no bgp client-to-client reflection\n");
18009
18010 /* BGP cluster ID. */
18011 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18012 vty_out(vty, " bgp cluster-id %pI4\n",
18013 &bgp->cluster_id);
18014
18015 /* Disable ebgp connected nexthop check */
18016 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18017 vty_out(vty,
18018 " bgp disable-ebgp-connected-route-check\n");
18019
18020 /* Confederation identifier*/
18021 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18022 vty_out(vty, " bgp confederation identifier %u\n",
18023 bgp->confed_id);
18024
18025 /* Confederation peer */
18026 if (bgp->confed_peers_cnt > 0) {
18027 int i;
18028
18029 vty_out(vty, " bgp confederation peers");
18030
18031 for (i = 0; i < bgp->confed_peers_cnt; i++)
18032 vty_out(vty, " %u", bgp->confed_peers[i]);
18033
18034 vty_out(vty, "\n");
18035 }
18036
18037 /* BGP deterministic-med. */
18038 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18039 != SAVE_BGP_DETERMINISTIC_MED)
18040 vty_out(vty, " %sbgp deterministic-med\n",
18041 CHECK_FLAG(bgp->flags,
18042 BGP_FLAG_DETERMINISTIC_MED)
18043 ? ""
18044 : "no ");
18045
18046 /* BGP update-delay. */
18047 bgp_config_write_update_delay(vty, bgp);
18048
18049 if (bgp->v_maxmed_onstartup
18050 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18051 vty_out(vty, " bgp max-med on-startup %u",
18052 bgp->v_maxmed_onstartup);
18053 if (bgp->maxmed_onstartup_value
18054 != BGP_MAXMED_VALUE_DEFAULT)
18055 vty_out(vty, " %u",
18056 bgp->maxmed_onstartup_value);
18057 vty_out(vty, "\n");
18058 }
18059 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18060 vty_out(vty, " bgp max-med administrative");
18061 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18062 vty_out(vty, " %u", bgp->maxmed_admin_value);
18063 vty_out(vty, "\n");
18064 }
18065
18066 /* write quanta */
18067 bgp_config_write_wpkt_quanta(vty, bgp);
18068 /* read quanta */
18069 bgp_config_write_rpkt_quanta(vty, bgp);
18070
18071 /* coalesce time */
18072 bgp_config_write_coalesce_time(vty, bgp);
18073
18074 /* BGP per-instance graceful-shutdown */
18075 /* BGP-wide settings and per-instance settings are mutually
18076 * exclusive.
18077 */
18078 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18079 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18080 vty_out(vty, " bgp graceful-shutdown\n");
18081
18082 /* Long-lived Graceful Restart */
18083 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18084 vty_out(vty,
18085 " bgp long-lived-graceful-restart stale-time %u\n",
18086 bgp->llgr_stale_time);
18087
18088 /* BGP graceful-restart. */
18089 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18090 vty_out(vty,
18091 " bgp graceful-restart stalepath-time %u\n",
18092 bgp->stalepath_time);
18093
18094 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18095 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18096 bgp->restart_time);
18097
18098 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18099 SAVE_BGP_GRACEFUL_NOTIFICATION)
18100 vty_out(vty, " %sbgp graceful-restart notification\n",
18101 CHECK_FLAG(bgp->flags,
18102 BGP_FLAG_GRACEFUL_NOTIFICATION)
18103 ? ""
18104 : "no ");
18105
18106 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18107 vty_out(vty,
18108 " bgp graceful-restart select-defer-time %u\n",
18109 bgp->select_defer_time);
18110
18111 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18112 vty_out(vty, " bgp graceful-restart\n");
18113
18114 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18115 vty_out(vty, " bgp graceful-restart-disable\n");
18116
18117 /* BGP graceful-restart Preserve State F bit. */
18118 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18119 vty_out(vty,
18120 " bgp graceful-restart preserve-fw-state\n");
18121
18122 /* BGP TCP keepalive */
18123 bgp_config_tcp_keepalive(vty, bgp);
18124
18125 /* Stale timer for RIB */
18126 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18127 vty_out(vty,
18128 " bgp graceful-restart rib-stale-time %u\n",
18129 bgp->rib_stale_time);
18130
18131 /* BGP bestpath method. */
18132 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18133 vty_out(vty, " bgp bestpath as-path ignore\n");
18134 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18135 vty_out(vty, " bgp bestpath as-path confed\n");
18136
18137 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18138 if (CHECK_FLAG(bgp->flags,
18139 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18140 vty_out(vty,
18141 " bgp bestpath as-path multipath-relax as-set\n");
18142 } else {
18143 vty_out(vty,
18144 " bgp bestpath as-path multipath-relax\n");
18145 }
18146 }
18147
18148 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18149 vty_out(vty,
18150 " bgp route-reflector allow-outbound-policy\n");
18151 }
18152 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18153 vty_out(vty, " bgp bestpath compare-routerid\n");
18154 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18155 vty_out(vty, " bgp bestpath aigp\n");
18156 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18157 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18158 vty_out(vty, " bgp bestpath med");
18159 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18160 vty_out(vty, " confed");
18161 if (CHECK_FLAG(bgp->flags,
18162 BGP_FLAG_MED_MISSING_AS_WORST))
18163 vty_out(vty, " missing-as-worst");
18164 vty_out(vty, "\n");
18165 }
18166
18167 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18168 vty_out(vty,
18169 " bgp bestpath peer-type multipath-relax\n");
18170
18171 /* Link bandwidth handling. */
18172 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18173 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18174 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18175 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18176 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18177 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18178
18179 /* BGP network import check. */
18180 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18181 != SAVE_BGP_IMPORT_CHECK)
18182 vty_out(vty, " %sbgp network import-check\n",
18183 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18184 ? ""
18185 : "no ");
18186
18187 /* BGP timers configuration. */
18188 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18189 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18190 vty_out(vty, " timers bgp %u %u\n",
18191 bgp->default_keepalive, bgp->default_holdtime);
18192
18193 /* BGP minimum holdtime configuration. */
18194 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18195 && bgp->default_min_holdtime != 0)
18196 vty_out(vty, " bgp minimum-holdtime %u\n",
18197 bgp->default_min_holdtime);
18198
18199 /* Conditional advertisement timer configuration */
18200 if (bgp->condition_check_period
18201 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18202 vty_out(vty,
18203 " bgp conditional-advertisement timer %u\n",
18204 bgp->condition_check_period);
18205
18206 /* peer-group */
18207 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18208 bgp_config_write_peer_global(vty, bgp, group->conf);
18209 }
18210
18211 /* Normal neighbor configuration. */
18212 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18213 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18214 bgp_config_write_peer_global(vty, bgp, peer);
18215 }
18216
18217 /* listen range and limit for dynamic BGP neighbors */
18218 bgp_config_write_listen(vty, bgp);
18219
18220 /*
18221 * BGP default autoshutdown neighbors
18222 *
18223 * This must be placed after any peer and peer-group
18224 * configuration, to avoid setting all peers to shutdown after
18225 * a daemon restart, which is undesired behavior. (see #2286)
18226 */
18227 if (bgp->autoshutdown)
18228 vty_out(vty, " bgp default shutdown\n");
18229
18230 /* BGP instance administrative shutdown */
18231 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18232 vty_out(vty, " bgp shutdown\n");
18233
18234 if (bgp->allow_martian)
18235 vty_out(vty, " bgp allow-martian-nexthop\n");
18236
18237 if (bgp->fast_convergence)
18238 vty_out(vty, " bgp fast-convergence\n");
18239
18240 if (bgp->srv6_enabled) {
18241 vty_frame(vty, " !\n segment-routing srv6\n");
18242 if (strlen(bgp->srv6_locator_name))
18243 vty_out(vty, " locator %s\n",
18244 bgp->srv6_locator_name);
18245 vty_endframe(vty, " exit\n");
18246 }
18247
18248 tovpn_sid_index = bgp->tovpn_sid_index;
18249 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18250 vty_out(vty, " sid vpn per-vrf export auto\n");
18251 } else if (tovpn_sid_index != 0) {
18252 vty_out(vty, " sid vpn per-vrf export %d\n",
18253 tovpn_sid_index);
18254 }
18255
18256 /* IPv4 unicast configuration. */
18257 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18258
18259 /* IPv4 multicast configuration. */
18260 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18261
18262 /* IPv4 labeled-unicast configuration. */
18263 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18264
18265 /* IPv4 VPN configuration. */
18266 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18267
18268 /* ENCAPv4 configuration. */
18269 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18270
18271 /* FLOWSPEC v4 configuration. */
18272 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18273
18274 /* IPv6 unicast configuration. */
18275 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18276
18277 /* IPv6 multicast configuration. */
18278 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18279
18280 /* IPv6 labeled-unicast configuration. */
18281 bgp_config_write_family(vty, bgp, AFI_IP6,
18282 SAFI_LABELED_UNICAST);
18283
18284 /* IPv6 VPN configuration. */
18285 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18286
18287 /* ENCAPv6 configuration. */
18288 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18289
18290 /* FLOWSPEC v6 configuration. */
18291 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18292
18293 /* EVPN configuration. */
18294 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18295
18296 hook_call(bgp_inst_config_write, bgp, vty);
18297
18298 #ifdef ENABLE_BGP_VNC
18299 bgp_rfapi_cfg_write(vty, bgp);
18300 #endif
18301
18302 vty_out(vty, "exit\n");
18303 vty_out(vty, "!\n");
18304 }
18305 return 0;
18306 }
18307
18308
18309 /* BGP node structure. */
18310 static struct cmd_node bgp_node = {
18311 .name = "bgp",
18312 .node = BGP_NODE,
18313 .parent_node = CONFIG_NODE,
18314 .prompt = "%s(config-router)# ",
18315 .config_write = bgp_config_write,
18316 };
18317
18318 static struct cmd_node bgp_ipv4_unicast_node = {
18319 .name = "bgp ipv4 unicast",
18320 .node = BGP_IPV4_NODE,
18321 .parent_node = BGP_NODE,
18322 .prompt = "%s(config-router-af)# ",
18323 .no_xpath = true,
18324 };
18325
18326 static struct cmd_node bgp_ipv4_multicast_node = {
18327 .name = "bgp ipv4 multicast",
18328 .node = BGP_IPV4M_NODE,
18329 .parent_node = BGP_NODE,
18330 .prompt = "%s(config-router-af)# ",
18331 .no_xpath = true,
18332 };
18333
18334 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18335 .name = "bgp ipv4 labeled unicast",
18336 .node = BGP_IPV4L_NODE,
18337 .parent_node = BGP_NODE,
18338 .prompt = "%s(config-router-af)# ",
18339 .no_xpath = true,
18340 };
18341
18342 static struct cmd_node bgp_ipv6_unicast_node = {
18343 .name = "bgp ipv6 unicast",
18344 .node = BGP_IPV6_NODE,
18345 .parent_node = BGP_NODE,
18346 .prompt = "%s(config-router-af)# ",
18347 .no_xpath = true,
18348 };
18349
18350 static struct cmd_node bgp_ipv6_multicast_node = {
18351 .name = "bgp ipv6 multicast",
18352 .node = BGP_IPV6M_NODE,
18353 .parent_node = BGP_NODE,
18354 .prompt = "%s(config-router-af)# ",
18355 .no_xpath = true,
18356 };
18357
18358 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18359 .name = "bgp ipv6 labeled unicast",
18360 .node = BGP_IPV6L_NODE,
18361 .parent_node = BGP_NODE,
18362 .prompt = "%s(config-router-af)# ",
18363 .no_xpath = true,
18364 };
18365
18366 static struct cmd_node bgp_vpnv4_node = {
18367 .name = "bgp vpnv4",
18368 .node = BGP_VPNV4_NODE,
18369 .parent_node = BGP_NODE,
18370 .prompt = "%s(config-router-af)# ",
18371 .no_xpath = true,
18372 };
18373
18374 static struct cmd_node bgp_vpnv6_node = {
18375 .name = "bgp vpnv6",
18376 .node = BGP_VPNV6_NODE,
18377 .parent_node = BGP_NODE,
18378 .prompt = "%s(config-router-af-vpnv6)# ",
18379 .no_xpath = true,
18380 };
18381
18382 static struct cmd_node bgp_evpn_node = {
18383 .name = "bgp evpn",
18384 .node = BGP_EVPN_NODE,
18385 .parent_node = BGP_NODE,
18386 .prompt = "%s(config-router-evpn)# ",
18387 .no_xpath = true,
18388 };
18389
18390 static struct cmd_node bgp_evpn_vni_node = {
18391 .name = "bgp evpn vni",
18392 .node = BGP_EVPN_VNI_NODE,
18393 .parent_node = BGP_EVPN_NODE,
18394 .prompt = "%s(config-router-af-vni)# ",
18395 };
18396
18397 static struct cmd_node bgp_flowspecv4_node = {
18398 .name = "bgp ipv4 flowspec",
18399 .node = BGP_FLOWSPECV4_NODE,
18400 .parent_node = BGP_NODE,
18401 .prompt = "%s(config-router-af)# ",
18402 .no_xpath = true,
18403 };
18404
18405 static struct cmd_node bgp_flowspecv6_node = {
18406 .name = "bgp ipv6 flowspec",
18407 .node = BGP_FLOWSPECV6_NODE,
18408 .parent_node = BGP_NODE,
18409 .prompt = "%s(config-router-af-vpnv6)# ",
18410 .no_xpath = true,
18411 };
18412
18413 static struct cmd_node bgp_srv6_node = {
18414 .name = "bgp srv6",
18415 .node = BGP_SRV6_NODE,
18416 .parent_node = BGP_NODE,
18417 .prompt = "%s(config-router-srv6)# ",
18418 };
18419
18420 static void community_list_vty(void);
18421
18422 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18423 {
18424 struct bgp *bgp;
18425 struct peer_group *group;
18426 struct listnode *lnbgp, *lnpeer;
18427
18428 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18429 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18430 vector_set(comps,
18431 XSTRDUP(MTYPE_COMPLETION, group->name));
18432 }
18433 }
18434
18435 static void bgp_ac_peer(vector comps, struct cmd_token *token)
18436 {
18437 struct bgp *bgp;
18438 struct peer *peer;
18439 struct listnode *lnbgp, *lnpeer;
18440
18441 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18442 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18443 /* only provide suggestions on the appropriate input
18444 * token type,
18445 * they'll otherwise show up multiple times */
18446 enum cmd_token_type match_type;
18447 char *name = peer->host;
18448
18449 if (peer->conf_if) {
18450 match_type = VARIABLE_TKN;
18451 name = peer->conf_if;
18452 } else if (strchr(peer->host, ':'))
18453 match_type = IPV6_TKN;
18454 else
18455 match_type = IPV4_TKN;
18456
18457 if (token->type != match_type)
18458 continue;
18459
18460 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18461 }
18462 }
18463 }
18464
18465 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18466 {
18467 bgp_ac_peer(comps, token);
18468
18469 if (token->type == VARIABLE_TKN)
18470 bgp_ac_peergroup(comps, token);
18471 }
18472
18473 static const struct cmd_variable_handler bgp_var_neighbor[] = {
18474 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18475 {.varname = "neighbors", .completions = bgp_ac_neighbor},
18476 {.varname = "peer", .completions = bgp_ac_neighbor},
18477 {.completions = NULL}};
18478
18479 static const struct cmd_variable_handler bgp_var_peergroup[] = {
18480 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18481 {.completions = NULL} };
18482
18483 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18484
18485 static struct thread *t_bgp_cfg;
18486
18487 bool bgp_config_inprocess(void)
18488 {
18489 return thread_is_scheduled(t_bgp_cfg);
18490 }
18491
18492 static void bgp_config_finish(struct thread *t)
18493 {
18494 struct listnode *node;
18495 struct bgp *bgp;
18496
18497 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18498 hook_call(bgp_config_end, bgp);
18499 }
18500
18501 static void bgp_config_start(void)
18502 {
18503 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18504 THREAD_OFF(t_bgp_cfg);
18505 thread_add_timer(bm->master, bgp_config_finish, NULL,
18506 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18507 }
18508
18509 /* When we receive a hook the configuration is read,
18510 * we start a timer to make sure we postpone sending
18511 * EoR before route-maps are processed.
18512 * This is especially valid if using `bgp route-map delay-timer`.
18513 */
18514 static void bgp_config_end(void)
18515 {
18516 #define BGP_POST_CONFIG_DELAY_SECONDS 1
18517 uint32_t bgp_post_config_delay =
18518 thread_is_scheduled(bm->t_rmap_update)
18519 ? thread_timer_remain_second(bm->t_rmap_update)
18520 : BGP_POST_CONFIG_DELAY_SECONDS;
18521
18522 /* If BGP config processing thread isn't running, then
18523 * we can return and rely it's properly handled.
18524 */
18525 if (!bgp_config_inprocess())
18526 return;
18527
18528 THREAD_OFF(t_bgp_cfg);
18529
18530 /* Start a new timer to make sure we don't send EoR
18531 * before route-maps are processed.
18532 */
18533 thread_add_timer(bm->master, bgp_config_finish, NULL,
18534 bgp_post_config_delay, &t_bgp_cfg);
18535 }
18536
18537 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18538 {
18539 int write = 0;
18540 struct interface *ifp;
18541 struct bgp_interface *iifp;
18542
18543 FOR_ALL_INTERFACES (vrf, ifp) {
18544 iifp = ifp->info;
18545 if (!iifp)
18546 continue;
18547
18548 if_vty_config_start(vty, ifp);
18549
18550 if (CHECK_FLAG(iifp->flags,
18551 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18552 vty_out(vty, " mpls bgp forwarding\n");
18553 write++;
18554 }
18555
18556 if_vty_config_end(vty);
18557 }
18558
18559 return write;
18560 }
18561
18562 /* Configuration write function for bgpd. */
18563 static int config_write_interface(struct vty *vty)
18564 {
18565 int write = 0;
18566 struct vrf *vrf = NULL;
18567
18568 /* Display all VRF aware OSPF interface configuration */
18569 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18570 write += config_write_interface_one(vty, vrf);
18571 }
18572
18573 return write;
18574 }
18575
18576 DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18577 "[no$no] mpls bgp forwarding",
18578 NO_STR MPLS_STR BGP_STR
18579 "Enable MPLS forwarding for eBGP directly connected peers\n")
18580 {
18581 bool check;
18582 struct bgp_interface *iifp;
18583
18584 VTY_DECLVAR_CONTEXT(interface, ifp);
18585 iifp = ifp->info;
18586 if (!iifp) {
18587 vty_out(vty, "Interface %s not available\n", ifp->name);
18588 return CMD_WARNING_CONFIG_FAILED;
18589 }
18590 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18591 if (check != !no) {
18592 if (no)
18593 UNSET_FLAG(iifp->flags,
18594 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18595 else
18596 SET_FLAG(iifp->flags,
18597 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18598 /* trigger a nht update on eBGP sessions */
18599 if (if_is_operative(ifp))
18600 bgp_nht_ifp_up(ifp);
18601 }
18602 return CMD_SUCCESS;
18603 }
18604
18605 DEFPY (bgp_inq_limit,
18606 bgp_inq_limit_cmd,
18607 "bgp input-queue-limit (1-4294967295)$limit",
18608 BGP_STR
18609 "Set the BGP Input Queue limit for all peers when message parsing\n"
18610 "Input-Queue limit\n")
18611 {
18612 bm->inq_limit = limit;
18613
18614 return CMD_SUCCESS;
18615 }
18616
18617 DEFPY (no_bgp_inq_limit,
18618 no_bgp_inq_limit_cmd,
18619 "no bgp input-queue-limit [(1-4294967295)$limit]",
18620 NO_STR
18621 BGP_STR
18622 "Set the BGP Input Queue limit for all peers when message parsing\n"
18623 "Input-Queue limit\n")
18624 {
18625 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18626
18627 return CMD_SUCCESS;
18628 }
18629
18630 DEFPY (bgp_outq_limit,
18631 bgp_outq_limit_cmd,
18632 "bgp output-queue-limit (1-4294967295)$limit",
18633 BGP_STR
18634 "Set the BGP Output Queue limit for all peers when message parsing\n"
18635 "Output-Queue limit\n")
18636 {
18637 bm->outq_limit = limit;
18638
18639 return CMD_SUCCESS;
18640 }
18641
18642 DEFPY (no_bgp_outq_limit,
18643 no_bgp_outq_limit_cmd,
18644 "no bgp output-queue-limit [(1-4294967295)$limit]",
18645 NO_STR
18646 BGP_STR
18647 "Set the BGP Output Queue limit for all peers when message parsing\n"
18648 "Output-Queue limit\n")
18649 {
18650 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18651
18652 return CMD_SUCCESS;
18653 }
18654
18655
18656 /* Initialization of BGP interface. */
18657 static void bgp_vty_if_init(void)
18658 {
18659 /* Install interface node. */
18660 if_cmd_init(config_write_interface);
18661
18662 /* "mpls bgp forwarding" commands. */
18663 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18664 }
18665
18666 void bgp_vty_init(void)
18667 {
18668 cmd_variable_handler_register(bgp_var_neighbor);
18669 cmd_variable_handler_register(bgp_var_peergroup);
18670
18671 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18672
18673 /* Install bgp top node. */
18674 install_node(&bgp_node);
18675 install_node(&bgp_ipv4_unicast_node);
18676 install_node(&bgp_ipv4_multicast_node);
18677 install_node(&bgp_ipv4_labeled_unicast_node);
18678 install_node(&bgp_ipv6_unicast_node);
18679 install_node(&bgp_ipv6_multicast_node);
18680 install_node(&bgp_ipv6_labeled_unicast_node);
18681 install_node(&bgp_vpnv4_node);
18682 install_node(&bgp_vpnv6_node);
18683 install_node(&bgp_evpn_node);
18684 install_node(&bgp_evpn_vni_node);
18685 install_node(&bgp_flowspecv4_node);
18686 install_node(&bgp_flowspecv6_node);
18687 install_node(&bgp_srv6_node);
18688
18689 /* Install default VTY commands to new nodes. */
18690 install_default(BGP_NODE);
18691 install_default(BGP_IPV4_NODE);
18692 install_default(BGP_IPV4M_NODE);
18693 install_default(BGP_IPV4L_NODE);
18694 install_default(BGP_IPV6_NODE);
18695 install_default(BGP_IPV6M_NODE);
18696 install_default(BGP_IPV6L_NODE);
18697 install_default(BGP_VPNV4_NODE);
18698 install_default(BGP_VPNV6_NODE);
18699 install_default(BGP_FLOWSPECV4_NODE);
18700 install_default(BGP_FLOWSPECV6_NODE);
18701 install_default(BGP_EVPN_NODE);
18702 install_default(BGP_EVPN_VNI_NODE);
18703 install_default(BGP_SRV6_NODE);
18704
18705 /* "global bgp inq-limit command */
18706 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18707 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18708 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18709 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
18710
18711 /* "bgp local-mac" hidden commands. */
18712 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18713 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18714
18715 /* "bgp suppress-fib-pending" global */
18716 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18717
18718 /* bgp route-map delay-timer commands. */
18719 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18720 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18721
18722 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18723
18724 /* bgp fast-convergence command */
18725 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18726 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18727
18728 /* global bgp update-delay command */
18729 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18730 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18731
18732 /* global bgp graceful-shutdown command */
18733 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18734 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18735
18736 /* Dummy commands (Currently not supported) */
18737 install_element(BGP_NODE, &no_synchronization_cmd);
18738 install_element(BGP_NODE, &no_auto_summary_cmd);
18739
18740 /* "router bgp" commands. */
18741 install_element(CONFIG_NODE, &router_bgp_cmd);
18742
18743 /* "no router bgp" commands. */
18744 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18745
18746 /* "bgp session-dscp command */
18747 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18748 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18749
18750 /* "bgp router-id" commands. */
18751 install_element(BGP_NODE, &bgp_router_id_cmd);
18752 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18753
18754 /* "bgp suppress-fib-pending" command */
18755 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18756
18757 /* "bgp cluster-id" commands. */
18758 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18759 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18760
18761 /* "bgp no-rib" commands. */
18762 install_element(CONFIG_NODE, &bgp_norib_cmd);
18763 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18764
18765 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18766
18767 /* "bgp confederation" commands. */
18768 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18769 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18770
18771 /* "bgp confederation peers" commands. */
18772 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18773 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18774
18775 /* bgp max-med command */
18776 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18777 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18778 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18779 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18780 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18781
18782 /* "neighbor role" commands. */
18783 install_element(BGP_NODE, &neighbor_role_cmd);
18784 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18785 install_element(BGP_NODE, &no_neighbor_role_cmd);
18786
18787 /* "neighbor aigp" commands. */
18788 install_element(BGP_NODE, &neighbor_aigp_cmd);
18789
18790 /* "neighbor graceful-shutdown" command */
18791 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18792
18793 /* bgp disable-ebgp-connected-nh-check */
18794 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18795 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18796
18797 /* bgp update-delay command */
18798 install_element(BGP_NODE, &bgp_update_delay_cmd);
18799 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18800
18801 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18802 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18803
18804 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18805 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18806
18807 /* "maximum-paths" commands. */
18808 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18809 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18810 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18811 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18812 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18813 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18814 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18815 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18816 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18817 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18818 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18819 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18820 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18821 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18822 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18823
18824 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18825 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18826 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18827 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18828 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18829 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18830 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18831 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18832 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18833 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18834
18835 /* "timers bgp" commands. */
18836 install_element(BGP_NODE, &bgp_timers_cmd);
18837 install_element(BGP_NODE, &no_bgp_timers_cmd);
18838
18839 /* "minimum-holdtime" commands. */
18840 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18841 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18842
18843 /* route-map delay-timer commands - per instance for backwards compat.
18844 */
18845 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18846 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18847
18848 /* "bgp client-to-client reflection" commands */
18849 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18850 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18851
18852 /* "bgp always-compare-med" commands */
18853 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18854 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18855
18856 /* bgp ebgp-requires-policy */
18857 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18858 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18859
18860 /* bgp suppress-duplicates */
18861 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18862 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18863
18864 /* bgp reject-as-sets */
18865 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18866 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18867
18868 /* "bgp deterministic-med" commands */
18869 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18870 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18871
18872 /* "bgp graceful-restart" command */
18873 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18874 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18875
18876 /* "bgp graceful-restart-disable" command */
18877 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18878 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18879
18880 /* "neighbor a:b:c:d graceful-restart" command */
18881 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18882 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18883
18884 /* "neighbor a:b:c:d graceful-restart-disable" command */
18885 install_element(BGP_NODE,
18886 &bgp_neighbor_graceful_restart_disable_set_cmd);
18887 install_element(BGP_NODE,
18888 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18889
18890 /* "neighbor a:b:c:d graceful-restart-helper" command */
18891 install_element(BGP_NODE,
18892 &bgp_neighbor_graceful_restart_helper_set_cmd);
18893 install_element(BGP_NODE,
18894 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18895
18896 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18897 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18898 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18899 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18900 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18901 install_element(BGP_NODE,
18902 &no_bgp_graceful_restart_select_defer_time_cmd);
18903 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18904 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18905 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18906
18907 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18908 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18909 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18910 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18911
18912 /* "bgp graceful-shutdown" commands */
18913 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18914 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18915
18916 /* "bgp hard-administrative-reset" commands */
18917 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18918
18919 /* "bgp long-lived-graceful-restart" commands */
18920 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18921 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18922
18923 /* "bgp fast-external-failover" commands */
18924 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18925 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18926
18927 /* "bgp bestpath aigp" commands */
18928 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
18929
18930 /* "bgp bestpath compare-routerid" commands */
18931 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18932 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18933
18934 /* "bgp bestpath as-path ignore" commands */
18935 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18936 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18937
18938 /* "bgp bestpath as-path confed" commands */
18939 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18940 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18941
18942 /* "bgp bestpath as-path multipath-relax" commands */
18943 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18944 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18945
18946 /* "bgp bestpath peer-type multipath-relax" commands */
18947 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18948 install_element(BGP_NODE,
18949 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18950
18951 /* "bgp log-neighbor-changes" commands */
18952 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18953 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18954
18955 /* "bgp bestpath med" commands */
18956 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18957 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18958
18959 /* "bgp bestpath bandwidth" commands */
18960 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18961 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18962
18963 /* "no bgp default <afi>-<safi>" commands. */
18964 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18965
18966 /* "bgp network import-check" commands. */
18967 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18968 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18969 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18970
18971 /* "bgp default local-preference" commands. */
18972 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18973 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18974
18975 /* bgp default show-hostname */
18976 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18977 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18978
18979 /* bgp default show-nexthop-hostname */
18980 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18981 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18982
18983 /* "bgp default subgroup-pkt-queue-max" commands. */
18984 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18985 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18986
18987 /* bgp ibgp-allow-policy-mods command */
18988 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18989 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18990
18991 /* "bgp listen limit" commands. */
18992 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18993 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18994
18995 /* "bgp listen range" commands. */
18996 install_element(BGP_NODE, &bgp_listen_range_cmd);
18997 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18998
18999 /* "bgp default shutdown" command */
19000 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19001
19002 /* "bgp shutdown" commands */
19003 install_element(BGP_NODE, &bgp_shutdown_cmd);
19004 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19005 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19006 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19007
19008 /* "neighbor remote-as" commands. */
19009 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19010 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19011 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19012 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19013 install_element(BGP_NODE,
19014 &neighbor_interface_v6only_config_remote_as_cmd);
19015 install_element(BGP_NODE, &no_neighbor_cmd);
19016 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19017
19018 /* "neighbor peer-group" commands. */
19019 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19020 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19021 install_element(BGP_NODE,
19022 &no_neighbor_interface_peer_group_remote_as_cmd);
19023
19024 /* "neighbor local-as" commands. */
19025 install_element(BGP_NODE, &neighbor_local_as_cmd);
19026 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19027 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19028 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19029
19030 /* "neighbor solo" commands. */
19031 install_element(BGP_NODE, &neighbor_solo_cmd);
19032 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19033
19034 /* "neighbor password" commands. */
19035 install_element(BGP_NODE, &neighbor_password_cmd);
19036 install_element(BGP_NODE, &no_neighbor_password_cmd);
19037
19038 /* "neighbor activate" commands. */
19039 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19040 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19041 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19042 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19043 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19044 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19045 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19046 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19047 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19048 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19049 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19050 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19051
19052 /* "no neighbor activate" commands. */
19053 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19054 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19055 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19056 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19057 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19058 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19059 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19060 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19061 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19062 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19063 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19064 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19065
19066 /* "neighbor peer-group" set commands. */
19067 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19068 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19069 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19070 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19071 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19072 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19073 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19074 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19075 install_element(BGP_FLOWSPECV4_NODE,
19076 &neighbor_set_peer_group_hidden_cmd);
19077 install_element(BGP_FLOWSPECV6_NODE,
19078 &neighbor_set_peer_group_hidden_cmd);
19079
19080 /* "no neighbor peer-group unset" commands. */
19081 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19082 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19083 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19084 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19085 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19086 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19087 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19088 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19089 install_element(BGP_FLOWSPECV4_NODE,
19090 &no_neighbor_set_peer_group_hidden_cmd);
19091 install_element(BGP_FLOWSPECV6_NODE,
19092 &no_neighbor_set_peer_group_hidden_cmd);
19093
19094 /* "neighbor softreconfiguration inbound" commands.*/
19095 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19096 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19097 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19098 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19099 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19100 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19101 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19102 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19103 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19104 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19105 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19106 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19107 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19108 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19109 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19110 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19111 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19112 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19113 install_element(BGP_FLOWSPECV4_NODE,
19114 &neighbor_soft_reconfiguration_cmd);
19115 install_element(BGP_FLOWSPECV4_NODE,
19116 &no_neighbor_soft_reconfiguration_cmd);
19117 install_element(BGP_FLOWSPECV6_NODE,
19118 &neighbor_soft_reconfiguration_cmd);
19119 install_element(BGP_FLOWSPECV6_NODE,
19120 &no_neighbor_soft_reconfiguration_cmd);
19121 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19122 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19123
19124 /* "neighbor attribute-unchanged" commands. */
19125 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19126 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19127 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19128 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19129 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19130 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19131 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19132 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19133 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19134 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19135 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19136 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19137 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19138 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19139 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19140 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19141 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19142 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19143
19144 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19145 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19146
19147 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19148 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19149 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19150 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19151
19152 /* "nexthop-local unchanged" commands */
19153 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19154 install_element(BGP_IPV6_NODE,
19155 &no_neighbor_nexthop_local_unchanged_cmd);
19156
19157 /* "neighbor next-hop-self" commands. */
19158 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19159 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19160 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19161 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19162 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19163 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19164 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19165 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19166 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19167 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19168 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19169 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19170 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19171 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19172 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19173 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19174 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19175 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19176 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19177 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19178
19179 /* "neighbor next-hop-self force" commands. */
19180 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19181 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19182 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19183 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19184 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19185 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19186 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19187 install_element(BGP_IPV4_NODE,
19188 &no_neighbor_nexthop_self_all_hidden_cmd);
19189 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19190 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19191 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19192 install_element(BGP_IPV4M_NODE,
19193 &no_neighbor_nexthop_self_all_hidden_cmd);
19194 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19195 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19196 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19197 install_element(BGP_IPV4L_NODE,
19198 &no_neighbor_nexthop_self_all_hidden_cmd);
19199 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19200 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19201 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19202 install_element(BGP_IPV6_NODE,
19203 &no_neighbor_nexthop_self_all_hidden_cmd);
19204 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19205 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19206 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19207 install_element(BGP_IPV6M_NODE,
19208 &no_neighbor_nexthop_self_all_hidden_cmd);
19209 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19210 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19211 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19212 install_element(BGP_IPV6L_NODE,
19213 &no_neighbor_nexthop_self_all_hidden_cmd);
19214 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19215 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19216 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19217 install_element(BGP_VPNV4_NODE,
19218 &no_neighbor_nexthop_self_all_hidden_cmd);
19219 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19220 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19221 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19222 install_element(BGP_VPNV6_NODE,
19223 &no_neighbor_nexthop_self_all_hidden_cmd);
19224 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19225 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19226
19227 /* "neighbor as-override" commands. */
19228 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19229 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19230 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19231 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19232 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19233 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19234 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19235 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19236 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19237 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19238 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19239 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19240 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19241 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19242 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19243 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19244 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19245 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19246
19247 /* "neighbor remove-private-AS" commands. */
19248 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19249 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19250 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19251 install_element(BGP_NODE,
19252 &no_neighbor_remove_private_as_all_hidden_cmd);
19253 install_element(BGP_NODE,
19254 &neighbor_remove_private_as_replace_as_hidden_cmd);
19255 install_element(BGP_NODE,
19256 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19257 install_element(BGP_NODE,
19258 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19259 install_element(
19260 BGP_NODE,
19261 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19262 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19263 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19264 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19265 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19266 install_element(BGP_IPV4_NODE,
19267 &neighbor_remove_private_as_replace_as_cmd);
19268 install_element(BGP_IPV4_NODE,
19269 &no_neighbor_remove_private_as_replace_as_cmd);
19270 install_element(BGP_IPV4_NODE,
19271 &neighbor_remove_private_as_all_replace_as_cmd);
19272 install_element(BGP_IPV4_NODE,
19273 &no_neighbor_remove_private_as_all_replace_as_cmd);
19274 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19275 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19276 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19277 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19278 install_element(BGP_IPV4M_NODE,
19279 &neighbor_remove_private_as_replace_as_cmd);
19280 install_element(BGP_IPV4M_NODE,
19281 &no_neighbor_remove_private_as_replace_as_cmd);
19282 install_element(BGP_IPV4M_NODE,
19283 &neighbor_remove_private_as_all_replace_as_cmd);
19284 install_element(BGP_IPV4M_NODE,
19285 &no_neighbor_remove_private_as_all_replace_as_cmd);
19286 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19287 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19288 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19289 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19290 install_element(BGP_IPV4L_NODE,
19291 &neighbor_remove_private_as_replace_as_cmd);
19292 install_element(BGP_IPV4L_NODE,
19293 &no_neighbor_remove_private_as_replace_as_cmd);
19294 install_element(BGP_IPV4L_NODE,
19295 &neighbor_remove_private_as_all_replace_as_cmd);
19296 install_element(BGP_IPV4L_NODE,
19297 &no_neighbor_remove_private_as_all_replace_as_cmd);
19298 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19299 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19300 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19301 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19302 install_element(BGP_IPV6_NODE,
19303 &neighbor_remove_private_as_replace_as_cmd);
19304 install_element(BGP_IPV6_NODE,
19305 &no_neighbor_remove_private_as_replace_as_cmd);
19306 install_element(BGP_IPV6_NODE,
19307 &neighbor_remove_private_as_all_replace_as_cmd);
19308 install_element(BGP_IPV6_NODE,
19309 &no_neighbor_remove_private_as_all_replace_as_cmd);
19310 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19311 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19312 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19313 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19314 install_element(BGP_IPV6M_NODE,
19315 &neighbor_remove_private_as_replace_as_cmd);
19316 install_element(BGP_IPV6M_NODE,
19317 &no_neighbor_remove_private_as_replace_as_cmd);
19318 install_element(BGP_IPV6M_NODE,
19319 &neighbor_remove_private_as_all_replace_as_cmd);
19320 install_element(BGP_IPV6M_NODE,
19321 &no_neighbor_remove_private_as_all_replace_as_cmd);
19322 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19323 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19324 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19325 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19326 install_element(BGP_IPV6L_NODE,
19327 &neighbor_remove_private_as_replace_as_cmd);
19328 install_element(BGP_IPV6L_NODE,
19329 &no_neighbor_remove_private_as_replace_as_cmd);
19330 install_element(BGP_IPV6L_NODE,
19331 &neighbor_remove_private_as_all_replace_as_cmd);
19332 install_element(BGP_IPV6L_NODE,
19333 &no_neighbor_remove_private_as_all_replace_as_cmd);
19334 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19335 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19336 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19337 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19338 install_element(BGP_VPNV4_NODE,
19339 &neighbor_remove_private_as_replace_as_cmd);
19340 install_element(BGP_VPNV4_NODE,
19341 &no_neighbor_remove_private_as_replace_as_cmd);
19342 install_element(BGP_VPNV4_NODE,
19343 &neighbor_remove_private_as_all_replace_as_cmd);
19344 install_element(BGP_VPNV4_NODE,
19345 &no_neighbor_remove_private_as_all_replace_as_cmd);
19346 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19347 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19348 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19349 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19350 install_element(BGP_VPNV6_NODE,
19351 &neighbor_remove_private_as_replace_as_cmd);
19352 install_element(BGP_VPNV6_NODE,
19353 &no_neighbor_remove_private_as_replace_as_cmd);
19354 install_element(BGP_VPNV6_NODE,
19355 &neighbor_remove_private_as_all_replace_as_cmd);
19356 install_element(BGP_VPNV6_NODE,
19357 &no_neighbor_remove_private_as_all_replace_as_cmd);
19358
19359 /* "neighbor send-community" commands.*/
19360 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19361 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19362 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19363 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19364 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19365 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19366 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19367 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19368 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19369 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19370 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19371 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19372 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19373 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19374 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19375 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19376 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19377 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19378 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19379 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19380 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19381 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19382 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19383 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19384 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19385 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19386 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19387 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19388 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19389 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19390 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19391 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19392 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19393 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19394 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19395 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19396
19397 /* "neighbor route-reflector" commands.*/
19398 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19399 install_element(BGP_NODE,
19400 &no_neighbor_route_reflector_client_hidden_cmd);
19401 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19402 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19403 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19404 install_element(BGP_IPV4M_NODE,
19405 &no_neighbor_route_reflector_client_cmd);
19406 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19407 install_element(BGP_IPV4L_NODE,
19408 &no_neighbor_route_reflector_client_cmd);
19409 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19410 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19411 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19412 install_element(BGP_IPV6M_NODE,
19413 &no_neighbor_route_reflector_client_cmd);
19414 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19415 install_element(BGP_IPV6L_NODE,
19416 &no_neighbor_route_reflector_client_cmd);
19417 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19418 install_element(BGP_VPNV4_NODE,
19419 &no_neighbor_route_reflector_client_cmd);
19420 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19421 install_element(BGP_VPNV6_NODE,
19422 &no_neighbor_route_reflector_client_cmd);
19423 install_element(BGP_FLOWSPECV4_NODE,
19424 &neighbor_route_reflector_client_cmd);
19425 install_element(BGP_FLOWSPECV4_NODE,
19426 &no_neighbor_route_reflector_client_cmd);
19427 install_element(BGP_FLOWSPECV6_NODE,
19428 &neighbor_route_reflector_client_cmd);
19429 install_element(BGP_FLOWSPECV6_NODE,
19430 &no_neighbor_route_reflector_client_cmd);
19431 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19432 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19433
19434 /* "neighbor route-server" commands.*/
19435 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19436 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19437 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19438 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19439 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19440 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19441 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19442 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19443 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19444 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19445 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19446 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19447 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19448 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19449 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19450 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19451 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19452 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19453 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19454 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19455 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19456 install_element(BGP_FLOWSPECV4_NODE,
19457 &no_neighbor_route_server_client_cmd);
19458 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19459 install_element(BGP_FLOWSPECV6_NODE,
19460 &no_neighbor_route_server_client_cmd);
19461
19462 /* "neighbor disable-addpath-rx" commands. */
19463 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19464 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19465 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19466 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19467 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19468 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19469 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19470 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19471 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19472 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19473 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19474 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19475 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19476 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19477 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19478 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19479
19480 /* "neighbor addpath-tx-all-paths" commands.*/
19481 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19482 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19483 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19484 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19485 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19486 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19487 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19488 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19489 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19490 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19491 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19492 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19493 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19494 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19495 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19496 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19497 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19498 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19499
19500 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19501 install_element(BGP_NODE,
19502 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19503 install_element(BGP_NODE,
19504 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19505 install_element(BGP_IPV4_NODE,
19506 &neighbor_addpath_tx_bestpath_per_as_cmd);
19507 install_element(BGP_IPV4_NODE,
19508 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19509 install_element(BGP_IPV4M_NODE,
19510 &neighbor_addpath_tx_bestpath_per_as_cmd);
19511 install_element(BGP_IPV4M_NODE,
19512 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19513 install_element(BGP_IPV4L_NODE,
19514 &neighbor_addpath_tx_bestpath_per_as_cmd);
19515 install_element(BGP_IPV4L_NODE,
19516 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19517 install_element(BGP_IPV6_NODE,
19518 &neighbor_addpath_tx_bestpath_per_as_cmd);
19519 install_element(BGP_IPV6_NODE,
19520 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19521 install_element(BGP_IPV6M_NODE,
19522 &neighbor_addpath_tx_bestpath_per_as_cmd);
19523 install_element(BGP_IPV6M_NODE,
19524 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19525 install_element(BGP_IPV6L_NODE,
19526 &neighbor_addpath_tx_bestpath_per_as_cmd);
19527 install_element(BGP_IPV6L_NODE,
19528 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19529 install_element(BGP_VPNV4_NODE,
19530 &neighbor_addpath_tx_bestpath_per_as_cmd);
19531 install_element(BGP_VPNV4_NODE,
19532 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19533 install_element(BGP_VPNV6_NODE,
19534 &neighbor_addpath_tx_bestpath_per_as_cmd);
19535 install_element(BGP_VPNV6_NODE,
19536 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19537
19538 /* "neighbor sender-as-path-loop-detection" commands. */
19539 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19540 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19541
19542 /* "neighbor path-attribute discard" commands. */
19543 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19544
19545 /* "neighbor passive" commands. */
19546 install_element(BGP_NODE, &neighbor_passive_cmd);
19547 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19548
19549
19550 /* "neighbor shutdown" commands. */
19551 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19552 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19553 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19554 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19555 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19556 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19557
19558 /* "neighbor capability extended-nexthop" commands.*/
19559 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19560 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19561
19562 /* "neighbor capability orf prefix-list" commands.*/
19563 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19564 install_element(BGP_NODE,
19565 &no_neighbor_capability_orf_prefix_hidden_cmd);
19566 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19567 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19568 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19569 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19570 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19571 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19572 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19573 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19574 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19575 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19576 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19577 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19578
19579 /* "neighbor capability dynamic" commands.*/
19580 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19581 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19582
19583 /* "neighbor dont-capability-negotiate" commands. */
19584 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19585 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19586
19587 /* "neighbor ebgp-multihop" commands. */
19588 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19589 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19590 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19591
19592 /* "neighbor disable-connected-check" commands. */
19593 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19594 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19595
19596 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19597 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19598 install_element(BGP_NODE,
19599 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19600
19601 /* "neighbor extended-optional-parameters" commands. */
19602 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19603 install_element(BGP_NODE,
19604 &no_neighbor_extended_optional_parameters_cmd);
19605
19606 /* "neighbor enforce-first-as" commands. */
19607 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19608 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19609
19610 /* "neighbor description" commands. */
19611 install_element(BGP_NODE, &neighbor_description_cmd);
19612 install_element(BGP_NODE, &no_neighbor_description_cmd);
19613 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19614
19615 /* "neighbor update-source" commands. "*/
19616 install_element(BGP_NODE, &neighbor_update_source_cmd);
19617 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19618
19619 /* "neighbor default-originate" commands. */
19620 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19621 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19622 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19623 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19624 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19625 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19626 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19627 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19628 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19629 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19630 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19631 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19632 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19633 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19634 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19635 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19636 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19637 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19638 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19639 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19640 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19641
19642 /* "neighbor port" commands. */
19643 install_element(BGP_NODE, &neighbor_port_cmd);
19644 install_element(BGP_NODE, &no_neighbor_port_cmd);
19645
19646 /* "neighbor weight" commands. */
19647 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19648 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19649
19650 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19651 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19652 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19653 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19654 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19655 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19656 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19657 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19658 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19659 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19660 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19661 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19662 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19663 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19664 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19665 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19666
19667 /* "neighbor override-capability" commands. */
19668 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19669 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19670
19671 /* "neighbor strict-capability-match" commands. */
19672 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19673 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19674
19675 /* "neighbor timers" commands. */
19676 install_element(BGP_NODE, &neighbor_timers_cmd);
19677 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19678
19679 /* "neighbor timers connect" commands. */
19680 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19681 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19682
19683 /* "neighbor timers delayopen" commands. */
19684 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19685 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19686
19687 /* "neighbor advertisement-interval" commands. */
19688 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19689 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19690
19691 /* "neighbor interface" commands. */
19692 install_element(BGP_NODE, &neighbor_interface_cmd);
19693 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19694
19695 /* "neighbor distribute" commands. */
19696 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19697 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19698 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19699 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19700 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19701 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19702 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19703 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19704 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19705 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19706 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19707 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19708 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19709 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19710 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19711 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19712 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19713 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19714
19715 /* "neighbor prefix-list" commands. */
19716 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19717 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19718 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19719 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19720 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19721 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19722 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19723 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19724 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19725 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19726 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19727 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19728 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19729 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19730 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19731 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19732 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19733 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19734 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19735 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19736 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19737 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19738
19739 /* "neighbor filter-list" commands. */
19740 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19741 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19742 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19743 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19744 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19745 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19746 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19747 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19748 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19749 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19750 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19751 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19752 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19753 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19754 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19755 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19756 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19757 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19758 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19759 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19760 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19761 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19762
19763 /* "neighbor route-map" commands. */
19764 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19765 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19766 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19767 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19768 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19769 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19770 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19771 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19772 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19773 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19774 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19775 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19776 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19777 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19778 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19779 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19780 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19781 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19782 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19783 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19784 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19785 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19786 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19787 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19788
19789 /* "neighbor unsuppress-map" commands. */
19790 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19791 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19792 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19793 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19794 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19795 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19796 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19797 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19798 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19799 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19800 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19801 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19802 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19803 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19804 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19805 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19806 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19807 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19808
19809 /* "neighbor advertise-map" commands. */
19810 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19811 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19812 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19813 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19814 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19815 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19816 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19817 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19818 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19819 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19820
19821 /* neighbor maximum-prefix-out commands. */
19822 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19823 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19824 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19825 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19826 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19827 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19828 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19829 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19830 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19831 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19832 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19833 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19834 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19835 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19836 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19837 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19838 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19839 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19840
19841 /* "neighbor maximum-prefix" commands. */
19842 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19843 install_element(BGP_NODE,
19844 &neighbor_maximum_prefix_threshold_hidden_cmd);
19845 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19846 install_element(BGP_NODE,
19847 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19848 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19849 install_element(BGP_NODE,
19850 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19851 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19852 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19853 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19854 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19855 install_element(BGP_IPV4_NODE,
19856 &neighbor_maximum_prefix_threshold_warning_cmd);
19857 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19858 install_element(BGP_IPV4_NODE,
19859 &neighbor_maximum_prefix_threshold_restart_cmd);
19860 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19861 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19862 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19863 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19864 install_element(BGP_IPV4M_NODE,
19865 &neighbor_maximum_prefix_threshold_warning_cmd);
19866 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19867 install_element(BGP_IPV4M_NODE,
19868 &neighbor_maximum_prefix_threshold_restart_cmd);
19869 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19870 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19871 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19872 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19873 install_element(BGP_IPV4L_NODE,
19874 &neighbor_maximum_prefix_threshold_warning_cmd);
19875 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19876 install_element(BGP_IPV4L_NODE,
19877 &neighbor_maximum_prefix_threshold_restart_cmd);
19878 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19879 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19880 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19881 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19882 install_element(BGP_IPV6_NODE,
19883 &neighbor_maximum_prefix_threshold_warning_cmd);
19884 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19885 install_element(BGP_IPV6_NODE,
19886 &neighbor_maximum_prefix_threshold_restart_cmd);
19887 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19888 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19889 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19890 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19891 install_element(BGP_IPV6M_NODE,
19892 &neighbor_maximum_prefix_threshold_warning_cmd);
19893 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19894 install_element(BGP_IPV6M_NODE,
19895 &neighbor_maximum_prefix_threshold_restart_cmd);
19896 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19897 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19898 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19899 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19900 install_element(BGP_IPV6L_NODE,
19901 &neighbor_maximum_prefix_threshold_warning_cmd);
19902 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19903 install_element(BGP_IPV6L_NODE,
19904 &neighbor_maximum_prefix_threshold_restart_cmd);
19905 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19906 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19907 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19908 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19909 install_element(BGP_VPNV4_NODE,
19910 &neighbor_maximum_prefix_threshold_warning_cmd);
19911 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19912 install_element(BGP_VPNV4_NODE,
19913 &neighbor_maximum_prefix_threshold_restart_cmd);
19914 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19915 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19916 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19917 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19918 install_element(BGP_VPNV6_NODE,
19919 &neighbor_maximum_prefix_threshold_warning_cmd);
19920 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19921 install_element(BGP_VPNV6_NODE,
19922 &neighbor_maximum_prefix_threshold_restart_cmd);
19923 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19924
19925 /* "neighbor allowas-in" */
19926 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19927 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19928 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19929 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19930 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19931 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19932 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19933 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19934 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19935 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19936 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19937 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19938 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19939 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19940 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19941 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19942 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19943 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19944 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19945 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19946
19947 /* neighbor accept-own */
19948 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19949 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19950
19951 /* "neighbor soo" */
19952 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19953 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19954 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19955 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19956 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19957 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19958 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19959 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19960 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19961 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19962 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19963 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19964 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19965 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19966 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19967 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19968 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19969 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19970
19971 /* address-family commands. */
19972 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19973 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19974 #ifdef KEEP_OLD_VPN_COMMANDS
19975 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19976 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19977 #endif /* KEEP_OLD_VPN_COMMANDS */
19978
19979 install_element(BGP_NODE, &address_family_evpn_cmd);
19980
19981 /* "exit-address-family" command. */
19982 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19983 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19984 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19985 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19986 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19987 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19988 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19989 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19990 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19991 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19992 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19993
19994 /* BGP retain all route-target */
19995 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19996 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19997
19998 /* "clear ip bgp commands" */
19999 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20000
20001 /* clear ip bgp prefix */
20002 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20003 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20004 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20005
20006 /* "show [ip] bgp summary" commands. */
20007 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20008 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20009 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20010 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20011 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20012 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20013 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20014
20015 /* "show [ip] bgp neighbors" commands. */
20016 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20017
20018 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20019
20020 /* "show [ip] bgp peer-group" commands. */
20021 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20022
20023 /* "show [ip] bgp paths" commands. */
20024 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20025
20026 /* "show [ip] bgp community" commands. */
20027 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20028
20029 /* "show ip bgp large-community" commands. */
20030 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20031 /* "show [ip] bgp attribute-info" commands. */
20032 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20033 /* "show [ip] bgp route-leak" command */
20034 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20035
20036 /* "redistribute" commands. */
20037 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20038 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20039 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20040 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20041 install_element(BGP_NODE,
20042 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20043 install_element(BGP_NODE,
20044 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20045 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20046 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20047 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20048 install_element(BGP_NODE,
20049 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20050 install_element(BGP_NODE,
20051 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20052 install_element(BGP_NODE,
20053 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20054 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20055 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20056 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20057 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20058 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20059 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20060 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20061 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20062 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20063 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20064 install_element(BGP_IPV4_NODE,
20065 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20066 install_element(BGP_IPV4_NODE,
20067 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20068 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20069 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20070 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20071 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20072 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20073 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20074
20075 /* import|export vpn [route-map RMAP_NAME] */
20076 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20077 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20078
20079 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20080 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20081
20082 /* ttl_security commands */
20083 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20084 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20085
20086 /* "bgp tcp-keepalive" commands */
20087 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20088 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20089
20090 /* "show [ip] bgp memory" commands. */
20091 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20092
20093 /* "show bgp martian next-hop" */
20094 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20095
20096 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20097
20098 /* "show [ip] bgp views" commands. */
20099 install_element(VIEW_NODE, &show_bgp_views_cmd);
20100
20101 /* "show [ip] bgp vrfs" commands. */
20102 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20103
20104 /* Community-list. */
20105 community_list_vty();
20106
20107 community_alias_vty();
20108
20109 /* vpn-policy commands */
20110 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20111 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20112 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20113 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20114 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20115 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20116 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20117 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20118 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20119 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20120 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20121 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20122
20123 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20124 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20125
20126 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20127 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20128 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20129 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20130 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20131 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20132 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20133 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20134 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20135 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20136
20137 /* tcp-mss command */
20138 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20139 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20140
20141 /* srv6 commands */
20142 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20143 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20144 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20145 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20146 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20147 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20148 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20149 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20150 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20151
20152 bgp_vty_if_init();
20153 }
20154
20155 #include "memory.h"
20156 #include "bgp_regex.h"
20157 #include "bgp_clist.h"
20158 #include "bgp_ecommunity.h"
20159
20160 /* VTY functions. */
20161
20162 /* Direction value to string conversion. */
20163 static const char *community_direct_str(int direct)
20164 {
20165 switch (direct) {
20166 case COMMUNITY_DENY:
20167 return "deny";
20168 case COMMUNITY_PERMIT:
20169 return "permit";
20170 default:
20171 return "unknown";
20172 }
20173 }
20174
20175 /* Display error string. */
20176 static void community_list_perror(struct vty *vty, int ret)
20177 {
20178 switch (ret) {
20179 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20180 vty_out(vty, "%% Can't find community-list\n");
20181 break;
20182 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20183 vty_out(vty, "%% Malformed community-list value\n");
20184 break;
20185 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20186 vty_out(vty,
20187 "%% Community name conflict, previously defined as standard community\n");
20188 break;
20189 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20190 vty_out(vty,
20191 "%% Community name conflict, previously defined as expanded community\n");
20192 break;
20193 }
20194 }
20195
20196 /* "community-list" keyword help string. */
20197 #define COMMUNITY_LIST_STR "Add a community list entry\n"
20198
20199 /*community-list standard */
20200 DEFUN (community_list_standard,
20201 bgp_community_list_standard_cmd,
20202 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20203 BGP_STR
20204 COMMUNITY_LIST_STR
20205 "Community list number (standard)\n"
20206 "Add an standard community-list entry\n"
20207 "Community list name\n"
20208 "Sequence number of an entry\n"
20209 "Sequence number\n"
20210 "Specify community to reject\n"
20211 "Specify community to accept\n"
20212 COMMUNITY_VAL_STR)
20213 {
20214 char *cl_name_or_number = NULL;
20215 char *seq = NULL;
20216 int direct = 0;
20217 int style = COMMUNITY_LIST_STANDARD;
20218 int idx = 0;
20219
20220 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20221 seq = argv[idx]->arg;
20222
20223 idx = 0;
20224 argv_find(argv, argc, "(1-99)", &idx);
20225 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20226 cl_name_or_number = argv[idx]->arg;
20227 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20228 : COMMUNITY_DENY;
20229 argv_find(argv, argc, "AA:NN", &idx);
20230 char *str = argv_concat(argv, argc, idx);
20231
20232 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20233 direct, style);
20234
20235 XFREE(MTYPE_TMP, str);
20236
20237 if (ret < 0) {
20238 /* Display error string. */
20239 community_list_perror(vty, ret);
20240 return CMD_WARNING_CONFIG_FAILED;
20241 }
20242
20243 return CMD_SUCCESS;
20244 }
20245
20246 DEFUN (no_community_list_standard_all,
20247 no_bgp_community_list_standard_all_cmd,
20248 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20249 NO_STR
20250 BGP_STR
20251 COMMUNITY_LIST_STR
20252 "Community list number (standard)\n"
20253 "Add an standard community-list entry\n"
20254 "Community list name\n"
20255 "Sequence number of an entry\n"
20256 "Sequence number\n"
20257 "Specify community to reject\n"
20258 "Specify community to accept\n"
20259 COMMUNITY_VAL_STR)
20260 {
20261 char *cl_name_or_number = NULL;
20262 char *str = NULL;
20263 int direct = 0;
20264 int style = COMMUNITY_LIST_STANDARD;
20265 char *seq = NULL;
20266 int idx = 0;
20267
20268 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20269 seq = argv[idx]->arg;
20270
20271 idx = 0;
20272 argv_find(argv, argc, "permit", &idx);
20273 argv_find(argv, argc, "deny", &idx);
20274
20275 if (idx) {
20276 direct = argv_find(argv, argc, "permit", &idx)
20277 ? COMMUNITY_PERMIT
20278 : COMMUNITY_DENY;
20279
20280 idx = 0;
20281 argv_find(argv, argc, "AA:NN", &idx);
20282 str = argv_concat(argv, argc, idx);
20283 }
20284
20285 idx = 0;
20286 argv_find(argv, argc, "(1-99)", &idx);
20287 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20288 cl_name_or_number = argv[idx]->arg;
20289
20290 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20291 direct, style);
20292
20293 XFREE(MTYPE_TMP, str);
20294
20295 if (ret < 0) {
20296 community_list_perror(vty, ret);
20297 return CMD_WARNING_CONFIG_FAILED;
20298 }
20299
20300 return CMD_SUCCESS;
20301 }
20302
20303 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20304 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20305 NO_STR BGP_STR COMMUNITY_LIST_STR
20306 "Community list number (standard)\n"
20307 "Add an standard community-list entry\n"
20308 "Community list name\n")
20309
20310 /*community-list expanded */
20311 DEFUN (community_list_expanded_all,
20312 bgp_community_list_expanded_all_cmd,
20313 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20314 BGP_STR
20315 COMMUNITY_LIST_STR
20316 "Community list number (expanded)\n"
20317 "Add an expanded community-list entry\n"
20318 "Community list name\n"
20319 "Sequence number of an entry\n"
20320 "Sequence number\n"
20321 "Specify community to reject\n"
20322 "Specify community to accept\n"
20323 COMMUNITY_VAL_STR)
20324 {
20325 char *cl_name_or_number = NULL;
20326 char *seq = NULL;
20327 int direct = 0;
20328 int style = COMMUNITY_LIST_EXPANDED;
20329 int idx = 0;
20330
20331 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20332 seq = argv[idx]->arg;
20333
20334 idx = 0;
20335
20336 argv_find(argv, argc, "(100-500)", &idx);
20337 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20338 cl_name_or_number = argv[idx]->arg;
20339 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20340 : COMMUNITY_DENY;
20341 argv_find(argv, argc, "AA:NN", &idx);
20342 char *str = argv_concat(argv, argc, idx);
20343
20344 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20345 direct, style);
20346
20347 XFREE(MTYPE_TMP, str);
20348
20349 if (ret < 0) {
20350 /* Display error string. */
20351 community_list_perror(vty, ret);
20352 return CMD_WARNING_CONFIG_FAILED;
20353 }
20354
20355 return CMD_SUCCESS;
20356 }
20357
20358 DEFUN (no_community_list_expanded_all,
20359 no_bgp_community_list_expanded_all_cmd,
20360 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20361 NO_STR
20362 BGP_STR
20363 COMMUNITY_LIST_STR
20364 "Community list number (expanded)\n"
20365 "Add an expanded community-list entry\n"
20366 "Community list name\n"
20367 "Sequence number of an entry\n"
20368 "Sequence number\n"
20369 "Specify community to reject\n"
20370 "Specify community to accept\n"
20371 COMMUNITY_VAL_STR)
20372 {
20373 char *cl_name_or_number = NULL;
20374 char *seq = NULL;
20375 char *str = NULL;
20376 int direct = 0;
20377 int style = COMMUNITY_LIST_EXPANDED;
20378 int idx = 0;
20379
20380 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20381 seq = argv[idx]->arg;
20382
20383 idx = 0;
20384 argv_find(argv, argc, "permit", &idx);
20385 argv_find(argv, argc, "deny", &idx);
20386
20387 if (idx) {
20388 direct = argv_find(argv, argc, "permit", &idx)
20389 ? COMMUNITY_PERMIT
20390 : COMMUNITY_DENY;
20391
20392 idx = 0;
20393 argv_find(argv, argc, "AA:NN", &idx);
20394 str = argv_concat(argv, argc, idx);
20395 }
20396
20397 idx = 0;
20398 argv_find(argv, argc, "(100-500)", &idx);
20399 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20400 cl_name_or_number = argv[idx]->arg;
20401
20402 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20403 direct, style);
20404
20405 XFREE(MTYPE_TMP, str);
20406
20407 if (ret < 0) {
20408 community_list_perror(vty, ret);
20409 return CMD_WARNING_CONFIG_FAILED;
20410 }
20411
20412 return CMD_SUCCESS;
20413 }
20414
20415 ALIAS(no_community_list_expanded_all,
20416 no_bgp_community_list_expanded_all_list_cmd,
20417 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20418 NO_STR BGP_STR COMMUNITY_LIST_STR
20419 "Community list number (expanded)\n"
20420 "Add an expanded community-list entry\n"
20421 "Community list name\n")
20422
20423 /* Return configuration string of community-list entry. */
20424 static const char *community_list_config_str(struct community_entry *entry)
20425 {
20426 const char *str;
20427
20428 if (entry->any)
20429 str = "";
20430 else {
20431 if (entry->style == COMMUNITY_LIST_STANDARD)
20432 str = community_str(entry->u.com, false, false);
20433 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20434 str = lcommunity_str(entry->u.lcom, false, false);
20435 else
20436 str = entry->config;
20437 }
20438 return str;
20439 }
20440
20441 static void community_list_show(struct vty *vty, struct community_list *list)
20442 {
20443 struct community_entry *entry;
20444
20445 for (entry = list->head; entry; entry = entry->next) {
20446 if (entry == list->head) {
20447 if (all_digit(list->name))
20448 vty_out(vty, "Community %s list %s\n",
20449 entry->style == COMMUNITY_LIST_STANDARD
20450 ? "standard"
20451 : "(expanded) access",
20452 list->name);
20453 else
20454 vty_out(vty, "Named Community %s list %s\n",
20455 entry->style == COMMUNITY_LIST_STANDARD
20456 ? "standard"
20457 : "expanded",
20458 list->name);
20459 }
20460 if (entry->any)
20461 vty_out(vty, " %s\n",
20462 community_direct_str(entry->direct));
20463 else
20464 vty_out(vty, " %s %s\n",
20465 community_direct_str(entry->direct),
20466 community_list_config_str(entry));
20467 }
20468 }
20469
20470 DEFUN (show_community_list,
20471 show_bgp_community_list_cmd,
20472 "show bgp community-list",
20473 SHOW_STR
20474 BGP_STR
20475 "List community-list\n")
20476 {
20477 struct community_list *list;
20478 struct community_list_master *cm;
20479
20480 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20481 if (!cm)
20482 return CMD_SUCCESS;
20483
20484 for (list = cm->num.head; list; list = list->next)
20485 community_list_show(vty, list);
20486
20487 for (list = cm->str.head; list; list = list->next)
20488 community_list_show(vty, list);
20489
20490 return CMD_SUCCESS;
20491 }
20492
20493 DEFUN (show_community_list_arg,
20494 show_bgp_community_list_arg_cmd,
20495 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20496 SHOW_STR
20497 BGP_STR
20498 "List community-list\n"
20499 "Community-list number\n"
20500 "Community-list name\n"
20501 "Detailed information on community-list\n")
20502 {
20503 int idx_comm_list = 3;
20504 struct community_list *list;
20505
20506 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20507 COMMUNITY_LIST_MASTER);
20508 if (!list) {
20509 vty_out(vty, "%% Can't find community-list\n");
20510 return CMD_WARNING;
20511 }
20512
20513 community_list_show(vty, list);
20514
20515 return CMD_SUCCESS;
20516 }
20517
20518 /*
20519 * Large Community code.
20520 */
20521 static int lcommunity_list_set_vty(struct vty *vty, int argc,
20522 struct cmd_token **argv, int style,
20523 int reject_all_digit_name)
20524 {
20525 int ret;
20526 int direct;
20527 char *str;
20528 int idx = 0;
20529 char *cl_name;
20530 char *seq = NULL;
20531
20532 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20533 seq = argv[idx]->arg;
20534
20535 idx = 0;
20536 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20537 : COMMUNITY_DENY;
20538
20539 /* All digit name check. */
20540 idx = 0;
20541 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20542 argv_find(argv, argc, "(1-99)", &idx);
20543 argv_find(argv, argc, "(100-500)", &idx);
20544 cl_name = argv[idx]->arg;
20545 if (reject_all_digit_name && all_digit(cl_name)) {
20546 vty_out(vty, "%% Community name cannot have all digits\n");
20547 return CMD_WARNING_CONFIG_FAILED;
20548 }
20549
20550 idx = 0;
20551 argv_find(argv, argc, "AA:BB:CC", &idx);
20552 argv_find(argv, argc, "LINE", &idx);
20553 /* Concat community string argument. */
20554 if (idx)
20555 str = argv_concat(argv, argc, idx);
20556 else
20557 str = NULL;
20558
20559 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20560
20561 /* Free temporary community list string allocated by
20562 argv_concat(). */
20563 XFREE(MTYPE_TMP, str);
20564
20565 if (ret < 0) {
20566 community_list_perror(vty, ret);
20567 return CMD_WARNING_CONFIG_FAILED;
20568 }
20569 return CMD_SUCCESS;
20570 }
20571
20572 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20573 struct cmd_token **argv, int style)
20574 {
20575 int ret;
20576 int direct = 0;
20577 char *str = NULL;
20578 int idx = 0;
20579 char *seq = NULL;
20580
20581 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20582 seq = argv[idx]->arg;
20583
20584 idx = 0;
20585 argv_find(argv, argc, "permit", &idx);
20586 argv_find(argv, argc, "deny", &idx);
20587
20588 if (idx) {
20589 /* Check the list direct. */
20590 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20591 direct = COMMUNITY_PERMIT;
20592 else
20593 direct = COMMUNITY_DENY;
20594
20595 idx = 0;
20596 argv_find(argv, argc, "LINE", &idx);
20597 argv_find(argv, argc, "AA:AA:NN", &idx);
20598 /* Concat community string argument. */
20599 str = argv_concat(argv, argc, idx);
20600 }
20601
20602 idx = 0;
20603 argv_find(argv, argc, "(1-99)", &idx);
20604 argv_find(argv, argc, "(100-500)", &idx);
20605 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20606
20607 /* Unset community list. */
20608 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20609 style);
20610
20611 /* Free temporary community list string allocated by
20612 argv_concat(). */
20613 XFREE(MTYPE_TMP, str);
20614
20615 if (ret < 0) {
20616 community_list_perror(vty, ret);
20617 return CMD_WARNING_CONFIG_FAILED;
20618 }
20619
20620 return CMD_SUCCESS;
20621 }
20622
20623 /* "large-community-list" keyword help string. */
20624 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20625 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20626
20627 DEFUN (lcommunity_list_standard,
20628 bgp_lcommunity_list_standard_cmd,
20629 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20630 BGP_STR
20631 LCOMMUNITY_LIST_STR
20632 "Large Community list number (standard)\n"
20633 "Sequence number of an entry\n"
20634 "Sequence number\n"
20635 "Specify large community to reject\n"
20636 "Specify large community to accept\n"
20637 LCOMMUNITY_VAL_STR)
20638 {
20639 return lcommunity_list_set_vty(vty, argc, argv,
20640 LARGE_COMMUNITY_LIST_STANDARD, 0);
20641 }
20642
20643 DEFUN (lcommunity_list_expanded,
20644 bgp_lcommunity_list_expanded_cmd,
20645 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20646 BGP_STR
20647 LCOMMUNITY_LIST_STR
20648 "Large Community list number (expanded)\n"
20649 "Sequence number of an entry\n"
20650 "Sequence number\n"
20651 "Specify large community to reject\n"
20652 "Specify large community to accept\n"
20653 "An ordered list as a regular-expression\n")
20654 {
20655 return lcommunity_list_set_vty(vty, argc, argv,
20656 LARGE_COMMUNITY_LIST_EXPANDED, 0);
20657 }
20658
20659 DEFUN (lcommunity_list_name_standard,
20660 bgp_lcommunity_list_name_standard_cmd,
20661 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20662 BGP_STR
20663 LCOMMUNITY_LIST_STR
20664 "Specify standard large-community-list\n"
20665 "Large Community list name\n"
20666 "Sequence number of an entry\n"
20667 "Sequence number\n"
20668 "Specify large community to reject\n"
20669 "Specify large community to accept\n"
20670 LCOMMUNITY_VAL_STR)
20671 {
20672 return lcommunity_list_set_vty(vty, argc, argv,
20673 LARGE_COMMUNITY_LIST_STANDARD, 1);
20674 }
20675
20676 DEFUN (lcommunity_list_name_expanded,
20677 bgp_lcommunity_list_name_expanded_cmd,
20678 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20679 BGP_STR
20680 LCOMMUNITY_LIST_STR
20681 "Specify expanded large-community-list\n"
20682 "Large Community list name\n"
20683 "Sequence number of an entry\n"
20684 "Sequence number\n"
20685 "Specify large community to reject\n"
20686 "Specify large community to accept\n"
20687 "An ordered list as a regular-expression\n")
20688 {
20689 return lcommunity_list_set_vty(vty, argc, argv,
20690 LARGE_COMMUNITY_LIST_EXPANDED, 1);
20691 }
20692
20693 DEFUN (no_lcommunity_list_all,
20694 no_bgp_lcommunity_list_all_cmd,
20695 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20696 NO_STR
20697 BGP_STR
20698 LCOMMUNITY_LIST_STR
20699 "Large Community list number (standard)\n"
20700 "Large Community list number (expanded)\n"
20701 "Large Community list name\n")
20702 {
20703 return lcommunity_list_unset_vty(vty, argc, argv,
20704 LARGE_COMMUNITY_LIST_STANDARD);
20705 }
20706
20707 DEFUN (no_lcommunity_list_name_standard_all,
20708 no_bgp_lcommunity_list_name_standard_all_cmd,
20709 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20710 NO_STR
20711 BGP_STR
20712 LCOMMUNITY_LIST_STR
20713 "Specify standard large-community-list\n"
20714 "Large Community list name\n")
20715 {
20716 return lcommunity_list_unset_vty(vty, argc, argv,
20717 LARGE_COMMUNITY_LIST_STANDARD);
20718 }
20719
20720 DEFUN (no_lcommunity_list_name_expanded_all,
20721 no_bgp_lcommunity_list_name_expanded_all_cmd,
20722 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20723 NO_STR
20724 BGP_STR
20725 LCOMMUNITY_LIST_STR
20726 "Specify expanded large-community-list\n"
20727 "Large Community list name\n")
20728 {
20729 return lcommunity_list_unset_vty(vty, argc, argv,
20730 LARGE_COMMUNITY_LIST_EXPANDED);
20731 }
20732
20733 DEFUN (no_lcommunity_list_standard,
20734 no_bgp_lcommunity_list_standard_cmd,
20735 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20736 NO_STR
20737 BGP_STR
20738 LCOMMUNITY_LIST_STR
20739 "Large Community list number (standard)\n"
20740 "Sequence number of an entry\n"
20741 "Sequence number\n"
20742 "Specify large community to reject\n"
20743 "Specify large community to accept\n"
20744 LCOMMUNITY_VAL_STR)
20745 {
20746 return lcommunity_list_unset_vty(vty, argc, argv,
20747 LARGE_COMMUNITY_LIST_STANDARD);
20748 }
20749
20750 DEFUN (no_lcommunity_list_expanded,
20751 no_bgp_lcommunity_list_expanded_cmd,
20752 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20753 NO_STR
20754 BGP_STR
20755 LCOMMUNITY_LIST_STR
20756 "Large Community list number (expanded)\n"
20757 "Sequence number of an entry\n"
20758 "Sequence number\n"
20759 "Specify large community to reject\n"
20760 "Specify large community to accept\n"
20761 "An ordered list as a regular-expression\n")
20762 {
20763 return lcommunity_list_unset_vty(vty, argc, argv,
20764 LARGE_COMMUNITY_LIST_EXPANDED);
20765 }
20766
20767 DEFUN (no_lcommunity_list_name_standard,
20768 no_bgp_lcommunity_list_name_standard_cmd,
20769 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20770 NO_STR
20771 BGP_STR
20772 LCOMMUNITY_LIST_STR
20773 "Specify standard large-community-list\n"
20774 "Large Community list name\n"
20775 "Sequence number of an entry\n"
20776 "Sequence number\n"
20777 "Specify large community to reject\n"
20778 "Specify large community to accept\n"
20779 LCOMMUNITY_VAL_STR)
20780 {
20781 return lcommunity_list_unset_vty(vty, argc, argv,
20782 LARGE_COMMUNITY_LIST_STANDARD);
20783 }
20784
20785 DEFUN (no_lcommunity_list_name_expanded,
20786 no_bgp_lcommunity_list_name_expanded_cmd,
20787 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20788 NO_STR
20789 BGP_STR
20790 LCOMMUNITY_LIST_STR
20791 "Specify expanded large-community-list\n"
20792 "Large community list name\n"
20793 "Sequence number of an entry\n"
20794 "Sequence number\n"
20795 "Specify large community to reject\n"
20796 "Specify large community to accept\n"
20797 "An ordered list as a regular-expression\n")
20798 {
20799 return lcommunity_list_unset_vty(vty, argc, argv,
20800 LARGE_COMMUNITY_LIST_EXPANDED);
20801 }
20802
20803 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20804 {
20805 struct community_entry *entry;
20806
20807 for (entry = list->head; entry; entry = entry->next) {
20808 if (entry == list->head) {
20809 if (all_digit(list->name))
20810 vty_out(vty, "Large community %s list %s\n",
20811 entry->style ==
20812 LARGE_COMMUNITY_LIST_STANDARD
20813 ? "standard"
20814 : "(expanded) access",
20815 list->name);
20816 else
20817 vty_out(vty,
20818 "Named large community %s list %s\n",
20819 entry->style ==
20820 LARGE_COMMUNITY_LIST_STANDARD
20821 ? "standard"
20822 : "expanded",
20823 list->name);
20824 }
20825 if (entry->any)
20826 vty_out(vty, " %s\n",
20827 community_direct_str(entry->direct));
20828 else
20829 vty_out(vty, " %s %s\n",
20830 community_direct_str(entry->direct),
20831 community_list_config_str(entry));
20832 }
20833 }
20834
20835 DEFUN (show_lcommunity_list,
20836 show_bgp_lcommunity_list_cmd,
20837 "show bgp large-community-list",
20838 SHOW_STR
20839 BGP_STR
20840 "List large-community list\n")
20841 {
20842 struct community_list *list;
20843 struct community_list_master *cm;
20844
20845 cm = community_list_master_lookup(bgp_clist,
20846 LARGE_COMMUNITY_LIST_MASTER);
20847 if (!cm)
20848 return CMD_SUCCESS;
20849
20850 for (list = cm->num.head; list; list = list->next)
20851 lcommunity_list_show(vty, list);
20852
20853 for (list = cm->str.head; list; list = list->next)
20854 lcommunity_list_show(vty, list);
20855
20856 return CMD_SUCCESS;
20857 }
20858
20859 DEFUN (show_lcommunity_list_arg,
20860 show_bgp_lcommunity_list_arg_cmd,
20861 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20862 SHOW_STR
20863 BGP_STR
20864 "List large-community list\n"
20865 "Large-community-list number\n"
20866 "Large-community-list name\n"
20867 "Detailed information on large-community-list\n")
20868 {
20869 struct community_list *list;
20870
20871 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20872 LARGE_COMMUNITY_LIST_MASTER);
20873 if (!list) {
20874 vty_out(vty, "%% Can't find large-community-list\n");
20875 return CMD_WARNING;
20876 }
20877
20878 lcommunity_list_show(vty, list);
20879
20880 return CMD_SUCCESS;
20881 }
20882
20883 /* "extcommunity-list" keyword help string. */
20884 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20885 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20886
20887 DEFUN (extcommunity_list_standard,
20888 bgp_extcommunity_list_standard_cmd,
20889 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20890 BGP_STR
20891 EXTCOMMUNITY_LIST_STR
20892 "Extended Community list number (standard)\n"
20893 "Specify standard extcommunity-list\n"
20894 "Community list name\n"
20895 "Sequence number of an entry\n"
20896 "Sequence number\n"
20897 "Specify community to reject\n"
20898 "Specify community to accept\n"
20899 EXTCOMMUNITY_VAL_STR)
20900 {
20901 int style = EXTCOMMUNITY_LIST_STANDARD;
20902 int direct = 0;
20903 char *cl_number_or_name = NULL;
20904 char *seq = NULL;
20905
20906 int idx = 0;
20907
20908 argv_find(argv, argc, "(1-99)", &idx);
20909 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20910 cl_number_or_name = argv[idx]->arg;
20911
20912 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20913 seq = argv[idx]->arg;
20914
20915 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20916 : COMMUNITY_DENY;
20917 argv_find(argv, argc, "AA:NN", &idx);
20918 char *str = argv_concat(argv, argc, idx);
20919
20920 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20921 direct, style);
20922
20923 XFREE(MTYPE_TMP, str);
20924
20925 if (ret < 0) {
20926 community_list_perror(vty, ret);
20927 return CMD_WARNING_CONFIG_FAILED;
20928 }
20929
20930 return CMD_SUCCESS;
20931 }
20932
20933 DEFUN (extcommunity_list_name_expanded,
20934 bgp_extcommunity_list_name_expanded_cmd,
20935 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20936 BGP_STR
20937 EXTCOMMUNITY_LIST_STR
20938 "Extended Community list number (expanded)\n"
20939 "Specify expanded extcommunity-list\n"
20940 "Extended Community list name\n"
20941 "Sequence number of an entry\n"
20942 "Sequence number\n"
20943 "Specify community to reject\n"
20944 "Specify community to accept\n"
20945 "An ordered list as a regular-expression\n")
20946 {
20947 int style = EXTCOMMUNITY_LIST_EXPANDED;
20948 int direct = 0;
20949 char *cl_number_or_name = NULL;
20950 char *seq = NULL;
20951 int idx = 0;
20952
20953 argv_find(argv, argc, "(100-500)", &idx);
20954 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20955 cl_number_or_name = argv[idx]->arg;
20956
20957 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20958 seq = argv[idx]->arg;
20959
20960 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20961 : COMMUNITY_DENY;
20962 argv_find(argv, argc, "LINE", &idx);
20963 char *str = argv_concat(argv, argc, idx);
20964
20965 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20966 direct, style);
20967
20968 XFREE(MTYPE_TMP, str);
20969
20970 if (ret < 0) {
20971 community_list_perror(vty, ret);
20972 return CMD_WARNING_CONFIG_FAILED;
20973 }
20974
20975 return CMD_SUCCESS;
20976 }
20977
20978 DEFUN (no_extcommunity_list_standard_all,
20979 no_bgp_extcommunity_list_standard_all_cmd,
20980 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20981 NO_STR
20982 BGP_STR
20983 EXTCOMMUNITY_LIST_STR
20984 "Extended Community list number (standard)\n"
20985 "Specify standard extcommunity-list\n"
20986 "Community list name\n"
20987 "Sequence number of an entry\n"
20988 "Sequence number\n"
20989 "Specify community to reject\n"
20990 "Specify community to accept\n"
20991 EXTCOMMUNITY_VAL_STR)
20992 {
20993 int style = EXTCOMMUNITY_LIST_STANDARD;
20994 int direct = 0;
20995 char *cl_number_or_name = NULL;
20996 char *str = NULL;
20997 char *seq = NULL;
20998 int idx = 0;
20999
21000 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21001 seq = argv[idx]->arg;
21002
21003 idx = 0;
21004 argv_find(argv, argc, "permit", &idx);
21005 argv_find(argv, argc, "deny", &idx);
21006 if (idx) {
21007 direct = argv_find(argv, argc, "permit", &idx)
21008 ? COMMUNITY_PERMIT
21009 : COMMUNITY_DENY;
21010
21011 idx = 0;
21012 argv_find(argv, argc, "AA:NN", &idx);
21013 str = argv_concat(argv, argc, idx);
21014 }
21015
21016 idx = 0;
21017 argv_find(argv, argc, "(1-99)", &idx);
21018 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21019 cl_number_or_name = argv[idx]->arg;
21020
21021 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21022 seq, direct, style);
21023
21024 XFREE(MTYPE_TMP, str);
21025
21026 if (ret < 0) {
21027 community_list_perror(vty, ret);
21028 return CMD_WARNING_CONFIG_FAILED;
21029 }
21030
21031 return CMD_SUCCESS;
21032 }
21033
21034 ALIAS(no_extcommunity_list_standard_all,
21035 no_bgp_extcommunity_list_standard_all_list_cmd,
21036 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21037 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21038 "Extended Community list number (standard)\n"
21039 "Specify standard extcommunity-list\n"
21040 "Community list name\n")
21041
21042 DEFUN (no_extcommunity_list_expanded_all,
21043 no_bgp_extcommunity_list_expanded_all_cmd,
21044 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21045 NO_STR
21046 BGP_STR
21047 EXTCOMMUNITY_LIST_STR
21048 "Extended Community list number (expanded)\n"
21049 "Specify expanded extcommunity-list\n"
21050 "Extended Community list name\n"
21051 "Sequence number of an entry\n"
21052 "Sequence number\n"
21053 "Specify community to reject\n"
21054 "Specify community to accept\n"
21055 "An ordered list as a regular-expression\n")
21056 {
21057 int style = EXTCOMMUNITY_LIST_EXPANDED;
21058 int direct = 0;
21059 char *cl_number_or_name = NULL;
21060 char *str = NULL;
21061 char *seq = NULL;
21062 int idx = 0;
21063
21064 if (argv_find(argv, argc, "(0-4294967295)", &idx))
21065 seq = argv[idx]->arg;
21066
21067 idx = 0;
21068 argv_find(argv, argc, "permit", &idx);
21069 argv_find(argv, argc, "deny", &idx);
21070
21071 if (idx) {
21072 direct = argv_find(argv, argc, "permit", &idx)
21073 ? COMMUNITY_PERMIT
21074 : COMMUNITY_DENY;
21075
21076 idx = 0;
21077 argv_find(argv, argc, "LINE", &idx);
21078 str = argv_concat(argv, argc, idx);
21079 }
21080
21081 idx = 0;
21082 argv_find(argv, argc, "(100-500)", &idx);
21083 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21084 cl_number_or_name = argv[idx]->arg;
21085
21086 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21087 seq, direct, style);
21088
21089 XFREE(MTYPE_TMP, str);
21090
21091 if (ret < 0) {
21092 community_list_perror(vty, ret);
21093 return CMD_WARNING_CONFIG_FAILED;
21094 }
21095
21096 return CMD_SUCCESS;
21097 }
21098
21099 ALIAS(no_extcommunity_list_expanded_all,
21100 no_bgp_extcommunity_list_expanded_all_list_cmd,
21101 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21102 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21103 "Extended Community list number (expanded)\n"
21104 "Specify expanded extcommunity-list\n"
21105 "Extended Community list name\n")
21106
21107 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21108 {
21109 struct community_entry *entry;
21110
21111 for (entry = list->head; entry; entry = entry->next) {
21112 if (entry == list->head) {
21113 if (all_digit(list->name))
21114 vty_out(vty, "Extended community %s list %s\n",
21115 entry->style == EXTCOMMUNITY_LIST_STANDARD
21116 ? "standard"
21117 : "(expanded) access",
21118 list->name);
21119 else
21120 vty_out(vty,
21121 "Named extended community %s list %s\n",
21122 entry->style == EXTCOMMUNITY_LIST_STANDARD
21123 ? "standard"
21124 : "expanded",
21125 list->name);
21126 }
21127 if (entry->any)
21128 vty_out(vty, " %s\n",
21129 community_direct_str(entry->direct));
21130 else
21131 vty_out(vty, " %s %s\n",
21132 community_direct_str(entry->direct),
21133 community_list_config_str(entry));
21134 }
21135 }
21136
21137 DEFUN (show_extcommunity_list,
21138 show_bgp_extcommunity_list_cmd,
21139 "show bgp extcommunity-list",
21140 SHOW_STR
21141 BGP_STR
21142 "List extended-community list\n")
21143 {
21144 struct community_list *list;
21145 struct community_list_master *cm;
21146
21147 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21148 if (!cm)
21149 return CMD_SUCCESS;
21150
21151 for (list = cm->num.head; list; list = list->next)
21152 extcommunity_list_show(vty, list);
21153
21154 for (list = cm->str.head; list; list = list->next)
21155 extcommunity_list_show(vty, list);
21156
21157 return CMD_SUCCESS;
21158 }
21159
21160 DEFUN (show_extcommunity_list_arg,
21161 show_bgp_extcommunity_list_arg_cmd,
21162 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21163 SHOW_STR
21164 BGP_STR
21165 "List extended-community list\n"
21166 "Extcommunity-list number\n"
21167 "Extcommunity-list name\n"
21168 "Detailed information on extcommunity-list\n")
21169 {
21170 int idx_comm_list = 3;
21171 struct community_list *list;
21172
21173 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21174 EXTCOMMUNITY_LIST_MASTER);
21175 if (!list) {
21176 vty_out(vty, "%% Can't find extcommunity-list\n");
21177 return CMD_WARNING;
21178 }
21179
21180 extcommunity_list_show(vty, list);
21181
21182 return CMD_SUCCESS;
21183 }
21184
21185 /* Display community-list and extcommunity-list configuration. */
21186 static int community_list_config_write(struct vty *vty)
21187 {
21188 struct community_list *list;
21189 struct community_entry *entry;
21190 struct community_list_master *cm;
21191 int write = 0;
21192
21193 /* Community-list. */
21194 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21195
21196 for (list = cm->num.head; list; list = list->next)
21197 for (entry = list->head; entry; entry = entry->next) {
21198 vty_out(vty,
21199 "bgp community-list %s seq %" PRId64 " %s %s\n",
21200 list->name, entry->seq,
21201 community_direct_str(entry->direct),
21202 community_list_config_str(entry));
21203 write++;
21204 }
21205 for (list = cm->str.head; list; list = list->next)
21206 for (entry = list->head; entry; entry = entry->next) {
21207 vty_out(vty,
21208 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21209 entry->style == COMMUNITY_LIST_STANDARD
21210 ? "standard"
21211 : "expanded",
21212 list->name, entry->seq,
21213 community_direct_str(entry->direct),
21214 community_list_config_str(entry));
21215 write++;
21216 }
21217
21218 /* Extcommunity-list. */
21219 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21220
21221 for (list = cm->num.head; list; list = list->next)
21222 for (entry = list->head; entry; entry = entry->next) {
21223 vty_out(vty,
21224 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21225 list->name, entry->seq,
21226 community_direct_str(entry->direct),
21227 community_list_config_str(entry));
21228 write++;
21229 }
21230 for (list = cm->str.head; list; list = list->next)
21231 for (entry = list->head; entry; entry = entry->next) {
21232 vty_out(vty,
21233 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21234 entry->style == EXTCOMMUNITY_LIST_STANDARD
21235 ? "standard"
21236 : "expanded",
21237 list->name, entry->seq,
21238 community_direct_str(entry->direct),
21239 community_list_config_str(entry));
21240 write++;
21241 }
21242
21243
21244 /* lcommunity-list. */
21245 cm = community_list_master_lookup(bgp_clist,
21246 LARGE_COMMUNITY_LIST_MASTER);
21247
21248 for (list = cm->num.head; list; list = list->next)
21249 for (entry = list->head; entry; entry = entry->next) {
21250 vty_out(vty,
21251 "bgp large-community-list %s seq %" PRId64" %s %s\n",
21252 list->name, entry->seq,
21253 community_direct_str(entry->direct),
21254 community_list_config_str(entry));
21255 write++;
21256 }
21257 for (list = cm->str.head; list; list = list->next)
21258 for (entry = list->head; entry; entry = entry->next) {
21259 vty_out(vty,
21260 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21261
21262 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21263 ? "standard"
21264 : "expanded",
21265 list->name, entry->seq, community_direct_str(entry->direct),
21266 community_list_config_str(entry));
21267 write++;
21268 }
21269
21270 return write;
21271 }
21272
21273 static int community_list_config_write(struct vty *vty);
21274 static struct cmd_node community_list_node = {
21275 .name = "community list",
21276 .node = COMMUNITY_LIST_NODE,
21277 .prompt = "",
21278 .config_write = community_list_config_write,
21279 };
21280
21281 static void community_list_vty(void)
21282 {
21283 install_node(&community_list_node);
21284
21285 /* Community-list. */
21286 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21287 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21288 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21289 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21290 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21291 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21292 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21293 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21294
21295 /* Extcommunity-list. */
21296 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21297 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21298 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21299 install_element(CONFIG_NODE,
21300 &no_bgp_extcommunity_list_standard_all_list_cmd);
21301 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21302 install_element(CONFIG_NODE,
21303 &no_bgp_extcommunity_list_expanded_all_list_cmd);
21304 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21305 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21306
21307 /* Large Community List */
21308 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21309 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21310 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21311 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21312 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21313 install_element(CONFIG_NODE,
21314 &no_bgp_lcommunity_list_name_standard_all_cmd);
21315 install_element(CONFIG_NODE,
21316 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21317 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21318 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21319 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21320 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21321 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21322 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21323
21324 bgp_community_list_command_completion_setup();
21325 }
21326
21327 static struct cmd_node community_alias_node = {
21328 .name = "community alias",
21329 .node = COMMUNITY_ALIAS_NODE,
21330 .prompt = "",
21331 .config_write = bgp_community_alias_write,
21332 };
21333
21334 void community_alias_vty(void)
21335 {
21336 install_node(&community_alias_node);
21337
21338 /* Community-list. */
21339 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21340
21341 bgp_community_alias_command_completion_setup();
21342 }