]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
650800b962a60bf91ec2c63449783207d6e5990f
[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_nexthop.h"
57 #include "bgpd/bgp_open.h"
58 #include "bgpd/bgp_regex.h"
59 #include "bgpd/bgp_route.h"
60 #include "bgpd/bgp_mplsvpn.h"
61 #include "bgpd/bgp_zebra.h"
62 #include "bgpd/bgp_table.h"
63 #include "bgpd/bgp_vty.h"
64 #include "bgpd/bgp_mpath.h"
65 #include "bgpd/bgp_packet.h"
66 #include "bgpd/bgp_updgrp.h"
67 #include "bgpd/bgp_bfd.h"
68 #include "bgpd/bgp_io.h"
69 #include "bgpd/bgp_evpn.h"
70 #include "bgpd/bgp_evpn_vty.h"
71 #include "bgpd/bgp_evpn_mh.h"
72 #include "bgpd/bgp_addpath.h"
73 #include "bgpd/bgp_mac.h"
74 #include "bgpd/bgp_flowspec.h"
75 #include "bgpd/bgp_conditional_adv.h"
76 #ifdef ENABLE_BGP_VNC
77 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
78 #endif
79
80 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
81 {
82 .val_bool = false,
83 .match_profile = "traditional",
84 .match_version = "< 7.4",
85 },
86 { .val_bool = true },
87 );
88 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
91 );
92 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
95 );
96 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
99 );
100 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
103 );
104 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
105 { .val_ulong = 10, .match_profile = "datacenter", },
106 { .val_ulong = 120 },
107 );
108 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
109 { .val_ulong = 9, .match_profile = "datacenter", },
110 { .val_ulong = 180 },
111 );
112 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
113 { .val_ulong = 3, .match_profile = "datacenter", },
114 { .val_ulong = 60 },
115 );
116 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
117 { .val_bool = false, .match_profile = "datacenter", },
118 { .val_bool = false, .match_version = "< 7.4", },
119 { .val_bool = true },
120 );
121 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
122 { .val_bool = false, .match_version = "< 7.6", },
123 { .val_bool = true },
124 );
125
126 DEFINE_HOOK(bgp_inst_config_write,
127 (struct bgp *bgp, struct vty *vty),
128 (bgp, vty));
129 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
130 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
131
132 static struct peer_group *listen_range_exists(struct bgp *bgp,
133 struct prefix *range, int exact);
134
135 /* Show BGP peer's information. */
136 enum show_type {
137 show_all,
138 show_peer,
139 show_ipv4_all,
140 show_ipv6_all,
141 show_ipv4_peer,
142 show_ipv6_peer
143 };
144
145 static struct peer_group *listen_range_exists(struct bgp *bgp,
146 struct prefix *range, int exact);
147
148 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
149 struct bgp *bgp,
150 bool use_json,
151 json_object *json);
152
153 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
154 enum show_type type,
155 const char *ip_str,
156 afi_t afi, bool use_json);
157
158 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
159 {
160 switch (afi) {
161 case AFI_IP:
162 switch (safi) {
163 case SAFI_UNICAST:
164 return BGP_IPV4_NODE;
165 case SAFI_MULTICAST:
166 return BGP_IPV4M_NODE;
167 case SAFI_LABELED_UNICAST:
168 return BGP_IPV4L_NODE;
169 case SAFI_MPLS_VPN:
170 return BGP_VPNV4_NODE;
171 case SAFI_FLOWSPEC:
172 return BGP_FLOWSPECV4_NODE;
173 default:
174 /* not expected */
175 return BGP_IPV4_NODE;
176 }
177 break;
178 case AFI_IP6:
179 switch (safi) {
180 case SAFI_UNICAST:
181 return BGP_IPV6_NODE;
182 case SAFI_MULTICAST:
183 return BGP_IPV6M_NODE;
184 case SAFI_LABELED_UNICAST:
185 return BGP_IPV6L_NODE;
186 case SAFI_MPLS_VPN:
187 return BGP_VPNV6_NODE;
188 case SAFI_FLOWSPEC:
189 return BGP_FLOWSPECV6_NODE;
190 default:
191 /* not expected */
192 return BGP_IPV4_NODE;
193 }
194 break;
195 case AFI_L2VPN:
196 return BGP_EVPN_NODE;
197 case AFI_UNSPEC:
198 case AFI_MAX:
199 // We should never be here but to clarify the switch statement..
200 return BGP_IPV4_NODE;
201 }
202
203 // Impossible to happen
204 return BGP_IPV4_NODE;
205 }
206
207 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
208 {
209 if (afi == AFI_IP) {
210 if (safi == SAFI_UNICAST)
211 return "IPv4 Unicast";
212 if (safi == SAFI_MULTICAST)
213 return "IPv4 Multicast";
214 if (safi == SAFI_LABELED_UNICAST)
215 return "IPv4 Labeled Unicast";
216 if (safi == SAFI_MPLS_VPN)
217 return "IPv4 VPN";
218 if (safi == SAFI_ENCAP)
219 return "IPv4 Encap";
220 if (safi == SAFI_FLOWSPEC)
221 return "IPv4 Flowspec";
222 } else if (afi == AFI_IP6) {
223 if (safi == SAFI_UNICAST)
224 return "IPv6 Unicast";
225 if (safi == SAFI_MULTICAST)
226 return "IPv6 Multicast";
227 if (safi == SAFI_LABELED_UNICAST)
228 return "IPv6 Labeled Unicast";
229 if (safi == SAFI_MPLS_VPN)
230 return "IPv6 VPN";
231 if (safi == SAFI_ENCAP)
232 return "IPv6 Encap";
233 if (safi == SAFI_FLOWSPEC)
234 return "IPv6 Flowspec";
235 } else if (afi == AFI_L2VPN) {
236 if (safi == SAFI_EVPN)
237 return "L2VPN EVPN";
238 }
239
240 return "Unknown";
241 }
242
243 /*
244 * Please note that we have intentionally camelCased
245 * the return strings here. So if you want
246 * to use this function, please ensure you
247 * are doing this within json output
248 */
249 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
250 {
251 if (afi == AFI_IP) {
252 if (safi == SAFI_UNICAST)
253 return "ipv4Unicast";
254 if (safi == SAFI_MULTICAST)
255 return "ipv4Multicast";
256 if (safi == SAFI_LABELED_UNICAST)
257 return "ipv4LabeledUnicast";
258 if (safi == SAFI_MPLS_VPN)
259 return "ipv4Vpn";
260 if (safi == SAFI_ENCAP)
261 return "ipv4Encap";
262 if (safi == SAFI_FLOWSPEC)
263 return "ipv4Flowspec";
264 } else if (afi == AFI_IP6) {
265 if (safi == SAFI_UNICAST)
266 return "ipv6Unicast";
267 if (safi == SAFI_MULTICAST)
268 return "ipv6Multicast";
269 if (safi == SAFI_LABELED_UNICAST)
270 return "ipv6LabeledUnicast";
271 if (safi == SAFI_MPLS_VPN)
272 return "ipv6Vpn";
273 if (safi == SAFI_ENCAP)
274 return "ipv6Encap";
275 if (safi == SAFI_FLOWSPEC)
276 return "ipv6Flowspec";
277 } else if (afi == AFI_L2VPN) {
278 if (safi == SAFI_EVPN)
279 return "l2VpnEvpn";
280 }
281
282 return "Unknown";
283 }
284
285 /* unset srv6 locator */
286 static int bgp_srv6_locator_unset(struct bgp *bgp)
287 {
288 int ret;
289 struct listnode *node, *nnode;
290 struct prefix_ipv6 *chunk;
291 struct bgp_srv6_function *func;
292 struct bgp *bgp_vrf;
293 struct in6_addr *tovpn_sid;
294
295 /* release chunk notification via ZAPI */
296 ret = bgp_zebra_srv6_manager_release_locator_chunk(
297 bgp->srv6_locator_name);
298 if (ret < 0)
299 return -1;
300
301 /* refresh chunks */
302 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
303 listnode_delete(bgp->srv6_locator_chunks, chunk);
304
305 /* refresh functions */
306 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
307 listnode_delete(bgp->srv6_functions, func);
308
309 /* refresh tovpn_sid */
310 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
311 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
312 continue;
313
314 /* refresh vpnv4 tovpn_sid */
315 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
316 if (tovpn_sid)
317 XFREE(MTYPE_BGP_SRV6_SID,
318 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
319
320 /* refresh vpnv6 tovpn_sid */
321 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
322 if (tovpn_sid)
323 XFREE(MTYPE_BGP_SRV6_SID,
324 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
325 }
326
327 /* update vpn bgp processes */
328 vpn_leak_postchange_all();
329
330 /* clear locator name */
331 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
332
333 return 0;
334 }
335
336 /* Utility function to get address family from current node. */
337 afi_t bgp_node_afi(struct vty *vty)
338 {
339 afi_t afi;
340 switch (vty->node) {
341 case BGP_IPV6_NODE:
342 case BGP_IPV6M_NODE:
343 case BGP_IPV6L_NODE:
344 case BGP_VPNV6_NODE:
345 case BGP_FLOWSPECV6_NODE:
346 afi = AFI_IP6;
347 break;
348 case BGP_EVPN_NODE:
349 afi = AFI_L2VPN;
350 break;
351 default:
352 afi = AFI_IP;
353 break;
354 }
355 return afi;
356 }
357
358 /* Utility function to get subsequent address family from current
359 node. */
360 safi_t bgp_node_safi(struct vty *vty)
361 {
362 safi_t safi;
363 switch (vty->node) {
364 case BGP_VPNV4_NODE:
365 case BGP_VPNV6_NODE:
366 safi = SAFI_MPLS_VPN;
367 break;
368 case BGP_IPV4M_NODE:
369 case BGP_IPV6M_NODE:
370 safi = SAFI_MULTICAST;
371 break;
372 case BGP_EVPN_NODE:
373 safi = SAFI_EVPN;
374 break;
375 case BGP_IPV4L_NODE:
376 case BGP_IPV6L_NODE:
377 safi = SAFI_LABELED_UNICAST;
378 break;
379 case BGP_FLOWSPECV4_NODE:
380 case BGP_FLOWSPECV6_NODE:
381 safi = SAFI_FLOWSPEC;
382 break;
383 default:
384 safi = SAFI_UNICAST;
385 break;
386 }
387 return safi;
388 }
389
390 /**
391 * Converts an AFI in string form to afi_t
392 *
393 * @param afi string, one of
394 * - "ipv4"
395 * - "ipv6"
396 * - "l2vpn"
397 * @return the corresponding afi_t
398 */
399 afi_t bgp_vty_afi_from_str(const char *afi_str)
400 {
401 afi_t afi = AFI_MAX; /* unknown */
402 if (strmatch(afi_str, "ipv4"))
403 afi = AFI_IP;
404 else if (strmatch(afi_str, "ipv6"))
405 afi = AFI_IP6;
406 else if (strmatch(afi_str, "l2vpn"))
407 afi = AFI_L2VPN;
408 return afi;
409 }
410
411 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
412 afi_t *afi)
413 {
414 int ret = 0;
415 if (argv_find(argv, argc, "ipv4", index)) {
416 ret = 1;
417 if (afi)
418 *afi = AFI_IP;
419 } else if (argv_find(argv, argc, "ipv6", index)) {
420 ret = 1;
421 if (afi)
422 *afi = AFI_IP6;
423 } else if (argv_find(argv, argc, "l2vpn", index)) {
424 ret = 1;
425 if (afi)
426 *afi = AFI_L2VPN;
427 }
428 return ret;
429 }
430
431 /* supports <unicast|multicast|vpn|labeled-unicast> */
432 safi_t bgp_vty_safi_from_str(const char *safi_str)
433 {
434 safi_t safi = SAFI_MAX; /* unknown */
435 if (strmatch(safi_str, "multicast"))
436 safi = SAFI_MULTICAST;
437 else if (strmatch(safi_str, "unicast"))
438 safi = SAFI_UNICAST;
439 else if (strmatch(safi_str, "vpn"))
440 safi = SAFI_MPLS_VPN;
441 else if (strmatch(safi_str, "evpn"))
442 safi = SAFI_EVPN;
443 else if (strmatch(safi_str, "labeled-unicast"))
444 safi = SAFI_LABELED_UNICAST;
445 else if (strmatch(safi_str, "flowspec"))
446 safi = SAFI_FLOWSPEC;
447 return safi;
448 }
449
450 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
451 safi_t *safi)
452 {
453 int ret = 0;
454 if (argv_find(argv, argc, "unicast", index)) {
455 ret = 1;
456 if (safi)
457 *safi = SAFI_UNICAST;
458 } else if (argv_find(argv, argc, "multicast", index)) {
459 ret = 1;
460 if (safi)
461 *safi = SAFI_MULTICAST;
462 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
463 ret = 1;
464 if (safi)
465 *safi = SAFI_LABELED_UNICAST;
466 } else if (argv_find(argv, argc, "vpn", index)) {
467 ret = 1;
468 if (safi)
469 *safi = SAFI_MPLS_VPN;
470 } else if (argv_find(argv, argc, "evpn", index)) {
471 ret = 1;
472 if (safi)
473 *safi = SAFI_EVPN;
474 } else if (argv_find(argv, argc, "flowspec", index)) {
475 ret = 1;
476 if (safi)
477 *safi = SAFI_FLOWSPEC;
478 }
479 return ret;
480 }
481
482 /*
483 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
484 *
485 * afi
486 * address-family identifier
487 *
488 * safi
489 * subsequent address-family identifier
490 *
491 * Returns:
492 * default_af string corresponding to the supplied afi/safi pair.
493 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
494 * return -1.
495 */
496 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
497 {
498 switch (afi) {
499 case AFI_IP:
500 switch (safi) {
501 case SAFI_UNICAST:
502 return "ipv4-unicast";
503 case SAFI_MULTICAST:
504 return "ipv4-multicast";
505 case SAFI_MPLS_VPN:
506 return "ipv4-vpn";
507 case SAFI_ENCAP:
508 return "ipv4-encap";
509 case SAFI_LABELED_UNICAST:
510 return "ipv4-labeled-unicast";
511 case SAFI_FLOWSPEC:
512 return "ipv4-flowspec";
513 default:
514 return "unknown-afi/safi";
515 }
516 break;
517 case AFI_IP6:
518 switch (safi) {
519 case SAFI_UNICAST:
520 return "ipv6-unicast";
521 case SAFI_MULTICAST:
522 return "ipv6-multicast";
523 case SAFI_MPLS_VPN:
524 return "ipv6-vpn";
525 case SAFI_ENCAP:
526 return "ipv6-encap";
527 case SAFI_LABELED_UNICAST:
528 return "ipv6-labeled-unicast";
529 case SAFI_FLOWSPEC:
530 return "ipv6-flowspec";
531 default:
532 return "unknown-afi/safi";
533 }
534 break;
535 case AFI_L2VPN:
536 switch (safi) {
537 case SAFI_EVPN:
538 return "l2vpn-evpn";
539 default:
540 return "unknown-afi/safi";
541 }
542 case AFI_UNSPEC:
543 case AFI_MAX:
544 return "unknown-afi/safi";
545 }
546 /* all AFIs are accounted for above, so this shouldn't happen */
547 return "unknown-afi/safi";
548 }
549
550 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
551 enum bgp_instance_type inst_type)
552 {
553 int ret = bgp_get(bgp, as, name, inst_type);
554
555 if (ret == BGP_CREATED) {
556 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
557 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
558
559 if (DFLT_BGP_IMPORT_CHECK)
560 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
561 if (DFLT_BGP_SHOW_HOSTNAME)
562 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
563 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
564 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
565 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
566 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
567 if (DFLT_BGP_DETERMINISTIC_MED)
568 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
569 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
570 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
571 if (DFLT_BGP_SUPPRESS_DUPLICATES)
572 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
573
574 ret = BGP_SUCCESS;
575 }
576 return ret;
577 }
578
579 /*
580 * bgp_vty_find_and_parse_afi_safi_bgp
581 *
582 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
583 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
584 * to appropriate values for the calling function. This is to allow the
585 * calling function to make decisions appropriate for the show command
586 * that is being parsed.
587 *
588 * The show commands are generally of the form:
589 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
590 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
591 *
592 * Since we use argv_find if the show command in particular doesn't have:
593 * [ip]
594 * [<view|vrf> VIEWVRFNAME]
595 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
596 * The command parsing should still be ok.
597 *
598 * vty -> The vty for the command so we can output some useful data in
599 * the event of a parse error in the vrf.
600 * argv -> The command tokens
601 * argc -> How many command tokens we have
602 * idx -> The current place in the command, generally should be 0 for this
603 * function
604 * afi -> The parsed afi if it was included in the show command, returned here
605 * safi -> The parsed safi if it was included in the show command, returned here
606 * bgp -> Pointer to the bgp data structure we need to fill in.
607 * use_json -> json is configured or not
608 *
609 * The function returns the correct location in the parse tree for the
610 * last token found.
611 *
612 * Returns 0 for failure to parse correctly, else the idx position of where
613 * it found the last token.
614 */
615 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
616 struct cmd_token **argv, int argc,
617 int *idx, afi_t *afi, safi_t *safi,
618 struct bgp **bgp, bool use_json)
619 {
620 char *vrf_name = NULL;
621
622 assert(afi);
623 assert(safi);
624 assert(bgp);
625
626 if (argv_find(argv, argc, "ip", idx))
627 *afi = AFI_IP;
628
629 if (argv_find(argv, argc, "view", idx))
630 vrf_name = argv[*idx + 1]->arg;
631 else if (argv_find(argv, argc, "vrf", idx)) {
632 vrf_name = argv[*idx + 1]->arg;
633 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
634 vrf_name = NULL;
635 }
636 if (vrf_name) {
637 if (strmatch(vrf_name, "all"))
638 *bgp = NULL;
639 else {
640 *bgp = bgp_lookup_by_name(vrf_name);
641 if (!*bgp) {
642 if (use_json) {
643 json_object *json = NULL;
644 json = json_object_new_object();
645 json_object_string_add(
646 json, "warning",
647 "View/Vrf is unknown");
648 vty_json(vty, json);
649 }
650 else
651 vty_out(vty, "View/Vrf %s is unknown\n",
652 vrf_name);
653 *idx = 0;
654 return 0;
655 }
656 }
657 } else {
658 *bgp = bgp_get_default();
659 if (!*bgp) {
660 if (use_json) {
661 json_object *json = NULL;
662 json = json_object_new_object();
663 json_object_string_add(
664 json, "warning",
665 "Default BGP instance not found");
666 vty_json(vty, json);
667 }
668 else
669 vty_out(vty,
670 "Default BGP instance not found\n");
671 *idx = 0;
672 return 0;
673 }
674 }
675
676 if (argv_find_and_parse_afi(argv, argc, idx, afi))
677 argv_find_and_parse_safi(argv, argc, idx, safi);
678
679 *idx += 1;
680 return *idx;
681 }
682
683 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
684 {
685 struct interface *ifp = NULL;
686
687 if (su->sa.sa_family == AF_INET)
688 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
689 else if (su->sa.sa_family == AF_INET6)
690 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
691 su->sin6.sin6_scope_id,
692 bgp->vrf_id);
693
694 if (ifp)
695 return true;
696
697 return false;
698 }
699
700 /* Utility function for looking up peer from VTY. */
701 /* This is used only for configuration, so disallow if attempted on
702 * a dynamic neighbor.
703 */
704 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
705 {
706 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
707 int ret;
708 union sockunion su;
709 struct peer *peer;
710
711 if (!bgp) {
712 return NULL;
713 }
714
715 ret = str2sockunion(ip_str, &su);
716 if (ret < 0) {
717 peer = peer_lookup_by_conf_if(bgp, ip_str);
718 if (!peer) {
719 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
720 == NULL) {
721 vty_out(vty,
722 "%% Malformed address or name: %s\n",
723 ip_str);
724 return NULL;
725 }
726 }
727 } else {
728 peer = peer_lookup(bgp, &su);
729 if (!peer) {
730 vty_out(vty,
731 "%% Specify remote-as or peer-group commands first\n");
732 return NULL;
733 }
734 if (peer_dynamic_neighbor(peer)) {
735 vty_out(vty,
736 "%% Operation not allowed on a dynamic neighbor\n");
737 return NULL;
738 }
739 }
740 return peer;
741 }
742
743 /* Utility function for looking up peer or peer group. */
744 /* This is used only for configuration, so disallow if attempted on
745 * a dynamic neighbor.
746 */
747 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
748 {
749 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
750 int ret;
751 union sockunion su;
752 struct peer *peer = NULL;
753 struct peer_group *group = NULL;
754
755 if (!bgp) {
756 return NULL;
757 }
758
759 ret = str2sockunion(peer_str, &su);
760 if (ret == 0) {
761 /* IP address, locate peer. */
762 peer = peer_lookup(bgp, &su);
763 } else {
764 /* Not IP, could match either peer configured on interface or a
765 * group. */
766 peer = peer_lookup_by_conf_if(bgp, peer_str);
767 if (!peer)
768 group = peer_group_lookup(bgp, peer_str);
769 }
770
771 if (peer) {
772 if (peer_dynamic_neighbor(peer)) {
773 vty_out(vty,
774 "%% Operation not allowed on a dynamic neighbor\n");
775 return NULL;
776 }
777
778 return peer;
779 }
780
781 if (group)
782 return group->conf;
783
784 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
785
786 return NULL;
787 }
788
789 int bgp_vty_return(struct vty *vty, int ret)
790 {
791 const char *str = NULL;
792
793 switch (ret) {
794 case BGP_ERR_INVALID_VALUE:
795 str = "Invalid value";
796 break;
797 case BGP_ERR_INVALID_FLAG:
798 str = "Invalid flag";
799 break;
800 case BGP_ERR_PEER_GROUP_SHUTDOWN:
801 str = "Peer-group has been shutdown. Activate the peer-group first";
802 break;
803 case BGP_ERR_PEER_FLAG_CONFLICT:
804 str = "Can't set override-capability and strict-capability-match at the same time";
805 break;
806 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
807 str = "Specify remote-as or peer-group remote AS first";
808 break;
809 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
810 str = "Cannot change the peer-group. Deconfigure first";
811 break;
812 case BGP_ERR_PEER_GROUP_MISMATCH:
813 str = "Peer is not a member of this peer-group";
814 break;
815 case BGP_ERR_PEER_FILTER_CONFLICT:
816 str = "Prefix/distribute list can not co-exist";
817 break;
818 case BGP_ERR_NOT_INTERNAL_PEER:
819 str = "Invalid command. Not an internal neighbor";
820 break;
821 case BGP_ERR_REMOVE_PRIVATE_AS:
822 str = "remove-private-AS cannot be configured for IBGP peers";
823 break;
824 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
825 str = "Local-AS allowed only for EBGP peers";
826 break;
827 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
828 str = "Cannot have local-as same as BGP AS number";
829 break;
830 case BGP_ERR_TCPSIG_FAILED:
831 str = "Error while applying TCP-Sig to session(s)";
832 break;
833 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
834 str = "ebgp-multihop and ttl-security cannot be configured together";
835 break;
836 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
837 str = "ttl-security only allowed for EBGP peers";
838 break;
839 case BGP_ERR_AS_OVERRIDE:
840 str = "as-override cannot be configured for IBGP peers";
841 break;
842 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
843 str = "Invalid limit for number of dynamic neighbors";
844 break;
845 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
846 str = "Dynamic neighbor listen range already exists";
847 break;
848 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
849 str = "Operation not allowed on a dynamic neighbor";
850 break;
851 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
852 str = "Operation not allowed on a directly connected neighbor";
853 break;
854 case BGP_ERR_PEER_SAFI_CONFLICT:
855 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
856 break;
857 case BGP_ERR_GR_INVALID_CMD:
858 str = "The Graceful Restart command used is not valid at this moment.";
859 break;
860 case BGP_ERR_GR_OPERATION_FAILED:
861 str = "The Graceful Restart Operation failed due to an err.";
862 break;
863 }
864 if (str) {
865 vty_out(vty, "%% %s\n", str);
866 return CMD_WARNING_CONFIG_FAILED;
867 }
868 return CMD_SUCCESS;
869 }
870
871 /* BGP clear sort. */
872 enum clear_sort {
873 clear_all,
874 clear_peer,
875 clear_group,
876 clear_external,
877 clear_as
878 };
879
880 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
881 safi_t safi, int error)
882 {
883 switch (error) {
884 case BGP_ERR_AF_UNCONFIGURED:
885 vty_out(vty,
886 "%%BGP: Enable %s address family for the neighbor %s\n",
887 get_afi_safi_str(afi, safi, false), peer->host);
888 break;
889 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
890 vty_out(vty,
891 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
892 peer->host);
893 break;
894 default:
895 break;
896 }
897 }
898
899 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
900 struct listnode **nnode, enum bgp_clear_type stype)
901 {
902 int ret = 0;
903 struct peer_af *paf;
904
905 /* if afi/.safi not specified, spin thru all of them */
906 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
907 afi_t tmp_afi;
908 safi_t tmp_safi;
909 enum bgp_af_index index;
910
911 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
912 paf = peer->peer_af_array[index];
913 if (!paf)
914 continue;
915
916 if (paf && paf->subgroup)
917 SET_FLAG(paf->subgroup->sflags,
918 SUBGRP_STATUS_FORCE_UPDATES);
919
920 tmp_afi = paf->afi;
921 tmp_safi = paf->safi;
922 if (!peer->afc[tmp_afi][tmp_safi])
923 continue;
924
925 if (stype == BGP_CLEAR_SOFT_NONE)
926 ret = peer_clear(peer, nnode);
927 else
928 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
929 stype);
930 }
931 /* if afi specified and safi not, spin thru safis on this afi */
932 } else if (safi == SAFI_UNSPEC) {
933 safi_t tmp_safi;
934
935 for (tmp_safi = SAFI_UNICAST;
936 tmp_safi < SAFI_MAX; tmp_safi++) {
937 if (!peer->afc[afi][tmp_safi])
938 continue;
939
940 paf = peer_af_find(peer, afi, tmp_safi);
941 if (paf && paf->subgroup)
942 SET_FLAG(paf->subgroup->sflags,
943 SUBGRP_STATUS_FORCE_UPDATES);
944
945 if (stype == BGP_CLEAR_SOFT_NONE)
946 ret = peer_clear(peer, nnode);
947 else
948 ret = peer_clear_soft(peer, afi,
949 tmp_safi, stype);
950 }
951 /* both afi/safi specified, let the caller know if not defined */
952 } else {
953 if (!peer->afc[afi][safi])
954 return 1;
955
956 paf = peer_af_find(peer, afi, safi);
957 if (paf && paf->subgroup)
958 SET_FLAG(paf->subgroup->sflags,
959 SUBGRP_STATUS_FORCE_UPDATES);
960
961 if (stype == BGP_CLEAR_SOFT_NONE)
962 ret = peer_clear(peer, nnode);
963 else
964 ret = peer_clear_soft(peer, afi, safi, stype);
965 }
966
967 return ret;
968 }
969
970 /* `clear ip bgp' functions. */
971 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
972 enum clear_sort sort, enum bgp_clear_type stype,
973 const char *arg)
974 {
975 int ret = 0;
976 bool found = false;
977 struct peer *peer;
978
979 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
980
981 /* Clear all neighbors. */
982 /*
983 * Pass along pointer to next node to peer_clear() when walking all
984 * nodes on the BGP instance as that may get freed if it is a
985 * doppelganger
986 */
987 if (sort == clear_all) {
988 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
989
990 bgp_peer_gr_flags_update(peer);
991
992 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
993 gr_router_detected = true;
994
995 ret = bgp_peer_clear(peer, afi, safi, &nnode,
996 stype);
997
998 if (ret < 0)
999 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1000 }
1001
1002 if (gr_router_detected
1003 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1004 bgp_zebra_send_capabilities(bgp, false);
1005 } else if (!gr_router_detected
1006 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1007 bgp_zebra_send_capabilities(bgp, true);
1008 }
1009
1010 /* This is to apply read-only mode on this clear. */
1011 if (stype == BGP_CLEAR_SOFT_NONE)
1012 bgp->update_delay_over = 0;
1013
1014 return CMD_SUCCESS;
1015 }
1016
1017 /* Clear specified neighbor. */
1018 if (sort == clear_peer) {
1019 union sockunion su;
1020
1021 /* Make sockunion for lookup. */
1022 ret = str2sockunion(arg, &su);
1023 if (ret < 0) {
1024 peer = peer_lookup_by_conf_if(bgp, arg);
1025 if (!peer) {
1026 peer = peer_lookup_by_hostname(bgp, arg);
1027 if (!peer) {
1028 vty_out(vty,
1029 "Malformed address or name: %s\n",
1030 arg);
1031 return CMD_WARNING;
1032 }
1033 }
1034 } else {
1035 peer = peer_lookup(bgp, &su);
1036 if (!peer) {
1037 vty_out(vty,
1038 "%%BGP: Unknown neighbor - \"%s\"\n",
1039 arg);
1040 return CMD_WARNING;
1041 }
1042 }
1043
1044 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1045 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1046
1047 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1048
1049 /* if afi/safi not defined for this peer, let caller know */
1050 if (ret == 1)
1051 ret = BGP_ERR_AF_UNCONFIGURED;
1052
1053 if (ret < 0)
1054 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1055
1056 return CMD_SUCCESS;
1057 }
1058
1059 /* Clear all neighbors belonging to a specific peer-group. */
1060 if (sort == clear_group) {
1061 struct peer_group *group;
1062
1063 group = peer_group_lookup(bgp, arg);
1064 if (!group) {
1065 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
1066 return CMD_WARNING;
1067 }
1068
1069 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1070 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1071
1072 if (ret < 0)
1073 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1074 else
1075 found = true;
1076 }
1077
1078 if (!found)
1079 vty_out(vty,
1080 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
1081 get_afi_safi_str(afi, safi, false), arg);
1082
1083 return CMD_SUCCESS;
1084 }
1085
1086 /* Clear all external (eBGP) neighbors. */
1087 if (sort == clear_external) {
1088 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1089 if (peer->sort == BGP_PEER_IBGP)
1090 continue;
1091
1092 bgp_peer_gr_flags_update(peer);
1093
1094 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1095 gr_router_detected = true;
1096
1097 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1098
1099 if (ret < 0)
1100 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1101 else
1102 found = true;
1103 }
1104
1105 if (gr_router_detected
1106 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1107 bgp_zebra_send_capabilities(bgp, false);
1108 } else if (!gr_router_detected
1109 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1110 bgp_zebra_send_capabilities(bgp, true);
1111 }
1112
1113 if (!found)
1114 vty_out(vty,
1115 "%%BGP: No external %s peer is configured\n",
1116 get_afi_safi_str(afi, safi, false));
1117
1118 return CMD_SUCCESS;
1119 }
1120
1121 /* Clear all neighbors belonging to a specific AS. */
1122 if (sort == clear_as) {
1123 as_t as = strtoul(arg, NULL, 10);
1124
1125 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1126 if (peer->as != as)
1127 continue;
1128
1129 bgp_peer_gr_flags_update(peer);
1130
1131 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1132 gr_router_detected = true;
1133
1134 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1135
1136 if (ret < 0)
1137 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1138 else
1139 found = true;
1140 }
1141
1142 if (gr_router_detected
1143 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1144 bgp_zebra_send_capabilities(bgp, false);
1145 } else if (!gr_router_detected
1146 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1147 bgp_zebra_send_capabilities(bgp, true);
1148 }
1149
1150 if (!found)
1151 vty_out(vty,
1152 "%%BGP: No %s peer is configured with AS %s\n",
1153 get_afi_safi_str(afi, safi, false), arg);
1154
1155 return CMD_SUCCESS;
1156 }
1157
1158 return CMD_SUCCESS;
1159 }
1160
1161 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1162 safi_t safi, enum clear_sort sort,
1163 enum bgp_clear_type stype, const char *arg)
1164 {
1165 struct bgp *bgp;
1166
1167 /* BGP structure lookup. */
1168 if (name) {
1169 bgp = bgp_lookup_by_name(name);
1170 if (bgp == NULL) {
1171 vty_out(vty, "Can't find BGP instance %s\n", name);
1172 return CMD_WARNING;
1173 }
1174 } else {
1175 bgp = bgp_get_default();
1176 if (bgp == NULL) {
1177 vty_out(vty, "No BGP process is configured\n");
1178 return CMD_WARNING;
1179 }
1180 }
1181
1182 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1183 }
1184
1185 /* clear soft inbound */
1186 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1187 {
1188 afi_t afi;
1189 safi_t safi;
1190
1191 FOREACH_AFI_SAFI (afi, safi)
1192 bgp_clear_vty(vty, name, afi, safi, clear_all,
1193 BGP_CLEAR_SOFT_IN, NULL);
1194 }
1195
1196 /* clear soft outbound */
1197 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1198 {
1199 afi_t afi;
1200 safi_t safi;
1201
1202 FOREACH_AFI_SAFI (afi, safi)
1203 bgp_clear_vty(vty, name, afi, safi, clear_all,
1204 BGP_CLEAR_SOFT_OUT, NULL);
1205 }
1206
1207
1208 #ifndef VTYSH_EXTRACT_PL
1209 #include "bgpd/bgp_vty_clippy.c"
1210 #endif
1211
1212 DEFUN_HIDDEN (bgp_local_mac,
1213 bgp_local_mac_cmd,
1214 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1215 BGP_STR
1216 "Local MAC config\n"
1217 "VxLAN Network Identifier\n"
1218 "VNI number\n"
1219 "local mac\n"
1220 "mac address\n"
1221 "mac-mobility sequence\n"
1222 "seq number\n")
1223 {
1224 int rv;
1225 vni_t vni;
1226 struct ethaddr mac;
1227 struct ipaddr ip;
1228 uint32_t seq;
1229 struct bgp *bgp;
1230
1231 vni = strtoul(argv[3]->arg, NULL, 10);
1232 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1233 vty_out(vty, "%% Malformed MAC address\n");
1234 return CMD_WARNING;
1235 }
1236 memset(&ip, 0, sizeof(ip));
1237 seq = strtoul(argv[7]->arg, NULL, 10);
1238
1239 bgp = bgp_get_default();
1240 if (!bgp) {
1241 vty_out(vty, "Default BGP instance is not there\n");
1242 return CMD_WARNING;
1243 }
1244
1245 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1246 zero_esi);
1247 if (rv < 0) {
1248 vty_out(vty, "Internal error\n");
1249 return CMD_WARNING;
1250 }
1251
1252 return CMD_SUCCESS;
1253 }
1254
1255 DEFUN_HIDDEN (no_bgp_local_mac,
1256 no_bgp_local_mac_cmd,
1257 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1258 NO_STR
1259 BGP_STR
1260 "Local MAC config\n"
1261 "VxLAN Network Identifier\n"
1262 "VNI number\n"
1263 "local mac\n"
1264 "mac address\n")
1265 {
1266 int rv;
1267 vni_t vni;
1268 struct ethaddr mac;
1269 struct ipaddr ip;
1270 struct bgp *bgp;
1271
1272 vni = strtoul(argv[4]->arg, NULL, 10);
1273 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1274 vty_out(vty, "%% Malformed MAC address\n");
1275 return CMD_WARNING;
1276 }
1277 memset(&ip, 0, sizeof(ip));
1278
1279 bgp = bgp_get_default();
1280 if (!bgp) {
1281 vty_out(vty, "Default BGP instance is not there\n");
1282 return CMD_WARNING;
1283 }
1284
1285 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1286 if (rv < 0) {
1287 vty_out(vty, "Internal error\n");
1288 return CMD_WARNING;
1289 }
1290
1291 return CMD_SUCCESS;
1292 }
1293
1294 DEFUN (no_synchronization,
1295 no_synchronization_cmd,
1296 "no synchronization",
1297 NO_STR
1298 "Perform IGP synchronization\n")
1299 {
1300 return CMD_SUCCESS;
1301 }
1302
1303 DEFUN (no_auto_summary,
1304 no_auto_summary_cmd,
1305 "no auto-summary",
1306 NO_STR
1307 "Enable automatic network number summarization\n")
1308 {
1309 return CMD_SUCCESS;
1310 }
1311
1312 /* "router bgp" commands. */
1313 DEFUN_NOSH (router_bgp,
1314 router_bgp_cmd,
1315 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1316 ROUTER_STR
1317 BGP_STR
1318 AS_STR
1319 BGP_INSTANCE_HELP_STR)
1320 {
1321 int idx_asn = 2;
1322 int idx_view_vrf = 3;
1323 int idx_vrf = 4;
1324 int is_new_bgp = 0;
1325 int ret;
1326 as_t as;
1327 struct bgp *bgp;
1328 const char *name = NULL;
1329 enum bgp_instance_type inst_type;
1330
1331 // "router bgp" without an ASN
1332 if (argc == 2) {
1333 // Pending: Make VRF option available for ASN less config
1334 bgp = bgp_get_default();
1335
1336 if (bgp == NULL) {
1337 vty_out(vty, "%% No BGP process is configured\n");
1338 return CMD_WARNING_CONFIG_FAILED;
1339 }
1340
1341 if (listcount(bm->bgp) > 1) {
1342 vty_out(vty, "%% Please specify ASN and VRF\n");
1343 return CMD_WARNING_CONFIG_FAILED;
1344 }
1345 }
1346
1347 // "router bgp X"
1348 else {
1349 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1350
1351 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1352 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1353 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1354
1355 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1356 if (argc > 3) {
1357 name = argv[idx_vrf]->arg;
1358
1359 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1360 if (strmatch(name, VRF_DEFAULT_NAME))
1361 name = NULL;
1362 else
1363 inst_type = BGP_INSTANCE_TYPE_VRF;
1364 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1365 inst_type = BGP_INSTANCE_TYPE_VIEW;
1366 }
1367
1368 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1369 is_new_bgp = (bgp_lookup(as, name) == NULL);
1370
1371 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1372 switch (ret) {
1373 case BGP_ERR_AS_MISMATCH:
1374 vty_out(vty, "BGP is already running; AS is %u\n", as);
1375 return CMD_WARNING_CONFIG_FAILED;
1376 case BGP_ERR_INSTANCE_MISMATCH:
1377 vty_out(vty,
1378 "BGP instance name and AS number mismatch\n");
1379 vty_out(vty,
1380 "BGP instance is already running; AS is %u\n",
1381 as);
1382 return CMD_WARNING_CONFIG_FAILED;
1383 }
1384
1385 /*
1386 * If we just instantiated the default instance, complete
1387 * any pending VRF-VPN leaking that was configured via
1388 * earlier "router bgp X vrf FOO" blocks.
1389 */
1390 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1391 vpn_leak_postchange_all();
1392
1393 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1394 bgp_vpn_leak_export(bgp);
1395 /* Pending: handle when user tries to change a view to vrf n vv.
1396 */
1397 }
1398
1399 /* unset the auto created flag as the user config is now present */
1400 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1401 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1402
1403 return CMD_SUCCESS;
1404 }
1405
1406 /* "no router bgp" commands. */
1407 DEFUN (no_router_bgp,
1408 no_router_bgp_cmd,
1409 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1410 NO_STR
1411 ROUTER_STR
1412 BGP_STR
1413 AS_STR
1414 BGP_INSTANCE_HELP_STR)
1415 {
1416 int idx_asn = 3;
1417 int idx_vrf = 5;
1418 as_t as;
1419 struct bgp *bgp;
1420 const char *name = NULL;
1421
1422 // "no router bgp" without an ASN
1423 if (argc == 3) {
1424 // Pending: Make VRF option available for ASN less config
1425 bgp = bgp_get_default();
1426
1427 if (bgp == NULL) {
1428 vty_out(vty, "%% No BGP process is configured\n");
1429 return CMD_WARNING_CONFIG_FAILED;
1430 }
1431
1432 if (listcount(bm->bgp) > 1) {
1433 vty_out(vty, "%% Please specify ASN and VRF\n");
1434 return CMD_WARNING_CONFIG_FAILED;
1435 }
1436
1437 if (bgp->l3vni) {
1438 vty_out(vty, "%% Please unconfigure l3vni %u",
1439 bgp->l3vni);
1440 return CMD_WARNING_CONFIG_FAILED;
1441 }
1442 } else {
1443 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1444
1445 if (argc > 4) {
1446 name = argv[idx_vrf]->arg;
1447 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1448 && strmatch(name, VRF_DEFAULT_NAME))
1449 name = NULL;
1450 }
1451
1452 /* Lookup bgp structure. */
1453 bgp = bgp_lookup(as, name);
1454 if (!bgp) {
1455 vty_out(vty, "%% Can't find BGP instance\n");
1456 return CMD_WARNING_CONFIG_FAILED;
1457 }
1458
1459 if (bgp->l3vni) {
1460 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1461 bgp->l3vni);
1462 return CMD_WARNING_CONFIG_FAILED;
1463 }
1464
1465 /* Cannot delete default instance if vrf instances exist */
1466 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1467 struct listnode *node;
1468 struct bgp *tmp_bgp;
1469
1470 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1471 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1472 continue;
1473 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1474 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1475 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1476 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1477 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1478 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1479 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1480 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1481 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1482 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1483 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1484 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1485 (bgp == bgp_get_evpn() &&
1486 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1487 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1488 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1489 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1490 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1491 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1492 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1493 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1494 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1495 vty_out(vty,
1496 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1497 return CMD_WARNING_CONFIG_FAILED;
1498 }
1499 }
1500 }
1501 }
1502
1503 bgp_delete(bgp);
1504
1505 return CMD_SUCCESS;
1506 }
1507
1508
1509 /* BGP router-id. */
1510
1511 DEFPY (bgp_router_id,
1512 bgp_router_id_cmd,
1513 "bgp router-id A.B.C.D",
1514 BGP_STR
1515 "Override configured router identifier\n"
1516 "Manually configured router identifier\n")
1517 {
1518 VTY_DECLVAR_CONTEXT(bgp, bgp);
1519 bgp_router_id_static_set(bgp, router_id);
1520 return CMD_SUCCESS;
1521 }
1522
1523 DEFPY (no_bgp_router_id,
1524 no_bgp_router_id_cmd,
1525 "no bgp router-id [A.B.C.D]",
1526 NO_STR
1527 BGP_STR
1528 "Override configured router identifier\n"
1529 "Manually configured router identifier\n")
1530 {
1531 VTY_DECLVAR_CONTEXT(bgp, bgp);
1532
1533 if (router_id_str) {
1534 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1535 vty_out(vty, "%% BGP router-id doesn't match\n");
1536 return CMD_WARNING_CONFIG_FAILED;
1537 }
1538 }
1539
1540 router_id.s_addr = 0;
1541 bgp_router_id_static_set(bgp, router_id);
1542
1543 return CMD_SUCCESS;
1544 }
1545
1546 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1547 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1548 NO_STR BGP_STR
1549 "Add community specific parameters\n"
1550 "Create an alias for a community\n"
1551 "Community (AA:BB or AA:BB:CC)\n"
1552 "Alias name\n")
1553 {
1554 struct community_alias ca1;
1555 struct community_alias ca2;
1556 struct community_alias *lookup_community;
1557 struct community_alias *lookup_alias;
1558
1559 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1560 vty_out(vty, "Invalid community format\n");
1561 return CMD_WARNING;
1562 }
1563
1564 memset(&ca1, 0, sizeof(ca1));
1565 memset(&ca2, 0, sizeof(ca2));
1566 strlcpy(ca1.community, community, sizeof(ca1.community));
1567 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
1568
1569 lookup_community = bgp_ca_community_lookup(&ca1);
1570 lookup_alias = bgp_ca_alias_lookup(&ca1);
1571
1572 if (no) {
1573 bgp_ca_alias_delete(&ca1);
1574 bgp_ca_community_delete(&ca1);
1575 } else {
1576 if (lookup_alias) {
1577 /* Lookup if community hash table has an item
1578 * with the same alias name.
1579 */
1580 strlcpy(ca2.community, lookup_alias->community,
1581 sizeof(ca2.community));
1582 if (bgp_ca_community_lookup(&ca2)) {
1583 vty_out(vty,
1584 "community (%s) already has this alias (%s)\n",
1585 lookup_alias->community,
1586 lookup_alias->alias);
1587 return CMD_WARNING;
1588 }
1589 bgp_ca_alias_delete(&ca1);
1590 }
1591
1592 if (lookup_community)
1593 bgp_ca_community_delete(&ca1);
1594
1595 bgp_ca_alias_insert(&ca1);
1596 bgp_ca_community_insert(&ca1);
1597 }
1598
1599 return CMD_SUCCESS;
1600 }
1601
1602 DEFPY (bgp_global_suppress_fib_pending,
1603 bgp_global_suppress_fib_pending_cmd,
1604 "[no] bgp suppress-fib-pending",
1605 NO_STR
1606 BGP_STR
1607 "Advertise only routes that are programmed in kernel to peers globally\n")
1608 {
1609 bm_wait_for_fib_set(!no);
1610
1611 return CMD_SUCCESS;
1612 }
1613
1614 DEFPY (bgp_suppress_fib_pending,
1615 bgp_suppress_fib_pending_cmd,
1616 "[no] bgp suppress-fib-pending",
1617 NO_STR
1618 BGP_STR
1619 "Advertise only routes that are programmed in kernel to peers\n")
1620 {
1621 VTY_DECLVAR_CONTEXT(bgp, bgp);
1622
1623 bgp_suppress_fib_pending_set(bgp, !no);
1624 return CMD_SUCCESS;
1625 }
1626
1627
1628 /* BGP Cluster ID. */
1629 DEFUN (bgp_cluster_id,
1630 bgp_cluster_id_cmd,
1631 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1632 BGP_STR
1633 "Configure Route-Reflector Cluster-id\n"
1634 "Route-Reflector Cluster-id in IP address format\n"
1635 "Route-Reflector Cluster-id as 32 bit quantity\n")
1636 {
1637 VTY_DECLVAR_CONTEXT(bgp, bgp);
1638 int idx_ipv4 = 2;
1639 int ret;
1640 struct in_addr cluster;
1641
1642 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1643 if (!ret) {
1644 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1645 return CMD_WARNING_CONFIG_FAILED;
1646 }
1647
1648 bgp_cluster_id_set(bgp, &cluster);
1649 bgp_clear_star_soft_out(vty, bgp->name);
1650
1651 return CMD_SUCCESS;
1652 }
1653
1654 DEFUN (no_bgp_cluster_id,
1655 no_bgp_cluster_id_cmd,
1656 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1657 NO_STR
1658 BGP_STR
1659 "Configure Route-Reflector Cluster-id\n"
1660 "Route-Reflector Cluster-id in IP address format\n"
1661 "Route-Reflector Cluster-id as 32 bit quantity\n")
1662 {
1663 VTY_DECLVAR_CONTEXT(bgp, bgp);
1664 bgp_cluster_id_unset(bgp);
1665 bgp_clear_star_soft_out(vty, bgp->name);
1666
1667 return CMD_SUCCESS;
1668 }
1669
1670 DEFPY (bgp_norib,
1671 bgp_norib_cmd,
1672 "bgp no-rib",
1673 BGP_STR
1674 "Disable BGP route installation to RIB (Zebra)\n")
1675 {
1676 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1677 vty_out(vty,
1678 "%% No-RIB option is already set, nothing to do here.\n");
1679 return CMD_SUCCESS;
1680 }
1681
1682 bgp_option_norib_set_runtime();
1683
1684 return CMD_SUCCESS;
1685 }
1686
1687 DEFPY (no_bgp_norib,
1688 no_bgp_norib_cmd,
1689 "no bgp no-rib",
1690 NO_STR
1691 BGP_STR
1692 "Disable BGP route installation to RIB (Zebra)\n")
1693 {
1694 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1695 vty_out(vty,
1696 "%% No-RIB option is not set, nothing to do here.\n");
1697 return CMD_SUCCESS;
1698 }
1699
1700 bgp_option_norib_unset_runtime();
1701
1702 return CMD_SUCCESS;
1703 }
1704
1705 DEFPY (no_bgp_send_extra_data,
1706 no_bgp_send_extra_data_cmd,
1707 "[no] bgp send-extra-data zebra",
1708 NO_STR
1709 BGP_STR
1710 "Extra data to Zebra for display/use\n"
1711 "To zebra\n")
1712 {
1713 if (no)
1714 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1715 else
1716 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1717
1718 return CMD_SUCCESS;
1719 }
1720
1721 DEFUN (bgp_confederation_identifier,
1722 bgp_confederation_identifier_cmd,
1723 "bgp confederation identifier (1-4294967295)",
1724 BGP_STR
1725 "AS confederation parameters\n"
1726 "AS number\n"
1727 "Set routing domain confederation AS\n")
1728 {
1729 VTY_DECLVAR_CONTEXT(bgp, bgp);
1730 int idx_number = 3;
1731 as_t as;
1732
1733 as = strtoul(argv[idx_number]->arg, NULL, 10);
1734
1735 bgp_confederation_id_set(bgp, as);
1736
1737 return CMD_SUCCESS;
1738 }
1739
1740 DEFUN (no_bgp_confederation_identifier,
1741 no_bgp_confederation_identifier_cmd,
1742 "no bgp confederation identifier [(1-4294967295)]",
1743 NO_STR
1744 BGP_STR
1745 "AS confederation parameters\n"
1746 "AS number\n"
1747 "Set routing domain confederation AS\n")
1748 {
1749 VTY_DECLVAR_CONTEXT(bgp, bgp);
1750 bgp_confederation_id_unset(bgp);
1751
1752 return CMD_SUCCESS;
1753 }
1754
1755 DEFUN (bgp_confederation_peers,
1756 bgp_confederation_peers_cmd,
1757 "bgp confederation peers (1-4294967295)...",
1758 BGP_STR
1759 "AS confederation parameters\n"
1760 "Peer ASs in BGP confederation\n"
1761 AS_STR)
1762 {
1763 VTY_DECLVAR_CONTEXT(bgp, bgp);
1764 int idx_asn = 3;
1765 as_t as;
1766 int i;
1767
1768 for (i = idx_asn; i < argc; i++) {
1769 as = strtoul(argv[i]->arg, NULL, 10);
1770
1771 if (bgp->as == as) {
1772 vty_out(vty,
1773 "%% Local member-AS not allowed in confed peer list\n");
1774 continue;
1775 }
1776
1777 bgp_confederation_peers_add(bgp, as);
1778 }
1779 return CMD_SUCCESS;
1780 }
1781
1782 DEFUN (no_bgp_confederation_peers,
1783 no_bgp_confederation_peers_cmd,
1784 "no bgp confederation peers (1-4294967295)...",
1785 NO_STR
1786 BGP_STR
1787 "AS confederation parameters\n"
1788 "Peer ASs in BGP confederation\n"
1789 AS_STR)
1790 {
1791 VTY_DECLVAR_CONTEXT(bgp, bgp);
1792 int idx_asn = 4;
1793 as_t as;
1794 int i;
1795
1796 for (i = idx_asn; i < argc; i++) {
1797 as = strtoul(argv[i]->arg, NULL, 10);
1798
1799 bgp_confederation_peers_remove(bgp, as);
1800 }
1801 return CMD_SUCCESS;
1802 }
1803
1804 /**
1805 * Central routine for maximum-paths configuration.
1806 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1807 * @set: 1 for setting values, 0 for removing the max-paths config.
1808 */
1809 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1810 const char *mpaths, uint16_t options,
1811 int set)
1812 {
1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 uint16_t maxpaths = 0;
1815 int ret;
1816 afi_t afi;
1817 safi_t safi;
1818
1819 afi = bgp_node_afi(vty);
1820 safi = bgp_node_safi(vty);
1821
1822 if (set) {
1823 maxpaths = strtol(mpaths, NULL, 10);
1824 if (maxpaths > multipath_num) {
1825 vty_out(vty,
1826 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1827 maxpaths, multipath_num);
1828 return CMD_WARNING_CONFIG_FAILED;
1829 }
1830 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1831 options);
1832 } else
1833 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1834
1835 if (ret < 0) {
1836 vty_out(vty,
1837 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1838 (set == 1) ? "" : "un",
1839 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1840 maxpaths, afi, safi);
1841 return CMD_WARNING_CONFIG_FAILED;
1842 }
1843
1844 bgp_recalculate_all_bestpaths(bgp);
1845
1846 return CMD_SUCCESS;
1847 }
1848
1849 DEFUN (bgp_maxmed_admin,
1850 bgp_maxmed_admin_cmd,
1851 "bgp max-med administrative ",
1852 BGP_STR
1853 "Advertise routes with max-med\n"
1854 "Administratively applied, for an indefinite period\n")
1855 {
1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857
1858 bgp->v_maxmed_admin = 1;
1859 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1860
1861 bgp_maxmed_update(bgp);
1862
1863 return CMD_SUCCESS;
1864 }
1865
1866 DEFUN (bgp_maxmed_admin_medv,
1867 bgp_maxmed_admin_medv_cmd,
1868 "bgp max-med administrative (0-4294967295)",
1869 BGP_STR
1870 "Advertise routes with max-med\n"
1871 "Administratively applied, for an indefinite period\n"
1872 "Max MED value to be used\n")
1873 {
1874 VTY_DECLVAR_CONTEXT(bgp, bgp);
1875 int idx_number = 3;
1876
1877 bgp->v_maxmed_admin = 1;
1878 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1879
1880 bgp_maxmed_update(bgp);
1881
1882 return CMD_SUCCESS;
1883 }
1884
1885 DEFUN (no_bgp_maxmed_admin,
1886 no_bgp_maxmed_admin_cmd,
1887 "no bgp max-med administrative [(0-4294967295)]",
1888 NO_STR
1889 BGP_STR
1890 "Advertise routes with max-med\n"
1891 "Administratively applied, for an indefinite period\n"
1892 "Max MED value to be used\n")
1893 {
1894 VTY_DECLVAR_CONTEXT(bgp, bgp);
1895 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1896 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1897 bgp_maxmed_update(bgp);
1898
1899 return CMD_SUCCESS;
1900 }
1901
1902 DEFUN (bgp_maxmed_onstartup,
1903 bgp_maxmed_onstartup_cmd,
1904 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1905 BGP_STR
1906 "Advertise routes with max-med\n"
1907 "Effective on a startup\n"
1908 "Time (seconds) period for max-med\n"
1909 "Max MED value to be used\n")
1910 {
1911 VTY_DECLVAR_CONTEXT(bgp, bgp);
1912 int idx = 0;
1913
1914 argv_find(argv, argc, "(5-86400)", &idx);
1915 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1916 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1917 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1918 else
1919 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1920
1921 bgp_maxmed_update(bgp);
1922
1923 return CMD_SUCCESS;
1924 }
1925
1926 DEFUN (no_bgp_maxmed_onstartup,
1927 no_bgp_maxmed_onstartup_cmd,
1928 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1929 NO_STR
1930 BGP_STR
1931 "Advertise routes with max-med\n"
1932 "Effective on a startup\n"
1933 "Time (seconds) period for max-med\n"
1934 "Max MED value to be used\n")
1935 {
1936 VTY_DECLVAR_CONTEXT(bgp, bgp);
1937
1938 /* Cancel max-med onstartup if its on */
1939 if (bgp->t_maxmed_onstartup) {
1940 thread_cancel(&bgp->t_maxmed_onstartup);
1941 bgp->maxmed_onstartup_over = 1;
1942 }
1943
1944 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1945 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1946
1947 bgp_maxmed_update(bgp);
1948
1949 return CMD_SUCCESS;
1950 }
1951
1952 static int bgp_global_update_delay_config_vty(struct vty *vty,
1953 uint16_t update_delay,
1954 uint16_t establish_wait)
1955 {
1956 struct listnode *node, *nnode;
1957 struct bgp *bgp;
1958 bool vrf_cfg = false;
1959
1960 /*
1961 * See if update-delay is set per-vrf and warn user to delete it
1962 * Note that we only need to check this if this is the first time
1963 * setting the global config.
1964 */
1965 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1966 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1967 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1968 vty_out(vty,
1969 "%% update-delay configuration found in vrf %s\n",
1970 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1971 ? VRF_DEFAULT_NAME
1972 : bgp->name);
1973 vrf_cfg = true;
1974 }
1975 }
1976 }
1977
1978 if (vrf_cfg) {
1979 vty_out(vty,
1980 "%%Failed: global update-delay config not permitted\n");
1981 return CMD_WARNING;
1982 }
1983
1984 if (!establish_wait) { /* update-delay <delay> */
1985 bm->v_update_delay = update_delay;
1986 bm->v_establish_wait = bm->v_update_delay;
1987 } else {
1988 /* update-delay <delay> <establish-wait> */
1989 if (update_delay < establish_wait) {
1990 vty_out(vty,
1991 "%%Failed: update-delay less than the establish-wait!\n");
1992 return CMD_WARNING_CONFIG_FAILED;
1993 }
1994
1995 bm->v_update_delay = update_delay;
1996 bm->v_establish_wait = establish_wait;
1997 }
1998
1999 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2000 bgp->v_update_delay = bm->v_update_delay;
2001 bgp->v_establish_wait = bm->v_establish_wait;
2002 }
2003
2004 return CMD_SUCCESS;
2005 }
2006
2007 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2008 {
2009 struct listnode *node, *nnode;
2010 struct bgp *bgp;
2011
2012 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2013 bm->v_establish_wait = bm->v_update_delay;
2014
2015 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2016 bgp->v_update_delay = bm->v_update_delay;
2017 bgp->v_establish_wait = bm->v_establish_wait;
2018 }
2019
2020 return CMD_SUCCESS;
2021 }
2022
2023 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2024 uint16_t establish_wait)
2025 {
2026 VTY_DECLVAR_CONTEXT(bgp, bgp);
2027
2028 /* if configured globally, per-instance config is not allowed */
2029 if (bm->v_update_delay) {
2030 vty_out(vty,
2031 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2032 return CMD_WARNING_CONFIG_FAILED;
2033 }
2034
2035
2036 if (!establish_wait) /* update-delay <delay> */
2037 {
2038 bgp->v_update_delay = update_delay;
2039 bgp->v_establish_wait = bgp->v_update_delay;
2040 return CMD_SUCCESS;
2041 }
2042
2043 /* update-delay <delay> <establish-wait> */
2044 if (update_delay < establish_wait) {
2045 vty_out(vty,
2046 "%%Failed: update-delay less than the establish-wait!\n");
2047 return CMD_WARNING_CONFIG_FAILED;
2048 }
2049
2050 bgp->v_update_delay = update_delay;
2051 bgp->v_establish_wait = establish_wait;
2052
2053 return CMD_SUCCESS;
2054 }
2055
2056 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2057 {
2058 VTY_DECLVAR_CONTEXT(bgp, bgp);
2059
2060 /* If configured globally, cannot remove from one bgp instance */
2061 if (bm->v_update_delay) {
2062 vty_out(vty,
2063 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2064 return CMD_WARNING_CONFIG_FAILED;
2065 }
2066 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2067 bgp->v_establish_wait = bgp->v_update_delay;
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2073 {
2074 /* If configured globally, no need to display per-instance value */
2075 if (bgp->v_update_delay != bm->v_update_delay) {
2076 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2077 if (bgp->v_update_delay != bgp->v_establish_wait)
2078 vty_out(vty, " %d", bgp->v_establish_wait);
2079 vty_out(vty, "\n");
2080 }
2081 }
2082
2083 /* Global update-delay configuration */
2084 DEFPY (bgp_global_update_delay,
2085 bgp_global_update_delay_cmd,
2086 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2087 BGP_STR
2088 "Force initial delay for best-path and updates for all bgp instances\n"
2089 "Max delay in seconds\n"
2090 "Establish wait in seconds\n")
2091 {
2092 return bgp_global_update_delay_config_vty(vty, delay, wait);
2093 }
2094
2095 /* Global update-delay deconfiguration */
2096 DEFPY (no_bgp_global_update_delay,
2097 no_bgp_global_update_delay_cmd,
2098 "no bgp update-delay [(0-3600) [(1-3600)]]",
2099 NO_STR
2100 BGP_STR
2101 "Force initial delay for best-path and updates\n"
2102 "Max delay in seconds\n"
2103 "Establish wait in seconds\n")
2104 {
2105 return bgp_global_update_delay_deconfig_vty(vty);
2106 }
2107
2108 /* Update-delay configuration */
2109
2110 DEFPY (bgp_update_delay,
2111 bgp_update_delay_cmd,
2112 "update-delay (0-3600)$delay [(1-3600)$wait]",
2113 "Force initial delay for best-path and updates\n"
2114 "Max delay in seconds\n"
2115 "Establish wait in seconds\n")
2116 {
2117 return bgp_update_delay_config_vty(vty, delay, wait);
2118 }
2119
2120 /* Update-delay deconfiguration */
2121 DEFPY (no_bgp_update_delay,
2122 no_bgp_update_delay_cmd,
2123 "no update-delay [(0-3600) [(1-3600)]]",
2124 NO_STR
2125 "Force initial delay for best-path and updates\n"
2126 "Max delay in seconds\n"
2127 "Establish wait in seconds\n")
2128 {
2129 return bgp_update_delay_deconfig_vty(vty);
2130 }
2131
2132
2133 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2134 bool set)
2135 {
2136 VTY_DECLVAR_CONTEXT(bgp, bgp);
2137
2138 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2139 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2140
2141 return CMD_SUCCESS;
2142 }
2143
2144 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2145 bool set)
2146 {
2147 VTY_DECLVAR_CONTEXT(bgp, bgp);
2148
2149 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2150 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2151
2152 return CMD_SUCCESS;
2153 }
2154
2155 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2156 {
2157 uint32_t quanta =
2158 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2159 if (quanta != BGP_WRITE_PACKET_MAX)
2160 vty_out(vty, " write-quanta %d\n", quanta);
2161 }
2162
2163 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2164 {
2165 uint32_t quanta =
2166 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2167 if (quanta != BGP_READ_PACKET_MAX)
2168 vty_out(vty, " read-quanta %d\n", quanta);
2169 }
2170
2171 /* Packet quanta configuration
2172 *
2173 * XXX: The value set here controls the size of a stack buffer in the IO
2174 * thread. When changing these limits be careful to prevent stack overflow.
2175 *
2176 * Furthermore, the maximums used here should correspond to
2177 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2178 */
2179 DEFPY (bgp_wpkt_quanta,
2180 bgp_wpkt_quanta_cmd,
2181 "[no] write-quanta (1-64)$quanta",
2182 NO_STR
2183 "How many packets to write to peer socket per run\n"
2184 "Number of packets\n")
2185 {
2186 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2187 }
2188
2189 DEFPY (bgp_rpkt_quanta,
2190 bgp_rpkt_quanta_cmd,
2191 "[no] read-quanta (1-10)$quanta",
2192 NO_STR
2193 "How many packets to read from peer socket per I/O cycle\n"
2194 "Number of packets\n")
2195 {
2196 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2197 }
2198
2199 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2200 {
2201 if (!bgp->heuristic_coalesce)
2202 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2203 }
2204
2205
2206 DEFUN (bgp_coalesce_time,
2207 bgp_coalesce_time_cmd,
2208 "coalesce-time (0-4294967295)",
2209 "Subgroup coalesce timer\n"
2210 "Subgroup coalesce timer value (in ms)\n")
2211 {
2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213
2214 int idx = 0;
2215 argv_find(argv, argc, "(0-4294967295)", &idx);
2216 bgp->heuristic_coalesce = false;
2217 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2218 return CMD_SUCCESS;
2219 }
2220
2221 DEFUN (no_bgp_coalesce_time,
2222 no_bgp_coalesce_time_cmd,
2223 "no coalesce-time (0-4294967295)",
2224 NO_STR
2225 "Subgroup coalesce timer\n"
2226 "Subgroup coalesce timer value (in ms)\n")
2227 {
2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229
2230 bgp->heuristic_coalesce = true;
2231 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2232 return CMD_SUCCESS;
2233 }
2234
2235 /* Maximum-paths configuration */
2236 DEFUN (bgp_maxpaths,
2237 bgp_maxpaths_cmd,
2238 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2239 "Forward packets over multiple paths\n"
2240 "Number of paths\n")
2241 {
2242 int idx_number = 1;
2243 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2244 argv[idx_number]->arg, 0, 1);
2245 }
2246
2247 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2248 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2249 "Forward packets over multiple paths\n"
2250 "Number of paths\n")
2251
2252 DEFUN (bgp_maxpaths_ibgp,
2253 bgp_maxpaths_ibgp_cmd,
2254 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2255 "Forward packets over multiple paths\n"
2256 "iBGP-multipath\n"
2257 "Number of paths\n")
2258 {
2259 int idx_number = 2;
2260 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2261 argv[idx_number]->arg, 0, 1);
2262 }
2263
2264 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2265 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2266 "Forward packets over multiple paths\n"
2267 "iBGP-multipath\n"
2268 "Number of paths\n")
2269
2270 DEFUN (bgp_maxpaths_ibgp_cluster,
2271 bgp_maxpaths_ibgp_cluster_cmd,
2272 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2273 "Forward packets over multiple paths\n"
2274 "iBGP-multipath\n"
2275 "Number of paths\n"
2276 "Match the cluster length\n")
2277 {
2278 int idx_number = 2;
2279 return bgp_maxpaths_config_vty(
2280 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2281 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
2282 }
2283
2284 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2285 "maximum-paths ibgp " CMD_RANGE_STR(
2286 1, MULTIPATH_NUM) " equal-cluster-length",
2287 "Forward packets over multiple paths\n"
2288 "iBGP-multipath\n"
2289 "Number of paths\n"
2290 "Match the cluster length\n")
2291
2292 DEFUN (no_bgp_maxpaths,
2293 no_bgp_maxpaths_cmd,
2294 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2295 NO_STR
2296 "Forward packets over multiple paths\n"
2297 "Number of paths\n")
2298 {
2299 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2300 }
2301
2302 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2303 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2304 "Forward packets over multiple paths\n"
2305 "Number of paths\n")
2306
2307 DEFUN (no_bgp_maxpaths_ibgp,
2308 no_bgp_maxpaths_ibgp_cmd,
2309 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2310 NO_STR
2311 "Forward packets over multiple paths\n"
2312 "iBGP-multipath\n"
2313 "Number of paths\n"
2314 "Match the cluster length\n")
2315 {
2316 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2317 }
2318
2319 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2320 "no maximum-paths ibgp [" CMD_RANGE_STR(
2321 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2322 NO_STR
2323 "Forward packets over multiple paths\n"
2324 "iBGP-multipath\n"
2325 "Number of paths\n"
2326 "Match the cluster length\n")
2327
2328 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2329 afi_t afi, safi_t safi)
2330 {
2331 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2332 vty_out(vty, " maximum-paths %d\n",
2333 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2334 }
2335
2336 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2337 vty_out(vty, " maximum-paths ibgp %d",
2338 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2339 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2340 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2341 vty_out(vty, " equal-cluster-length");
2342 vty_out(vty, "\n");
2343 }
2344 }
2345
2346 /* BGP timers. */
2347
2348 DEFUN (bgp_timers,
2349 bgp_timers_cmd,
2350 "timers bgp (0-65535) (0-65535)",
2351 "Adjust routing timers\n"
2352 "BGP timers\n"
2353 "Keepalive interval\n"
2354 "Holdtime\n")
2355 {
2356 VTY_DECLVAR_CONTEXT(bgp, bgp);
2357 int idx_number = 2;
2358 int idx_number_2 = 3;
2359 unsigned long keepalive = 0;
2360 unsigned long holdtime = 0;
2361
2362 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2363 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2364
2365 /* Holdtime value check. */
2366 if (holdtime < 3 && holdtime != 0) {
2367 vty_out(vty,
2368 "%% hold time value must be either 0 or greater than 3\n");
2369 return CMD_WARNING_CONFIG_FAILED;
2370 }
2371
2372 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2373 BGP_DEFAULT_DELAYOPEN);
2374
2375 return CMD_SUCCESS;
2376 }
2377
2378 DEFUN (no_bgp_timers,
2379 no_bgp_timers_cmd,
2380 "no timers bgp [(0-65535) (0-65535)]",
2381 NO_STR
2382 "Adjust routing timers\n"
2383 "BGP timers\n"
2384 "Keepalive interval\n"
2385 "Holdtime\n")
2386 {
2387 VTY_DECLVAR_CONTEXT(bgp, bgp);
2388 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2389 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2390
2391 return CMD_SUCCESS;
2392 }
2393
2394 /* BGP minimum holdtime. */
2395
2396 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2397 "bgp minimum-holdtime (1-65535)",
2398 "BGP specific commands\n"
2399 "BGP minimum holdtime\n"
2400 "Seconds\n")
2401 {
2402 VTY_DECLVAR_CONTEXT(bgp, bgp);
2403 int idx_number = 2;
2404 unsigned long min_holdtime;
2405
2406 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2407
2408 bgp->default_min_holdtime = min_holdtime;
2409
2410 return CMD_SUCCESS;
2411 }
2412
2413 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2414 "no bgp minimum-holdtime [(1-65535)]",
2415 NO_STR
2416 "BGP specific commands\n"
2417 "BGP minimum holdtime\n"
2418 "Seconds\n")
2419 {
2420 VTY_DECLVAR_CONTEXT(bgp, bgp);
2421
2422 bgp->default_min_holdtime = 0;
2423
2424 return CMD_SUCCESS;
2425 }
2426
2427 DEFUN (bgp_client_to_client_reflection,
2428 bgp_client_to_client_reflection_cmd,
2429 "bgp client-to-client reflection",
2430 BGP_STR
2431 "Configure client to client route reflection\n"
2432 "reflection of routes allowed\n")
2433 {
2434 VTY_DECLVAR_CONTEXT(bgp, bgp);
2435 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2436 bgp_clear_star_soft_out(vty, bgp->name);
2437
2438 return CMD_SUCCESS;
2439 }
2440
2441 DEFUN (no_bgp_client_to_client_reflection,
2442 no_bgp_client_to_client_reflection_cmd,
2443 "no bgp client-to-client reflection",
2444 NO_STR
2445 BGP_STR
2446 "Configure client to client route reflection\n"
2447 "reflection of routes allowed\n")
2448 {
2449 VTY_DECLVAR_CONTEXT(bgp, bgp);
2450 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2451 bgp_clear_star_soft_out(vty, bgp->name);
2452
2453 return CMD_SUCCESS;
2454 }
2455
2456 /* "bgp always-compare-med" configuration. */
2457 DEFUN (bgp_always_compare_med,
2458 bgp_always_compare_med_cmd,
2459 "bgp always-compare-med",
2460 BGP_STR
2461 "Allow comparing MED from different neighbors\n")
2462 {
2463 VTY_DECLVAR_CONTEXT(bgp, bgp);
2464 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2465 bgp_recalculate_all_bestpaths(bgp);
2466
2467 return CMD_SUCCESS;
2468 }
2469
2470 DEFUN (no_bgp_always_compare_med,
2471 no_bgp_always_compare_med_cmd,
2472 "no bgp always-compare-med",
2473 NO_STR
2474 BGP_STR
2475 "Allow comparing MED from different neighbors\n")
2476 {
2477 VTY_DECLVAR_CONTEXT(bgp, bgp);
2478 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2479 bgp_recalculate_all_bestpaths(bgp);
2480
2481 return CMD_SUCCESS;
2482 }
2483
2484
2485 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2486 "bgp ebgp-requires-policy",
2487 BGP_STR
2488 "Require in and out policy for eBGP peers (RFC8212)\n")
2489 {
2490 VTY_DECLVAR_CONTEXT(bgp, bgp);
2491 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2492 return CMD_SUCCESS;
2493 }
2494
2495 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2496 "no bgp ebgp-requires-policy",
2497 NO_STR
2498 BGP_STR
2499 "Require in and out policy for eBGP peers (RFC8212)\n")
2500 {
2501 VTY_DECLVAR_CONTEXT(bgp, bgp);
2502 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2503 return CMD_SUCCESS;
2504 }
2505
2506 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2507 "bgp suppress-duplicates",
2508 BGP_STR
2509 "Suppress duplicate updates if the route actually not changed\n")
2510 {
2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2513 return CMD_SUCCESS;
2514 }
2515
2516 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2517 "no bgp suppress-duplicates",
2518 NO_STR
2519 BGP_STR
2520 "Suppress duplicate updates if the route actually not changed\n")
2521 {
2522 VTY_DECLVAR_CONTEXT(bgp, bgp);
2523 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2524 return CMD_SUCCESS;
2525 }
2526
2527 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2528 "bgp reject-as-sets",
2529 BGP_STR
2530 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2531 {
2532 VTY_DECLVAR_CONTEXT(bgp, bgp);
2533 struct listnode *node, *nnode;
2534 struct peer *peer;
2535
2536 bgp->reject_as_sets = true;
2537
2538 /* Reset existing BGP sessions to reject routes
2539 * with aspath containing AS_SET or AS_CONFED_SET.
2540 */
2541 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2542 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2543 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2544 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2545 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2546 }
2547 }
2548
2549 return CMD_SUCCESS;
2550 }
2551
2552 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2553 "no bgp reject-as-sets",
2554 NO_STR
2555 BGP_STR
2556 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2557 {
2558 VTY_DECLVAR_CONTEXT(bgp, bgp);
2559 struct listnode *node, *nnode;
2560 struct peer *peer;
2561
2562 bgp->reject_as_sets = false;
2563
2564 /* Reset existing BGP sessions to reject routes
2565 * with aspath containing AS_SET or AS_CONFED_SET.
2566 */
2567 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2568 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2569 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2570 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2571 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2572 }
2573 }
2574
2575 return CMD_SUCCESS;
2576 }
2577
2578 /* "bgp deterministic-med" configuration. */
2579 DEFUN (bgp_deterministic_med,
2580 bgp_deterministic_med_cmd,
2581 "bgp deterministic-med",
2582 BGP_STR
2583 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2584 {
2585 VTY_DECLVAR_CONTEXT(bgp, bgp);
2586
2587 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2588 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2589 bgp_recalculate_all_bestpaths(bgp);
2590 }
2591
2592 return CMD_SUCCESS;
2593 }
2594
2595 DEFUN (no_bgp_deterministic_med,
2596 no_bgp_deterministic_med_cmd,
2597 "no bgp deterministic-med",
2598 NO_STR
2599 BGP_STR
2600 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2601 {
2602 VTY_DECLVAR_CONTEXT(bgp, bgp);
2603 int bestpath_per_as_used;
2604 afi_t afi;
2605 safi_t safi;
2606 struct peer *peer;
2607 struct listnode *node, *nnode;
2608
2609 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2610 bestpath_per_as_used = 0;
2611
2612 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2613 FOREACH_AFI_SAFI (afi, safi)
2614 if (bgp_addpath_dmed_required(
2615 peer->addpath_type[afi][safi])) {
2616 bestpath_per_as_used = 1;
2617 break;
2618 }
2619
2620 if (bestpath_per_as_used)
2621 break;
2622 }
2623
2624 if (bestpath_per_as_used) {
2625 vty_out(vty,
2626 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2627 return CMD_WARNING_CONFIG_FAILED;
2628 } else {
2629 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2630 bgp_recalculate_all_bestpaths(bgp);
2631 }
2632 }
2633
2634 return CMD_SUCCESS;
2635 }
2636
2637 /* "bgp graceful-restart mode" configuration. */
2638 DEFUN (bgp_graceful_restart,
2639 bgp_graceful_restart_cmd,
2640 "bgp graceful-restart",
2641 BGP_STR
2642 GR_CMD
2643 )
2644 {
2645 int ret = BGP_GR_FAILURE;
2646
2647 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2648 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2649
2650 VTY_DECLVAR_CONTEXT(bgp, bgp);
2651
2652 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2653
2654 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2655 ret);
2656
2657 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2658 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2659 vty_out(vty,
2660 "Graceful restart configuration changed, reset all peers to take effect\n");
2661 return bgp_vty_return(vty, ret);
2662 }
2663
2664 DEFUN (no_bgp_graceful_restart,
2665 no_bgp_graceful_restart_cmd,
2666 "no bgp graceful-restart",
2667 NO_STR
2668 BGP_STR
2669 NO_GR_CMD
2670 )
2671 {
2672 VTY_DECLVAR_CONTEXT(bgp, bgp);
2673
2674 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2675 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2676
2677 int ret = BGP_GR_FAILURE;
2678
2679 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2680
2681 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2682 ret);
2683
2684 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2685 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2686 vty_out(vty,
2687 "Graceful restart configuration changed, reset all peers to take effect\n");
2688
2689 return bgp_vty_return(vty, ret);
2690 }
2691
2692 DEFUN (bgp_graceful_restart_stalepath_time,
2693 bgp_graceful_restart_stalepath_time_cmd,
2694 "bgp graceful-restart stalepath-time (1-4095)",
2695 BGP_STR
2696 "Graceful restart capability parameters\n"
2697 "Set the max time to hold onto restarting peer's stale paths\n"
2698 "Delay value (seconds)\n")
2699 {
2700 VTY_DECLVAR_CONTEXT(bgp, bgp);
2701 int idx_number = 3;
2702 uint32_t stalepath;
2703
2704 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2705 bgp->stalepath_time = stalepath;
2706 return CMD_SUCCESS;
2707 }
2708
2709 DEFUN (bgp_graceful_restart_restart_time,
2710 bgp_graceful_restart_restart_time_cmd,
2711 "bgp graceful-restart restart-time (0-4095)",
2712 BGP_STR
2713 "Graceful restart capability parameters\n"
2714 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2715 "Delay value (seconds)\n")
2716 {
2717 VTY_DECLVAR_CONTEXT(bgp, bgp);
2718 int idx_number = 3;
2719 uint32_t restart;
2720
2721 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2722 bgp->restart_time = restart;
2723 return CMD_SUCCESS;
2724 }
2725
2726 DEFUN (bgp_graceful_restart_select_defer_time,
2727 bgp_graceful_restart_select_defer_time_cmd,
2728 "bgp graceful-restart select-defer-time (0-3600)",
2729 BGP_STR
2730 "Graceful restart capability parameters\n"
2731 "Set the time to defer the BGP route selection after restart\n"
2732 "Delay value (seconds, 0 - disable)\n")
2733 {
2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
2735 int idx_number = 3;
2736 uint32_t defer_time;
2737
2738 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2739 bgp->select_defer_time = defer_time;
2740 if (defer_time == 0)
2741 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2742 else
2743 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2744
2745 return CMD_SUCCESS;
2746 }
2747
2748 DEFUN (no_bgp_graceful_restart_stalepath_time,
2749 no_bgp_graceful_restart_stalepath_time_cmd,
2750 "no bgp graceful-restart stalepath-time [(1-4095)]",
2751 NO_STR
2752 BGP_STR
2753 "Graceful restart capability parameters\n"
2754 "Set the max time to hold onto restarting peer's stale paths\n"
2755 "Delay value (seconds)\n")
2756 {
2757 VTY_DECLVAR_CONTEXT(bgp, bgp);
2758
2759 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2760 return CMD_SUCCESS;
2761 }
2762
2763 DEFUN (no_bgp_graceful_restart_restart_time,
2764 no_bgp_graceful_restart_restart_time_cmd,
2765 "no bgp graceful-restart restart-time [(0-4095)]",
2766 NO_STR
2767 BGP_STR
2768 "Graceful restart capability parameters\n"
2769 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2770 "Delay value (seconds)\n")
2771 {
2772 VTY_DECLVAR_CONTEXT(bgp, bgp);
2773
2774 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2775 return CMD_SUCCESS;
2776 }
2777
2778 DEFUN (no_bgp_graceful_restart_select_defer_time,
2779 no_bgp_graceful_restart_select_defer_time_cmd,
2780 "no bgp graceful-restart select-defer-time [(0-3600)]",
2781 NO_STR
2782 BGP_STR
2783 "Graceful restart capability parameters\n"
2784 "Set the time to defer the BGP route selection after restart\n"
2785 "Delay value (seconds)\n")
2786 {
2787 VTY_DECLVAR_CONTEXT(bgp, bgp);
2788
2789 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2790 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2791
2792 return CMD_SUCCESS;
2793 }
2794
2795 DEFUN (bgp_graceful_restart_preserve_fw,
2796 bgp_graceful_restart_preserve_fw_cmd,
2797 "bgp graceful-restart preserve-fw-state",
2798 BGP_STR
2799 "Graceful restart capability parameters\n"
2800 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2801 {
2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2804 return CMD_SUCCESS;
2805 }
2806
2807 DEFUN (no_bgp_graceful_restart_preserve_fw,
2808 no_bgp_graceful_restart_preserve_fw_cmd,
2809 "no bgp graceful-restart preserve-fw-state",
2810 NO_STR
2811 BGP_STR
2812 "Graceful restart capability parameters\n"
2813 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2814 {
2815 VTY_DECLVAR_CONTEXT(bgp, bgp);
2816 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2817 return CMD_SUCCESS;
2818 }
2819
2820 DEFUN (bgp_graceful_restart_disable,
2821 bgp_graceful_restart_disable_cmd,
2822 "bgp graceful-restart-disable",
2823 BGP_STR
2824 GR_DISABLE)
2825 {
2826 int ret = BGP_GR_FAILURE;
2827
2828 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2829 zlog_debug(
2830 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2831
2832 VTY_DECLVAR_CONTEXT(bgp, bgp);
2833
2834 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2835
2836 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2837 bgp->peer, ret);
2838
2839 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2840 zlog_debug(
2841 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2842 vty_out(vty,
2843 "Graceful restart configuration changed, reset all peers to take effect\n");
2844
2845 return bgp_vty_return(vty, ret);
2846 }
2847
2848 DEFUN (no_bgp_graceful_restart_disable,
2849 no_bgp_graceful_restart_disable_cmd,
2850 "no bgp graceful-restart-disable",
2851 NO_STR
2852 BGP_STR
2853 NO_GR_DISABLE
2854 )
2855 {
2856 VTY_DECLVAR_CONTEXT(bgp, bgp);
2857
2858 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2859 zlog_debug(
2860 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2861
2862 int ret = BGP_GR_FAILURE;
2863
2864 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2865
2866 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2867 ret);
2868
2869 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2870 zlog_debug(
2871 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2872 vty_out(vty,
2873 "Graceful restart configuration changed, reset all peers to take effect\n");
2874
2875 return bgp_vty_return(vty, ret);
2876 }
2877
2878 DEFUN (bgp_neighbor_graceful_restart_set,
2879 bgp_neighbor_graceful_restart_set_cmd,
2880 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2881 NEIGHBOR_STR
2882 NEIGHBOR_ADDR_STR2
2883 GR_NEIGHBOR_CMD
2884 )
2885 {
2886 int idx_peer = 1;
2887 struct peer *peer;
2888 int ret = BGP_GR_FAILURE;
2889
2890 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2891
2892 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2893 zlog_debug(
2894 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2895
2896 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2897 if (!peer)
2898 return CMD_WARNING_CONFIG_FAILED;
2899
2900 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2901
2902 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2903 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2904
2905 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2906 zlog_debug(
2907 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2908 vty_out(vty,
2909 "Graceful restart configuration changed, reset this peer to take effect\n");
2910
2911 return bgp_vty_return(vty, ret);
2912 }
2913
2914 DEFUN (no_bgp_neighbor_graceful_restart,
2915 no_bgp_neighbor_graceful_restart_set_cmd,
2916 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2917 NO_STR
2918 NEIGHBOR_STR
2919 NEIGHBOR_ADDR_STR2
2920 NO_GR_NEIGHBOR_CMD
2921 )
2922 {
2923 int idx_peer = 2;
2924 int ret = BGP_GR_FAILURE;
2925 struct peer *peer;
2926
2927 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2928
2929 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2930 if (!peer)
2931 return CMD_WARNING_CONFIG_FAILED;
2932
2933 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2934 zlog_debug(
2935 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
2936
2937 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2938
2939 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2940 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2941
2942 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2943 zlog_debug(
2944 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
2945 vty_out(vty,
2946 "Graceful restart configuration changed, reset this peer to take effect\n");
2947
2948 return bgp_vty_return(vty, ret);
2949 }
2950
2951 DEFUN (bgp_neighbor_graceful_restart_helper_set,
2952 bgp_neighbor_graceful_restart_helper_set_cmd,
2953 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2954 NEIGHBOR_STR
2955 NEIGHBOR_ADDR_STR2
2956 GR_NEIGHBOR_HELPER_CMD
2957 )
2958 {
2959 int idx_peer = 1;
2960 struct peer *peer;
2961 int ret = BGP_GR_FAILURE;
2962
2963 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2964
2965 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2966 zlog_debug(
2967 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
2968
2969 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2970
2971 if (!peer)
2972 return CMD_WARNING_CONFIG_FAILED;
2973
2974
2975 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
2976
2977 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2978 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2979
2980 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2981 zlog_debug(
2982 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
2983 vty_out(vty,
2984 "Graceful restart configuration changed, reset this peer to take effect\n");
2985
2986 return bgp_vty_return(vty, ret);
2987 }
2988
2989 DEFUN (no_bgp_neighbor_graceful_restart_helper,
2990 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2991 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2992 NO_STR
2993 NEIGHBOR_STR
2994 NEIGHBOR_ADDR_STR2
2995 NO_GR_NEIGHBOR_HELPER_CMD
2996 )
2997 {
2998 int idx_peer = 2;
2999 int ret = BGP_GR_FAILURE;
3000 struct peer *peer;
3001
3002 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3003
3004 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3005 if (!peer)
3006 return CMD_WARNING_CONFIG_FAILED;
3007
3008 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3009 zlog_debug(
3010 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3011
3012 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3013
3014 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3015 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3016
3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
3019 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3020 vty_out(vty,
3021 "Graceful restart configuration changed, reset this peer to take effect\n");
3022
3023 return bgp_vty_return(vty, ret);
3024 }
3025
3026 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3027 bgp_neighbor_graceful_restart_disable_set_cmd,
3028 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3029 NEIGHBOR_STR
3030 NEIGHBOR_ADDR_STR2
3031 GR_NEIGHBOR_DISABLE_CMD
3032 )
3033 {
3034 int idx_peer = 1;
3035 struct peer *peer;
3036 int ret = BGP_GR_FAILURE;
3037
3038 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3039
3040 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3041 zlog_debug(
3042 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3043
3044 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3045 if (!peer)
3046 return CMD_WARNING_CONFIG_FAILED;
3047
3048 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3049
3050 if (peer->bgp->t_startup)
3051 bgp_peer_gr_flags_update(peer);
3052
3053 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3054 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3055
3056 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3057 zlog_debug(
3058 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3059 vty_out(vty,
3060 "Graceful restart configuration changed, reset this peer to take effect\n");
3061
3062 return bgp_vty_return(vty, ret);
3063 }
3064
3065 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3066 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3067 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3068 NO_STR
3069 NEIGHBOR_STR
3070 NEIGHBOR_ADDR_STR2
3071 NO_GR_NEIGHBOR_DISABLE_CMD
3072 )
3073 {
3074 int idx_peer = 2;
3075 int ret = BGP_GR_FAILURE;
3076 struct peer *peer;
3077
3078 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3079
3080 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3081 if (!peer)
3082 return CMD_WARNING_CONFIG_FAILED;
3083
3084 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3085 zlog_debug(
3086 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3087
3088 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3089
3090 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3091 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3092
3093 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3094 zlog_debug(
3095 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3096 vty_out(vty,
3097 "Graceful restart configuration changed, reset this peer to take effect\n");
3098
3099 return bgp_vty_return(vty, ret);
3100 }
3101
3102 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3103 bgp_graceful_restart_disable_eor_cmd,
3104 "bgp graceful-restart disable-eor",
3105 BGP_STR
3106 "Graceful restart configuration parameters\n"
3107 "Disable EOR Check\n")
3108 {
3109 VTY_DECLVAR_CONTEXT(bgp, bgp);
3110 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3111
3112 return CMD_SUCCESS;
3113 }
3114
3115 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3116 no_bgp_graceful_restart_disable_eor_cmd,
3117 "no bgp graceful-restart disable-eor",
3118 NO_STR
3119 BGP_STR
3120 "Graceful restart configuration parameters\n"
3121 "Disable EOR Check\n")
3122 {
3123 VTY_DECLVAR_CONTEXT(bgp, bgp);
3124 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3125
3126 return CMD_SUCCESS;
3127 }
3128
3129 DEFUN (bgp_graceful_restart_rib_stale_time,
3130 bgp_graceful_restart_rib_stale_time_cmd,
3131 "bgp graceful-restart rib-stale-time (1-3600)",
3132 BGP_STR
3133 "Graceful restart configuration parameters\n"
3134 "Specify the stale route removal timer in rib\n"
3135 "Delay value (seconds)\n")
3136 {
3137 VTY_DECLVAR_CONTEXT(bgp, bgp);
3138 int idx_number = 3;
3139 uint32_t stale_time;
3140
3141 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3142 bgp->rib_stale_time = stale_time;
3143 /* Send the stale timer update message to RIB */
3144 if (bgp_zebra_stale_timer_update(bgp))
3145 return CMD_WARNING;
3146
3147 return CMD_SUCCESS;
3148 }
3149
3150 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3151 no_bgp_graceful_restart_rib_stale_time_cmd,
3152 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3153 NO_STR
3154 BGP_STR
3155 "Graceful restart configuration parameters\n"
3156 "Specify the stale route removal timer in rib\n"
3157 "Delay value (seconds)\n")
3158 {
3159 VTY_DECLVAR_CONTEXT(bgp, bgp);
3160
3161 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3162 /* Send the stale timer update message to RIB */
3163 if (bgp_zebra_stale_timer_update(bgp))
3164 return CMD_WARNING;
3165
3166 return CMD_SUCCESS;
3167 }
3168
3169 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3170 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3171 BGP_STR
3172 "Enable Long-lived Graceful Restart\n"
3173 "Specifies maximum time to wait before purging long-lived stale routes\n"
3174 "Stale time value (seconds)\n")
3175 {
3176 VTY_DECLVAR_CONTEXT(bgp, bgp);
3177
3178 uint32_t llgr_stale_time;
3179
3180 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3181 bgp->llgr_stale_time = llgr_stale_time;
3182
3183 return CMD_SUCCESS;
3184 }
3185
3186 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3187 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3188 NO_STR BGP_STR
3189 "Enable Long-lived Graceful Restart\n"
3190 "Specifies maximum time to wait before purging long-lived stale routes\n"
3191 "Stale time value (seconds)\n")
3192 {
3193 VTY_DECLVAR_CONTEXT(bgp, bgp);
3194
3195 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3196
3197 return CMD_SUCCESS;
3198 }
3199
3200 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3201 struct bgp *bgp)
3202 {
3203 bgp_static_redo_import_check(bgp);
3204 bgp_redistribute_redo(bgp);
3205 bgp_clear_star_soft_out(vty, bgp->name);
3206 bgp_clear_star_soft_in(vty, bgp->name);
3207 }
3208
3209 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3210 {
3211 struct listnode *node, *nnode;
3212 struct bgp *bgp;
3213 bool vrf_cfg = false;
3214
3215 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3216 return CMD_SUCCESS;
3217
3218 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3219 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3220 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3221 vty_out(vty,
3222 "%% graceful-shutdown configuration found in vrf %s\n",
3223 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3224 VRF_DEFAULT_NAME : bgp->name);
3225 vrf_cfg = true;
3226 }
3227 }
3228
3229 if (vrf_cfg) {
3230 vty_out(vty,
3231 "%%Failed: global graceful-shutdown not permitted\n");
3232 return CMD_WARNING;
3233 }
3234
3235 /* Set flag globally */
3236 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3237
3238 /* Initiate processing for all BGP instances. */
3239 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3240 bgp_initiate_graceful_shut_unshut(vty, bgp);
3241
3242 return CMD_SUCCESS;
3243 }
3244
3245 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3246 {
3247 struct listnode *node, *nnode;
3248 struct bgp *bgp;
3249
3250 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3251 return CMD_SUCCESS;
3252
3253 /* Unset flag globally */
3254 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3255
3256 /* Initiate processing for all BGP instances. */
3257 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3258 bgp_initiate_graceful_shut_unshut(vty, bgp);
3259
3260 return CMD_SUCCESS;
3261 }
3262
3263 /* "bgp graceful-shutdown" configuration */
3264 DEFUN (bgp_graceful_shutdown,
3265 bgp_graceful_shutdown_cmd,
3266 "bgp graceful-shutdown",
3267 BGP_STR
3268 "Graceful shutdown parameters\n")
3269 {
3270 if (vty->node == CONFIG_NODE)
3271 return bgp_global_graceful_shutdown_config_vty(vty);
3272
3273 VTY_DECLVAR_CONTEXT(bgp, bgp);
3274
3275 /* if configured globally, per-instance config is not allowed */
3276 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3277 vty_out(vty,
3278 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3279 return CMD_WARNING_CONFIG_FAILED;
3280 }
3281
3282 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3283 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3284 bgp_initiate_graceful_shut_unshut(vty, bgp);
3285 }
3286
3287 return CMD_SUCCESS;
3288 }
3289
3290 DEFUN (no_bgp_graceful_shutdown,
3291 no_bgp_graceful_shutdown_cmd,
3292 "no bgp graceful-shutdown",
3293 NO_STR
3294 BGP_STR
3295 "Graceful shutdown parameters\n")
3296 {
3297 if (vty->node == CONFIG_NODE)
3298 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3299
3300 VTY_DECLVAR_CONTEXT(bgp, bgp);
3301
3302 /* If configured globally, cannot remove from one bgp instance */
3303 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3304 vty_out(vty,
3305 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3306 return CMD_WARNING_CONFIG_FAILED;
3307 }
3308
3309 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3310 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3311 bgp_initiate_graceful_shut_unshut(vty, bgp);
3312 }
3313
3314 return CMD_SUCCESS;
3315 }
3316
3317 /* "bgp fast-external-failover" configuration. */
3318 DEFUN (bgp_fast_external_failover,
3319 bgp_fast_external_failover_cmd,
3320 "bgp fast-external-failover",
3321 BGP_STR
3322 "Immediately reset session if a link to a directly connected external peer goes down\n")
3323 {
3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
3325 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3326 return CMD_SUCCESS;
3327 }
3328
3329 DEFUN (no_bgp_fast_external_failover,
3330 no_bgp_fast_external_failover_cmd,
3331 "no bgp fast-external-failover",
3332 NO_STR
3333 BGP_STR
3334 "Immediately reset session if a link to a directly connected external peer goes down\n")
3335 {
3336 VTY_DECLVAR_CONTEXT(bgp, bgp);
3337 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3338 return CMD_SUCCESS;
3339 }
3340
3341 /* "bgp bestpath compare-routerid" configuration. */
3342 DEFUN (bgp_bestpath_compare_router_id,
3343 bgp_bestpath_compare_router_id_cmd,
3344 "bgp bestpath compare-routerid",
3345 BGP_STR
3346 "Change the default bestpath selection\n"
3347 "Compare router-id for identical EBGP paths\n")
3348 {
3349 VTY_DECLVAR_CONTEXT(bgp, bgp);
3350 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3351 bgp_recalculate_all_bestpaths(bgp);
3352
3353 return CMD_SUCCESS;
3354 }
3355
3356 DEFUN (no_bgp_bestpath_compare_router_id,
3357 no_bgp_bestpath_compare_router_id_cmd,
3358 "no bgp bestpath compare-routerid",
3359 NO_STR
3360 BGP_STR
3361 "Change the default bestpath selection\n"
3362 "Compare router-id for identical EBGP paths\n")
3363 {
3364 VTY_DECLVAR_CONTEXT(bgp, bgp);
3365 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3366 bgp_recalculate_all_bestpaths(bgp);
3367
3368 return CMD_SUCCESS;
3369 }
3370
3371 /* "bgp bestpath as-path ignore" configuration. */
3372 DEFUN (bgp_bestpath_aspath_ignore,
3373 bgp_bestpath_aspath_ignore_cmd,
3374 "bgp bestpath as-path ignore",
3375 BGP_STR
3376 "Change the default bestpath selection\n"
3377 "AS-path attribute\n"
3378 "Ignore as-path length in selecting a route\n")
3379 {
3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3382 bgp_recalculate_all_bestpaths(bgp);
3383
3384 return CMD_SUCCESS;
3385 }
3386
3387 DEFUN (no_bgp_bestpath_aspath_ignore,
3388 no_bgp_bestpath_aspath_ignore_cmd,
3389 "no bgp bestpath as-path ignore",
3390 NO_STR
3391 BGP_STR
3392 "Change the default bestpath selection\n"
3393 "AS-path attribute\n"
3394 "Ignore as-path length in selecting a route\n")
3395 {
3396 VTY_DECLVAR_CONTEXT(bgp, bgp);
3397 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3398 bgp_recalculate_all_bestpaths(bgp);
3399
3400 return CMD_SUCCESS;
3401 }
3402
3403 /* "bgp bestpath as-path confed" configuration. */
3404 DEFUN (bgp_bestpath_aspath_confed,
3405 bgp_bestpath_aspath_confed_cmd,
3406 "bgp bestpath as-path confed",
3407 BGP_STR
3408 "Change the default bestpath selection\n"
3409 "AS-path attribute\n"
3410 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3411 {
3412 VTY_DECLVAR_CONTEXT(bgp, bgp);
3413 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3414 bgp_recalculate_all_bestpaths(bgp);
3415
3416 return CMD_SUCCESS;
3417 }
3418
3419 DEFUN (no_bgp_bestpath_aspath_confed,
3420 no_bgp_bestpath_aspath_confed_cmd,
3421 "no bgp bestpath as-path confed",
3422 NO_STR
3423 BGP_STR
3424 "Change the default bestpath selection\n"
3425 "AS-path attribute\n"
3426 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3427 {
3428 VTY_DECLVAR_CONTEXT(bgp, bgp);
3429 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3430 bgp_recalculate_all_bestpaths(bgp);
3431
3432 return CMD_SUCCESS;
3433 }
3434
3435 /* "bgp bestpath as-path multipath-relax" configuration. */
3436 DEFUN (bgp_bestpath_aspath_multipath_relax,
3437 bgp_bestpath_aspath_multipath_relax_cmd,
3438 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3439 BGP_STR
3440 "Change the default bestpath selection\n"
3441 "AS-path attribute\n"
3442 "Allow load sharing across routes that have different AS paths (but same length)\n"
3443 "Generate an AS_SET\n"
3444 "Do not generate an AS_SET\n")
3445 {
3446 VTY_DECLVAR_CONTEXT(bgp, bgp);
3447 int idx = 0;
3448 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3449
3450 /* no-as-set is now the default behavior so we can silently
3451 * ignore it */
3452 if (argv_find(argv, argc, "as-set", &idx))
3453 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3454 else
3455 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3456
3457 bgp_recalculate_all_bestpaths(bgp);
3458
3459 return CMD_SUCCESS;
3460 }
3461
3462 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3463 no_bgp_bestpath_aspath_multipath_relax_cmd,
3464 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3465 NO_STR
3466 BGP_STR
3467 "Change the default bestpath selection\n"
3468 "AS-path attribute\n"
3469 "Allow load sharing across routes that have different AS paths (but same length)\n"
3470 "Generate an AS_SET\n"
3471 "Do not generate an AS_SET\n")
3472 {
3473 VTY_DECLVAR_CONTEXT(bgp, bgp);
3474 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3475 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3476 bgp_recalculate_all_bestpaths(bgp);
3477
3478 return CMD_SUCCESS;
3479 }
3480
3481 /* "bgp bestpath peer-type multipath-relax" configuration. */
3482 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3483 bgp_bestpath_peer_type_multipath_relax_cmd,
3484 "bgp bestpath peer-type multipath-relax",
3485 BGP_STR
3486 "Change the default bestpath selection\n"
3487 "Peer type\n"
3488 "Allow load sharing across routes learned from different peer types\n")
3489 {
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3492 bgp_recalculate_all_bestpaths(bgp);
3493
3494 return CMD_SUCCESS;
3495 }
3496
3497 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3498 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3499 "no bgp bestpath peer-type multipath-relax",
3500 NO_STR BGP_STR
3501 "Change the default bestpath selection\n"
3502 "Peer type\n"
3503 "Allow load sharing across routes learned from different peer types\n")
3504 {
3505 VTY_DECLVAR_CONTEXT(bgp, bgp);
3506 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3507 bgp_recalculate_all_bestpaths(bgp);
3508
3509 return CMD_SUCCESS;
3510 }
3511
3512 /* "bgp log-neighbor-changes" configuration. */
3513 DEFUN (bgp_log_neighbor_changes,
3514 bgp_log_neighbor_changes_cmd,
3515 "bgp log-neighbor-changes",
3516 BGP_STR
3517 "Log neighbor up/down and reset reason\n")
3518 {
3519 VTY_DECLVAR_CONTEXT(bgp, bgp);
3520 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3521 return CMD_SUCCESS;
3522 }
3523
3524 DEFUN (no_bgp_log_neighbor_changes,
3525 no_bgp_log_neighbor_changes_cmd,
3526 "no bgp log-neighbor-changes",
3527 NO_STR
3528 BGP_STR
3529 "Log neighbor up/down and reset reason\n")
3530 {
3531 VTY_DECLVAR_CONTEXT(bgp, bgp);
3532 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3533 return CMD_SUCCESS;
3534 }
3535
3536 /* "bgp bestpath med" configuration. */
3537 DEFUN (bgp_bestpath_med,
3538 bgp_bestpath_med_cmd,
3539 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3540 BGP_STR
3541 "Change the default bestpath selection\n"
3542 "MED attribute\n"
3543 "Compare MED among confederation paths\n"
3544 "Treat missing MED as the least preferred one\n"
3545 "Treat missing MED as the least preferred one\n"
3546 "Compare MED among confederation paths\n")
3547 {
3548 VTY_DECLVAR_CONTEXT(bgp, bgp);
3549
3550 int idx = 0;
3551 if (argv_find(argv, argc, "confed", &idx))
3552 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3553 idx = 0;
3554 if (argv_find(argv, argc, "missing-as-worst", &idx))
3555 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3556
3557 bgp_recalculate_all_bestpaths(bgp);
3558
3559 return CMD_SUCCESS;
3560 }
3561
3562 DEFUN (no_bgp_bestpath_med,
3563 no_bgp_bestpath_med_cmd,
3564 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3565 NO_STR
3566 BGP_STR
3567 "Change the default bestpath selection\n"
3568 "MED attribute\n"
3569 "Compare MED among confederation paths\n"
3570 "Treat missing MED as the least preferred one\n"
3571 "Treat missing MED as the least preferred one\n"
3572 "Compare MED among confederation paths\n")
3573 {
3574 VTY_DECLVAR_CONTEXT(bgp, bgp);
3575
3576 int idx = 0;
3577 if (argv_find(argv, argc, "confed", &idx))
3578 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3579 idx = 0;
3580 if (argv_find(argv, argc, "missing-as-worst", &idx))
3581 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3582
3583 bgp_recalculate_all_bestpaths(bgp);
3584
3585 return CMD_SUCCESS;
3586 }
3587
3588 /* "bgp bestpath bandwidth" configuration. */
3589 DEFPY (bgp_bestpath_bw,
3590 bgp_bestpath_bw_cmd,
3591 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3592 BGP_STR
3593 "Change the default bestpath selection\n"
3594 "Link Bandwidth attribute\n"
3595 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3596 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3597 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3598 {
3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
3600 afi_t afi;
3601 safi_t safi;
3602
3603 if (!bw_cfg) {
3604 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3605 return CMD_ERR_INCOMPLETE;
3606 }
3607 if (!strcmp(bw_cfg, "ignore"))
3608 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3609 else if (!strcmp(bw_cfg, "skip-missing"))
3610 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3611 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3612 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3613 else
3614 return CMD_ERR_NO_MATCH;
3615
3616 /* This config is used in route install, so redo that. */
3617 FOREACH_AFI_SAFI (afi, safi) {
3618 if (!bgp_fibupd_safi(safi))
3619 continue;
3620 bgp_zebra_announce_table(bgp, afi, safi);
3621 }
3622
3623 return CMD_SUCCESS;
3624 }
3625
3626 DEFPY (no_bgp_bestpath_bw,
3627 no_bgp_bestpath_bw_cmd,
3628 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3629 NO_STR
3630 BGP_STR
3631 "Change the default bestpath selection\n"
3632 "Link Bandwidth attribute\n"
3633 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3634 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3635 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3636 {
3637 VTY_DECLVAR_CONTEXT(bgp, bgp);
3638 afi_t afi;
3639 safi_t safi;
3640
3641 bgp->lb_handling = BGP_LINK_BW_ECMP;
3642
3643 /* This config is used in route install, so redo that. */
3644 FOREACH_AFI_SAFI (afi, safi) {
3645 if (!bgp_fibupd_safi(safi))
3646 continue;
3647 bgp_zebra_announce_table(bgp, afi, safi);
3648 }
3649 return CMD_SUCCESS;
3650 }
3651
3652 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3653 "[no] bgp default <ipv4-unicast|"
3654 "ipv4-multicast|"
3655 "ipv4-vpn|"
3656 "ipv4-labeled-unicast|"
3657 "ipv4-flowspec|"
3658 "ipv6-unicast|"
3659 "ipv6-multicast|"
3660 "ipv6-vpn|"
3661 "ipv6-labeled-unicast|"
3662 "ipv6-flowspec|"
3663 "l2vpn-evpn>$afi_safi",
3664 NO_STR
3665 BGP_STR
3666 "Configure BGP defaults\n"
3667 "Activate ipv4-unicast for a peer by default\n"
3668 "Activate ipv4-multicast for a peer by default\n"
3669 "Activate ipv4-vpn for a peer by default\n"
3670 "Activate ipv4-labeled-unicast for a peer by default\n"
3671 "Activate ipv4-flowspec for a peer by default\n"
3672 "Activate ipv6-unicast for a peer by default\n"
3673 "Activate ipv6-multicast for a peer by default\n"
3674 "Activate ipv6-vpn for a peer by default\n"
3675 "Activate ipv6-labeled-unicast for a peer by default\n"
3676 "Activate ipv6-flowspec for a peer by default\n"
3677 "Activate l2vpn-evpn for a peer by default\n")
3678 {
3679 VTY_DECLVAR_CONTEXT(bgp, bgp);
3680 char afi_safi_str[strlen(afi_safi) + 1];
3681 char *afi_safi_str_tok;
3682
3683 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3684 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3685 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3686 afi_t afi = bgp_vty_afi_from_str(afi_str);
3687 safi_t safi;
3688
3689 if (strmatch(safi_str, "labeled"))
3690 safi = bgp_vty_safi_from_str("labeled-unicast");
3691 else
3692 safi = bgp_vty_safi_from_str(safi_str);
3693
3694 if (no)
3695 bgp->default_af[afi][safi] = false;
3696 else {
3697 if ((safi == SAFI_LABELED_UNICAST
3698 && bgp->default_af[afi][SAFI_UNICAST])
3699 || (safi == SAFI_UNICAST
3700 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3701 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3702 else
3703 bgp->default_af[afi][safi] = true;
3704 }
3705
3706 return CMD_SUCCESS;
3707 }
3708
3709 /* Display hostname in certain command outputs */
3710 DEFUN (bgp_default_show_hostname,
3711 bgp_default_show_hostname_cmd,
3712 "bgp default show-hostname",
3713 BGP_STR
3714 "Configure BGP defaults\n"
3715 "Show hostname in certain command outputs\n")
3716 {
3717 VTY_DECLVAR_CONTEXT(bgp, bgp);
3718 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3719 return CMD_SUCCESS;
3720 }
3721
3722 DEFUN (no_bgp_default_show_hostname,
3723 no_bgp_default_show_hostname_cmd,
3724 "no bgp default show-hostname",
3725 NO_STR
3726 BGP_STR
3727 "Configure BGP defaults\n"
3728 "Show hostname in certain command outputs\n")
3729 {
3730 VTY_DECLVAR_CONTEXT(bgp, bgp);
3731 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3732 return CMD_SUCCESS;
3733 }
3734
3735 /* Display hostname in certain command outputs */
3736 DEFUN (bgp_default_show_nexthop_hostname,
3737 bgp_default_show_nexthop_hostname_cmd,
3738 "bgp default show-nexthop-hostname",
3739 BGP_STR
3740 "Configure BGP defaults\n"
3741 "Show hostname for nexthop in certain command outputs\n")
3742 {
3743 VTY_DECLVAR_CONTEXT(bgp, bgp);
3744 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3745 return CMD_SUCCESS;
3746 }
3747
3748 DEFUN (no_bgp_default_show_nexthop_hostname,
3749 no_bgp_default_show_nexthop_hostname_cmd,
3750 "no bgp default show-nexthop-hostname",
3751 NO_STR
3752 BGP_STR
3753 "Configure BGP defaults\n"
3754 "Show hostname for nexthop in certain command outputs\n")
3755 {
3756 VTY_DECLVAR_CONTEXT(bgp, bgp);
3757 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3758 return CMD_SUCCESS;
3759 }
3760
3761 /* "bgp network import-check" configuration. */
3762 DEFUN (bgp_network_import_check,
3763 bgp_network_import_check_cmd,
3764 "bgp network import-check",
3765 BGP_STR
3766 "BGP network command\n"
3767 "Check BGP network route exists in IGP\n")
3768 {
3769 VTY_DECLVAR_CONTEXT(bgp, bgp);
3770 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3771 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3772 bgp_static_redo_import_check(bgp);
3773 }
3774
3775 return CMD_SUCCESS;
3776 }
3777
3778 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3779 "bgp network import-check exact",
3780 BGP_STR
3781 "BGP network command\n"
3782 "Check BGP network route exists in IGP\n"
3783 "Match route precisely\n")
3784
3785 DEFUN (no_bgp_network_import_check,
3786 no_bgp_network_import_check_cmd,
3787 "no bgp network import-check",
3788 NO_STR
3789 BGP_STR
3790 "BGP network command\n"
3791 "Check BGP network route exists in IGP\n")
3792 {
3793 VTY_DECLVAR_CONTEXT(bgp, bgp);
3794 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3795 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3796 bgp_static_redo_import_check(bgp);
3797 }
3798
3799 return CMD_SUCCESS;
3800 }
3801
3802 DEFUN (bgp_default_local_preference,
3803 bgp_default_local_preference_cmd,
3804 "bgp default local-preference (0-4294967295)",
3805 BGP_STR
3806 "Configure BGP defaults\n"
3807 "local preference (higher=more preferred)\n"
3808 "Configure default local preference value\n")
3809 {
3810 VTY_DECLVAR_CONTEXT(bgp, bgp);
3811 int idx_number = 3;
3812 uint32_t local_pref;
3813
3814 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3815
3816 bgp_default_local_preference_set(bgp, local_pref);
3817 bgp_clear_star_soft_in(vty, bgp->name);
3818
3819 return CMD_SUCCESS;
3820 }
3821
3822 DEFUN (no_bgp_default_local_preference,
3823 no_bgp_default_local_preference_cmd,
3824 "no bgp default local-preference [(0-4294967295)]",
3825 NO_STR
3826 BGP_STR
3827 "Configure BGP defaults\n"
3828 "local preference (higher=more preferred)\n"
3829 "Configure default local preference value\n")
3830 {
3831 VTY_DECLVAR_CONTEXT(bgp, bgp);
3832 bgp_default_local_preference_unset(bgp);
3833 bgp_clear_star_soft_in(vty, bgp->name);
3834
3835 return CMD_SUCCESS;
3836 }
3837
3838
3839 DEFUN (bgp_default_subgroup_pkt_queue_max,
3840 bgp_default_subgroup_pkt_queue_max_cmd,
3841 "bgp default subgroup-pkt-queue-max (20-100)",
3842 BGP_STR
3843 "Configure BGP defaults\n"
3844 "subgroup-pkt-queue-max\n"
3845 "Configure subgroup packet queue max\n")
3846 {
3847 VTY_DECLVAR_CONTEXT(bgp, bgp);
3848 int idx_number = 3;
3849 uint32_t max_size;
3850
3851 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3852
3853 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3854
3855 return CMD_SUCCESS;
3856 }
3857
3858 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3859 no_bgp_default_subgroup_pkt_queue_max_cmd,
3860 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3861 NO_STR
3862 BGP_STR
3863 "Configure BGP defaults\n"
3864 "subgroup-pkt-queue-max\n"
3865 "Configure subgroup packet queue max\n")
3866 {
3867 VTY_DECLVAR_CONTEXT(bgp, bgp);
3868 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3869 return CMD_SUCCESS;
3870 }
3871
3872
3873 DEFUN (bgp_rr_allow_outbound_policy,
3874 bgp_rr_allow_outbound_policy_cmd,
3875 "bgp route-reflector allow-outbound-policy",
3876 BGP_STR
3877 "Allow modifications made by out route-map\n"
3878 "on ibgp neighbors\n")
3879 {
3880 VTY_DECLVAR_CONTEXT(bgp, bgp);
3881
3882 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3883 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3884 update_group_announce_rrclients(bgp);
3885 bgp_clear_star_soft_out(vty, bgp->name);
3886 }
3887
3888 return CMD_SUCCESS;
3889 }
3890
3891 DEFUN (no_bgp_rr_allow_outbound_policy,
3892 no_bgp_rr_allow_outbound_policy_cmd,
3893 "no bgp route-reflector allow-outbound-policy",
3894 NO_STR
3895 BGP_STR
3896 "Allow modifications made by out route-map\n"
3897 "on ibgp neighbors\n")
3898 {
3899 VTY_DECLVAR_CONTEXT(bgp, bgp);
3900
3901 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3902 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3903 update_group_announce_rrclients(bgp);
3904 bgp_clear_star_soft_out(vty, bgp->name);
3905 }
3906
3907 return CMD_SUCCESS;
3908 }
3909
3910 DEFUN (bgp_listen_limit,
3911 bgp_listen_limit_cmd,
3912 "bgp listen limit (1-65535)",
3913 BGP_STR
3914 "BGP Dynamic Neighbors listen commands\n"
3915 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3916 "Configure Dynamic Neighbors listen limit value\n")
3917 {
3918 VTY_DECLVAR_CONTEXT(bgp, bgp);
3919 int idx_number = 3;
3920 int listen_limit;
3921
3922 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
3923
3924 bgp_listen_limit_set(bgp, listen_limit);
3925
3926 return CMD_SUCCESS;
3927 }
3928
3929 DEFUN (no_bgp_listen_limit,
3930 no_bgp_listen_limit_cmd,
3931 "no bgp listen limit [(1-65535)]",
3932 NO_STR
3933 BGP_STR
3934 "BGP Dynamic Neighbors listen commands\n"
3935 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3936 "Configure Dynamic Neighbors listen limit value\n")
3937 {
3938 VTY_DECLVAR_CONTEXT(bgp, bgp);
3939 bgp_listen_limit_unset(bgp);
3940 return CMD_SUCCESS;
3941 }
3942
3943
3944 /*
3945 * Check if this listen range is already configured. Check for exact
3946 * match or overlap based on input.
3947 */
3948 static struct peer_group *listen_range_exists(struct bgp *bgp,
3949 struct prefix *range, int exact)
3950 {
3951 struct listnode *node, *nnode;
3952 struct listnode *node1, *nnode1;
3953 struct peer_group *group;
3954 struct prefix *lr;
3955 afi_t afi;
3956 int match;
3957
3958 afi = family2afi(range->family);
3959 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3960 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3961 lr)) {
3962 if (exact)
3963 match = prefix_same(range, lr);
3964 else
3965 match = (prefix_match(range, lr)
3966 || prefix_match(lr, range));
3967 if (match)
3968 return group;
3969 }
3970 }
3971
3972 return NULL;
3973 }
3974
3975 DEFUN (bgp_listen_range,
3976 bgp_listen_range_cmd,
3977 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
3978 BGP_STR
3979 "Configure BGP dynamic neighbors listen range\n"
3980 "Configure BGP dynamic neighbors listen range\n"
3981 NEIGHBOR_ADDR_STR
3982 "Member of the peer-group\n"
3983 "Peer-group name\n")
3984 {
3985 VTY_DECLVAR_CONTEXT(bgp, bgp);
3986 struct prefix range;
3987 struct peer_group *group, *existing_group;
3988 afi_t afi;
3989 int ret;
3990 int idx = 0;
3991
3992 argv_find(argv, argc, "A.B.C.D/M", &idx);
3993 argv_find(argv, argc, "X:X::X:X/M", &idx);
3994 char *prefix = argv[idx]->arg;
3995 argv_find(argv, argc, "PGNAME", &idx);
3996 char *peergroup = argv[idx]->arg;
3997
3998 /* Convert IP prefix string to struct prefix. */
3999 ret = str2prefix(prefix, &range);
4000 if (!ret) {
4001 vty_out(vty, "%% Malformed listen range\n");
4002 return CMD_WARNING_CONFIG_FAILED;
4003 }
4004
4005 afi = family2afi(range.family);
4006
4007 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4008 vty_out(vty,
4009 "%% Malformed listen range (link-local address)\n");
4010 return CMD_WARNING_CONFIG_FAILED;
4011 }
4012
4013 apply_mask(&range);
4014
4015 /* Check if same listen range is already configured. */
4016 existing_group = listen_range_exists(bgp, &range, 1);
4017 if (existing_group) {
4018 if (strcmp(existing_group->name, peergroup) == 0)
4019 return CMD_SUCCESS;
4020 else {
4021 vty_out(vty,
4022 "%% Same listen range is attached to peer-group %s\n",
4023 existing_group->name);
4024 return CMD_WARNING_CONFIG_FAILED;
4025 }
4026 }
4027
4028 /* Check if an overlapping listen range exists. */
4029 if (listen_range_exists(bgp, &range, 0)) {
4030 vty_out(vty,
4031 "%% Listen range overlaps with existing listen range\n");
4032 return CMD_WARNING_CONFIG_FAILED;
4033 }
4034
4035 group = peer_group_lookup(bgp, peergroup);
4036 if (!group) {
4037 vty_out(vty, "%% Configure the peer-group first\n");
4038 return CMD_WARNING_CONFIG_FAILED;
4039 }
4040
4041 ret = peer_group_listen_range_add(group, &range);
4042 return bgp_vty_return(vty, ret);
4043 }
4044
4045 DEFUN (no_bgp_listen_range,
4046 no_bgp_listen_range_cmd,
4047 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4048 NO_STR
4049 BGP_STR
4050 "Unconfigure BGP dynamic neighbors listen range\n"
4051 "Unconfigure BGP dynamic neighbors listen range\n"
4052 NEIGHBOR_ADDR_STR
4053 "Member of the peer-group\n"
4054 "Peer-group name\n")
4055 {
4056 VTY_DECLVAR_CONTEXT(bgp, bgp);
4057 struct prefix range;
4058 struct peer_group *group;
4059 afi_t afi;
4060 int ret;
4061 int idx = 0;
4062
4063 argv_find(argv, argc, "A.B.C.D/M", &idx);
4064 argv_find(argv, argc, "X:X::X:X/M", &idx);
4065 char *prefix = argv[idx]->arg;
4066 argv_find(argv, argc, "PGNAME", &idx);
4067 char *peergroup = argv[idx]->arg;
4068
4069 /* Convert IP prefix string to struct prefix. */
4070 ret = str2prefix(prefix, &range);
4071 if (!ret) {
4072 vty_out(vty, "%% Malformed listen range\n");
4073 return CMD_WARNING_CONFIG_FAILED;
4074 }
4075
4076 afi = family2afi(range.family);
4077
4078 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4079 vty_out(vty,
4080 "%% Malformed listen range (link-local address)\n");
4081 return CMD_WARNING_CONFIG_FAILED;
4082 }
4083
4084 apply_mask(&range);
4085
4086 group = peer_group_lookup(bgp, peergroup);
4087 if (!group) {
4088 vty_out(vty, "%% Peer-group does not exist\n");
4089 return CMD_WARNING_CONFIG_FAILED;
4090 }
4091
4092 ret = peer_group_listen_range_del(group, &range);
4093 return bgp_vty_return(vty, ret);
4094 }
4095
4096 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4097 {
4098 struct peer_group *group;
4099 struct listnode *node, *nnode, *rnode, *nrnode;
4100 struct prefix *range;
4101 afi_t afi;
4102
4103 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4104 vty_out(vty, " bgp listen limit %d\n",
4105 bgp->dynamic_neighbors_limit);
4106
4107 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4108 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4109 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4110 nrnode, range)) {
4111 vty_out(vty,
4112 " bgp listen range %pFX peer-group %s\n",
4113 range, group->name);
4114 }
4115 }
4116 }
4117 }
4118
4119
4120 DEFUN (bgp_disable_connected_route_check,
4121 bgp_disable_connected_route_check_cmd,
4122 "bgp disable-ebgp-connected-route-check",
4123 BGP_STR
4124 "Disable checking if nexthop is connected on ebgp sessions\n")
4125 {
4126 VTY_DECLVAR_CONTEXT(bgp, bgp);
4127 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4128 bgp_clear_star_soft_in(vty, bgp->name);
4129
4130 return CMD_SUCCESS;
4131 }
4132
4133 DEFUN (no_bgp_disable_connected_route_check,
4134 no_bgp_disable_connected_route_check_cmd,
4135 "no bgp disable-ebgp-connected-route-check",
4136 NO_STR
4137 BGP_STR
4138 "Disable checking if nexthop is connected on ebgp sessions\n")
4139 {
4140 VTY_DECLVAR_CONTEXT(bgp, bgp);
4141 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4142 bgp_clear_star_soft_in(vty, bgp->name);
4143
4144 return CMD_SUCCESS;
4145 }
4146
4147
4148 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4149 const char *as_str)
4150 {
4151 VTY_DECLVAR_CONTEXT(bgp, bgp);
4152 int ret;
4153 as_t as;
4154 int as_type = AS_SPECIFIED;
4155 union sockunion su;
4156
4157 if (as_str[0] == 'i') {
4158 as = 0;
4159 as_type = AS_INTERNAL;
4160 } else if (as_str[0] == 'e') {
4161 as = 0;
4162 as_type = AS_EXTERNAL;
4163 } else {
4164 /* Get AS number. */
4165 as = strtoul(as_str, NULL, 10);
4166 }
4167
4168 /* If peer is peer group or interface peer, call proper function. */
4169 ret = str2sockunion(peer_str, &su);
4170 if (ret < 0) {
4171 struct peer *peer;
4172
4173 /* Check if existing interface peer */
4174 peer = peer_lookup_by_conf_if(bgp, peer_str);
4175
4176 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4177
4178 /* if not interface peer, check peer-group settings */
4179 if (ret < 0 && !peer) {
4180 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4181 if (ret < 0) {
4182 vty_out(vty,
4183 "%% Create the peer-group or interface first\n");
4184 return CMD_WARNING_CONFIG_FAILED;
4185 }
4186 return CMD_SUCCESS;
4187 }
4188 } else {
4189 if (peer_address_self_check(bgp, &su)) {
4190 vty_out(vty,
4191 "%% Can not configure the local system as neighbor\n");
4192 return CMD_WARNING_CONFIG_FAILED;
4193 }
4194 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4195 }
4196
4197 /* This peer belongs to peer group. */
4198 switch (ret) {
4199 case BGP_ERR_PEER_GROUP_MEMBER:
4200 vty_out(vty,
4201 "%% Peer-group member cannot override remote-as of peer-group\n");
4202 return CMD_WARNING_CONFIG_FAILED;
4203 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
4204 vty_out(vty,
4205 "%% Peer-group members must be all internal or all external\n");
4206 return CMD_WARNING_CONFIG_FAILED;
4207 }
4208 return bgp_vty_return(vty, ret);
4209 }
4210
4211 DEFUN (bgp_default_shutdown,
4212 bgp_default_shutdown_cmd,
4213 "[no] bgp default shutdown",
4214 NO_STR
4215 BGP_STR
4216 "Configure BGP defaults\n"
4217 "Apply administrative shutdown to newly configured peers\n")
4218 {
4219 VTY_DECLVAR_CONTEXT(bgp, bgp);
4220 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4221 return CMD_SUCCESS;
4222 }
4223
4224 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4225 BGP_STR
4226 "Administrative shutdown of the BGP instance\n"
4227 "Add a shutdown message (RFC 8203)\n"
4228 "Shutdown message\n")
4229 {
4230 char *msgstr = NULL;
4231
4232 VTY_DECLVAR_CONTEXT(bgp, bgp);
4233
4234 if (argc > 3)
4235 msgstr = argv_concat(argv, argc, 3);
4236
4237 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4238 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4239 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4240 return CMD_WARNING_CONFIG_FAILED;
4241 }
4242
4243 bgp_shutdown_enable(bgp, msgstr);
4244 XFREE(MTYPE_TMP, msgstr);
4245
4246 return CMD_SUCCESS;
4247 }
4248
4249 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4250 BGP_STR "Administrative shutdown of the BGP instance\n")
4251 {
4252 VTY_DECLVAR_CONTEXT(bgp, bgp);
4253
4254 bgp_shutdown_enable(bgp, NULL);
4255
4256 return CMD_SUCCESS;
4257 }
4258
4259 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4260 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4261 {
4262 VTY_DECLVAR_CONTEXT(bgp, bgp);
4263
4264 bgp_shutdown_disable(bgp);
4265
4266 return CMD_SUCCESS;
4267 }
4268
4269 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4270 "no bgp shutdown message MSG...", NO_STR BGP_STR
4271 "Administrative shutdown of the BGP instance\n"
4272 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4273
4274 DEFUN (neighbor_remote_as,
4275 neighbor_remote_as_cmd,
4276 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4277 NEIGHBOR_STR
4278 NEIGHBOR_ADDR_STR2
4279 "Specify a BGP neighbor\n"
4280 AS_STR
4281 "Internal BGP peer\n"
4282 "External BGP peer\n")
4283 {
4284 int idx_peer = 1;
4285 int idx_remote_as = 3;
4286 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4287 argv[idx_remote_as]->arg);
4288 }
4289 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4290 * sessions do not wait for hold timer expiry to bring down the sessions
4291 * when nexthop becomes unreachable
4292 */
4293 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4294 BGP_STR "Fast convergence for bgp sessions\n")
4295 {
4296 VTY_DECLVAR_CONTEXT(bgp, bgp);
4297 bgp->fast_convergence = true;
4298
4299 return CMD_SUCCESS;
4300 }
4301
4302 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4303 "no bgp fast-convergence",
4304 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4305 {
4306 VTY_DECLVAR_CONTEXT(bgp, bgp);
4307 bgp->fast_convergence = false;
4308
4309 return CMD_SUCCESS;
4310 }
4311
4312 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4313 int v6only,
4314 const char *peer_group_name,
4315 const char *as_str)
4316 {
4317 VTY_DECLVAR_CONTEXT(bgp, bgp);
4318 as_t as = 0;
4319 int as_type = AS_UNSPECIFIED;
4320 struct peer *peer;
4321 struct peer_group *group;
4322 int ret = 0;
4323
4324 group = peer_group_lookup(bgp, conf_if);
4325
4326 if (group) {
4327 vty_out(vty, "%% Name conflict with peer-group \n");
4328 return CMD_WARNING_CONFIG_FAILED;
4329 }
4330
4331 if (as_str) {
4332 if (as_str[0] == 'i') {
4333 as_type = AS_INTERNAL;
4334 } else if (as_str[0] == 'e') {
4335 as_type = AS_EXTERNAL;
4336 } else {
4337 /* Get AS number. */
4338 as = strtoul(as_str, NULL, 10);
4339 as_type = AS_SPECIFIED;
4340 }
4341 }
4342
4343 peer = peer_lookup_by_conf_if(bgp, conf_if);
4344 if (peer) {
4345 if (as_str)
4346 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4347 } else {
4348 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4349 NULL);
4350
4351 if (!peer) {
4352 vty_out(vty, "%% BGP failed to create peer\n");
4353 return CMD_WARNING_CONFIG_FAILED;
4354 }
4355
4356 if (v6only)
4357 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4358
4359 /* Request zebra to initiate IPv6 RAs on this interface. We do
4360 * this
4361 * any unnumbered peer in order to not worry about run-time
4362 * transitions
4363 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4364 * address
4365 * gets deleted later etc.)
4366 */
4367 if (peer->ifp)
4368 bgp_zebra_initiate_radv(bgp, peer);
4369 }
4370
4371 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4372 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4373 if (v6only)
4374 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4375 else
4376 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4377
4378 /* v6only flag changed. Reset bgp seesion */
4379 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4380 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4381 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4382 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4383 } else
4384 bgp_session_reset(peer);
4385 }
4386
4387 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4388 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4389 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4390 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4391 }
4392
4393 if (peer_group_name) {
4394 group = peer_group_lookup(bgp, peer_group_name);
4395 if (!group) {
4396 vty_out(vty, "%% Configure the peer-group first\n");
4397 return CMD_WARNING_CONFIG_FAILED;
4398 }
4399
4400 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4401 }
4402
4403 return bgp_vty_return(vty, ret);
4404 }
4405
4406 DEFUN (neighbor_interface_config,
4407 neighbor_interface_config_cmd,
4408 "neighbor WORD interface [peer-group PGNAME]",
4409 NEIGHBOR_STR
4410 "Interface name or neighbor tag\n"
4411 "Enable BGP on interface\n"
4412 "Member of the peer-group\n"
4413 "Peer-group name\n")
4414 {
4415 int idx_word = 1;
4416 int idx_peer_group_word = 4;
4417
4418 if (argc > idx_peer_group_word)
4419 return peer_conf_interface_get(
4420 vty, argv[idx_word]->arg, 0,
4421 argv[idx_peer_group_word]->arg, NULL);
4422 else
4423 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4424 NULL, NULL);
4425 }
4426
4427 DEFUN (neighbor_interface_config_v6only,
4428 neighbor_interface_config_v6only_cmd,
4429 "neighbor WORD interface v6only [peer-group PGNAME]",
4430 NEIGHBOR_STR
4431 "Interface name or neighbor tag\n"
4432 "Enable BGP on interface\n"
4433 "Enable BGP with v6 link-local only\n"
4434 "Member of the peer-group\n"
4435 "Peer-group name\n")
4436 {
4437 int idx_word = 1;
4438 int idx_peer_group_word = 5;
4439
4440 if (argc > idx_peer_group_word)
4441 return peer_conf_interface_get(
4442 vty, argv[idx_word]->arg, 1,
4443 argv[idx_peer_group_word]->arg, NULL);
4444
4445 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4446 }
4447
4448
4449 DEFUN (neighbor_interface_config_remote_as,
4450 neighbor_interface_config_remote_as_cmd,
4451 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4452 NEIGHBOR_STR
4453 "Interface name or neighbor tag\n"
4454 "Enable BGP on interface\n"
4455 "Specify a BGP neighbor\n"
4456 AS_STR
4457 "Internal BGP peer\n"
4458 "External BGP peer\n")
4459 {
4460 int idx_word = 1;
4461 int idx_remote_as = 4;
4462 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4463 argv[idx_remote_as]->arg);
4464 }
4465
4466 DEFUN (neighbor_interface_v6only_config_remote_as,
4467 neighbor_interface_v6only_config_remote_as_cmd,
4468 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4469 NEIGHBOR_STR
4470 "Interface name or neighbor tag\n"
4471 "Enable BGP with v6 link-local only\n"
4472 "Enable BGP on interface\n"
4473 "Specify a BGP neighbor\n"
4474 AS_STR
4475 "Internal BGP peer\n"
4476 "External BGP peer\n")
4477 {
4478 int idx_word = 1;
4479 int idx_remote_as = 5;
4480 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4481 argv[idx_remote_as]->arg);
4482 }
4483
4484 DEFUN (neighbor_peer_group,
4485 neighbor_peer_group_cmd,
4486 "neighbor WORD peer-group",
4487 NEIGHBOR_STR
4488 "Interface name or neighbor tag\n"
4489 "Configure peer-group\n")
4490 {
4491 VTY_DECLVAR_CONTEXT(bgp, bgp);
4492 int idx_word = 1;
4493 struct peer *peer;
4494 struct peer_group *group;
4495
4496 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4497 if (peer) {
4498 vty_out(vty, "%% Name conflict with interface: \n");
4499 return CMD_WARNING_CONFIG_FAILED;
4500 }
4501
4502 group = peer_group_get(bgp, argv[idx_word]->arg);
4503 if (!group) {
4504 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4505 return CMD_WARNING_CONFIG_FAILED;
4506 }
4507
4508 return CMD_SUCCESS;
4509 }
4510
4511 DEFUN (no_neighbor,
4512 no_neighbor_cmd,
4513 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4514 NO_STR
4515 NEIGHBOR_STR
4516 NEIGHBOR_ADDR_STR2
4517 "Specify a BGP neighbor\n"
4518 AS_STR
4519 "Internal BGP peer\n"
4520 "External BGP peer\n")
4521 {
4522 VTY_DECLVAR_CONTEXT(bgp, bgp);
4523 int idx_peer = 2;
4524 int ret;
4525 union sockunion su;
4526 struct peer_group *group;
4527 struct peer *peer;
4528 struct peer *other;
4529
4530 ret = str2sockunion(argv[idx_peer]->arg, &su);
4531 if (ret < 0) {
4532 /* look up for neighbor by interface name config. */
4533 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4534 if (peer) {
4535 /* Request zebra to terminate IPv6 RAs on this
4536 * interface. */
4537 if (peer->ifp)
4538 bgp_zebra_terminate_radv(peer->bgp, peer);
4539 peer_notify_unconfig(peer);
4540 peer_delete(peer);
4541 return CMD_SUCCESS;
4542 }
4543
4544 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4545 if (group) {
4546 peer_group_notify_unconfig(group);
4547 peer_group_delete(group);
4548 } else {
4549 vty_out(vty, "%% Create the peer-group first\n");
4550 return CMD_WARNING_CONFIG_FAILED;
4551 }
4552 } else {
4553 peer = peer_lookup(bgp, &su);
4554 if (peer) {
4555 if (peer_dynamic_neighbor(peer)) {
4556 vty_out(vty,
4557 "%% Operation not allowed on a dynamic neighbor\n");
4558 return CMD_WARNING_CONFIG_FAILED;
4559 }
4560
4561 other = peer->doppelganger;
4562
4563 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4564 bgp_zebra_terminate_radv(peer->bgp, peer);
4565
4566 peer_notify_unconfig(peer);
4567 peer_delete(peer);
4568 if (other && other->status != Deleted) {
4569 peer_notify_unconfig(other);
4570 peer_delete(other);
4571 }
4572 }
4573 }
4574
4575 return CMD_SUCCESS;
4576 }
4577
4578 DEFUN (no_neighbor_interface_config,
4579 no_neighbor_interface_config_cmd,
4580 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4581 NO_STR
4582 NEIGHBOR_STR
4583 "Interface name\n"
4584 "Configure BGP on interface\n"
4585 "Enable BGP with v6 link-local only\n"
4586 "Member of the peer-group\n"
4587 "Peer-group name\n"
4588 "Specify a BGP neighbor\n"
4589 AS_STR
4590 "Internal BGP peer\n"
4591 "External BGP peer\n")
4592 {
4593 VTY_DECLVAR_CONTEXT(bgp, bgp);
4594 int idx_word = 2;
4595 struct peer *peer;
4596
4597 /* look up for neighbor by interface name config. */
4598 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4599 if (peer) {
4600 /* Request zebra to terminate IPv6 RAs on this interface. */
4601 if (peer->ifp)
4602 bgp_zebra_terminate_radv(peer->bgp, peer);
4603 peer_notify_unconfig(peer);
4604 peer_delete(peer);
4605 } else {
4606 vty_out(vty, "%% Create the bgp interface first\n");
4607 return CMD_WARNING_CONFIG_FAILED;
4608 }
4609 return CMD_SUCCESS;
4610 }
4611
4612 DEFUN (no_neighbor_peer_group,
4613 no_neighbor_peer_group_cmd,
4614 "no neighbor WORD peer-group",
4615 NO_STR
4616 NEIGHBOR_STR
4617 "Neighbor tag\n"
4618 "Configure peer-group\n")
4619 {
4620 VTY_DECLVAR_CONTEXT(bgp, bgp);
4621 int idx_word = 2;
4622 struct peer_group *group;
4623
4624 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4625 if (group) {
4626 peer_group_notify_unconfig(group);
4627 peer_group_delete(group);
4628 } else {
4629 vty_out(vty, "%% Create the peer-group first\n");
4630 return CMD_WARNING_CONFIG_FAILED;
4631 }
4632 return CMD_SUCCESS;
4633 }
4634
4635 DEFUN (no_neighbor_interface_peer_group_remote_as,
4636 no_neighbor_interface_peer_group_remote_as_cmd,
4637 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4638 NO_STR
4639 NEIGHBOR_STR
4640 "Interface name or neighbor tag\n"
4641 "Specify a BGP neighbor\n"
4642 AS_STR
4643 "Internal BGP peer\n"
4644 "External BGP peer\n")
4645 {
4646 VTY_DECLVAR_CONTEXT(bgp, bgp);
4647 int idx_word = 2;
4648 struct peer_group *group;
4649 struct peer *peer;
4650
4651 /* look up for neighbor by interface name config. */
4652 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4653 if (peer) {
4654 peer_as_change(peer, 0, AS_UNSPECIFIED);
4655 return CMD_SUCCESS;
4656 }
4657
4658 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4659 if (group)
4660 peer_group_remote_as_delete(group);
4661 else {
4662 vty_out(vty, "%% Create the peer-group or interface first\n");
4663 return CMD_WARNING_CONFIG_FAILED;
4664 }
4665 return CMD_SUCCESS;
4666 }
4667
4668 DEFUN (neighbor_local_as,
4669 neighbor_local_as_cmd,
4670 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4671 NEIGHBOR_STR
4672 NEIGHBOR_ADDR_STR2
4673 "Specify a local-as number\n"
4674 "AS number used as local AS\n")
4675 {
4676 int idx_peer = 1;
4677 int idx_number = 3;
4678 struct peer *peer;
4679 int ret;
4680 as_t as;
4681
4682 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4683 if (!peer)
4684 return CMD_WARNING_CONFIG_FAILED;
4685
4686 as = strtoul(argv[idx_number]->arg, NULL, 10);
4687 ret = peer_local_as_set(peer, as, 0, 0);
4688 return bgp_vty_return(vty, ret);
4689 }
4690
4691 DEFUN (neighbor_local_as_no_prepend,
4692 neighbor_local_as_no_prepend_cmd,
4693 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "Specify a local-as number\n"
4697 "AS number used as local AS\n"
4698 "Do not prepend local-as to updates from ebgp peers\n")
4699 {
4700 int idx_peer = 1;
4701 int idx_number = 3;
4702 struct peer *peer;
4703 int ret;
4704 as_t as;
4705
4706 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4707 if (!peer)
4708 return CMD_WARNING_CONFIG_FAILED;
4709
4710 as = strtoul(argv[idx_number]->arg, NULL, 10);
4711 ret = peer_local_as_set(peer, as, 1, 0);
4712 return bgp_vty_return(vty, ret);
4713 }
4714
4715 DEFUN (neighbor_local_as_no_prepend_replace_as,
4716 neighbor_local_as_no_prepend_replace_as_cmd,
4717 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4718 NEIGHBOR_STR
4719 NEIGHBOR_ADDR_STR2
4720 "Specify a local-as number\n"
4721 "AS number used as local AS\n"
4722 "Do not prepend local-as to updates from ebgp peers\n"
4723 "Do not prepend local-as to updates from ibgp peers\n")
4724 {
4725 int idx_peer = 1;
4726 int idx_number = 3;
4727 struct peer *peer;
4728 int ret;
4729 as_t as;
4730
4731 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4732 if (!peer)
4733 return CMD_WARNING_CONFIG_FAILED;
4734
4735 as = strtoul(argv[idx_number]->arg, NULL, 10);
4736 ret = peer_local_as_set(peer, as, 1, 1);
4737 return bgp_vty_return(vty, ret);
4738 }
4739
4740 DEFUN (no_neighbor_local_as,
4741 no_neighbor_local_as_cmd,
4742 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4743 NO_STR
4744 NEIGHBOR_STR
4745 NEIGHBOR_ADDR_STR2
4746 "Specify a local-as number\n"
4747 "AS number used as local AS\n"
4748 "Do not prepend local-as to updates from ebgp peers\n"
4749 "Do not prepend local-as to updates from ibgp peers\n")
4750 {
4751 int idx_peer = 2;
4752 struct peer *peer;
4753 int ret;
4754
4755 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4756 if (!peer)
4757 return CMD_WARNING_CONFIG_FAILED;
4758
4759 ret = peer_local_as_unset(peer);
4760 return bgp_vty_return(vty, ret);
4761 }
4762
4763
4764 DEFUN (neighbor_solo,
4765 neighbor_solo_cmd,
4766 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4767 NEIGHBOR_STR
4768 NEIGHBOR_ADDR_STR2
4769 "Solo peer - part of its own update group\n")
4770 {
4771 int idx_peer = 1;
4772 struct peer *peer;
4773 int ret;
4774
4775 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4776 if (!peer)
4777 return CMD_WARNING_CONFIG_FAILED;
4778
4779 ret = update_group_adjust_soloness(peer, 1);
4780 return bgp_vty_return(vty, ret);
4781 }
4782
4783 DEFUN (no_neighbor_solo,
4784 no_neighbor_solo_cmd,
4785 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4786 NO_STR
4787 NEIGHBOR_STR
4788 NEIGHBOR_ADDR_STR2
4789 "Solo peer - part of its own update group\n")
4790 {
4791 int idx_peer = 2;
4792 struct peer *peer;
4793 int ret;
4794
4795 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4796 if (!peer)
4797 return CMD_WARNING_CONFIG_FAILED;
4798
4799 ret = update_group_adjust_soloness(peer, 0);
4800 return bgp_vty_return(vty, ret);
4801 }
4802
4803 DEFUN (neighbor_password,
4804 neighbor_password_cmd,
4805 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4806 NEIGHBOR_STR
4807 NEIGHBOR_ADDR_STR2
4808 "Set a password\n"
4809 "The password\n")
4810 {
4811 int idx_peer = 1;
4812 int idx_line = 3;
4813 struct peer *peer;
4814 int ret;
4815
4816 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4817 if (!peer)
4818 return CMD_WARNING_CONFIG_FAILED;
4819
4820 ret = peer_password_set(peer, argv[idx_line]->arg);
4821 return bgp_vty_return(vty, ret);
4822 }
4823
4824 DEFUN (no_neighbor_password,
4825 no_neighbor_password_cmd,
4826 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4827 NO_STR
4828 NEIGHBOR_STR
4829 NEIGHBOR_ADDR_STR2
4830 "Set a password\n"
4831 "The password\n")
4832 {
4833 int idx_peer = 2;
4834 struct peer *peer;
4835 int ret;
4836
4837 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4838 if (!peer)
4839 return CMD_WARNING_CONFIG_FAILED;
4840
4841 ret = peer_password_unset(peer);
4842 return bgp_vty_return(vty, ret);
4843 }
4844
4845 DEFUN (neighbor_activate,
4846 neighbor_activate_cmd,
4847 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4848 NEIGHBOR_STR
4849 NEIGHBOR_ADDR_STR2
4850 "Enable the Address Family for this Neighbor\n")
4851 {
4852 int idx_peer = 1;
4853 int ret;
4854 struct peer *peer;
4855
4856 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4857 if (!peer)
4858 return CMD_WARNING_CONFIG_FAILED;
4859
4860 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4861 return bgp_vty_return(vty, ret);
4862 }
4863
4864 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4865 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4867 "Enable the Address Family for this Neighbor\n")
4868
4869 DEFUN (no_neighbor_activate,
4870 no_neighbor_activate_cmd,
4871 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4872 NO_STR
4873 NEIGHBOR_STR
4874 NEIGHBOR_ADDR_STR2
4875 "Enable the Address Family for this Neighbor\n")
4876 {
4877 int idx_peer = 2;
4878 int ret;
4879 struct peer *peer;
4880
4881 /* Lookup peer. */
4882 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4883 if (!peer)
4884 return CMD_WARNING_CONFIG_FAILED;
4885
4886 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4887 return bgp_vty_return(vty, ret);
4888 }
4889
4890 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4891 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4892 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4893 "Enable the Address Family for this Neighbor\n")
4894
4895 DEFUN (neighbor_set_peer_group,
4896 neighbor_set_peer_group_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
4900 "Member of the peer-group\n"
4901 "Peer-group name\n")
4902 {
4903 VTY_DECLVAR_CONTEXT(bgp, bgp);
4904 int idx_peer = 1;
4905 int idx_word = 3;
4906 int ret;
4907 as_t as;
4908 union sockunion su;
4909 struct peer *peer;
4910 struct peer_group *group;
4911
4912 ret = str2sockunion(argv[idx_peer]->arg, &su);
4913 if (ret < 0) {
4914 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4915 if (!peer) {
4916 vty_out(vty, "%% Malformed address or name: %s\n",
4917 argv[idx_peer]->arg);
4918 return CMD_WARNING_CONFIG_FAILED;
4919 }
4920 } else {
4921 if (peer_address_self_check(bgp, &su)) {
4922 vty_out(vty,
4923 "%% Can not configure the local system as neighbor\n");
4924 return CMD_WARNING_CONFIG_FAILED;
4925 }
4926
4927 /* Disallow for dynamic neighbor. */
4928 peer = peer_lookup(bgp, &su);
4929 if (peer && peer_dynamic_neighbor(peer)) {
4930 vty_out(vty,
4931 "%% Operation not allowed on a dynamic neighbor\n");
4932 return CMD_WARNING_CONFIG_FAILED;
4933 }
4934 }
4935
4936 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4937 if (!group) {
4938 vty_out(vty, "%% Configure the peer-group first\n");
4939 return CMD_WARNING_CONFIG_FAILED;
4940 }
4941
4942 ret = peer_group_bind(bgp, &su, peer, group, &as);
4943
4944 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4945 vty_out(vty,
4946 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4947 as);
4948 return CMD_WARNING_CONFIG_FAILED;
4949 }
4950
4951 return bgp_vty_return(vty, ret);
4952 }
4953
4954 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
4955 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4957 "Member of the peer-group\n"
4958 "Peer-group name\n")
4959
4960 DEFUN (no_neighbor_set_peer_group,
4961 no_neighbor_set_peer_group_cmd,
4962 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4963 NO_STR
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
4966 "Member of the peer-group\n"
4967 "Peer-group name\n")
4968 {
4969 VTY_DECLVAR_CONTEXT(bgp, bgp);
4970 int idx_peer = 2;
4971 int idx_word = 4;
4972 int ret;
4973 struct peer *peer;
4974 struct peer_group *group;
4975
4976 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4977 if (!peer)
4978 return CMD_WARNING_CONFIG_FAILED;
4979
4980 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4981 if (!group) {
4982 vty_out(vty, "%% Configure the peer-group first\n");
4983 return CMD_WARNING_CONFIG_FAILED;
4984 }
4985
4986 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4987 bgp_zebra_terminate_radv(peer->bgp, peer);
4988
4989 peer_notify_unconfig(peer);
4990 ret = peer_delete(peer);
4991
4992 return bgp_vty_return(vty, ret);
4993 }
4994
4995 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
4996 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4997 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4998 "Member of the peer-group\n"
4999 "Peer-group name\n")
5000
5001 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5002 uint32_t flag, int set)
5003 {
5004 int ret;
5005 struct peer *peer;
5006
5007 peer = peer_and_group_lookup_vty(vty, ip_str);
5008 if (!peer)
5009 return CMD_WARNING_CONFIG_FAILED;
5010
5011 /*
5012 * If 'neighbor <interface>', then this is for directly connected peers,
5013 * we should not accept disable-connected-check.
5014 */
5015 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5016 vty_out(vty,
5017 "%s is directly connected peer, cannot accept disable-connected-check\n",
5018 ip_str);
5019 return CMD_WARNING_CONFIG_FAILED;
5020 }
5021
5022 if (!set && flag == PEER_FLAG_SHUTDOWN)
5023 peer_tx_shutdown_message_unset(peer);
5024
5025 if (set)
5026 ret = peer_flag_set(peer, flag);
5027 else
5028 ret = peer_flag_unset(peer, flag);
5029
5030 return bgp_vty_return(vty, ret);
5031 }
5032
5033 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5034 {
5035 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5036 }
5037
5038 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5039 uint32_t flag)
5040 {
5041 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5042 }
5043
5044 /* neighbor passive. */
5045 DEFUN (neighbor_passive,
5046 neighbor_passive_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5048 NEIGHBOR_STR
5049 NEIGHBOR_ADDR_STR2
5050 "Don't send open messages to this neighbor\n")
5051 {
5052 int idx_peer = 1;
5053 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5054 }
5055
5056 DEFUN (no_neighbor_passive,
5057 no_neighbor_passive_cmd,
5058 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5059 NO_STR
5060 NEIGHBOR_STR
5061 NEIGHBOR_ADDR_STR2
5062 "Don't send open messages to this neighbor\n")
5063 {
5064 int idx_peer = 2;
5065 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5066 }
5067
5068 /* neighbor shutdown. */
5069 DEFUN (neighbor_shutdown_msg,
5070 neighbor_shutdown_msg_cmd,
5071 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5072 NEIGHBOR_STR
5073 NEIGHBOR_ADDR_STR2
5074 "Administratively shut down this neighbor\n"
5075 "Add a shutdown message (RFC 8203)\n"
5076 "Shutdown message\n")
5077 {
5078 int idx_peer = 1;
5079
5080 if (argc >= 5) {
5081 struct peer *peer =
5082 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5083 char *message;
5084
5085 if (!peer)
5086 return CMD_WARNING_CONFIG_FAILED;
5087 message = argv_concat(argv, argc, 4);
5088 peer_tx_shutdown_message_set(peer, message);
5089 XFREE(MTYPE_TMP, message);
5090 }
5091
5092 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5093 }
5094
5095 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5096 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5097 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5098 "Administratively shut down this neighbor\n")
5099
5100 DEFUN (no_neighbor_shutdown_msg,
5101 no_neighbor_shutdown_msg_cmd,
5102 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5103 NO_STR
5104 NEIGHBOR_STR
5105 NEIGHBOR_ADDR_STR2
5106 "Administratively shut down this neighbor\n"
5107 "Remove a shutdown message (RFC 8203)\n"
5108 "Shutdown message\n")
5109 {
5110 int idx_peer = 2;
5111
5112 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5113 PEER_FLAG_SHUTDOWN);
5114 }
5115
5116 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5117 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5118 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5119 "Administratively shut down this neighbor\n")
5120
5121 DEFUN(neighbor_shutdown_rtt,
5122 neighbor_shutdown_rtt_cmd,
5123 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5124 NEIGHBOR_STR
5125 NEIGHBOR_ADDR_STR2
5126 "Administratively shut down this neighbor\n"
5127 "Shutdown if round-trip-time is higher than expected\n"
5128 "Round-trip-time in milliseconds\n"
5129 "Specify the number of keepalives before shutdown\n"
5130 "The number of keepalives with higher RTT to shutdown\n")
5131 {
5132 int idx_peer = 1;
5133 int idx_rtt = 4;
5134 int idx_count = 0;
5135 struct peer *peer;
5136
5137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5138
5139 if (!peer)
5140 return CMD_WARNING_CONFIG_FAILED;
5141
5142 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5143
5144 if (argv_find(argv, argc, "count", &idx_count))
5145 peer->rtt_keepalive_conf =
5146 strtol(argv[idx_count + 1]->arg, NULL, 10);
5147
5148 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5149 PEER_FLAG_RTT_SHUTDOWN);
5150 }
5151
5152 DEFUN(no_neighbor_shutdown_rtt,
5153 no_neighbor_shutdown_rtt_cmd,
5154 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5155 NO_STR
5156 NEIGHBOR_STR
5157 NEIGHBOR_ADDR_STR2
5158 "Administratively shut down this neighbor\n"
5159 "Shutdown if round-trip-time is higher than expected\n"
5160 "Round-trip-time in milliseconds\n"
5161 "Specify the number of keepalives before shutdown\n"
5162 "The number of keepalives with higher RTT to shutdown\n")
5163 {
5164 int idx_peer = 2;
5165 struct peer *peer;
5166
5167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5168
5169 if (!peer)
5170 return CMD_WARNING_CONFIG_FAILED;
5171
5172 peer->rtt_expected = 0;
5173 peer->rtt_keepalive_conf = 1;
5174
5175 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5176 PEER_FLAG_RTT_SHUTDOWN);
5177 }
5178
5179 /* neighbor capability dynamic. */
5180 DEFUN (neighbor_capability_dynamic,
5181 neighbor_capability_dynamic_cmd,
5182 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5183 NEIGHBOR_STR
5184 NEIGHBOR_ADDR_STR2
5185 "Advertise capability to the peer\n"
5186 "Advertise dynamic capability to this neighbor\n")
5187 {
5188 int idx_peer = 1;
5189 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5190 PEER_FLAG_DYNAMIC_CAPABILITY);
5191 }
5192
5193 DEFUN (no_neighbor_capability_dynamic,
5194 no_neighbor_capability_dynamic_cmd,
5195 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5196 NO_STR
5197 NEIGHBOR_STR
5198 NEIGHBOR_ADDR_STR2
5199 "Advertise capability to the peer\n"
5200 "Advertise dynamic capability to this neighbor\n")
5201 {
5202 int idx_peer = 2;
5203 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5204 PEER_FLAG_DYNAMIC_CAPABILITY);
5205 }
5206
5207 /* neighbor dont-capability-negotiate */
5208 DEFUN (neighbor_dont_capability_negotiate,
5209 neighbor_dont_capability_negotiate_cmd,
5210 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5211 NEIGHBOR_STR
5212 NEIGHBOR_ADDR_STR2
5213 "Do not perform capability negotiation\n")
5214 {
5215 int idx_peer = 1;
5216 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5217 PEER_FLAG_DONT_CAPABILITY);
5218 }
5219
5220 DEFUN (no_neighbor_dont_capability_negotiate,
5221 no_neighbor_dont_capability_negotiate_cmd,
5222 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5223 NO_STR
5224 NEIGHBOR_STR
5225 NEIGHBOR_ADDR_STR2
5226 "Do not perform capability negotiation\n")
5227 {
5228 int idx_peer = 2;
5229 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5230 PEER_FLAG_DONT_CAPABILITY);
5231 }
5232
5233 /* neighbor capability extended next hop encoding */
5234 DEFUN (neighbor_capability_enhe,
5235 neighbor_capability_enhe_cmd,
5236 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5237 NEIGHBOR_STR
5238 NEIGHBOR_ADDR_STR2
5239 "Advertise capability to the peer\n"
5240 "Advertise extended next-hop capability to the peer\n")
5241 {
5242 int idx_peer = 1;
5243 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5244 PEER_FLAG_CAPABILITY_ENHE);
5245 }
5246
5247 DEFUN (no_neighbor_capability_enhe,
5248 no_neighbor_capability_enhe_cmd,
5249 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5250 NO_STR
5251 NEIGHBOR_STR
5252 NEIGHBOR_ADDR_STR2
5253 "Advertise capability to the peer\n"
5254 "Advertise extended next-hop capability to the peer\n")
5255 {
5256 int idx_peer = 2;
5257 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5258 PEER_FLAG_CAPABILITY_ENHE);
5259 }
5260
5261 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5262 afi_t afi, safi_t safi, uint32_t flag,
5263 int set)
5264 {
5265 int ret;
5266 struct peer *peer;
5267
5268 peer = peer_and_group_lookup_vty(vty, peer_str);
5269 if (!peer)
5270 return CMD_WARNING_CONFIG_FAILED;
5271
5272 if (set)
5273 ret = peer_af_flag_set(peer, afi, safi, flag);
5274 else
5275 ret = peer_af_flag_unset(peer, afi, safi, flag);
5276
5277 return bgp_vty_return(vty, ret);
5278 }
5279
5280 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5281 afi_t afi, safi_t safi, uint32_t flag)
5282 {
5283 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5284 }
5285
5286 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5287 afi_t afi, safi_t safi, uint32_t flag)
5288 {
5289 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5290 }
5291
5292 /* neighbor capability orf prefix-list. */
5293 DEFUN (neighbor_capability_orf_prefix,
5294 neighbor_capability_orf_prefix_cmd,
5295 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5296 NEIGHBOR_STR
5297 NEIGHBOR_ADDR_STR2
5298 "Advertise capability to the peer\n"
5299 "Advertise ORF capability to the peer\n"
5300 "Advertise prefixlist ORF capability to this neighbor\n"
5301 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5302 "Capability to RECEIVE the ORF from this neighbor\n"
5303 "Capability to SEND the ORF to this neighbor\n")
5304 {
5305 int idx_send_recv = 5;
5306 char *peer_str = argv[1]->arg;
5307 struct peer *peer;
5308 afi_t afi = bgp_node_afi(vty);
5309 safi_t safi = bgp_node_safi(vty);
5310
5311 peer = peer_and_group_lookup_vty(vty, peer_str);
5312 if (!peer)
5313 return CMD_WARNING_CONFIG_FAILED;
5314
5315 if (strmatch(argv[idx_send_recv]->text, "send"))
5316 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5317 PEER_FLAG_ORF_PREFIX_SM);
5318
5319 if (strmatch(argv[idx_send_recv]->text, "receive"))
5320 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5321 PEER_FLAG_ORF_PREFIX_RM);
5322
5323 if (strmatch(argv[idx_send_recv]->text, "both"))
5324 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5325 PEER_FLAG_ORF_PREFIX_SM)
5326 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5327 PEER_FLAG_ORF_PREFIX_RM);
5328
5329 return CMD_WARNING_CONFIG_FAILED;
5330 }
5331
5332 ALIAS_HIDDEN(
5333 neighbor_capability_orf_prefix,
5334 neighbor_capability_orf_prefix_hidden_cmd,
5335 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5336 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5337 "Advertise capability to the peer\n"
5338 "Advertise ORF capability to the peer\n"
5339 "Advertise prefixlist ORF capability to this neighbor\n"
5340 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5341 "Capability to RECEIVE the ORF from this neighbor\n"
5342 "Capability to SEND the ORF to this neighbor\n")
5343
5344 DEFUN (no_neighbor_capability_orf_prefix,
5345 no_neighbor_capability_orf_prefix_cmd,
5346 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5347 NO_STR
5348 NEIGHBOR_STR
5349 NEIGHBOR_ADDR_STR2
5350 "Advertise capability to the peer\n"
5351 "Advertise ORF capability to the peer\n"
5352 "Advertise prefixlist ORF capability to this neighbor\n"
5353 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5354 "Capability to RECEIVE the ORF from this neighbor\n"
5355 "Capability to SEND the ORF to this neighbor\n")
5356 {
5357 int idx_send_recv = 6;
5358 char *peer_str = argv[2]->arg;
5359 struct peer *peer;
5360 afi_t afi = bgp_node_afi(vty);
5361 safi_t safi = bgp_node_safi(vty);
5362
5363 peer = peer_and_group_lookup_vty(vty, peer_str);
5364 if (!peer)
5365 return CMD_WARNING_CONFIG_FAILED;
5366
5367 if (strmatch(argv[idx_send_recv]->text, "send"))
5368 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5369 PEER_FLAG_ORF_PREFIX_SM);
5370
5371 if (strmatch(argv[idx_send_recv]->text, "receive"))
5372 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5373 PEER_FLAG_ORF_PREFIX_RM);
5374
5375 if (strmatch(argv[idx_send_recv]->text, "both"))
5376 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5377 PEER_FLAG_ORF_PREFIX_SM)
5378 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5379 PEER_FLAG_ORF_PREFIX_RM);
5380
5381 return CMD_WARNING_CONFIG_FAILED;
5382 }
5383
5384 ALIAS_HIDDEN(
5385 no_neighbor_capability_orf_prefix,
5386 no_neighbor_capability_orf_prefix_hidden_cmd,
5387 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5388 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5389 "Advertise capability to the peer\n"
5390 "Advertise ORF capability to the peer\n"
5391 "Advertise prefixlist ORF capability to this neighbor\n"
5392 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5393 "Capability to RECEIVE the ORF from this neighbor\n"
5394 "Capability to SEND the ORF to this neighbor\n")
5395
5396 /* neighbor next-hop-self. */
5397 DEFUN (neighbor_nexthop_self,
5398 neighbor_nexthop_self_cmd,
5399 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5400 NEIGHBOR_STR
5401 NEIGHBOR_ADDR_STR2
5402 "Disable the next hop calculation for this neighbor\n")
5403 {
5404 int idx_peer = 1;
5405 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5406 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5407 }
5408
5409 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5410 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5411 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5412 "Disable the next hop calculation for this neighbor\n")
5413
5414 /* neighbor next-hop-self. */
5415 DEFUN (neighbor_nexthop_self_force,
5416 neighbor_nexthop_self_force_cmd,
5417 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5418 NEIGHBOR_STR
5419 NEIGHBOR_ADDR_STR2
5420 "Disable the next hop calculation for this neighbor\n"
5421 "Set the next hop to self for reflected routes\n")
5422 {
5423 int idx_peer = 1;
5424 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5425 bgp_node_safi(vty),
5426 PEER_FLAG_FORCE_NEXTHOP_SELF);
5427 }
5428
5429 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5430 neighbor_nexthop_self_force_hidden_cmd,
5431 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5432 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5433 "Disable the next hop calculation for this neighbor\n"
5434 "Set the next hop to self for reflected routes\n")
5435
5436 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5437 neighbor_nexthop_self_all_hidden_cmd,
5438 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5439 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5440 "Disable the next hop calculation for this neighbor\n"
5441 "Set the next hop to self for reflected routes\n")
5442
5443 DEFUN (no_neighbor_nexthop_self,
5444 no_neighbor_nexthop_self_cmd,
5445 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5446 NO_STR
5447 NEIGHBOR_STR
5448 NEIGHBOR_ADDR_STR2
5449 "Disable the next hop calculation for this neighbor\n")
5450 {
5451 int idx_peer = 2;
5452 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5453 bgp_node_afi(vty), bgp_node_safi(vty),
5454 PEER_FLAG_NEXTHOP_SELF);
5455 }
5456
5457 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5458 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5459 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5460 "Disable the next hop calculation for this neighbor\n")
5461
5462 DEFUN (no_neighbor_nexthop_self_force,
5463 no_neighbor_nexthop_self_force_cmd,
5464 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5465 NO_STR
5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR2
5468 "Disable the next hop calculation for this neighbor\n"
5469 "Set the next hop to self for reflected routes\n")
5470 {
5471 int idx_peer = 2;
5472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5473 bgp_node_afi(vty), bgp_node_safi(vty),
5474 PEER_FLAG_FORCE_NEXTHOP_SELF);
5475 }
5476
5477 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5478 no_neighbor_nexthop_self_force_hidden_cmd,
5479 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5481 "Disable the next hop calculation for this neighbor\n"
5482 "Set the next hop to self for reflected routes\n")
5483
5484 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5485 no_neighbor_nexthop_self_all_hidden_cmd,
5486 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5487 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5488 "Disable the next hop calculation for this neighbor\n"
5489 "Set the next hop to self for reflected routes\n")
5490
5491 /* neighbor as-override */
5492 DEFUN (neighbor_as_override,
5493 neighbor_as_override_cmd,
5494 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5495 NEIGHBOR_STR
5496 NEIGHBOR_ADDR_STR2
5497 "Override ASNs in outbound updates if aspath equals remote-as\n")
5498 {
5499 int idx_peer = 1;
5500 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5501 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5502 }
5503
5504 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5505 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5507 "Override ASNs in outbound updates if aspath equals remote-as\n")
5508
5509 DEFUN (no_neighbor_as_override,
5510 no_neighbor_as_override_cmd,
5511 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5512 NO_STR
5513 NEIGHBOR_STR
5514 NEIGHBOR_ADDR_STR2
5515 "Override ASNs in outbound updates if aspath equals remote-as\n")
5516 {
5517 int idx_peer = 2;
5518 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5519 bgp_node_afi(vty), bgp_node_safi(vty),
5520 PEER_FLAG_AS_OVERRIDE);
5521 }
5522
5523 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5524 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5525 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5526 "Override ASNs in outbound updates if aspath equals remote-as\n")
5527
5528 /* neighbor remove-private-AS. */
5529 DEFUN (neighbor_remove_private_as,
5530 neighbor_remove_private_as_cmd,
5531 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5532 NEIGHBOR_STR
5533 NEIGHBOR_ADDR_STR2
5534 "Remove private ASNs in outbound updates\n")
5535 {
5536 int idx_peer = 1;
5537 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5538 bgp_node_safi(vty),
5539 PEER_FLAG_REMOVE_PRIVATE_AS);
5540 }
5541
5542 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5543 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5544 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5545 "Remove private ASNs in outbound updates\n")
5546
5547 DEFUN (neighbor_remove_private_as_all,
5548 neighbor_remove_private_as_all_cmd,
5549 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5550 NEIGHBOR_STR
5551 NEIGHBOR_ADDR_STR2
5552 "Remove private ASNs in outbound updates\n"
5553 "Apply to all AS numbers\n")
5554 {
5555 int idx_peer = 1;
5556 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5557 bgp_node_safi(vty),
5558 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5559 }
5560
5561 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5562 neighbor_remove_private_as_all_hidden_cmd,
5563 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5564 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5565 "Remove private ASNs in outbound updates\n"
5566 "Apply to all AS numbers")
5567
5568 DEFUN (neighbor_remove_private_as_replace_as,
5569 neighbor_remove_private_as_replace_as_cmd,
5570 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5571 NEIGHBOR_STR
5572 NEIGHBOR_ADDR_STR2
5573 "Remove private ASNs in outbound updates\n"
5574 "Replace private ASNs with our ASN in outbound updates\n")
5575 {
5576 int idx_peer = 1;
5577 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5578 bgp_node_safi(vty),
5579 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5580 }
5581
5582 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5583 neighbor_remove_private_as_replace_as_hidden_cmd,
5584 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5585 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5586 "Remove private ASNs in outbound updates\n"
5587 "Replace private ASNs with our ASN in outbound updates\n")
5588
5589 DEFUN (neighbor_remove_private_as_all_replace_as,
5590 neighbor_remove_private_as_all_replace_as_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5592 NEIGHBOR_STR
5593 NEIGHBOR_ADDR_STR2
5594 "Remove private ASNs in outbound updates\n"
5595 "Apply to all AS numbers\n"
5596 "Replace private ASNs with our ASN in outbound updates\n")
5597 {
5598 int idx_peer = 1;
5599 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5600 bgp_node_safi(vty),
5601 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5602 }
5603
5604 ALIAS_HIDDEN(
5605 neighbor_remove_private_as_all_replace_as,
5606 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5607 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5608 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5609 "Remove private ASNs in outbound updates\n"
5610 "Apply to all AS numbers\n"
5611 "Replace private ASNs with our ASN in outbound updates\n")
5612
5613 DEFUN (no_neighbor_remove_private_as,
5614 no_neighbor_remove_private_as_cmd,
5615 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5616 NO_STR
5617 NEIGHBOR_STR
5618 NEIGHBOR_ADDR_STR2
5619 "Remove private ASNs in outbound updates\n")
5620 {
5621 int idx_peer = 2;
5622 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5623 bgp_node_afi(vty), bgp_node_safi(vty),
5624 PEER_FLAG_REMOVE_PRIVATE_AS);
5625 }
5626
5627 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5628 no_neighbor_remove_private_as_hidden_cmd,
5629 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5630 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Remove private ASNs in outbound updates\n")
5632
5633 DEFUN (no_neighbor_remove_private_as_all,
5634 no_neighbor_remove_private_as_all_cmd,
5635 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5636 NO_STR
5637 NEIGHBOR_STR
5638 NEIGHBOR_ADDR_STR2
5639 "Remove private ASNs in outbound updates\n"
5640 "Apply to all AS numbers\n")
5641 {
5642 int idx_peer = 2;
5643 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5644 bgp_node_afi(vty), bgp_node_safi(vty),
5645 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5646 }
5647
5648 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5649 no_neighbor_remove_private_as_all_hidden_cmd,
5650 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5651 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5652 "Remove private ASNs in outbound updates\n"
5653 "Apply to all AS numbers\n")
5654
5655 DEFUN (no_neighbor_remove_private_as_replace_as,
5656 no_neighbor_remove_private_as_replace_as_cmd,
5657 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5658 NO_STR
5659 NEIGHBOR_STR
5660 NEIGHBOR_ADDR_STR2
5661 "Remove private ASNs in outbound updates\n"
5662 "Replace private ASNs with our ASN in outbound updates\n")
5663 {
5664 int idx_peer = 2;
5665 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5666 bgp_node_afi(vty), bgp_node_safi(vty),
5667 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5668 }
5669
5670 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5671 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5672 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5674 "Remove private ASNs in outbound updates\n"
5675 "Replace private ASNs with our ASN in outbound updates\n")
5676
5677 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5678 no_neighbor_remove_private_as_all_replace_as_cmd,
5679 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5680 NO_STR
5681 NEIGHBOR_STR
5682 NEIGHBOR_ADDR_STR2
5683 "Remove private ASNs in outbound updates\n"
5684 "Apply to all AS numbers\n"
5685 "Replace private ASNs with our ASN in outbound updates\n")
5686 {
5687 int idx_peer = 2;
5688 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5689 bgp_node_afi(vty), bgp_node_safi(vty),
5690 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5691 }
5692
5693 ALIAS_HIDDEN(
5694 no_neighbor_remove_private_as_all_replace_as,
5695 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5696 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5697 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5698 "Remove private ASNs in outbound updates\n"
5699 "Apply to all AS numbers\n"
5700 "Replace private ASNs with our ASN in outbound updates\n")
5701
5702
5703 /* neighbor send-community. */
5704 DEFUN (neighbor_send_community,
5705 neighbor_send_community_cmd,
5706 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5707 NEIGHBOR_STR
5708 NEIGHBOR_ADDR_STR2
5709 "Send Community attribute to this neighbor\n")
5710 {
5711 int idx_peer = 1;
5712
5713 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5714 bgp_node_safi(vty),
5715 PEER_FLAG_SEND_COMMUNITY);
5716 }
5717
5718 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5720 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5721 "Send Community attribute to this neighbor\n")
5722
5723 DEFUN (no_neighbor_send_community,
5724 no_neighbor_send_community_cmd,
5725 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5726 NO_STR
5727 NEIGHBOR_STR
5728 NEIGHBOR_ADDR_STR2
5729 "Send Community attribute to this neighbor\n")
5730 {
5731 int idx_peer = 2;
5732
5733 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5734 bgp_node_afi(vty), bgp_node_safi(vty),
5735 PEER_FLAG_SEND_COMMUNITY);
5736 }
5737
5738 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Send Community attribute to this neighbor\n")
5742
5743 /* neighbor send-community extended. */
5744 DEFUN (neighbor_send_community_type,
5745 neighbor_send_community_type_cmd,
5746 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5747 NEIGHBOR_STR
5748 NEIGHBOR_ADDR_STR2
5749 "Send Community attribute to this neighbor\n"
5750 "Send Standard and Extended Community attributes\n"
5751 "Send Standard, Large and Extended Community attributes\n"
5752 "Send Extended Community attributes\n"
5753 "Send Standard Community attributes\n"
5754 "Send Large Community attributes\n")
5755 {
5756 const char *type = argv[argc - 1]->text;
5757 char *peer_str = argv[1]->arg;
5758 struct peer *peer;
5759 afi_t afi = bgp_node_afi(vty);
5760 safi_t safi = bgp_node_safi(vty);
5761
5762 peer = peer_and_group_lookup_vty(vty, peer_str);
5763 if (!peer)
5764 return CMD_WARNING_CONFIG_FAILED;
5765
5766 if (strmatch(type, "standard"))
5767 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5768 PEER_FLAG_SEND_COMMUNITY);
5769
5770 if (strmatch(type, "extended"))
5771 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5772 PEER_FLAG_SEND_EXT_COMMUNITY);
5773
5774 if (strmatch(type, "large"))
5775 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5776 PEER_FLAG_SEND_LARGE_COMMUNITY);
5777
5778 if (strmatch(type, "both")) {
5779 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5780 PEER_FLAG_SEND_COMMUNITY)
5781 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5782 PEER_FLAG_SEND_EXT_COMMUNITY);
5783 }
5784 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5785 PEER_FLAG_SEND_COMMUNITY)
5786 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5787 PEER_FLAG_SEND_EXT_COMMUNITY)
5788 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5789 PEER_FLAG_SEND_LARGE_COMMUNITY);
5790 }
5791
5792 ALIAS_HIDDEN(
5793 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5794 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5795 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5796 "Send Community attribute to this neighbor\n"
5797 "Send Standard and Extended Community attributes\n"
5798 "Send Standard, Large and Extended Community attributes\n"
5799 "Send Extended Community attributes\n"
5800 "Send Standard Community attributes\n"
5801 "Send Large Community attributes\n")
5802
5803 DEFUN (no_neighbor_send_community_type,
5804 no_neighbor_send_community_type_cmd,
5805 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5806 NO_STR
5807 NEIGHBOR_STR
5808 NEIGHBOR_ADDR_STR2
5809 "Send Community attribute to this neighbor\n"
5810 "Send Standard and Extended Community attributes\n"
5811 "Send Standard, Large and Extended Community attributes\n"
5812 "Send Extended Community attributes\n"
5813 "Send Standard Community attributes\n"
5814 "Send Large Community attributes\n")
5815 {
5816 const char *type = argv[argc - 1]->text;
5817 char *peer_str = argv[2]->arg;
5818 struct peer *peer;
5819 afi_t afi = bgp_node_afi(vty);
5820 safi_t safi = bgp_node_safi(vty);
5821
5822 peer = peer_and_group_lookup_vty(vty, peer_str);
5823 if (!peer)
5824 return CMD_WARNING_CONFIG_FAILED;
5825
5826 if (strmatch(type, "standard"))
5827 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5828 PEER_FLAG_SEND_COMMUNITY);
5829
5830 if (strmatch(type, "extended"))
5831 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5832 PEER_FLAG_SEND_EXT_COMMUNITY);
5833
5834 if (strmatch(type, "large"))
5835 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5836 PEER_FLAG_SEND_LARGE_COMMUNITY);
5837
5838 if (strmatch(type, "both")) {
5839
5840 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5841 PEER_FLAG_SEND_COMMUNITY)
5842 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5843 PEER_FLAG_SEND_EXT_COMMUNITY);
5844 }
5845
5846 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5847 PEER_FLAG_SEND_COMMUNITY)
5848 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5849 PEER_FLAG_SEND_EXT_COMMUNITY)
5850 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5851 PEER_FLAG_SEND_LARGE_COMMUNITY);
5852 }
5853
5854 ALIAS_HIDDEN(
5855 no_neighbor_send_community_type,
5856 no_neighbor_send_community_type_hidden_cmd,
5857 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5858 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5859 "Send Community attribute to this neighbor\n"
5860 "Send Standard and Extended Community attributes\n"
5861 "Send Standard, Large and Extended Community attributes\n"
5862 "Send Extended Community attributes\n"
5863 "Send Standard Community attributes\n"
5864 "Send Large Community attributes\n")
5865
5866 /* neighbor soft-reconfig. */
5867 DEFUN (neighbor_soft_reconfiguration,
5868 neighbor_soft_reconfiguration_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Per neighbor soft reconfiguration\n"
5873 "Allow inbound soft reconfiguration for this neighbor\n")
5874 {
5875 int idx_peer = 1;
5876 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5877 bgp_node_safi(vty),
5878 PEER_FLAG_SOFT_RECONFIG);
5879 }
5880
5881 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5882 neighbor_soft_reconfiguration_hidden_cmd,
5883 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5885 "Per neighbor soft reconfiguration\n"
5886 "Allow inbound soft reconfiguration for this neighbor\n")
5887
5888 DEFUN (no_neighbor_soft_reconfiguration,
5889 no_neighbor_soft_reconfiguration_cmd,
5890 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5891 NO_STR
5892 NEIGHBOR_STR
5893 NEIGHBOR_ADDR_STR2
5894 "Per neighbor soft reconfiguration\n"
5895 "Allow inbound soft reconfiguration for this neighbor\n")
5896 {
5897 int idx_peer = 2;
5898 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5899 bgp_node_afi(vty), bgp_node_safi(vty),
5900 PEER_FLAG_SOFT_RECONFIG);
5901 }
5902
5903 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5904 no_neighbor_soft_reconfiguration_hidden_cmd,
5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5906 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5907 "Per neighbor soft reconfiguration\n"
5908 "Allow inbound soft reconfiguration for this neighbor\n")
5909
5910 DEFUN (neighbor_route_reflector_client,
5911 neighbor_route_reflector_client_cmd,
5912 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5913 NEIGHBOR_STR
5914 NEIGHBOR_ADDR_STR2
5915 "Configure a neighbor as Route Reflector client\n")
5916 {
5917 int idx_peer = 1;
5918 struct peer *peer;
5919
5920
5921 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5922 if (!peer)
5923 return CMD_WARNING_CONFIG_FAILED;
5924
5925 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5926 bgp_node_safi(vty),
5927 PEER_FLAG_REFLECTOR_CLIENT);
5928 }
5929
5930 ALIAS_HIDDEN(neighbor_route_reflector_client,
5931 neighbor_route_reflector_client_hidden_cmd,
5932 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5934 "Configure a neighbor as Route Reflector client\n")
5935
5936 DEFUN (no_neighbor_route_reflector_client,
5937 no_neighbor_route_reflector_client_cmd,
5938 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5939 NO_STR
5940 NEIGHBOR_STR
5941 NEIGHBOR_ADDR_STR2
5942 "Configure a neighbor as Route Reflector client\n")
5943 {
5944 int idx_peer = 2;
5945 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5946 bgp_node_afi(vty), bgp_node_safi(vty),
5947 PEER_FLAG_REFLECTOR_CLIENT);
5948 }
5949
5950 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5951 no_neighbor_route_reflector_client_hidden_cmd,
5952 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5953 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5954 "Configure a neighbor as Route Reflector client\n")
5955
5956 /* neighbor route-server-client. */
5957 DEFUN (neighbor_route_server_client,
5958 neighbor_route_server_client_cmd,
5959 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5960 NEIGHBOR_STR
5961 NEIGHBOR_ADDR_STR2
5962 "Configure a neighbor as Route Server client\n")
5963 {
5964 int idx_peer = 1;
5965 struct peer *peer;
5966
5967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5968 if (!peer)
5969 return CMD_WARNING_CONFIG_FAILED;
5970 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5971 bgp_node_safi(vty),
5972 PEER_FLAG_RSERVER_CLIENT);
5973 }
5974
5975 ALIAS_HIDDEN(neighbor_route_server_client,
5976 neighbor_route_server_client_hidden_cmd,
5977 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5978 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5979 "Configure a neighbor as Route Server client\n")
5980
5981 DEFUN (no_neighbor_route_server_client,
5982 no_neighbor_route_server_client_cmd,
5983 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5984 NO_STR
5985 NEIGHBOR_STR
5986 NEIGHBOR_ADDR_STR2
5987 "Configure a neighbor as Route Server client\n")
5988 {
5989 int idx_peer = 2;
5990 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5991 bgp_node_afi(vty), bgp_node_safi(vty),
5992 PEER_FLAG_RSERVER_CLIENT);
5993 }
5994
5995 ALIAS_HIDDEN(no_neighbor_route_server_client,
5996 no_neighbor_route_server_client_hidden_cmd,
5997 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5998 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5999 "Configure a neighbor as Route Server client\n")
6000
6001 DEFUN (neighbor_nexthop_local_unchanged,
6002 neighbor_nexthop_local_unchanged_cmd,
6003 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6004 NEIGHBOR_STR
6005 NEIGHBOR_ADDR_STR2
6006 "Configure treatment of outgoing link-local nexthop attribute\n"
6007 "Leave link-local nexthop unchanged for this peer\n")
6008 {
6009 int idx_peer = 1;
6010 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6011 bgp_node_safi(vty),
6012 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6013 }
6014
6015 DEFUN (no_neighbor_nexthop_local_unchanged,
6016 no_neighbor_nexthop_local_unchanged_cmd,
6017 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6018 NO_STR
6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "Configure treatment of outgoing link-local-nexthop attribute\n"
6022 "Leave link-local nexthop unchanged for this peer\n")
6023 {
6024 int idx_peer = 2;
6025 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6026 bgp_node_afi(vty), bgp_node_safi(vty),
6027 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6028 }
6029
6030 DEFUN (neighbor_attr_unchanged,
6031 neighbor_attr_unchanged_cmd,
6032 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "BGP attribute is propagated unchanged to this neighbor\n"
6036 "As-path attribute\n"
6037 "Nexthop attribute\n"
6038 "Med attribute\n")
6039 {
6040 int idx = 0;
6041 char *peer_str = argv[1]->arg;
6042 struct peer *peer;
6043 bool aspath = false;
6044 bool nexthop = false;
6045 bool med = false;
6046 afi_t afi = bgp_node_afi(vty);
6047 safi_t safi = bgp_node_safi(vty);
6048 int ret = 0;
6049
6050 peer = peer_and_group_lookup_vty(vty, peer_str);
6051 if (!peer)
6052 return CMD_WARNING_CONFIG_FAILED;
6053
6054 if (argv_find(argv, argc, "as-path", &idx))
6055 aspath = true;
6056
6057 idx = 0;
6058 if (argv_find(argv, argc, "next-hop", &idx))
6059 nexthop = true;
6060
6061 idx = 0;
6062 if (argv_find(argv, argc, "med", &idx))
6063 med = true;
6064
6065 /* no flags means all of them! */
6066 if (!aspath && !nexthop && !med) {
6067 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6068 PEER_FLAG_AS_PATH_UNCHANGED);
6069 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6070 PEER_FLAG_NEXTHOP_UNCHANGED);
6071 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6072 PEER_FLAG_MED_UNCHANGED);
6073 } else {
6074 if (!aspath) {
6075 if (peer_af_flag_check(peer, afi, safi,
6076 PEER_FLAG_AS_PATH_UNCHANGED)) {
6077 ret |= peer_af_flag_unset_vty(
6078 vty, peer_str, afi, safi,
6079 PEER_FLAG_AS_PATH_UNCHANGED);
6080 }
6081 } else
6082 ret |= peer_af_flag_set_vty(
6083 vty, peer_str, afi, safi,
6084 PEER_FLAG_AS_PATH_UNCHANGED);
6085
6086 if (!nexthop) {
6087 if (peer_af_flag_check(peer, afi, safi,
6088 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6089 ret |= peer_af_flag_unset_vty(
6090 vty, peer_str, afi, safi,
6091 PEER_FLAG_NEXTHOP_UNCHANGED);
6092 }
6093 } else
6094 ret |= peer_af_flag_set_vty(
6095 vty, peer_str, afi, safi,
6096 PEER_FLAG_NEXTHOP_UNCHANGED);
6097
6098 if (!med) {
6099 if (peer_af_flag_check(peer, afi, safi,
6100 PEER_FLAG_MED_UNCHANGED)) {
6101 ret |= peer_af_flag_unset_vty(
6102 vty, peer_str, afi, safi,
6103 PEER_FLAG_MED_UNCHANGED);
6104 }
6105 } else
6106 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6107 PEER_FLAG_MED_UNCHANGED);
6108 }
6109
6110 return ret;
6111 }
6112
6113 ALIAS_HIDDEN(
6114 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6115 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6116 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6117 "BGP attribute is propagated unchanged to this neighbor\n"
6118 "As-path attribute\n"
6119 "Nexthop attribute\n"
6120 "Med attribute\n")
6121
6122 DEFUN (no_neighbor_attr_unchanged,
6123 no_neighbor_attr_unchanged_cmd,
6124 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6125 NO_STR
6126 NEIGHBOR_STR
6127 NEIGHBOR_ADDR_STR2
6128 "BGP attribute is propagated unchanged to this neighbor\n"
6129 "As-path attribute\n"
6130 "Nexthop attribute\n"
6131 "Med attribute\n")
6132 {
6133 int idx = 0;
6134 char *peer_str = argv[2]->arg;
6135 struct peer *peer;
6136 bool aspath = false;
6137 bool nexthop = false;
6138 bool med = false;
6139 afi_t afi = bgp_node_afi(vty);
6140 safi_t safi = bgp_node_safi(vty);
6141 int ret = 0;
6142
6143 peer = peer_and_group_lookup_vty(vty, peer_str);
6144 if (!peer)
6145 return CMD_WARNING_CONFIG_FAILED;
6146
6147 if (argv_find(argv, argc, "as-path", &idx))
6148 aspath = true;
6149
6150 idx = 0;
6151 if (argv_find(argv, argc, "next-hop", &idx))
6152 nexthop = true;
6153
6154 idx = 0;
6155 if (argv_find(argv, argc, "med", &idx))
6156 med = true;
6157
6158 if (!aspath && !nexthop && !med) // no flags means all of them!
6159 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6160 PEER_FLAG_AS_PATH_UNCHANGED)
6161 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6162 PEER_FLAG_NEXTHOP_UNCHANGED)
6163 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6164 PEER_FLAG_MED_UNCHANGED);
6165
6166 if (aspath)
6167 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6168 PEER_FLAG_AS_PATH_UNCHANGED);
6169
6170 if (nexthop)
6171 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6172 PEER_FLAG_NEXTHOP_UNCHANGED);
6173
6174 if (med)
6175 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6176 PEER_FLAG_MED_UNCHANGED);
6177
6178 return ret;
6179 }
6180
6181 ALIAS_HIDDEN(
6182 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6185 "BGP attribute is propagated unchanged to this neighbor\n"
6186 "As-path attribute\n"
6187 "Nexthop attribute\n"
6188 "Med attribute\n")
6189
6190 /* EBGP multihop configuration. */
6191 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6192 const char *ttl_str)
6193 {
6194 struct peer *peer;
6195 unsigned int ttl;
6196
6197 peer = peer_and_group_lookup_vty(vty, ip_str);
6198 if (!peer)
6199 return CMD_WARNING_CONFIG_FAILED;
6200
6201 if (peer->conf_if)
6202 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6203
6204 if (!ttl_str)
6205 ttl = MAXTTL;
6206 else
6207 ttl = strtoul(ttl_str, NULL, 10);
6208
6209 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6210 }
6211
6212 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6213 {
6214 struct peer *peer;
6215
6216 peer = peer_and_group_lookup_vty(vty, ip_str);
6217 if (!peer)
6218 return CMD_WARNING_CONFIG_FAILED;
6219
6220 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6221 }
6222
6223 /* neighbor ebgp-multihop. */
6224 DEFUN (neighbor_ebgp_multihop,
6225 neighbor_ebgp_multihop_cmd,
6226 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6227 NEIGHBOR_STR
6228 NEIGHBOR_ADDR_STR2
6229 "Allow EBGP neighbors not on directly connected networks\n")
6230 {
6231 int idx_peer = 1;
6232 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6233 }
6234
6235 DEFUN (neighbor_ebgp_multihop_ttl,
6236 neighbor_ebgp_multihop_ttl_cmd,
6237 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6238 NEIGHBOR_STR
6239 NEIGHBOR_ADDR_STR2
6240 "Allow EBGP neighbors not on directly connected networks\n"
6241 "maximum hop count\n")
6242 {
6243 int idx_peer = 1;
6244 int idx_number = 3;
6245 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6246 argv[idx_number]->arg);
6247 }
6248
6249 DEFUN (no_neighbor_ebgp_multihop,
6250 no_neighbor_ebgp_multihop_cmd,
6251 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6252 NO_STR
6253 NEIGHBOR_STR
6254 NEIGHBOR_ADDR_STR2
6255 "Allow EBGP neighbors not on directly connected networks\n"
6256 "maximum hop count\n")
6257 {
6258 int idx_peer = 2;
6259 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6260 }
6261
6262
6263 /* disable-connected-check */
6264 DEFUN (neighbor_disable_connected_check,
6265 neighbor_disable_connected_check_cmd,
6266 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6267 NEIGHBOR_STR
6268 NEIGHBOR_ADDR_STR2
6269 "one-hop away EBGP peer using loopback address\n"
6270 "Enforce EBGP neighbors perform multihop\n")
6271 {
6272 int idx_peer = 1;
6273 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6274 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6275 }
6276
6277 DEFUN (no_neighbor_disable_connected_check,
6278 no_neighbor_disable_connected_check_cmd,
6279 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6280 NO_STR
6281 NEIGHBOR_STR
6282 NEIGHBOR_ADDR_STR2
6283 "one-hop away EBGP peer using loopback address\n"
6284 "Enforce EBGP neighbors perform multihop\n")
6285 {
6286 int idx_peer = 2;
6287 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6288 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6289 }
6290
6291 /* disable-link-bw-encoding-ieee */
6292 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6293 neighbor_disable_link_bw_encoding_ieee_cmd,
6294 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6295 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6296 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6297 {
6298 int idx_peer = 1;
6299
6300 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6301 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6302 }
6303
6304 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6305 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6306 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6308 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6309 {
6310 int idx_peer = 2;
6311
6312 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6313 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6314 }
6315
6316 /* extended-optional-parameters */
6317 DEFUN(neighbor_extended_optional_parameters,
6318 neighbor_extended_optional_parameters_cmd,
6319 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6321 "Force the extended optional parameters format for OPEN messages\n")
6322 {
6323 int idx_peer = 1;
6324
6325 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6326 PEER_FLAG_EXTENDED_OPT_PARAMS);
6327 }
6328
6329 DEFUN(no_neighbor_extended_optional_parameters,
6330 no_neighbor_extended_optional_parameters_cmd,
6331 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6332 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6333 "Force the extended optional parameters format for OPEN messages\n")
6334 {
6335 int idx_peer = 2;
6336
6337 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6338 PEER_FLAG_EXTENDED_OPT_PARAMS);
6339 }
6340
6341 /* enforce-first-as */
6342 DEFUN (neighbor_enforce_first_as,
6343 neighbor_enforce_first_as_cmd,
6344 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6345 NEIGHBOR_STR
6346 NEIGHBOR_ADDR_STR2
6347 "Enforce the first AS for EBGP routes\n")
6348 {
6349 int idx_peer = 1;
6350
6351 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6352 PEER_FLAG_ENFORCE_FIRST_AS);
6353 }
6354
6355 DEFUN (no_neighbor_enforce_first_as,
6356 no_neighbor_enforce_first_as_cmd,
6357 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6358 NO_STR
6359 NEIGHBOR_STR
6360 NEIGHBOR_ADDR_STR2
6361 "Enforce the first AS for EBGP routes\n")
6362 {
6363 int idx_peer = 2;
6364
6365 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6366 PEER_FLAG_ENFORCE_FIRST_AS);
6367 }
6368
6369
6370 DEFUN (neighbor_description,
6371 neighbor_description_cmd,
6372 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6373 NEIGHBOR_STR
6374 NEIGHBOR_ADDR_STR2
6375 "Neighbor specific description\n"
6376 "Up to 80 characters describing this neighbor\n")
6377 {
6378 int idx_peer = 1;
6379 int idx_line = 3;
6380 struct peer *peer;
6381 char *str;
6382
6383 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6384 if (!peer)
6385 return CMD_WARNING_CONFIG_FAILED;
6386
6387 str = argv_concat(argv, argc, idx_line);
6388
6389 peer_description_set(peer, str);
6390
6391 XFREE(MTYPE_TMP, str);
6392
6393 return CMD_SUCCESS;
6394 }
6395
6396 DEFUN (no_neighbor_description,
6397 no_neighbor_description_cmd,
6398 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6399 NO_STR
6400 NEIGHBOR_STR
6401 NEIGHBOR_ADDR_STR2
6402 "Neighbor specific description\n")
6403 {
6404 int idx_peer = 2;
6405 struct peer *peer;
6406
6407 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6408 if (!peer)
6409 return CMD_WARNING_CONFIG_FAILED;
6410
6411 peer_description_unset(peer);
6412
6413 return CMD_SUCCESS;
6414 }
6415
6416 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6417 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6418 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6419 "Neighbor specific description\n"
6420 "Up to 80 characters describing this neighbor\n")
6421
6422 /* Neighbor update-source. */
6423 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6424 const char *source_str)
6425 {
6426 struct peer *peer;
6427 struct prefix p;
6428 union sockunion su;
6429
6430 peer = peer_and_group_lookup_vty(vty, peer_str);
6431 if (!peer)
6432 return CMD_WARNING_CONFIG_FAILED;
6433
6434 if (peer->conf_if)
6435 return CMD_WARNING;
6436
6437 if (source_str) {
6438 if (str2sockunion(source_str, &su) == 0)
6439 peer_update_source_addr_set(peer, &su);
6440 else {
6441 if (str2prefix(source_str, &p)) {
6442 vty_out(vty,
6443 "%% Invalid update-source, remove prefix length \n");
6444 return CMD_WARNING_CONFIG_FAILED;
6445 } else
6446 peer_update_source_if_set(peer, source_str);
6447 }
6448 } else
6449 peer_update_source_unset(peer);
6450
6451 return CMD_SUCCESS;
6452 }
6453
6454 #define BGP_UPDATE_SOURCE_HELP_STR \
6455 "IPv4 address\n" \
6456 "IPv6 address\n" \
6457 "Interface name (requires zebra to be running)\n"
6458
6459 DEFUN (neighbor_update_source,
6460 neighbor_update_source_cmd,
6461 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6462 NEIGHBOR_STR
6463 NEIGHBOR_ADDR_STR2
6464 "Source of routing updates\n"
6465 BGP_UPDATE_SOURCE_HELP_STR)
6466 {
6467 int idx_peer = 1;
6468 int idx_peer_2 = 3;
6469 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6470 argv[idx_peer_2]->arg);
6471 }
6472
6473 DEFUN (no_neighbor_update_source,
6474 no_neighbor_update_source_cmd,
6475 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6476 NO_STR
6477 NEIGHBOR_STR
6478 NEIGHBOR_ADDR_STR2
6479 "Source of routing updates\n"
6480 BGP_UPDATE_SOURCE_HELP_STR)
6481 {
6482 int idx_peer = 2;
6483 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6484 }
6485
6486 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6487 afi_t afi, safi_t safi,
6488 const char *rmap, int set)
6489 {
6490 int ret;
6491 struct peer *peer;
6492 struct route_map *route_map = NULL;
6493
6494 peer = peer_and_group_lookup_vty(vty, peer_str);
6495 if (!peer)
6496 return CMD_WARNING_CONFIG_FAILED;
6497
6498 if (set) {
6499 if (rmap)
6500 route_map = route_map_lookup_warn_noexist(vty, rmap);
6501 ret = peer_default_originate_set(peer, afi, safi,
6502 rmap, route_map);
6503 } else
6504 ret = peer_default_originate_unset(peer, afi, safi);
6505
6506 return bgp_vty_return(vty, ret);
6507 }
6508
6509 /* neighbor default-originate. */
6510 DEFUN (neighbor_default_originate,
6511 neighbor_default_originate_cmd,
6512 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6513 NEIGHBOR_STR
6514 NEIGHBOR_ADDR_STR2
6515 "Originate default route to this neighbor\n")
6516 {
6517 int idx_peer = 1;
6518 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6519 bgp_node_afi(vty),
6520 bgp_node_safi(vty), NULL, 1);
6521 }
6522
6523 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6524 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6525 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6526 "Originate default route to this neighbor\n")
6527
6528 DEFUN (neighbor_default_originate_rmap,
6529 neighbor_default_originate_rmap_cmd,
6530 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6531 NEIGHBOR_STR
6532 NEIGHBOR_ADDR_STR2
6533 "Originate default route to this neighbor\n"
6534 "Route-map to specify criteria to originate default\n"
6535 "route-map name\n")
6536 {
6537 int idx_peer = 1;
6538 int idx_word = 4;
6539 return peer_default_originate_set_vty(
6540 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6541 argv[idx_word]->arg, 1);
6542 }
6543
6544 ALIAS_HIDDEN(
6545 neighbor_default_originate_rmap,
6546 neighbor_default_originate_rmap_hidden_cmd,
6547 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6549 "Originate default route to this neighbor\n"
6550 "Route-map to specify criteria to originate default\n"
6551 "route-map name\n")
6552
6553 DEFUN (no_neighbor_default_originate,
6554 no_neighbor_default_originate_cmd,
6555 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6556 NO_STR
6557 NEIGHBOR_STR
6558 NEIGHBOR_ADDR_STR2
6559 "Originate default route to this neighbor\n"
6560 "Route-map to specify criteria to originate default\n"
6561 "route-map name\n")
6562 {
6563 int idx_peer = 2;
6564 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6565 bgp_node_afi(vty),
6566 bgp_node_safi(vty), NULL, 0);
6567 }
6568
6569 ALIAS_HIDDEN(
6570 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6571 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6572 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6573 "Originate default route to this neighbor\n"
6574 "Route-map to specify criteria to originate default\n"
6575 "route-map name\n")
6576
6577
6578 /* Set neighbor's BGP port. */
6579 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6580 const char *port_str)
6581 {
6582 struct peer *peer;
6583 uint16_t port;
6584 struct servent *sp;
6585
6586 peer = peer_lookup_vty(vty, ip_str);
6587 if (!peer)
6588 return CMD_WARNING_CONFIG_FAILED;
6589
6590 if (!port_str) {
6591 sp = getservbyname("bgp", "tcp");
6592 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6593 } else {
6594 port = strtoul(port_str, NULL, 10);
6595 }
6596
6597 peer_port_set(peer, port);
6598
6599 return CMD_SUCCESS;
6600 }
6601
6602 /* Set specified peer's BGP port. */
6603 DEFUN (neighbor_port,
6604 neighbor_port_cmd,
6605 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6606 NEIGHBOR_STR
6607 NEIGHBOR_ADDR_STR
6608 "Neighbor's BGP port\n"
6609 "TCP port number\n")
6610 {
6611 int idx_ip = 1;
6612 int idx_number = 3;
6613 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6614 argv[idx_number]->arg);
6615 }
6616
6617 DEFUN (no_neighbor_port,
6618 no_neighbor_port_cmd,
6619 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6620 NO_STR
6621 NEIGHBOR_STR
6622 NEIGHBOR_ADDR_STR
6623 "Neighbor's BGP port\n"
6624 "TCP port number\n")
6625 {
6626 int idx_ip = 2;
6627 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6628 }
6629
6630
6631 /* neighbor weight. */
6632 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6633 safi_t safi, const char *weight_str)
6634 {
6635 int ret;
6636 struct peer *peer;
6637 unsigned long weight;
6638
6639 peer = peer_and_group_lookup_vty(vty, ip_str);
6640 if (!peer)
6641 return CMD_WARNING_CONFIG_FAILED;
6642
6643 weight = strtoul(weight_str, NULL, 10);
6644
6645 ret = peer_weight_set(peer, afi, safi, weight);
6646 return bgp_vty_return(vty, ret);
6647 }
6648
6649 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6650 safi_t safi)
6651 {
6652 int ret;
6653 struct peer *peer;
6654
6655 peer = peer_and_group_lookup_vty(vty, ip_str);
6656 if (!peer)
6657 return CMD_WARNING_CONFIG_FAILED;
6658
6659 ret = peer_weight_unset(peer, afi, safi);
6660 return bgp_vty_return(vty, ret);
6661 }
6662
6663 DEFUN (neighbor_weight,
6664 neighbor_weight_cmd,
6665 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6666 NEIGHBOR_STR
6667 NEIGHBOR_ADDR_STR2
6668 "Set default weight for routes from this neighbor\n"
6669 "default weight\n")
6670 {
6671 int idx_peer = 1;
6672 int idx_number = 3;
6673 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6674 bgp_node_safi(vty), argv[idx_number]->arg);
6675 }
6676
6677 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6678 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6679 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6680 "Set default weight for routes from this neighbor\n"
6681 "default weight\n")
6682
6683 DEFUN (no_neighbor_weight,
6684 no_neighbor_weight_cmd,
6685 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6686 NO_STR
6687 NEIGHBOR_STR
6688 NEIGHBOR_ADDR_STR2
6689 "Set default weight for routes from this neighbor\n"
6690 "default weight\n")
6691 {
6692 int idx_peer = 2;
6693 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6694 bgp_node_afi(vty), bgp_node_safi(vty));
6695 }
6696
6697 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6698 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6699 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6700 "Set default weight for routes from this neighbor\n"
6701 "default weight\n")
6702
6703
6704 /* Override capability negotiation. */
6705 DEFUN (neighbor_override_capability,
6706 neighbor_override_capability_cmd,
6707 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6708 NEIGHBOR_STR
6709 NEIGHBOR_ADDR_STR2
6710 "Override capability negotiation result\n")
6711 {
6712 int idx_peer = 1;
6713 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6714 PEER_FLAG_OVERRIDE_CAPABILITY);
6715 }
6716
6717 DEFUN (no_neighbor_override_capability,
6718 no_neighbor_override_capability_cmd,
6719 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6720 NO_STR
6721 NEIGHBOR_STR
6722 NEIGHBOR_ADDR_STR2
6723 "Override capability negotiation result\n")
6724 {
6725 int idx_peer = 2;
6726 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6727 PEER_FLAG_OVERRIDE_CAPABILITY);
6728 }
6729
6730 DEFUN (neighbor_strict_capability,
6731 neighbor_strict_capability_cmd,
6732 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6733 NEIGHBOR_STR
6734 NEIGHBOR_ADDR_STR2
6735 "Strict capability negotiation match\n")
6736 {
6737 int idx_peer = 1;
6738
6739 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6740 PEER_FLAG_STRICT_CAP_MATCH);
6741 }
6742
6743 DEFUN (no_neighbor_strict_capability,
6744 no_neighbor_strict_capability_cmd,
6745 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6746 NO_STR
6747 NEIGHBOR_STR
6748 NEIGHBOR_ADDR_STR2
6749 "Strict capability negotiation match\n")
6750 {
6751 int idx_peer = 2;
6752
6753 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6754 PEER_FLAG_STRICT_CAP_MATCH);
6755 }
6756
6757 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6758 const char *keep_str, const char *hold_str)
6759 {
6760 int ret;
6761 struct peer *peer;
6762 uint32_t keepalive;
6763 uint32_t holdtime;
6764
6765 peer = peer_and_group_lookup_vty(vty, ip_str);
6766 if (!peer)
6767 return CMD_WARNING_CONFIG_FAILED;
6768
6769 keepalive = strtoul(keep_str, NULL, 10);
6770 holdtime = strtoul(hold_str, NULL, 10);
6771
6772 ret = peer_timers_set(peer, keepalive, holdtime);
6773
6774 return bgp_vty_return(vty, ret);
6775 }
6776
6777 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
6778 {
6779 int ret;
6780 struct peer *peer;
6781
6782 peer = peer_and_group_lookup_vty(vty, ip_str);
6783 if (!peer)
6784 return CMD_WARNING_CONFIG_FAILED;
6785
6786 ret = peer_timers_unset(peer);
6787
6788 return bgp_vty_return(vty, ret);
6789 }
6790
6791 DEFUN (neighbor_timers,
6792 neighbor_timers_cmd,
6793 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6794 NEIGHBOR_STR
6795 NEIGHBOR_ADDR_STR2
6796 "BGP per neighbor timers\n"
6797 "Keepalive interval\n"
6798 "Holdtime\n")
6799 {
6800 int idx_peer = 1;
6801 int idx_number = 3;
6802 int idx_number_2 = 4;
6803 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6804 argv[idx_number]->arg,
6805 argv[idx_number_2]->arg);
6806 }
6807
6808 DEFUN (no_neighbor_timers,
6809 no_neighbor_timers_cmd,
6810 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6811 NO_STR
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
6814 "BGP per neighbor timers\n"
6815 "Keepalive interval\n"
6816 "Holdtime\n")
6817 {
6818 int idx_peer = 2;
6819 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6820 }
6821
6822
6823 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6824 const char *time_str)
6825 {
6826 int ret;
6827 struct peer *peer;
6828 uint32_t connect;
6829
6830 peer = peer_and_group_lookup_vty(vty, ip_str);
6831 if (!peer)
6832 return CMD_WARNING_CONFIG_FAILED;
6833
6834 connect = strtoul(time_str, NULL, 10);
6835
6836 ret = peer_timers_connect_set(peer, connect);
6837
6838 return bgp_vty_return(vty, ret);
6839 }
6840
6841 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
6842 {
6843 int ret;
6844 struct peer *peer;
6845
6846 peer = peer_and_group_lookup_vty(vty, ip_str);
6847 if (!peer)
6848 return CMD_WARNING_CONFIG_FAILED;
6849
6850 ret = peer_timers_connect_unset(peer);
6851
6852 return bgp_vty_return(vty, ret);
6853 }
6854
6855 DEFUN (neighbor_timers_connect,
6856 neighbor_timers_connect_cmd,
6857 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6858 NEIGHBOR_STR
6859 NEIGHBOR_ADDR_STR2
6860 "BGP per neighbor timers\n"
6861 "BGP connect timer\n"
6862 "Connect timer\n")
6863 {
6864 int idx_peer = 1;
6865 int idx_number = 4;
6866 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6867 argv[idx_number]->arg);
6868 }
6869
6870 DEFUN (no_neighbor_timers_connect,
6871 no_neighbor_timers_connect_cmd,
6872 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6873 NO_STR
6874 NEIGHBOR_STR
6875 NEIGHBOR_ADDR_STR2
6876 "BGP per neighbor timers\n"
6877 "BGP connect timer\n"
6878 "Connect timer\n")
6879 {
6880 int idx_peer = 2;
6881 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
6882 }
6883
6884 DEFPY (neighbor_timers_delayopen,
6885 neighbor_timers_delayopen_cmd,
6886 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6887 NEIGHBOR_STR
6888 NEIGHBOR_ADDR_STR2
6889 "BGP per neighbor timers\n"
6890 "RFC 4271 DelayOpenTimer\n"
6891 "DelayOpenTime timer interval\n")
6892 {
6893 struct peer *peer;
6894
6895 peer = peer_and_group_lookup_vty(vty, neighbor);
6896 if (!peer)
6897 return CMD_WARNING_CONFIG_FAILED;
6898
6899 if (!interval) {
6900 if (peer_timers_delayopen_unset(peer))
6901 return CMD_WARNING_CONFIG_FAILED;
6902 } else {
6903 if (peer_timers_delayopen_set(peer, interval))
6904 return CMD_WARNING_CONFIG_FAILED;
6905 }
6906
6907 return CMD_SUCCESS;
6908 }
6909
6910 DEFPY (no_neighbor_timers_delayopen,
6911 no_neighbor_timers_delayopen_cmd,
6912 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6913 NO_STR
6914 NEIGHBOR_STR
6915 NEIGHBOR_ADDR_STR2
6916 "BGP per neighbor timers\n"
6917 "RFC 4271 DelayOpenTimer\n"
6918 "DelayOpenTime timer interval\n")
6919 {
6920 struct peer *peer;
6921
6922 peer = peer_and_group_lookup_vty(vty, neighbor);
6923 if (!peer)
6924 return CMD_WARNING_CONFIG_FAILED;
6925
6926 if (peer_timers_delayopen_unset(peer))
6927 return CMD_WARNING_CONFIG_FAILED;
6928
6929 return CMD_SUCCESS;
6930 }
6931
6932 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6933 const char *time_str, int set)
6934 {
6935 int ret;
6936 struct peer *peer;
6937 uint32_t routeadv = 0;
6938
6939 peer = peer_and_group_lookup_vty(vty, ip_str);
6940 if (!peer)
6941 return CMD_WARNING_CONFIG_FAILED;
6942
6943 if (time_str)
6944 routeadv = strtoul(time_str, NULL, 10);
6945
6946 if (set)
6947 ret = peer_advertise_interval_set(peer, routeadv);
6948 else
6949 ret = peer_advertise_interval_unset(peer);
6950
6951 return bgp_vty_return(vty, ret);
6952 }
6953
6954 DEFUN (neighbor_advertise_interval,
6955 neighbor_advertise_interval_cmd,
6956 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6957 NEIGHBOR_STR
6958 NEIGHBOR_ADDR_STR2
6959 "Minimum interval between sending BGP routing updates\n"
6960 "time in seconds\n")
6961 {
6962 int idx_peer = 1;
6963 int idx_number = 3;
6964 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6965 argv[idx_number]->arg, 1);
6966 }
6967
6968 DEFUN (no_neighbor_advertise_interval,
6969 no_neighbor_advertise_interval_cmd,
6970 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6971 NO_STR
6972 NEIGHBOR_STR
6973 NEIGHBOR_ADDR_STR2
6974 "Minimum interval between sending BGP routing updates\n"
6975 "time in seconds\n")
6976 {
6977 int idx_peer = 2;
6978 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
6979 }
6980
6981
6982 /* Time to wait before processing route-map updates */
6983 DEFUN (bgp_set_route_map_delay_timer,
6984 bgp_set_route_map_delay_timer_cmd,
6985 "bgp route-map delay-timer (0-600)",
6986 SET_STR
6987 "BGP route-map delay timer\n"
6988 "Time in secs to wait before processing route-map changes\n"
6989 "0 disables the timer, no route updates happen when route-maps change\n")
6990 {
6991 int idx_number = 3;
6992 uint32_t rmap_delay_timer;
6993
6994 if (argv[idx_number]->arg) {
6995 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6996 bm->rmap_update_timer = rmap_delay_timer;
6997
6998 /* if the dynamic update handling is being disabled, and a timer
6999 * is
7000 * running, stop the timer and act as if the timer has already
7001 * fired.
7002 */
7003 if (!rmap_delay_timer && bm->t_rmap_update) {
7004 BGP_TIMER_OFF(bm->t_rmap_update);
7005 thread_execute(bm->master, bgp_route_map_update_timer,
7006 NULL, 0);
7007 }
7008 return CMD_SUCCESS;
7009 } else {
7010 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7011 return CMD_WARNING_CONFIG_FAILED;
7012 }
7013 }
7014
7015 DEFUN (no_bgp_set_route_map_delay_timer,
7016 no_bgp_set_route_map_delay_timer_cmd,
7017 "no bgp route-map delay-timer [(0-600)]",
7018 NO_STR
7019 BGP_STR
7020 "Default BGP route-map delay timer\n"
7021 "Reset to default time to wait for processing route-map changes\n"
7022 "0 disables the timer, no route updates happen when route-maps change\n")
7023 {
7024
7025 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7026
7027 return CMD_SUCCESS;
7028 }
7029
7030 /* neighbor interface */
7031 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7032 const char *str)
7033 {
7034 struct peer *peer;
7035
7036 peer = peer_lookup_vty(vty, ip_str);
7037 if (!peer || peer->conf_if) {
7038 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7039 return CMD_WARNING_CONFIG_FAILED;
7040 }
7041
7042 if (str)
7043 peer_interface_set(peer, str);
7044 else
7045 peer_interface_unset(peer);
7046
7047 return CMD_SUCCESS;
7048 }
7049
7050 DEFUN (neighbor_interface,
7051 neighbor_interface_cmd,
7052 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7053 NEIGHBOR_STR
7054 NEIGHBOR_ADDR_STR
7055 "Interface\n"
7056 "Interface name\n")
7057 {
7058 int idx_ip = 1;
7059 int idx_word = 3;
7060
7061 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7062 }
7063
7064 DEFUN (no_neighbor_interface,
7065 no_neighbor_interface_cmd,
7066 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7067 NO_STR
7068 NEIGHBOR_STR
7069 NEIGHBOR_ADDR_STR
7070 "Interface\n"
7071 "Interface name\n")
7072 {
7073 int idx_peer = 2;
7074
7075 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7076 }
7077
7078 DEFUN (neighbor_distribute_list,
7079 neighbor_distribute_list_cmd,
7080 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7081 NEIGHBOR_STR
7082 NEIGHBOR_ADDR_STR2
7083 "Filter updates to/from this neighbor\n"
7084 "IP Access-list name\n"
7085 "Filter incoming updates\n"
7086 "Filter outgoing updates\n")
7087 {
7088 int idx_peer = 1;
7089 int idx_acl = 3;
7090 int direct, ret;
7091 struct peer *peer;
7092
7093 const char *pstr = argv[idx_peer]->arg;
7094 const char *acl = argv[idx_acl]->arg;
7095 const char *inout = argv[argc - 1]->text;
7096
7097 peer = peer_and_group_lookup_vty(vty, pstr);
7098 if (!peer)
7099 return CMD_WARNING_CONFIG_FAILED;
7100
7101 /* Check filter direction. */
7102 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7103 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7104 direct, acl);
7105
7106 return bgp_vty_return(vty, ret);
7107 }
7108
7109 ALIAS_HIDDEN(
7110 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7111 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7112 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7113 "Filter updates to/from this neighbor\n"
7114 "IP Access-list name\n"
7115 "Filter incoming updates\n"
7116 "Filter outgoing updates\n")
7117
7118 DEFUN (no_neighbor_distribute_list,
7119 no_neighbor_distribute_list_cmd,
7120 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7121 NO_STR
7122 NEIGHBOR_STR
7123 NEIGHBOR_ADDR_STR2
7124 "Filter updates to/from this neighbor\n"
7125 "IP Access-list name\n"
7126 "Filter incoming updates\n"
7127 "Filter outgoing updates\n")
7128 {
7129 int idx_peer = 2;
7130 int direct, ret;
7131 struct peer *peer;
7132
7133 const char *pstr = argv[idx_peer]->arg;
7134 const char *inout = argv[argc - 1]->text;
7135
7136 peer = peer_and_group_lookup_vty(vty, pstr);
7137 if (!peer)
7138 return CMD_WARNING_CONFIG_FAILED;
7139
7140 /* Check filter direction. */
7141 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7142 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7143 direct);
7144
7145 return bgp_vty_return(vty, ret);
7146 }
7147
7148 ALIAS_HIDDEN(
7149 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7150 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7152 "Filter updates to/from this neighbor\n"
7153 "IP Access-list name\n"
7154 "Filter incoming updates\n"
7155 "Filter outgoing updates\n")
7156
7157 /* Set prefix list to the peer. */
7158 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7159 afi_t afi, safi_t safi,
7160 const char *name_str,
7161 const char *direct_str)
7162 {
7163 int ret;
7164 int direct = FILTER_IN;
7165 struct peer *peer;
7166
7167 peer = peer_and_group_lookup_vty(vty, ip_str);
7168 if (!peer)
7169 return CMD_WARNING_CONFIG_FAILED;
7170
7171 /* Check filter direction. */
7172 if (strncmp(direct_str, "i", 1) == 0)
7173 direct = FILTER_IN;
7174 else if (strncmp(direct_str, "o", 1) == 0)
7175 direct = FILTER_OUT;
7176
7177 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7178
7179 return bgp_vty_return(vty, ret);
7180 }
7181
7182 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7183 afi_t afi, safi_t safi,
7184 const char *direct_str)
7185 {
7186 int ret;
7187 struct peer *peer;
7188 int direct = FILTER_IN;
7189
7190 peer = peer_and_group_lookup_vty(vty, ip_str);
7191 if (!peer)
7192 return CMD_WARNING_CONFIG_FAILED;
7193
7194 /* Check filter direction. */
7195 if (strncmp(direct_str, "i", 1) == 0)
7196 direct = FILTER_IN;
7197 else if (strncmp(direct_str, "o", 1) == 0)
7198 direct = FILTER_OUT;
7199
7200 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7201
7202 return bgp_vty_return(vty, ret);
7203 }
7204
7205 DEFUN (neighbor_prefix_list,
7206 neighbor_prefix_list_cmd,
7207 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7208 NEIGHBOR_STR
7209 NEIGHBOR_ADDR_STR2
7210 "Filter updates to/from this neighbor\n"
7211 "Name of a prefix list\n"
7212 "Filter incoming updates\n"
7213 "Filter outgoing updates\n")
7214 {
7215 int idx_peer = 1;
7216 int idx_word = 3;
7217 int idx_in_out = 4;
7218 return peer_prefix_list_set_vty(
7219 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7220 argv[idx_word]->arg, argv[idx_in_out]->arg);
7221 }
7222
7223 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7224 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7225 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7226 "Filter updates to/from this neighbor\n"
7227 "Name of a prefix list\n"
7228 "Filter incoming updates\n"
7229 "Filter outgoing updates\n")
7230
7231 DEFUN (no_neighbor_prefix_list,
7232 no_neighbor_prefix_list_cmd,
7233 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7234 NO_STR
7235 NEIGHBOR_STR
7236 NEIGHBOR_ADDR_STR2
7237 "Filter updates to/from this neighbor\n"
7238 "Name of a prefix list\n"
7239 "Filter incoming updates\n"
7240 "Filter outgoing updates\n")
7241 {
7242 int idx_peer = 2;
7243 int idx_in_out = 5;
7244 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7245 bgp_node_afi(vty), bgp_node_safi(vty),
7246 argv[idx_in_out]->arg);
7247 }
7248
7249 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7250 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7252 "Filter updates to/from this neighbor\n"
7253 "Name of a prefix list\n"
7254 "Filter incoming updates\n"
7255 "Filter outgoing updates\n")
7256
7257 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7258 safi_t safi, const char *name_str,
7259 const char *direct_str)
7260 {
7261 int ret;
7262 struct peer *peer;
7263 int direct = FILTER_IN;
7264
7265 peer = peer_and_group_lookup_vty(vty, ip_str);
7266 if (!peer)
7267 return CMD_WARNING_CONFIG_FAILED;
7268
7269 /* Check filter direction. */
7270 if (strncmp(direct_str, "i", 1) == 0)
7271 direct = FILTER_IN;
7272 else if (strncmp(direct_str, "o", 1) == 0)
7273 direct = FILTER_OUT;
7274
7275 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7276
7277 return bgp_vty_return(vty, ret);
7278 }
7279
7280 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7281 safi_t safi, const char *direct_str)
7282 {
7283 int ret;
7284 struct peer *peer;
7285 int direct = FILTER_IN;
7286
7287 peer = peer_and_group_lookup_vty(vty, ip_str);
7288 if (!peer)
7289 return CMD_WARNING_CONFIG_FAILED;
7290
7291 /* Check filter direction. */
7292 if (strncmp(direct_str, "i", 1) == 0)
7293 direct = FILTER_IN;
7294 else if (strncmp(direct_str, "o", 1) == 0)
7295 direct = FILTER_OUT;
7296
7297 ret = peer_aslist_unset(peer, afi, safi, direct);
7298
7299 return bgp_vty_return(vty, ret);
7300 }
7301
7302 DEFUN (neighbor_filter_list,
7303 neighbor_filter_list_cmd,
7304 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7305 NEIGHBOR_STR
7306 NEIGHBOR_ADDR_STR2
7307 "Establish BGP filters\n"
7308 "AS path access-list name\n"
7309 "Filter incoming routes\n"
7310 "Filter outgoing routes\n")
7311 {
7312 int idx_peer = 1;
7313 int idx_word = 3;
7314 int idx_in_out = 4;
7315 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7316 bgp_node_safi(vty), argv[idx_word]->arg,
7317 argv[idx_in_out]->arg);
7318 }
7319
7320 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7321 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7322 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7323 "Establish BGP filters\n"
7324 "AS path access-list name\n"
7325 "Filter incoming routes\n"
7326 "Filter outgoing routes\n")
7327
7328 DEFUN (no_neighbor_filter_list,
7329 no_neighbor_filter_list_cmd,
7330 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7331 NO_STR
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Establish BGP filters\n"
7335 "AS path access-list name\n"
7336 "Filter incoming routes\n"
7337 "Filter outgoing routes\n")
7338 {
7339 int idx_peer = 2;
7340 int idx_in_out = 5;
7341 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7342 bgp_node_afi(vty), bgp_node_safi(vty),
7343 argv[idx_in_out]->arg);
7344 }
7345
7346 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7347 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7348 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7349 "Establish BGP filters\n"
7350 "AS path access-list name\n"
7351 "Filter incoming routes\n"
7352 "Filter outgoing routes\n")
7353
7354 /* Set advertise-map to the peer. */
7355 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7356 afi_t afi, safi_t safi,
7357 const char *advertise_str,
7358 const char *condition_str, bool condition,
7359 bool set)
7360 {
7361 int ret = CMD_WARNING_CONFIG_FAILED;
7362 struct peer *peer;
7363 struct route_map *advertise_map;
7364 struct route_map *condition_map;
7365
7366 peer = peer_and_group_lookup_vty(vty, ip_str);
7367 if (!peer)
7368 return ret;
7369
7370 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7371 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7372
7373 if (set)
7374 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7375 advertise_map, condition_str,
7376 condition_map, condition);
7377 else
7378 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7379 advertise_map, condition_str,
7380 condition_map, condition);
7381
7382 return bgp_vty_return(vty, ret);
7383 }
7384
7385 DEFPY (bgp_condadv_period,
7386 bgp_condadv_period_cmd,
7387 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7388 NO_STR
7389 BGP_STR
7390 "Conditional advertisement settings\n"
7391 "Set period to rescan BGP table to check if condition is met\n"
7392 "Period between BGP table scans, in seconds; default 60\n")
7393 {
7394 VTY_DECLVAR_CONTEXT(bgp, bgp);
7395
7396 bgp->condition_check_period =
7397 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7398
7399 return CMD_SUCCESS;
7400 }
7401
7402 DEFPY (neighbor_advertise_map,
7403 neighbor_advertise_map_cmd,
7404 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7405 NO_STR
7406 NEIGHBOR_STR
7407 NEIGHBOR_ADDR_STR2
7408 "Route-map to conditionally advertise routes\n"
7409 "Name of advertise map\n"
7410 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7411 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7412 "Name of the exist or non exist map\n")
7413 {
7414 bool condition = CONDITION_EXIST;
7415
7416 if (!strcmp(exist, "non-exist-map"))
7417 condition = CONDITION_NON_EXIST;
7418
7419 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7420 bgp_node_safi(vty), advertise_str,
7421 condition_str, condition, !no);
7422 }
7423
7424 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7425 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7426 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7427 "Route-map to conditionally advertise routes\n"
7428 "Name of advertise map\n"
7429 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7430 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7431 "Name of the exist or non exist map\n")
7432
7433 /* Set route-map to the peer. */
7434 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7435 afi_t afi, safi_t safi, const char *name_str,
7436 const char *direct_str)
7437 {
7438 int ret;
7439 struct peer *peer;
7440 int direct = RMAP_IN;
7441 struct route_map *route_map;
7442
7443 peer = peer_and_group_lookup_vty(vty, ip_str);
7444 if (!peer)
7445 return CMD_WARNING_CONFIG_FAILED;
7446
7447 /* Check filter direction. */
7448 if (strncmp(direct_str, "in", 2) == 0)
7449 direct = RMAP_IN;
7450 else if (strncmp(direct_str, "o", 1) == 0)
7451 direct = RMAP_OUT;
7452
7453 route_map = route_map_lookup_warn_noexist(vty, name_str);
7454 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7455
7456 return bgp_vty_return(vty, ret);
7457 }
7458
7459 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7460 afi_t afi, safi_t safi,
7461 const char *direct_str)
7462 {
7463 int ret;
7464 struct peer *peer;
7465 int direct = RMAP_IN;
7466
7467 peer = peer_and_group_lookup_vty(vty, ip_str);
7468 if (!peer)
7469 return CMD_WARNING_CONFIG_FAILED;
7470
7471 /* Check filter direction. */
7472 if (strncmp(direct_str, "in", 2) == 0)
7473 direct = RMAP_IN;
7474 else if (strncmp(direct_str, "o", 1) == 0)
7475 direct = RMAP_OUT;
7476
7477 ret = peer_route_map_unset(peer, afi, safi, direct);
7478
7479 return bgp_vty_return(vty, ret);
7480 }
7481
7482 DEFUN (neighbor_route_map,
7483 neighbor_route_map_cmd,
7484 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7485 NEIGHBOR_STR
7486 NEIGHBOR_ADDR_STR2
7487 "Apply route map to neighbor\n"
7488 "Name of route map\n"
7489 "Apply map to incoming routes\n"
7490 "Apply map to outbound routes\n")
7491 {
7492 int idx_peer = 1;
7493 int idx_word = 3;
7494 int idx_in_out = 4;
7495 return peer_route_map_set_vty(
7496 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7497 argv[idx_word]->arg, argv[idx_in_out]->arg);
7498 }
7499
7500 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7501 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7502 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7503 "Apply route map to neighbor\n"
7504 "Name of route map\n"
7505 "Apply map to incoming routes\n"
7506 "Apply map to outbound routes\n")
7507
7508 DEFUN (no_neighbor_route_map,
7509 no_neighbor_route_map_cmd,
7510 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7511 NO_STR
7512 NEIGHBOR_STR
7513 NEIGHBOR_ADDR_STR2
7514 "Apply route map to neighbor\n"
7515 "Name of route map\n"
7516 "Apply map to incoming routes\n"
7517 "Apply map to outbound routes\n")
7518 {
7519 int idx_peer = 2;
7520 int idx_in_out = 5;
7521 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7522 bgp_node_afi(vty), bgp_node_safi(vty),
7523 argv[idx_in_out]->arg);
7524 }
7525
7526 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7527 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7528 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7529 "Apply route map to neighbor\n"
7530 "Name of route map\n"
7531 "Apply map to incoming routes\n"
7532 "Apply map to outbound routes\n")
7533
7534 /* Set unsuppress-map to the peer. */
7535 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7536 afi_t afi, safi_t safi,
7537 const char *name_str)
7538 {
7539 int ret;
7540 struct peer *peer;
7541 struct route_map *route_map;
7542
7543 peer = peer_and_group_lookup_vty(vty, ip_str);
7544 if (!peer)
7545 return CMD_WARNING_CONFIG_FAILED;
7546
7547 route_map = route_map_lookup_warn_noexist(vty, name_str);
7548 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7549
7550 return bgp_vty_return(vty, ret);
7551 }
7552
7553 /* Unset route-map from the peer. */
7554 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7555 afi_t afi, safi_t safi)
7556 {
7557 int ret;
7558 struct peer *peer;
7559
7560 peer = peer_and_group_lookup_vty(vty, ip_str);
7561 if (!peer)
7562 return CMD_WARNING_CONFIG_FAILED;
7563
7564 ret = peer_unsuppress_map_unset(peer, afi, safi);
7565
7566 return bgp_vty_return(vty, ret);
7567 }
7568
7569 DEFUN (neighbor_unsuppress_map,
7570 neighbor_unsuppress_map_cmd,
7571 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7572 NEIGHBOR_STR
7573 NEIGHBOR_ADDR_STR2
7574 "Route-map to selectively unsuppress suppressed routes\n"
7575 "Name of route map\n")
7576 {
7577 int idx_peer = 1;
7578 int idx_word = 3;
7579 return peer_unsuppress_map_set_vty(
7580 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7581 argv[idx_word]->arg);
7582 }
7583
7584 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7585 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7587 "Route-map to selectively unsuppress suppressed routes\n"
7588 "Name of route map\n")
7589
7590 DEFUN (no_neighbor_unsuppress_map,
7591 no_neighbor_unsuppress_map_cmd,
7592 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7593 NO_STR
7594 NEIGHBOR_STR
7595 NEIGHBOR_ADDR_STR2
7596 "Route-map to selectively unsuppress suppressed routes\n"
7597 "Name of route map\n")
7598 {
7599 int idx_peer = 2;
7600 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7601 bgp_node_afi(vty),
7602 bgp_node_safi(vty));
7603 }
7604
7605 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7606 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7607 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7608 "Route-map to selectively unsuppress suppressed routes\n"
7609 "Name of route map\n")
7610
7611 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7612 afi_t afi, safi_t safi,
7613 const char *num_str,
7614 const char *threshold_str, int warning,
7615 const char *restart_str,
7616 const char *force_str)
7617 {
7618 int ret;
7619 struct peer *peer;
7620 uint32_t max;
7621 uint8_t threshold;
7622 uint16_t restart;
7623
7624 peer = peer_and_group_lookup_vty(vty, ip_str);
7625 if (!peer)
7626 return CMD_WARNING_CONFIG_FAILED;
7627
7628 max = strtoul(num_str, NULL, 10);
7629 if (threshold_str)
7630 threshold = atoi(threshold_str);
7631 else
7632 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7633
7634 if (restart_str)
7635 restart = atoi(restart_str);
7636 else
7637 restart = 0;
7638
7639 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7640 restart, force_str ? true : false);
7641
7642 return bgp_vty_return(vty, ret);
7643 }
7644
7645 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7646 afi_t afi, safi_t safi)
7647 {
7648 int ret;
7649 struct peer *peer;
7650
7651 peer = peer_and_group_lookup_vty(vty, ip_str);
7652 if (!peer)
7653 return CMD_WARNING_CONFIG_FAILED;
7654
7655 ret = peer_maximum_prefix_unset(peer, afi, safi);
7656
7657 return bgp_vty_return(vty, ret);
7658 }
7659
7660 /* Maximum number of prefix to be sent to the neighbor. */
7661 DEFUN(neighbor_maximum_prefix_out,
7662 neighbor_maximum_prefix_out_cmd,
7663 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7664 NEIGHBOR_STR
7665 NEIGHBOR_ADDR_STR2
7666 "Maximum number of prefixes to be sent to this peer\n"
7667 "Maximum no. of prefix limit\n")
7668 {
7669 int idx_peer = 1;
7670 int idx_number = 3;
7671 struct peer *peer;
7672 uint32_t max;
7673 afi_t afi = bgp_node_afi(vty);
7674 safi_t safi = bgp_node_safi(vty);
7675
7676 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7677 if (!peer)
7678 return CMD_WARNING_CONFIG_FAILED;
7679
7680 max = strtoul(argv[idx_number]->arg, NULL, 10);
7681
7682 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7683 peer->pmax_out[afi][safi] = max;
7684
7685 return CMD_SUCCESS;
7686 }
7687
7688 DEFUN(no_neighbor_maximum_prefix_out,
7689 no_neighbor_maximum_prefix_out_cmd,
7690 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7691 NO_STR
7692 NEIGHBOR_STR
7693 NEIGHBOR_ADDR_STR2
7694 "Maximum number of prefixes to be sent to this peer\n")
7695 {
7696 int idx_peer = 2;
7697 struct peer *peer;
7698 afi_t afi = bgp_node_afi(vty);
7699 safi_t safi = bgp_node_safi(vty);
7700
7701 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7702 if (!peer)
7703 return CMD_WARNING_CONFIG_FAILED;
7704
7705 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7706 peer->pmax_out[afi][safi] = 0;
7707
7708 return CMD_SUCCESS;
7709 }
7710
7711 /* Maximum number of prefix configuration. Prefix count is different
7712 for each peer configuration. So this configuration can be set for
7713 each peer configuration. */
7714 DEFUN (neighbor_maximum_prefix,
7715 neighbor_maximum_prefix_cmd,
7716 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7717 NEIGHBOR_STR
7718 NEIGHBOR_ADDR_STR2
7719 "Maximum number of prefix accept from this peer\n"
7720 "maximum no. of prefix limit\n"
7721 "Force checking all received routes not only accepted\n")
7722 {
7723 int idx_peer = 1;
7724 int idx_number = 3;
7725 int idx_force = 0;
7726 char *force = NULL;
7727
7728 if (argv_find(argv, argc, "force", &idx_force))
7729 force = argv[idx_force]->arg;
7730
7731 return peer_maximum_prefix_set_vty(
7732 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7733 argv[idx_number]->arg, NULL, 0, NULL, force);
7734 }
7735
7736 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7737 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7739 "Maximum number of prefix accept from this peer\n"
7740 "maximum no. of prefix limit\n"
7741 "Force checking all received routes not only accepted\n")
7742
7743 DEFUN (neighbor_maximum_prefix_threshold,
7744 neighbor_maximum_prefix_threshold_cmd,
7745 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7746 NEIGHBOR_STR
7747 NEIGHBOR_ADDR_STR2
7748 "Maximum number of prefix accept from this peer\n"
7749 "maximum no. of prefix limit\n"
7750 "Threshold value (%) at which to generate a warning msg\n"
7751 "Force checking all received routes not only accepted\n")
7752 {
7753 int idx_peer = 1;
7754 int idx_number = 3;
7755 int idx_number_2 = 4;
7756 int idx_force = 0;
7757 char *force = NULL;
7758
7759 if (argv_find(argv, argc, "force", &idx_force))
7760 force = argv[idx_force]->arg;
7761
7762 return peer_maximum_prefix_set_vty(
7763 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7764 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
7765 }
7766
7767 ALIAS_HIDDEN(
7768 neighbor_maximum_prefix_threshold,
7769 neighbor_maximum_prefix_threshold_hidden_cmd,
7770 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7772 "Maximum number of prefix accept from this peer\n"
7773 "maximum no. of prefix limit\n"
7774 "Threshold value (%) at which to generate a warning msg\n"
7775 "Force checking all received routes not only accepted\n")
7776
7777 DEFUN (neighbor_maximum_prefix_warning,
7778 neighbor_maximum_prefix_warning_cmd,
7779 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7780 NEIGHBOR_STR
7781 NEIGHBOR_ADDR_STR2
7782 "Maximum number of prefix accept from this peer\n"
7783 "maximum no. of prefix limit\n"
7784 "Only give warning message when limit is exceeded\n"
7785 "Force checking all received routes not only accepted\n")
7786 {
7787 int idx_peer = 1;
7788 int idx_number = 3;
7789 int idx_force = 0;
7790 char *force = NULL;
7791
7792 if (argv_find(argv, argc, "force", &idx_force))
7793 force = argv[idx_force]->arg;
7794
7795 return peer_maximum_prefix_set_vty(
7796 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7797 argv[idx_number]->arg, NULL, 1, NULL, force);
7798 }
7799
7800 ALIAS_HIDDEN(
7801 neighbor_maximum_prefix_warning,
7802 neighbor_maximum_prefix_warning_hidden_cmd,
7803 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7805 "Maximum number of prefix accept from this peer\n"
7806 "maximum no. of prefix limit\n"
7807 "Only give warning message when limit is exceeded\n"
7808 "Force checking all received routes not only accepted\n")
7809
7810 DEFUN (neighbor_maximum_prefix_threshold_warning,
7811 neighbor_maximum_prefix_threshold_warning_cmd,
7812 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7813 NEIGHBOR_STR
7814 NEIGHBOR_ADDR_STR2
7815 "Maximum number of prefix accept from this peer\n"
7816 "maximum no. of prefix limit\n"
7817 "Threshold value (%) at which to generate a warning msg\n"
7818 "Only give warning message when limit is exceeded\n"
7819 "Force checking all received routes not only accepted\n")
7820 {
7821 int idx_peer = 1;
7822 int idx_number = 3;
7823 int idx_number_2 = 4;
7824 int idx_force = 0;
7825 char *force = NULL;
7826
7827 if (argv_find(argv, argc, "force", &idx_force))
7828 force = argv[idx_force]->arg;
7829
7830 return peer_maximum_prefix_set_vty(
7831 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7832 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
7833 }
7834
7835 ALIAS_HIDDEN(
7836 neighbor_maximum_prefix_threshold_warning,
7837 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
7838 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7839 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7840 "Maximum number of prefix accept from this peer\n"
7841 "maximum no. of prefix limit\n"
7842 "Threshold value (%) at which to generate a warning msg\n"
7843 "Only give warning message when limit is exceeded\n"
7844 "Force checking all received routes not only accepted\n")
7845
7846 DEFUN (neighbor_maximum_prefix_restart,
7847 neighbor_maximum_prefix_restart_cmd,
7848 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7849 NEIGHBOR_STR
7850 NEIGHBOR_ADDR_STR2
7851 "Maximum number of prefix accept from this peer\n"
7852 "maximum no. of prefix limit\n"
7853 "Restart bgp connection after limit is exceeded\n"
7854 "Restart interval in minutes\n"
7855 "Force checking all received routes not only accepted\n")
7856 {
7857 int idx_peer = 1;
7858 int idx_number = 3;
7859 int idx_number_2 = 5;
7860 int idx_force = 0;
7861 char *force = NULL;
7862
7863 if (argv_find(argv, argc, "force", &idx_force))
7864 force = argv[idx_force]->arg;
7865
7866 return peer_maximum_prefix_set_vty(
7867 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7868 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
7869 }
7870
7871 ALIAS_HIDDEN(
7872 neighbor_maximum_prefix_restart,
7873 neighbor_maximum_prefix_restart_hidden_cmd,
7874 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7876 "Maximum number of prefix accept from this peer\n"
7877 "maximum no. of prefix limit\n"
7878 "Restart bgp connection after limit is exceeded\n"
7879 "Restart interval in minutes\n"
7880 "Force checking all received routes not only accepted\n")
7881
7882 DEFUN (neighbor_maximum_prefix_threshold_restart,
7883 neighbor_maximum_prefix_threshold_restart_cmd,
7884 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7885 NEIGHBOR_STR
7886 NEIGHBOR_ADDR_STR2
7887 "Maximum number of prefixes to accept from this peer\n"
7888 "maximum no. of prefix limit\n"
7889 "Threshold value (%) at which to generate a warning msg\n"
7890 "Restart bgp connection after limit is exceeded\n"
7891 "Restart interval in minutes\n"
7892 "Force checking all received routes not only accepted\n")
7893 {
7894 int idx_peer = 1;
7895 int idx_number = 3;
7896 int idx_number_2 = 4;
7897 int idx_number_3 = 6;
7898 int idx_force = 0;
7899 char *force = NULL;
7900
7901 if (argv_find(argv, argc, "force", &idx_force))
7902 force = argv[idx_force]->arg;
7903
7904 return peer_maximum_prefix_set_vty(
7905 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7906 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7907 argv[idx_number_3]->arg, force);
7908 }
7909
7910 ALIAS_HIDDEN(
7911 neighbor_maximum_prefix_threshold_restart,
7912 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
7913 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7914 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7915 "Maximum number of prefixes to accept from this peer\n"
7916 "maximum no. of prefix limit\n"
7917 "Threshold value (%) at which to generate a warning msg\n"
7918 "Restart bgp connection after limit is exceeded\n"
7919 "Restart interval in minutes\n"
7920 "Force checking all received routes not only accepted\n")
7921
7922 DEFUN (no_neighbor_maximum_prefix,
7923 no_neighbor_maximum_prefix_cmd,
7924 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7925 NO_STR
7926 NEIGHBOR_STR
7927 NEIGHBOR_ADDR_STR2
7928 "Maximum number of prefixes to accept from this peer\n"
7929 "maximum no. of prefix limit\n"
7930 "Threshold value (%) at which to generate a warning msg\n"
7931 "Restart bgp connection after limit is exceeded\n"
7932 "Restart interval in minutes\n"
7933 "Only give warning message when limit is exceeded\n"
7934 "Force checking all received routes not only accepted\n")
7935 {
7936 int idx_peer = 2;
7937 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7938 bgp_node_afi(vty),
7939 bgp_node_safi(vty));
7940 }
7941
7942 ALIAS_HIDDEN(
7943 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
7944 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7946 "Maximum number of prefixes to accept from this peer\n"
7947 "maximum no. of prefix limit\n"
7948 "Threshold value (%) at which to generate a warning msg\n"
7949 "Restart bgp connection after limit is exceeded\n"
7950 "Restart interval in minutes\n"
7951 "Only give warning message when limit is exceeded\n"
7952 "Force checking all received routes not only accepted\n")
7953
7954
7955 /* "neighbor allowas-in" */
7956 DEFUN (neighbor_allowas_in,
7957 neighbor_allowas_in_cmd,
7958 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7959 NEIGHBOR_STR
7960 NEIGHBOR_ADDR_STR2
7961 "Accept as-path with my AS present in it\n"
7962 "Number of occurrences of AS number\n"
7963 "Only accept my AS in the as-path if the route was originated in my AS\n")
7964 {
7965 int idx_peer = 1;
7966 int idx_number_origin = 3;
7967 int ret;
7968 int origin = 0;
7969 struct peer *peer;
7970 int allow_num = 0;
7971
7972 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7973 if (!peer)
7974 return CMD_WARNING_CONFIG_FAILED;
7975
7976 if (argc <= idx_number_origin)
7977 allow_num = 3;
7978 else {
7979 if (argv[idx_number_origin]->type == WORD_TKN)
7980 origin = 1;
7981 else
7982 allow_num = atoi(argv[idx_number_origin]->arg);
7983 }
7984
7985 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7986 allow_num, origin);
7987
7988 return bgp_vty_return(vty, ret);
7989 }
7990
7991 ALIAS_HIDDEN(
7992 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7993 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7995 "Accept as-path with my AS present in it\n"
7996 "Number of occurrences of AS number\n"
7997 "Only accept my AS in the as-path if the route was originated in my AS\n")
7998
7999 DEFUN (no_neighbor_allowas_in,
8000 no_neighbor_allowas_in_cmd,
8001 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8002 NO_STR
8003 NEIGHBOR_STR
8004 NEIGHBOR_ADDR_STR2
8005 "allow local ASN appears in aspath attribute\n"
8006 "Number of occurrences of AS number\n"
8007 "Only accept my AS in the as-path if the route was originated in my AS\n")
8008 {
8009 int idx_peer = 2;
8010 int ret;
8011 struct peer *peer;
8012
8013 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8014 if (!peer)
8015 return CMD_WARNING_CONFIG_FAILED;
8016
8017 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8018 bgp_node_safi(vty));
8019
8020 return bgp_vty_return(vty, ret);
8021 }
8022
8023 ALIAS_HIDDEN(
8024 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8025 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8026 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8027 "allow local ASN appears in aspath attribute\n"
8028 "Number of occurrences of AS number\n"
8029 "Only accept my AS in the as-path if the route was originated in my AS\n")
8030
8031 DEFUN (neighbor_ttl_security,
8032 neighbor_ttl_security_cmd,
8033 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8034 NEIGHBOR_STR
8035 NEIGHBOR_ADDR_STR2
8036 "BGP ttl-security parameters\n"
8037 "Specify the maximum number of hops to the BGP peer\n"
8038 "Number of hops to BGP peer\n")
8039 {
8040 int idx_peer = 1;
8041 int idx_number = 4;
8042 struct peer *peer;
8043 int gtsm_hops;
8044
8045 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8046 if (!peer)
8047 return CMD_WARNING_CONFIG_FAILED;
8048
8049 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8050
8051 /*
8052 * If 'neighbor swpX', then this is for directly connected peers,
8053 * we should not accept a ttl-security hops value greater than 1.
8054 */
8055 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8056 vty_out(vty,
8057 "%s is directly connected peer, hops cannot exceed 1\n",
8058 argv[idx_peer]->arg);
8059 return CMD_WARNING_CONFIG_FAILED;
8060 }
8061
8062 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8063 }
8064
8065 DEFUN (no_neighbor_ttl_security,
8066 no_neighbor_ttl_security_cmd,
8067 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8068 NO_STR
8069 NEIGHBOR_STR
8070 NEIGHBOR_ADDR_STR2
8071 "BGP ttl-security parameters\n"
8072 "Specify the maximum number of hops to the BGP peer\n"
8073 "Number of hops to BGP peer\n")
8074 {
8075 int idx_peer = 2;
8076 struct peer *peer;
8077
8078 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8079 if (!peer)
8080 return CMD_WARNING_CONFIG_FAILED;
8081
8082 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8083 }
8084
8085 /* disable-addpath-rx */
8086 DEFUN(neighbor_disable_addpath_rx,
8087 neighbor_disable_addpath_rx_cmd,
8088 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8089 NEIGHBOR_STR
8090 NEIGHBOR_ADDR_STR2
8091 "Do not accept additional paths\n")
8092 {
8093 char *peer_str = argv[1]->arg;
8094 struct peer *peer;
8095 afi_t afi = bgp_node_afi(vty);
8096 safi_t safi = bgp_node_safi(vty);
8097
8098 peer = peer_and_group_lookup_vty(vty, peer_str);
8099 if (!peer)
8100 return CMD_WARNING_CONFIG_FAILED;
8101
8102 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8103 PEER_FLAG_DISABLE_ADDPATH_RX);
8104 }
8105
8106 DEFUN(no_neighbor_disable_addpath_rx,
8107 no_neighbor_disable_addpath_rx_cmd,
8108 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8109 NO_STR
8110 NEIGHBOR_STR
8111 NEIGHBOR_ADDR_STR2
8112 "Do not accept additional paths\n")
8113 {
8114 char *peer_str = argv[2]->arg;
8115 struct peer *peer;
8116 afi_t afi = bgp_node_afi(vty);
8117 safi_t safi = bgp_node_safi(vty);
8118
8119 peer = peer_and_group_lookup_vty(vty, peer_str);
8120 if (!peer)
8121 return CMD_WARNING_CONFIG_FAILED;
8122
8123 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8124 PEER_FLAG_DISABLE_ADDPATH_RX);
8125 }
8126
8127 DEFUN (neighbor_addpath_tx_all_paths,
8128 neighbor_addpath_tx_all_paths_cmd,
8129 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8130 NEIGHBOR_STR
8131 NEIGHBOR_ADDR_STR2
8132 "Use addpath to advertise all paths to a neighbor\n")
8133 {
8134 int idx_peer = 1;
8135 struct peer *peer;
8136
8137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8138 if (!peer)
8139 return CMD_WARNING_CONFIG_FAILED;
8140
8141 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8142 BGP_ADDPATH_ALL);
8143 return CMD_SUCCESS;
8144 }
8145
8146 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8147 neighbor_addpath_tx_all_paths_hidden_cmd,
8148 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8150 "Use addpath to advertise all paths to a neighbor\n")
8151
8152 DEFUN (no_neighbor_addpath_tx_all_paths,
8153 no_neighbor_addpath_tx_all_paths_cmd,
8154 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8155 NO_STR
8156 NEIGHBOR_STR
8157 NEIGHBOR_ADDR_STR2
8158 "Use addpath to advertise all paths to a neighbor\n")
8159 {
8160 int idx_peer = 2;
8161 struct peer *peer;
8162
8163 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8164 if (!peer)
8165 return CMD_WARNING_CONFIG_FAILED;
8166
8167 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8168 != BGP_ADDPATH_ALL) {
8169 vty_out(vty,
8170 "%% Peer not currently configured to transmit all paths.");
8171 return CMD_WARNING_CONFIG_FAILED;
8172 }
8173
8174 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8175 BGP_ADDPATH_NONE);
8176
8177 return CMD_SUCCESS;
8178 }
8179
8180 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8181 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8182 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8184 "Use addpath to advertise all paths to a neighbor\n")
8185
8186 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8187 neighbor_addpath_tx_bestpath_per_as_cmd,
8188 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8189 NEIGHBOR_STR
8190 NEIGHBOR_ADDR_STR2
8191 "Use addpath to advertise the bestpath per each neighboring AS\n")
8192 {
8193 int idx_peer = 1;
8194 struct peer *peer;
8195
8196 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8197 if (!peer)
8198 return CMD_WARNING_CONFIG_FAILED;
8199
8200 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8201 BGP_ADDPATH_BEST_PER_AS);
8202
8203 return CMD_SUCCESS;
8204 }
8205
8206 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8207 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8208 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8210 "Use addpath to advertise the bestpath per each neighboring AS\n")
8211
8212 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8213 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8214 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8215 NO_STR
8216 NEIGHBOR_STR
8217 NEIGHBOR_ADDR_STR2
8218 "Use addpath to advertise the bestpath per each neighboring AS\n")
8219 {
8220 int idx_peer = 2;
8221 struct peer *peer;
8222
8223 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8224 if (!peer)
8225 return CMD_WARNING_CONFIG_FAILED;
8226
8227 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8228 != BGP_ADDPATH_BEST_PER_AS) {
8229 vty_out(vty,
8230 "%% Peer not currently configured to transmit all best path per as.");
8231 return CMD_WARNING_CONFIG_FAILED;
8232 }
8233
8234 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8235 BGP_ADDPATH_NONE);
8236
8237 return CMD_SUCCESS;
8238 }
8239
8240 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8241 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8242 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8243 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8244 "Use addpath to advertise the bestpath per each neighboring AS\n")
8245
8246 DEFPY(
8247 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8248 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8249 NEIGHBOR_STR
8250 NEIGHBOR_ADDR_STR2
8251 "Detect AS loops before sending to neighbor\n")
8252 {
8253 struct peer *peer;
8254
8255 peer = peer_and_group_lookup_vty(vty, neighbor);
8256 if (!peer)
8257 return CMD_WARNING_CONFIG_FAILED;
8258
8259 peer->as_path_loop_detection = true;
8260
8261 return CMD_SUCCESS;
8262 }
8263
8264 DEFPY(
8265 no_neighbor_aspath_loop_detection,
8266 no_neighbor_aspath_loop_detection_cmd,
8267 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8268 NO_STR
8269 NEIGHBOR_STR
8270 NEIGHBOR_ADDR_STR2
8271 "Detect AS loops before sending to neighbor\n")
8272 {
8273 struct peer *peer;
8274
8275 peer = peer_and_group_lookup_vty(vty, neighbor);
8276 if (!peer)
8277 return CMD_WARNING_CONFIG_FAILED;
8278
8279 peer->as_path_loop_detection = false;
8280
8281 return CMD_SUCCESS;
8282 }
8283
8284 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8285 struct ecommunity **list, bool is_rt6)
8286 {
8287 struct ecommunity *ecom = NULL;
8288 struct ecommunity *ecomadd;
8289
8290 for (; argc; --argc, ++argv) {
8291 if (is_rt6)
8292 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8293 ECOMMUNITY_ROUTE_TARGET,
8294 0);
8295 else
8296 ecomadd = ecommunity_str2com(argv[0]->arg,
8297 ECOMMUNITY_ROUTE_TARGET,
8298 0);
8299 if (!ecomadd) {
8300 vty_out(vty, "Malformed community-list value\n");
8301 if (ecom)
8302 ecommunity_free(&ecom);
8303 return CMD_WARNING_CONFIG_FAILED;
8304 }
8305
8306 if (ecom) {
8307 ecommunity_merge(ecom, ecomadd);
8308 ecommunity_free(&ecomadd);
8309 } else {
8310 ecom = ecomadd;
8311 }
8312 }
8313
8314 if (*list) {
8315 ecommunity_free(&*list);
8316 }
8317 *list = ecom;
8318
8319 return CMD_SUCCESS;
8320 }
8321
8322 /*
8323 * v2vimport is true if we are handling a `import vrf ...` command
8324 */
8325 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8326 {
8327 afi_t afi;
8328
8329 switch (vty->node) {
8330 case BGP_IPV4_NODE:
8331 afi = AFI_IP;
8332 break;
8333 case BGP_IPV6_NODE:
8334 afi = AFI_IP6;
8335 break;
8336 default:
8337 vty_out(vty,
8338 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8339 return AFI_MAX;
8340 }
8341
8342 if (!v2vimport) {
8343 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8344 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8345 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8346 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8347 vty_out(vty,
8348 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8349 return AFI_MAX;
8350 }
8351 } else {
8352 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8353 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8354 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8355 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8356 vty_out(vty,
8357 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8358 return AFI_MAX;
8359 }
8360 }
8361 return afi;
8362 }
8363
8364 DEFPY (af_rd_vpn_export,
8365 af_rd_vpn_export_cmd,
8366 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8367 NO_STR
8368 "Specify route distinguisher\n"
8369 "Between current address-family and vpn\n"
8370 "For routes leaked from current address-family to vpn\n"
8371 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8372 {
8373 VTY_DECLVAR_CONTEXT(bgp, bgp);
8374 struct prefix_rd prd;
8375 int ret;
8376 afi_t afi;
8377 int idx = 0;
8378 bool yes = true;
8379
8380 if (argv_find(argv, argc, "no", &idx))
8381 yes = false;
8382
8383 if (yes) {
8384 ret = str2prefix_rd(rd_str, &prd);
8385 if (!ret) {
8386 vty_out(vty, "%% Malformed rd\n");
8387 return CMD_WARNING_CONFIG_FAILED;
8388 }
8389 }
8390
8391 afi = vpn_policy_getafi(vty, bgp, false);
8392 if (afi == AFI_MAX)
8393 return CMD_WARNING_CONFIG_FAILED;
8394
8395 /*
8396 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8397 */
8398 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8399 bgp_get_default(), bgp);
8400
8401 if (yes) {
8402 bgp->vpn_policy[afi].tovpn_rd = prd;
8403 SET_FLAG(bgp->vpn_policy[afi].flags,
8404 BGP_VPN_POLICY_TOVPN_RD_SET);
8405 } else {
8406 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8407 BGP_VPN_POLICY_TOVPN_RD_SET);
8408 }
8409
8410 /* post-change: re-export vpn routes */
8411 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8412 bgp_get_default(), bgp);
8413
8414 return CMD_SUCCESS;
8415 }
8416
8417 ALIAS (af_rd_vpn_export,
8418 af_no_rd_vpn_export_cmd,
8419 "no rd vpn export",
8420 NO_STR
8421 "Specify route distinguisher\n"
8422 "Between current address-family and vpn\n"
8423 "For routes leaked from current address-family to vpn\n")
8424
8425 DEFPY (af_label_vpn_export,
8426 af_label_vpn_export_cmd,
8427 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8428 NO_STR
8429 "label value for VRF\n"
8430 "Between current address-family and vpn\n"
8431 "For routes leaked from current address-family to vpn\n"
8432 "Label Value <0-1048575>\n"
8433 "Automatically assign a label\n")
8434 {
8435 VTY_DECLVAR_CONTEXT(bgp, bgp);
8436 mpls_label_t label = MPLS_LABEL_NONE;
8437 afi_t afi;
8438 int idx = 0;
8439 bool yes = true;
8440
8441 if (argv_find(argv, argc, "no", &idx))
8442 yes = false;
8443
8444 /* If "no ...", squash trailing parameter */
8445 if (!yes)
8446 label_auto = NULL;
8447
8448 if (yes) {
8449 if (!label_auto)
8450 label = label_val; /* parser should force unsigned */
8451 }
8452
8453 afi = vpn_policy_getafi(vty, bgp, false);
8454 if (afi == AFI_MAX)
8455 return CMD_WARNING_CONFIG_FAILED;
8456
8457
8458 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8459 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8460 /* no change */
8461 return CMD_SUCCESS;
8462
8463 /*
8464 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8465 */
8466 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8467 bgp_get_default(), bgp);
8468
8469 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8470 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8471
8472 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8473
8474 /*
8475 * label has previously been automatically
8476 * assigned by labelpool: release it
8477 *
8478 * NB if tovpn_label == MPLS_LABEL_NONE it
8479 * means the automatic assignment is in flight
8480 * and therefore the labelpool callback must
8481 * detect that the auto label is not needed.
8482 */
8483
8484 bgp_lp_release(LP_TYPE_VRF,
8485 &bgp->vpn_policy[afi],
8486 bgp->vpn_policy[afi].tovpn_label);
8487 }
8488 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8489 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8490 }
8491
8492 bgp->vpn_policy[afi].tovpn_label = label;
8493 if (label_auto) {
8494 SET_FLAG(bgp->vpn_policy[afi].flags,
8495 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8496 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8497 vpn_leak_label_callback);
8498 }
8499
8500 /* post-change: re-export vpn routes */
8501 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8502 bgp_get_default(), bgp);
8503
8504 hook_call(bgp_snmp_update_last_changed, bgp);
8505 return CMD_SUCCESS;
8506 }
8507
8508 DEFPY (af_sid_vpn_export,
8509 af_sid_vpn_export_cmd,
8510 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8511 NO_STR
8512 "sid value for VRF\n"
8513 "Between current address-family and vpn\n"
8514 "For routes leaked from current address-family to vpn\n"
8515 "Sid allocation index\n"
8516 "Automatically assign a label\n")
8517 {
8518 VTY_DECLVAR_CONTEXT(bgp, bgp);
8519 afi_t afi;
8520 int debug = 0;
8521 int idx = 0;
8522 bool yes = true;
8523
8524 if (argv_find(argv, argc, "no", &idx))
8525 yes = false;
8526 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8527 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8528
8529 afi = vpn_policy_getafi(vty, bgp, false);
8530 if (afi == AFI_MAX)
8531 return CMD_WARNING_CONFIG_FAILED;
8532
8533 if (!yes) {
8534 /* implement me */
8535 vty_out(vty, "It's not implemented");
8536 return CMD_WARNING_CONFIG_FAILED;
8537 }
8538
8539 /* skip when it's already configured */
8540 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8541 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8542 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8543 return CMD_SUCCESS;
8544
8545 /*
8546 * mode change between sid_idx and sid_auto isn't supported.
8547 * user must negate sid vpn export when they want to change the mode
8548 */
8549 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8550 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8551 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8552 vty_out(vty, "it's already configured as %s.\n",
8553 sid_auto ? "auto-mode" : "idx-mode");
8554 return CMD_WARNING_CONFIG_FAILED;
8555 }
8556
8557 /* pre-change */
8558 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8559 bgp_get_default(), bgp);
8560
8561 if (sid_auto) {
8562 /* SID allocation auto-mode */
8563 if (debug)
8564 zlog_debug("%s: auto sid alloc.", __func__);
8565 SET_FLAG(bgp->vpn_policy[afi].flags,
8566 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8567 } else {
8568 /* SID allocation index-mode */
8569 if (debug)
8570 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8571 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8572 }
8573
8574 /* post-change */
8575 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8576 bgp_get_default(), bgp);
8577 return CMD_SUCCESS;
8578 }
8579
8580 ALIAS (af_label_vpn_export,
8581 af_no_label_vpn_export_cmd,
8582 "no label vpn export",
8583 NO_STR
8584 "label value for VRF\n"
8585 "Between current address-family and vpn\n"
8586 "For routes leaked from current address-family to vpn\n")
8587
8588 DEFPY (af_nexthop_vpn_export,
8589 af_nexthop_vpn_export_cmd,
8590 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8591 NO_STR
8592 "Specify next hop to use for VRF advertised prefixes\n"
8593 "Between current address-family and vpn\n"
8594 "For routes leaked from current address-family to vpn\n"
8595 "IPv4 prefix\n"
8596 "IPv6 prefix\n")
8597 {
8598 VTY_DECLVAR_CONTEXT(bgp, bgp);
8599 afi_t afi;
8600 struct prefix p;
8601
8602 if (!no) {
8603 if (!nexthop_su) {
8604 vty_out(vty, "%% Nexthop required\n");
8605 return CMD_WARNING_CONFIG_FAILED;
8606 }
8607 if (!sockunion2hostprefix(nexthop_su, &p))
8608 return CMD_WARNING_CONFIG_FAILED;
8609 }
8610
8611 afi = vpn_policy_getafi(vty, bgp, false);
8612 if (afi == AFI_MAX)
8613 return CMD_WARNING_CONFIG_FAILED;
8614
8615 /*
8616 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8617 */
8618 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8619 bgp_get_default(), bgp);
8620
8621 if (!no) {
8622 bgp->vpn_policy[afi].tovpn_nexthop = p;
8623 SET_FLAG(bgp->vpn_policy[afi].flags,
8624 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8625 } else {
8626 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8627 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8628 }
8629
8630 /* post-change: re-export vpn routes */
8631 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8632 bgp_get_default(), bgp);
8633
8634 return CMD_SUCCESS;
8635 }
8636
8637 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8638 {
8639 if (!strcmp(dstr, "import")) {
8640 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8641 } else if (!strcmp(dstr, "export")) {
8642 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8643 } else if (!strcmp(dstr, "both")) {
8644 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8645 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8646 } else {
8647 vty_out(vty, "%% direction parse error\n");
8648 return CMD_WARNING_CONFIG_FAILED;
8649 }
8650 return CMD_SUCCESS;
8651 }
8652
8653 DEFPY (af_rt_vpn_imexport,
8654 af_rt_vpn_imexport_cmd,
8655 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8656 NO_STR
8657 "Specify route target list\n"
8658 "Specify route target list\n"
8659 "Between current address-family and vpn\n"
8660 "For routes leaked from vpn to current address-family: match any\n"
8661 "For routes leaked from current address-family to vpn: set\n"
8662 "both import: match any and export: set\n"
8663 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8664 {
8665 VTY_DECLVAR_CONTEXT(bgp, bgp);
8666 int ret;
8667 struct ecommunity *ecom = NULL;
8668 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8669 vpn_policy_direction_t dir;
8670 afi_t afi;
8671 int idx = 0;
8672 bool yes = true;
8673
8674 if (argv_find(argv, argc, "no", &idx))
8675 yes = false;
8676
8677 afi = vpn_policy_getafi(vty, bgp, false);
8678 if (afi == AFI_MAX)
8679 return CMD_WARNING_CONFIG_FAILED;
8680
8681 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8682 if (ret != CMD_SUCCESS)
8683 return ret;
8684
8685 if (yes) {
8686 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8687 vty_out(vty, "%% Missing RTLIST\n");
8688 return CMD_WARNING_CONFIG_FAILED;
8689 }
8690 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8691 if (ret != CMD_SUCCESS) {
8692 return ret;
8693 }
8694 }
8695
8696 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8697 if (!dodir[dir])
8698 continue;
8699
8700 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8701
8702 if (yes) {
8703 if (bgp->vpn_policy[afi].rtlist[dir])
8704 ecommunity_free(
8705 &bgp->vpn_policy[afi].rtlist[dir]);
8706 bgp->vpn_policy[afi].rtlist[dir] =
8707 ecommunity_dup(ecom);
8708 } else {
8709 if (bgp->vpn_policy[afi].rtlist[dir])
8710 ecommunity_free(
8711 &bgp->vpn_policy[afi].rtlist[dir]);
8712 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8713 }
8714
8715 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8716 }
8717
8718 if (ecom)
8719 ecommunity_free(&ecom);
8720
8721 return CMD_SUCCESS;
8722 }
8723
8724 ALIAS (af_rt_vpn_imexport,
8725 af_no_rt_vpn_imexport_cmd,
8726 "no <rt|route-target> vpn <import|export|both>$direction_str",
8727 NO_STR
8728 "Specify route target list\n"
8729 "Specify route target list\n"
8730 "Between current address-family and vpn\n"
8731 "For routes leaked from vpn to current address-family\n"
8732 "For routes leaked from current address-family to vpn\n"
8733 "both import and export\n")
8734
8735 DEFPY (af_route_map_vpn_imexport,
8736 af_route_map_vpn_imexport_cmd,
8737 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8738 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8739 NO_STR
8740 "Specify route map\n"
8741 "Between current address-family and vpn\n"
8742 "For routes leaked from vpn to current address-family\n"
8743 "For routes leaked from current address-family to vpn\n"
8744 "name of route-map\n")
8745 {
8746 VTY_DECLVAR_CONTEXT(bgp, bgp);
8747 int ret;
8748 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8749 vpn_policy_direction_t dir;
8750 afi_t afi;
8751 int idx = 0;
8752 bool yes = true;
8753
8754 if (argv_find(argv, argc, "no", &idx))
8755 yes = false;
8756
8757 afi = vpn_policy_getafi(vty, bgp, false);
8758 if (afi == AFI_MAX)
8759 return CMD_WARNING_CONFIG_FAILED;
8760
8761 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8762 if (ret != CMD_SUCCESS)
8763 return ret;
8764
8765 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8766 if (!dodir[dir])
8767 continue;
8768
8769 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8770
8771 if (yes) {
8772 if (bgp->vpn_policy[afi].rmap_name[dir])
8773 XFREE(MTYPE_ROUTE_MAP_NAME,
8774 bgp->vpn_policy[afi].rmap_name[dir]);
8775 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8776 MTYPE_ROUTE_MAP_NAME, rmap_str);
8777 bgp->vpn_policy[afi].rmap[dir] =
8778 route_map_lookup_warn_noexist(vty, rmap_str);
8779 if (!bgp->vpn_policy[afi].rmap[dir])
8780 return CMD_SUCCESS;
8781 } else {
8782 if (bgp->vpn_policy[afi].rmap_name[dir])
8783 XFREE(MTYPE_ROUTE_MAP_NAME,
8784 bgp->vpn_policy[afi].rmap_name[dir]);
8785 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8786 bgp->vpn_policy[afi].rmap[dir] = NULL;
8787 }
8788
8789 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8790 }
8791
8792 return CMD_SUCCESS;
8793 }
8794
8795 ALIAS (af_route_map_vpn_imexport,
8796 af_no_route_map_vpn_imexport_cmd,
8797 "no route-map vpn <import|export>$direction_str",
8798 NO_STR
8799 "Specify route map\n"
8800 "Between current address-family and vpn\n"
8801 "For routes leaked from vpn to current address-family\n"
8802 "For routes leaked from current address-family to vpn\n")
8803
8804 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
8805 "import vrf route-map RMAP$rmap_str",
8806 "Import routes from another VRF\n"
8807 "Vrf routes being filtered\n"
8808 "Specify route map\n"
8809 "name of route-map\n")
8810 {
8811 VTY_DECLVAR_CONTEXT(bgp, bgp);
8812 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8813 afi_t afi;
8814 struct bgp *bgp_default;
8815
8816 afi = vpn_policy_getafi(vty, bgp, true);
8817 if (afi == AFI_MAX)
8818 return CMD_WARNING_CONFIG_FAILED;
8819
8820 bgp_default = bgp_get_default();
8821 if (!bgp_default) {
8822 int32_t ret;
8823 as_t as = bgp->as;
8824
8825 /* Auto-create assuming the same AS */
8826 ret = bgp_get_vty(&bgp_default, &as, NULL,
8827 BGP_INSTANCE_TYPE_DEFAULT);
8828
8829 if (ret) {
8830 vty_out(vty,
8831 "VRF default is not configured as a bgp instance\n");
8832 return CMD_WARNING;
8833 }
8834 }
8835
8836 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8837
8838 if (bgp->vpn_policy[afi].rmap_name[dir])
8839 XFREE(MTYPE_ROUTE_MAP_NAME,
8840 bgp->vpn_policy[afi].rmap_name[dir]);
8841 bgp->vpn_policy[afi].rmap_name[dir] =
8842 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8843 bgp->vpn_policy[afi].rmap[dir] =
8844 route_map_lookup_warn_noexist(vty, rmap_str);
8845 if (!bgp->vpn_policy[afi].rmap[dir])
8846 return CMD_SUCCESS;
8847
8848 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8849 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8850
8851 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8852
8853 return CMD_SUCCESS;
8854 }
8855
8856 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8857 "no import vrf route-map [RMAP$rmap_str]",
8858 NO_STR
8859 "Import routes from another VRF\n"
8860 "Vrf routes being filtered\n"
8861 "Specify route map\n"
8862 "name of route-map\n")
8863 {
8864 VTY_DECLVAR_CONTEXT(bgp, bgp);
8865 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8866 afi_t afi;
8867
8868 afi = vpn_policy_getafi(vty, bgp, true);
8869 if (afi == AFI_MAX)
8870 return CMD_WARNING_CONFIG_FAILED;
8871
8872 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8873
8874 if (bgp->vpn_policy[afi].rmap_name[dir])
8875 XFREE(MTYPE_ROUTE_MAP_NAME,
8876 bgp->vpn_policy[afi].rmap_name[dir]);
8877 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8878 bgp->vpn_policy[afi].rmap[dir] = NULL;
8879
8880 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8881 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8882 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8883
8884 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8885
8886 return CMD_SUCCESS;
8887 }
8888
8889 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8890 "[no] import vrf VIEWVRFNAME$import_name",
8891 NO_STR
8892 "Import routes from another VRF\n"
8893 "VRF to import from\n"
8894 "The name of the VRF\n")
8895 {
8896 VTY_DECLVAR_CONTEXT(bgp, bgp);
8897 struct listnode *node;
8898 struct bgp *vrf_bgp, *bgp_default;
8899 int32_t ret = 0;
8900 as_t as = bgp->as;
8901 bool remove = false;
8902 int32_t idx = 0;
8903 char *vname;
8904 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
8905 safi_t safi;
8906 afi_t afi;
8907
8908 if (import_name == NULL) {
8909 vty_out(vty, "%% Missing import name\n");
8910 return CMD_WARNING;
8911 }
8912
8913 if (strcmp(import_name, "route-map") == 0) {
8914 vty_out(vty, "%% Must include route-map name\n");
8915 return CMD_WARNING;
8916 }
8917
8918 if (argv_find(argv, argc, "no", &idx))
8919 remove = true;
8920
8921 afi = vpn_policy_getafi(vty, bgp, true);
8922 if (afi == AFI_MAX)
8923 return CMD_WARNING_CONFIG_FAILED;
8924
8925 safi = bgp_node_safi(vty);
8926
8927 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8928 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8929 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8930 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8931 remove ? "unimport" : "import", import_name);
8932 return CMD_WARNING;
8933 }
8934
8935 bgp_default = bgp_get_default();
8936 if (!bgp_default) {
8937 /* Auto-create assuming the same AS */
8938 ret = bgp_get_vty(&bgp_default, &as, NULL,
8939 BGP_INSTANCE_TYPE_DEFAULT);
8940
8941 if (ret) {
8942 vty_out(vty,
8943 "VRF default is not configured as a bgp instance\n");
8944 return CMD_WARNING;
8945 }
8946 }
8947
8948 vrf_bgp = bgp_lookup_by_name(import_name);
8949 if (!vrf_bgp) {
8950 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8951 vrf_bgp = bgp_default;
8952 else
8953 /* Auto-create assuming the same AS */
8954 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8955
8956 if (ret) {
8957 vty_out(vty,
8958 "VRF %s is not configured as a bgp instance\n",
8959 import_name);
8960 return CMD_WARNING;
8961 }
8962 }
8963
8964 if (remove) {
8965 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8966 } else {
8967 /* Already importing from "import_vrf"? */
8968 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8969 vname)) {
8970 if (strcmp(vname, import_name) == 0)
8971 return CMD_WARNING;
8972 }
8973
8974 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8975 }
8976
8977 return CMD_SUCCESS;
8978 }
8979
8980 /* This command is valid only in a bgp vrf instance or the default instance */
8981 DEFPY (bgp_imexport_vpn,
8982 bgp_imexport_vpn_cmd,
8983 "[no] <import|export>$direction_str vpn",
8984 NO_STR
8985 "Import routes to this address-family\n"
8986 "Export routes from this address-family\n"
8987 "to/from default instance VPN RIB\n")
8988 {
8989 VTY_DECLVAR_CONTEXT(bgp, bgp);
8990 int previous_state;
8991 afi_t afi;
8992 safi_t safi;
8993 int idx = 0;
8994 bool yes = true;
8995 int flag;
8996 vpn_policy_direction_t dir;
8997
8998 if (argv_find(argv, argc, "no", &idx))
8999 yes = false;
9000
9001 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9002 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9003
9004 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9005 return CMD_WARNING_CONFIG_FAILED;
9006 }
9007
9008 afi = bgp_node_afi(vty);
9009 safi = bgp_node_safi(vty);
9010 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9011 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9012 return CMD_WARNING_CONFIG_FAILED;
9013 }
9014
9015 if (!strcmp(direction_str, "import")) {
9016 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9017 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9018 } else if (!strcmp(direction_str, "export")) {
9019 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9020 dir = BGP_VPN_POLICY_DIR_TOVPN;
9021 } else {
9022 vty_out(vty, "%% unknown direction %s\n", direction_str);
9023 return CMD_WARNING_CONFIG_FAILED;
9024 }
9025
9026 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9027
9028 if (yes) {
9029 SET_FLAG(bgp->af_flags[afi][safi], flag);
9030 if (!previous_state) {
9031 /* trigger export current vrf */
9032 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9033 }
9034 } else {
9035 if (previous_state) {
9036 /* trigger un-export current vrf */
9037 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9038 }
9039 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9040 }
9041
9042 hook_call(bgp_snmp_init_stats, bgp);
9043
9044 return CMD_SUCCESS;
9045 }
9046
9047 DEFPY (af_routetarget_import,
9048 af_routetarget_import_cmd,
9049 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9050 NO_STR
9051 "Specify route target list\n"
9052 "Specify route target list\n"
9053 "Specify route target list\n"
9054 "Specify route target list\n"
9055 "Flow-spec redirect type route target\n"
9056 "Import routes to this address-family\n"
9057 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9058 {
9059 VTY_DECLVAR_CONTEXT(bgp, bgp);
9060 int ret;
9061 struct ecommunity *ecom = NULL;
9062 afi_t afi;
9063 int idx = 0, idx_unused = 0;
9064 bool yes = true;
9065 bool rt6 = false;
9066
9067 if (argv_find(argv, argc, "no", &idx))
9068 yes = false;
9069
9070 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9071 argv_find(argv, argc, "route-target6", &idx_unused))
9072 rt6 = true;
9073
9074 afi = vpn_policy_getafi(vty, bgp, false);
9075 if (afi == AFI_MAX)
9076 return CMD_WARNING_CONFIG_FAILED;
9077
9078 if (rt6 && afi != AFI_IP6)
9079 return CMD_WARNING_CONFIG_FAILED;
9080
9081 if (yes) {
9082 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9083 vty_out(vty, "%% Missing RTLIST\n");
9084 return CMD_WARNING_CONFIG_FAILED;
9085 }
9086 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9087 if (ret != CMD_SUCCESS)
9088 return ret;
9089 }
9090
9091 if (yes) {
9092 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9093 ecommunity_free(&bgp->vpn_policy[afi]
9094 .import_redirect_rtlist);
9095 bgp->vpn_policy[afi].import_redirect_rtlist =
9096 ecommunity_dup(ecom);
9097 } else {
9098 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9099 ecommunity_free(&bgp->vpn_policy[afi]
9100 .import_redirect_rtlist);
9101 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9102 }
9103
9104 if (ecom)
9105 ecommunity_free(&ecom);
9106
9107 return CMD_SUCCESS;
9108 }
9109
9110 DEFUN_NOSH (address_family_ipv4_safi,
9111 address_family_ipv4_safi_cmd,
9112 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9113 "Enter Address Family command mode\n"
9114 "Address Family\n"
9115 BGP_SAFI_WITH_LABEL_HELP_STR)
9116 {
9117
9118 if (argc == 3) {
9119 VTY_DECLVAR_CONTEXT(bgp, bgp);
9120 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9121 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9122 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9123 && safi != SAFI_EVPN) {
9124 vty_out(vty,
9125 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9126 return CMD_WARNING_CONFIG_FAILED;
9127 }
9128 vty->node = bgp_node_type(AFI_IP, safi);
9129 } else
9130 vty->node = BGP_IPV4_NODE;
9131
9132 return CMD_SUCCESS;
9133 }
9134
9135 DEFUN_NOSH (address_family_ipv6_safi,
9136 address_family_ipv6_safi_cmd,
9137 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9138 "Enter Address Family command mode\n"
9139 "Address Family\n"
9140 BGP_SAFI_WITH_LABEL_HELP_STR)
9141 {
9142 if (argc == 3) {
9143 VTY_DECLVAR_CONTEXT(bgp, bgp);
9144 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9145 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9146 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9147 && safi != SAFI_EVPN) {
9148 vty_out(vty,
9149 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9150 return CMD_WARNING_CONFIG_FAILED;
9151 }
9152 vty->node = bgp_node_type(AFI_IP6, safi);
9153 } else
9154 vty->node = BGP_IPV6_NODE;
9155
9156 return CMD_SUCCESS;
9157 }
9158
9159 #ifdef KEEP_OLD_VPN_COMMANDS
9160 DEFUN_NOSH (address_family_vpnv4,
9161 address_family_vpnv4_cmd,
9162 "address-family vpnv4 [unicast]",
9163 "Enter Address Family command mode\n"
9164 "Address Family\n"
9165 "Address Family modifier\n")
9166 {
9167 vty->node = BGP_VPNV4_NODE;
9168 return CMD_SUCCESS;
9169 }
9170
9171 DEFUN_NOSH (address_family_vpnv6,
9172 address_family_vpnv6_cmd,
9173 "address-family vpnv6 [unicast]",
9174 "Enter Address Family command mode\n"
9175 "Address Family\n"
9176 "Address Family modifier\n")
9177 {
9178 vty->node = BGP_VPNV6_NODE;
9179 return CMD_SUCCESS;
9180 }
9181 #endif /* KEEP_OLD_VPN_COMMANDS */
9182
9183 DEFUN_NOSH (address_family_evpn,
9184 address_family_evpn_cmd,
9185 "address-family l2vpn evpn",
9186 "Enter Address Family command mode\n"
9187 "Address Family\n"
9188 "Address Family modifier\n")
9189 {
9190 VTY_DECLVAR_CONTEXT(bgp, bgp);
9191 vty->node = BGP_EVPN_NODE;
9192 return CMD_SUCCESS;
9193 }
9194
9195 DEFUN_NOSH (bgp_segment_routing_srv6,
9196 bgp_segment_routing_srv6_cmd,
9197 "segment-routing srv6",
9198 "Segment-Routing configuration\n"
9199 "Segment-Routing SRv6 configuration\n")
9200 {
9201 VTY_DECLVAR_CONTEXT(bgp, bgp);
9202 bgp->srv6_enabled = true;
9203 vty->node = BGP_SRV6_NODE;
9204 return CMD_SUCCESS;
9205 }
9206
9207 DEFUN (no_bgp_segment_routing_srv6,
9208 no_bgp_segment_routing_srv6_cmd,
9209 "no segment-routing srv6",
9210 NO_STR
9211 "Segment-Routing configuration\n"
9212 "Segment-Routing SRv6 configuration\n")
9213 {
9214 VTY_DECLVAR_CONTEXT(bgp, bgp);
9215
9216 if (strlen(bgp->srv6_locator_name) > 0)
9217 if (bgp_srv6_locator_unset(bgp) < 0)
9218 return CMD_WARNING_CONFIG_FAILED;
9219
9220 bgp->srv6_enabled = false;
9221 return CMD_SUCCESS;
9222 }
9223
9224 DEFPY (bgp_srv6_locator,
9225 bgp_srv6_locator_cmd,
9226 "locator NAME$name",
9227 "Specify SRv6 locator\n"
9228 "Specify SRv6 locator\n")
9229 {
9230 VTY_DECLVAR_CONTEXT(bgp, bgp);
9231 int ret;
9232
9233 if (strlen(bgp->srv6_locator_name) > 0
9234 && strcmp(name, bgp->srv6_locator_name) != 0) {
9235 vty_out(vty, "srv6 locator is already configured\n");
9236 return CMD_WARNING_CONFIG_FAILED;
9237 }
9238
9239 snprintf(bgp->srv6_locator_name,
9240 sizeof(bgp->srv6_locator_name), "%s", name);
9241
9242 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9243 if (ret < 0)
9244 return CMD_WARNING_CONFIG_FAILED;
9245
9246 return CMD_SUCCESS;
9247 }
9248
9249 DEFPY (no_bgp_srv6_locator,
9250 no_bgp_srv6_locator_cmd,
9251 "no locator NAME$name",
9252 NO_STR
9253 "Specify SRv6 locator\n"
9254 "Specify SRv6 locator\n")
9255 {
9256 VTY_DECLVAR_CONTEXT(bgp, bgp);
9257
9258 /* when locator isn't configured, do nothing */
9259 if (strlen(bgp->srv6_locator_name) < 1)
9260 return CMD_SUCCESS;
9261
9262 /* name validation */
9263 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9264 vty_out(vty, "%% No srv6 locator is configured\n");
9265 return CMD_WARNING_CONFIG_FAILED;
9266 }
9267
9268 /* unset locator */
9269 if (bgp_srv6_locator_unset(bgp) < 0)
9270 return CMD_WARNING_CONFIG_FAILED;
9271
9272 return CMD_SUCCESS;
9273 }
9274
9275 DEFPY (show_bgp_srv6,
9276 show_bgp_srv6_cmd,
9277 "show bgp segment-routing srv6",
9278 SHOW_STR
9279 BGP_STR
9280 "BGP Segment Routing\n"
9281 "BGP Segment Routing SRv6\n")
9282 {
9283 struct bgp *bgp;
9284 struct listnode *node;
9285 struct prefix_ipv6 *chunk;
9286 struct bgp_srv6_function *func;
9287 struct in6_addr *tovpn4_sid;
9288 struct in6_addr *tovpn6_sid;
9289 char buf[256];
9290 char buf_tovpn4_sid[256];
9291 char buf_tovpn6_sid[256];
9292
9293 bgp = bgp_get_default();
9294 if (!bgp)
9295 return CMD_SUCCESS;
9296
9297 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9298 vty_out(vty, "locator_chunks:\n");
9299 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9300 prefix2str(chunk, buf, sizeof(buf));
9301 vty_out(vty, "- %s\n", buf);
9302 }
9303
9304 vty_out(vty, "functions:\n");
9305 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9306 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9307 vty_out(vty, "- sid: %s\n", buf);
9308 vty_out(vty, " locator: %s\n", func->locator_name);
9309 }
9310
9311 vty_out(vty, "bgps:\n");
9312 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9313 vty_out(vty, "- name: %s\n",
9314 bgp->name ? bgp->name : "default");
9315
9316 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9317 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9318 if (tovpn4_sid)
9319 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9320 sizeof(buf_tovpn4_sid));
9321 if (tovpn6_sid)
9322 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9323 sizeof(buf_tovpn6_sid));
9324
9325 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9326 tovpn4_sid ? buf_tovpn4_sid : "none");
9327 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9328 tovpn6_sid ? buf_tovpn6_sid : "none");
9329 }
9330
9331 return CMD_SUCCESS;
9332 }
9333
9334 DEFUN_NOSH (exit_address_family,
9335 exit_address_family_cmd,
9336 "exit-address-family",
9337 "Exit from Address Family configuration mode\n")
9338 {
9339 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9340 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9341 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9342 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9343 || vty->node == BGP_EVPN_NODE
9344 || vty->node == BGP_FLOWSPECV4_NODE
9345 || vty->node == BGP_FLOWSPECV6_NODE)
9346 vty->node = BGP_NODE;
9347 return CMD_SUCCESS;
9348 }
9349
9350 /* Recalculate bestpath and re-advertise a prefix */
9351 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9352 const char *ip_str, afi_t afi, safi_t safi,
9353 struct prefix_rd *prd)
9354 {
9355 int ret;
9356 struct prefix match;
9357 struct bgp_dest *dest;
9358 struct bgp_dest *rm;
9359 struct bgp *bgp;
9360 struct bgp_table *table;
9361 struct bgp_table *rib;
9362
9363 /* BGP structure lookup. */
9364 if (view_name) {
9365 bgp = bgp_lookup_by_name(view_name);
9366 if (bgp == NULL) {
9367 vty_out(vty, "%% Can't find BGP instance %s\n",
9368 view_name);
9369 return CMD_WARNING;
9370 }
9371 } else {
9372 bgp = bgp_get_default();
9373 if (bgp == NULL) {
9374 vty_out(vty, "%% No BGP process is configured\n");
9375 return CMD_WARNING;
9376 }
9377 }
9378
9379 /* Check IP address argument. */
9380 ret = str2prefix(ip_str, &match);
9381 if (!ret) {
9382 vty_out(vty, "%% address is malformed\n");
9383 return CMD_WARNING;
9384 }
9385
9386 match.family = afi2family(afi);
9387 rib = bgp->rib[afi][safi];
9388
9389 if (safi == SAFI_MPLS_VPN) {
9390 for (dest = bgp_table_top(rib); dest;
9391 dest = bgp_route_next(dest)) {
9392 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9393
9394 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9395 continue;
9396
9397 table = bgp_dest_get_bgp_table_info(dest);
9398 if (table == NULL)
9399 continue;
9400
9401 rm = bgp_node_match(table, &match);
9402 if (rm != NULL) {
9403 const struct prefix *rm_p =
9404 bgp_dest_get_prefix(rm);
9405
9406 if (rm_p->prefixlen == match.prefixlen) {
9407 SET_FLAG(rm->flags,
9408 BGP_NODE_USER_CLEAR);
9409 bgp_process(bgp, rm, afi, safi);
9410 }
9411 bgp_dest_unlock_node(rm);
9412 }
9413 }
9414 } else {
9415 dest = bgp_node_match(rib, &match);
9416 if (dest != NULL) {
9417 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9418
9419 if (dest_p->prefixlen == match.prefixlen) {
9420 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9421 bgp_process(bgp, dest, afi, safi);
9422 }
9423 bgp_dest_unlock_node(dest);
9424 }
9425 }
9426
9427 return CMD_SUCCESS;
9428 }
9429
9430 /* one clear bgp command to rule them all */
9431 DEFUN (clear_ip_bgp_all,
9432 clear_ip_bgp_all_cmd,
9433 "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>]",
9434 CLEAR_STR
9435 IP_STR
9436 BGP_STR
9437 BGP_INSTANCE_HELP_STR
9438 BGP_AFI_HELP_STR
9439 "Address Family\n"
9440 BGP_SAFI_WITH_LABEL_HELP_STR
9441 "Address Family modifier\n"
9442 "Clear all peers\n"
9443 "BGP IPv4 neighbor to clear\n"
9444 "BGP IPv6 neighbor to clear\n"
9445 "BGP neighbor on interface to clear\n"
9446 "Clear peers with the AS number\n"
9447 "Clear all external peers\n"
9448 "Clear all members of peer-group\n"
9449 "BGP peer-group name\n"
9450 BGP_SOFT_STR
9451 BGP_SOFT_IN_STR
9452 BGP_SOFT_OUT_STR
9453 BGP_SOFT_IN_STR
9454 "Push out prefix-list ORF and do inbound soft reconfig\n"
9455 BGP_SOFT_OUT_STR)
9456 {
9457 char *vrf = NULL;
9458
9459 afi_t afi = AFI_UNSPEC;
9460 safi_t safi = SAFI_UNSPEC;
9461 enum clear_sort clr_sort = clear_peer;
9462 enum bgp_clear_type clr_type;
9463 char *clr_arg = NULL;
9464
9465 int idx = 0;
9466
9467 /* clear [ip] bgp */
9468 if (argv_find(argv, argc, "ip", &idx))
9469 afi = AFI_IP;
9470
9471 /* [<vrf> VIEWVRFNAME] */
9472 if (argv_find(argv, argc, "vrf", &idx)) {
9473 vrf = argv[idx + 1]->arg;
9474 idx += 2;
9475 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9476 vrf = NULL;
9477 } else if (argv_find(argv, argc, "view", &idx)) {
9478 /* [<view> VIEWVRFNAME] */
9479 vrf = argv[idx + 1]->arg;
9480 idx += 2;
9481 }
9482 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9483 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9484 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9485
9486 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9487 if (argv_find(argv, argc, "*", &idx)) {
9488 clr_sort = clear_all;
9489 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9490 clr_sort = clear_peer;
9491 clr_arg = argv[idx]->arg;
9492 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9493 clr_sort = clear_peer;
9494 clr_arg = argv[idx]->arg;
9495 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9496 clr_sort = clear_group;
9497 idx++;
9498 clr_arg = argv[idx]->arg;
9499 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9500 clr_sort = clear_peer;
9501 clr_arg = argv[idx]->arg;
9502 } else if (argv_find(argv, argc, "WORD", &idx)) {
9503 clr_sort = clear_peer;
9504 clr_arg = argv[idx]->arg;
9505 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9506 clr_sort = clear_as;
9507 clr_arg = argv[idx]->arg;
9508 } else if (argv_find(argv, argc, "external", &idx)) {
9509 clr_sort = clear_external;
9510 }
9511
9512 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9513 if (argv_find(argv, argc, "soft", &idx)) {
9514 if (argv_find(argv, argc, "in", &idx)
9515 || argv_find(argv, argc, "out", &idx))
9516 clr_type = strmatch(argv[idx]->text, "in")
9517 ? BGP_CLEAR_SOFT_IN
9518 : BGP_CLEAR_SOFT_OUT;
9519 else
9520 clr_type = BGP_CLEAR_SOFT_BOTH;
9521 } else if (argv_find(argv, argc, "in", &idx)) {
9522 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9523 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9524 : BGP_CLEAR_SOFT_IN;
9525 } else if (argv_find(argv, argc, "out", &idx)) {
9526 clr_type = BGP_CLEAR_SOFT_OUT;
9527 } else
9528 clr_type = BGP_CLEAR_SOFT_NONE;
9529
9530 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9531 }
9532
9533 DEFUN (clear_ip_bgp_prefix,
9534 clear_ip_bgp_prefix_cmd,
9535 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9536 CLEAR_STR
9537 IP_STR
9538 BGP_STR
9539 BGP_INSTANCE_HELP_STR
9540 "Clear bestpath and re-advertise\n"
9541 "IPv4 prefix\n")
9542 {
9543 char *vrf = NULL;
9544 char *prefix = NULL;
9545
9546 int idx = 0;
9547
9548 /* [<view|vrf> VIEWVRFNAME] */
9549 if (argv_find(argv, argc, "vrf", &idx)) {
9550 vrf = argv[idx + 1]->arg;
9551 idx += 2;
9552 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9553 vrf = NULL;
9554 } else if (argv_find(argv, argc, "view", &idx)) {
9555 /* [<view> VIEWVRFNAME] */
9556 vrf = argv[idx + 1]->arg;
9557 idx += 2;
9558 }
9559
9560 prefix = argv[argc - 1]->arg;
9561
9562 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9563 }
9564
9565 DEFUN (clear_bgp_ipv6_safi_prefix,
9566 clear_bgp_ipv6_safi_prefix_cmd,
9567 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9568 CLEAR_STR
9569 IP_STR
9570 BGP_STR
9571 "Address Family\n"
9572 BGP_SAFI_HELP_STR
9573 "Clear bestpath and re-advertise\n"
9574 "IPv6 prefix\n")
9575 {
9576 int idx_safi = 0;
9577 int idx_ipv6_prefix = 0;
9578 safi_t safi = SAFI_UNICAST;
9579 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9580 argv[idx_ipv6_prefix]->arg : NULL;
9581
9582 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9583 return bgp_clear_prefix(
9584 vty, NULL, prefix, AFI_IP6,
9585 safi, NULL);
9586 }
9587
9588 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9589 clear_bgp_instance_ipv6_safi_prefix_cmd,
9590 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9591 CLEAR_STR
9592 IP_STR
9593 BGP_STR
9594 BGP_INSTANCE_HELP_STR
9595 "Address Family\n"
9596 BGP_SAFI_HELP_STR
9597 "Clear bestpath and re-advertise\n"
9598 "IPv6 prefix\n")
9599 {
9600 int idx_safi = 0;
9601 int idx_vrfview = 0;
9602 int idx_ipv6_prefix = 0;
9603 safi_t safi = SAFI_UNICAST;
9604 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9605 argv[idx_ipv6_prefix]->arg : NULL;
9606 char *vrfview = NULL;
9607
9608 /* [<view|vrf> VIEWVRFNAME] */
9609 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9610 vrfview = argv[idx_vrfview + 1]->arg;
9611 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9612 vrfview = NULL;
9613 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9614 /* [<view> VIEWVRFNAME] */
9615 vrfview = argv[idx_vrfview + 1]->arg;
9616 }
9617 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9618
9619 return bgp_clear_prefix(
9620 vty, vrfview, prefix,
9621 AFI_IP6, safi, NULL);
9622 }
9623
9624 DEFUN (show_bgp_views,
9625 show_bgp_views_cmd,
9626 "show [ip] bgp views",
9627 SHOW_STR
9628 IP_STR
9629 BGP_STR
9630 "Show the defined BGP views\n")
9631 {
9632 struct list *inst = bm->bgp;
9633 struct listnode *node;
9634 struct bgp *bgp;
9635
9636 vty_out(vty, "Defined BGP views:\n");
9637 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9638 /* Skip VRFs. */
9639 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9640 continue;
9641 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9642 bgp->as);
9643 }
9644
9645 return CMD_SUCCESS;
9646 }
9647
9648 DEFUN (show_bgp_vrfs,
9649 show_bgp_vrfs_cmd,
9650 "show [ip] bgp vrfs [json]",
9651 SHOW_STR
9652 IP_STR
9653 BGP_STR
9654 "Show BGP VRFs\n"
9655 JSON_STR)
9656 {
9657 char buf[ETHER_ADDR_STRLEN];
9658 struct list *inst = bm->bgp;
9659 struct listnode *node;
9660 struct bgp *bgp;
9661 bool uj = use_json(argc, argv);
9662 json_object *json = NULL;
9663 json_object *json_vrfs = NULL;
9664 int count = 0;
9665
9666 if (uj) {
9667 json = json_object_new_object();
9668 json_vrfs = json_object_new_object();
9669 }
9670
9671 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9672 const char *name, *type;
9673 struct peer *peer;
9674 struct listnode *node2, *nnode2;
9675 int peers_cfg, peers_estb;
9676 json_object *json_vrf = NULL;
9677
9678 /* Skip Views. */
9679 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9680 continue;
9681
9682 count++;
9683 if (!uj && count == 1) {
9684 vty_out(vty,
9685 "%4s %-5s %-16s %9s %10s %-37s\n",
9686 "Type", "Id", "routerId", "#PeersCfg",
9687 "#PeersEstb", "Name");
9688 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9689 "L3-VNI", "RouterMAC", "Interface");
9690 }
9691
9692 peers_cfg = peers_estb = 0;
9693 if (uj)
9694 json_vrf = json_object_new_object();
9695
9696
9697 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9698 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9699 continue;
9700 peers_cfg++;
9701 if (peer_established(peer))
9702 peers_estb++;
9703 }
9704
9705 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9706 name = VRF_DEFAULT_NAME;
9707 type = "DFLT";
9708 } else {
9709 name = bgp->name;
9710 type = "VRF";
9711 }
9712
9713
9714 if (uj) {
9715 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9716 ? -1
9717 : (int64_t)bgp->vrf_id;
9718 char buf[BUFSIZ] = {0};
9719
9720 json_object_string_add(json_vrf, "type", type);
9721 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9722 json_object_string_addf(json_vrf, "routerId", "%pI4",
9723 &bgp->router_id);
9724 json_object_int_add(json_vrf, "numConfiguredPeers",
9725 peers_cfg);
9726 json_object_int_add(json_vrf, "numEstablishedPeers",
9727 peers_estb);
9728
9729 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9730 json_object_string_add(
9731 json_vrf, "rmac",
9732 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9733 json_object_string_add(json_vrf, "interface",
9734 ifindex2ifname(bgp->l3vni_svi_ifindex,
9735 bgp->vrf_id));
9736 json_object_object_add(json_vrfs, name, json_vrf);
9737 } else {
9738 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
9739 type,
9740 bgp->vrf_id == VRF_UNKNOWN ? -1
9741 : (int)bgp->vrf_id,
9742 &bgp->router_id, peers_cfg, peers_estb, name);
9743 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9744 bgp->l3vni,
9745 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9746 ifindex2ifname(bgp->l3vni_svi_ifindex,
9747 bgp->vrf_id));
9748 }
9749 }
9750
9751 if (uj) {
9752 json_object_object_add(json, "vrfs", json_vrfs);
9753
9754 json_object_int_add(json, "totalVrfs", count);
9755
9756 vty_json(vty, json);
9757 } else {
9758 if (count)
9759 vty_out(vty,
9760 "\nTotal number of VRFs (including default): %d\n",
9761 count);
9762 }
9763
9764 return CMD_SUCCESS;
9765 }
9766
9767 DEFUN (show_bgp_mac_hash,
9768 show_bgp_mac_hash_cmd,
9769 "show bgp mac hash",
9770 SHOW_STR
9771 BGP_STR
9772 "Mac Address\n"
9773 "Mac Address database\n")
9774 {
9775 bgp_mac_dump_table(vty);
9776
9777 return CMD_SUCCESS;
9778 }
9779
9780 static void show_tip_entry(struct hash_bucket *bucket, void *args)
9781 {
9782 struct vty *vty = (struct vty *)args;
9783 struct tip_addr *tip = (struct tip_addr *)bucket->data;
9784
9785 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
9786 }
9787
9788 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9789 {
9790 vty_out(vty, "self nexthop database:\n");
9791 bgp_nexthop_show_address_hash(vty, bgp);
9792
9793 vty_out(vty, "Tunnel-ip database:\n");
9794 hash_iterate(bgp->tip_hash,
9795 (void (*)(struct hash_bucket *, void *))show_tip_entry,
9796 vty);
9797 }
9798
9799 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9800 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9801 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
9802 "martian next-hops\n"
9803 "martian next-hop database\n")
9804 {
9805 struct bgp *bgp = NULL;
9806 int idx = 0;
9807 char *name = NULL;
9808
9809 /* [<vrf> VIEWVRFNAME] */
9810 if (argv_find(argv, argc, "vrf", &idx)) {
9811 name = argv[idx + 1]->arg;
9812 if (name && strmatch(name, VRF_DEFAULT_NAME))
9813 name = NULL;
9814 } else if (argv_find(argv, argc, "view", &idx))
9815 /* [<view> VIEWVRFNAME] */
9816 name = argv[idx + 1]->arg;
9817 if (name)
9818 bgp = bgp_lookup_by_name(name);
9819 else
9820 bgp = bgp_get_default();
9821
9822 if (!bgp) {
9823 vty_out(vty, "%% No BGP process is configured\n");
9824 return CMD_WARNING;
9825 }
9826 bgp_show_martian_nexthops(vty, bgp);
9827
9828 return CMD_SUCCESS;
9829 }
9830
9831 DEFUN (show_bgp_memory,
9832 show_bgp_memory_cmd,
9833 "show [ip] bgp memory",
9834 SHOW_STR
9835 IP_STR
9836 BGP_STR
9837 "Global BGP memory statistics\n")
9838 {
9839 char memstrbuf[MTYPE_MEMSTR_LEN];
9840 unsigned long count;
9841
9842 /* RIB related usage stats */
9843 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9844 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9845 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9846 count * sizeof(struct bgp_dest)));
9847
9848 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9849 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9850 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9851 count * sizeof(struct bgp_path_info)));
9852 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9853 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9854 count,
9855 mtype_memstr(
9856 memstrbuf, sizeof(memstrbuf),
9857 count * sizeof(struct bgp_path_info_extra)));
9858
9859 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9860 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9861 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9862 count * sizeof(struct bgp_static)));
9863
9864 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9865 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9866 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9867 count * sizeof(struct bpacket)));
9868
9869 /* Adj-In/Out */
9870 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9871 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9872 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9873 count * sizeof(struct bgp_adj_in)));
9874 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9875 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9876 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9877 count * sizeof(struct bgp_adj_out)));
9878
9879 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9880 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9881 count,
9882 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9883 count * sizeof(struct bgp_nexthop_cache)));
9884
9885 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9886 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9887 count,
9888 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9889 count * sizeof(struct bgp_damp_info)));
9890
9891 /* Attributes */
9892 count = attr_count();
9893 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9894 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9895 count * sizeof(struct attr)));
9896
9897 if ((count = attr_unknown_count()))
9898 vty_out(vty, "%ld unknown attributes\n", count);
9899
9900 /* AS_PATH attributes */
9901 count = aspath_count();
9902 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9903 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9904 count * sizeof(struct aspath)));
9905
9906 count = mtype_stats_alloc(MTYPE_AS_SEG);
9907 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9908 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9909 count * sizeof(struct assegment)));
9910
9911 /* Other attributes */
9912 if ((count = community_count()))
9913 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9914 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9915 count * sizeof(struct community)));
9916 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9917 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9918 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9919 count * sizeof(struct ecommunity)));
9920 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9921 vty_out(vty,
9922 "%ld BGP large-community entries, using %s of memory\n",
9923 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9924 count * sizeof(struct lcommunity)));
9925
9926 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9927 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9928 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9929 count * sizeof(struct cluster_list)));
9930
9931 /* Peer related usage */
9932 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9933 vty_out(vty, "%ld peers, using %s of memory\n", count,
9934 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9935 count * sizeof(struct peer)));
9936
9937 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9938 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9939 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9940 count * sizeof(struct peer_group)));
9941
9942 /* Other */
9943 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9944 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9945 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9946 count * sizeof(regex_t)));
9947 return CMD_SUCCESS;
9948 }
9949
9950 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9951 {
9952 json_object *bestpath = json_object_new_object();
9953
9954 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
9955 json_object_string_add(bestpath, "asPath", "ignore");
9956
9957 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
9958 json_object_string_add(bestpath, "asPath", "confed");
9959
9960 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9961 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
9962 json_object_string_add(bestpath, "multiPathRelax",
9963 "as-set");
9964 else
9965 json_object_string_add(bestpath, "multiPathRelax",
9966 "true");
9967 } else
9968 json_object_string_add(bestpath, "multiPathRelax", "false");
9969
9970 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9971 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9972
9973 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
9974 json_object_string_add(bestpath, "compareRouterId", "true");
9975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9976 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9977 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
9978 json_object_string_add(bestpath, "med", "confed");
9979 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
9980 json_object_string_add(bestpath, "med",
9981 "missing-as-worst");
9982 else
9983 json_object_string_add(bestpath, "med", "true");
9984 }
9985
9986 json_object_object_add(json, "bestPath", bestpath);
9987 }
9988
9989 /* Print the error code/subcode for why the peer is down */
9990 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9991 json_object *json_peer, bool use_json)
9992 {
9993 const char *code_str;
9994 const char *subcode_str;
9995
9996 if (use_json) {
9997 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9998 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9999 char errorcodesubcode_hexstr[5];
10000 char errorcodesubcode_str[256];
10001
10002 code_str = bgp_notify_code_str(peer->notify.code);
10003 subcode_str = bgp_notify_subcode_str(
10004 peer->notify.code,
10005 peer->notify.subcode);
10006
10007 snprintf(errorcodesubcode_hexstr,
10008 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10009 peer->notify.code, peer->notify.subcode);
10010 json_object_string_add(json_peer,
10011 "lastErrorCodeSubcode",
10012 errorcodesubcode_hexstr);
10013 snprintf(errorcodesubcode_str, 255, "%s%s",
10014 code_str, subcode_str);
10015 json_object_string_add(json_peer,
10016 "lastNotificationReason",
10017 errorcodesubcode_str);
10018 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10019 && peer->notify.code == BGP_NOTIFY_CEASE
10020 && (peer->notify.subcode
10021 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10022 || peer->notify.subcode
10023 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10024 && peer->notify.length) {
10025 char msgbuf[1024];
10026 const char *msg_str;
10027
10028 msg_str = bgp_notify_admin_message(
10029 msgbuf, sizeof(msgbuf),
10030 (uint8_t *)peer->notify.data,
10031 peer->notify.length);
10032 if (msg_str)
10033 json_object_string_add(
10034 json_peer,
10035 "lastShutdownDescription",
10036 msg_str);
10037 }
10038
10039 }
10040 json_object_string_add(json_peer, "lastResetDueTo",
10041 peer_down_str[(int)peer->last_reset]);
10042 json_object_int_add(json_peer, "lastResetCode",
10043 peer->last_reset);
10044 } else {
10045 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10046 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10047 code_str = bgp_notify_code_str(peer->notify.code);
10048 subcode_str =
10049 bgp_notify_subcode_str(peer->notify.code,
10050 peer->notify.subcode);
10051 vty_out(vty, " Notification %s (%s%s)\n",
10052 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10053 ? "sent"
10054 : "received",
10055 code_str, subcode_str);
10056 } else {
10057 vty_out(vty, " %s\n",
10058 peer_down_str[(int)peer->last_reset]);
10059 }
10060 }
10061 }
10062
10063 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10064 safi_t safi)
10065 {
10066 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10067 }
10068
10069 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10070 struct peer *peer, json_object *json_peer,
10071 int max_neighbor_width, bool use_json)
10072 {
10073 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10074 int len;
10075
10076 if (use_json) {
10077 if (peer_dynamic_neighbor(peer))
10078 json_object_boolean_true_add(json_peer,
10079 "dynamicPeer");
10080 if (peer->hostname)
10081 json_object_string_add(json_peer, "hostname",
10082 peer->hostname);
10083
10084 if (peer->domainname)
10085 json_object_string_add(json_peer, "domainname",
10086 peer->domainname);
10087 json_object_int_add(json_peer, "connectionsEstablished",
10088 peer->established);
10089 json_object_int_add(json_peer, "connectionsDropped",
10090 peer->dropped);
10091 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10092 use_json, json_peer);
10093 if (peer_established(peer))
10094 json_object_string_add(json_peer, "lastResetDueTo",
10095 "AFI/SAFI Not Negotiated");
10096 else
10097 bgp_show_peer_reset(NULL, peer, json_peer, true);
10098 } else {
10099 dn_flag[1] = '\0';
10100 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10101 if (peer->hostname
10102 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10103 len = vty_out(vty, "%s%s(%s)", dn_flag,
10104 peer->hostname, peer->host);
10105 else
10106 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10107
10108 /* pad the neighbor column with spaces */
10109 if (len < max_neighbor_width)
10110 vty_out(vty, "%*s", max_neighbor_width - len,
10111 " ");
10112 vty_out(vty, "%7d %7d %9s", peer->established,
10113 peer->dropped,
10114 peer_uptime(peer->uptime, timebuf,
10115 BGP_UPTIME_LEN, 0, NULL));
10116 if (peer_established(peer))
10117 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10118 else
10119 bgp_show_peer_reset(vty, peer, NULL,
10120 false);
10121 }
10122 }
10123
10124 /* Strip peer's description to the given size. */
10125 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10126 {
10127 static char stripped[BUFSIZ];
10128 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10129
10130 strlcpy(stripped, desc, len + 1);
10131
10132 return stripped;
10133 }
10134
10135 /* Determine whether var peer should be filtered out of the summary. */
10136 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10137 struct peer *fpeer, int as_type,
10138 as_t as)
10139 {
10140
10141 /* filter neighbor XXXX */
10142 if (fpeer && fpeer != peer)
10143 return true;
10144
10145 /* filter remote-as (internal|external) */
10146 if (as_type != AS_UNSPECIFIED) {
10147 if (peer->as_type == AS_SPECIFIED) {
10148 if (as_type == AS_INTERNAL) {
10149 if (peer->as != peer->local_as)
10150 return true;
10151 } else if (peer->as == peer->local_as)
10152 return true;
10153 } else if (as_type != peer->as_type)
10154 return true;
10155 } else if (as && as != peer->as) /* filter remote-as XXX */
10156 return true;
10157
10158 return false;
10159 }
10160
10161 /* Show BGP peer's summary information.
10162 *
10163 * Peer's description is stripped according to if `wide` option is given
10164 * or not.
10165 *
10166 * When adding new columns to `show bgp summary` output, please make
10167 * sure `Desc` is the lastest column to show because it can contain
10168 * whitespaces and the whole output will be tricky.
10169 */
10170 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10171 struct peer *fpeer, int as_type, as_t as,
10172 uint16_t show_flags)
10173 {
10174 struct peer *peer;
10175 struct listnode *node, *nnode;
10176 unsigned int count = 0, dn_count = 0;
10177 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10178 char neighbor_buf[VTY_BUFSIZ];
10179 int neighbor_col_default_width = 16;
10180 int len, failed_count = 0;
10181 unsigned int filtered_count = 0;
10182 int max_neighbor_width = 0;
10183 int pfx_rcd_safi;
10184 json_object *json = NULL;
10185 json_object *json_peer = NULL;
10186 json_object *json_peers = NULL;
10187 struct peer_af *paf;
10188 struct bgp_filter *filter;
10189 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10190 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10191 bool show_established =
10192 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10193 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10194 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10195
10196 /* labeled-unicast routes are installed in the unicast table so in order
10197 * to
10198 * display the correct PfxRcd value we must look at SAFI_UNICAST
10199 */
10200
10201 if (safi == SAFI_LABELED_UNICAST)
10202 pfx_rcd_safi = SAFI_UNICAST;
10203 else
10204 pfx_rcd_safi = safi;
10205
10206 if (use_json) {
10207 json = json_object_new_object();
10208 json_peers = json_object_new_object();
10209 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10210 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10211 as_type, as)) {
10212 filtered_count++;
10213 count++;
10214 continue;
10215 }
10216
10217 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10218 continue;
10219
10220 if (peer->afc[afi][safi]) {
10221 /* See if we have at least a single failed peer */
10222 if (bgp_has_peer_failed(peer, afi, safi))
10223 failed_count++;
10224 count++;
10225 }
10226 if (peer_dynamic_neighbor(peer))
10227 dn_count++;
10228 }
10229
10230 } else {
10231 /* Loop over all neighbors that will be displayed to determine
10232 * how many
10233 * characters are needed for the Neighbor column
10234 */
10235 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10236 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10237 as_type, as)) {
10238 filtered_count++;
10239 count++;
10240 continue;
10241 }
10242
10243 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10244 continue;
10245
10246 if (peer->afc[afi][safi]) {
10247 memset(dn_flag, '\0', sizeof(dn_flag));
10248 if (peer_dynamic_neighbor(peer))
10249 dn_flag[0] = '*';
10250
10251 if (peer->hostname
10252 && CHECK_FLAG(bgp->flags,
10253 BGP_FLAG_SHOW_HOSTNAME))
10254 snprintf(neighbor_buf,
10255 sizeof(neighbor_buf),
10256 "%s%s(%s) ", dn_flag,
10257 peer->hostname, peer->host);
10258 else
10259 snprintf(neighbor_buf,
10260 sizeof(neighbor_buf), "%s%s ",
10261 dn_flag, peer->host);
10262
10263 len = strlen(neighbor_buf);
10264
10265 if (len > max_neighbor_width)
10266 max_neighbor_width = len;
10267
10268 /* See if we have at least a single failed peer */
10269 if (bgp_has_peer_failed(peer, afi, safi))
10270 failed_count++;
10271 count++;
10272 }
10273 }
10274
10275 /* Originally we displayed the Neighbor column as 16
10276 * characters wide so make that the default
10277 */
10278 if (max_neighbor_width < neighbor_col_default_width)
10279 max_neighbor_width = neighbor_col_default_width;
10280 }
10281
10282 if (show_failed && !failed_count) {
10283 if (use_json) {
10284 json_object_int_add(json, "failedPeersCount", 0);
10285 json_object_int_add(json, "dynamicPeers", dn_count);
10286 json_object_int_add(json, "totalPeers", count);
10287
10288 vty_json(vty, json);
10289 } else {
10290 vty_out(vty, "%% No failed BGP neighbors found\n");
10291 }
10292 return CMD_SUCCESS;
10293 }
10294
10295 count = 0; /* Reset the value as its used again */
10296 filtered_count = 0;
10297 dn_count = 0;
10298 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10299 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10300 continue;
10301
10302 if (!peer->afc[afi][safi])
10303 continue;
10304
10305 if (!count) {
10306 unsigned long ents;
10307 char memstrbuf[MTYPE_MEMSTR_LEN];
10308 int64_t vrf_id_ui;
10309
10310 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10311 ? -1
10312 : (int64_t)bgp->vrf_id;
10313
10314 /* Usage summary and header */
10315 if (use_json) {
10316 json_object_string_addf(json, "routerId",
10317 "%pI4",
10318 &bgp->router_id);
10319 json_object_int_add(json, "as", bgp->as);
10320 json_object_int_add(json, "vrfId", vrf_id_ui);
10321 json_object_string_add(
10322 json, "vrfName",
10323 (bgp->inst_type
10324 == BGP_INSTANCE_TYPE_DEFAULT)
10325 ? VRF_DEFAULT_NAME
10326 : bgp->name);
10327 } else {
10328 vty_out(vty,
10329 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10330 &bgp->router_id, bgp->as,
10331 bgp->vrf_id == VRF_UNKNOWN
10332 ? -1
10333 : (int)bgp->vrf_id);
10334 vty_out(vty, "\n");
10335 }
10336
10337 if (bgp_update_delay_configured(bgp)) {
10338 if (use_json) {
10339 json_object_int_add(
10340 json, "updateDelayLimit",
10341 bgp->v_update_delay);
10342
10343 if (bgp->v_update_delay
10344 != bgp->v_establish_wait)
10345 json_object_int_add(
10346 json,
10347 "updateDelayEstablishWait",
10348 bgp->v_establish_wait);
10349
10350 if (bgp_update_delay_active(bgp)) {
10351 json_object_string_add(
10352 json,
10353 "updateDelayFirstNeighbor",
10354 bgp->update_delay_begin_time);
10355 json_object_boolean_true_add(
10356 json,
10357 "updateDelayInProgress");
10358 } else {
10359 if (bgp->update_delay_over) {
10360 json_object_string_add(
10361 json,
10362 "updateDelayFirstNeighbor",
10363 bgp->update_delay_begin_time);
10364 json_object_string_add(
10365 json,
10366 "updateDelayBestpathResumed",
10367 bgp->update_delay_end_time);
10368 json_object_string_add(
10369 json,
10370 "updateDelayZebraUpdateResume",
10371 bgp->update_delay_zebra_resume_time);
10372 json_object_string_add(
10373 json,
10374 "updateDelayPeerUpdateResume",
10375 bgp->update_delay_peers_resume_time);
10376 }
10377 }
10378 } else {
10379 vty_out(vty,
10380 "Read-only mode update-delay limit: %d seconds\n",
10381 bgp->v_update_delay);
10382 if (bgp->v_update_delay
10383 != bgp->v_establish_wait)
10384 vty_out(vty,
10385 " Establish wait: %d seconds\n",
10386 bgp->v_establish_wait);
10387
10388 if (bgp_update_delay_active(bgp)) {
10389 vty_out(vty,
10390 " First neighbor established: %s\n",
10391 bgp->update_delay_begin_time);
10392 vty_out(vty,
10393 " Delay in progress\n");
10394 } else {
10395 if (bgp->update_delay_over) {
10396 vty_out(vty,
10397 " First neighbor established: %s\n",
10398 bgp->update_delay_begin_time);
10399 vty_out(vty,
10400 " Best-paths resumed: %s\n",
10401 bgp->update_delay_end_time);
10402 vty_out(vty,
10403 " zebra update resumed: %s\n",
10404 bgp->update_delay_zebra_resume_time);
10405 vty_out(vty,
10406 " peers update resumed: %s\n",
10407 bgp->update_delay_peers_resume_time);
10408 }
10409 }
10410 }
10411 }
10412
10413 if (use_json) {
10414 if (bgp_maxmed_onstartup_configured(bgp)
10415 && bgp->maxmed_active)
10416 json_object_boolean_true_add(
10417 json, "maxMedOnStartup");
10418 if (bgp->v_maxmed_admin)
10419 json_object_boolean_true_add(
10420 json, "maxMedAdministrative");
10421
10422 json_object_int_add(
10423 json, "tableVersion",
10424 bgp_table_version(bgp->rib[afi][safi]));
10425
10426 ents = bgp_table_count(bgp->rib[afi][safi]);
10427 json_object_int_add(json, "ribCount", ents);
10428 json_object_int_add(
10429 json, "ribMemory",
10430 ents * sizeof(struct bgp_dest));
10431
10432 ents = bgp->af_peer_count[afi][safi];
10433 json_object_int_add(json, "peerCount", ents);
10434 json_object_int_add(json, "peerMemory",
10435 ents * sizeof(struct peer));
10436
10437 if ((ents = listcount(bgp->group))) {
10438 json_object_int_add(
10439 json, "peerGroupCount", ents);
10440 json_object_int_add(
10441 json, "peerGroupMemory",
10442 ents * sizeof(struct
10443 peer_group));
10444 }
10445
10446 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10447 BGP_CONFIG_DAMPENING))
10448 json_object_boolean_true_add(
10449 json, "dampeningEnabled");
10450 } else {
10451 if (!show_terse) {
10452 if (bgp_maxmed_onstartup_configured(bgp)
10453 && bgp->maxmed_active)
10454 vty_out(vty,
10455 "Max-med on-startup active\n");
10456 if (bgp->v_maxmed_admin)
10457 vty_out(vty,
10458 "Max-med administrative active\n");
10459
10460 vty_out(vty,
10461 "BGP table version %" PRIu64
10462 "\n",
10463 bgp_table_version(
10464 bgp->rib[afi][safi]));
10465
10466 ents = bgp_table_count(
10467 bgp->rib[afi][safi]);
10468 vty_out(vty,
10469 "RIB entries %ld, using %s of memory\n",
10470 ents,
10471 mtype_memstr(
10472 memstrbuf,
10473 sizeof(memstrbuf),
10474 ents
10475 * sizeof(
10476 struct
10477 bgp_dest)));
10478
10479 /* Peer related usage */
10480 ents = bgp->af_peer_count[afi][safi];
10481 vty_out(vty,
10482 "Peers %ld, using %s of memory\n",
10483 ents,
10484 mtype_memstr(
10485 memstrbuf,
10486 sizeof(memstrbuf),
10487 ents
10488 * sizeof(
10489 struct
10490 peer)));
10491
10492 if ((ents = listcount(bgp->group)))
10493 vty_out(vty,
10494 "Peer groups %ld, using %s of memory\n",
10495 ents,
10496 mtype_memstr(
10497 memstrbuf,
10498 sizeof(memstrbuf),
10499 ents
10500 * sizeof(
10501 struct
10502 peer_group)));
10503
10504 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10505 BGP_CONFIG_DAMPENING))
10506 vty_out(vty,
10507 "Dampening enabled.\n");
10508 }
10509 if (show_failed) {
10510 vty_out(vty, "\n");
10511
10512 /* Subtract 8 here because 'Neighbor' is
10513 * 8 characters */
10514 vty_out(vty, "Neighbor");
10515 vty_out(vty, "%*s",
10516 max_neighbor_width - 8, " ");
10517 vty_out(vty,
10518 BGP_SHOW_SUMMARY_HEADER_FAILED);
10519 }
10520 }
10521 }
10522
10523 paf = peer_af_find(peer, afi, safi);
10524 filter = &peer->filter[afi][safi];
10525
10526 count++;
10527 /* Works for both failed & successful cases */
10528 if (peer_dynamic_neighbor(peer))
10529 dn_count++;
10530
10531 if (use_json) {
10532 json_peer = NULL;
10533 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10534 as_type, as)) {
10535 filtered_count++;
10536 continue;
10537 }
10538 if (show_failed &&
10539 bgp_has_peer_failed(peer, afi, safi)) {
10540 json_peer = json_object_new_object();
10541 bgp_show_failed_summary(vty, bgp, peer,
10542 json_peer, 0, use_json);
10543 } else if (!show_failed) {
10544 if (show_established
10545 && bgp_has_peer_failed(peer, afi, safi)) {
10546 filtered_count++;
10547 continue;
10548 }
10549
10550 json_peer = json_object_new_object();
10551 if (peer_dynamic_neighbor(peer)) {
10552 json_object_boolean_true_add(json_peer,
10553 "dynamicPeer");
10554 }
10555
10556 if (peer->hostname)
10557 json_object_string_add(json_peer, "hostname",
10558 peer->hostname);
10559
10560 if (peer->domainname)
10561 json_object_string_add(json_peer, "domainname",
10562 peer->domainname);
10563
10564 json_object_int_add(json_peer, "remoteAs", peer->as);
10565 json_object_int_add(
10566 json_peer, "localAs",
10567 peer->change_local_as
10568 ? peer->change_local_as
10569 : peer->local_as);
10570 json_object_int_add(json_peer, "version", 4);
10571 json_object_int_add(json_peer, "msgRcvd",
10572 PEER_TOTAL_RX(peer));
10573 json_object_int_add(json_peer, "msgSent",
10574 PEER_TOTAL_TX(peer));
10575
10576 atomic_size_t outq_count, inq_count;
10577 outq_count = atomic_load_explicit(
10578 &peer->obuf->count,
10579 memory_order_relaxed);
10580 inq_count = atomic_load_explicit(
10581 &peer->ibuf->count,
10582 memory_order_relaxed);
10583
10584 json_object_int_add(json_peer, "tableVersion",
10585 peer->version[afi][safi]);
10586 json_object_int_add(json_peer, "outq",
10587 outq_count);
10588 json_object_int_add(json_peer, "inq",
10589 inq_count);
10590 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10591 use_json, json_peer);
10592
10593 json_object_int_add(json_peer, "pfxRcd",
10594 peer->pcount[afi][pfx_rcd_safi]);
10595
10596 if (paf && PAF_SUBGRP(paf))
10597 json_object_int_add(
10598 json_peer, "pfxSnt",
10599 (PAF_SUBGRP(paf))->scount);
10600 else
10601 json_object_int_add(json_peer, "pfxSnt",
10602 0);
10603
10604 /* BGP FSM state */
10605 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10606 || CHECK_FLAG(peer->bgp->flags,
10607 BGP_FLAG_SHUTDOWN))
10608 json_object_string_add(json_peer,
10609 "state",
10610 "Idle (Admin)");
10611 else if (peer->afc_recv[afi][safi])
10612 json_object_string_add(
10613 json_peer, "state",
10614 lookup_msg(bgp_status_msg,
10615 peer->status, NULL));
10616 else if (CHECK_FLAG(
10617 peer->sflags,
10618 PEER_STATUS_PREFIX_OVERFLOW))
10619 json_object_string_add(json_peer,
10620 "state",
10621 "Idle (PfxCt)");
10622 else
10623 json_object_string_add(
10624 json_peer, "state",
10625 lookup_msg(bgp_status_msg,
10626 peer->status, NULL));
10627
10628 /* BGP peer state */
10629 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10630 || CHECK_FLAG(peer->bgp->flags,
10631 BGP_FLAG_SHUTDOWN))
10632 json_object_string_add(json_peer,
10633 "peerState",
10634 "Admin");
10635 else if (CHECK_FLAG(
10636 peer->sflags,
10637 PEER_STATUS_PREFIX_OVERFLOW))
10638 json_object_string_add(json_peer,
10639 "peerState",
10640 "PfxCt");
10641 else if (CHECK_FLAG(peer->flags,
10642 PEER_FLAG_PASSIVE))
10643 json_object_string_add(json_peer,
10644 "peerState",
10645 "Passive");
10646 else if (CHECK_FLAG(peer->sflags,
10647 PEER_STATUS_NSF_WAIT))
10648 json_object_string_add(json_peer,
10649 "peerState",
10650 "NSF passive");
10651 else if (CHECK_FLAG(
10652 peer->bgp->flags,
10653 BGP_FLAG_EBGP_REQUIRES_POLICY)
10654 && (!bgp_inbound_policy_exists(peer,
10655 filter)
10656 || !bgp_outbound_policy_exists(
10657 peer, filter)))
10658 json_object_string_add(json_peer,
10659 "peerState",
10660 "Policy");
10661 else
10662 json_object_string_add(
10663 json_peer, "peerState", "OK");
10664
10665 json_object_int_add(json_peer, "connectionsEstablished",
10666 peer->established);
10667 json_object_int_add(json_peer, "connectionsDropped",
10668 peer->dropped);
10669 if (peer->desc)
10670 json_object_string_add(
10671 json_peer, "desc", peer->desc);
10672 }
10673 /* Avoid creating empty peer dicts in JSON */
10674 if (json_peer == NULL)
10675 continue;
10676
10677 if (peer->conf_if)
10678 json_object_string_add(json_peer, "idType",
10679 "interface");
10680 else if (peer->su.sa.sa_family == AF_INET)
10681 json_object_string_add(json_peer, "idType",
10682 "ipv4");
10683 else if (peer->su.sa.sa_family == AF_INET6)
10684 json_object_string_add(json_peer, "idType",
10685 "ipv6");
10686 json_object_object_add(json_peers, peer->host,
10687 json_peer);
10688 } else {
10689 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10690 as_type, as)) {
10691 filtered_count++;
10692 continue;
10693 }
10694 if (show_failed &&
10695 bgp_has_peer_failed(peer, afi, safi)) {
10696 bgp_show_failed_summary(vty, bgp, peer, NULL,
10697 max_neighbor_width,
10698 use_json);
10699 } else if (!show_failed) {
10700 if (show_established
10701 && bgp_has_peer_failed(peer, afi, safi)) {
10702 filtered_count++;
10703 continue;
10704 }
10705
10706 if ((count - filtered_count) == 1) {
10707 /* display headline before the first
10708 * neighbor line */
10709 vty_out(vty, "\n");
10710
10711 /* Subtract 8 here because 'Neighbor' is
10712 * 8 characters */
10713 vty_out(vty, "Neighbor");
10714 vty_out(vty, "%*s",
10715 max_neighbor_width - 8, " ");
10716 vty_out(vty,
10717 show_wide
10718 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10719 : BGP_SHOW_SUMMARY_HEADER_ALL);
10720 }
10721
10722 memset(dn_flag, '\0', sizeof(dn_flag));
10723 if (peer_dynamic_neighbor(peer)) {
10724 dn_flag[0] = '*';
10725 }
10726
10727 if (peer->hostname
10728 && CHECK_FLAG(bgp->flags,
10729 BGP_FLAG_SHOW_HOSTNAME))
10730 len = vty_out(vty, "%s%s(%s)", dn_flag,
10731 peer->hostname,
10732 peer->host);
10733 else
10734 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10735
10736 /* pad the neighbor column with spaces */
10737 if (len < max_neighbor_width)
10738 vty_out(vty, "%*s", max_neighbor_width - len,
10739 " ");
10740
10741 atomic_size_t outq_count, inq_count;
10742 outq_count = atomic_load_explicit(
10743 &peer->obuf->count,
10744 memory_order_relaxed);
10745 inq_count = atomic_load_explicit(
10746 &peer->ibuf->count,
10747 memory_order_relaxed);
10748
10749 if (show_wide)
10750 vty_out(vty,
10751 "4 %10u %10u %9u %9u %8" PRIu64
10752 " %4zu %4zu %8s",
10753 peer->as,
10754 peer->change_local_as
10755 ? peer->change_local_as
10756 : peer->local_as,
10757 PEER_TOTAL_RX(peer),
10758 PEER_TOTAL_TX(peer),
10759 peer->version[afi][safi],
10760 inq_count, outq_count,
10761 peer_uptime(peer->uptime,
10762 timebuf,
10763 BGP_UPTIME_LEN, 0,
10764 NULL));
10765 else
10766 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10767 " %4zu %4zu %8s",
10768 peer->as, PEER_TOTAL_RX(peer),
10769 PEER_TOTAL_TX(peer),
10770 peer->version[afi][safi],
10771 inq_count, outq_count,
10772 peer_uptime(peer->uptime,
10773 timebuf,
10774 BGP_UPTIME_LEN, 0,
10775 NULL));
10776
10777 if (peer_established(peer)) {
10778 if (peer->afc_recv[afi][safi]) {
10779 if (CHECK_FLAG(
10780 bgp->flags,
10781 BGP_FLAG_EBGP_REQUIRES_POLICY)
10782 && !bgp_inbound_policy_exists(
10783 peer, filter))
10784 vty_out(vty, " %12s",
10785 "(Policy)");
10786 else
10787 vty_out(vty,
10788 " %12u",
10789 peer->pcount
10790 [afi]
10791 [pfx_rcd_safi]);
10792 } else {
10793 vty_out(vty, " NoNeg");
10794 }
10795
10796 if (paf && PAF_SUBGRP(paf)) {
10797 if (CHECK_FLAG(
10798 bgp->flags,
10799 BGP_FLAG_EBGP_REQUIRES_POLICY)
10800 && !bgp_outbound_policy_exists(
10801 peer, filter))
10802 vty_out(vty, " %8s",
10803 "(Policy)");
10804 else
10805 vty_out(vty,
10806 " %8u",
10807 (PAF_SUBGRP(
10808 paf))
10809 ->scount);
10810 } else {
10811 vty_out(vty, " NoNeg");
10812 }
10813 } else {
10814 if (CHECK_FLAG(peer->flags,
10815 PEER_FLAG_SHUTDOWN)
10816 || CHECK_FLAG(peer->bgp->flags,
10817 BGP_FLAG_SHUTDOWN))
10818 vty_out(vty, " Idle (Admin)");
10819 else if (CHECK_FLAG(
10820 peer->sflags,
10821 PEER_STATUS_PREFIX_OVERFLOW))
10822 vty_out(vty, " Idle (PfxCt)");
10823 else
10824 vty_out(vty, " %12s",
10825 lookup_msg(bgp_status_msg,
10826 peer->status, NULL));
10827
10828 vty_out(vty, " %8u", 0);
10829 }
10830 /* Make sure `Desc` column is the lastest in
10831 * the output.
10832 */
10833 if (peer->desc)
10834 vty_out(vty, " %s",
10835 bgp_peer_description_stripped(
10836 peer->desc,
10837 show_wide ? 64 : 20));
10838 else
10839 vty_out(vty, " N/A");
10840 vty_out(vty, "\n");
10841 }
10842
10843 }
10844 }
10845
10846 if (use_json) {
10847 json_object_object_add(json, "peers", json_peers);
10848 json_object_int_add(json, "failedPeers", failed_count);
10849 json_object_int_add(json, "displayedPeers",
10850 count - filtered_count);
10851 json_object_int_add(json, "totalPeers", count);
10852 json_object_int_add(json, "dynamicPeers", dn_count);
10853
10854 if (!show_failed)
10855 bgp_show_bestpath_json(bgp, json);
10856
10857 vty_json(vty, json);
10858 } else {
10859 if (count) {
10860 if (filtered_count == count)
10861 vty_out(vty, "\n%% No matching neighbor\n");
10862 else {
10863 if (show_failed)
10864 vty_out(vty, "\nDisplayed neighbors %d",
10865 failed_count);
10866 else if (as_type != AS_UNSPECIFIED || as
10867 || fpeer || show_established)
10868 vty_out(vty, "\nDisplayed neighbors %d",
10869 count - filtered_count);
10870
10871 vty_out(vty, "\nTotal number of neighbors %d\n",
10872 count);
10873 }
10874 } else {
10875 vty_out(vty, "No %s neighbor is configured\n",
10876 get_afi_safi_str(afi, safi, false));
10877 }
10878
10879 if (dn_count) {
10880 vty_out(vty, "* - dynamic neighbor\n");
10881 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10882 dn_count, bgp->dynamic_neighbors_limit);
10883 }
10884 }
10885
10886 return CMD_SUCCESS;
10887 }
10888
10889 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10890 int safi, struct peer *fpeer, int as_type,
10891 as_t as, uint16_t show_flags)
10892 {
10893 int is_first = 1;
10894 int afi_wildcard = (afi == AFI_MAX);
10895 int safi_wildcard = (safi == SAFI_MAX);
10896 int is_wildcard = (afi_wildcard || safi_wildcard);
10897 bool nbr_output = false;
10898 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10899
10900 if (use_json && is_wildcard)
10901 vty_out(vty, "{\n");
10902 if (afi_wildcard)
10903 afi = 1; /* AFI_IP */
10904 while (afi < AFI_MAX) {
10905 if (safi_wildcard)
10906 safi = 1; /* SAFI_UNICAST */
10907 while (safi < SAFI_MAX) {
10908 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
10909 nbr_output = true;
10910
10911 if (is_wildcard) {
10912 /*
10913 * So limit output to those afi/safi
10914 * pairs that
10915 * actualy have something interesting in
10916 * them
10917 */
10918 if (use_json) {
10919 if (!is_first)
10920 vty_out(vty, ",\n");
10921 else
10922 is_first = 0;
10923
10924 vty_out(vty, "\"%s\":",
10925 get_afi_safi_str(afi,
10926 safi,
10927 true));
10928 } else {
10929 vty_out(vty,
10930 "\n%s Summary (%s):\n",
10931 get_afi_safi_str(afi,
10932 safi,
10933 false),
10934 bgp->name_pretty);
10935 }
10936 }
10937 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10938 as_type, as, show_flags);
10939 }
10940 safi++;
10941 if (!safi_wildcard)
10942 safi = SAFI_MAX;
10943 }
10944 afi++;
10945 if (!afi_wildcard)
10946 afi = AFI_MAX;
10947 }
10948
10949 if (use_json && is_wildcard)
10950 vty_out(vty, "}\n");
10951 else if (!nbr_output) {
10952 if (use_json)
10953 vty_out(vty, "{}\n");
10954 else
10955 vty_out(vty, "%% No BGP neighbors found in %s\n",
10956 bgp->name_pretty);
10957 }
10958 }
10959
10960 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
10961 safi_t safi,
10962 const char *neighbor,
10963 int as_type, as_t as,
10964 uint16_t show_flags)
10965 {
10966 struct listnode *node, *nnode;
10967 struct bgp *bgp;
10968 struct peer *fpeer = NULL;
10969 int is_first = 1;
10970 bool nbr_output = false;
10971 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10972
10973 if (use_json)
10974 vty_out(vty, "{\n");
10975
10976 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10977 nbr_output = true;
10978 if (use_json) {
10979 if (!is_first)
10980 vty_out(vty, ",\n");
10981 else
10982 is_first = 0;
10983
10984 vty_out(vty, "\"%s\":",
10985 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10986 ? VRF_DEFAULT_NAME
10987 : bgp->name);
10988 }
10989 if (neighbor) {
10990 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10991 use_json);
10992 if (!fpeer)
10993 continue;
10994 }
10995 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
10996 as, show_flags);
10997 }
10998
10999 if (use_json)
11000 vty_out(vty, "}\n");
11001 else if (!nbr_output)
11002 vty_out(vty, "%% BGP instance not found\n");
11003 }
11004
11005 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11006 safi_t safi, const char *neighbor, int as_type,
11007 as_t as, uint16_t show_flags)
11008 {
11009 struct bgp *bgp;
11010 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11011 struct peer *fpeer = NULL;
11012
11013 if (name) {
11014 if (strmatch(name, "all")) {
11015 bgp_show_all_instances_summary_vty(vty, afi, safi,
11016 neighbor, as_type,
11017 as, show_flags);
11018 return CMD_SUCCESS;
11019 } else {
11020 bgp = bgp_lookup_by_name(name);
11021
11022 if (!bgp) {
11023 if (use_json)
11024 vty_out(vty, "{}\n");
11025 else
11026 vty_out(vty,
11027 "%% BGP instance not found\n");
11028 return CMD_WARNING;
11029 }
11030
11031 if (neighbor) {
11032 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11033 use_json);
11034 if (!fpeer)
11035 return CMD_WARNING;
11036 }
11037 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11038 as_type, as, show_flags);
11039 return CMD_SUCCESS;
11040 }
11041 }
11042
11043 bgp = bgp_get_default();
11044
11045 if (bgp) {
11046 if (neighbor) {
11047 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11048 use_json);
11049 if (!fpeer)
11050 return CMD_WARNING;
11051 }
11052 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11053 as, show_flags);
11054 } else {
11055 if (use_json)
11056 vty_out(vty, "{}\n");
11057 else
11058 vty_out(vty, "%% BGP instance not found\n");
11059 return CMD_WARNING;
11060 }
11061
11062 return CMD_SUCCESS;
11063 }
11064
11065 /* `show [ip] bgp summary' commands. */
11066 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11067 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11068 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11069 "]] [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]",
11070 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11071 BGP_SAFI_WITH_LABEL_HELP_STR
11072 "Display the entries for all address families\n"
11073 "Summary of BGP neighbor status\n"
11074 "Show only sessions in Established state\n"
11075 "Show only sessions not in Established state\n"
11076 "Show only the specified neighbor session\n"
11077 "Neighbor to display information about\n"
11078 "Neighbor to display information about\n"
11079 "Neighbor on BGP configured interface\n"
11080 "Show only the specified remote AS sessions\n"
11081 "AS number\n"
11082 "Internal (iBGP) AS sessions\n"
11083 "External (eBGP) AS sessions\n"
11084 "Shorten the information on BGP instances\n"
11085 "Increase table width for longer output\n" JSON_STR)
11086 {
11087 char *vrf = NULL;
11088 afi_t afi = AFI_MAX;
11089 safi_t safi = SAFI_MAX;
11090 as_t as = 0; /* 0 means AS filter not set */
11091 int as_type = AS_UNSPECIFIED;
11092 uint16_t show_flags = 0;
11093
11094 int idx = 0;
11095
11096 /* show [ip] bgp */
11097 if (!all && argv_find(argv, argc, "ip", &idx))
11098 afi = AFI_IP;
11099 /* [<vrf> VIEWVRFNAME] */
11100 if (argv_find(argv, argc, "vrf", &idx)) {
11101 vrf = argv[idx + 1]->arg;
11102 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11103 vrf = NULL;
11104 } else if (argv_find(argv, argc, "view", &idx))
11105 /* [<view> VIEWVRFNAME] */
11106 vrf = argv[idx + 1]->arg;
11107 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11108 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11109 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11110 }
11111
11112 if (argv_find(argv, argc, "failed", &idx))
11113 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11114
11115 if (argv_find(argv, argc, "established", &idx))
11116 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11117
11118 if (argv_find(argv, argc, "remote-as", &idx)) {
11119 if (argv[idx + 1]->arg[0] == 'i')
11120 as_type = AS_INTERNAL;
11121 else if (argv[idx + 1]->arg[0] == 'e')
11122 as_type = AS_EXTERNAL;
11123 else
11124 as = (as_t)atoi(argv[idx + 1]->arg);
11125 }
11126
11127 if (argv_find(argv, argc, "terse", &idx))
11128 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11129
11130 if (argv_find(argv, argc, "wide", &idx))
11131 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11132
11133 if (argv_find(argv, argc, "json", &idx))
11134 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11135
11136 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11137 show_flags);
11138 }
11139
11140 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11141 {
11142 if (for_json)
11143 return get_afi_safi_json_str(afi, safi);
11144 else
11145 return get_afi_safi_vty_str(afi, safi);
11146 }
11147
11148
11149 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11150 afi_t afi, safi_t safi,
11151 uint16_t adv_smcap, uint16_t adv_rmcap,
11152 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11153 bool use_json, json_object *json_pref)
11154 {
11155 /* Send-Mode */
11156 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11157 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11158 if (use_json) {
11159 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11160 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11161 json_object_string_add(json_pref, "sendMode",
11162 "advertisedAndReceived");
11163 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11164 json_object_string_add(json_pref, "sendMode",
11165 "advertised");
11166 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11167 json_object_string_add(json_pref, "sendMode",
11168 "received");
11169 } else {
11170 vty_out(vty, " Send-mode: ");
11171 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11172 vty_out(vty, "advertised");
11173 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11174 vty_out(vty, "%sreceived",
11175 CHECK_FLAG(p->af_cap[afi][safi],
11176 adv_smcap)
11177 ? ", "
11178 : "");
11179 vty_out(vty, "\n");
11180 }
11181 }
11182
11183 /* Receive-Mode */
11184 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11185 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11186 if (use_json) {
11187 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11188 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11189 json_object_string_add(json_pref, "recvMode",
11190 "advertisedAndReceived");
11191 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11192 json_object_string_add(json_pref, "recvMode",
11193 "advertised");
11194 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11195 json_object_string_add(json_pref, "recvMode",
11196 "received");
11197 } else {
11198 vty_out(vty, " Receive-mode: ");
11199 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11200 vty_out(vty, "advertised");
11201 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11202 vty_out(vty, "%sreceived",
11203 CHECK_FLAG(p->af_cap[afi][safi],
11204 adv_rmcap)
11205 ? ", "
11206 : "");
11207 vty_out(vty, "\n");
11208 }
11209 }
11210 }
11211
11212 static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11213 struct peer *p,
11214 bool use_json,
11215 json_object *json)
11216 {
11217 bool rbit_status = false;
11218
11219 if (!use_json)
11220 vty_out(vty, "\n R bit: ");
11221
11222 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11223 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11224 && (peer_established(p))) {
11225
11226 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11227 rbit_status = true;
11228 else
11229 rbit_status = false;
11230 }
11231
11232 if (rbit_status) {
11233 if (use_json)
11234 json_object_boolean_true_add(json, "rBit");
11235 else
11236 vty_out(vty, "True\n");
11237 } else {
11238 if (use_json)
11239 json_object_boolean_false_add(json, "rBit");
11240 else
11241 vty_out(vty, "False\n");
11242 }
11243 }
11244
11245 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11246 struct peer *peer,
11247 bool use_json,
11248 json_object *json)
11249 {
11250 const char *mode = "NotApplicable";
11251
11252 if (!use_json)
11253 vty_out(vty, "\n Remote GR Mode: ");
11254
11255 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11256 && (peer_established(peer))) {
11257
11258 if ((peer->nsf_af_count == 0)
11259 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11260
11261 mode = "Disable";
11262
11263 } else if (peer->nsf_af_count == 0
11264 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11265
11266 mode = "Helper";
11267
11268 } else if (peer->nsf_af_count != 0
11269 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11270
11271 mode = "Restart";
11272 }
11273 }
11274
11275 if (use_json) {
11276 json_object_string_add(json, "remoteGrMode", mode);
11277 } else
11278 vty_out(vty, mode, "\n");
11279 }
11280
11281 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11282 struct peer *p,
11283 bool use_json,
11284 json_object *json)
11285 {
11286 const char *mode = "Invalid";
11287
11288 if (!use_json)
11289 vty_out(vty, " Local GR Mode: ");
11290
11291 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11292 mode = "Helper";
11293 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11294 mode = "Restart";
11295 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11296 mode = "Disable";
11297 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11298 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11299 mode = "Helper*";
11300 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11301 mode = "Restart*";
11302 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11303 mode = "Disable*";
11304 else
11305 mode = "Invalid*";
11306 }
11307
11308 if (use_json) {
11309 json_object_string_add(json, "localGrMode", mode);
11310 } else {
11311 vty_out(vty, mode, "\n");
11312 }
11313 }
11314
11315 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11316 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11317 {
11318 afi_t afi;
11319 safi_t safi;
11320 json_object *json_afi_safi = NULL;
11321 json_object *json_timer = NULL;
11322 json_object *json_endofrib_status = NULL;
11323 bool eor_flag = false;
11324
11325 FOREACH_AFI_SAFI_NSF (afi, safi) {
11326 if (!peer->afc[afi][safi])
11327 continue;
11328
11329 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11330 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11331 continue;
11332
11333 if (use_json) {
11334 json_afi_safi = json_object_new_object();
11335 json_endofrib_status = json_object_new_object();
11336 json_timer = json_object_new_object();
11337 }
11338
11339 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11340 eor_flag = true;
11341 else
11342 eor_flag = false;
11343
11344 if (!use_json) {
11345 vty_out(vty, " %s:\n",
11346 get_afi_safi_str(afi, safi, false));
11347
11348 vty_out(vty, " F bit: ");
11349 }
11350
11351 if (peer->nsf[afi][safi] &&
11352 CHECK_FLAG(peer->af_cap[afi][safi],
11353 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11354
11355 if (use_json) {
11356 json_object_boolean_true_add(json_afi_safi,
11357 "fBit");
11358 } else
11359 vty_out(vty, "True\n");
11360 } else {
11361 if (use_json)
11362 json_object_boolean_false_add(json_afi_safi,
11363 "fBit");
11364 else
11365 vty_out(vty, "False\n");
11366 }
11367
11368 if (!use_json)
11369 vty_out(vty, " End-of-RIB sent: ");
11370
11371 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11372 PEER_STATUS_EOR_SEND)) {
11373 if (use_json) {
11374 json_object_boolean_true_add(
11375 json_endofrib_status, "endOfRibSend");
11376
11377 PRINT_EOR_JSON(eor_flag);
11378 } else {
11379 vty_out(vty, "Yes\n");
11380 vty_out(vty,
11381 " End-of-RIB sent after update: ");
11382
11383 PRINT_EOR(eor_flag);
11384 }
11385 } else {
11386 if (use_json) {
11387 json_object_boolean_false_add(
11388 json_endofrib_status, "endOfRibSend");
11389 json_object_boolean_false_add(
11390 json_endofrib_status,
11391 "endOfRibSentAfterUpdate");
11392 } else {
11393 vty_out(vty, "No\n");
11394 vty_out(vty,
11395 " End-of-RIB sent after update: ");
11396 vty_out(vty, "No\n");
11397 }
11398 }
11399
11400 if (!use_json)
11401 vty_out(vty, " End-of-RIB received: ");
11402
11403 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11404 PEER_STATUS_EOR_RECEIVED)) {
11405 if (use_json)
11406 json_object_boolean_true_add(
11407 json_endofrib_status, "endOfRibRecv");
11408 else
11409 vty_out(vty, "Yes\n");
11410 } else {
11411 if (use_json)
11412 json_object_boolean_false_add(
11413 json_endofrib_status, "endOfRibRecv");
11414 else
11415 vty_out(vty, "No\n");
11416 }
11417
11418 if (use_json) {
11419 json_object_int_add(json_timer, "stalePathTimer",
11420 peer->bgp->stalepath_time);
11421
11422 if (peer->t_gr_stale != NULL) {
11423 json_object_int_add(json_timer,
11424 "stalePathTimerRemaining",
11425 thread_timer_remain_second(
11426 peer->t_gr_stale));
11427 }
11428
11429 /* Display Configured Selection
11430 * Deferral only when when
11431 * Gr mode is enabled.
11432 */
11433 if (CHECK_FLAG(peer->flags,
11434 PEER_FLAG_GRACEFUL_RESTART)) {
11435 json_object_int_add(json_timer,
11436 "selectionDeferralTimer",
11437 peer->bgp->stalepath_time);
11438 }
11439
11440 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11441 NULL) {
11442
11443 json_object_int_add(
11444 json_timer,
11445 "selectionDeferralTimerRemaining",
11446 thread_timer_remain_second(
11447 peer->bgp->gr_info[afi][safi]
11448 .t_select_deferral));
11449 }
11450 } else {
11451 vty_out(vty, " Timers:\n");
11452 vty_out(vty,
11453 " Configured Stale Path Time(sec): %u\n",
11454 peer->bgp->stalepath_time);
11455
11456 if (peer->t_gr_stale != NULL)
11457 vty_out(vty,
11458 " Stale Path Remaining(sec): %ld\n",
11459 thread_timer_remain_second(
11460 peer->t_gr_stale));
11461 /* Display Configured Selection
11462 * Deferral only when when
11463 * Gr mode is enabled.
11464 */
11465 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11466 vty_out(vty,
11467 " Configured Selection Deferral Time(sec): %u\n",
11468 peer->bgp->select_defer_time);
11469
11470 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11471 NULL)
11472 vty_out(vty,
11473 " Selection Deferral Time Remaining(sec): %ld\n",
11474 thread_timer_remain_second(
11475 peer->bgp->gr_info[afi][safi]
11476 .t_select_deferral));
11477 }
11478 if (use_json) {
11479 json_object_object_add(json_afi_safi, "endOfRibStatus",
11480 json_endofrib_status);
11481 json_object_object_add(json_afi_safi, "timers",
11482 json_timer);
11483 json_object_object_add(
11484 json, get_afi_safi_str(afi, safi, true),
11485 json_afi_safi);
11486 }
11487 }
11488 }
11489
11490 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11491 struct peer *p,
11492 bool use_json,
11493 json_object *json)
11494 {
11495 if (use_json) {
11496 json_object *json_timer = NULL;
11497
11498 json_timer = json_object_new_object();
11499
11500 json_object_int_add(json_timer, "configuredRestartTimer",
11501 p->bgp->restart_time);
11502
11503 json_object_int_add(json_timer, "receivedRestartTimer",
11504 p->v_gr_restart);
11505
11506 if (p->t_gr_restart != NULL)
11507 json_object_int_add(
11508 json_timer, "restartTimerRemaining",
11509 thread_timer_remain_second(p->t_gr_restart));
11510
11511 json_object_object_add(json, "timers", json_timer);
11512 } else {
11513
11514 vty_out(vty, " Timers:\n");
11515 vty_out(vty, " Configured Restart Time(sec): %u\n",
11516 p->bgp->restart_time);
11517
11518 vty_out(vty, " Received Restart Time(sec): %u\n",
11519 p->v_gr_restart);
11520 if (p->t_gr_restart != NULL)
11521 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11522 thread_timer_remain_second(p->t_gr_restart));
11523 if (p->t_gr_restart != NULL) {
11524 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11525 thread_timer_remain_second(p->t_gr_restart));
11526 }
11527 }
11528 }
11529
11530 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11531 bool use_json, json_object *json)
11532 {
11533 char buf[SU_ADDRSTRLEN] = {0};
11534 char dn_flag[2] = {0};
11535 /* '*' + v6 address of neighbor */
11536 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11537
11538 if (!p->conf_if && peer_dynamic_neighbor(p))
11539 dn_flag[0] = '*';
11540
11541 if (p->conf_if) {
11542 if (use_json)
11543 json_object_string_add(
11544 json, "neighborAddr",
11545 BGP_PEER_SU_UNSPEC(p)
11546 ? "none"
11547 : sockunion2str(&p->su, buf,
11548 SU_ADDRSTRLEN));
11549 else
11550 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11551 BGP_PEER_SU_UNSPEC(p)
11552 ? "none"
11553 : sockunion2str(&p->su, buf,
11554 SU_ADDRSTRLEN));
11555 } else {
11556 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11557 p->host);
11558
11559 if (use_json)
11560 json_object_string_add(json, "neighborAddr",
11561 neighborAddr);
11562 else
11563 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11564 }
11565
11566 /* more gr info in new format */
11567 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11568 }
11569
11570 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11571 safi_t safi, bool use_json,
11572 json_object *json_neigh)
11573 {
11574 struct bgp_filter *filter;
11575 struct peer_af *paf;
11576 char orf_pfx_name[BUFSIZ];
11577 int orf_pfx_count;
11578 json_object *json_af = NULL;
11579 json_object *json_prefA = NULL;
11580 json_object *json_prefB = NULL;
11581 json_object *json_addr = NULL;
11582 json_object *json_advmap = NULL;
11583
11584 if (use_json) {
11585 json_addr = json_object_new_object();
11586 json_af = json_object_new_object();
11587 filter = &p->filter[afi][safi];
11588
11589 if (peer_group_active(p))
11590 json_object_string_add(json_addr, "peerGroupMember",
11591 p->group->name);
11592
11593 paf = peer_af_find(p, afi, safi);
11594 if (paf && PAF_SUBGRP(paf)) {
11595 json_object_int_add(json_addr, "updateGroupId",
11596 PAF_UPDGRP(paf)->id);
11597 json_object_int_add(json_addr, "subGroupId",
11598 PAF_SUBGRP(paf)->id);
11599 json_object_int_add(json_addr, "packetQueueLength",
11600 bpacket_queue_virtual_length(paf));
11601 }
11602
11603 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11604 || CHECK_FLAG(p->af_cap[afi][safi],
11605 PEER_CAP_ORF_PREFIX_SM_RCV)
11606 || CHECK_FLAG(p->af_cap[afi][safi],
11607 PEER_CAP_ORF_PREFIX_RM_ADV)
11608 || CHECK_FLAG(p->af_cap[afi][safi],
11609 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11610 json_object_int_add(json_af, "orfType",
11611 ORF_TYPE_PREFIX);
11612 json_prefA = json_object_new_object();
11613 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11614 PEER_CAP_ORF_PREFIX_SM_ADV,
11615 PEER_CAP_ORF_PREFIX_RM_ADV,
11616 PEER_CAP_ORF_PREFIX_SM_RCV,
11617 PEER_CAP_ORF_PREFIX_RM_RCV,
11618 use_json, json_prefA);
11619 json_object_object_add(json_af, "orfPrefixList",
11620 json_prefA);
11621 }
11622
11623 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11624 || CHECK_FLAG(p->af_cap[afi][safi],
11625 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11626 || CHECK_FLAG(p->af_cap[afi][safi],
11627 PEER_CAP_ORF_PREFIX_RM_ADV)
11628 || CHECK_FLAG(p->af_cap[afi][safi],
11629 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11630 json_object_int_add(json_af, "orfOldType",
11631 ORF_TYPE_PREFIX_OLD);
11632 json_prefB = json_object_new_object();
11633 bgp_show_peer_afi_orf_cap(
11634 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11635 PEER_CAP_ORF_PREFIX_RM_ADV,
11636 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11637 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11638 json_prefB);
11639 json_object_object_add(json_af, "orfOldPrefixList",
11640 json_prefB);
11641 }
11642
11643 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11644 || CHECK_FLAG(p->af_cap[afi][safi],
11645 PEER_CAP_ORF_PREFIX_SM_RCV)
11646 || CHECK_FLAG(p->af_cap[afi][safi],
11647 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11648 || CHECK_FLAG(p->af_cap[afi][safi],
11649 PEER_CAP_ORF_PREFIX_RM_ADV)
11650 || CHECK_FLAG(p->af_cap[afi][safi],
11651 PEER_CAP_ORF_PREFIX_RM_RCV)
11652 || CHECK_FLAG(p->af_cap[afi][safi],
11653 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11654 json_object_object_add(json_addr, "afDependentCap",
11655 json_af);
11656 else
11657 json_object_free(json_af);
11658
11659 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11660 p->host, afi, safi);
11661 orf_pfx_count = prefix_bgp_show_prefix_list(
11662 NULL, afi, orf_pfx_name, use_json);
11663
11664 if (CHECK_FLAG(p->af_sflags[afi][safi],
11665 PEER_STATUS_ORF_PREFIX_SEND)
11666 || orf_pfx_count) {
11667 if (CHECK_FLAG(p->af_sflags[afi][safi],
11668 PEER_STATUS_ORF_PREFIX_SEND))
11669 json_object_boolean_true_add(json_neigh,
11670 "orfSent");
11671 if (orf_pfx_count)
11672 json_object_int_add(json_addr, "orfRecvCounter",
11673 orf_pfx_count);
11674 }
11675 if (CHECK_FLAG(p->af_sflags[afi][safi],
11676 PEER_STATUS_ORF_WAIT_REFRESH))
11677 json_object_string_add(
11678 json_addr, "orfFirstUpdate",
11679 "deferredUntilORFOrRouteRefreshRecvd");
11680
11681 if (CHECK_FLAG(p->af_flags[afi][safi],
11682 PEER_FLAG_REFLECTOR_CLIENT))
11683 json_object_boolean_true_add(json_addr,
11684 "routeReflectorClient");
11685 if (CHECK_FLAG(p->af_flags[afi][safi],
11686 PEER_FLAG_RSERVER_CLIENT))
11687 json_object_boolean_true_add(json_addr,
11688 "routeServerClient");
11689 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11690 json_object_boolean_true_add(json_addr,
11691 "inboundSoftConfigPermit");
11692
11693 if (CHECK_FLAG(p->af_flags[afi][safi],
11694 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11695 json_object_boolean_true_add(
11696 json_addr,
11697 "privateAsNumsAllReplacedInUpdatesToNbr");
11698 else if (CHECK_FLAG(p->af_flags[afi][safi],
11699 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11700 json_object_boolean_true_add(
11701 json_addr,
11702 "privateAsNumsReplacedInUpdatesToNbr");
11703 else if (CHECK_FLAG(p->af_flags[afi][safi],
11704 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11705 json_object_boolean_true_add(
11706 json_addr,
11707 "privateAsNumsAllRemovedInUpdatesToNbr");
11708 else if (CHECK_FLAG(p->af_flags[afi][safi],
11709 PEER_FLAG_REMOVE_PRIVATE_AS))
11710 json_object_boolean_true_add(
11711 json_addr,
11712 "privateAsNumsRemovedInUpdatesToNbr");
11713
11714 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11715 json_object_boolean_true_add(
11716 json_addr,
11717 bgp_addpath_names(p->addpath_type[afi][safi])
11718 ->type_json_name);
11719
11720 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11721 json_object_string_add(json_addr,
11722 "overrideASNsInOutboundUpdates",
11723 "ifAspathEqualRemoteAs");
11724
11725 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11726 || CHECK_FLAG(p->af_flags[afi][safi],
11727 PEER_FLAG_FORCE_NEXTHOP_SELF))
11728 json_object_boolean_true_add(json_addr,
11729 "routerAlwaysNextHop");
11730 if (CHECK_FLAG(p->af_flags[afi][safi],
11731 PEER_FLAG_AS_PATH_UNCHANGED))
11732 json_object_boolean_true_add(
11733 json_addr, "unchangedAsPathPropogatedToNbr");
11734 if (CHECK_FLAG(p->af_flags[afi][safi],
11735 PEER_FLAG_NEXTHOP_UNCHANGED))
11736 json_object_boolean_true_add(
11737 json_addr, "unchangedNextHopPropogatedToNbr");
11738 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11739 json_object_boolean_true_add(
11740 json_addr, "unchangedMedPropogatedToNbr");
11741 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11742 || CHECK_FLAG(p->af_flags[afi][safi],
11743 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11744 if (CHECK_FLAG(p->af_flags[afi][safi],
11745 PEER_FLAG_SEND_COMMUNITY)
11746 && CHECK_FLAG(p->af_flags[afi][safi],
11747 PEER_FLAG_SEND_EXT_COMMUNITY))
11748 json_object_string_add(json_addr,
11749 "commAttriSentToNbr",
11750 "extendedAndStandard");
11751 else if (CHECK_FLAG(p->af_flags[afi][safi],
11752 PEER_FLAG_SEND_EXT_COMMUNITY))
11753 json_object_string_add(json_addr,
11754 "commAttriSentToNbr",
11755 "extended");
11756 else
11757 json_object_string_add(json_addr,
11758 "commAttriSentToNbr",
11759 "standard");
11760 }
11761 if (CHECK_FLAG(p->af_flags[afi][safi],
11762 PEER_FLAG_DEFAULT_ORIGINATE)) {
11763 if (p->default_rmap[afi][safi].name)
11764 json_object_string_add(
11765 json_addr, "defaultRouteMap",
11766 p->default_rmap[afi][safi].name);
11767
11768 if (paf && PAF_SUBGRP(paf)
11769 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11770 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11771 json_object_boolean_true_add(json_addr,
11772 "defaultSent");
11773 else
11774 json_object_boolean_true_add(json_addr,
11775 "defaultNotSent");
11776 }
11777
11778 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11779 if (is_evpn_enabled())
11780 json_object_boolean_true_add(
11781 json_addr, "advertiseAllVnis");
11782 }
11783
11784 if (filter->plist[FILTER_IN].name
11785 || filter->dlist[FILTER_IN].name
11786 || filter->aslist[FILTER_IN].name
11787 || filter->map[RMAP_IN].name)
11788 json_object_boolean_true_add(json_addr,
11789 "inboundPathPolicyConfig");
11790 if (filter->plist[FILTER_OUT].name
11791 || filter->dlist[FILTER_OUT].name
11792 || filter->aslist[FILTER_OUT].name
11793 || filter->map[RMAP_OUT].name || filter->usmap.name)
11794 json_object_boolean_true_add(
11795 json_addr, "outboundPathPolicyConfig");
11796
11797 /* prefix-list */
11798 if (filter->plist[FILTER_IN].name)
11799 json_object_string_add(json_addr,
11800 "incomingUpdatePrefixFilterList",
11801 filter->plist[FILTER_IN].name);
11802 if (filter->plist[FILTER_OUT].name)
11803 json_object_string_add(json_addr,
11804 "outgoingUpdatePrefixFilterList",
11805 filter->plist[FILTER_OUT].name);
11806
11807 /* distribute-list */
11808 if (filter->dlist[FILTER_IN].name)
11809 json_object_string_add(
11810 json_addr, "incomingUpdateNetworkFilterList",
11811 filter->dlist[FILTER_IN].name);
11812 if (filter->dlist[FILTER_OUT].name)
11813 json_object_string_add(
11814 json_addr, "outgoingUpdateNetworkFilterList",
11815 filter->dlist[FILTER_OUT].name);
11816
11817 /* filter-list. */
11818 if (filter->aslist[FILTER_IN].name)
11819 json_object_string_add(json_addr,
11820 "incomingUpdateAsPathFilterList",
11821 filter->aslist[FILTER_IN].name);
11822 if (filter->aslist[FILTER_OUT].name)
11823 json_object_string_add(json_addr,
11824 "outgoingUpdateAsPathFilterList",
11825 filter->aslist[FILTER_OUT].name);
11826
11827 /* route-map. */
11828 if (filter->map[RMAP_IN].name)
11829 json_object_string_add(
11830 json_addr, "routeMapForIncomingAdvertisements",
11831 filter->map[RMAP_IN].name);
11832 if (filter->map[RMAP_OUT].name)
11833 json_object_string_add(
11834 json_addr, "routeMapForOutgoingAdvertisements",
11835 filter->map[RMAP_OUT].name);
11836
11837 /* ebgp-requires-policy (inbound) */
11838 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11839 && !bgp_inbound_policy_exists(p, filter))
11840 json_object_string_add(
11841 json_addr, "inboundEbgpRequiresPolicy",
11842 "Inbound updates discarded due to missing policy");
11843
11844 /* ebgp-requires-policy (outbound) */
11845 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11846 && (!bgp_outbound_policy_exists(p, filter)))
11847 json_object_string_add(
11848 json_addr, "outboundEbgpRequiresPolicy",
11849 "Outbound updates discarded due to missing policy");
11850
11851 /* unsuppress-map */
11852 if (filter->usmap.name)
11853 json_object_string_add(json_addr,
11854 "selectiveUnsuppressRouteMap",
11855 filter->usmap.name);
11856
11857 /* advertise-map */
11858 if (filter->advmap.aname) {
11859 json_advmap = json_object_new_object();
11860 json_object_string_add(json_advmap, "condition",
11861 filter->advmap.condition
11862 ? "EXIST"
11863 : "NON_EXIST");
11864 json_object_string_add(json_advmap, "conditionMap",
11865 filter->advmap.cname);
11866 json_object_string_add(json_advmap, "advertiseMap",
11867 filter->advmap.aname);
11868 json_object_string_add(json_advmap, "advertiseStatus",
11869 filter->advmap.update_type
11870 == ADVERTISE
11871 ? "Advertise"
11872 : "Withdraw");
11873 json_object_object_add(json_addr, "advertiseMap",
11874 json_advmap);
11875 }
11876
11877 /* Receive prefix count */
11878 json_object_int_add(json_addr, "acceptedPrefixCounter",
11879 p->pcount[afi][safi]);
11880 if (paf && PAF_SUBGRP(paf))
11881 json_object_int_add(json_addr, "sentPrefixCounter",
11882 (PAF_SUBGRP(paf))->scount);
11883
11884 /* Maximum prefix */
11885 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11886 json_object_int_add(json_addr, "prefixOutAllowedMax",
11887 p->pmax_out[afi][safi]);
11888
11889 /* Maximum prefix */
11890 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11891 json_object_int_add(json_addr, "prefixAllowedMax",
11892 p->pmax[afi][safi]);
11893 if (CHECK_FLAG(p->af_flags[afi][safi],
11894 PEER_FLAG_MAX_PREFIX_WARNING))
11895 json_object_boolean_true_add(
11896 json_addr, "prefixAllowedMaxWarning");
11897 json_object_int_add(json_addr,
11898 "prefixAllowedWarningThresh",
11899 p->pmax_threshold[afi][safi]);
11900 if (p->pmax_restart[afi][safi])
11901 json_object_int_add(
11902 json_addr,
11903 "prefixAllowedRestartIntervalMsecs",
11904 p->pmax_restart[afi][safi] * 60000);
11905 }
11906 json_object_object_add(json_neigh,
11907 get_afi_safi_str(afi, safi, true),
11908 json_addr);
11909
11910 } else {
11911 filter = &p->filter[afi][safi];
11912
11913 vty_out(vty, " For address family: %s\n",
11914 get_afi_safi_str(afi, safi, false));
11915
11916 if (peer_group_active(p))
11917 vty_out(vty, " %s peer-group member\n",
11918 p->group->name);
11919
11920 paf = peer_af_find(p, afi, safi);
11921 if (paf && PAF_SUBGRP(paf)) {
11922 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
11923 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11924 vty_out(vty, " Packet Queue length %d\n",
11925 bpacket_queue_virtual_length(paf));
11926 } else {
11927 vty_out(vty, " Not part of any update group\n");
11928 }
11929 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11930 || CHECK_FLAG(p->af_cap[afi][safi],
11931 PEER_CAP_ORF_PREFIX_SM_RCV)
11932 || CHECK_FLAG(p->af_cap[afi][safi],
11933 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11934 || CHECK_FLAG(p->af_cap[afi][safi],
11935 PEER_CAP_ORF_PREFIX_RM_ADV)
11936 || CHECK_FLAG(p->af_cap[afi][safi],
11937 PEER_CAP_ORF_PREFIX_RM_RCV)
11938 || CHECK_FLAG(p->af_cap[afi][safi],
11939 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11940 vty_out(vty, " AF-dependant capabilities:\n");
11941
11942 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11943 || CHECK_FLAG(p->af_cap[afi][safi],
11944 PEER_CAP_ORF_PREFIX_SM_RCV)
11945 || CHECK_FLAG(p->af_cap[afi][safi],
11946 PEER_CAP_ORF_PREFIX_RM_ADV)
11947 || CHECK_FLAG(p->af_cap[afi][safi],
11948 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11949 vty_out(vty,
11950 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11951 ORF_TYPE_PREFIX);
11952 bgp_show_peer_afi_orf_cap(
11953 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11954 PEER_CAP_ORF_PREFIX_RM_ADV,
11955 PEER_CAP_ORF_PREFIX_SM_RCV,
11956 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11957 }
11958 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11959 || CHECK_FLAG(p->af_cap[afi][safi],
11960 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11961 || CHECK_FLAG(p->af_cap[afi][safi],
11962 PEER_CAP_ORF_PREFIX_RM_ADV)
11963 || CHECK_FLAG(p->af_cap[afi][safi],
11964 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11965 vty_out(vty,
11966 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11967 ORF_TYPE_PREFIX_OLD);
11968 bgp_show_peer_afi_orf_cap(
11969 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11970 PEER_CAP_ORF_PREFIX_RM_ADV,
11971 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11972 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11973 }
11974
11975 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11976 p->host, afi, safi);
11977 orf_pfx_count = prefix_bgp_show_prefix_list(
11978 NULL, afi, orf_pfx_name, use_json);
11979
11980 if (CHECK_FLAG(p->af_sflags[afi][safi],
11981 PEER_STATUS_ORF_PREFIX_SEND)
11982 || orf_pfx_count) {
11983 vty_out(vty, " Outbound Route Filter (ORF):");
11984 if (CHECK_FLAG(p->af_sflags[afi][safi],
11985 PEER_STATUS_ORF_PREFIX_SEND))
11986 vty_out(vty, " sent;");
11987 if (orf_pfx_count)
11988 vty_out(vty, " received (%d entries)",
11989 orf_pfx_count);
11990 vty_out(vty, "\n");
11991 }
11992 if (CHECK_FLAG(p->af_sflags[afi][safi],
11993 PEER_STATUS_ORF_WAIT_REFRESH))
11994 vty_out(vty,
11995 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11996
11997 if (CHECK_FLAG(p->af_flags[afi][safi],
11998 PEER_FLAG_REFLECTOR_CLIENT))
11999 vty_out(vty, " Route-Reflector Client\n");
12000 if (CHECK_FLAG(p->af_flags[afi][safi],
12001 PEER_FLAG_RSERVER_CLIENT))
12002 vty_out(vty, " Route-Server Client\n");
12003 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12004 vty_out(vty,
12005 " Inbound soft reconfiguration allowed\n");
12006
12007 if (CHECK_FLAG(p->af_flags[afi][safi],
12008 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12009 vty_out(vty,
12010 " Private AS numbers (all) replaced in updates to this neighbor\n");
12011 else if (CHECK_FLAG(p->af_flags[afi][safi],
12012 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12013 vty_out(vty,
12014 " Private AS numbers replaced in updates to this neighbor\n");
12015 else if (CHECK_FLAG(p->af_flags[afi][safi],
12016 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12017 vty_out(vty,
12018 " Private AS numbers (all) removed in updates to this neighbor\n");
12019 else if (CHECK_FLAG(p->af_flags[afi][safi],
12020 PEER_FLAG_REMOVE_PRIVATE_AS))
12021 vty_out(vty,
12022 " Private AS numbers removed in updates to this neighbor\n");
12023
12024 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12025 vty_out(vty, " %s\n",
12026 bgp_addpath_names(p->addpath_type[afi][safi])
12027 ->human_description);
12028
12029 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12030 vty_out(vty,
12031 " Override ASNs in outbound updates if aspath equals remote-as\n");
12032
12033 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12034 || CHECK_FLAG(p->af_flags[afi][safi],
12035 PEER_FLAG_FORCE_NEXTHOP_SELF))
12036 vty_out(vty, " NEXT_HOP is always this router\n");
12037 if (CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_AS_PATH_UNCHANGED))
12039 vty_out(vty,
12040 " AS_PATH is propagated unchanged to this neighbor\n");
12041 if (CHECK_FLAG(p->af_flags[afi][safi],
12042 PEER_FLAG_NEXTHOP_UNCHANGED))
12043 vty_out(vty,
12044 " NEXT_HOP is propagated unchanged to this neighbor\n");
12045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12046 vty_out(vty,
12047 " MED is propagated unchanged to this neighbor\n");
12048 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12049 || CHECK_FLAG(p->af_flags[afi][safi],
12050 PEER_FLAG_SEND_EXT_COMMUNITY)
12051 || CHECK_FLAG(p->af_flags[afi][safi],
12052 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12053 vty_out(vty,
12054 " Community attribute sent to this neighbor");
12055 if (CHECK_FLAG(p->af_flags[afi][safi],
12056 PEER_FLAG_SEND_COMMUNITY)
12057 && CHECK_FLAG(p->af_flags[afi][safi],
12058 PEER_FLAG_SEND_EXT_COMMUNITY)
12059 && CHECK_FLAG(p->af_flags[afi][safi],
12060 PEER_FLAG_SEND_LARGE_COMMUNITY))
12061 vty_out(vty, "(all)\n");
12062 else if (CHECK_FLAG(p->af_flags[afi][safi],
12063 PEER_FLAG_SEND_LARGE_COMMUNITY))
12064 vty_out(vty, "(large)\n");
12065 else if (CHECK_FLAG(p->af_flags[afi][safi],
12066 PEER_FLAG_SEND_EXT_COMMUNITY))
12067 vty_out(vty, "(extended)\n");
12068 else
12069 vty_out(vty, "(standard)\n");
12070 }
12071 if (CHECK_FLAG(p->af_flags[afi][safi],
12072 PEER_FLAG_DEFAULT_ORIGINATE)) {
12073 vty_out(vty, " Default information originate,");
12074
12075 if (p->default_rmap[afi][safi].name)
12076 vty_out(vty, " default route-map %s%s,",
12077 p->default_rmap[afi][safi].map ? "*"
12078 : "",
12079 p->default_rmap[afi][safi].name);
12080 if (paf && PAF_SUBGRP(paf)
12081 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12082 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12083 vty_out(vty, " default sent\n");
12084 else
12085 vty_out(vty, " default not sent\n");
12086 }
12087
12088 /* advertise-vni-all */
12089 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12090 if (is_evpn_enabled())
12091 vty_out(vty, " advertise-all-vni\n");
12092 }
12093
12094 if (filter->plist[FILTER_IN].name
12095 || filter->dlist[FILTER_IN].name
12096 || filter->aslist[FILTER_IN].name
12097 || filter->map[RMAP_IN].name)
12098 vty_out(vty, " Inbound path policy configured\n");
12099 if (filter->plist[FILTER_OUT].name
12100 || filter->dlist[FILTER_OUT].name
12101 || filter->aslist[FILTER_OUT].name
12102 || filter->map[RMAP_OUT].name || filter->usmap.name)
12103 vty_out(vty, " Outbound path policy configured\n");
12104
12105 /* prefix-list */
12106 if (filter->plist[FILTER_IN].name)
12107 vty_out(vty,
12108 " Incoming update prefix filter list is %s%s\n",
12109 filter->plist[FILTER_IN].plist ? "*" : "",
12110 filter->plist[FILTER_IN].name);
12111 if (filter->plist[FILTER_OUT].name)
12112 vty_out(vty,
12113 " Outgoing update prefix filter list is %s%s\n",
12114 filter->plist[FILTER_OUT].plist ? "*" : "",
12115 filter->plist[FILTER_OUT].name);
12116
12117 /* distribute-list */
12118 if (filter->dlist[FILTER_IN].name)
12119 vty_out(vty,
12120 " Incoming update network filter list is %s%s\n",
12121 filter->dlist[FILTER_IN].alist ? "*" : "",
12122 filter->dlist[FILTER_IN].name);
12123 if (filter->dlist[FILTER_OUT].name)
12124 vty_out(vty,
12125 " Outgoing update network filter list is %s%s\n",
12126 filter->dlist[FILTER_OUT].alist ? "*" : "",
12127 filter->dlist[FILTER_OUT].name);
12128
12129 /* filter-list. */
12130 if (filter->aslist[FILTER_IN].name)
12131 vty_out(vty,
12132 " Incoming update AS path filter list is %s%s\n",
12133 filter->aslist[FILTER_IN].aslist ? "*" : "",
12134 filter->aslist[FILTER_IN].name);
12135 if (filter->aslist[FILTER_OUT].name)
12136 vty_out(vty,
12137 " Outgoing update AS path filter list is %s%s\n",
12138 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12139 filter->aslist[FILTER_OUT].name);
12140
12141 /* route-map. */
12142 if (filter->map[RMAP_IN].name)
12143 vty_out(vty,
12144 " Route map for incoming advertisements is %s%s\n",
12145 filter->map[RMAP_IN].map ? "*" : "",
12146 filter->map[RMAP_IN].name);
12147 if (filter->map[RMAP_OUT].name)
12148 vty_out(vty,
12149 " Route map for outgoing advertisements is %s%s\n",
12150 filter->map[RMAP_OUT].map ? "*" : "",
12151 filter->map[RMAP_OUT].name);
12152
12153 /* ebgp-requires-policy (inbound) */
12154 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12155 && !bgp_inbound_policy_exists(p, filter))
12156 vty_out(vty,
12157 " Inbound updates discarded due to missing policy\n");
12158
12159 /* ebgp-requires-policy (outbound) */
12160 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12161 && !bgp_outbound_policy_exists(p, filter))
12162 vty_out(vty,
12163 " Outbound updates discarded due to missing policy\n");
12164
12165 /* unsuppress-map */
12166 if (filter->usmap.name)
12167 vty_out(vty,
12168 " Route map for selective unsuppress is %s%s\n",
12169 filter->usmap.map ? "*" : "",
12170 filter->usmap.name);
12171
12172 /* advertise-map */
12173 if (filter->advmap.aname && filter->advmap.cname)
12174 vty_out(vty,
12175 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12176 filter->advmap.condition ? "EXIST"
12177 : "NON_EXIST",
12178 filter->advmap.cmap ? "*" : "",
12179 filter->advmap.cname,
12180 filter->advmap.amap ? "*" : "",
12181 filter->advmap.aname,
12182 filter->advmap.update_type == ADVERTISE
12183 ? "Advertise"
12184 : "Withdraw");
12185
12186 /* Receive prefix count */
12187 vty_out(vty, " %u accepted prefixes\n",
12188 p->pcount[afi][safi]);
12189
12190 /* maximum-prefix-out */
12191 if (CHECK_FLAG(p->af_flags[afi][safi],
12192 PEER_FLAG_MAX_PREFIX_OUT))
12193 vty_out(vty,
12194 " Maximum allowed prefixes sent %u\n",
12195 p->pmax_out[afi][safi]);
12196
12197 /* Maximum prefix */
12198 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12199 vty_out(vty,
12200 " Maximum prefixes allowed %u%s\n",
12201 p->pmax[afi][safi],
12202 CHECK_FLAG(p->af_flags[afi][safi],
12203 PEER_FLAG_MAX_PREFIX_WARNING)
12204 ? " (warning-only)"
12205 : "");
12206 vty_out(vty, " Threshold for warning message %d%%",
12207 p->pmax_threshold[afi][safi]);
12208 if (p->pmax_restart[afi][safi])
12209 vty_out(vty, ", restart interval %d min",
12210 p->pmax_restart[afi][safi]);
12211 vty_out(vty, "\n");
12212 }
12213
12214 vty_out(vty, "\n");
12215 }
12216 }
12217
12218 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12219 json_object *json)
12220 {
12221 struct bgp *bgp;
12222 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12223 char timebuf[BGP_UPTIME_LEN];
12224 char dn_flag[2];
12225 afi_t afi;
12226 safi_t safi;
12227 uint16_t i;
12228 uint8_t *msg;
12229 json_object *json_neigh = NULL;
12230 time_t epoch_tbuf;
12231 uint32_t sync_tcp_mss;
12232
12233 bgp = p->bgp;
12234
12235 if (use_json)
12236 json_neigh = json_object_new_object();
12237
12238 memset(dn_flag, '\0', sizeof(dn_flag));
12239 if (!p->conf_if && peer_dynamic_neighbor(p))
12240 dn_flag[0] = '*';
12241
12242 if (!use_json) {
12243 if (p->conf_if) /* Configured interface name. */
12244 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12245 BGP_PEER_SU_UNSPEC(p)
12246 ? "None"
12247 : sockunion2str(&p->su, buf,
12248 SU_ADDRSTRLEN));
12249 else /* Configured IP address. */
12250 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12251 p->host);
12252 }
12253
12254 if (use_json) {
12255 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12256 json_object_string_add(json_neigh, "bgpNeighborAddr",
12257 "none");
12258 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12259 json_object_string_add(
12260 json_neigh, "bgpNeighborAddr",
12261 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12262
12263 json_object_int_add(json_neigh, "remoteAs", p->as);
12264
12265 if (p->change_local_as)
12266 json_object_int_add(json_neigh, "localAs",
12267 p->change_local_as);
12268 else
12269 json_object_int_add(json_neigh, "localAs", p->local_as);
12270
12271 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12272 json_object_boolean_true_add(json_neigh,
12273 "localAsNoPrepend");
12274
12275 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12276 json_object_boolean_true_add(json_neigh,
12277 "localAsReplaceAs");
12278 } else {
12279 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12280 || (p->as_type == AS_INTERNAL))
12281 vty_out(vty, "remote AS %u, ", p->as);
12282 else
12283 vty_out(vty, "remote AS Unspecified, ");
12284 vty_out(vty, "local AS %u%s%s, ",
12285 p->change_local_as ? p->change_local_as : p->local_as,
12286 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12287 ? " no-prepend"
12288 : "",
12289 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12290 ? " replace-as"
12291 : "");
12292 }
12293 /* peer type internal or confed-internal */
12294 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12295 if (use_json) {
12296 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12297 json_object_boolean_true_add(
12298 json_neigh, "nbrConfedInternalLink");
12299 else
12300 json_object_boolean_true_add(json_neigh,
12301 "nbrInternalLink");
12302 } else {
12303 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12304 vty_out(vty, "confed-internal link\n");
12305 else
12306 vty_out(vty, "internal link\n");
12307 }
12308 /* peer type external or confed-external */
12309 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12310 if (use_json) {
12311 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12312 json_object_boolean_true_add(
12313 json_neigh, "nbrConfedExternalLink");
12314 else
12315 json_object_boolean_true_add(json_neigh,
12316 "nbrExternalLink");
12317 } else {
12318 if (bgp_confederation_peers_check(bgp, p->as))
12319 vty_out(vty, "confed-external link\n");
12320 else
12321 vty_out(vty, "external link\n");
12322 }
12323 } else {
12324 if (use_json)
12325 json_object_boolean_true_add(json_neigh,
12326 "nbrUnspecifiedLink");
12327 else
12328 vty_out(vty, "unspecified link\n");
12329 }
12330
12331 /* Description. */
12332 if (p->desc) {
12333 if (use_json)
12334 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12335 else
12336 vty_out(vty, " Description: %s\n", p->desc);
12337 }
12338
12339 if (p->hostname) {
12340 if (use_json) {
12341 if (p->hostname)
12342 json_object_string_add(json_neigh, "hostname",
12343 p->hostname);
12344
12345 if (p->domainname)
12346 json_object_string_add(json_neigh, "domainname",
12347 p->domainname);
12348 } else {
12349 if (p->domainname && (p->domainname[0] != '\0'))
12350 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12351 p->domainname);
12352 else
12353 vty_out(vty, "Hostname: %s\n", p->hostname);
12354 }
12355 }
12356
12357 /* Peer-group */
12358 if (p->group) {
12359 if (use_json) {
12360 json_object_string_add(json_neigh, "peerGroup",
12361 p->group->name);
12362
12363 if (dn_flag[0]) {
12364 struct prefix prefix, *range = NULL;
12365
12366 if (sockunion2hostprefix(&(p->su), &prefix))
12367 range = peer_group_lookup_dynamic_neighbor_range(
12368 p->group, &prefix);
12369
12370 if (range) {
12371 json_object_string_addf(
12372 json_neigh,
12373 "peerSubnetRangeGroup", "%pFX",
12374 range);
12375 }
12376 }
12377 } else {
12378 vty_out(vty,
12379 " Member of peer-group %s for session parameters\n",
12380 p->group->name);
12381
12382 if (dn_flag[0]) {
12383 struct prefix prefix, *range = NULL;
12384
12385 if (sockunion2hostprefix(&(p->su), &prefix))
12386 range = peer_group_lookup_dynamic_neighbor_range(
12387 p->group, &prefix);
12388
12389 if (range) {
12390 vty_out(vty,
12391 " Belongs to the subnet range group: %pFX\n",
12392 range);
12393 }
12394 }
12395 }
12396 }
12397
12398 if (use_json) {
12399 /* Administrative shutdown. */
12400 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12401 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12402 json_object_boolean_true_add(json_neigh,
12403 "adminShutDown");
12404
12405 /* BGP Version. */
12406 json_object_int_add(json_neigh, "bgpVersion", 4);
12407 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12408 &p->remote_id);
12409 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12410 &bgp->router_id);
12411
12412 /* Confederation */
12413 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12414 && bgp_confederation_peers_check(bgp, p->as))
12415 json_object_boolean_true_add(json_neigh,
12416 "nbrCommonAdmin");
12417
12418 /* Status. */
12419 json_object_string_add(
12420 json_neigh, "bgpState",
12421 lookup_msg(bgp_status_msg, p->status, NULL));
12422
12423 if (peer_established(p)) {
12424 time_t uptime;
12425
12426 uptime = bgp_clock();
12427 uptime -= p->uptime;
12428 epoch_tbuf = time(NULL) - uptime;
12429
12430 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12431 uptime * 1000);
12432 json_object_string_add(json_neigh, "bgpTimerUpString",
12433 peer_uptime(p->uptime, timebuf,
12434 BGP_UPTIME_LEN, 0,
12435 NULL));
12436 json_object_int_add(json_neigh,
12437 "bgpTimerUpEstablishedEpoch",
12438 epoch_tbuf);
12439 }
12440
12441 else if (p->status == Active) {
12442 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12443 json_object_string_add(json_neigh, "bgpStateIs",
12444 "passive");
12445 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12446 json_object_string_add(json_neigh, "bgpStateIs",
12447 "passiveNSF");
12448 }
12449
12450 /* read timer */
12451 time_t uptime;
12452 struct tm tm;
12453
12454 uptime = bgp_clock();
12455 uptime -= p->readtime;
12456 gmtime_r(&uptime, &tm);
12457
12458 json_object_int_add(json_neigh, "bgpTimerLastRead",
12459 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12460 + (tm.tm_hour * 3600000));
12461
12462 uptime = bgp_clock();
12463 uptime -= p->last_write;
12464 gmtime_r(&uptime, &tm);
12465
12466 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12467 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12468 + (tm.tm_hour * 3600000));
12469
12470 uptime = bgp_clock();
12471 uptime -= p->update_time;
12472 gmtime_r(&uptime, &tm);
12473
12474 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12475 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12476 + (tm.tm_hour * 3600000));
12477
12478 /* Configured timer values. */
12479 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12480 p->v_holdtime * 1000);
12481 json_object_int_add(json_neigh,
12482 "bgpTimerKeepAliveIntervalMsecs",
12483 p->v_keepalive * 1000);
12484 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12485 json_object_int_add(json_neigh,
12486 "bgpTimerDelayOpenTimeMsecs",
12487 p->v_delayopen * 1000);
12488 }
12489
12490 /* Configured and Synced tcp-mss value for peer */
12491 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12492 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12493 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12494 p->tcp_mss);
12495 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12496 sync_tcp_mss);
12497 }
12498
12499 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12500 json_object_int_add(json_neigh,
12501 "bgpTimerConfiguredHoldTimeMsecs",
12502 p->holdtime * 1000);
12503 json_object_int_add(
12504 json_neigh,
12505 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12506 p->keepalive * 1000);
12507 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12508 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12509 json_object_int_add(json_neigh,
12510 "bgpTimerConfiguredHoldTimeMsecs",
12511 bgp->default_holdtime);
12512 json_object_int_add(
12513 json_neigh,
12514 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12515 bgp->default_keepalive);
12516 }
12517
12518 /* Extended Optional Parameters Length for BGP OPEN Message */
12519 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12520 json_object_boolean_true_add(
12521 json_neigh, "extendedOptionalParametersLength");
12522 else
12523 json_object_boolean_false_add(
12524 json_neigh, "extendedOptionalParametersLength");
12525 } else {
12526 /* Administrative shutdown. */
12527 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12528 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12529 vty_out(vty, " Administratively shut down\n");
12530
12531 /* BGP Version. */
12532 vty_out(vty, " BGP version 4");
12533 vty_out(vty, ", remote router ID %s",
12534 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12535 vty_out(vty, ", local router ID %s\n",
12536 inet_ntop(AF_INET, &bgp->router_id, buf1,
12537 sizeof(buf1)));
12538
12539 /* Confederation */
12540 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12541 && bgp_confederation_peers_check(bgp, p->as))
12542 vty_out(vty,
12543 " Neighbor under common administration\n");
12544
12545 /* Status. */
12546 vty_out(vty, " BGP state = %s",
12547 lookup_msg(bgp_status_msg, p->status, NULL));
12548
12549 if (peer_established(p))
12550 vty_out(vty, ", up for %8s",
12551 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12552 0, NULL));
12553
12554 else if (p->status == Active) {
12555 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12556 vty_out(vty, " (passive)");
12557 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12558 vty_out(vty, " (NSF passive)");
12559 }
12560 vty_out(vty, "\n");
12561
12562 /* read timer */
12563 vty_out(vty, " Last read %s",
12564 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12565 NULL));
12566 vty_out(vty, ", Last write %s\n",
12567 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12568 NULL));
12569
12570 /* Configured timer values. */
12571 vty_out(vty,
12572 " Hold time is %d, keepalive interval is %d seconds\n",
12573 p->v_holdtime, p->v_keepalive);
12574 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12575 vty_out(vty, " Configured hold time is %d",
12576 p->holdtime);
12577 vty_out(vty, ", keepalive interval is %d seconds\n",
12578 p->keepalive);
12579 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12580 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12581 vty_out(vty, " Configured hold time is %d",
12582 bgp->default_holdtime);
12583 vty_out(vty, ", keepalive interval is %d seconds\n",
12584 bgp->default_keepalive);
12585 }
12586 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12587 vty_out(vty,
12588 " Configured DelayOpenTime is %d seconds\n",
12589 p->delayopen);
12590
12591 /* Configured and synced tcp-mss value for peer */
12592 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12593 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12594 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12595 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12596 }
12597
12598 /* Extended Optional Parameters Length for BGP OPEN Message */
12599 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12600 vty_out(vty,
12601 " Extended Optional Parameters Length is enabled\n");
12602 }
12603 /* Capability. */
12604 if (peer_established(p) &&
12605 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12606 if (use_json) {
12607 json_object *json_cap = NULL;
12608
12609 json_cap = json_object_new_object();
12610
12611 /* AS4 */
12612 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12613 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12614 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12615 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12616 json_object_string_add(
12617 json_cap, "4byteAs",
12618 "advertisedAndReceived");
12619 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12620 json_object_string_add(json_cap,
12621 "4byteAs",
12622 "advertised");
12623 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12624 json_object_string_add(json_cap,
12625 "4byteAs",
12626 "received");
12627 }
12628
12629 /* Extended Message Support */
12630 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12631 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12632 json_object_string_add(json_cap,
12633 "extendedMessage",
12634 "advertisedAndReceived");
12635 else if (CHECK_FLAG(p->cap,
12636 PEER_CAP_EXTENDED_MESSAGE_ADV))
12637 json_object_string_add(json_cap,
12638 "extendedMessage",
12639 "advertised");
12640 else if (CHECK_FLAG(p->cap,
12641 PEER_CAP_EXTENDED_MESSAGE_RCV))
12642 json_object_string_add(json_cap,
12643 "extendedMessage",
12644 "received");
12645
12646 /* AddPath */
12647 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12648 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12649 json_object *json_add = NULL;
12650 const char *print_store;
12651
12652 json_add = json_object_new_object();
12653
12654 FOREACH_AFI_SAFI (afi, safi) {
12655 json_object *json_sub = NULL;
12656 json_sub = json_object_new_object();
12657 print_store = get_afi_safi_str(
12658 afi, safi, true);
12659
12660 if (CHECK_FLAG(
12661 p->af_cap[afi][safi],
12662 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12663 CHECK_FLAG(
12664 p->af_cap[afi][safi],
12665 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12666 if (CHECK_FLAG(
12667 p->af_cap[afi]
12668 [safi],
12669 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12670 CHECK_FLAG(
12671 p->af_cap[afi]
12672 [safi],
12673 PEER_CAP_ADDPATH_AF_TX_RCV))
12674 json_object_boolean_true_add(
12675 json_sub,
12676 "txAdvertisedAndReceived");
12677 else if (
12678 CHECK_FLAG(
12679 p->af_cap[afi]
12680 [safi],
12681 PEER_CAP_ADDPATH_AF_TX_ADV))
12682 json_object_boolean_true_add(
12683 json_sub,
12684 "txAdvertised");
12685 else if (
12686 CHECK_FLAG(
12687 p->af_cap[afi]
12688 [safi],
12689 PEER_CAP_ADDPATH_AF_TX_RCV))
12690 json_object_boolean_true_add(
12691 json_sub,
12692 "txReceived");
12693 }
12694
12695 if (CHECK_FLAG(
12696 p->af_cap[afi][safi],
12697 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12698 CHECK_FLAG(
12699 p->af_cap[afi][safi],
12700 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12701 if (CHECK_FLAG(
12702 p->af_cap[afi]
12703 [safi],
12704 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12705 CHECK_FLAG(
12706 p->af_cap[afi]
12707 [safi],
12708 PEER_CAP_ADDPATH_AF_RX_RCV))
12709 json_object_boolean_true_add(
12710 json_sub,
12711 "rxAdvertisedAndReceived");
12712 else if (
12713 CHECK_FLAG(
12714 p->af_cap[afi]
12715 [safi],
12716 PEER_CAP_ADDPATH_AF_RX_ADV))
12717 json_object_boolean_true_add(
12718 json_sub,
12719 "rxAdvertised");
12720 else if (
12721 CHECK_FLAG(
12722 p->af_cap[afi]
12723 [safi],
12724 PEER_CAP_ADDPATH_AF_RX_RCV))
12725 json_object_boolean_true_add(
12726 json_sub,
12727 "rxReceived");
12728 }
12729
12730 if (CHECK_FLAG(
12731 p->af_cap[afi][safi],
12732 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12733 CHECK_FLAG(
12734 p->af_cap[afi][safi],
12735 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12736 CHECK_FLAG(
12737 p->af_cap[afi][safi],
12738 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12739 CHECK_FLAG(
12740 p->af_cap[afi][safi],
12741 PEER_CAP_ADDPATH_AF_RX_RCV))
12742 json_object_object_add(
12743 json_add, print_store,
12744 json_sub);
12745 else
12746 json_object_free(json_sub);
12747 }
12748
12749 json_object_object_add(json_cap, "addPath",
12750 json_add);
12751 }
12752
12753 /* Dynamic */
12754 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12755 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12756 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12757 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12758 json_object_string_add(
12759 json_cap, "dynamic",
12760 "advertisedAndReceived");
12761 else if (CHECK_FLAG(p->cap,
12762 PEER_CAP_DYNAMIC_ADV))
12763 json_object_string_add(json_cap,
12764 "dynamic",
12765 "advertised");
12766 else if (CHECK_FLAG(p->cap,
12767 PEER_CAP_DYNAMIC_RCV))
12768 json_object_string_add(json_cap,
12769 "dynamic",
12770 "received");
12771 }
12772
12773 /* Extended nexthop */
12774 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12775 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12776 json_object *json_nxt = NULL;
12777 const char *print_store;
12778
12779
12780 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12781 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12782 json_object_string_add(
12783 json_cap, "extendedNexthop",
12784 "advertisedAndReceived");
12785 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12786 json_object_string_add(
12787 json_cap, "extendedNexthop",
12788 "advertised");
12789 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12790 json_object_string_add(
12791 json_cap, "extendedNexthop",
12792 "received");
12793
12794 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12795 json_nxt = json_object_new_object();
12796
12797 for (safi = SAFI_UNICAST;
12798 safi < SAFI_MAX; safi++) {
12799 if (CHECK_FLAG(
12800 p->af_cap[AFI_IP]
12801 [safi],
12802 PEER_CAP_ENHE_AF_RCV)) {
12803 print_store =
12804 get_afi_safi_str(
12805 AFI_IP,
12806 safi,
12807 true);
12808 json_object_string_add(
12809 json_nxt,
12810 print_store,
12811 "recieved"); /* misspelled for compatibility */
12812 }
12813 }
12814 json_object_object_add(
12815 json_cap,
12816 "extendedNexthopFamililesByPeer",
12817 json_nxt);
12818 }
12819 }
12820
12821 /* Long-lived Graceful Restart */
12822 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12823 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12824 json_object *json_llgr = NULL;
12825 const char *afi_safi_str;
12826
12827 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12828 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12829 json_object_string_add(
12830 json_cap,
12831 "longLivedGracefulRestart",
12832 "advertisedAndReceived");
12833 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12834 json_object_string_add(
12835 json_cap,
12836 "longLivedGracefulRestart",
12837 "advertised");
12838 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12839 json_object_string_add(
12840 json_cap,
12841 "longLivedGracefulRestart",
12842 "received");
12843
12844 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12845 json_llgr = json_object_new_object();
12846
12847 FOREACH_AFI_SAFI (afi, safi) {
12848 if (CHECK_FLAG(
12849 p->af_cap[afi]
12850 [safi],
12851 PEER_CAP_ENHE_AF_RCV)) {
12852 afi_safi_str =
12853 get_afi_safi_str(
12854 afi,
12855 safi,
12856 true);
12857 json_object_string_add(
12858 json_llgr,
12859 afi_safi_str,
12860 "received");
12861 }
12862 }
12863 json_object_object_add(
12864 json_cap,
12865 "longLivedGracefulRestartByPeer",
12866 json_llgr);
12867 }
12868 }
12869
12870 /* Route Refresh */
12871 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12872 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12873 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12874 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12875 (CHECK_FLAG(p->cap,
12876 PEER_CAP_REFRESH_NEW_RCV) ||
12877 CHECK_FLAG(p->cap,
12878 PEER_CAP_REFRESH_OLD_RCV))) {
12879 if (CHECK_FLAG(
12880 p->cap,
12881 PEER_CAP_REFRESH_OLD_RCV) &&
12882 CHECK_FLAG(
12883 p->cap,
12884 PEER_CAP_REFRESH_NEW_RCV))
12885 json_object_string_add(
12886 json_cap,
12887 "routeRefresh",
12888 "advertisedAndReceivedOldNew");
12889 else {
12890 if (CHECK_FLAG(
12891 p->cap,
12892 PEER_CAP_REFRESH_OLD_RCV))
12893 json_object_string_add(
12894 json_cap,
12895 "routeRefresh",
12896 "advertisedAndReceivedOld");
12897 else
12898 json_object_string_add(
12899 json_cap,
12900 "routeRefresh",
12901 "advertisedAndReceivedNew");
12902 }
12903 } else if (CHECK_FLAG(p->cap,
12904 PEER_CAP_REFRESH_ADV))
12905 json_object_string_add(json_cap,
12906 "routeRefresh",
12907 "advertised");
12908 else if (CHECK_FLAG(p->cap,
12909 PEER_CAP_REFRESH_NEW_RCV) ||
12910 CHECK_FLAG(p->cap,
12911 PEER_CAP_REFRESH_OLD_RCV))
12912 json_object_string_add(json_cap,
12913 "routeRefresh",
12914 "received");
12915 }
12916
12917 /* Enhanced Route Refresh */
12918 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
12919 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
12920 if (CHECK_FLAG(p->cap,
12921 PEER_CAP_ENHANCED_RR_ADV) &&
12922 CHECK_FLAG(p->cap,
12923 PEER_CAP_ENHANCED_RR_RCV))
12924 json_object_string_add(
12925 json_cap,
12926 "enhancedRouteRefresh",
12927 "advertisedAndReceived");
12928 else if (CHECK_FLAG(p->cap,
12929 PEER_CAP_ENHANCED_RR_ADV))
12930 json_object_string_add(
12931 json_cap,
12932 "enhancedRouteRefresh",
12933 "advertised");
12934 else if (CHECK_FLAG(p->cap,
12935 PEER_CAP_ENHANCED_RR_RCV))
12936 json_object_string_add(
12937 json_cap,
12938 "enhancedRouteRefresh",
12939 "received");
12940 }
12941
12942 /* Multiprotocol Extensions */
12943 json_object *json_multi = NULL;
12944
12945 json_multi = json_object_new_object();
12946
12947 FOREACH_AFI_SAFI (afi, safi) {
12948 if (p->afc_adv[afi][safi] ||
12949 p->afc_recv[afi][safi]) {
12950 json_object *json_exten = NULL;
12951 json_exten = json_object_new_object();
12952
12953 if (p->afc_adv[afi][safi] &&
12954 p->afc_recv[afi][safi])
12955 json_object_boolean_true_add(
12956 json_exten,
12957 "advertisedAndReceived");
12958 else if (p->afc_adv[afi][safi])
12959 json_object_boolean_true_add(
12960 json_exten,
12961 "advertised");
12962 else if (p->afc_recv[afi][safi])
12963 json_object_boolean_true_add(
12964 json_exten, "received");
12965
12966 json_object_object_add(
12967 json_multi,
12968 get_afi_safi_str(afi, safi,
12969 true),
12970 json_exten);
12971 }
12972 }
12973 json_object_object_add(json_cap,
12974 "multiprotocolExtensions",
12975 json_multi);
12976
12977 /* Hostname capabilities */
12978 json_object *json_hname = NULL;
12979
12980 json_hname = json_object_new_object();
12981
12982 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12983 json_object_string_add(
12984 json_hname, "advHostName",
12985 bgp->peer_self->hostname
12986 ? bgp->peer_self->hostname
12987 : "n/a");
12988 json_object_string_add(
12989 json_hname, "advDomainName",
12990 bgp->peer_self->domainname
12991 ? bgp->peer_self->domainname
12992 : "n/a");
12993 }
12994
12995
12996 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12997 json_object_string_add(
12998 json_hname, "rcvHostName",
12999 p->hostname ? p->hostname : "n/a");
13000 json_object_string_add(
13001 json_hname, "rcvDomainName",
13002 p->domainname ? p->domainname : "n/a");
13003 }
13004
13005 json_object_object_add(json_cap, "hostName",
13006 json_hname);
13007
13008 /* Gracefull Restart */
13009 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13010 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13011 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13012 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13013 json_object_string_add(
13014 json_cap, "gracefulRestart",
13015 "advertisedAndReceived");
13016 else if (CHECK_FLAG(p->cap,
13017 PEER_CAP_RESTART_ADV))
13018 json_object_string_add(
13019 json_cap,
13020 "gracefulRestartCapability",
13021 "advertised");
13022 else if (CHECK_FLAG(p->cap,
13023 PEER_CAP_RESTART_RCV))
13024 json_object_string_add(
13025 json_cap,
13026 "gracefulRestartCapability",
13027 "received");
13028
13029 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13030 int restart_af_count = 0;
13031 json_object *json_restart = NULL;
13032 json_restart = json_object_new_object();
13033
13034 json_object_int_add(
13035 json_cap,
13036 "gracefulRestartRemoteTimerMsecs",
13037 p->v_gr_restart * 1000);
13038
13039 FOREACH_AFI_SAFI (afi, safi) {
13040 if (CHECK_FLAG(
13041 p->af_cap[afi]
13042 [safi],
13043 PEER_CAP_RESTART_AF_RCV)) {
13044 json_object *json_sub =
13045 NULL;
13046 json_sub =
13047 json_object_new_object();
13048
13049 if (CHECK_FLAG(
13050 p->af_cap
13051 [afi]
13052 [safi],
13053 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13054 json_object_boolean_true_add(
13055 json_sub,
13056 "preserved");
13057 restart_af_count++;
13058 json_object_object_add(
13059 json_restart,
13060 get_afi_safi_str(
13061 afi,
13062 safi,
13063 true),
13064 json_sub);
13065 }
13066 }
13067 if (!restart_af_count) {
13068 json_object_string_add(
13069 json_cap,
13070 "addressFamiliesByPeer",
13071 "none");
13072 json_object_free(json_restart);
13073 } else
13074 json_object_object_add(
13075 json_cap,
13076 "addressFamiliesByPeer",
13077 json_restart);
13078 }
13079 }
13080 json_object_object_add(
13081 json_neigh, "neighborCapabilities", json_cap);
13082 } else {
13083 vty_out(vty, " Neighbor capabilities:\n");
13084
13085 /* AS4 */
13086 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13087 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13088 vty_out(vty, " 4 Byte AS:");
13089 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13090 vty_out(vty, " advertised");
13091 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13092 vty_out(vty, " %sreceived",
13093 CHECK_FLAG(p->cap,
13094 PEER_CAP_AS4_ADV)
13095 ? "and "
13096 : "");
13097 vty_out(vty, "\n");
13098 }
13099
13100 /* Extended Message Support */
13101 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13102 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13103 vty_out(vty, " Extended Message:");
13104 if (CHECK_FLAG(p->cap,
13105 PEER_CAP_EXTENDED_MESSAGE_ADV))
13106 vty_out(vty, " advertised");
13107 if (CHECK_FLAG(p->cap,
13108 PEER_CAP_EXTENDED_MESSAGE_RCV))
13109 vty_out(vty, " %sreceived",
13110 CHECK_FLAG(
13111 p->cap,
13112 PEER_CAP_EXTENDED_MESSAGE_ADV)
13113 ? "and "
13114 : "");
13115 vty_out(vty, "\n");
13116 }
13117
13118 /* AddPath */
13119 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13120 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13121 vty_out(vty, " AddPath:\n");
13122
13123 FOREACH_AFI_SAFI (afi, safi) {
13124 if (CHECK_FLAG(
13125 p->af_cap[afi][safi],
13126 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13127 CHECK_FLAG(
13128 p->af_cap[afi][safi],
13129 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13130 vty_out(vty, " %s: TX ",
13131 get_afi_safi_str(
13132 afi, safi,
13133 false));
13134
13135 if (CHECK_FLAG(
13136 p->af_cap[afi]
13137 [safi],
13138 PEER_CAP_ADDPATH_AF_TX_ADV))
13139 vty_out(vty,
13140 "advertised");
13141
13142 if (CHECK_FLAG(
13143 p->af_cap[afi]
13144 [safi],
13145 PEER_CAP_ADDPATH_AF_TX_RCV))
13146 vty_out(vty,
13147 "%sreceived",
13148 CHECK_FLAG(
13149 p->af_cap
13150 [afi]
13151 [safi],
13152 PEER_CAP_ADDPATH_AF_TX_ADV)
13153 ? " and "
13154 : "");
13155
13156 vty_out(vty, "\n");
13157 }
13158
13159 if (CHECK_FLAG(
13160 p->af_cap[afi][safi],
13161 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13162 CHECK_FLAG(
13163 p->af_cap[afi][safi],
13164 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13165 vty_out(vty, " %s: RX ",
13166 get_afi_safi_str(
13167 afi, safi,
13168 false));
13169
13170 if (CHECK_FLAG(
13171 p->af_cap[afi]
13172 [safi],
13173 PEER_CAP_ADDPATH_AF_RX_ADV))
13174 vty_out(vty,
13175 "advertised");
13176
13177 if (CHECK_FLAG(
13178 p->af_cap[afi]
13179 [safi],
13180 PEER_CAP_ADDPATH_AF_RX_RCV))
13181 vty_out(vty,
13182 "%sreceived",
13183 CHECK_FLAG(
13184 p->af_cap
13185 [afi]
13186 [safi],
13187 PEER_CAP_ADDPATH_AF_RX_ADV)
13188 ? " and "
13189 : "");
13190
13191 vty_out(vty, "\n");
13192 }
13193 }
13194 }
13195
13196 /* Dynamic */
13197 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13198 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13199 vty_out(vty, " Dynamic:");
13200 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13201 vty_out(vty, " advertised");
13202 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13203 vty_out(vty, " %sreceived",
13204 CHECK_FLAG(p->cap,
13205 PEER_CAP_DYNAMIC_ADV)
13206 ? "and "
13207 : "");
13208 vty_out(vty, "\n");
13209 }
13210
13211 /* Extended nexthop */
13212 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13213 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13214 vty_out(vty, " Extended nexthop:");
13215 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13216 vty_out(vty, " advertised");
13217 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13218 vty_out(vty, " %sreceived",
13219 CHECK_FLAG(p->cap,
13220 PEER_CAP_ENHE_ADV)
13221 ? "and "
13222 : "");
13223 vty_out(vty, "\n");
13224
13225 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13226 vty_out(vty,
13227 " Address families by peer:\n ");
13228 for (safi = SAFI_UNICAST;
13229 safi < SAFI_MAX; safi++)
13230 if (CHECK_FLAG(
13231 p->af_cap[AFI_IP]
13232 [safi],
13233 PEER_CAP_ENHE_AF_RCV))
13234 vty_out(vty,
13235 " %s\n",
13236 get_afi_safi_str(
13237 AFI_IP,
13238 safi,
13239 false));
13240 }
13241 }
13242
13243 /* Long-lived Graceful Restart */
13244 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13245 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13246 vty_out(vty,
13247 " Long-lived Graceful Restart:");
13248 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13249 vty_out(vty, " advertised");
13250 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13251 vty_out(vty, " %sreceived",
13252 CHECK_FLAG(p->cap,
13253 PEER_CAP_LLGR_ADV)
13254 ? "and "
13255 : "");
13256 vty_out(vty, "\n");
13257
13258 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13259 vty_out(vty,
13260 " Address families by peer:\n");
13261 FOREACH_AFI_SAFI (afi, safi)
13262 if (CHECK_FLAG(
13263 p->af_cap[afi]
13264 [safi],
13265 PEER_CAP_LLGR_AF_RCV))
13266 vty_out(vty,
13267 " %s\n",
13268 get_afi_safi_str(
13269 afi,
13270 safi,
13271 false));
13272 }
13273 }
13274
13275 /* Route Refresh */
13276 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13277 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13278 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13279 vty_out(vty, " Route refresh:");
13280 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13281 vty_out(vty, " advertised");
13282 if (CHECK_FLAG(p->cap,
13283 PEER_CAP_REFRESH_NEW_RCV) ||
13284 CHECK_FLAG(p->cap,
13285 PEER_CAP_REFRESH_OLD_RCV))
13286 vty_out(vty, " %sreceived(%s)",
13287 CHECK_FLAG(p->cap,
13288 PEER_CAP_REFRESH_ADV)
13289 ? "and "
13290 : "",
13291 (CHECK_FLAG(
13292 p->cap,
13293 PEER_CAP_REFRESH_OLD_RCV) &&
13294 CHECK_FLAG(
13295 p->cap,
13296 PEER_CAP_REFRESH_NEW_RCV))
13297 ? "old & new"
13298 : CHECK_FLAG(
13299 p->cap,
13300 PEER_CAP_REFRESH_OLD_RCV)
13301 ? "old"
13302 : "new");
13303
13304 vty_out(vty, "\n");
13305 }
13306
13307 /* Enhanced Route Refresh */
13308 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13309 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13310 vty_out(vty, " Enhanced Route Refresh:");
13311 if (CHECK_FLAG(p->cap,
13312 PEER_CAP_ENHANCED_RR_ADV))
13313 vty_out(vty, " advertised");
13314 if (CHECK_FLAG(p->cap,
13315 PEER_CAP_ENHANCED_RR_RCV))
13316 vty_out(vty, " %sreceived",
13317 CHECK_FLAG(p->cap,
13318 PEER_CAP_REFRESH_ADV)
13319 ? "and "
13320 : "");
13321 vty_out(vty, "\n");
13322 }
13323
13324 /* Multiprotocol Extensions */
13325 FOREACH_AFI_SAFI (afi, safi)
13326 if (p->afc_adv[afi][safi] ||
13327 p->afc_recv[afi][safi]) {
13328 vty_out(vty, " Address Family %s:",
13329 get_afi_safi_str(afi, safi,
13330 false));
13331 if (p->afc_adv[afi][safi])
13332 vty_out(vty, " advertised");
13333 if (p->afc_recv[afi][safi])
13334 vty_out(vty, " %sreceived",
13335 p->afc_adv[afi][safi]
13336 ? "and "
13337 : "");
13338 vty_out(vty, "\n");
13339 }
13340
13341 /* Hostname capability */
13342 vty_out(vty, " Hostname Capability:");
13343
13344 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13345 vty_out(vty,
13346 " advertised (name: %s,domain name: %s)",
13347 bgp->peer_self->hostname
13348 ? bgp->peer_self->hostname
13349 : "n/a",
13350 bgp->peer_self->domainname
13351 ? bgp->peer_self->domainname
13352 : "n/a");
13353 } else {
13354 vty_out(vty, " not advertised");
13355 }
13356
13357 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13358 vty_out(vty,
13359 " received (name: %s,domain name: %s)",
13360 p->hostname ? p->hostname : "n/a",
13361 p->domainname ? p->domainname : "n/a");
13362 } else {
13363 vty_out(vty, " not received");
13364 }
13365
13366 vty_out(vty, "\n");
13367
13368 /* Graceful Restart */
13369 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13370 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13371 vty_out(vty,
13372 " Graceful Restart Capability:");
13373 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13374 vty_out(vty, " advertised");
13375 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13376 vty_out(vty, " %sreceived",
13377 CHECK_FLAG(p->cap,
13378 PEER_CAP_RESTART_ADV)
13379 ? "and "
13380 : "");
13381 vty_out(vty, "\n");
13382
13383 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13384 int restart_af_count = 0;
13385
13386 vty_out(vty,
13387 " Remote Restart timer is %d seconds\n",
13388 p->v_gr_restart);
13389 vty_out(vty,
13390 " Address families by peer:\n ");
13391
13392 FOREACH_AFI_SAFI (afi, safi)
13393 if (CHECK_FLAG(
13394 p->af_cap[afi]
13395 [safi],
13396 PEER_CAP_RESTART_AF_RCV)) {
13397 vty_out(vty, "%s%s(%s)",
13398 restart_af_count
13399 ? ", "
13400 : "",
13401 get_afi_safi_str(
13402 afi,
13403 safi,
13404 false),
13405 CHECK_FLAG(
13406 p->af_cap
13407 [afi]
13408 [safi],
13409 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13410 ? "preserved"
13411 : "not preserved");
13412 restart_af_count++;
13413 }
13414 if (!restart_af_count)
13415 vty_out(vty, "none");
13416 vty_out(vty, "\n");
13417 }
13418 } /* Gracefull Restart */
13419 }
13420 }
13421
13422 /* graceful restart information */
13423 json_object *json_grace = NULL;
13424 json_object *json_grace_send = NULL;
13425 json_object *json_grace_recv = NULL;
13426 int eor_send_af_count = 0;
13427 int eor_receive_af_count = 0;
13428
13429 if (use_json) {
13430 json_grace = json_object_new_object();
13431 json_grace_send = json_object_new_object();
13432 json_grace_recv = json_object_new_object();
13433
13434 if ((peer_established(p)) &&
13435 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13436 FOREACH_AFI_SAFI (afi, safi) {
13437 if (CHECK_FLAG(p->af_sflags[afi][safi],
13438 PEER_STATUS_EOR_SEND)) {
13439 json_object_boolean_true_add(
13440 json_grace_send,
13441 get_afi_safi_str(afi, safi,
13442 true));
13443 eor_send_af_count++;
13444 }
13445 }
13446 FOREACH_AFI_SAFI (afi, safi) {
13447 if (CHECK_FLAG(p->af_sflags[afi][safi],
13448 PEER_STATUS_EOR_RECEIVED)) {
13449 json_object_boolean_true_add(
13450 json_grace_recv,
13451 get_afi_safi_str(afi, safi,
13452 true));
13453 eor_receive_af_count++;
13454 }
13455 }
13456 }
13457 json_object_object_add(json_grace, "endOfRibSend",
13458 json_grace_send);
13459 json_object_object_add(json_grace, "endOfRibRecv",
13460 json_grace_recv);
13461
13462
13463 if (p->t_gr_restart)
13464 json_object_int_add(
13465 json_grace, "gracefulRestartTimerMsecs",
13466 thread_timer_remain_second(p->t_gr_restart) *
13467 1000);
13468
13469 if (p->t_gr_stale)
13470 json_object_int_add(
13471 json_grace, "gracefulStalepathTimerMsecs",
13472 thread_timer_remain_second(p->t_gr_stale) *
13473 1000);
13474 /* more gr info in new format */
13475 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13476 json_object_object_add(json_neigh, "gracefulRestartInfo",
13477 json_grace);
13478 } else {
13479 vty_out(vty, " Graceful restart information:\n");
13480 if ((peer_established(p)) &&
13481 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13482
13483 vty_out(vty, " End-of-RIB send: ");
13484 FOREACH_AFI_SAFI (afi, safi) {
13485 if (CHECK_FLAG(p->af_sflags[afi][safi],
13486 PEER_STATUS_EOR_SEND)) {
13487 vty_out(vty, "%s%s",
13488 eor_send_af_count ? ", " : "",
13489 get_afi_safi_str(afi, safi,
13490 false));
13491 eor_send_af_count++;
13492 }
13493 }
13494 vty_out(vty, "\n");
13495 vty_out(vty, " End-of-RIB received: ");
13496 FOREACH_AFI_SAFI (afi, safi) {
13497 if (CHECK_FLAG(p->af_sflags[afi][safi],
13498 PEER_STATUS_EOR_RECEIVED)) {
13499 vty_out(vty, "%s%s",
13500 eor_receive_af_count ? ", "
13501 : "",
13502 get_afi_safi_str(afi, safi,
13503 false));
13504 eor_receive_af_count++;
13505 }
13506 }
13507 vty_out(vty, "\n");
13508 }
13509
13510 if (p->t_gr_restart)
13511 vty_out(vty,
13512 " The remaining time of restart timer is %ld\n",
13513 thread_timer_remain_second(p->t_gr_restart));
13514
13515 if (p->t_gr_stale)
13516 vty_out(vty,
13517 " The remaining time of stalepath timer is %ld\n",
13518 thread_timer_remain_second(p->t_gr_stale));
13519
13520 /* more gr info in new format */
13521 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13522 }
13523
13524 if (use_json) {
13525 json_object *json_stat = NULL;
13526 json_stat = json_object_new_object();
13527 /* Packet counts. */
13528
13529 atomic_size_t outq_count, inq_count;
13530 outq_count = atomic_load_explicit(&p->obuf->count,
13531 memory_order_relaxed);
13532 inq_count = atomic_load_explicit(&p->ibuf->count,
13533 memory_order_relaxed);
13534
13535 json_object_int_add(json_stat, "depthInq",
13536 (unsigned long)inq_count);
13537 json_object_int_add(json_stat, "depthOutq",
13538 (unsigned long)outq_count);
13539 json_object_int_add(json_stat, "opensSent",
13540 atomic_load_explicit(&p->open_out,
13541 memory_order_relaxed));
13542 json_object_int_add(json_stat, "opensRecv",
13543 atomic_load_explicit(&p->open_in,
13544 memory_order_relaxed));
13545 json_object_int_add(json_stat, "notificationsSent",
13546 atomic_load_explicit(&p->notify_out,
13547 memory_order_relaxed));
13548 json_object_int_add(json_stat, "notificationsRecv",
13549 atomic_load_explicit(&p->notify_in,
13550 memory_order_relaxed));
13551 json_object_int_add(json_stat, "updatesSent",
13552 atomic_load_explicit(&p->update_out,
13553 memory_order_relaxed));
13554 json_object_int_add(json_stat, "updatesRecv",
13555 atomic_load_explicit(&p->update_in,
13556 memory_order_relaxed));
13557 json_object_int_add(json_stat, "keepalivesSent",
13558 atomic_load_explicit(&p->keepalive_out,
13559 memory_order_relaxed));
13560 json_object_int_add(json_stat, "keepalivesRecv",
13561 atomic_load_explicit(&p->keepalive_in,
13562 memory_order_relaxed));
13563 json_object_int_add(json_stat, "routeRefreshSent",
13564 atomic_load_explicit(&p->refresh_out,
13565 memory_order_relaxed));
13566 json_object_int_add(json_stat, "routeRefreshRecv",
13567 atomic_load_explicit(&p->refresh_in,
13568 memory_order_relaxed));
13569 json_object_int_add(json_stat, "capabilitySent",
13570 atomic_load_explicit(&p->dynamic_cap_out,
13571 memory_order_relaxed));
13572 json_object_int_add(json_stat, "capabilityRecv",
13573 atomic_load_explicit(&p->dynamic_cap_in,
13574 memory_order_relaxed));
13575 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13576 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13577 json_object_object_add(json_neigh, "messageStats", json_stat);
13578 } else {
13579 atomic_size_t outq_count, inq_count;
13580 outq_count = atomic_load_explicit(&p->obuf->count,
13581 memory_order_relaxed);
13582 inq_count = atomic_load_explicit(&p->ibuf->count,
13583 memory_order_relaxed);
13584
13585 /* Packet counts. */
13586 vty_out(vty, " Message statistics:\n");
13587 vty_out(vty, " Inq depth is %zu\n", inq_count);
13588 vty_out(vty, " Outq depth is %zu\n", outq_count);
13589 vty_out(vty, " Sent Rcvd\n");
13590 vty_out(vty, " Opens: %10d %10d\n",
13591 atomic_load_explicit(&p->open_out,
13592 memory_order_relaxed),
13593 atomic_load_explicit(&p->open_in,
13594 memory_order_relaxed));
13595 vty_out(vty, " Notifications: %10d %10d\n",
13596 atomic_load_explicit(&p->notify_out,
13597 memory_order_relaxed),
13598 atomic_load_explicit(&p->notify_in,
13599 memory_order_relaxed));
13600 vty_out(vty, " Updates: %10d %10d\n",
13601 atomic_load_explicit(&p->update_out,
13602 memory_order_relaxed),
13603 atomic_load_explicit(&p->update_in,
13604 memory_order_relaxed));
13605 vty_out(vty, " Keepalives: %10d %10d\n",
13606 atomic_load_explicit(&p->keepalive_out,
13607 memory_order_relaxed),
13608 atomic_load_explicit(&p->keepalive_in,
13609 memory_order_relaxed));
13610 vty_out(vty, " Route Refresh: %10d %10d\n",
13611 atomic_load_explicit(&p->refresh_out,
13612 memory_order_relaxed),
13613 atomic_load_explicit(&p->refresh_in,
13614 memory_order_relaxed));
13615 vty_out(vty, " Capability: %10d %10d\n",
13616 atomic_load_explicit(&p->dynamic_cap_out,
13617 memory_order_relaxed),
13618 atomic_load_explicit(&p->dynamic_cap_in,
13619 memory_order_relaxed));
13620 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13621 PEER_TOTAL_RX(p));
13622 }
13623
13624 if (use_json) {
13625 /* advertisement-interval */
13626 json_object_int_add(json_neigh,
13627 "minBtwnAdvertisementRunsTimerMsecs",
13628 p->v_routeadv * 1000);
13629
13630 /* Update-source. */
13631 if (p->update_if || p->update_source) {
13632 if (p->update_if)
13633 json_object_string_add(json_neigh,
13634 "updateSource",
13635 p->update_if);
13636 else if (p->update_source)
13637 json_object_string_add(
13638 json_neigh, "updateSource",
13639 sockunion2str(p->update_source, buf1,
13640 SU_ADDRSTRLEN));
13641 }
13642 } else {
13643 /* advertisement-interval */
13644 vty_out(vty,
13645 " Minimum time between advertisement runs is %d seconds\n",
13646 p->v_routeadv);
13647
13648 /* Update-source. */
13649 if (p->update_if || p->update_source) {
13650 vty_out(vty, " Update source is ");
13651 if (p->update_if)
13652 vty_out(vty, "%s", p->update_if);
13653 else if (p->update_source)
13654 vty_out(vty, "%s",
13655 sockunion2str(p->update_source, buf1,
13656 SU_ADDRSTRLEN));
13657 vty_out(vty, "\n");
13658 }
13659
13660 vty_out(vty, "\n");
13661 }
13662
13663 /* Address Family Information */
13664 json_object *json_hold = NULL;
13665
13666 if (use_json)
13667 json_hold = json_object_new_object();
13668
13669 FOREACH_AFI_SAFI (afi, safi)
13670 if (p->afc[afi][safi])
13671 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13672 json_hold);
13673
13674 if (use_json) {
13675 json_object_object_add(json_neigh, "addressFamilyInfo",
13676 json_hold);
13677 json_object_int_add(json_neigh, "connectionsEstablished",
13678 p->established);
13679 json_object_int_add(json_neigh, "connectionsDropped",
13680 p->dropped);
13681 } else
13682 vty_out(vty, " Connections established %d; dropped %d\n",
13683 p->established, p->dropped);
13684
13685 if (!p->last_reset) {
13686 if (use_json)
13687 json_object_string_add(json_neigh, "lastReset",
13688 "never");
13689 else
13690 vty_out(vty, " Last reset never\n");
13691 } else {
13692 if (use_json) {
13693 time_t uptime;
13694 struct tm tm;
13695
13696 uptime = bgp_clock();
13697 uptime -= p->resettime;
13698 gmtime_r(&uptime, &tm);
13699
13700 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13701 (tm.tm_sec * 1000)
13702 + (tm.tm_min * 60000)
13703 + (tm.tm_hour * 3600000));
13704 bgp_show_peer_reset(NULL, p, json_neigh, true);
13705 } else {
13706 vty_out(vty, " Last reset %s, ",
13707 peer_uptime(p->resettime, timebuf,
13708 BGP_UPTIME_LEN, 0, NULL));
13709
13710 bgp_show_peer_reset(vty, p, NULL, false);
13711 if (p->last_reset_cause_size) {
13712 msg = p->last_reset_cause;
13713 vty_out(vty,
13714 " Message received that caused BGP to send a NOTIFICATION:\n ");
13715 for (i = 1; i <= p->last_reset_cause_size;
13716 i++) {
13717 vty_out(vty, "%02X", *msg++);
13718
13719 if (i != p->last_reset_cause_size) {
13720 if (i % 16 == 0) {
13721 vty_out(vty, "\n ");
13722 } else if (i % 4 == 0) {
13723 vty_out(vty, " ");
13724 }
13725 }
13726 }
13727 vty_out(vty, "\n");
13728 }
13729 }
13730 }
13731
13732 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13733 if (use_json)
13734 json_object_boolean_true_add(json_neigh,
13735 "prefixesConfigExceedMax");
13736 else
13737 vty_out(vty,
13738 " Peer had exceeded the max. no. of prefixes configured.\n");
13739
13740 if (p->t_pmax_restart) {
13741 if (use_json) {
13742 json_object_boolean_true_add(
13743 json_neigh, "reducePrefixNumFrom");
13744 json_object_int_add(json_neigh,
13745 "restartInTimerMsec",
13746 thread_timer_remain_second(
13747 p->t_pmax_restart)
13748 * 1000);
13749 } else
13750 vty_out(vty,
13751 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13752 p->host, thread_timer_remain_second(
13753 p->t_pmax_restart));
13754 } else {
13755 if (use_json)
13756 json_object_boolean_true_add(
13757 json_neigh,
13758 "reducePrefixNumAndClearIpBgp");
13759 else
13760 vty_out(vty,
13761 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13762 p->host);
13763 }
13764 }
13765
13766 /* EBGP Multihop and GTSM */
13767 if (p->sort != BGP_PEER_IBGP) {
13768 if (use_json) {
13769 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13770 json_object_int_add(json_neigh,
13771 "externalBgpNbrMaxHopsAway",
13772 p->gtsm_hops);
13773 else if (p->ttl > BGP_DEFAULT_TTL)
13774 json_object_int_add(json_neigh,
13775 "externalBgpNbrMaxHopsAway",
13776 p->ttl);
13777 } else {
13778 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13779 vty_out(vty,
13780 " External BGP neighbor may be up to %d hops away.\n",
13781 p->gtsm_hops);
13782 else if (p->ttl > BGP_DEFAULT_TTL)
13783 vty_out(vty,
13784 " External BGP neighbor may be up to %d hops away.\n",
13785 p->ttl);
13786 }
13787 } else {
13788 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
13789 if (use_json)
13790 json_object_int_add(json_neigh,
13791 "internalBgpNbrMaxHopsAway",
13792 p->gtsm_hops);
13793 else
13794 vty_out(vty,
13795 " Internal BGP neighbor may be up to %d hops away.\n",
13796 p->gtsm_hops);
13797 }
13798 }
13799
13800 /* Local address. */
13801 if (p->su_local) {
13802 if (use_json) {
13803 json_object_string_add(json_neigh, "hostLocal",
13804 sockunion2str(p->su_local, buf1,
13805 SU_ADDRSTRLEN));
13806 json_object_int_add(json_neigh, "portLocal",
13807 ntohs(p->su_local->sin.sin_port));
13808 } else
13809 vty_out(vty, "Local host: %s, Local port: %d\n",
13810 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13811 ntohs(p->su_local->sin.sin_port));
13812 }
13813
13814 /* Remote address. */
13815 if (p->su_remote) {
13816 if (use_json) {
13817 json_object_string_add(json_neigh, "hostForeign",
13818 sockunion2str(p->su_remote, buf1,
13819 SU_ADDRSTRLEN));
13820 json_object_int_add(json_neigh, "portForeign",
13821 ntohs(p->su_remote->sin.sin_port));
13822 } else
13823 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13824 sockunion2str(p->su_remote, buf1,
13825 SU_ADDRSTRLEN),
13826 ntohs(p->su_remote->sin.sin_port));
13827 }
13828
13829 /* Nexthop display. */
13830 if (p->su_local) {
13831 if (use_json) {
13832 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13833 &p->nexthop.v4);
13834 json_object_string_addf(json_neigh, "nexthopGlobal",
13835 "%pI6", &p->nexthop.v6_global);
13836 json_object_string_addf(json_neigh, "nexthopLocal",
13837 "%pI6", &p->nexthop.v6_local);
13838 if (p->shared_network)
13839 json_object_string_add(json_neigh,
13840 "bgpConnection",
13841 "sharedNetwork");
13842 else
13843 json_object_string_add(json_neigh,
13844 "bgpConnection",
13845 "nonSharedNetwork");
13846 } else {
13847 vty_out(vty, "Nexthop: %s\n",
13848 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13849 sizeof(buf1)));
13850 vty_out(vty, "Nexthop global: %s\n",
13851 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13852 sizeof(buf1)));
13853 vty_out(vty, "Nexthop local: %s\n",
13854 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13855 sizeof(buf1)));
13856 vty_out(vty, "BGP connection: %s\n",
13857 p->shared_network ? "shared network"
13858 : "non shared network");
13859 }
13860 }
13861
13862 /* Timer information. */
13863 if (use_json) {
13864 json_object_int_add(json_neigh, "connectRetryTimer",
13865 p->v_connect);
13866 if (peer_established(p) && p->rtt)
13867 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13868 p->rtt);
13869 if (p->t_start)
13870 json_object_int_add(
13871 json_neigh, "nextStartTimerDueInMsecs",
13872 thread_timer_remain_second(p->t_start) * 1000);
13873 if (p->t_connect)
13874 json_object_int_add(
13875 json_neigh, "nextConnectTimerDueInMsecs",
13876 thread_timer_remain_second(p->t_connect)
13877 * 1000);
13878 if (p->t_routeadv) {
13879 json_object_int_add(json_neigh, "mraiInterval",
13880 p->v_routeadv);
13881 json_object_int_add(
13882 json_neigh, "mraiTimerExpireInMsecs",
13883 thread_timer_remain_second(p->t_routeadv)
13884 * 1000);
13885 }
13886 if (p->password)
13887 json_object_int_add(json_neigh, "authenticationEnabled",
13888 1);
13889
13890 if (p->t_read)
13891 json_object_string_add(json_neigh, "readThread", "on");
13892 else
13893 json_object_string_add(json_neigh, "readThread", "off");
13894
13895 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
13896 json_object_string_add(json_neigh, "writeThread", "on");
13897 else
13898 json_object_string_add(json_neigh, "writeThread",
13899 "off");
13900 } else {
13901 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13902 p->v_connect);
13903 if (peer_established(p) && p->rtt)
13904 vty_out(vty, "Estimated round trip time: %d ms\n",
13905 p->rtt);
13906 if (p->t_start)
13907 vty_out(vty, "Next start timer due in %ld seconds\n",
13908 thread_timer_remain_second(p->t_start));
13909 if (p->t_connect)
13910 vty_out(vty, "Next connect timer due in %ld seconds\n",
13911 thread_timer_remain_second(p->t_connect));
13912 if (p->t_routeadv)
13913 vty_out(vty,
13914 "MRAI (interval %u) timer expires in %ld seconds\n",
13915 p->v_routeadv,
13916 thread_timer_remain_second(p->t_routeadv));
13917 if (p->password)
13918 vty_out(vty, "Peer Authentication Enabled\n");
13919
13920 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
13921 p->t_read ? "on" : "off",
13922 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13923 ? "on"
13924 : "off", p->fd);
13925 }
13926
13927 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13928 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13929 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13930
13931 if (!use_json)
13932 vty_out(vty, "\n");
13933
13934 /* BFD information. */
13935 if (p->bfd_config)
13936 bgp_bfd_show_info(vty, p, json_neigh);
13937
13938 if (use_json) {
13939 if (p->conf_if) /* Configured interface name. */
13940 json_object_object_add(json, p->conf_if, json_neigh);
13941 else /* Configured IP address. */
13942 json_object_object_add(json, p->host, json_neigh);
13943 }
13944 }
13945
13946 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13947 enum show_type type,
13948 union sockunion *su,
13949 const char *conf_if, afi_t afi,
13950 bool use_json)
13951 {
13952 struct listnode *node, *nnode;
13953 struct peer *peer;
13954 int find = 0;
13955 safi_t safi = SAFI_UNICAST;
13956 json_object *json = NULL;
13957 json_object *json_neighbor = NULL;
13958
13959 if (use_json) {
13960 json = json_object_new_object();
13961 json_neighbor = json_object_new_object();
13962 }
13963
13964 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13965
13966 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13967 continue;
13968
13969 if ((peer->afc[afi][safi]) == 0)
13970 continue;
13971
13972 if (type == show_all) {
13973 bgp_show_peer_gr_status(vty, peer, use_json,
13974 json_neighbor);
13975
13976 if (use_json) {
13977 json_object_object_add(json, peer->host,
13978 json_neighbor);
13979 json_neighbor = NULL;
13980 }
13981
13982 } else if (type == show_peer) {
13983 if (conf_if) {
13984 if ((peer->conf_if
13985 && !strcmp(peer->conf_if, conf_if))
13986 || (peer->hostname
13987 && !strcmp(peer->hostname, conf_if))) {
13988 find = 1;
13989 bgp_show_peer_gr_status(vty, peer,
13990 use_json,
13991 json_neighbor);
13992 }
13993 } else {
13994 if (sockunion_same(&peer->su, su)) {
13995 find = 1;
13996 bgp_show_peer_gr_status(vty, peer,
13997 use_json,
13998 json_neighbor);
13999 }
14000 }
14001 if (use_json && find)
14002 json_object_object_add(json, peer->host,
14003 json_neighbor);
14004 }
14005
14006 if (find) {
14007 json_neighbor = NULL;
14008 break;
14009 }
14010 }
14011
14012 if (type == show_peer && !find) {
14013 if (use_json)
14014 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14015 else
14016 vty_out(vty, "%% No such neighbor\n");
14017 }
14018 if (use_json) {
14019 if (json_neighbor)
14020 json_object_free(json_neighbor);
14021 vty_json(vty, json);
14022 } else {
14023 vty_out(vty, "\n");
14024 }
14025
14026 return CMD_SUCCESS;
14027 }
14028
14029 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14030 enum show_type type, union sockunion *su,
14031 const char *conf_if, bool use_json,
14032 json_object *json)
14033 {
14034 struct listnode *node, *nnode;
14035 struct peer *peer;
14036 int find = 0;
14037 bool nbr_output = false;
14038 afi_t afi = AFI_MAX;
14039 safi_t safi = SAFI_MAX;
14040
14041 if (type == show_ipv4_peer || type == show_ipv4_all) {
14042 afi = AFI_IP;
14043 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14044 afi = AFI_IP6;
14045 }
14046
14047 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14048 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14049 continue;
14050
14051 switch (type) {
14052 case show_all:
14053 bgp_show_peer(vty, peer, use_json, json);
14054 nbr_output = true;
14055 break;
14056 case show_peer:
14057 if (conf_if) {
14058 if ((peer->conf_if
14059 && !strcmp(peer->conf_if, conf_if))
14060 || (peer->hostname
14061 && !strcmp(peer->hostname, conf_if))) {
14062 find = 1;
14063 bgp_show_peer(vty, peer, use_json,
14064 json);
14065 }
14066 } else {
14067 if (sockunion_same(&peer->su, su)) {
14068 find = 1;
14069 bgp_show_peer(vty, peer, use_json,
14070 json);
14071 }
14072 }
14073 break;
14074 case show_ipv4_peer:
14075 case show_ipv6_peer:
14076 FOREACH_SAFI (safi) {
14077 if (peer->afc[afi][safi]) {
14078 if (conf_if) {
14079 if ((peer->conf_if
14080 && !strcmp(peer->conf_if, conf_if))
14081 || (peer->hostname
14082 && !strcmp(peer->hostname, conf_if))) {
14083 find = 1;
14084 bgp_show_peer(vty, peer, use_json,
14085 json);
14086 break;
14087 }
14088 } else {
14089 if (sockunion_same(&peer->su, su)) {
14090 find = 1;
14091 bgp_show_peer(vty, peer, use_json,
14092 json);
14093 break;
14094 }
14095 }
14096 }
14097 }
14098 break;
14099 case show_ipv4_all:
14100 case show_ipv6_all:
14101 FOREACH_SAFI (safi) {
14102 if (peer->afc[afi][safi]) {
14103 bgp_show_peer(vty, peer, use_json, json);
14104 nbr_output = true;
14105 break;
14106 }
14107 }
14108 break;
14109 }
14110 }
14111
14112 if ((type == show_peer || type == show_ipv4_peer ||
14113 type == show_ipv6_peer) && !find) {
14114 if (use_json)
14115 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14116 else
14117 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14118 }
14119
14120 if (type != show_peer && type != show_ipv4_peer &&
14121 type != show_ipv6_peer && !nbr_output && !use_json)
14122 vty_out(vty, "%% No BGP neighbors found\n");
14123
14124 if (use_json) {
14125 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14126 json, JSON_C_TO_STRING_PRETTY));
14127 } else {
14128 vty_out(vty, "\n");
14129 }
14130
14131 return CMD_SUCCESS;
14132 }
14133
14134 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14135 enum show_type type,
14136 const char *ip_str,
14137 afi_t afi, bool use_json)
14138 {
14139
14140 int ret;
14141 struct bgp *bgp;
14142 union sockunion su;
14143
14144 bgp = bgp_get_default();
14145
14146 if (!bgp)
14147 return;
14148
14149 if (!use_json)
14150 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14151 NULL);
14152
14153 if (ip_str) {
14154 ret = str2sockunion(ip_str, &su);
14155 if (ret < 0)
14156 bgp_show_neighbor_graceful_restart(
14157 vty, bgp, type, NULL, ip_str, afi, use_json);
14158 else
14159 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14160 NULL, afi, use_json);
14161 } else
14162 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14163 afi, use_json);
14164 }
14165
14166 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14167 enum show_type type,
14168 const char *ip_str,
14169 bool use_json)
14170 {
14171 struct listnode *node, *nnode;
14172 struct bgp *bgp;
14173 union sockunion su;
14174 json_object *json = NULL;
14175 int ret, is_first = 1;
14176 bool nbr_output = false;
14177
14178 if (use_json)
14179 vty_out(vty, "{\n");
14180
14181 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14182 nbr_output = true;
14183 if (use_json) {
14184 if (!(json = json_object_new_object())) {
14185 flog_err(
14186 EC_BGP_JSON_MEM_ERROR,
14187 "Unable to allocate memory for JSON object");
14188 vty_out(vty,
14189 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14190 return;
14191 }
14192
14193 json_object_int_add(json, "vrfId",
14194 (bgp->vrf_id == VRF_UNKNOWN)
14195 ? -1
14196 : (int64_t)bgp->vrf_id);
14197 json_object_string_add(
14198 json, "vrfName",
14199 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14200 ? VRF_DEFAULT_NAME
14201 : bgp->name);
14202
14203 if (!is_first)
14204 vty_out(vty, ",\n");
14205 else
14206 is_first = 0;
14207
14208 vty_out(vty, "\"%s\":",
14209 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14210 ? VRF_DEFAULT_NAME
14211 : bgp->name);
14212 } else {
14213 vty_out(vty, "\nInstance %s:\n",
14214 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14215 ? VRF_DEFAULT_NAME
14216 : bgp->name);
14217 }
14218
14219 if (type == show_peer || type == show_ipv4_peer ||
14220 type == show_ipv6_peer) {
14221 ret = str2sockunion(ip_str, &su);
14222 if (ret < 0)
14223 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14224 use_json, json);
14225 else
14226 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14227 use_json, json);
14228 } else {
14229 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14230 use_json, json);
14231 }
14232 json_object_free(json);
14233 json = NULL;
14234 }
14235
14236 if (use_json)
14237 vty_out(vty, "}\n");
14238 else if (!nbr_output)
14239 vty_out(vty, "%% BGP instance not found\n");
14240 }
14241
14242 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14243 enum show_type type, const char *ip_str,
14244 bool use_json)
14245 {
14246 int ret;
14247 struct bgp *bgp;
14248 union sockunion su;
14249 json_object *json = NULL;
14250
14251 if (name) {
14252 if (strmatch(name, "all")) {
14253 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14254 use_json);
14255 return CMD_SUCCESS;
14256 } else {
14257 bgp = bgp_lookup_by_name(name);
14258 if (!bgp) {
14259 if (use_json) {
14260 json = json_object_new_object();
14261 vty_json(vty, json);
14262 } else
14263 vty_out(vty,
14264 "%% BGP instance not found\n");
14265
14266 return CMD_WARNING;
14267 }
14268 }
14269 } else {
14270 bgp = bgp_get_default();
14271 }
14272
14273 if (bgp) {
14274 json = json_object_new_object();
14275 if (ip_str) {
14276 ret = str2sockunion(ip_str, &su);
14277 if (ret < 0)
14278 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14279 use_json, json);
14280 else
14281 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14282 use_json, json);
14283 } else {
14284 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14285 json);
14286 }
14287 json_object_free(json);
14288 } else {
14289 if (use_json)
14290 vty_out(vty, "{}\n");
14291 else
14292 vty_out(vty, "%% BGP instance not found\n");
14293 }
14294
14295 return CMD_SUCCESS;
14296 }
14297
14298
14299
14300 /* "show [ip] bgp neighbors graceful-restart" commands. */
14301 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14302 show_ip_bgp_neighbors_graceful_restart_cmd,
14303 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14304 SHOW_STR
14305 BGP_STR
14306 IP_STR
14307 IPV6_STR
14308 NEIGHBOR_STR
14309 "Neighbor to display information about\n"
14310 "Neighbor to display information about\n"
14311 "Neighbor on BGP configured interface\n"
14312 GR_SHOW
14313 JSON_STR)
14314 {
14315 char *sh_arg = NULL;
14316 enum show_type sh_type;
14317 int idx = 0;
14318 afi_t afi = AFI_MAX;
14319 bool uj = use_json(argc, argv);
14320
14321 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14322 afi = AFI_MAX;
14323
14324 idx++;
14325
14326 if (argv_find(argv, argc, "A.B.C.D", &idx)
14327 || argv_find(argv, argc, "X:X::X:X", &idx)
14328 || argv_find(argv, argc, "WORD", &idx)) {
14329 sh_type = show_peer;
14330 sh_arg = argv[idx]->arg;
14331 } else
14332 sh_type = show_all;
14333
14334 if (!argv_find(argv, argc, "graceful-restart", &idx))
14335 return CMD_SUCCESS;
14336
14337
14338 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14339 afi, uj);
14340 }
14341
14342 /* "show [ip] bgp neighbors" commands. */
14343 DEFUN (show_ip_bgp_neighbors,
14344 show_ip_bgp_neighbors_cmd,
14345 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14346 SHOW_STR
14347 IP_STR
14348 BGP_STR
14349 BGP_INSTANCE_HELP_STR
14350 "Address Family\n"
14351 "Address Family\n"
14352 "Detailed information on TCP and BGP neighbor connections\n"
14353 "Neighbor to display information about\n"
14354 "Neighbor to display information about\n"
14355 "Neighbor on BGP configured interface\n"
14356 JSON_STR)
14357 {
14358 char *vrf = NULL;
14359 char *sh_arg = NULL;
14360 enum show_type sh_type;
14361 afi_t afi = AFI_MAX;
14362
14363 bool uj = use_json(argc, argv);
14364
14365 int idx = 0;
14366
14367 /* [<vrf> VIEWVRFNAME] */
14368 if (argv_find(argv, argc, "vrf", &idx)) {
14369 vrf = argv[idx + 1]->arg;
14370 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14371 vrf = NULL;
14372 } else if (argv_find(argv, argc, "view", &idx))
14373 /* [<view> VIEWVRFNAME] */
14374 vrf = argv[idx + 1]->arg;
14375
14376 idx++;
14377
14378 if (argv_find(argv, argc, "ipv4", &idx)) {
14379 sh_type = show_ipv4_all;
14380 afi = AFI_IP;
14381 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14382 sh_type = show_ipv6_all;
14383 afi = AFI_IP6;
14384 } else {
14385 sh_type = show_all;
14386 }
14387
14388 if (argv_find(argv, argc, "A.B.C.D", &idx)
14389 || argv_find(argv, argc, "X:X::X:X", &idx)
14390 || argv_find(argv, argc, "WORD", &idx)) {
14391 sh_type = show_peer;
14392 sh_arg = argv[idx]->arg;
14393 }
14394
14395 if (sh_type == show_peer && afi == AFI_IP) {
14396 sh_type = show_ipv4_peer;
14397 } else if (sh_type == show_peer && afi == AFI_IP6) {
14398 sh_type = show_ipv6_peer;
14399 }
14400
14401 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14402 }
14403
14404 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14405 paths' and `show ip mbgp paths'. Those functions results are the
14406 same.*/
14407 DEFUN (show_ip_bgp_paths,
14408 show_ip_bgp_paths_cmd,
14409 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14410 SHOW_STR
14411 IP_STR
14412 BGP_STR
14413 BGP_SAFI_HELP_STR
14414 "Path information\n")
14415 {
14416 vty_out(vty, "Address Refcnt Path\n");
14417 aspath_print_all_vty(vty);
14418 return CMD_SUCCESS;
14419 }
14420
14421 #include "hash.h"
14422
14423 static void community_show_all_iterator(struct hash_bucket *bucket,
14424 struct vty *vty)
14425 {
14426 struct community *com;
14427
14428 com = (struct community *)bucket->data;
14429 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14430 community_str(com, false));
14431 }
14432
14433 /* Show BGP's community internal data. */
14434 DEFUN (show_ip_bgp_community_info,
14435 show_ip_bgp_community_info_cmd,
14436 "show [ip] bgp community-info",
14437 SHOW_STR
14438 IP_STR
14439 BGP_STR
14440 "List all bgp community information\n")
14441 {
14442 vty_out(vty, "Address Refcnt Community\n");
14443
14444 hash_iterate(community_hash(),
14445 (void (*)(struct hash_bucket *,
14446 void *))community_show_all_iterator,
14447 vty);
14448
14449 return CMD_SUCCESS;
14450 }
14451
14452 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14453 struct vty *vty)
14454 {
14455 struct lcommunity *lcom;
14456
14457 lcom = (struct lcommunity *)bucket->data;
14458 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14459 lcommunity_str(lcom, false));
14460 }
14461
14462 /* Show BGP's community internal data. */
14463 DEFUN (show_ip_bgp_lcommunity_info,
14464 show_ip_bgp_lcommunity_info_cmd,
14465 "show ip bgp large-community-info",
14466 SHOW_STR
14467 IP_STR
14468 BGP_STR
14469 "List all bgp large-community information\n")
14470 {
14471 vty_out(vty, "Address Refcnt Large-community\n");
14472
14473 hash_iterate(lcommunity_hash(),
14474 (void (*)(struct hash_bucket *,
14475 void *))lcommunity_show_all_iterator,
14476 vty);
14477
14478 return CMD_SUCCESS;
14479 }
14480 /* Graceful Restart */
14481
14482 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14483 struct bgp *bgp,
14484 bool use_json,
14485 json_object *json)
14486 {
14487
14488
14489 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14490
14491 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14492
14493 switch (bgp_global_gr_mode) {
14494
14495 case GLOBAL_HELPER:
14496 vty_out(vty, "Global BGP GR Mode : Helper\n");
14497 break;
14498
14499 case GLOBAL_GR:
14500 vty_out(vty, "Global BGP GR Mode : Restart\n");
14501 break;
14502
14503 case GLOBAL_DISABLE:
14504 vty_out(vty, "Global BGP GR Mode : Disable\n");
14505 break;
14506
14507 case GLOBAL_INVALID:
14508 vty_out(vty,
14509 "Global BGP GR Mode Invalid\n");
14510 break;
14511 }
14512 vty_out(vty, "\n");
14513 }
14514
14515 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14516 enum show_type type,
14517 const char *ip_str,
14518 afi_t afi, bool use_json)
14519 {
14520 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14521 afi = AFI_IP;
14522
14523 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14524
14525 bgp_show_neighbor_graceful_restart_vty(
14526 vty, type, ip_str, afi, use_json);
14527 afi++;
14528 }
14529 } else if (afi != AFI_MAX) {
14530 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14531 use_json);
14532 } else {
14533 return CMD_ERR_INCOMPLETE;
14534 }
14535
14536 return CMD_SUCCESS;
14537 }
14538 /* Graceful Restart */
14539
14540 DEFUN (show_ip_bgp_attr_info,
14541 show_ip_bgp_attr_info_cmd,
14542 "show [ip] bgp attribute-info",
14543 SHOW_STR
14544 IP_STR
14545 BGP_STR
14546 "List all bgp attribute information\n")
14547 {
14548 attr_show_all(vty);
14549 return CMD_SUCCESS;
14550 }
14551
14552 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14553 afi_t afi, safi_t safi,
14554 bool use_json, json_object *json)
14555 {
14556 struct bgp *bgp;
14557 struct listnode *node;
14558 char *vname;
14559 char buf1[INET6_ADDRSTRLEN];
14560 char *ecom_str;
14561 vpn_policy_direction_t dir;
14562
14563 if (json) {
14564 json_object *json_import_vrfs = NULL;
14565 json_object *json_export_vrfs = NULL;
14566
14567 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14568
14569 if (!bgp) {
14570 vty_json(vty, json);
14571
14572 return CMD_WARNING;
14573 }
14574
14575 /* Provide context for the block */
14576 json_object_string_add(json, "vrf", name ? name : "default");
14577 json_object_string_add(json, "afiSafi",
14578 get_afi_safi_str(afi, safi, true));
14579
14580 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14581 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14582 json_object_string_add(json, "importFromVrfs", "none");
14583 json_object_string_add(json, "importRts", "none");
14584 } else {
14585 json_import_vrfs = json_object_new_array();
14586
14587 for (ALL_LIST_ELEMENTS_RO(
14588 bgp->vpn_policy[afi].import_vrf,
14589 node, vname))
14590 json_object_array_add(json_import_vrfs,
14591 json_object_new_string(vname));
14592
14593 json_object_object_add(json, "importFromVrfs",
14594 json_import_vrfs);
14595 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14596 if (bgp->vpn_policy[afi].rtlist[dir]) {
14597 ecom_str = ecommunity_ecom2str(
14598 bgp->vpn_policy[afi].rtlist[dir],
14599 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14600 json_object_string_add(json, "importRts",
14601 ecom_str);
14602 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14603 } else
14604 json_object_string_add(json, "importRts",
14605 "none");
14606 }
14607
14608 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14609 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14610 json_object_string_add(json, "exportToVrfs", "none");
14611 json_object_string_add(json, "routeDistinguisher",
14612 "none");
14613 json_object_string_add(json, "exportRts", "none");
14614 } else {
14615 json_export_vrfs = json_object_new_array();
14616
14617 for (ALL_LIST_ELEMENTS_RO(
14618 bgp->vpn_policy[afi].export_vrf,
14619 node, vname))
14620 json_object_array_add(json_export_vrfs,
14621 json_object_new_string(vname));
14622 json_object_object_add(json, "exportToVrfs",
14623 json_export_vrfs);
14624 json_object_string_add(json, "routeDistinguisher",
14625 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14626 buf1, RD_ADDRSTRLEN));
14627
14628 dir = BGP_VPN_POLICY_DIR_TOVPN;
14629 if (bgp->vpn_policy[afi].rtlist[dir]) {
14630 ecom_str = ecommunity_ecom2str(
14631 bgp->vpn_policy[afi].rtlist[dir],
14632 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14633 json_object_string_add(json, "exportRts",
14634 ecom_str);
14635 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14636 } else
14637 json_object_string_add(json, "exportRts",
14638 "none");
14639 }
14640
14641 if (use_json) {
14642 vty_json(vty, json);
14643 }
14644 } else {
14645 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14646
14647 if (!bgp) {
14648 vty_out(vty, "%% No such BGP instance exist\n");
14649 return CMD_WARNING;
14650 }
14651
14652 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14653 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14654 vty_out(vty,
14655 "This VRF is not importing %s routes from any other VRF\n",
14656 get_afi_safi_str(afi, safi, false));
14657 else {
14658 vty_out(vty,
14659 "This VRF is importing %s routes from the following VRFs:\n",
14660 get_afi_safi_str(afi, safi, false));
14661
14662 for (ALL_LIST_ELEMENTS_RO(
14663 bgp->vpn_policy[afi].import_vrf,
14664 node, vname))
14665 vty_out(vty, " %s\n", vname);
14666
14667 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14668 ecom_str = NULL;
14669 if (bgp->vpn_policy[afi].rtlist[dir]) {
14670 ecom_str = ecommunity_ecom2str(
14671 bgp->vpn_policy[afi].rtlist[dir],
14672 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14673 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14674
14675 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14676 } else
14677 vty_out(vty, "Import RT(s):\n");
14678 }
14679
14680 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14681 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14682 vty_out(vty,
14683 "This VRF is not exporting %s routes to any other VRF\n",
14684 get_afi_safi_str(afi, safi, false));
14685 else {
14686 vty_out(vty,
14687 "This VRF is exporting %s routes to the following VRFs:\n",
14688 get_afi_safi_str(afi, safi, false));
14689
14690 for (ALL_LIST_ELEMENTS_RO(
14691 bgp->vpn_policy[afi].export_vrf,
14692 node, vname))
14693 vty_out(vty, " %s\n", vname);
14694
14695 vty_out(vty, "RD: %s\n",
14696 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14697 buf1, RD_ADDRSTRLEN));
14698
14699 dir = BGP_VPN_POLICY_DIR_TOVPN;
14700 if (bgp->vpn_policy[afi].rtlist[dir]) {
14701 ecom_str = ecommunity_ecom2str(
14702 bgp->vpn_policy[afi].rtlist[dir],
14703 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14704 vty_out(vty, "Export RT: %s\n", ecom_str);
14705 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14706 } else
14707 vty_out(vty, "Import RT(s):\n");
14708 }
14709 }
14710
14711 return CMD_SUCCESS;
14712 }
14713
14714 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14715 safi_t safi, bool use_json)
14716 {
14717 struct listnode *node, *nnode;
14718 struct bgp *bgp;
14719 char *vrf_name = NULL;
14720 json_object *json = NULL;
14721 json_object *json_vrf = NULL;
14722 json_object *json_vrfs = NULL;
14723
14724 if (use_json) {
14725 json = json_object_new_object();
14726 json_vrfs = json_object_new_object();
14727 }
14728
14729 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14730
14731 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14732 vrf_name = bgp->name;
14733
14734 if (use_json) {
14735 json_vrf = json_object_new_object();
14736 } else {
14737 vty_out(vty, "\nInstance %s:\n",
14738 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14739 ? VRF_DEFAULT_NAME : bgp->name);
14740 }
14741 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14742 if (use_json) {
14743 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14744 json_object_object_add(json_vrfs,
14745 VRF_DEFAULT_NAME, json_vrf);
14746 else
14747 json_object_object_add(json_vrfs, vrf_name,
14748 json_vrf);
14749 }
14750 }
14751
14752 if (use_json) {
14753 json_object_object_add(json, "vrfs", json_vrfs);
14754 vty_json(vty, json);
14755 }
14756
14757 return CMD_SUCCESS;
14758 }
14759
14760 /* "show [ip] bgp route-leak" command. */
14761 DEFUN (show_ip_bgp_route_leak,
14762 show_ip_bgp_route_leak_cmd,
14763 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
14764 SHOW_STR
14765 IP_STR
14766 BGP_STR
14767 BGP_INSTANCE_HELP_STR
14768 BGP_AFI_HELP_STR
14769 BGP_SAFI_HELP_STR
14770 "Route leaking information\n"
14771 JSON_STR)
14772 {
14773 char *vrf = NULL;
14774 afi_t afi = AFI_MAX;
14775 safi_t safi = SAFI_MAX;
14776
14777 bool uj = use_json(argc, argv);
14778 int idx = 0;
14779 json_object *json = NULL;
14780
14781 /* show [ip] bgp */
14782 if (argv_find(argv, argc, "ip", &idx)) {
14783 afi = AFI_IP;
14784 safi = SAFI_UNICAST;
14785 }
14786 /* [vrf VIEWVRFNAME] */
14787 if (argv_find(argv, argc, "view", &idx)) {
14788 vty_out(vty,
14789 "%% This command is not applicable to BGP views\n");
14790 return CMD_WARNING;
14791 }
14792
14793 if (argv_find(argv, argc, "vrf", &idx)) {
14794 vrf = argv[idx + 1]->arg;
14795 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14796 vrf = NULL;
14797 }
14798 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14799 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
14800 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14801
14802 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
14803 vty_out(vty,
14804 "%% This command is applicable only for unicast ipv4|ipv6\n");
14805 return CMD_WARNING;
14806 }
14807
14808 if (vrf && strmatch(vrf, "all"))
14809 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14810
14811 if (uj)
14812 json = json_object_new_object();
14813
14814 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
14815 }
14816
14817 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14818 safi_t safi)
14819 {
14820 struct listnode *node, *nnode;
14821 struct bgp *bgp;
14822
14823 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14824 vty_out(vty, "\nInstance %s:\n",
14825 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14826 ? VRF_DEFAULT_NAME
14827 : bgp->name);
14828 update_group_show(bgp, afi, safi, vty, 0);
14829 }
14830 }
14831
14832 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14833 int safi, uint64_t subgrp_id)
14834 {
14835 struct bgp *bgp;
14836
14837 if (name) {
14838 if (strmatch(name, "all")) {
14839 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14840 return CMD_SUCCESS;
14841 } else {
14842 bgp = bgp_lookup_by_name(name);
14843 }
14844 } else {
14845 bgp = bgp_get_default();
14846 }
14847
14848 if (bgp)
14849 update_group_show(bgp, afi, safi, vty, subgrp_id);
14850 return CMD_SUCCESS;
14851 }
14852
14853 DEFUN (show_ip_bgp_updgrps,
14854 show_ip_bgp_updgrps_cmd,
14855 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
14856 SHOW_STR
14857 IP_STR
14858 BGP_STR
14859 BGP_INSTANCE_HELP_STR
14860 BGP_AFI_HELP_STR
14861 BGP_SAFI_WITH_LABEL_HELP_STR
14862 "Detailed info about dynamic update groups\n"
14863 "Specific subgroup to display detailed info for\n")
14864 {
14865 char *vrf = NULL;
14866 afi_t afi = AFI_IP6;
14867 safi_t safi = SAFI_UNICAST;
14868 uint64_t subgrp_id = 0;
14869
14870 int idx = 0;
14871
14872 /* show [ip] bgp */
14873 if (argv_find(argv, argc, "ip", &idx))
14874 afi = AFI_IP;
14875 /* [<vrf> VIEWVRFNAME] */
14876 if (argv_find(argv, argc, "vrf", &idx)) {
14877 vrf = argv[idx + 1]->arg;
14878 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14879 vrf = NULL;
14880 } else if (argv_find(argv, argc, "view", &idx))
14881 /* [<view> VIEWVRFNAME] */
14882 vrf = argv[idx + 1]->arg;
14883 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14884 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14885 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14886 }
14887
14888 /* get subgroup id, if provided */
14889 idx = argc - 1;
14890 if (argv[idx]->type == VARIABLE_TKN)
14891 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
14892
14893 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
14894 }
14895
14896 DEFUN (show_bgp_instance_all_ipv6_updgrps,
14897 show_bgp_instance_all_ipv6_updgrps_cmd,
14898 "show [ip] bgp <view|vrf> all update-groups",
14899 SHOW_STR
14900 IP_STR
14901 BGP_STR
14902 BGP_INSTANCE_ALL_HELP_STR
14903 "Detailed info about dynamic update groups\n")
14904 {
14905 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14906 return CMD_SUCCESS;
14907 }
14908
14909 DEFUN (show_bgp_l2vpn_evpn_updgrps,
14910 show_bgp_l2vpn_evpn_updgrps_cmd,
14911 "show [ip] bgp l2vpn evpn update-groups",
14912 SHOW_STR
14913 IP_STR
14914 BGP_STR
14915 "l2vpn address family\n"
14916 "evpn sub-address family\n"
14917 "Detailed info about dynamic update groups\n")
14918 {
14919 char *vrf = NULL;
14920 uint64_t subgrp_id = 0;
14921
14922 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14923 return CMD_SUCCESS;
14924 }
14925
14926 DEFUN (show_bgp_updgrps_stats,
14927 show_bgp_updgrps_stats_cmd,
14928 "show [ip] bgp update-groups statistics",
14929 SHOW_STR
14930 IP_STR
14931 BGP_STR
14932 "Detailed info about dynamic update groups\n"
14933 "Statistics\n")
14934 {
14935 struct bgp *bgp;
14936
14937 bgp = bgp_get_default();
14938 if (bgp)
14939 update_group_show_stats(bgp, vty);
14940
14941 return CMD_SUCCESS;
14942 }
14943
14944 DEFUN (show_bgp_instance_updgrps_stats,
14945 show_bgp_instance_updgrps_stats_cmd,
14946 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
14947 SHOW_STR
14948 IP_STR
14949 BGP_STR
14950 BGP_INSTANCE_HELP_STR
14951 "Detailed info about dynamic update groups\n"
14952 "Statistics\n")
14953 {
14954 int idx_word = 3;
14955 struct bgp *bgp;
14956
14957 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14958 if (bgp)
14959 update_group_show_stats(bgp, vty);
14960
14961 return CMD_SUCCESS;
14962 }
14963
14964 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14965 afi_t afi, safi_t safi,
14966 const char *what, uint64_t subgrp_id)
14967 {
14968 struct bgp *bgp;
14969
14970 if (name)
14971 bgp = bgp_lookup_by_name(name);
14972 else
14973 bgp = bgp_get_default();
14974
14975 if (bgp) {
14976 if (!strcmp(what, "advertise-queue"))
14977 update_group_show_adj_queue(bgp, afi, safi, vty,
14978 subgrp_id);
14979 else if (!strcmp(what, "advertised-routes"))
14980 update_group_show_advertised(bgp, afi, safi, vty,
14981 subgrp_id);
14982 else if (!strcmp(what, "packet-queue"))
14983 update_group_show_packet_queue(bgp, afi, safi, vty,
14984 subgrp_id);
14985 }
14986 }
14987
14988 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14989 show_ip_bgp_instance_updgrps_adj_s_cmd,
14990 "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",
14991 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14992 BGP_SAFI_HELP_STR
14993 "Detailed info about dynamic update groups\n"
14994 "Specific subgroup to display info for\n"
14995 "Advertisement queue\n"
14996 "Announced routes\n"
14997 "Packet queue\n")
14998 {
14999 uint64_t subgrp_id = 0;
15000 afi_t afiz;
15001 safi_t safiz;
15002 if (sgid)
15003 subgrp_id = strtoull(sgid, NULL, 10);
15004
15005 if (!ip && !afi)
15006 afiz = AFI_IP6;
15007 if (!ip && afi)
15008 afiz = bgp_vty_afi_from_str(afi);
15009 if (ip && !afi)
15010 afiz = AFI_IP;
15011 if (ip && afi) {
15012 afiz = bgp_vty_afi_from_str(afi);
15013 if (afiz != AFI_IP)
15014 vty_out(vty,
15015 "%% Cannot specify both 'ip' and 'ipv6'\n");
15016 return CMD_WARNING;
15017 }
15018
15019 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15020
15021 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15022 return CMD_SUCCESS;
15023 }
15024
15025 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15026 json_object *json)
15027 {
15028 struct listnode *node, *nnode;
15029 struct prefix *range;
15030 struct peer *conf;
15031 struct peer *peer;
15032 afi_t afi;
15033 safi_t safi;
15034 const char *peer_status;
15035 int lr_count;
15036 int dynamic;
15037 bool af_cfgd;
15038 json_object *json_peer_group = NULL;
15039 json_object *json_peer_group_afc = NULL;
15040 json_object *json_peer_group_members = NULL;
15041 json_object *json_peer_group_dynamic = NULL;
15042 json_object *json_peer_group_dynamic_af = NULL;
15043 json_object *json_peer_group_ranges = NULL;
15044
15045 conf = group->conf;
15046
15047 if (json) {
15048 json_peer_group = json_object_new_object();
15049 json_peer_group_afc = json_object_new_array();
15050 }
15051
15052 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15053 if (json)
15054 json_object_int_add(json_peer_group, "remoteAs",
15055 conf->as);
15056 else
15057 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15058 group->name, conf->as);
15059 } else if (conf->as_type == AS_INTERNAL) {
15060 if (json)
15061 json_object_int_add(json_peer_group, "remoteAs",
15062 group->bgp->as);
15063 else
15064 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15065 group->name, group->bgp->as);
15066 } else {
15067 if (!json)
15068 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15069 }
15070
15071 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15072 if (json)
15073 json_object_string_add(json_peer_group, "type",
15074 "internal");
15075 else
15076 vty_out(vty, " Peer-group type is internal\n");
15077 } else {
15078 if (json)
15079 json_object_string_add(json_peer_group, "type",
15080 "external");
15081 else
15082 vty_out(vty, " Peer-group type is external\n");
15083 }
15084
15085 /* Display AFs configured. */
15086 if (!json)
15087 vty_out(vty, " Configured address-families:");
15088
15089 FOREACH_AFI_SAFI (afi, safi) {
15090 if (conf->afc[afi][safi]) {
15091 af_cfgd = true;
15092 if (json)
15093 json_object_array_add(
15094 json_peer_group_afc,
15095 json_object_new_string(get_afi_safi_str(
15096 afi, safi, false)));
15097 else
15098 vty_out(vty, " %s;",
15099 get_afi_safi_str(afi, safi, false));
15100 }
15101 }
15102
15103 if (json) {
15104 json_object_object_add(json_peer_group,
15105 "addressFamiliesConfigured",
15106 json_peer_group_afc);
15107 } else {
15108 if (!af_cfgd)
15109 vty_out(vty, " none\n");
15110 else
15111 vty_out(vty, "\n");
15112 }
15113
15114 /* Display listen ranges (for dynamic neighbors), if any */
15115 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15116 lr_count = listcount(group->listen_range[afi]);
15117 if (lr_count) {
15118 if (json) {
15119 if (!json_peer_group_dynamic)
15120 json_peer_group_dynamic =
15121 json_object_new_object();
15122
15123 json_peer_group_dynamic_af =
15124 json_object_new_object();
15125 json_peer_group_ranges =
15126 json_object_new_array();
15127 json_object_int_add(json_peer_group_dynamic_af,
15128 "count", lr_count);
15129 } else {
15130 vty_out(vty, " %d %s listen range(s)\n",
15131 lr_count, afi2str(afi));
15132 }
15133
15134 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15135 nnode, range)) {
15136 if (json) {
15137 char buf[BUFSIZ];
15138
15139 snprintfrr(buf, sizeof(buf), "%pFX",
15140 range);
15141
15142 json_object_array_add(
15143 json_peer_group_ranges,
15144 json_object_new_string(buf));
15145 } else {
15146 vty_out(vty, " %pFX\n", range);
15147 }
15148 }
15149
15150 if (json) {
15151 json_object_object_add(
15152 json_peer_group_dynamic_af, "ranges",
15153 json_peer_group_ranges);
15154
15155 json_object_object_add(
15156 json_peer_group_dynamic, afi2str(afi),
15157 json_peer_group_dynamic_af);
15158 }
15159 }
15160 }
15161
15162 if (json_peer_group_dynamic)
15163 json_object_object_add(json_peer_group, "dynamicRanges",
15164 json_peer_group_dynamic);
15165
15166 /* Display group members and their status */
15167 if (listcount(group->peer)) {
15168 if (json)
15169 json_peer_group_members = json_object_new_object();
15170 else
15171 vty_out(vty, " Peer-group members:\n");
15172 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15173 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15174 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15175 peer_status = "Idle (Admin)";
15176 else if (CHECK_FLAG(peer->sflags,
15177 PEER_STATUS_PREFIX_OVERFLOW))
15178 peer_status = "Idle (PfxCt)";
15179 else
15180 peer_status = lookup_msg(bgp_status_msg,
15181 peer->status, NULL);
15182
15183 dynamic = peer_dynamic_neighbor(peer);
15184
15185 if (json) {
15186 json_object *json_peer_group_member =
15187 json_object_new_object();
15188
15189 json_object_string_add(json_peer_group_member,
15190 "status", peer_status);
15191
15192 if (dynamic)
15193 json_object_boolean_true_add(
15194 json_peer_group_member,
15195 "dynamic");
15196
15197 json_object_object_add(json_peer_group_members,
15198 peer->host,
15199 json_peer_group_member);
15200 } else {
15201 vty_out(vty, " %s %s %s \n", peer->host,
15202 dynamic ? "(dynamic)" : "",
15203 peer_status);
15204 }
15205 }
15206 if (json)
15207 json_object_object_add(json_peer_group, "members",
15208 json_peer_group_members);
15209 }
15210
15211 if (json)
15212 json_object_object_add(json, group->name, json_peer_group);
15213
15214 return CMD_SUCCESS;
15215 }
15216
15217 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15218 const char *group_name, bool uj)
15219 {
15220 struct bgp *bgp;
15221 struct listnode *node, *nnode;
15222 struct peer_group *group;
15223 bool found = false;
15224 json_object *json = NULL;
15225
15226 if (uj)
15227 json = json_object_new_object();
15228
15229 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15230
15231 if (!bgp) {
15232 if (uj)
15233 vty_json(vty, json);
15234 else
15235 vty_out(vty, "%% BGP instance not found\n");
15236
15237 return CMD_WARNING;
15238 }
15239
15240 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15241 if (group_name) {
15242 if (strmatch(group->name, group_name)) {
15243 bgp_show_one_peer_group(vty, group, json);
15244 found = true;
15245 break;
15246 }
15247 } else {
15248 bgp_show_one_peer_group(vty, group, json);
15249 }
15250 }
15251
15252 if (group_name && !found && !uj)
15253 vty_out(vty, "%% No such peer-group\n");
15254
15255 if (uj)
15256 vty_json(vty, json);
15257
15258 return CMD_SUCCESS;
15259 }
15260
15261 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15262 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15263 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15264 "Detailed information on BGP peer groups\n"
15265 "Peer group name\n" JSON_STR)
15266 {
15267 char *vrf, *pg;
15268 int idx = 0;
15269 bool uj = use_json(argc, argv);
15270
15271 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15272 : NULL;
15273 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15274
15275 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15276 }
15277
15278
15279 /* Redistribute VTY commands. */
15280
15281 DEFUN (bgp_redistribute_ipv4,
15282 bgp_redistribute_ipv4_cmd,
15283 "redistribute " FRR_IP_REDIST_STR_BGPD,
15284 "Redistribute information from another routing protocol\n"
15285 FRR_IP_REDIST_HELP_STR_BGPD)
15286 {
15287 VTY_DECLVAR_CONTEXT(bgp, bgp);
15288 int idx_protocol = 1;
15289 int type;
15290
15291 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15292 if (type < 0) {
15293 vty_out(vty, "%% Invalid route type\n");
15294 return CMD_WARNING_CONFIG_FAILED;
15295 }
15296
15297 bgp_redist_add(bgp, AFI_IP, type, 0);
15298 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15299 }
15300
15301 ALIAS_HIDDEN(
15302 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15303 "redistribute " FRR_IP_REDIST_STR_BGPD,
15304 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15305
15306 DEFUN (bgp_redistribute_ipv4_rmap,
15307 bgp_redistribute_ipv4_rmap_cmd,
15308 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15309 "Redistribute information from another routing protocol\n"
15310 FRR_IP_REDIST_HELP_STR_BGPD
15311 "Route map reference\n"
15312 "Pointer to route-map entries\n")
15313 {
15314 VTY_DECLVAR_CONTEXT(bgp, bgp);
15315 int idx_protocol = 1;
15316 int idx_word = 3;
15317 int type;
15318 struct bgp_redist *red;
15319 bool changed;
15320 struct route_map *route_map = route_map_lookup_warn_noexist(
15321 vty, argv[idx_word]->arg);
15322
15323 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15324 if (type < 0) {
15325 vty_out(vty, "%% Invalid route type\n");
15326 return CMD_WARNING_CONFIG_FAILED;
15327 }
15328
15329 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15330 changed =
15331 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15332 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15333 }
15334
15335 ALIAS_HIDDEN(
15336 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15337 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15338 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15339 "Route map reference\n"
15340 "Pointer to route-map entries\n")
15341
15342 DEFUN (bgp_redistribute_ipv4_metric,
15343 bgp_redistribute_ipv4_metric_cmd,
15344 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15345 "Redistribute information from another routing protocol\n"
15346 FRR_IP_REDIST_HELP_STR_BGPD
15347 "Metric for redistributed routes\n"
15348 "Default metric\n")
15349 {
15350 VTY_DECLVAR_CONTEXT(bgp, bgp);
15351 int idx_protocol = 1;
15352 int idx_number = 3;
15353 int type;
15354 uint32_t metric;
15355 struct bgp_redist *red;
15356 bool changed;
15357
15358 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15359 if (type < 0) {
15360 vty_out(vty, "%% Invalid route type\n");
15361 return CMD_WARNING_CONFIG_FAILED;
15362 }
15363 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15364
15365 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15366 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15367 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15368 }
15369
15370 ALIAS_HIDDEN(
15371 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15372 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15373 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15374 "Metric for redistributed routes\n"
15375 "Default metric\n")
15376
15377 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15378 bgp_redistribute_ipv4_rmap_metric_cmd,
15379 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15380 "Redistribute information from another routing protocol\n"
15381 FRR_IP_REDIST_HELP_STR_BGPD
15382 "Route map reference\n"
15383 "Pointer to route-map entries\n"
15384 "Metric for redistributed routes\n"
15385 "Default metric\n")
15386 {
15387 VTY_DECLVAR_CONTEXT(bgp, bgp);
15388 int idx_protocol = 1;
15389 int idx_word = 3;
15390 int idx_number = 5;
15391 int type;
15392 uint32_t metric;
15393 struct bgp_redist *red;
15394 bool changed;
15395 struct route_map *route_map =
15396 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15397
15398 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15399 if (type < 0) {
15400 vty_out(vty, "%% Invalid route type\n");
15401 return CMD_WARNING_CONFIG_FAILED;
15402 }
15403 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15404
15405 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15406 changed =
15407 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15408 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15409 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15410 }
15411
15412 ALIAS_HIDDEN(
15413 bgp_redistribute_ipv4_rmap_metric,
15414 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15415 "redistribute " FRR_IP_REDIST_STR_BGPD
15416 " route-map WORD metric (0-4294967295)",
15417 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15418 "Route map reference\n"
15419 "Pointer to route-map entries\n"
15420 "Metric for redistributed routes\n"
15421 "Default metric\n")
15422
15423 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15424 bgp_redistribute_ipv4_metric_rmap_cmd,
15425 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15426 "Redistribute information from another routing protocol\n"
15427 FRR_IP_REDIST_HELP_STR_BGPD
15428 "Metric for redistributed routes\n"
15429 "Default metric\n"
15430 "Route map reference\n"
15431 "Pointer to route-map entries\n")
15432 {
15433 VTY_DECLVAR_CONTEXT(bgp, bgp);
15434 int idx_protocol = 1;
15435 int idx_number = 3;
15436 int idx_word = 5;
15437 int type;
15438 uint32_t metric;
15439 struct bgp_redist *red;
15440 bool changed;
15441 struct route_map *route_map =
15442 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15443
15444 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15445 if (type < 0) {
15446 vty_out(vty, "%% Invalid route type\n");
15447 return CMD_WARNING_CONFIG_FAILED;
15448 }
15449 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15450
15451 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15452 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15453 changed |=
15454 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15455 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15456 }
15457
15458 ALIAS_HIDDEN(
15459 bgp_redistribute_ipv4_metric_rmap,
15460 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15461 "redistribute " FRR_IP_REDIST_STR_BGPD
15462 " metric (0-4294967295) route-map WORD",
15463 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15464 "Metric for redistributed routes\n"
15465 "Default metric\n"
15466 "Route map reference\n"
15467 "Pointer to route-map entries\n")
15468
15469 DEFUN (bgp_redistribute_ipv4_ospf,
15470 bgp_redistribute_ipv4_ospf_cmd,
15471 "redistribute <ospf|table> (1-65535)",
15472 "Redistribute information from another routing protocol\n"
15473 "Open Shortest Path First (OSPFv2)\n"
15474 "Non-main Kernel Routing Table\n"
15475 "Instance ID/Table ID\n")
15476 {
15477 VTY_DECLVAR_CONTEXT(bgp, bgp);
15478 int idx_ospf_table = 1;
15479 int idx_number = 2;
15480 unsigned short instance;
15481 unsigned short protocol;
15482
15483 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15484
15485 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15486 protocol = ZEBRA_ROUTE_OSPF;
15487 else
15488 protocol = ZEBRA_ROUTE_TABLE;
15489
15490 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15491 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15492 }
15493
15494 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15495 "redistribute <ospf|table> (1-65535)",
15496 "Redistribute information from another routing protocol\n"
15497 "Open Shortest Path First (OSPFv2)\n"
15498 "Non-main Kernel Routing Table\n"
15499 "Instance ID/Table ID\n")
15500
15501 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15502 bgp_redistribute_ipv4_ospf_rmap_cmd,
15503 "redistribute <ospf|table> (1-65535) route-map WORD",
15504 "Redistribute information from another routing protocol\n"
15505 "Open Shortest Path First (OSPFv2)\n"
15506 "Non-main Kernel Routing Table\n"
15507 "Instance ID/Table ID\n"
15508 "Route map reference\n"
15509 "Pointer to route-map entries\n")
15510 {
15511 VTY_DECLVAR_CONTEXT(bgp, bgp);
15512 int idx_ospf_table = 1;
15513 int idx_number = 2;
15514 int idx_word = 4;
15515 struct bgp_redist *red;
15516 unsigned short instance;
15517 int protocol;
15518 bool changed;
15519 struct route_map *route_map =
15520 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15521
15522 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15523 protocol = ZEBRA_ROUTE_OSPF;
15524 else
15525 protocol = ZEBRA_ROUTE_TABLE;
15526
15527 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15528 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15529 changed =
15530 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15531 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15532 }
15533
15534 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15535 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15536 "redistribute <ospf|table> (1-65535) route-map WORD",
15537 "Redistribute information from another routing protocol\n"
15538 "Open Shortest Path First (OSPFv2)\n"
15539 "Non-main Kernel Routing Table\n"
15540 "Instance ID/Table ID\n"
15541 "Route map reference\n"
15542 "Pointer to route-map entries\n")
15543
15544 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15545 bgp_redistribute_ipv4_ospf_metric_cmd,
15546 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15547 "Redistribute information from another routing protocol\n"
15548 "Open Shortest Path First (OSPFv2)\n"
15549 "Non-main Kernel Routing Table\n"
15550 "Instance ID/Table ID\n"
15551 "Metric for redistributed routes\n"
15552 "Default metric\n")
15553 {
15554 VTY_DECLVAR_CONTEXT(bgp, bgp);
15555 int idx_ospf_table = 1;
15556 int idx_number = 2;
15557 int idx_number_2 = 4;
15558 uint32_t metric;
15559 struct bgp_redist *red;
15560 unsigned short instance;
15561 int protocol;
15562 bool changed;
15563
15564 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15565 protocol = ZEBRA_ROUTE_OSPF;
15566 else
15567 protocol = ZEBRA_ROUTE_TABLE;
15568
15569 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15570 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15571
15572 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15573 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15574 metric);
15575 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15576 }
15577
15578 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15579 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15580 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15581 "Redistribute information from another routing protocol\n"
15582 "Open Shortest Path First (OSPFv2)\n"
15583 "Non-main Kernel Routing Table\n"
15584 "Instance ID/Table ID\n"
15585 "Metric for redistributed routes\n"
15586 "Default metric\n")
15587
15588 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15589 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15590 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15591 "Redistribute information from another routing protocol\n"
15592 "Open Shortest Path First (OSPFv2)\n"
15593 "Non-main Kernel Routing Table\n"
15594 "Instance ID/Table ID\n"
15595 "Route map reference\n"
15596 "Pointer to route-map entries\n"
15597 "Metric for redistributed routes\n"
15598 "Default metric\n")
15599 {
15600 VTY_DECLVAR_CONTEXT(bgp, bgp);
15601 int idx_ospf_table = 1;
15602 int idx_number = 2;
15603 int idx_word = 4;
15604 int idx_number_2 = 6;
15605 uint32_t metric;
15606 struct bgp_redist *red;
15607 unsigned short instance;
15608 int protocol;
15609 bool changed;
15610 struct route_map *route_map =
15611 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15612
15613 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15614 protocol = ZEBRA_ROUTE_OSPF;
15615 else
15616 protocol = ZEBRA_ROUTE_TABLE;
15617
15618 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15619 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15620
15621 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15622 changed =
15623 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15624 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15625 metric);
15626 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15627 }
15628
15629 ALIAS_HIDDEN(
15630 bgp_redistribute_ipv4_ospf_rmap_metric,
15631 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15632 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15633 "Redistribute information from another routing protocol\n"
15634 "Open Shortest Path First (OSPFv2)\n"
15635 "Non-main Kernel Routing Table\n"
15636 "Instance ID/Table ID\n"
15637 "Route map reference\n"
15638 "Pointer to route-map entries\n"
15639 "Metric for redistributed routes\n"
15640 "Default metric\n")
15641
15642 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15643 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15644 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15645 "Redistribute information from another routing protocol\n"
15646 "Open Shortest Path First (OSPFv2)\n"
15647 "Non-main Kernel Routing Table\n"
15648 "Instance ID/Table ID\n"
15649 "Metric for redistributed routes\n"
15650 "Default metric\n"
15651 "Route map reference\n"
15652 "Pointer to route-map entries\n")
15653 {
15654 VTY_DECLVAR_CONTEXT(bgp, bgp);
15655 int idx_ospf_table = 1;
15656 int idx_number = 2;
15657 int idx_number_2 = 4;
15658 int idx_word = 6;
15659 uint32_t metric;
15660 struct bgp_redist *red;
15661 unsigned short instance;
15662 int protocol;
15663 bool changed;
15664 struct route_map *route_map =
15665 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15666
15667 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15668 protocol = ZEBRA_ROUTE_OSPF;
15669 else
15670 protocol = ZEBRA_ROUTE_TABLE;
15671
15672 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15673 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15674
15675 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15676 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15677 metric);
15678 changed |=
15679 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15680 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15681 }
15682
15683 ALIAS_HIDDEN(
15684 bgp_redistribute_ipv4_ospf_metric_rmap,
15685 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15686 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15687 "Redistribute information from another routing protocol\n"
15688 "Open Shortest Path First (OSPFv2)\n"
15689 "Non-main Kernel Routing Table\n"
15690 "Instance ID/Table ID\n"
15691 "Metric for redistributed routes\n"
15692 "Default metric\n"
15693 "Route map reference\n"
15694 "Pointer to route-map entries\n")
15695
15696 DEFUN (no_bgp_redistribute_ipv4_ospf,
15697 no_bgp_redistribute_ipv4_ospf_cmd,
15698 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15699 NO_STR
15700 "Redistribute information from another routing protocol\n"
15701 "Open Shortest Path First (OSPFv2)\n"
15702 "Non-main Kernel Routing Table\n"
15703 "Instance ID/Table ID\n"
15704 "Metric for redistributed routes\n"
15705 "Default metric\n"
15706 "Route map reference\n"
15707 "Pointer to route-map entries\n")
15708 {
15709 VTY_DECLVAR_CONTEXT(bgp, bgp);
15710 int idx_ospf_table = 2;
15711 int idx_number = 3;
15712 unsigned short instance;
15713 int protocol;
15714
15715 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15716 protocol = ZEBRA_ROUTE_OSPF;
15717 else
15718 protocol = ZEBRA_ROUTE_TABLE;
15719
15720 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15721 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
15722 }
15723
15724 ALIAS_HIDDEN(
15725 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15726 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15727 NO_STR
15728 "Redistribute information from another routing protocol\n"
15729 "Open Shortest Path First (OSPFv2)\n"
15730 "Non-main Kernel Routing Table\n"
15731 "Instance ID/Table ID\n"
15732 "Metric for redistributed routes\n"
15733 "Default metric\n"
15734 "Route map reference\n"
15735 "Pointer to route-map entries\n")
15736
15737 DEFUN (no_bgp_redistribute_ipv4,
15738 no_bgp_redistribute_ipv4_cmd,
15739 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15740 NO_STR
15741 "Redistribute information from another routing protocol\n"
15742 FRR_IP_REDIST_HELP_STR_BGPD
15743 "Metric for redistributed routes\n"
15744 "Default metric\n"
15745 "Route map reference\n"
15746 "Pointer to route-map entries\n")
15747 {
15748 VTY_DECLVAR_CONTEXT(bgp, bgp);
15749 int idx_protocol = 2;
15750 int type;
15751
15752 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15753 if (type < 0) {
15754 vty_out(vty, "%% Invalid route type\n");
15755 return CMD_WARNING_CONFIG_FAILED;
15756 }
15757 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
15758 }
15759
15760 ALIAS_HIDDEN(
15761 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15762 "no redistribute " FRR_IP_REDIST_STR_BGPD
15763 " [{metric (0-4294967295)|route-map WORD}]",
15764 NO_STR
15765 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15766 "Metric for redistributed routes\n"
15767 "Default metric\n"
15768 "Route map reference\n"
15769 "Pointer to route-map entries\n")
15770
15771 DEFUN (bgp_redistribute_ipv6,
15772 bgp_redistribute_ipv6_cmd,
15773 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15774 "Redistribute information from another routing protocol\n"
15775 FRR_IP6_REDIST_HELP_STR_BGPD)
15776 {
15777 VTY_DECLVAR_CONTEXT(bgp, bgp);
15778 int idx_protocol = 1;
15779 int type;
15780
15781 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15782 if (type < 0) {
15783 vty_out(vty, "%% Invalid route type\n");
15784 return CMD_WARNING_CONFIG_FAILED;
15785 }
15786
15787 bgp_redist_add(bgp, AFI_IP6, type, 0);
15788 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
15789 }
15790
15791 DEFUN (bgp_redistribute_ipv6_rmap,
15792 bgp_redistribute_ipv6_rmap_cmd,
15793 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15794 "Redistribute information from another routing protocol\n"
15795 FRR_IP6_REDIST_HELP_STR_BGPD
15796 "Route map reference\n"
15797 "Pointer to route-map entries\n")
15798 {
15799 VTY_DECLVAR_CONTEXT(bgp, bgp);
15800 int idx_protocol = 1;
15801 int idx_word = 3;
15802 int type;
15803 struct bgp_redist *red;
15804 bool changed;
15805 struct route_map *route_map =
15806 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15807
15808 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15809 if (type < 0) {
15810 vty_out(vty, "%% Invalid route type\n");
15811 return CMD_WARNING_CONFIG_FAILED;
15812 }
15813
15814 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15815 changed =
15816 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15817 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15818 }
15819
15820 DEFUN (bgp_redistribute_ipv6_metric,
15821 bgp_redistribute_ipv6_metric_cmd,
15822 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
15823 "Redistribute information from another routing protocol\n"
15824 FRR_IP6_REDIST_HELP_STR_BGPD
15825 "Metric for redistributed routes\n"
15826 "Default metric\n")
15827 {
15828 VTY_DECLVAR_CONTEXT(bgp, bgp);
15829 int idx_protocol = 1;
15830 int idx_number = 3;
15831 int type;
15832 uint32_t metric;
15833 struct bgp_redist *red;
15834 bool changed;
15835
15836 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15837 if (type < 0) {
15838 vty_out(vty, "%% Invalid route type\n");
15839 return CMD_WARNING_CONFIG_FAILED;
15840 }
15841 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15842
15843 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15844 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15845 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15846 }
15847
15848 DEFUN (bgp_redistribute_ipv6_rmap_metric,
15849 bgp_redistribute_ipv6_rmap_metric_cmd,
15850 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15851 "Redistribute information from another routing protocol\n"
15852 FRR_IP6_REDIST_HELP_STR_BGPD
15853 "Route map reference\n"
15854 "Pointer to route-map entries\n"
15855 "Metric for redistributed routes\n"
15856 "Default metric\n")
15857 {
15858 VTY_DECLVAR_CONTEXT(bgp, bgp);
15859 int idx_protocol = 1;
15860 int idx_word = 3;
15861 int idx_number = 5;
15862 int type;
15863 uint32_t metric;
15864 struct bgp_redist *red;
15865 bool changed;
15866 struct route_map *route_map =
15867 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15868
15869 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15870 if (type < 0) {
15871 vty_out(vty, "%% Invalid route type\n");
15872 return CMD_WARNING_CONFIG_FAILED;
15873 }
15874 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15875
15876 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15877 changed =
15878 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15879 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15880 metric);
15881 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15882 }
15883
15884 DEFUN (bgp_redistribute_ipv6_metric_rmap,
15885 bgp_redistribute_ipv6_metric_rmap_cmd,
15886 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15887 "Redistribute information from another routing protocol\n"
15888 FRR_IP6_REDIST_HELP_STR_BGPD
15889 "Metric for redistributed routes\n"
15890 "Default metric\n"
15891 "Route map reference\n"
15892 "Pointer to route-map entries\n")
15893 {
15894 VTY_DECLVAR_CONTEXT(bgp, bgp);
15895 int idx_protocol = 1;
15896 int idx_number = 3;
15897 int idx_word = 5;
15898 int type;
15899 uint32_t metric;
15900 struct bgp_redist *red;
15901 bool changed;
15902 struct route_map *route_map =
15903 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15904
15905 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15906 if (type < 0) {
15907 vty_out(vty, "%% Invalid route type\n");
15908 return CMD_WARNING_CONFIG_FAILED;
15909 }
15910 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15911
15912 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15913 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15914 metric);
15915 changed |=
15916 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15917 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
15918 }
15919
15920 DEFUN (no_bgp_redistribute_ipv6,
15921 no_bgp_redistribute_ipv6_cmd,
15922 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15923 NO_STR
15924 "Redistribute information from another routing protocol\n"
15925 FRR_IP6_REDIST_HELP_STR_BGPD
15926 "Metric for redistributed routes\n"
15927 "Default metric\n"
15928 "Route map reference\n"
15929 "Pointer to route-map entries\n")
15930 {
15931 VTY_DECLVAR_CONTEXT(bgp, bgp);
15932 int idx_protocol = 2;
15933 int type;
15934
15935 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15936 if (type < 0) {
15937 vty_out(vty, "%% Invalid route type\n");
15938 return CMD_WARNING_CONFIG_FAILED;
15939 }
15940
15941 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
15942 }
15943
15944 /* Neighbor update tcp-mss. */
15945 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15946 const char *tcp_mss_str)
15947 {
15948 struct peer *peer;
15949 uint32_t tcp_mss_val = 0;
15950
15951 peer = peer_and_group_lookup_vty(vty, peer_str);
15952 if (!peer)
15953 return CMD_WARNING_CONFIG_FAILED;
15954
15955 if (tcp_mss_str) {
15956 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15957 peer_tcp_mss_set(peer, tcp_mss_val);
15958 } else {
15959 peer_tcp_mss_unset(peer);
15960 }
15961
15962 return CMD_SUCCESS;
15963 }
15964
15965 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15966 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15968 "TCP max segment size\n"
15969 "TCP MSS value\n")
15970 {
15971 int peer_index = 1;
15972 int mss_index = 3;
15973
15974 vty_out(vty,
15975 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15976 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
15977 argv[mss_index]->arg);
15978 }
15979
15980 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
15981 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
15982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15983 "TCP max segment size\n"
15984 "TCP MSS value\n")
15985 {
15986 int peer_index = 2;
15987
15988 vty_out(vty,
15989 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15990 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
15991 }
15992
15993 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15994 afi_t afi, safi_t safi)
15995 {
15996 int i;
15997
15998 /* Unicast redistribution only. */
15999 if (safi != SAFI_UNICAST)
16000 return;
16001
16002 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16003 /* Redistribute BGP does not make sense. */
16004 if (i != ZEBRA_ROUTE_BGP) {
16005 struct list *red_list;
16006 struct listnode *node;
16007 struct bgp_redist *red;
16008
16009 red_list = bgp->redist[afi][i];
16010 if (!red_list)
16011 continue;
16012
16013 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16014 /* "redistribute" configuration. */
16015 vty_out(vty, " redistribute %s",
16016 zebra_route_string(i));
16017 if (red->instance)
16018 vty_out(vty, " %d", red->instance);
16019 if (red->redist_metric_flag)
16020 vty_out(vty, " metric %u",
16021 red->redist_metric);
16022 if (red->rmap.name)
16023 vty_out(vty, " route-map %s",
16024 red->rmap.name);
16025 vty_out(vty, "\n");
16026 }
16027 }
16028 }
16029 }
16030
16031 /* peer-group helpers for config-write */
16032
16033 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16034 {
16035 if (!peer_group_active(peer)) {
16036 if (CHECK_FLAG(peer->flags_invert, flag))
16037 return !CHECK_FLAG(peer->flags, flag);
16038 else
16039 return !!CHECK_FLAG(peer->flags, flag);
16040 }
16041
16042 return !!CHECK_FLAG(peer->flags_override, flag);
16043 }
16044
16045 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16046 uint32_t flag)
16047 {
16048 if (!peer_group_active(peer)) {
16049 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16050 return !peer_af_flag_check(peer, afi, safi, flag);
16051 else
16052 return !!peer_af_flag_check(peer, afi, safi, flag);
16053 }
16054
16055 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16056 }
16057
16058 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16059 uint8_t type, int direct)
16060 {
16061 struct bgp_filter *filter;
16062
16063 if (peer_group_active(peer))
16064 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16065 type);
16066
16067 filter = &peer->filter[afi][safi];
16068 switch (type) {
16069 case PEER_FT_DISTRIBUTE_LIST:
16070 return !!(filter->dlist[direct].name);
16071 case PEER_FT_FILTER_LIST:
16072 return !!(filter->aslist[direct].name);
16073 case PEER_FT_PREFIX_LIST:
16074 return !!(filter->plist[direct].name);
16075 case PEER_FT_ROUTE_MAP:
16076 return !!(filter->map[direct].name);
16077 case PEER_FT_UNSUPPRESS_MAP:
16078 return !!(filter->usmap.name);
16079 case PEER_FT_ADVERTISE_MAP:
16080 return !!(filter->advmap.aname
16081 && ((filter->advmap.condition == direct)
16082 && filter->advmap.cname));
16083 default:
16084 return false;
16085 }
16086 }
16087
16088 /* Return true if the addpath type is set for peer and different from
16089 * peer-group.
16090 */
16091 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16092 safi_t safi)
16093 {
16094 enum bgp_addpath_strat type, g_type;
16095
16096 type = peer->addpath_type[afi][safi];
16097
16098 if (type != BGP_ADDPATH_NONE) {
16099 if (peer_group_active(peer)) {
16100 g_type = peer->group->conf->addpath_type[afi][safi];
16101
16102 if (type != g_type)
16103 return true;
16104 else
16105 return false;
16106 }
16107
16108 return true;
16109 }
16110
16111 return false;
16112 }
16113
16114 /* This is part of the address-family block (unicast only) */
16115 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16116 afi_t afi)
16117 {
16118 int indent = 2;
16119 uint32_t tovpn_sid_index = 0;
16120
16121 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16122 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16123 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16124 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16125 bgp->vpn_policy[afi]
16126 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16127 else
16128 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16129 bgp->vpn_policy[afi]
16130 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16131 }
16132 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16133 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16134 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16135 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16136 return;
16137
16138 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16139 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16140
16141 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16142
16143 } else {
16144 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16145 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16146 bgp->vpn_policy[afi].tovpn_label);
16147 }
16148 }
16149
16150 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16151 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16152 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16153 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16154 } else if (tovpn_sid_index != 0) {
16155 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16156 tovpn_sid_index);
16157 }
16158
16159 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16160 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16161 char buf[RD_ADDRSTRLEN];
16162 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16163 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16164 sizeof(buf)));
16165 }
16166 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16167 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16168
16169 char buf[PREFIX_STRLEN];
16170 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16171 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16172 sizeof(buf))) {
16173
16174 vty_out(vty, "%*snexthop vpn export %s\n",
16175 indent, "", buf);
16176 }
16177 }
16178 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16179 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16180 && ecommunity_cmp(
16181 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16182 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16183
16184 char *b = ecommunity_ecom2str(
16185 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16186 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16187 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16188 XFREE(MTYPE_ECOMMUNITY_STR, b);
16189 } else {
16190 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16191 char *b = ecommunity_ecom2str(
16192 bgp->vpn_policy[afi]
16193 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16194 ECOMMUNITY_FORMAT_ROUTE_MAP,
16195 ECOMMUNITY_ROUTE_TARGET);
16196 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16197 XFREE(MTYPE_ECOMMUNITY_STR, b);
16198 }
16199 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16200 char *b = ecommunity_ecom2str(
16201 bgp->vpn_policy[afi]
16202 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16203 ECOMMUNITY_FORMAT_ROUTE_MAP,
16204 ECOMMUNITY_ROUTE_TARGET);
16205 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16206 XFREE(MTYPE_ECOMMUNITY_STR, b);
16207 }
16208 }
16209
16210 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16211 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16212 bgp->vpn_policy[afi]
16213 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16214
16215 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16216 char *b = ecommunity_ecom2str(
16217 bgp->vpn_policy[afi]
16218 .import_redirect_rtlist,
16219 ECOMMUNITY_FORMAT_ROUTE_MAP,
16220 ECOMMUNITY_ROUTE_TARGET);
16221
16222 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16223 != ECOMMUNITY_SIZE)
16224 vty_out(vty, "%*srt6 redirect import %s\n",
16225 indent, "", b);
16226 else
16227 vty_out(vty, "%*srt redirect import %s\n",
16228 indent, "", b);
16229 XFREE(MTYPE_ECOMMUNITY_STR, b);
16230 }
16231 }
16232
16233 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16234 afi_t afi, safi_t safi)
16235 {
16236 struct bgp_filter *filter;
16237 char *addr;
16238
16239 addr = peer->host;
16240 filter = &peer->filter[afi][safi];
16241
16242 /* distribute-list. */
16243 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16244 FILTER_IN))
16245 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16246 filter->dlist[FILTER_IN].name);
16247
16248 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16249 FILTER_OUT))
16250 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16251 filter->dlist[FILTER_OUT].name);
16252
16253 /* prefix-list. */
16254 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16255 FILTER_IN))
16256 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16257 filter->plist[FILTER_IN].name);
16258
16259 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16260 FILTER_OUT))
16261 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16262 filter->plist[FILTER_OUT].name);
16263
16264 /* route-map. */
16265 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16266 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16267 filter->map[RMAP_IN].name);
16268
16269 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16270 RMAP_OUT))
16271 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16272 filter->map[RMAP_OUT].name);
16273
16274 /* unsuppress-map */
16275 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16276 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16277 filter->usmap.name);
16278
16279 /* advertise-map : always applied in OUT direction*/
16280 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16281 CONDITION_NON_EXIST))
16282 vty_out(vty,
16283 " neighbor %s advertise-map %s non-exist-map %s\n",
16284 addr, filter->advmap.aname, filter->advmap.cname);
16285
16286 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16287 CONDITION_EXIST))
16288 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16289 addr, filter->advmap.aname, filter->advmap.cname);
16290
16291 /* filter-list. */
16292 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16293 FILTER_IN))
16294 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16295 filter->aslist[FILTER_IN].name);
16296
16297 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16298 FILTER_OUT))
16299 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16300 filter->aslist[FILTER_OUT].name);
16301 }
16302
16303 /* BGP peer configuration display function. */
16304 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16305 struct peer *peer)
16306 {
16307 struct peer *g_peer = NULL;
16308 char buf[SU_ADDRSTRLEN];
16309 char *addr;
16310 int if_pg_printed = false;
16311 int if_ras_printed = false;
16312
16313 /* Skip dynamic neighbors. */
16314 if (peer_dynamic_neighbor(peer))
16315 return;
16316
16317 if (peer->conf_if)
16318 addr = peer->conf_if;
16319 else
16320 addr = peer->host;
16321
16322 /************************************
16323 ****** Global to the neighbor ******
16324 ************************************/
16325 if (peer->conf_if) {
16326 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16327 vty_out(vty, " neighbor %s interface v6only", addr);
16328 else
16329 vty_out(vty, " neighbor %s interface", addr);
16330
16331 if (peer_group_active(peer)) {
16332 vty_out(vty, " peer-group %s", peer->group->name);
16333 if_pg_printed = true;
16334 } else if (peer->as_type == AS_SPECIFIED) {
16335 vty_out(vty, " remote-as %u", peer->as);
16336 if_ras_printed = true;
16337 } else if (peer->as_type == AS_INTERNAL) {
16338 vty_out(vty, " remote-as internal");
16339 if_ras_printed = true;
16340 } else if (peer->as_type == AS_EXTERNAL) {
16341 vty_out(vty, " remote-as external");
16342 if_ras_printed = true;
16343 }
16344
16345 vty_out(vty, "\n");
16346 }
16347
16348 /* remote-as and peer-group */
16349 /* peer is a member of a peer-group */
16350 if (peer_group_active(peer)) {
16351 g_peer = peer->group->conf;
16352
16353 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16354 if (peer->as_type == AS_SPECIFIED) {
16355 vty_out(vty, " neighbor %s remote-as %u\n",
16356 addr, peer->as);
16357 } else if (peer->as_type == AS_INTERNAL) {
16358 vty_out(vty,
16359 " neighbor %s remote-as internal\n",
16360 addr);
16361 } else if (peer->as_type == AS_EXTERNAL) {
16362 vty_out(vty,
16363 " neighbor %s remote-as external\n",
16364 addr);
16365 }
16366 }
16367
16368 /* For swpX peers we displayed the peer-group
16369 * via 'neighbor swpX interface peer-group PGNAME' */
16370 if (!if_pg_printed)
16371 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16372 peer->group->name);
16373 }
16374
16375 /* peer is NOT a member of a peer-group */
16376 else {
16377 /* peer is a peer-group, declare the peer-group */
16378 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16379 vty_out(vty, " neighbor %s peer-group\n", addr);
16380 }
16381
16382 if (!if_ras_printed) {
16383 if (peer->as_type == AS_SPECIFIED) {
16384 vty_out(vty, " neighbor %s remote-as %u\n",
16385 addr, peer->as);
16386 } else if (peer->as_type == AS_INTERNAL) {
16387 vty_out(vty,
16388 " neighbor %s remote-as internal\n",
16389 addr);
16390 } else if (peer->as_type == AS_EXTERNAL) {
16391 vty_out(vty,
16392 " neighbor %s remote-as external\n",
16393 addr);
16394 }
16395 }
16396 }
16397
16398 /* local-as */
16399 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16400 vty_out(vty, " neighbor %s local-as %u", addr,
16401 peer->change_local_as);
16402 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16403 vty_out(vty, " no-prepend");
16404 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16405 vty_out(vty, " replace-as");
16406 vty_out(vty, "\n");
16407 }
16408
16409 /* description */
16410 if (peer->desc) {
16411 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16412 }
16413
16414 /* shutdown */
16415 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16416 if (peer->tx_shutdown_message)
16417 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16418 peer->tx_shutdown_message);
16419 else
16420 vty_out(vty, " neighbor %s shutdown\n", addr);
16421 }
16422
16423 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16424 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16425 peer->rtt_expected, peer->rtt_keepalive_conf);
16426
16427 /* bfd */
16428 if (peer->bfd_config)
16429 bgp_bfd_peer_config_write(vty, peer, addr);
16430
16431 /* password */
16432 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16433 vty_out(vty, " neighbor %s password %s\n", addr,
16434 peer->password);
16435
16436 /* neighbor solo */
16437 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16438 if (!peer_group_active(peer)) {
16439 vty_out(vty, " neighbor %s solo\n", addr);
16440 }
16441 }
16442
16443 /* BGP port */
16444 if (peer->port != BGP_PORT_DEFAULT) {
16445 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16446 }
16447
16448 /* Local interface name */
16449 if (peer->ifname) {
16450 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16451 }
16452
16453 /* TCP max segment size */
16454 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16455 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16456
16457 /* passive */
16458 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16459 vty_out(vty, " neighbor %s passive\n", addr);
16460
16461 /* ebgp-multihop */
16462 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16463 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16464 && peer->ttl == MAXTTL)) {
16465 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16466 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16467 peer->ttl);
16468 }
16469 }
16470
16471 /* ttl-security hops */
16472 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16473 if (!peer_group_active(peer)
16474 || g_peer->gtsm_hops != peer->gtsm_hops) {
16475 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16476 addr, peer->gtsm_hops);
16477 }
16478 }
16479
16480 /* disable-connected-check */
16481 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16482 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16483
16484 /* link-bw-encoding-ieee */
16485 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16486 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16487 addr);
16488
16489 /* extended-optional-parameters */
16490 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16491 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16492 addr);
16493
16494 /* enforce-first-as */
16495 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16496 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16497
16498 /* update-source */
16499 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16500 if (peer->update_source)
16501 vty_out(vty, " neighbor %s update-source %s\n", addr,
16502 sockunion2str(peer->update_source, buf,
16503 SU_ADDRSTRLEN));
16504 else if (peer->update_if)
16505 vty_out(vty, " neighbor %s update-source %s\n", addr,
16506 peer->update_if);
16507 }
16508
16509 /* advertisement-interval */
16510 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16511 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16512 peer->routeadv);
16513
16514 /* timers */
16515 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16516 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16517 peer->keepalive, peer->holdtime);
16518
16519 /* timers connect */
16520 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16521 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16522 peer->connect);
16523 /* need special-case handling for changed default values due to
16524 * config profile / version (because there is no "timers bgp connect"
16525 * command, we need to save this per-peer :/)
16526 */
16527 else if (!peer_group_active(peer) && !peer->connect &&
16528 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16529 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16530 peer->bgp->default_connect_retry);
16531
16532 /* timers delayopen */
16533 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16534 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16535 peer->delayopen);
16536 /* Save config even though flag is not set if default values have been
16537 * changed
16538 */
16539 else if (!peer_group_active(peer) && !peer->delayopen
16540 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16541 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16542 peer->bgp->default_delayopen);
16543
16544 /* capability dynamic */
16545 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16546 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16547
16548 /* capability extended-nexthop */
16549 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16550 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE))
16551 vty_out(vty,
16552 " no neighbor %s capability extended-nexthop\n",
16553 addr);
16554 else if (!peer->conf_if)
16555 vty_out(vty,
16556 " neighbor %s capability extended-nexthop\n",
16557 addr);
16558 }
16559
16560 /* dont-capability-negotiation */
16561 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16562 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16563
16564 /* override-capability */
16565 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16566 vty_out(vty, " neighbor %s override-capability\n", addr);
16567
16568 /* strict-capability-match */
16569 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16570 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16571
16572 /* Sender side AS path loop detection. */
16573 if (peer->as_path_loop_detection)
16574 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16575 addr);
16576
16577 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16578 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16579
16580 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16581 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16582 vty_out(vty,
16583 " neighbor %s graceful-restart-helper\n", addr);
16584 } else if (CHECK_FLAG(
16585 peer->peer_gr_new_status_flag,
16586 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16587 vty_out(vty,
16588 " neighbor %s graceful-restart\n", addr);
16589 } else if (
16590 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16591 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16592 && !(CHECK_FLAG(
16593 peer->peer_gr_new_status_flag,
16594 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16595 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16596 addr);
16597 }
16598 }
16599 }
16600
16601 /* BGP peer configuration display function. */
16602 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16603 struct peer *peer, afi_t afi, safi_t safi)
16604 {
16605 struct peer *g_peer = NULL;
16606 char *addr;
16607 bool flag_scomm, flag_secomm, flag_slcomm;
16608
16609 /* Skip dynamic neighbors. */
16610 if (peer_dynamic_neighbor(peer))
16611 return;
16612
16613 if (peer->conf_if)
16614 addr = peer->conf_if;
16615 else
16616 addr = peer->host;
16617
16618 /************************************
16619 ****** Per AF to the neighbor ******
16620 ************************************/
16621 if (peer_group_active(peer)) {
16622 g_peer = peer->group->conf;
16623
16624 /* If the peer-group is active but peer is not, print a 'no
16625 * activate' */
16626 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16627 vty_out(vty, " no neighbor %s activate\n", addr);
16628 }
16629
16630 /* If the peer-group is not active but peer is, print an
16631 'activate' */
16632 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16633 vty_out(vty, " neighbor %s activate\n", addr);
16634 }
16635 } else {
16636 if (peer->afc[afi][safi]) {
16637 if (safi == SAFI_ENCAP)
16638 vty_out(vty, " neighbor %s activate\n", addr);
16639 else if (!bgp->default_af[afi][safi])
16640 vty_out(vty, " neighbor %s activate\n", addr);
16641 } else {
16642 if (bgp->default_af[afi][safi])
16643 vty_out(vty, " no neighbor %s activate\n",
16644 addr);
16645 }
16646 }
16647
16648 /* addpath TX knobs */
16649 if (peergroup_af_addpath_check(peer, afi, safi)) {
16650 switch (peer->addpath_type[afi][safi]) {
16651 case BGP_ADDPATH_ALL:
16652 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16653 addr);
16654 break;
16655 case BGP_ADDPATH_BEST_PER_AS:
16656 vty_out(vty,
16657 " neighbor %s addpath-tx-bestpath-per-AS\n",
16658 addr);
16659 break;
16660 case BGP_ADDPATH_MAX:
16661 case BGP_ADDPATH_NONE:
16662 break;
16663 }
16664 }
16665
16666 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16667 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16668
16669 /* ORF capability. */
16670 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16671 || peergroup_af_flag_check(peer, afi, safi,
16672 PEER_FLAG_ORF_PREFIX_RM)) {
16673 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16674
16675 if (peergroup_af_flag_check(peer, afi, safi,
16676 PEER_FLAG_ORF_PREFIX_SM)
16677 && peergroup_af_flag_check(peer, afi, safi,
16678 PEER_FLAG_ORF_PREFIX_RM))
16679 vty_out(vty, " both");
16680 else if (peergroup_af_flag_check(peer, afi, safi,
16681 PEER_FLAG_ORF_PREFIX_SM))
16682 vty_out(vty, " send");
16683 else
16684 vty_out(vty, " receive");
16685 vty_out(vty, "\n");
16686 }
16687
16688 /* Route reflector client. */
16689 if (peergroup_af_flag_check(peer, afi, safi,
16690 PEER_FLAG_REFLECTOR_CLIENT)) {
16691 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16692 }
16693
16694 /* next-hop-self force */
16695 if (peergroup_af_flag_check(peer, afi, safi,
16696 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16697 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16698 }
16699
16700 /* next-hop-self */
16701 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16702 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16703 }
16704
16705 /* remove-private-AS */
16706 if (peergroup_af_flag_check(peer, afi, safi,
16707 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16708 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16709 addr);
16710 }
16711
16712 else if (peergroup_af_flag_check(peer, afi, safi,
16713 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16714 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16715 addr);
16716 }
16717
16718 else if (peergroup_af_flag_check(peer, afi, safi,
16719 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16720 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16721 }
16722
16723 else if (peergroup_af_flag_check(peer, afi, safi,
16724 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16725 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16726 }
16727
16728 /* as-override */
16729 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16730 vty_out(vty, " neighbor %s as-override\n", addr);
16731 }
16732
16733 /* send-community print. */
16734 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16735 PEER_FLAG_SEND_COMMUNITY);
16736 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16737 PEER_FLAG_SEND_EXT_COMMUNITY);
16738 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16739 PEER_FLAG_SEND_LARGE_COMMUNITY);
16740
16741 if (flag_scomm && flag_secomm && flag_slcomm) {
16742 vty_out(vty, " no neighbor %s send-community all\n", addr);
16743 } else {
16744 if (flag_scomm)
16745 vty_out(vty, " no neighbor %s send-community\n", addr);
16746 if (flag_secomm)
16747 vty_out(vty,
16748 " no neighbor %s send-community extended\n",
16749 addr);
16750
16751 if (flag_slcomm)
16752 vty_out(vty, " no neighbor %s send-community large\n",
16753 addr);
16754 }
16755
16756 /* Default information */
16757 if (peergroup_af_flag_check(peer, afi, safi,
16758 PEER_FLAG_DEFAULT_ORIGINATE)) {
16759 vty_out(vty, " neighbor %s default-originate", addr);
16760
16761 if (peer->default_rmap[afi][safi].name)
16762 vty_out(vty, " route-map %s",
16763 peer->default_rmap[afi][safi].name);
16764
16765 vty_out(vty, "\n");
16766 }
16767
16768 /* Soft reconfiguration inbound. */
16769 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16770 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16771 addr);
16772 }
16773
16774 /* maximum-prefix. */
16775 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16776 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16777 peer->pmax[afi][safi]);
16778
16779 if (peer->pmax_threshold[afi][safi]
16780 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16781 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16782 if (peer_af_flag_check(peer, afi, safi,
16783 PEER_FLAG_MAX_PREFIX_WARNING))
16784 vty_out(vty, " warning-only");
16785 if (peer->pmax_restart[afi][safi])
16786 vty_out(vty, " restart %u",
16787 peer->pmax_restart[afi][safi]);
16788 if (peer_af_flag_check(peer, afi, safi,
16789 PEER_FLAG_MAX_PREFIX_FORCE))
16790 vty_out(vty, " force");
16791
16792 vty_out(vty, "\n");
16793 }
16794
16795 /* maximum-prefix-out */
16796 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16797 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16798 addr, peer->pmax_out[afi][safi]);
16799
16800 /* Route server client. */
16801 if (peergroup_af_flag_check(peer, afi, safi,
16802 PEER_FLAG_RSERVER_CLIENT)) {
16803 vty_out(vty, " neighbor %s route-server-client\n", addr);
16804 }
16805
16806 /* Nexthop-local unchanged. */
16807 if (peergroup_af_flag_check(peer, afi, safi,
16808 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16809 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16810 }
16811
16812 /* allowas-in <1-10> */
16813 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16814 if (peer_af_flag_check(peer, afi, safi,
16815 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16816 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16817 } else if (peer->allowas_in[afi][safi] == 3) {
16818 vty_out(vty, " neighbor %s allowas-in\n", addr);
16819 } else {
16820 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16821 peer->allowas_in[afi][safi]);
16822 }
16823 }
16824
16825 /* weight */
16826 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16827 vty_out(vty, " neighbor %s weight %lu\n", addr,
16828 peer->weight[afi][safi]);
16829
16830 /* Filter. */
16831 bgp_config_write_filter(vty, peer, afi, safi);
16832
16833 /* atribute-unchanged. */
16834 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16835 || (safi != SAFI_EVPN
16836 && peer_af_flag_check(peer, afi, safi,
16837 PEER_FLAG_NEXTHOP_UNCHANGED))
16838 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16839
16840 if (!peer_group_active(peer)
16841 || peergroup_af_flag_check(peer, afi, safi,
16842 PEER_FLAG_AS_PATH_UNCHANGED)
16843 || peergroup_af_flag_check(peer, afi, safi,
16844 PEER_FLAG_NEXTHOP_UNCHANGED)
16845 || peergroup_af_flag_check(peer, afi, safi,
16846 PEER_FLAG_MED_UNCHANGED)) {
16847
16848 vty_out(vty,
16849 " neighbor %s attribute-unchanged%s%s%s\n",
16850 addr,
16851 peer_af_flag_check(peer, afi, safi,
16852 PEER_FLAG_AS_PATH_UNCHANGED)
16853 ? " as-path"
16854 : "",
16855 peer_af_flag_check(peer, afi, safi,
16856 PEER_FLAG_NEXTHOP_UNCHANGED)
16857 ? " next-hop"
16858 : "",
16859 peer_af_flag_check(peer, afi, safi,
16860 PEER_FLAG_MED_UNCHANGED)
16861 ? " med"
16862 : "");
16863 }
16864 }
16865 }
16866
16867 /* Address family based peer configuration display. */
16868 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16869 safi_t safi)
16870 {
16871 struct peer *peer;
16872 struct peer_group *group;
16873 struct listnode *node, *nnode;
16874
16875
16876 vty_frame(vty, " !\n address-family ");
16877 if (afi == AFI_IP) {
16878 if (safi == SAFI_UNICAST)
16879 vty_frame(vty, "ipv4 unicast");
16880 else if (safi == SAFI_LABELED_UNICAST)
16881 vty_frame(vty, "ipv4 labeled-unicast");
16882 else if (safi == SAFI_MULTICAST)
16883 vty_frame(vty, "ipv4 multicast");
16884 else if (safi == SAFI_MPLS_VPN)
16885 vty_frame(vty, "ipv4 vpn");
16886 else if (safi == SAFI_ENCAP)
16887 vty_frame(vty, "ipv4 encap");
16888 else if (safi == SAFI_FLOWSPEC)
16889 vty_frame(vty, "ipv4 flowspec");
16890 } else if (afi == AFI_IP6) {
16891 if (safi == SAFI_UNICAST)
16892 vty_frame(vty, "ipv6 unicast");
16893 else if (safi == SAFI_LABELED_UNICAST)
16894 vty_frame(vty, "ipv6 labeled-unicast");
16895 else if (safi == SAFI_MULTICAST)
16896 vty_frame(vty, "ipv6 multicast");
16897 else if (safi == SAFI_MPLS_VPN)
16898 vty_frame(vty, "ipv6 vpn");
16899 else if (safi == SAFI_ENCAP)
16900 vty_frame(vty, "ipv6 encap");
16901 else if (safi == SAFI_FLOWSPEC)
16902 vty_frame(vty, "ipv6 flowspec");
16903 } else if (afi == AFI_L2VPN) {
16904 if (safi == SAFI_EVPN)
16905 vty_frame(vty, "l2vpn evpn");
16906 }
16907 vty_frame(vty, "\n");
16908
16909 bgp_config_write_distance(vty, bgp, afi, safi);
16910
16911 bgp_config_write_network(vty, bgp, afi, safi);
16912
16913 bgp_config_write_redistribute(vty, bgp, afi, safi);
16914
16915 /* BGP flag dampening. */
16916 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16917 bgp_config_write_damp(vty, afi, safi);
16918
16919 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16920 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16921
16922 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16923 /* Do not display doppelganger peers */
16924 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16925 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16926 }
16927
16928 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16929 bgp_config_write_table_map(vty, bgp, afi, safi);
16930
16931 if (safi == SAFI_EVPN)
16932 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16933
16934 if (safi == SAFI_FLOWSPEC)
16935 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16936
16937 if (safi == SAFI_UNICAST) {
16938 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16939 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16940 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16941
16942 vty_out(vty, " export vpn\n");
16943 }
16944 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16945 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16946
16947 vty_out(vty, " import vpn\n");
16948 }
16949 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16950 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16951 char *name;
16952
16953 for (ALL_LIST_ELEMENTS_RO(
16954 bgp->vpn_policy[afi].import_vrf, node,
16955 name))
16956 vty_out(vty, " import vrf %s\n", name);
16957 }
16958 }
16959
16960 vty_endframe(vty, " exit-address-family\n");
16961 }
16962
16963 int bgp_config_write(struct vty *vty)
16964 {
16965 struct bgp *bgp;
16966 struct peer_group *group;
16967 struct peer *peer;
16968 struct listnode *node, *nnode;
16969 struct listnode *mnode, *mnnode;
16970 afi_t afi;
16971 safi_t safi;
16972
16973 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16974 vty_out(vty, "bgp route-map delay-timer %u\n",
16975 bm->rmap_update_timer);
16976
16977 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16978 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16979 if (bm->v_update_delay != bm->v_establish_wait)
16980 vty_out(vty, " %d", bm->v_establish_wait);
16981 vty_out(vty, "\n");
16982 }
16983
16984 if (bm->wait_for_fib)
16985 vty_out(vty, "bgp suppress-fib-pending\n");
16986
16987 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16988 vty_out(vty, "bgp graceful-shutdown\n");
16989
16990 /* No-RIB (Zebra) option flag configuration */
16991 if (bgp_option_check(BGP_OPT_NO_FIB))
16992 vty_out(vty, "bgp no-rib\n");
16993
16994 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
16995 vty_out(vty, "no bgp send-extra-data zebra\n");
16996
16997 /* BGP configuration. */
16998 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16999
17000 /* skip all auto created vrf as they dont have user config */
17001 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17002 continue;
17003
17004 /* Router bgp ASN */
17005 vty_out(vty, "router bgp %u", bgp->as);
17006
17007 if (bgp->name)
17008 vty_out(vty, " %s %s",
17009 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17010 ? "view" : "vrf", bgp->name);
17011 vty_out(vty, "\n");
17012
17013 /* BGP fast-external-failover. */
17014 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17015 vty_out(vty, " no bgp fast-external-failover\n");
17016
17017 /* BGP router ID. */
17018 if (bgp->router_id_static.s_addr != INADDR_ANY)
17019 vty_out(vty, " bgp router-id %pI4\n",
17020 &bgp->router_id_static);
17021
17022 /* Suppress fib pending */
17023 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17024 vty_out(vty, " bgp suppress-fib-pending\n");
17025
17026 /* BGP log-neighbor-changes. */
17027 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17028 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17029 vty_out(vty, " %sbgp log-neighbor-changes\n",
17030 CHECK_FLAG(bgp->flags,
17031 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17032 ? ""
17033 : "no ");
17034
17035 /* BGP configuration. */
17036 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17037 vty_out(vty, " bgp always-compare-med\n");
17038
17039 /* RFC8212 default eBGP policy. */
17040 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17041 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17042 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17043 CHECK_FLAG(bgp->flags,
17044 BGP_FLAG_EBGP_REQUIRES_POLICY)
17045 ? ""
17046 : "no ");
17047
17048 /* draft-ietf-idr-deprecate-as-set-confed-set */
17049 if (bgp->reject_as_sets)
17050 vty_out(vty, " bgp reject-as-sets\n");
17051
17052 /* Suppress duplicate updates if the route actually not changed
17053 */
17054 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17055 != SAVE_BGP_SUPPRESS_DUPLICATES)
17056 vty_out(vty, " %sbgp suppress-duplicates\n",
17057 CHECK_FLAG(bgp->flags,
17058 BGP_FLAG_SUPPRESS_DUPLICATES)
17059 ? ""
17060 : "no ");
17061
17062 /* BGP default <afi>-<safi> */
17063 FOREACH_AFI_SAFI (afi, safi) {
17064 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17065 if (!bgp->default_af[afi][safi])
17066 vty_out(vty, " no bgp default %s\n",
17067 get_bgp_default_af_flag(afi,
17068 safi));
17069 } else if (bgp->default_af[afi][safi])
17070 vty_out(vty, " bgp default %s\n",
17071 get_bgp_default_af_flag(afi, safi));
17072 }
17073
17074 /* BGP default local-preference. */
17075 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17076 vty_out(vty, " bgp default local-preference %u\n",
17077 bgp->default_local_pref);
17078
17079 /* BGP default show-hostname */
17080 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17081 != SAVE_BGP_SHOW_HOSTNAME)
17082 vty_out(vty, " %sbgp default show-hostname\n",
17083 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17084 ? ""
17085 : "no ");
17086
17087 /* BGP default show-nexthop-hostname */
17088 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17089 != SAVE_BGP_SHOW_HOSTNAME)
17090 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17091 CHECK_FLAG(bgp->flags,
17092 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17093 ? ""
17094 : "no ");
17095
17096 /* BGP default subgroup-pkt-queue-max. */
17097 if (bgp->default_subgroup_pkt_queue_max
17098 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17099 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17100 bgp->default_subgroup_pkt_queue_max);
17101
17102 /* BGP client-to-client reflection. */
17103 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17104 vty_out(vty, " no bgp client-to-client reflection\n");
17105
17106 /* BGP cluster ID. */
17107 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17108 vty_out(vty, " bgp cluster-id %pI4\n",
17109 &bgp->cluster_id);
17110
17111 /* Disable ebgp connected nexthop check */
17112 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17113 vty_out(vty,
17114 " bgp disable-ebgp-connected-route-check\n");
17115
17116 /* Confederation identifier*/
17117 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17118 vty_out(vty, " bgp confederation identifier %u\n",
17119 bgp->confed_id);
17120
17121 /* Confederation peer */
17122 if (bgp->confed_peers_cnt > 0) {
17123 int i;
17124
17125 vty_out(vty, " bgp confederation peers");
17126
17127 for (i = 0; i < bgp->confed_peers_cnt; i++)
17128 vty_out(vty, " %u", bgp->confed_peers[i]);
17129
17130 vty_out(vty, "\n");
17131 }
17132
17133 /* BGP deterministic-med. */
17134 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17135 != SAVE_BGP_DETERMINISTIC_MED)
17136 vty_out(vty, " %sbgp deterministic-med\n",
17137 CHECK_FLAG(bgp->flags,
17138 BGP_FLAG_DETERMINISTIC_MED)
17139 ? ""
17140 : "no ");
17141
17142 /* BGP update-delay. */
17143 bgp_config_write_update_delay(vty, bgp);
17144
17145 if (bgp->v_maxmed_onstartup
17146 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17147 vty_out(vty, " bgp max-med on-startup %u",
17148 bgp->v_maxmed_onstartup);
17149 if (bgp->maxmed_onstartup_value
17150 != BGP_MAXMED_VALUE_DEFAULT)
17151 vty_out(vty, " %u",
17152 bgp->maxmed_onstartup_value);
17153 vty_out(vty, "\n");
17154 }
17155 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17156 vty_out(vty, " bgp max-med administrative");
17157 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17158 vty_out(vty, " %u", bgp->maxmed_admin_value);
17159 vty_out(vty, "\n");
17160 }
17161
17162 /* write quanta */
17163 bgp_config_write_wpkt_quanta(vty, bgp);
17164 /* read quanta */
17165 bgp_config_write_rpkt_quanta(vty, bgp);
17166
17167 /* coalesce time */
17168 bgp_config_write_coalesce_time(vty, bgp);
17169
17170 /* BGP per-instance graceful-shutdown */
17171 /* BGP-wide settings and per-instance settings are mutually
17172 * exclusive.
17173 */
17174 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17175 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17176 vty_out(vty, " bgp graceful-shutdown\n");
17177
17178 /* Long-lived Graceful Restart */
17179 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17180 vty_out(vty,
17181 " bgp long-lived-graceful-restart stale-time %u\n",
17182 bgp->llgr_stale_time);
17183
17184 /* BGP graceful-restart. */
17185 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17186 vty_out(vty,
17187 " bgp graceful-restart stalepath-time %u\n",
17188 bgp->stalepath_time);
17189
17190 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17191 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17192 bgp->restart_time);
17193
17194 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17195 vty_out(vty,
17196 " bgp graceful-restart select-defer-time %u\n",
17197 bgp->select_defer_time);
17198
17199 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17200 vty_out(vty, " bgp graceful-restart\n");
17201
17202 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17203 vty_out(vty, " bgp graceful-restart-disable\n");
17204
17205 /* BGP graceful-restart Preserve State F bit. */
17206 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17207 vty_out(vty,
17208 " bgp graceful-restart preserve-fw-state\n");
17209
17210 /* Stale timer for RIB */
17211 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17212 vty_out(vty,
17213 " bgp graceful-restart rib-stale-time %u\n",
17214 bgp->rib_stale_time);
17215
17216 /* BGP bestpath method. */
17217 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17218 vty_out(vty, " bgp bestpath as-path ignore\n");
17219 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17220 vty_out(vty, " bgp bestpath as-path confed\n");
17221
17222 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17223 if (CHECK_FLAG(bgp->flags,
17224 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17225 vty_out(vty,
17226 " bgp bestpath as-path multipath-relax as-set\n");
17227 } else {
17228 vty_out(vty,
17229 " bgp bestpath as-path multipath-relax\n");
17230 }
17231 }
17232
17233 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17234 vty_out(vty,
17235 " bgp route-reflector allow-outbound-policy\n");
17236 }
17237 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17238 vty_out(vty, " bgp bestpath compare-routerid\n");
17239 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17240 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17241 vty_out(vty, " bgp bestpath med");
17242 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17243 vty_out(vty, " confed");
17244 if (CHECK_FLAG(bgp->flags,
17245 BGP_FLAG_MED_MISSING_AS_WORST))
17246 vty_out(vty, " missing-as-worst");
17247 vty_out(vty, "\n");
17248 }
17249
17250 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17251 vty_out(vty,
17252 " bgp bestpath peer-type multipath-relax\n");
17253
17254 /* Link bandwidth handling. */
17255 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17256 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17257 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17258 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17259 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17260 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17261
17262 /* BGP network import check. */
17263 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17264 != SAVE_BGP_IMPORT_CHECK)
17265 vty_out(vty, " %sbgp network import-check\n",
17266 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17267 ? ""
17268 : "no ");
17269
17270 /* BGP timers configuration. */
17271 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17272 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17273 vty_out(vty, " timers bgp %u %u\n",
17274 bgp->default_keepalive, bgp->default_holdtime);
17275
17276 /* BGP minimum holdtime configuration. */
17277 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17278 && bgp->default_min_holdtime != 0)
17279 vty_out(vty, " bgp minimum-holdtime %u\n",
17280 bgp->default_min_holdtime);
17281
17282 /* Conditional advertisement timer configuration */
17283 if (bgp->condition_check_period
17284 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17285 vty_out(vty,
17286 " bgp conditional-advertisement timer %u\n",
17287 bgp->condition_check_period);
17288
17289 /* peer-group */
17290 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17291 bgp_config_write_peer_global(vty, bgp, group->conf);
17292 }
17293
17294 /* Normal neighbor configuration. */
17295 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17296 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17297 bgp_config_write_peer_global(vty, bgp, peer);
17298 }
17299
17300 /* listen range and limit for dynamic BGP neighbors */
17301 bgp_config_write_listen(vty, bgp);
17302
17303 /*
17304 * BGP default autoshutdown neighbors
17305 *
17306 * This must be placed after any peer and peer-group
17307 * configuration, to avoid setting all peers to shutdown after
17308 * a daemon restart, which is undesired behavior. (see #2286)
17309 */
17310 if (bgp->autoshutdown)
17311 vty_out(vty, " bgp default shutdown\n");
17312
17313 /* BGP instance administrative shutdown */
17314 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17315 vty_out(vty, " bgp shutdown\n");
17316
17317 if (bgp->fast_convergence)
17318 vty_out(vty, " bgp fast-convergence\n");
17319
17320 if (bgp->srv6_enabled) {
17321 vty_frame(vty, " !\n segment-routing srv6\n");
17322 if (strlen(bgp->srv6_locator_name))
17323 vty_out(vty, " locator %s\n",
17324 bgp->srv6_locator_name);
17325 vty_endframe(vty, " exit\n");
17326 }
17327
17328
17329 /* IPv4 unicast configuration. */
17330 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17331
17332 /* IPv4 multicast configuration. */
17333 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17334
17335 /* IPv4 labeled-unicast configuration. */
17336 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17337
17338 /* IPv4 VPN configuration. */
17339 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17340
17341 /* ENCAPv4 configuration. */
17342 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17343
17344 /* FLOWSPEC v4 configuration. */
17345 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17346
17347 /* IPv6 unicast configuration. */
17348 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17349
17350 /* IPv6 multicast configuration. */
17351 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17352
17353 /* IPv6 labeled-unicast configuration. */
17354 bgp_config_write_family(vty, bgp, AFI_IP6,
17355 SAFI_LABELED_UNICAST);
17356
17357 /* IPv6 VPN configuration. */
17358 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17359
17360 /* ENCAPv6 configuration. */
17361 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17362
17363 /* FLOWSPEC v6 configuration. */
17364 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17365
17366 /* EVPN configuration. */
17367 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17368
17369 hook_call(bgp_inst_config_write, bgp, vty);
17370
17371 #ifdef ENABLE_BGP_VNC
17372 bgp_rfapi_cfg_write(vty, bgp);
17373 #endif
17374
17375 vty_out(vty, "exit\n");
17376 vty_out(vty, "!\n");
17377 }
17378 return 0;
17379 }
17380
17381
17382 /* BGP node structure. */
17383 static struct cmd_node bgp_node = {
17384 .name = "bgp",
17385 .node = BGP_NODE,
17386 .parent_node = CONFIG_NODE,
17387 .prompt = "%s(config-router)# ",
17388 .config_write = bgp_config_write,
17389 };
17390
17391 static struct cmd_node bgp_ipv4_unicast_node = {
17392 .name = "bgp ipv4 unicast",
17393 .node = BGP_IPV4_NODE,
17394 .parent_node = BGP_NODE,
17395 .prompt = "%s(config-router-af)# ",
17396 .no_xpath = true,
17397 };
17398
17399 static struct cmd_node bgp_ipv4_multicast_node = {
17400 .name = "bgp ipv4 multicast",
17401 .node = BGP_IPV4M_NODE,
17402 .parent_node = BGP_NODE,
17403 .prompt = "%s(config-router-af)# ",
17404 .no_xpath = true,
17405 };
17406
17407 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17408 .name = "bgp ipv4 labeled unicast",
17409 .node = BGP_IPV4L_NODE,
17410 .parent_node = BGP_NODE,
17411 .prompt = "%s(config-router-af)# ",
17412 .no_xpath = true,
17413 };
17414
17415 static struct cmd_node bgp_ipv6_unicast_node = {
17416 .name = "bgp ipv6 unicast",
17417 .node = BGP_IPV6_NODE,
17418 .parent_node = BGP_NODE,
17419 .prompt = "%s(config-router-af)# ",
17420 .no_xpath = true,
17421 };
17422
17423 static struct cmd_node bgp_ipv6_multicast_node = {
17424 .name = "bgp ipv6 multicast",
17425 .node = BGP_IPV6M_NODE,
17426 .parent_node = BGP_NODE,
17427 .prompt = "%s(config-router-af)# ",
17428 .no_xpath = true,
17429 };
17430
17431 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17432 .name = "bgp ipv6 labeled unicast",
17433 .node = BGP_IPV6L_NODE,
17434 .parent_node = BGP_NODE,
17435 .prompt = "%s(config-router-af)# ",
17436 .no_xpath = true,
17437 };
17438
17439 static struct cmd_node bgp_vpnv4_node = {
17440 .name = "bgp vpnv4",
17441 .node = BGP_VPNV4_NODE,
17442 .parent_node = BGP_NODE,
17443 .prompt = "%s(config-router-af)# ",
17444 .no_xpath = true,
17445 };
17446
17447 static struct cmd_node bgp_vpnv6_node = {
17448 .name = "bgp vpnv6",
17449 .node = BGP_VPNV6_NODE,
17450 .parent_node = BGP_NODE,
17451 .prompt = "%s(config-router-af-vpnv6)# ",
17452 .no_xpath = true,
17453 };
17454
17455 static struct cmd_node bgp_evpn_node = {
17456 .name = "bgp evpn",
17457 .node = BGP_EVPN_NODE,
17458 .parent_node = BGP_NODE,
17459 .prompt = "%s(config-router-evpn)# ",
17460 .no_xpath = true,
17461 };
17462
17463 static struct cmd_node bgp_evpn_vni_node = {
17464 .name = "bgp evpn vni",
17465 .node = BGP_EVPN_VNI_NODE,
17466 .parent_node = BGP_EVPN_NODE,
17467 .prompt = "%s(config-router-af-vni)# ",
17468 };
17469
17470 static struct cmd_node bgp_flowspecv4_node = {
17471 .name = "bgp ipv4 flowspec",
17472 .node = BGP_FLOWSPECV4_NODE,
17473 .parent_node = BGP_NODE,
17474 .prompt = "%s(config-router-af)# ",
17475 .no_xpath = true,
17476 };
17477
17478 static struct cmd_node bgp_flowspecv6_node = {
17479 .name = "bgp ipv6 flowspec",
17480 .node = BGP_FLOWSPECV6_NODE,
17481 .parent_node = BGP_NODE,
17482 .prompt = "%s(config-router-af-vpnv6)# ",
17483 .no_xpath = true,
17484 };
17485
17486 static struct cmd_node bgp_srv6_node = {
17487 .name = "bgp srv6",
17488 .node = BGP_SRV6_NODE,
17489 .parent_node = BGP_NODE,
17490 .prompt = "%s(config-router-srv6)# ",
17491 };
17492
17493 static void community_list_vty(void);
17494
17495 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17496 {
17497 struct bgp *bgp;
17498 struct peer_group *group;
17499 struct listnode *lnbgp, *lnpeer;
17500
17501 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17502 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17503 vector_set(comps,
17504 XSTRDUP(MTYPE_COMPLETION, group->name));
17505 }
17506 }
17507
17508 static void bgp_ac_peer(vector comps, struct cmd_token *token)
17509 {
17510 struct bgp *bgp;
17511 struct peer *peer;
17512 struct listnode *lnbgp, *lnpeer;
17513
17514 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17515 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17516 /* only provide suggestions on the appropriate input
17517 * token type,
17518 * they'll otherwise show up multiple times */
17519 enum cmd_token_type match_type;
17520 char *name = peer->host;
17521
17522 if (peer->conf_if) {
17523 match_type = VARIABLE_TKN;
17524 name = peer->conf_if;
17525 } else if (strchr(peer->host, ':'))
17526 match_type = IPV6_TKN;
17527 else
17528 match_type = IPV4_TKN;
17529
17530 if (token->type != match_type)
17531 continue;
17532
17533 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17534 }
17535 }
17536 }
17537
17538 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17539 {
17540 bgp_ac_peer(comps, token);
17541
17542 if (token->type == VARIABLE_TKN)
17543 bgp_ac_peergroup(comps, token);
17544 }
17545
17546 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17547 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17548 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17549 {.varname = "peer", .completions = bgp_ac_neighbor},
17550 {.completions = NULL}};
17551
17552 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17553 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17554 {.completions = NULL} };
17555
17556 void bgp_vty_init(void)
17557 {
17558 cmd_variable_handler_register(bgp_var_neighbor);
17559 cmd_variable_handler_register(bgp_var_peergroup);
17560
17561 /* Install bgp top node. */
17562 install_node(&bgp_node);
17563 install_node(&bgp_ipv4_unicast_node);
17564 install_node(&bgp_ipv4_multicast_node);
17565 install_node(&bgp_ipv4_labeled_unicast_node);
17566 install_node(&bgp_ipv6_unicast_node);
17567 install_node(&bgp_ipv6_multicast_node);
17568 install_node(&bgp_ipv6_labeled_unicast_node);
17569 install_node(&bgp_vpnv4_node);
17570 install_node(&bgp_vpnv6_node);
17571 install_node(&bgp_evpn_node);
17572 install_node(&bgp_evpn_vni_node);
17573 install_node(&bgp_flowspecv4_node);
17574 install_node(&bgp_flowspecv6_node);
17575 install_node(&bgp_srv6_node);
17576
17577 /* Install default VTY commands to new nodes. */
17578 install_default(BGP_NODE);
17579 install_default(BGP_IPV4_NODE);
17580 install_default(BGP_IPV4M_NODE);
17581 install_default(BGP_IPV4L_NODE);
17582 install_default(BGP_IPV6_NODE);
17583 install_default(BGP_IPV6M_NODE);
17584 install_default(BGP_IPV6L_NODE);
17585 install_default(BGP_VPNV4_NODE);
17586 install_default(BGP_VPNV6_NODE);
17587 install_default(BGP_FLOWSPECV4_NODE);
17588 install_default(BGP_FLOWSPECV6_NODE);
17589 install_default(BGP_EVPN_NODE);
17590 install_default(BGP_EVPN_VNI_NODE);
17591 install_default(BGP_SRV6_NODE);
17592
17593 /* "bgp local-mac" hidden commands. */
17594 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17595 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17596
17597 /* "bgp suppress-fib-pending" global */
17598 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17599
17600 /* bgp route-map delay-timer commands. */
17601 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17602 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17603
17604 /* bgp fast-convergence command */
17605 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17606 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17607
17608 /* global bgp update-delay command */
17609 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17610 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17611
17612 /* global bgp graceful-shutdown command */
17613 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17614 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17615
17616 /* Dummy commands (Currently not supported) */
17617 install_element(BGP_NODE, &no_synchronization_cmd);
17618 install_element(BGP_NODE, &no_auto_summary_cmd);
17619
17620 /* "router bgp" commands. */
17621 install_element(CONFIG_NODE, &router_bgp_cmd);
17622
17623 /* "no router bgp" commands. */
17624 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17625
17626 /* "bgp router-id" commands. */
17627 install_element(BGP_NODE, &bgp_router_id_cmd);
17628 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17629
17630 /* "bgp suppress-fib-pending" command */
17631 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17632
17633 /* "bgp cluster-id" commands. */
17634 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17635 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17636
17637 /* "bgp no-rib" commands. */
17638 install_element(CONFIG_NODE, &bgp_norib_cmd);
17639 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17640
17641 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17642
17643 /* "bgp confederation" commands. */
17644 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17645 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17646
17647 /* "bgp confederation peers" commands. */
17648 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17649 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17650
17651 /* bgp max-med command */
17652 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17653 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17654 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17655 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17656 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17657
17658 /* bgp disable-ebgp-connected-nh-check */
17659 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17660 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17661
17662 /* bgp update-delay command */
17663 install_element(BGP_NODE, &bgp_update_delay_cmd);
17664 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17665
17666 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17667 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17668
17669 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17670 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17671
17672 /* "maximum-paths" commands. */
17673 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17674 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17675 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17676 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17677 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17678 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17679 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17680 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17681 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17682 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17683 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17684 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17685 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17686 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17687 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17688
17689 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17690 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17691 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17692 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17693 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17694 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17695 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17696 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17697 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17698 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17699
17700 /* "timers bgp" commands. */
17701 install_element(BGP_NODE, &bgp_timers_cmd);
17702 install_element(BGP_NODE, &no_bgp_timers_cmd);
17703
17704 /* "minimum-holdtime" commands. */
17705 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17706 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17707
17708 /* route-map delay-timer commands - per instance for backwards compat.
17709 */
17710 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17711 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17712
17713 /* "bgp client-to-client reflection" commands */
17714 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17715 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17716
17717 /* "bgp always-compare-med" commands */
17718 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17719 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17720
17721 /* bgp ebgp-requires-policy */
17722 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17723 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17724
17725 /* bgp suppress-duplicates */
17726 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17727 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17728
17729 /* bgp reject-as-sets */
17730 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17731 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17732
17733 /* "bgp deterministic-med" commands */
17734 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17735 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17736
17737 /* "bgp graceful-restart" command */
17738 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17739 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17740
17741 /* "bgp graceful-restart-disable" command */
17742 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17743 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17744
17745 /* "neighbor a:b:c:d graceful-restart" command */
17746 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17747 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17748
17749 /* "neighbor a:b:c:d graceful-restart-disable" command */
17750 install_element(BGP_NODE,
17751 &bgp_neighbor_graceful_restart_disable_set_cmd);
17752 install_element(BGP_NODE,
17753 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17754
17755 /* "neighbor a:b:c:d graceful-restart-helper" command */
17756 install_element(BGP_NODE,
17757 &bgp_neighbor_graceful_restart_helper_set_cmd);
17758 install_element(BGP_NODE,
17759 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17760
17761 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17762 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17763 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17764 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17765 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17766 install_element(BGP_NODE,
17767 &no_bgp_graceful_restart_select_defer_time_cmd);
17768 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17769 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17770
17771 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17772 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17773 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17774 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17775
17776 /* "bgp graceful-shutdown" commands */
17777 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17778 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17779
17780 /* "bgp long-lived-graceful-restart" commands */
17781 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17782 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17783
17784 /* "bgp fast-external-failover" commands */
17785 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17786 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17787
17788 /* "bgp bestpath compare-routerid" commands */
17789 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17790 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17791
17792 /* "bgp bestpath as-path ignore" commands */
17793 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17794 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17795
17796 /* "bgp bestpath as-path confed" commands */
17797 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17798 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17799
17800 /* "bgp bestpath as-path multipath-relax" commands */
17801 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17802 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17803
17804 /* "bgp bestpath peer-type multipath-relax" commands */
17805 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17806 install_element(BGP_NODE,
17807 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17808
17809 /* "bgp log-neighbor-changes" commands */
17810 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17811 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17812
17813 /* "bgp bestpath med" commands */
17814 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17815 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17816
17817 /* "bgp bestpath bandwidth" commands */
17818 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17819 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17820
17821 /* "no bgp default <afi>-<safi>" commands. */
17822 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
17823
17824 /* "bgp network import-check" commands. */
17825 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17826 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17827 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17828
17829 /* "bgp default local-preference" commands. */
17830 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17831 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17832
17833 /* bgp default show-hostname */
17834 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17835 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17836
17837 /* bgp default show-nexthop-hostname */
17838 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17839 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17840
17841 /* "bgp default subgroup-pkt-queue-max" commands. */
17842 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17843 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17844
17845 /* bgp ibgp-allow-policy-mods command */
17846 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17847 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17848
17849 /* "bgp listen limit" commands. */
17850 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17851 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17852
17853 /* "bgp listen range" commands. */
17854 install_element(BGP_NODE, &bgp_listen_range_cmd);
17855 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17856
17857 /* "bgp default shutdown" command */
17858 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17859
17860 /* "bgp shutdown" commands */
17861 install_element(BGP_NODE, &bgp_shutdown_cmd);
17862 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17863 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17864 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17865
17866 /* "neighbor remote-as" commands. */
17867 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17868 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17869 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17870 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17871 install_element(BGP_NODE,
17872 &neighbor_interface_v6only_config_remote_as_cmd);
17873 install_element(BGP_NODE, &no_neighbor_cmd);
17874 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17875
17876 /* "neighbor peer-group" commands. */
17877 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17878 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17879 install_element(BGP_NODE,
17880 &no_neighbor_interface_peer_group_remote_as_cmd);
17881
17882 /* "neighbor local-as" commands. */
17883 install_element(BGP_NODE, &neighbor_local_as_cmd);
17884 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17885 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17886 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17887
17888 /* "neighbor solo" commands. */
17889 install_element(BGP_NODE, &neighbor_solo_cmd);
17890 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17891
17892 /* "neighbor password" commands. */
17893 install_element(BGP_NODE, &neighbor_password_cmd);
17894 install_element(BGP_NODE, &no_neighbor_password_cmd);
17895
17896 /* "neighbor activate" commands. */
17897 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17898 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17899 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17900 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17901 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17902 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17903 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17904 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17905 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
17906 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17907 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
17908 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17909
17910 /* "no neighbor activate" commands. */
17911 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17912 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17913 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17914 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17915 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17916 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17917 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17918 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17919 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
17920 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17921 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
17922 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17923
17924 /* "neighbor peer-group" set commands. */
17925 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17926 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17927 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17928 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17929 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17930 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17931 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17932 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17933 install_element(BGP_FLOWSPECV4_NODE,
17934 &neighbor_set_peer_group_hidden_cmd);
17935 install_element(BGP_FLOWSPECV6_NODE,
17936 &neighbor_set_peer_group_hidden_cmd);
17937
17938 /* "no neighbor peer-group unset" commands. */
17939 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17940 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17941 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17942 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17943 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17944 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17945 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17946 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17947 install_element(BGP_FLOWSPECV4_NODE,
17948 &no_neighbor_set_peer_group_hidden_cmd);
17949 install_element(BGP_FLOWSPECV6_NODE,
17950 &no_neighbor_set_peer_group_hidden_cmd);
17951
17952 /* "neighbor softreconfiguration inbound" commands.*/
17953 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17954 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17955 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17956 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17957 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17958 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17959 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17960 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17961 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17962 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17963 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17964 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17965 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17966 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17967 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17968 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17969 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17970 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17971 install_element(BGP_FLOWSPECV4_NODE,
17972 &neighbor_soft_reconfiguration_cmd);
17973 install_element(BGP_FLOWSPECV4_NODE,
17974 &no_neighbor_soft_reconfiguration_cmd);
17975 install_element(BGP_FLOWSPECV6_NODE,
17976 &neighbor_soft_reconfiguration_cmd);
17977 install_element(BGP_FLOWSPECV6_NODE,
17978 &no_neighbor_soft_reconfiguration_cmd);
17979 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17980 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
17981
17982 /* "neighbor attribute-unchanged" commands. */
17983 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17984 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17985 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17986 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17987 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17988 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17989 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17990 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17991 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17992 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17993 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17994 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17995 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17996 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17997 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17998 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17999 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18000 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18001
18002 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18003 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18004
18005 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18006 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18007 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18008 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18009
18010 /* "nexthop-local unchanged" commands */
18011 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18012 install_element(BGP_IPV6_NODE,
18013 &no_neighbor_nexthop_local_unchanged_cmd);
18014
18015 /* "neighbor next-hop-self" commands. */
18016 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18017 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18018 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18019 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18020 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18021 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18022 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18023 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18024 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18025 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18026 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18027 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18028 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18029 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18030 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18031 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18032 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18033 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18034 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18035 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18036
18037 /* "neighbor next-hop-self force" commands. */
18038 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18039 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18040 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18041 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18042 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18043 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18044 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18045 install_element(BGP_IPV4_NODE,
18046 &no_neighbor_nexthop_self_all_hidden_cmd);
18047 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18048 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18049 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18050 install_element(BGP_IPV4M_NODE,
18051 &no_neighbor_nexthop_self_all_hidden_cmd);
18052 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18053 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18054 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18055 install_element(BGP_IPV4L_NODE,
18056 &no_neighbor_nexthop_self_all_hidden_cmd);
18057 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18058 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18059 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18060 install_element(BGP_IPV6_NODE,
18061 &no_neighbor_nexthop_self_all_hidden_cmd);
18062 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18063 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18064 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18065 install_element(BGP_IPV6M_NODE,
18066 &no_neighbor_nexthop_self_all_hidden_cmd);
18067 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18068 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18069 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18070 install_element(BGP_IPV6L_NODE,
18071 &no_neighbor_nexthop_self_all_hidden_cmd);
18072 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18073 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18074 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18075 install_element(BGP_VPNV4_NODE,
18076 &no_neighbor_nexthop_self_all_hidden_cmd);
18077 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18078 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18079 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18080 install_element(BGP_VPNV6_NODE,
18081 &no_neighbor_nexthop_self_all_hidden_cmd);
18082 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18083 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18084
18085 /* "neighbor as-override" commands. */
18086 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18087 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18088 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18089 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18090 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18091 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18092 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18093 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18094 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18095 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18096 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18097 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18098 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18099 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18100 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18101 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18102 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18103 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18104
18105 /* "neighbor remove-private-AS" commands. */
18106 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18107 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18108 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18109 install_element(BGP_NODE,
18110 &no_neighbor_remove_private_as_all_hidden_cmd);
18111 install_element(BGP_NODE,
18112 &neighbor_remove_private_as_replace_as_hidden_cmd);
18113 install_element(BGP_NODE,
18114 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18115 install_element(BGP_NODE,
18116 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18117 install_element(
18118 BGP_NODE,
18119 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18120 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18121 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18122 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18123 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18124 install_element(BGP_IPV4_NODE,
18125 &neighbor_remove_private_as_replace_as_cmd);
18126 install_element(BGP_IPV4_NODE,
18127 &no_neighbor_remove_private_as_replace_as_cmd);
18128 install_element(BGP_IPV4_NODE,
18129 &neighbor_remove_private_as_all_replace_as_cmd);
18130 install_element(BGP_IPV4_NODE,
18131 &no_neighbor_remove_private_as_all_replace_as_cmd);
18132 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18133 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18134 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18135 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18136 install_element(BGP_IPV4M_NODE,
18137 &neighbor_remove_private_as_replace_as_cmd);
18138 install_element(BGP_IPV4M_NODE,
18139 &no_neighbor_remove_private_as_replace_as_cmd);
18140 install_element(BGP_IPV4M_NODE,
18141 &neighbor_remove_private_as_all_replace_as_cmd);
18142 install_element(BGP_IPV4M_NODE,
18143 &no_neighbor_remove_private_as_all_replace_as_cmd);
18144 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18145 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18146 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18147 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18148 install_element(BGP_IPV4L_NODE,
18149 &neighbor_remove_private_as_replace_as_cmd);
18150 install_element(BGP_IPV4L_NODE,
18151 &no_neighbor_remove_private_as_replace_as_cmd);
18152 install_element(BGP_IPV4L_NODE,
18153 &neighbor_remove_private_as_all_replace_as_cmd);
18154 install_element(BGP_IPV4L_NODE,
18155 &no_neighbor_remove_private_as_all_replace_as_cmd);
18156 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18157 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18158 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18159 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18160 install_element(BGP_IPV6_NODE,
18161 &neighbor_remove_private_as_replace_as_cmd);
18162 install_element(BGP_IPV6_NODE,
18163 &no_neighbor_remove_private_as_replace_as_cmd);
18164 install_element(BGP_IPV6_NODE,
18165 &neighbor_remove_private_as_all_replace_as_cmd);
18166 install_element(BGP_IPV6_NODE,
18167 &no_neighbor_remove_private_as_all_replace_as_cmd);
18168 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18169 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18170 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18171 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18172 install_element(BGP_IPV6M_NODE,
18173 &neighbor_remove_private_as_replace_as_cmd);
18174 install_element(BGP_IPV6M_NODE,
18175 &no_neighbor_remove_private_as_replace_as_cmd);
18176 install_element(BGP_IPV6M_NODE,
18177 &neighbor_remove_private_as_all_replace_as_cmd);
18178 install_element(BGP_IPV6M_NODE,
18179 &no_neighbor_remove_private_as_all_replace_as_cmd);
18180 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18181 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18182 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18183 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18184 install_element(BGP_IPV6L_NODE,
18185 &neighbor_remove_private_as_replace_as_cmd);
18186 install_element(BGP_IPV6L_NODE,
18187 &no_neighbor_remove_private_as_replace_as_cmd);
18188 install_element(BGP_IPV6L_NODE,
18189 &neighbor_remove_private_as_all_replace_as_cmd);
18190 install_element(BGP_IPV6L_NODE,
18191 &no_neighbor_remove_private_as_all_replace_as_cmd);
18192 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18193 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18194 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18195 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18196 install_element(BGP_VPNV4_NODE,
18197 &neighbor_remove_private_as_replace_as_cmd);
18198 install_element(BGP_VPNV4_NODE,
18199 &no_neighbor_remove_private_as_replace_as_cmd);
18200 install_element(BGP_VPNV4_NODE,
18201 &neighbor_remove_private_as_all_replace_as_cmd);
18202 install_element(BGP_VPNV4_NODE,
18203 &no_neighbor_remove_private_as_all_replace_as_cmd);
18204 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18205 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18206 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18207 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18208 install_element(BGP_VPNV6_NODE,
18209 &neighbor_remove_private_as_replace_as_cmd);
18210 install_element(BGP_VPNV6_NODE,
18211 &no_neighbor_remove_private_as_replace_as_cmd);
18212 install_element(BGP_VPNV6_NODE,
18213 &neighbor_remove_private_as_all_replace_as_cmd);
18214 install_element(BGP_VPNV6_NODE,
18215 &no_neighbor_remove_private_as_all_replace_as_cmd);
18216
18217 /* "neighbor send-community" commands.*/
18218 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18219 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18220 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18221 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18222 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18223 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18224 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18225 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18226 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18227 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18228 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18229 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18230 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18231 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18232 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18233 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18234 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18235 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18236 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18237 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18238 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18239 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18240 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18241 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18242 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18243 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18244 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18245 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18246 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18247 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18248 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18249 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18250 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18251 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18252 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18253 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18254
18255 /* "neighbor route-reflector" commands.*/
18256 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18257 install_element(BGP_NODE,
18258 &no_neighbor_route_reflector_client_hidden_cmd);
18259 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18260 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18261 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18262 install_element(BGP_IPV4M_NODE,
18263 &no_neighbor_route_reflector_client_cmd);
18264 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18265 install_element(BGP_IPV4L_NODE,
18266 &no_neighbor_route_reflector_client_cmd);
18267 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18268 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18269 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18270 install_element(BGP_IPV6M_NODE,
18271 &no_neighbor_route_reflector_client_cmd);
18272 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18273 install_element(BGP_IPV6L_NODE,
18274 &no_neighbor_route_reflector_client_cmd);
18275 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18276 install_element(BGP_VPNV4_NODE,
18277 &no_neighbor_route_reflector_client_cmd);
18278 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18279 install_element(BGP_VPNV6_NODE,
18280 &no_neighbor_route_reflector_client_cmd);
18281 install_element(BGP_FLOWSPECV4_NODE,
18282 &neighbor_route_reflector_client_cmd);
18283 install_element(BGP_FLOWSPECV4_NODE,
18284 &no_neighbor_route_reflector_client_cmd);
18285 install_element(BGP_FLOWSPECV6_NODE,
18286 &neighbor_route_reflector_client_cmd);
18287 install_element(BGP_FLOWSPECV6_NODE,
18288 &no_neighbor_route_reflector_client_cmd);
18289 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18290 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18291
18292 /* "neighbor route-server" commands.*/
18293 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18294 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18295 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18296 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18297 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18298 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18299 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18300 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18301 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18302 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18303 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18304 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18305 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18306 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18307 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18308 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18309 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18310 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18311 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18312 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18313 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18314 install_element(BGP_FLOWSPECV4_NODE,
18315 &no_neighbor_route_server_client_cmd);
18316 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18317 install_element(BGP_FLOWSPECV6_NODE,
18318 &no_neighbor_route_server_client_cmd);
18319
18320 /* "neighbor disable-addpath-rx" commands. */
18321 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18322 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18323 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18324 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18325 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18326 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18327 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18328 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18329 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18330 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18331 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18332 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18333 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18334 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18335 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18336 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18337
18338 /* "neighbor addpath-tx-all-paths" commands.*/
18339 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18340 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18341 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18342 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18343 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18344 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18345 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18346 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18347 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18348 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18349 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18350 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18351 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18352 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18353 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18354 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18355 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18356 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18357
18358 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18359 install_element(BGP_NODE,
18360 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18361 install_element(BGP_NODE,
18362 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18363 install_element(BGP_IPV4_NODE,
18364 &neighbor_addpath_tx_bestpath_per_as_cmd);
18365 install_element(BGP_IPV4_NODE,
18366 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18367 install_element(BGP_IPV4M_NODE,
18368 &neighbor_addpath_tx_bestpath_per_as_cmd);
18369 install_element(BGP_IPV4M_NODE,
18370 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18371 install_element(BGP_IPV4L_NODE,
18372 &neighbor_addpath_tx_bestpath_per_as_cmd);
18373 install_element(BGP_IPV4L_NODE,
18374 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18375 install_element(BGP_IPV6_NODE,
18376 &neighbor_addpath_tx_bestpath_per_as_cmd);
18377 install_element(BGP_IPV6_NODE,
18378 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18379 install_element(BGP_IPV6M_NODE,
18380 &neighbor_addpath_tx_bestpath_per_as_cmd);
18381 install_element(BGP_IPV6M_NODE,
18382 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18383 install_element(BGP_IPV6L_NODE,
18384 &neighbor_addpath_tx_bestpath_per_as_cmd);
18385 install_element(BGP_IPV6L_NODE,
18386 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18387 install_element(BGP_VPNV4_NODE,
18388 &neighbor_addpath_tx_bestpath_per_as_cmd);
18389 install_element(BGP_VPNV4_NODE,
18390 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18391 install_element(BGP_VPNV6_NODE,
18392 &neighbor_addpath_tx_bestpath_per_as_cmd);
18393 install_element(BGP_VPNV6_NODE,
18394 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18395
18396 /* "neighbor sender-as-path-loop-detection" commands. */
18397 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18398 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18399
18400 /* "neighbor passive" commands. */
18401 install_element(BGP_NODE, &neighbor_passive_cmd);
18402 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18403
18404
18405 /* "neighbor shutdown" commands. */
18406 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18407 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18408 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18409 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18410 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18411 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18412
18413 /* "neighbor capability extended-nexthop" commands.*/
18414 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18415 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18416
18417 /* "neighbor capability orf prefix-list" commands.*/
18418 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18419 install_element(BGP_NODE,
18420 &no_neighbor_capability_orf_prefix_hidden_cmd);
18421 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18422 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18423 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18424 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18425 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18426 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18427 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18428 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18429 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18430 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18431 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18432 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18433
18434 /* "neighbor capability dynamic" commands.*/
18435 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18436 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18437
18438 /* "neighbor dont-capability-negotiate" commands. */
18439 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18440 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18441
18442 /* "neighbor ebgp-multihop" commands. */
18443 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18444 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18445 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18446
18447 /* "neighbor disable-connected-check" commands. */
18448 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18449 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18450
18451 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18452 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18453 install_element(BGP_NODE,
18454 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
18455
18456 /* "neighbor extended-optional-parameters" commands. */
18457 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18458 install_element(BGP_NODE,
18459 &no_neighbor_extended_optional_parameters_cmd);
18460
18461 /* "neighbor enforce-first-as" commands. */
18462 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18463 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18464
18465 /* "neighbor description" commands. */
18466 install_element(BGP_NODE, &neighbor_description_cmd);
18467 install_element(BGP_NODE, &no_neighbor_description_cmd);
18468 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18469
18470 /* "neighbor update-source" commands. "*/
18471 install_element(BGP_NODE, &neighbor_update_source_cmd);
18472 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18473
18474 /* "neighbor default-originate" commands. */
18475 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18476 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18477 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18478 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18479 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18480 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18481 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18482 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18483 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18484 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18485 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18486 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18487 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18488 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18489 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18490 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18491 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18492 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18493 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18494 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18495 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18496
18497 /* "neighbor port" commands. */
18498 install_element(BGP_NODE, &neighbor_port_cmd);
18499 install_element(BGP_NODE, &no_neighbor_port_cmd);
18500
18501 /* "neighbor weight" commands. */
18502 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18503 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18504
18505 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18506 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18507 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18508 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18509 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18510 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18511 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18512 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18513 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18514 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18515 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18516 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18517 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18518 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18519 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18520 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18521
18522 /* "neighbor override-capability" commands. */
18523 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18524 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18525
18526 /* "neighbor strict-capability-match" commands. */
18527 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18528 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18529
18530 /* "neighbor timers" commands. */
18531 install_element(BGP_NODE, &neighbor_timers_cmd);
18532 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18533
18534 /* "neighbor timers connect" commands. */
18535 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18536 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18537
18538 /* "neighbor timers delayopen" commands. */
18539 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18540 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18541
18542 /* "neighbor advertisement-interval" commands. */
18543 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18544 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18545
18546 /* "neighbor interface" commands. */
18547 install_element(BGP_NODE, &neighbor_interface_cmd);
18548 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18549
18550 /* "neighbor distribute" commands. */
18551 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18552 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18553 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18554 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18555 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18556 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18557 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18558 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18559 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18560 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18561 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18562 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18563 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18564 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18565 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18566 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18567 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18568 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18569
18570 /* "neighbor prefix-list" commands. */
18571 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18572 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18573 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18574 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18575 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18576 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18577 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18578 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18579 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18580 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18581 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18582 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18583 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18584 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18585 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18586 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18587 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18588 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18589 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18590 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18591 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18592 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18593
18594 /* "neighbor filter-list" commands. */
18595 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18596 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18597 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18598 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18599 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18600 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18601 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18602 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18603 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18604 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18605 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18606 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18607 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18608 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18609 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18610 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18611 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18612 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18613 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18614 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18615 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18616 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18617
18618 /* "neighbor route-map" commands. */
18619 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18620 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18621 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18622 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18623 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18624 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18625 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18626 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18627 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18628 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18629 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18630 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18631 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18632 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18633 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18634 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18635 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18636 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18637 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18638 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18639 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18640 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18641 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18642 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18643
18644 /* "neighbor unsuppress-map" commands. */
18645 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18646 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18647 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18648 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18649 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18650 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18651 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18652 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18653 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18654 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18655 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18656 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18657 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18658 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18659 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18660 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18661 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18662 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18663
18664 /* "neighbor advertise-map" commands. */
18665 install_element(BGP_NODE, &bgp_condadv_period_cmd);
18666 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18667 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18668 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18669 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18670 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18671 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18672 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18673 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18674 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18675
18676 /* neighbor maximum-prefix-out commands. */
18677 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18678 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18679 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18680 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18681 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18682 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18683 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18684 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18685 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18686 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18687 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18688 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18689 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18690 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18691 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18692 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18693 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18694 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18695
18696 /* "neighbor maximum-prefix" commands. */
18697 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18698 install_element(BGP_NODE,
18699 &neighbor_maximum_prefix_threshold_hidden_cmd);
18700 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18701 install_element(BGP_NODE,
18702 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18703 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18704 install_element(BGP_NODE,
18705 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18706 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18707 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18708 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18709 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18710 install_element(BGP_IPV4_NODE,
18711 &neighbor_maximum_prefix_threshold_warning_cmd);
18712 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18713 install_element(BGP_IPV4_NODE,
18714 &neighbor_maximum_prefix_threshold_restart_cmd);
18715 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18716 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18717 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18718 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18719 install_element(BGP_IPV4M_NODE,
18720 &neighbor_maximum_prefix_threshold_warning_cmd);
18721 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18722 install_element(BGP_IPV4M_NODE,
18723 &neighbor_maximum_prefix_threshold_restart_cmd);
18724 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18725 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18726 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18727 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18728 install_element(BGP_IPV4L_NODE,
18729 &neighbor_maximum_prefix_threshold_warning_cmd);
18730 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18731 install_element(BGP_IPV4L_NODE,
18732 &neighbor_maximum_prefix_threshold_restart_cmd);
18733 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18734 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18735 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18736 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18737 install_element(BGP_IPV6_NODE,
18738 &neighbor_maximum_prefix_threshold_warning_cmd);
18739 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18740 install_element(BGP_IPV6_NODE,
18741 &neighbor_maximum_prefix_threshold_restart_cmd);
18742 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18743 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18744 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18745 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18746 install_element(BGP_IPV6M_NODE,
18747 &neighbor_maximum_prefix_threshold_warning_cmd);
18748 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18749 install_element(BGP_IPV6M_NODE,
18750 &neighbor_maximum_prefix_threshold_restart_cmd);
18751 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18752 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18753 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18754 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18755 install_element(BGP_IPV6L_NODE,
18756 &neighbor_maximum_prefix_threshold_warning_cmd);
18757 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18758 install_element(BGP_IPV6L_NODE,
18759 &neighbor_maximum_prefix_threshold_restart_cmd);
18760 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18761 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18762 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18763 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18764 install_element(BGP_VPNV4_NODE,
18765 &neighbor_maximum_prefix_threshold_warning_cmd);
18766 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18767 install_element(BGP_VPNV4_NODE,
18768 &neighbor_maximum_prefix_threshold_restart_cmd);
18769 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18770 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18771 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18772 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18773 install_element(BGP_VPNV6_NODE,
18774 &neighbor_maximum_prefix_threshold_warning_cmd);
18775 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18776 install_element(BGP_VPNV6_NODE,
18777 &neighbor_maximum_prefix_threshold_restart_cmd);
18778 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18779
18780 /* "neighbor allowas-in" */
18781 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18782 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18783 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18784 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18785 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18786 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18787 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18788 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18789 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18790 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18791 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18792 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18793 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18794 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18795 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18796 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18797 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18798 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18799 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18800 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18801
18802 /* address-family commands. */
18803 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18804 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18805 #ifdef KEEP_OLD_VPN_COMMANDS
18806 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18807 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18808 #endif /* KEEP_OLD_VPN_COMMANDS */
18809
18810 install_element(BGP_NODE, &address_family_evpn_cmd);
18811
18812 /* "exit-address-family" command. */
18813 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18814 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18815 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18816 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18817 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18818 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18819 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18820 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18821 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18822 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18823 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18824
18825 /* "clear ip bgp commands" */
18826 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18827
18828 /* clear ip bgp prefix */
18829 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18830 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18831 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18832
18833 /* "show [ip] bgp summary" commands. */
18834 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18835 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18836 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18837 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18838 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18839 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18840 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18841
18842 /* "show [ip] bgp neighbors" commands. */
18843 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18844
18845 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18846
18847 /* "show [ip] bgp peer-group" commands. */
18848 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18849
18850 /* "show [ip] bgp paths" commands. */
18851 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18852
18853 /* "show [ip] bgp community" commands. */
18854 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18855
18856 /* "show ip bgp large-community" commands. */
18857 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18858 /* "show [ip] bgp attribute-info" commands. */
18859 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18860 /* "show [ip] bgp route-leak" command */
18861 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18862
18863 /* "redistribute" commands. */
18864 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18865 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18866 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18867 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18868 install_element(BGP_NODE,
18869 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18870 install_element(BGP_NODE,
18871 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18872 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18873 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18874 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18875 install_element(BGP_NODE,
18876 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18877 install_element(BGP_NODE,
18878 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18879 install_element(BGP_NODE,
18880 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18881 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18882 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18883 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18884 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18885 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18886 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18887 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18888 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18889 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18890 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18891 install_element(BGP_IPV4_NODE,
18892 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18893 install_element(BGP_IPV4_NODE,
18894 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18895 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18896 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18897 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18898 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18899 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18900 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18901
18902 /* import|export vpn [route-map WORD] */
18903 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18904 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
18905
18906 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18907 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18908
18909 /* ttl_security commands */
18910 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18911 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18912
18913 /* "show [ip] bgp memory" commands. */
18914 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18915
18916 /* "show bgp martian next-hop" */
18917 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18918
18919 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18920
18921 /* "show [ip] bgp views" commands. */
18922 install_element(VIEW_NODE, &show_bgp_views_cmd);
18923
18924 /* "show [ip] bgp vrfs" commands. */
18925 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18926
18927 /* Community-list. */
18928 community_list_vty();
18929
18930 community_alias_vty();
18931
18932 /* vpn-policy commands */
18933 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18934 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18935 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18936 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18937 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18938 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18939 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18940 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18941 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18942 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
18943 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18944 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
18945
18946 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18947 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18948
18949 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18950 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18951 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18952 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
18953 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18954 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18955 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18956 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
18957 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18958 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
18959
18960 /* tcp-mss command */
18961 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18962 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
18963
18964 /* srv6 commands */
18965 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
18966 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
18967 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
18968 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
18969 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
18970 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
18971 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
18972 }
18973
18974 #include "memory.h"
18975 #include "bgp_regex.h"
18976 #include "bgp_clist.h"
18977 #include "bgp_ecommunity.h"
18978
18979 /* VTY functions. */
18980
18981 /* Direction value to string conversion. */
18982 static const char *community_direct_str(int direct)
18983 {
18984 switch (direct) {
18985 case COMMUNITY_DENY:
18986 return "deny";
18987 case COMMUNITY_PERMIT:
18988 return "permit";
18989 default:
18990 return "unknown";
18991 }
18992 }
18993
18994 /* Display error string. */
18995 static void community_list_perror(struct vty *vty, int ret)
18996 {
18997 switch (ret) {
18998 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18999 vty_out(vty, "%% Can't find community-list\n");
19000 break;
19001 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19002 vty_out(vty, "%% Malformed community-list value\n");
19003 break;
19004 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19005 vty_out(vty,
19006 "%% Community name conflict, previously defined as standard community\n");
19007 break;
19008 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19009 vty_out(vty,
19010 "%% Community name conflict, previously defined as expanded community\n");
19011 break;
19012 }
19013 }
19014
19015 /* "community-list" keyword help string. */
19016 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19017
19018 /*community-list standard */
19019 DEFUN (community_list_standard,
19020 bgp_community_list_standard_cmd,
19021 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19022 BGP_STR
19023 COMMUNITY_LIST_STR
19024 "Community list number (standard)\n"
19025 "Add an standard community-list entry\n"
19026 "Community list name\n"
19027 "Sequence number of an entry\n"
19028 "Sequence number\n"
19029 "Specify community to reject\n"
19030 "Specify community to accept\n"
19031 COMMUNITY_VAL_STR)
19032 {
19033 char *cl_name_or_number = NULL;
19034 char *seq = NULL;
19035 int direct = 0;
19036 int style = COMMUNITY_LIST_STANDARD;
19037 int idx = 0;
19038
19039 argv_find(argv, argc, "(0-4294967295)", &idx);
19040 if (idx)
19041 seq = argv[idx]->arg;
19042
19043 idx = 0;
19044 argv_find(argv, argc, "(1-99)", &idx);
19045 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19046 cl_name_or_number = argv[idx]->arg;
19047 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19048 : COMMUNITY_DENY;
19049 argv_find(argv, argc, "AA:NN", &idx);
19050 char *str = argv_concat(argv, argc, idx);
19051
19052 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19053 direct, style);
19054
19055 XFREE(MTYPE_TMP, str);
19056
19057 if (ret < 0) {
19058 /* Display error string. */
19059 community_list_perror(vty, ret);
19060 return CMD_WARNING_CONFIG_FAILED;
19061 }
19062
19063 return CMD_SUCCESS;
19064 }
19065
19066 DEFUN (no_community_list_standard_all,
19067 no_bgp_community_list_standard_all_cmd,
19068 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19069 NO_STR
19070 BGP_STR
19071 COMMUNITY_LIST_STR
19072 "Community list number (standard)\n"
19073 "Add an standard community-list entry\n"
19074 "Community list name\n"
19075 "Sequence number of an entry\n"
19076 "Sequence number\n"
19077 "Specify community to reject\n"
19078 "Specify community to accept\n"
19079 COMMUNITY_VAL_STR)
19080 {
19081 char *cl_name_or_number = NULL;
19082 char *str = NULL;
19083 int direct = 0;
19084 int style = COMMUNITY_LIST_STANDARD;
19085 char *seq = NULL;
19086 int idx = 0;
19087
19088 argv_find(argv, argc, "(0-4294967295)", &idx);
19089 if (idx)
19090 seq = argv[idx]->arg;
19091
19092 idx = 0;
19093 argv_find(argv, argc, "permit", &idx);
19094 argv_find(argv, argc, "deny", &idx);
19095
19096 if (idx) {
19097 direct = argv_find(argv, argc, "permit", &idx)
19098 ? COMMUNITY_PERMIT
19099 : COMMUNITY_DENY;
19100
19101 idx = 0;
19102 argv_find(argv, argc, "AA:NN", &idx);
19103 str = argv_concat(argv, argc, idx);
19104 }
19105
19106 idx = 0;
19107 argv_find(argv, argc, "(1-99)", &idx);
19108 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19109 cl_name_or_number = argv[idx]->arg;
19110
19111 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19112 direct, style);
19113
19114 XFREE(MTYPE_TMP, str);
19115
19116 if (ret < 0) {
19117 community_list_perror(vty, ret);
19118 return CMD_WARNING_CONFIG_FAILED;
19119 }
19120
19121 return CMD_SUCCESS;
19122 }
19123
19124 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19125 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19126 NO_STR BGP_STR COMMUNITY_LIST_STR
19127 "Community list number (standard)\n"
19128 "Add an standard community-list entry\n"
19129 "Community list name\n")
19130
19131 /*community-list expanded */
19132 DEFUN (community_list_expanded_all,
19133 bgp_community_list_expanded_all_cmd,
19134 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19135 BGP_STR
19136 COMMUNITY_LIST_STR
19137 "Community list number (expanded)\n"
19138 "Add an expanded community-list entry\n"
19139 "Community list name\n"
19140 "Sequence number of an entry\n"
19141 "Sequence number\n"
19142 "Specify community to reject\n"
19143 "Specify community to accept\n"
19144 COMMUNITY_VAL_STR)
19145 {
19146 char *cl_name_or_number = NULL;
19147 char *seq = NULL;
19148 int direct = 0;
19149 int style = COMMUNITY_LIST_EXPANDED;
19150 int idx = 0;
19151
19152 argv_find(argv, argc, "(0-4294967295)", &idx);
19153 if (idx)
19154 seq = argv[idx]->arg;
19155
19156 idx = 0;
19157
19158 argv_find(argv, argc, "(100-500)", &idx);
19159 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19160 cl_name_or_number = argv[idx]->arg;
19161 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19162 : COMMUNITY_DENY;
19163 argv_find(argv, argc, "AA:NN", &idx);
19164 char *str = argv_concat(argv, argc, idx);
19165
19166 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19167 direct, style);
19168
19169 XFREE(MTYPE_TMP, str);
19170
19171 if (ret < 0) {
19172 /* Display error string. */
19173 community_list_perror(vty, ret);
19174 return CMD_WARNING_CONFIG_FAILED;
19175 }
19176
19177 return CMD_SUCCESS;
19178 }
19179
19180 DEFUN (no_community_list_expanded_all,
19181 no_bgp_community_list_expanded_all_cmd,
19182 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19183 NO_STR
19184 BGP_STR
19185 COMMUNITY_LIST_STR
19186 "Community list number (expanded)\n"
19187 "Add an expanded community-list entry\n"
19188 "Community list name\n"
19189 "Sequence number of an entry\n"
19190 "Sequence number\n"
19191 "Specify community to reject\n"
19192 "Specify community to accept\n"
19193 COMMUNITY_VAL_STR)
19194 {
19195 char *cl_name_or_number = NULL;
19196 char *seq = NULL;
19197 char *str = NULL;
19198 int direct = 0;
19199 int style = COMMUNITY_LIST_EXPANDED;
19200 int idx = 0;
19201
19202 argv_find(argv, argc, "(0-4294967295)", &idx);
19203 if (idx)
19204 seq = argv[idx]->arg;
19205
19206 idx = 0;
19207 argv_find(argv, argc, "permit", &idx);
19208 argv_find(argv, argc, "deny", &idx);
19209
19210 if (idx) {
19211 direct = argv_find(argv, argc, "permit", &idx)
19212 ? COMMUNITY_PERMIT
19213 : COMMUNITY_DENY;
19214
19215 idx = 0;
19216 argv_find(argv, argc, "AA:NN", &idx);
19217 str = argv_concat(argv, argc, idx);
19218 }
19219
19220 idx = 0;
19221 argv_find(argv, argc, "(100-500)", &idx);
19222 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19223 cl_name_or_number = argv[idx]->arg;
19224
19225 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19226 direct, style);
19227
19228 XFREE(MTYPE_TMP, str);
19229
19230 if (ret < 0) {
19231 community_list_perror(vty, ret);
19232 return CMD_WARNING_CONFIG_FAILED;
19233 }
19234
19235 return CMD_SUCCESS;
19236 }
19237
19238 ALIAS(no_community_list_expanded_all,
19239 no_bgp_community_list_expanded_all_list_cmd,
19240 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19241 NO_STR BGP_STR COMMUNITY_LIST_STR
19242 "Community list number (expanded)\n"
19243 "Add an expanded community-list entry\n"
19244 "Community list name\n")
19245
19246 /* Return configuration string of community-list entry. */
19247 static const char *community_list_config_str(struct community_entry *entry)
19248 {
19249 const char *str;
19250
19251 if (entry->any)
19252 str = "";
19253 else {
19254 if (entry->style == COMMUNITY_LIST_STANDARD)
19255 str = community_str(entry->u.com, false);
19256 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19257 str = lcommunity_str(entry->u.lcom, false);
19258 else
19259 str = entry->config;
19260 }
19261 return str;
19262 }
19263
19264 static void community_list_show(struct vty *vty, struct community_list *list)
19265 {
19266 struct community_entry *entry;
19267
19268 for (entry = list->head; entry; entry = entry->next) {
19269 if (entry == list->head) {
19270 if (all_digit(list->name))
19271 vty_out(vty, "Community %s list %s\n",
19272 entry->style == COMMUNITY_LIST_STANDARD
19273 ? "standard"
19274 : "(expanded) access",
19275 list->name);
19276 else
19277 vty_out(vty, "Named Community %s list %s\n",
19278 entry->style == COMMUNITY_LIST_STANDARD
19279 ? "standard"
19280 : "expanded",
19281 list->name);
19282 }
19283 if (entry->any)
19284 vty_out(vty, " %s\n",
19285 community_direct_str(entry->direct));
19286 else
19287 vty_out(vty, " %s %s\n",
19288 community_direct_str(entry->direct),
19289 community_list_config_str(entry));
19290 }
19291 }
19292
19293 DEFUN (show_community_list,
19294 show_bgp_community_list_cmd,
19295 "show bgp community-list",
19296 SHOW_STR
19297 BGP_STR
19298 "List community-list\n")
19299 {
19300 struct community_list *list;
19301 struct community_list_master *cm;
19302
19303 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19304 if (!cm)
19305 return CMD_SUCCESS;
19306
19307 for (list = cm->num.head; list; list = list->next)
19308 community_list_show(vty, list);
19309
19310 for (list = cm->str.head; list; list = list->next)
19311 community_list_show(vty, list);
19312
19313 return CMD_SUCCESS;
19314 }
19315
19316 DEFUN (show_community_list_arg,
19317 show_bgp_community_list_arg_cmd,
19318 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19319 SHOW_STR
19320 BGP_STR
19321 "List community-list\n"
19322 "Community-list number\n"
19323 "Community-list name\n"
19324 "Detailed information on community-list\n")
19325 {
19326 int idx_comm_list = 3;
19327 struct community_list *list;
19328
19329 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19330 COMMUNITY_LIST_MASTER);
19331 if (!list) {
19332 vty_out(vty, "%% Can't find community-list\n");
19333 return CMD_WARNING;
19334 }
19335
19336 community_list_show(vty, list);
19337
19338 return CMD_SUCCESS;
19339 }
19340
19341 /*
19342 * Large Community code.
19343 */
19344 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19345 struct cmd_token **argv, int style,
19346 int reject_all_digit_name)
19347 {
19348 int ret;
19349 int direct;
19350 char *str;
19351 int idx = 0;
19352 char *cl_name;
19353 char *seq = NULL;
19354
19355 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19356 seq = argv[idx]->arg;
19357
19358 idx = 0;
19359 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19360 : COMMUNITY_DENY;
19361
19362 /* All digit name check. */
19363 idx = 0;
19364 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19365 argv_find(argv, argc, "(1-99)", &idx);
19366 argv_find(argv, argc, "(100-500)", &idx);
19367 cl_name = argv[idx]->arg;
19368 if (reject_all_digit_name && all_digit(cl_name)) {
19369 vty_out(vty, "%% Community name cannot have all digits\n");
19370 return CMD_WARNING_CONFIG_FAILED;
19371 }
19372
19373 idx = 0;
19374 argv_find(argv, argc, "AA:BB:CC", &idx);
19375 argv_find(argv, argc, "LINE", &idx);
19376 /* Concat community string argument. */
19377 if (idx)
19378 str = argv_concat(argv, argc, idx);
19379 else
19380 str = NULL;
19381
19382 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19383
19384 /* Free temporary community list string allocated by
19385 argv_concat(). */
19386 XFREE(MTYPE_TMP, str);
19387
19388 if (ret < 0) {
19389 community_list_perror(vty, ret);
19390 return CMD_WARNING_CONFIG_FAILED;
19391 }
19392 return CMD_SUCCESS;
19393 }
19394
19395 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19396 struct cmd_token **argv, int style)
19397 {
19398 int ret;
19399 int direct = 0;
19400 char *str = NULL;
19401 int idx = 0;
19402 char *seq = NULL;
19403
19404 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19405 seq = argv[idx]->arg;
19406
19407 idx = 0;
19408 argv_find(argv, argc, "permit", &idx);
19409 argv_find(argv, argc, "deny", &idx);
19410
19411 if (idx) {
19412 /* Check the list direct. */
19413 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19414 direct = COMMUNITY_PERMIT;
19415 else
19416 direct = COMMUNITY_DENY;
19417
19418 idx = 0;
19419 argv_find(argv, argc, "LINE", &idx);
19420 argv_find(argv, argc, "AA:AA:NN", &idx);
19421 /* Concat community string argument. */
19422 str = argv_concat(argv, argc, idx);
19423 }
19424
19425 idx = 0;
19426 argv_find(argv, argc, "(1-99)", &idx);
19427 argv_find(argv, argc, "(100-500)", &idx);
19428 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19429
19430 /* Unset community list. */
19431 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19432 style);
19433
19434 /* Free temporary community list string allocated by
19435 argv_concat(). */
19436 XFREE(MTYPE_TMP, str);
19437
19438 if (ret < 0) {
19439 community_list_perror(vty, ret);
19440 return CMD_WARNING_CONFIG_FAILED;
19441 }
19442
19443 return CMD_SUCCESS;
19444 }
19445
19446 /* "large-community-list" keyword help string. */
19447 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19448 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19449
19450 DEFUN (lcommunity_list_standard,
19451 bgp_lcommunity_list_standard_cmd,
19452 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19453 BGP_STR
19454 LCOMMUNITY_LIST_STR
19455 "Large Community list number (standard)\n"
19456 "Sequence number of an entry\n"
19457 "Sequence number\n"
19458 "Specify large community to reject\n"
19459 "Specify large community to accept\n"
19460 LCOMMUNITY_VAL_STR)
19461 {
19462 return lcommunity_list_set_vty(vty, argc, argv,
19463 LARGE_COMMUNITY_LIST_STANDARD, 0);
19464 }
19465
19466 DEFUN (lcommunity_list_expanded,
19467 bgp_lcommunity_list_expanded_cmd,
19468 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19469 BGP_STR
19470 LCOMMUNITY_LIST_STR
19471 "Large Community list number (expanded)\n"
19472 "Sequence number of an entry\n"
19473 "Sequence number\n"
19474 "Specify large community to reject\n"
19475 "Specify large community to accept\n"
19476 "An ordered list as a regular-expression\n")
19477 {
19478 return lcommunity_list_set_vty(vty, argc, argv,
19479 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19480 }
19481
19482 DEFUN (lcommunity_list_name_standard,
19483 bgp_lcommunity_list_name_standard_cmd,
19484 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19485 BGP_STR
19486 LCOMMUNITY_LIST_STR
19487 "Specify standard large-community-list\n"
19488 "Large Community list name\n"
19489 "Sequence number of an entry\n"
19490 "Sequence number\n"
19491 "Specify large community to reject\n"
19492 "Specify large community to accept\n"
19493 LCOMMUNITY_VAL_STR)
19494 {
19495 return lcommunity_list_set_vty(vty, argc, argv,
19496 LARGE_COMMUNITY_LIST_STANDARD, 1);
19497 }
19498
19499 DEFUN (lcommunity_list_name_expanded,
19500 bgp_lcommunity_list_name_expanded_cmd,
19501 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19502 BGP_STR
19503 LCOMMUNITY_LIST_STR
19504 "Specify expanded large-community-list\n"
19505 "Large Community list name\n"
19506 "Sequence number of an entry\n"
19507 "Sequence number\n"
19508 "Specify large community to reject\n"
19509 "Specify large community to accept\n"
19510 "An ordered list as a regular-expression\n")
19511 {
19512 return lcommunity_list_set_vty(vty, argc, argv,
19513 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19514 }
19515
19516 DEFUN (no_lcommunity_list_all,
19517 no_bgp_lcommunity_list_all_cmd,
19518 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
19519 NO_STR
19520 BGP_STR
19521 LCOMMUNITY_LIST_STR
19522 "Large Community list number (standard)\n"
19523 "Large Community list number (expanded)\n"
19524 "Large Community list name\n")
19525 {
19526 return lcommunity_list_unset_vty(vty, argc, argv,
19527 LARGE_COMMUNITY_LIST_STANDARD);
19528 }
19529
19530 DEFUN (no_lcommunity_list_name_standard_all,
19531 no_bgp_lcommunity_list_name_standard_all_cmd,
19532 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
19533 NO_STR
19534 BGP_STR
19535 LCOMMUNITY_LIST_STR
19536 "Specify standard large-community-list\n"
19537 "Large Community list name\n")
19538 {
19539 return lcommunity_list_unset_vty(vty, argc, argv,
19540 LARGE_COMMUNITY_LIST_STANDARD);
19541 }
19542
19543 DEFUN (no_lcommunity_list_name_expanded_all,
19544 no_bgp_lcommunity_list_name_expanded_all_cmd,
19545 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
19546 NO_STR
19547 BGP_STR
19548 LCOMMUNITY_LIST_STR
19549 "Specify expanded large-community-list\n"
19550 "Large Community list name\n")
19551 {
19552 return lcommunity_list_unset_vty(vty, argc, argv,
19553 LARGE_COMMUNITY_LIST_EXPANDED);
19554 }
19555
19556 DEFUN (no_lcommunity_list_standard,
19557 no_bgp_lcommunity_list_standard_cmd,
19558 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19559 NO_STR
19560 BGP_STR
19561 LCOMMUNITY_LIST_STR
19562 "Large Community list number (standard)\n"
19563 "Sequence number of an entry\n"
19564 "Sequence number\n"
19565 "Specify large community to reject\n"
19566 "Specify large community to accept\n"
19567 LCOMMUNITY_VAL_STR)
19568 {
19569 return lcommunity_list_unset_vty(vty, argc, argv,
19570 LARGE_COMMUNITY_LIST_STANDARD);
19571 }
19572
19573 DEFUN (no_lcommunity_list_expanded,
19574 no_bgp_lcommunity_list_expanded_cmd,
19575 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19576 NO_STR
19577 BGP_STR
19578 LCOMMUNITY_LIST_STR
19579 "Large Community list number (expanded)\n"
19580 "Sequence number of an entry\n"
19581 "Sequence number\n"
19582 "Specify large community to reject\n"
19583 "Specify large community to accept\n"
19584 "An ordered list as a regular-expression\n")
19585 {
19586 return lcommunity_list_unset_vty(vty, argc, argv,
19587 LARGE_COMMUNITY_LIST_EXPANDED);
19588 }
19589
19590 DEFUN (no_lcommunity_list_name_standard,
19591 no_bgp_lcommunity_list_name_standard_cmd,
19592 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19593 NO_STR
19594 BGP_STR
19595 LCOMMUNITY_LIST_STR
19596 "Specify standard large-community-list\n"
19597 "Large Community list name\n"
19598 "Sequence number of an entry\n"
19599 "Sequence number\n"
19600 "Specify large community to reject\n"
19601 "Specify large community to accept\n"
19602 LCOMMUNITY_VAL_STR)
19603 {
19604 return lcommunity_list_unset_vty(vty, argc, argv,
19605 LARGE_COMMUNITY_LIST_STANDARD);
19606 }
19607
19608 DEFUN (no_lcommunity_list_name_expanded,
19609 no_bgp_lcommunity_list_name_expanded_cmd,
19610 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19611 NO_STR
19612 BGP_STR
19613 LCOMMUNITY_LIST_STR
19614 "Specify expanded large-community-list\n"
19615 "Large community list name\n"
19616 "Sequence number of an entry\n"
19617 "Sequence number\n"
19618 "Specify large community to reject\n"
19619 "Specify large community to accept\n"
19620 "An ordered list as a regular-expression\n")
19621 {
19622 return lcommunity_list_unset_vty(vty, argc, argv,
19623 LARGE_COMMUNITY_LIST_EXPANDED);
19624 }
19625
19626 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19627 {
19628 struct community_entry *entry;
19629
19630 for (entry = list->head; entry; entry = entry->next) {
19631 if (entry == list->head) {
19632 if (all_digit(list->name))
19633 vty_out(vty, "Large community %s list %s\n",
19634 entry->style ==
19635 LARGE_COMMUNITY_LIST_STANDARD
19636 ? "standard"
19637 : "(expanded) access",
19638 list->name);
19639 else
19640 vty_out(vty,
19641 "Named large community %s list %s\n",
19642 entry->style ==
19643 LARGE_COMMUNITY_LIST_STANDARD
19644 ? "standard"
19645 : "expanded",
19646 list->name);
19647 }
19648 if (entry->any)
19649 vty_out(vty, " %s\n",
19650 community_direct_str(entry->direct));
19651 else
19652 vty_out(vty, " %s %s\n",
19653 community_direct_str(entry->direct),
19654 community_list_config_str(entry));
19655 }
19656 }
19657
19658 DEFUN (show_lcommunity_list,
19659 show_bgp_lcommunity_list_cmd,
19660 "show bgp large-community-list",
19661 SHOW_STR
19662 BGP_STR
19663 "List large-community list\n")
19664 {
19665 struct community_list *list;
19666 struct community_list_master *cm;
19667
19668 cm = community_list_master_lookup(bgp_clist,
19669 LARGE_COMMUNITY_LIST_MASTER);
19670 if (!cm)
19671 return CMD_SUCCESS;
19672
19673 for (list = cm->num.head; list; list = list->next)
19674 lcommunity_list_show(vty, list);
19675
19676 for (list = cm->str.head; list; list = list->next)
19677 lcommunity_list_show(vty, list);
19678
19679 return CMD_SUCCESS;
19680 }
19681
19682 DEFUN (show_lcommunity_list_arg,
19683 show_bgp_lcommunity_list_arg_cmd,
19684 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
19685 SHOW_STR
19686 BGP_STR
19687 "List large-community list\n"
19688 "Large-community-list number\n"
19689 "Large-community-list name\n"
19690 "Detailed information on large-community-list\n")
19691 {
19692 struct community_list *list;
19693
19694 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19695 LARGE_COMMUNITY_LIST_MASTER);
19696 if (!list) {
19697 vty_out(vty, "%% Can't find large-community-list\n");
19698 return CMD_WARNING;
19699 }
19700
19701 lcommunity_list_show(vty, list);
19702
19703 return CMD_SUCCESS;
19704 }
19705
19706 /* "extcommunity-list" keyword help string. */
19707 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19708 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19709
19710 DEFUN (extcommunity_list_standard,
19711 bgp_extcommunity_list_standard_cmd,
19712 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19713 BGP_STR
19714 EXTCOMMUNITY_LIST_STR
19715 "Extended Community list number (standard)\n"
19716 "Specify standard extcommunity-list\n"
19717 "Community list name\n"
19718 "Sequence number of an entry\n"
19719 "Sequence number\n"
19720 "Specify community to reject\n"
19721 "Specify community to accept\n"
19722 EXTCOMMUNITY_VAL_STR)
19723 {
19724 int style = EXTCOMMUNITY_LIST_STANDARD;
19725 int direct = 0;
19726 char *cl_number_or_name = NULL;
19727 char *seq = NULL;
19728
19729 int idx = 0;
19730
19731 argv_find(argv, argc, "(1-99)", &idx);
19732 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19733 cl_number_or_name = argv[idx]->arg;
19734
19735 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19736 seq = argv[idx]->arg;
19737
19738 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19739 : COMMUNITY_DENY;
19740 argv_find(argv, argc, "AA:NN", &idx);
19741 char *str = argv_concat(argv, argc, idx);
19742
19743 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19744 direct, style);
19745
19746 XFREE(MTYPE_TMP, str);
19747
19748 if (ret < 0) {
19749 community_list_perror(vty, ret);
19750 return CMD_WARNING_CONFIG_FAILED;
19751 }
19752
19753 return CMD_SUCCESS;
19754 }
19755
19756 DEFUN (extcommunity_list_name_expanded,
19757 bgp_extcommunity_list_name_expanded_cmd,
19758 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
19759 BGP_STR
19760 EXTCOMMUNITY_LIST_STR
19761 "Extended Community list number (expanded)\n"
19762 "Specify expanded extcommunity-list\n"
19763 "Extended Community list name\n"
19764 "Sequence number of an entry\n"
19765 "Sequence number\n"
19766 "Specify community to reject\n"
19767 "Specify community to accept\n"
19768 "An ordered list as a regular-expression\n")
19769 {
19770 int style = EXTCOMMUNITY_LIST_EXPANDED;
19771 int direct = 0;
19772 char *cl_number_or_name = NULL;
19773 char *seq = NULL;
19774 int idx = 0;
19775
19776 argv_find(argv, argc, "(100-500)", &idx);
19777 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19778 cl_number_or_name = argv[idx]->arg;
19779
19780 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19781 seq = argv[idx]->arg;
19782
19783 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19784 : COMMUNITY_DENY;
19785 argv_find(argv, argc, "LINE", &idx);
19786 char *str = argv_concat(argv, argc, idx);
19787
19788 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19789 direct, style);
19790
19791 XFREE(MTYPE_TMP, str);
19792
19793 if (ret < 0) {
19794 community_list_perror(vty, ret);
19795 return CMD_WARNING_CONFIG_FAILED;
19796 }
19797
19798 return CMD_SUCCESS;
19799 }
19800
19801 DEFUN (no_extcommunity_list_standard_all,
19802 no_bgp_extcommunity_list_standard_all_cmd,
19803 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19804 NO_STR
19805 BGP_STR
19806 EXTCOMMUNITY_LIST_STR
19807 "Extended Community list number (standard)\n"
19808 "Specify standard extcommunity-list\n"
19809 "Community list name\n"
19810 "Sequence number of an entry\n"
19811 "Sequence number\n"
19812 "Specify community to reject\n"
19813 "Specify community to accept\n"
19814 EXTCOMMUNITY_VAL_STR)
19815 {
19816 int style = EXTCOMMUNITY_LIST_STANDARD;
19817 int direct = 0;
19818 char *cl_number_or_name = NULL;
19819 char *str = NULL;
19820 char *seq = NULL;
19821 int idx = 0;
19822
19823 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19824 seq = argv[idx]->arg;
19825
19826 idx = 0;
19827 argv_find(argv, argc, "permit", &idx);
19828 argv_find(argv, argc, "deny", &idx);
19829 if (idx) {
19830 direct = argv_find(argv, argc, "permit", &idx)
19831 ? COMMUNITY_PERMIT
19832 : COMMUNITY_DENY;
19833
19834 idx = 0;
19835 argv_find(argv, argc, "AA:NN", &idx);
19836 str = argv_concat(argv, argc, idx);
19837 }
19838
19839 idx = 0;
19840 argv_find(argv, argc, "(1-99)", &idx);
19841 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19842 cl_number_or_name = argv[idx]->arg;
19843
19844 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19845 seq, direct, style);
19846
19847 XFREE(MTYPE_TMP, str);
19848
19849 if (ret < 0) {
19850 community_list_perror(vty, ret);
19851 return CMD_WARNING_CONFIG_FAILED;
19852 }
19853
19854 return CMD_SUCCESS;
19855 }
19856
19857 ALIAS(no_extcommunity_list_standard_all,
19858 no_bgp_extcommunity_list_standard_all_list_cmd,
19859 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
19860 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19861 "Extended Community list number (standard)\n"
19862 "Specify standard extcommunity-list\n"
19863 "Community list name\n")
19864
19865 DEFUN (no_extcommunity_list_expanded_all,
19866 no_bgp_extcommunity_list_expanded_all_cmd,
19867 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
19868 NO_STR
19869 BGP_STR
19870 EXTCOMMUNITY_LIST_STR
19871 "Extended Community list number (expanded)\n"
19872 "Specify expanded extcommunity-list\n"
19873 "Extended Community list name\n"
19874 "Sequence number of an entry\n"
19875 "Sequence number\n"
19876 "Specify community to reject\n"
19877 "Specify community to accept\n"
19878 "An ordered list as a regular-expression\n")
19879 {
19880 int style = EXTCOMMUNITY_LIST_EXPANDED;
19881 int direct = 0;
19882 char *cl_number_or_name = NULL;
19883 char *str = NULL;
19884 char *seq = NULL;
19885 int idx = 0;
19886
19887 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19888 seq = argv[idx]->arg;
19889
19890 idx = 0;
19891 argv_find(argv, argc, "permit", &idx);
19892 argv_find(argv, argc, "deny", &idx);
19893
19894 if (idx) {
19895 direct = argv_find(argv, argc, "permit", &idx)
19896 ? COMMUNITY_PERMIT
19897 : COMMUNITY_DENY;
19898
19899 idx = 0;
19900 argv_find(argv, argc, "LINE", &idx);
19901 str = argv_concat(argv, argc, idx);
19902 }
19903
19904 idx = 0;
19905 argv_find(argv, argc, "(100-500)", &idx);
19906 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19907 cl_number_or_name = argv[idx]->arg;
19908
19909 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19910 seq, direct, style);
19911
19912 XFREE(MTYPE_TMP, str);
19913
19914 if (ret < 0) {
19915 community_list_perror(vty, ret);
19916 return CMD_WARNING_CONFIG_FAILED;
19917 }
19918
19919 return CMD_SUCCESS;
19920 }
19921
19922 ALIAS(no_extcommunity_list_expanded_all,
19923 no_bgp_extcommunity_list_expanded_all_list_cmd,
19924 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
19925 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19926 "Extended Community list number (expanded)\n"
19927 "Specify expanded extcommunity-list\n"
19928 "Extended Community list name\n")
19929
19930 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
19931 {
19932 struct community_entry *entry;
19933
19934 for (entry = list->head; entry; entry = entry->next) {
19935 if (entry == list->head) {
19936 if (all_digit(list->name))
19937 vty_out(vty, "Extended community %s list %s\n",
19938 entry->style == EXTCOMMUNITY_LIST_STANDARD
19939 ? "standard"
19940 : "(expanded) access",
19941 list->name);
19942 else
19943 vty_out(vty,
19944 "Named extended community %s list %s\n",
19945 entry->style == EXTCOMMUNITY_LIST_STANDARD
19946 ? "standard"
19947 : "expanded",
19948 list->name);
19949 }
19950 if (entry->any)
19951 vty_out(vty, " %s\n",
19952 community_direct_str(entry->direct));
19953 else
19954 vty_out(vty, " %s %s\n",
19955 community_direct_str(entry->direct),
19956 community_list_config_str(entry));
19957 }
19958 }
19959
19960 DEFUN (show_extcommunity_list,
19961 show_bgp_extcommunity_list_cmd,
19962 "show bgp extcommunity-list",
19963 SHOW_STR
19964 BGP_STR
19965 "List extended-community list\n")
19966 {
19967 struct community_list *list;
19968 struct community_list_master *cm;
19969
19970 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19971 if (!cm)
19972 return CMD_SUCCESS;
19973
19974 for (list = cm->num.head; list; list = list->next)
19975 extcommunity_list_show(vty, list);
19976
19977 for (list = cm->str.head; list; list = list->next)
19978 extcommunity_list_show(vty, list);
19979
19980 return CMD_SUCCESS;
19981 }
19982
19983 DEFUN (show_extcommunity_list_arg,
19984 show_bgp_extcommunity_list_arg_cmd,
19985 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
19986 SHOW_STR
19987 BGP_STR
19988 "List extended-community list\n"
19989 "Extcommunity-list number\n"
19990 "Extcommunity-list name\n"
19991 "Detailed information on extcommunity-list\n")
19992 {
19993 int idx_comm_list = 3;
19994 struct community_list *list;
19995
19996 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19997 EXTCOMMUNITY_LIST_MASTER);
19998 if (!list) {
19999 vty_out(vty, "%% Can't find extcommunity-list\n");
20000 return CMD_WARNING;
20001 }
20002
20003 extcommunity_list_show(vty, list);
20004
20005 return CMD_SUCCESS;
20006 }
20007
20008 /* Display community-list and extcommunity-list configuration. */
20009 static int community_list_config_write(struct vty *vty)
20010 {
20011 struct community_list *list;
20012 struct community_entry *entry;
20013 struct community_list_master *cm;
20014 int write = 0;
20015
20016 /* Community-list. */
20017 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20018
20019 for (list = cm->num.head; list; list = list->next)
20020 for (entry = list->head; entry; entry = entry->next) {
20021 vty_out(vty,
20022 "bgp community-list %s seq %" PRId64 " %s %s\n",
20023 list->name, entry->seq,
20024 community_direct_str(entry->direct),
20025 community_list_config_str(entry));
20026 write++;
20027 }
20028 for (list = cm->str.head; list; list = list->next)
20029 for (entry = list->head; entry; entry = entry->next) {
20030 vty_out(vty,
20031 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20032 entry->style == COMMUNITY_LIST_STANDARD
20033 ? "standard"
20034 : "expanded",
20035 list->name, entry->seq,
20036 community_direct_str(entry->direct),
20037 community_list_config_str(entry));
20038 write++;
20039 }
20040
20041 /* Extcommunity-list. */
20042 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20043
20044 for (list = cm->num.head; list; list = list->next)
20045 for (entry = list->head; entry; entry = entry->next) {
20046 vty_out(vty,
20047 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20048 list->name, entry->seq,
20049 community_direct_str(entry->direct),
20050 community_list_config_str(entry));
20051 write++;
20052 }
20053 for (list = cm->str.head; list; list = list->next)
20054 for (entry = list->head; entry; entry = entry->next) {
20055 vty_out(vty,
20056 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20057 entry->style == EXTCOMMUNITY_LIST_STANDARD
20058 ? "standard"
20059 : "expanded",
20060 list->name, entry->seq,
20061 community_direct_str(entry->direct),
20062 community_list_config_str(entry));
20063 write++;
20064 }
20065
20066
20067 /* lcommunity-list. */
20068 cm = community_list_master_lookup(bgp_clist,
20069 LARGE_COMMUNITY_LIST_MASTER);
20070
20071 for (list = cm->num.head; list; list = list->next)
20072 for (entry = list->head; entry; entry = entry->next) {
20073 vty_out(vty,
20074 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20075 list->name, entry->seq,
20076 community_direct_str(entry->direct),
20077 community_list_config_str(entry));
20078 write++;
20079 }
20080 for (list = cm->str.head; list; list = list->next)
20081 for (entry = list->head; entry; entry = entry->next) {
20082 vty_out(vty,
20083 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20084
20085 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20086 ? "standard"
20087 : "expanded",
20088 list->name, entry->seq, community_direct_str(entry->direct),
20089 community_list_config_str(entry));
20090 write++;
20091 }
20092
20093 return write;
20094 }
20095
20096 static int community_list_config_write(struct vty *vty);
20097 static struct cmd_node community_list_node = {
20098 .name = "community list",
20099 .node = COMMUNITY_LIST_NODE,
20100 .prompt = "",
20101 .config_write = community_list_config_write,
20102 };
20103
20104 static void community_list_vty(void)
20105 {
20106 install_node(&community_list_node);
20107
20108 /* Community-list. */
20109 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20110 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20111 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20112 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20113 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20114 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20115 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20116 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20117
20118 /* Extcommunity-list. */
20119 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20120 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20121 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20122 install_element(CONFIG_NODE,
20123 &no_bgp_extcommunity_list_standard_all_list_cmd);
20124 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20125 install_element(CONFIG_NODE,
20126 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20127 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20128 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20129
20130 /* Large Community List */
20131 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20132 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20133 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20134 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20135 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20136 install_element(CONFIG_NODE,
20137 &no_bgp_lcommunity_list_name_standard_all_cmd);
20138 install_element(CONFIG_NODE,
20139 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20140 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20141 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20142 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20143 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20144 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20145 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20146
20147 bgp_community_list_command_completion_setup();
20148 }
20149
20150 static struct cmd_node community_alias_node = {
20151 .name = "community alias",
20152 .node = COMMUNITY_ALIAS_NODE,
20153 .prompt = "",
20154 .config_write = bgp_community_alias_write,
20155 };
20156
20157 void community_alias_vty(void)
20158 {
20159 install_node(&community_alias_node);
20160
20161 /* Community-list. */
20162 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20163
20164 bgp_community_alias_command_completion_setup();
20165 }